from ij.text import TextWindow,TextPanel from ij import WindowManager def getTableData(tabname): ''' get's the first table open with the provided name returns the heading list and a nested list of contents ''' frames=WindowManager.getNonImageWindows() titles=[frames[i].title for i in range(len(frames))] #print(titles) matchidx=titles.index(tabname) panel=frames[matchidx].getTextPanel() text=panel.getText() lines=text.split('\n') headers=lines[0].split('\t') sdata=[lines[i].split('\t') for i in range(1,len(lines)-1)] return sdata,headers def makeTableFromStrings(sdata,headings,title): ''' convert's the string table to a long string and makes a table out of it ''' rows=len(sdata) cols=len(sdata[0]) text='\n'.join(['\t'.join([sdata[i][j] for j in range(cols)]) for i in range(rows)]) TextWindow(title,'\t'.join(headings),text,400,200) return text def getTableValues(sdata): ''' get's the table rows as a floating point arrays ''' rows=len(sdata) cols=len(sdata[0]) fdata=[[float(sdata[i][j]) for j in range(cols)] for i in range(rows)] return fdata def getTableStrings(fdata): ''' get's the table rows as string arrays ''' rows=len(fdata) cols=len(fdata[0]) sdata=[[str(fdata[i][j]) for j in range(cols)] for i in range(rows)] return sdata def transpose(arr): ''' returns the transpose of a nested array ''' rows=len(arr) cols=len(arr[0]) return [[arr[j][i] for j in range(rows)] for i in range(cols)] def copyArr(arr): ''' copy a 2d array ''' return [row[:] for row in arr] def appendTable(dst,src): ''' adds the rows of a source table to a destination table ''' newdst=copyArr(dst) newsrc=copyArr(src) return newdst.extend(newsrc) def combineTables(dst,src): ''' adds the columns of a source table to a destination table must be same type? uses dst length if src is longer ''' return [dstrow[i][:].extend(srcrow[i][:]) for i in range(len(dst))]