def testprofiling(ID): tree = Display.getFront().getLayerSet().findById(ID) coords = Matrix(getNodeCoordinates(tree)) #Define axis vectors and origin xnorm = Matrix([[1,0,0]]) ynorm = Matrix([[0,1,0]]) znorm = Matrix([[0,0,1]]) center= Matrix([[0,0,0]]) #Project nodes onto axis dpx=[] dpy=[] dpz=[] m=coords.getRowDimension() for i in range(0, m): xstore = Matrix([coords.getRow( i )]) * xnorm.transpose() ystore = Matrix([coords.getRow( i )]) * ynorm.transpose() zstore = Matrix([coords.getRow( i )]) * znorm.transpose() dpx.append(xstore.getRow(0)) dpy.append(ystore.getRow(0)) dpz.append(zstore.getRow(0)) #get it back in array form (get rid of list in list of Jarray) dpx=[ x[0] for x in dpx] dpy=[ x[0] for x in dpy] dpz=[ x[0] for x in dpz] zipped=zip(dpx, dpy, dpz) return zipped
def profileDistances(ID, biniter): histo=getDendriticProfiles(ID, biniter) xhisto=histo[0] yhisto=histo[1] zhisto=histo[2] xdistance=[] ydistance=[] zdistance=[] tree = Display.getFront().getLayerSet().findById(ID) coords = Matrix(getNodeCoordinates(tree)) m=coords.getRowDimension() for i in range(0, m): xdist = coords.get(i, 1 ) if xdist > 0 : xdistance.append(xdist) else: xdistance.append((-1)*xdist) for i in range(0, m): ydist = coords.get(i, 0 ) if ydist > 0 : ydistance.append(ydist) else: ydistance.append((-1)*ydist) for i in range(0, m): zdist = sqrt(coords.get(i, 0)**2 + coords.get(i,1)**2) zdistance.append(zdist) return xdistance, ydistance, zdistance
def pca(ID, biniter): tree = Display.getFront().getLayerSet().findById(ID) #Calculate the center of mass center = Matrix( [[0,0,0]] ) coords = Matrix(getNodeCoordinates(tree)) m=coords.getRowDimension() for i in range(0, coords.getRowDimension()): center += Matrix([coords.getRow( i )]) center /= float(m) #print center """ x, y, z = 0, 0, 0 nc = getNodeCoordinates(tree) for c in nc: x += c[0] y += c[1] z += c[2] print "center:", x/len(nc), y/len(nc), z/len(nc) """ #Define covvariance matrix cova = Matrix([[0,0,0],[0,0,0],[0,0,0]]) diff= Matrix ( [[0,0,0]]) for i in range(0, m): diff = Matrix([coords.getRow( i )]) - center cova += diff.transpose() * diff cova /= float(m) #Evaluedecomposition evaluedecomp = cova.eig() evalues = evaluedecomp.getRealEigenvalues() evectors = evaluedecomp.getV() # is a Matrix instance #Find maximum Eigenvector for maximal Eigenvalue maxevaluepos = -1 maxevalue = 0 for i in range(0, len(evalues)): if evalues[i] > maxevalue or maxevaluepos==-1: maxevalue=evalues[i] maxevaluepos=i maxevector=evectors.getColumn(maxevaluepos) #HAVE TO GET VALUES OF COLUMN of evector matrix i NOT ROW #--------------------TEST if Eigenvaluedecomposition is correct----------- #vectormatrix=Matrix([evectors.getColumn(maxevaluepos)]) #test=cova * vectormatrix.transpose() #test2=vectormatrix*maxevalue #print test #print test2 #------------------------------------------------------------------------- #Define a vector over the point cloud and count points in defined interval #Normalize vector length=sqrt(maxevector[0]**2 + maxevector[1]**2 + maxevector[2]**2) normvector = map(lambda x: x / length, maxevector) normvectormatrix = Matrix([normvector]) pca=[] m=coords.getRowDimension() for i in range(0, m): pcastore = (Matrix([coords.getRow( i )]) - center ) * normvectormatrix.transpose() pca.append(pcastore.getRow(0)) #Count number of nodes which fall in defined interval of pca projection -> has to be fixed globally when to compare PCAs! counter = 0 histovector = [] pca=[ x[0] for x in pca] #get it back in array form (get rid of list in list) binleft = -12500 #binleft = min(pca) iterations = biniter length = int(25000/iterations + 0.5) #int((max(pca)-min(pca))/iterations + 0.5) binright = binleft + length for i in range(0,iterations): for i in range(0, len(pca)): if pca[i] <= binright and pca[i] >= binleft: counter += 1 histovector.append(counter) counter=0 binleft+=length binright+=length #print "The histogram vector is:", histovector return histovector
def getDendriticProfiles(ID, biniter): tree = Display.getFront().getLayerSet().findById(ID) coords = Matrix(getNodeCoordinates(tree)) # Define axis vectors and origin xnorm = Matrix([[1, 0, 0]]) ynorm = Matrix([[0, 1, 0]]) znorm = Matrix([[0, 0, 1]]) center = Matrix([[0, 0, 0]]) # Project nodes onto axis dpx = [] dpy = [] dpz = [] m = coords.getRowDimension() for i in range(0, m): xstore = Matrix([coords.getRow(i)]) * xnorm.transpose() ystore = Matrix([coords.getRow(i)]) * ynorm.transpose() zstore = Matrix([coords.getRow(i)]) * znorm.transpose() dpx.append(xstore.getRow(0)) dpy.append(ystore.getRow(0)) dpz.append(zstore.getRow(0)) # Count number of nodes which fall in defined interval of pca projection xhistovector = [] yhistovector = [] zhistovector = [] # get it back in array form (get rid of list in list of Jarray) dpx = [x[0] for x in dpx] dpy = [x[0] for x in dpy] dpz = [x[0] for x in dpz] # Initialize interval size and fix iterations to a specific number xbinleft = -34600.0 ybinleft = -24200.0 zbinleft = 0 # --------PARAMETER FOR MACHINE LEARNING----- iterations = biniter # ------------------------------------------- xlength = int((35600.0 + 34600.0) / iterations + 0.5) ylength = int((21300.0 + 24200.0) / iterations + 0.5) zlength = int((22500) / iterations + 0.5) xbinright = xbinleft + xlength ybinright = ybinleft + ylength zbinright = zbinleft + zlength # Count elements in bins xaxis = [] # Count lengths in bins xdist = [] ydist = [] zdist = [] for i in range(0, iterations): counter = 0 xdiff = 0 for i in range(0, len(dpx)): if dpx[i] <= xbinright and dpx[i] >= xbinleft: counter += 1 xdiff += sqrt(dpy[i] ** 2 + dpz[i] ** 2) # sqrt(dpy[i]**2) xdist is yvalue if counter != 0: xdiff /= counter xdist.append(xdiff) xhistovector.append(counter) xaxis.append(xbinleft) xbinleft += xlength xbinright += xlength yaxis = [] for i in range(0, iterations): counter = 0 ydiff = 0 for i in range(0, len(dpy)): if dpy[i] <= ybinright and dpy[i] >= ybinleft: counter += 1 ydiff += sqrt(dpx[i] ** 2 + dpz[i] ** 2) if counter != 0: ydiff /= counter ydist.append(ydiff) yhistovector.append(counter) yaxis.append(ybinleft) ybinleft += ylength ybinright += ylength zaxis = [] for i in range(0, iterations): counter = 0 zdiff = 0 for i in range(0, len(dpz)): if dpz[i] <= zbinright and dpz[i] >= zbinleft: counter += 1 zdiff += sqrt(dpx[i] ** 2 + dpy[i] ** 2) if counter != 0: zdiff /= counter zdist.append(zdiff) zhistovector.append(counter) zaxis.append(zbinleft) zbinleft += zlength zbinright += zlength # print xdist # print ydist # print zdist """ #Normalize for i in range(0, iterations): xhistovector[i]/=float(xlength) yhistovector[i]/=float(ylength) zhistovector[i]/=float(zlength) """ return xhistovector, yhistovector, zhistovector, xdist, ydist, zdist
def getDendriticProfiles(ID): tree = Display.getFront().getLayerSet().findById(ID) coords = Matrix(getNodeCoordinates(tree)) #Define axis vectors and origin xnorm = Matrix([[1,0,0]]) ynorm = Matrix([[0,1,0]]) znorm = Matrix([[0,0,1]]) center= Matrix([[0,0,0]]) #Project nodes onto axis dpx=[] dpy=[] dpz=[] m=coords.getRowDimension() for i in range(0, m): xstore = Matrix([coords.getRow( i )]) * xnorm.transpose() ystore = Matrix([coords.getRow( i )]) * ynorm.transpose() zstore = Matrix([coords.getRow( i )]) * znorm.transpose() dpx.append(xstore.getRow(0)) dpy.append(ystore.getRow(0)) dpz.append(zstore.getRow(0)) #Count number of nodes which fall in defined interval of pca projection counter = 0 xhistovector = [] yhistovector = [] zhistovector = [] #get it back in array form (get rid of list in list of Jarray) dpx=[ x[0] for x in dpx] dpy=[ x[0] for x in dpy] dpz=[ x[0] for x in dpz] #Initialize interval size and fix iterations to a specific number xbinleft = min(dpx) ybinleft = min(dpy) zbinleft = min(dpz) #-------PARAMETER FOR MACHINE LEARNING-------------- iterations =100 #--------------------------------------------------- xlength = int((max(dpx)-min(dpx))/iterations + 0.5) ylength = int((max(dpy)-min(dpy))/iterations + 0.5) zlength = int((max(dpz)-min(dpz))/iterations + 0.5) xbinright = xbinleft + xlength ybinright = ybinleft + ylength zbinright = zbinleft + zlength #Count elements in bins xaxis=[] for i in range(0,iterations): for i in range(0, len(dpx)): if dpx[i] <= xbinright and dpx[i] >= xbinleft: counter += 1 xhistovector.append(counter) counter=0 xbinleft += xlength xbinright += xlength xaxis.append(xbinleft) yaxis=[] for i in range(0,iterations): for i in range(0, len(dpy)): if dpy[i] <= ybinright and dpy[i] >= ybinleft: counter += 1 yhistovector.append(ylength) counter=0 ybinleft += ylength ybinright += ylength yaxis.append(ybinleft) zaxis=[] for i in range(0,iterations): for i in range(0, len(dpz)): if dpz[i] <= zbinright and dpz[i] >= zbinleft: counter += 1 zhistovector.append(counter) counter=0 zbinleft += zlength zbinright += zlength zaxis.append(zbinleft) #Normalize bin-count by division through length for i in range(0, iterations): xhistovector[i]/=float(xlength) yhistovector[i]/=float(ylength) zhistovector[i]/=float(zlength) return xhistovector, yhistovector, zhistovector
# data may be a radius or a java.awt.geom.Area coords.append( correct([x, y, z]) ) #print coords[len(coords)-1] return coords #---------Select tree----------------- #tree = Display.getFront().getActive() ID = 74329 tree = Display.getFront().getLayerSet().findById(ID) #------------------------------------- #Calculate the center of mass center = Matrix( [[0,0,0]] ) coords = Matrix(getNodeCoordinates(tree)) m=coords.getRowDimension() for i in range(0, coords.getRowDimension()): center += Matrix([coords.getRow( i )]) center /= float(m) print center """ x, y, z = 0, 0, 0 nc = getNodeCoordinates(tree) for c in nc: x += c[0] y += c[1] z += c[2] print "center:", x/len(nc), y/len(nc), z/len(nc)
ID=75408 tree = Display.getFront().getLayerSet().findById(ID) coords = Matrix(getNodeCoordinates(tree)) #Define axis vectors and origin xnorm = Matrix([[1,0,0]]) ynorm = Matrix([[0,1,0]]) znorm = Matrix([[0,0,1]]) center= Matrix([[0,0,0]]) #Project nodes onto axis dpx=[] dpy=[] dpz=[] m=coords.getRowDimension() for i in range(0, m): xstore = Matrix([coords.getRow( i )]) * xnorm.transpose() ystore = Matrix([coords.getRow( i )]) * ynorm.transpose() zstore = Matrix([coords.getRow( i )]) * znorm.transpose() dpx.append(xstore.getRow(0)) dpy.append(ystore.getRow(0)) dpz.append(zstore.getRow(0)) #Count number of nodes which fall in defined interval of pca projection counter = 0 xhistovector = [] yhistovector = [] zhistovector = [] #get it back in array form (get rid of list in list of Jarray)
def sphereCount(ID, biniter): #find center of mass tree = Display.getFront().getLayerSet().findById(ID) coords = Matrix(getNodeCoordinates(tree)) center = Matrix( [[0,0,0]] ) m=coords.getRowDimension() for i in range(0, m): center += Matrix([coords.getRow( i )]) center /= float(m) #calculate all distances of all points to center of mass and put them in a list xdist=[] ydist=[] zdist=[] for i in range(0, m): xdiff=[] if coords.get(i,0) > center.get(0,0): xdiff = coords.get(i,0) - center.get(0,0) else: xdiff = center.get(0,0) - coords.get(i,0) xdist.append(xdiff) for i in range(0, m): ydiff=[] if coords.get(i,1) > center.get(0,1): ydiff = coords.get(i,1) - center.get(0,1) else: ydiff = center.get(0,1) - coords.get(i,1) ydist.append(ydiff) for i in range(0, m): zdiff=[] if coords.get(i,2) > center.get(0,2): zdiff = coords.get(i,2) - center.get(0,2) else: zdiff = center.get(0,2) - coords.get(i,2) zdist.append(zdiff) nodeDist=[] dist=[] for i in range(0, m): dist=sqrt(xdist[i]**2 + ydist[i]**2 + zdist[i]**2) nodeDist.append(dist) iterations=biniter Ri=0 #inner radius """ The maximum distance can only be achieved in the xy-plane With "fixed" coordinates this will approx. be 35000nm To make the scholl-profiles comparable this length has to be used. """ scholl=[] xaxis=[] counter=0 length= int(35000 / biniter + 0.5) Ra=length #outer radius for i in range(0, biniter): for i in range(0, len(nodeDist)): if nodeDist[i] <= Ra and nodeDist[i] >= Ri: counter += 1 scholl.append(counter) counter=0 xaxis.append(Ri) # adapt THIS position in all other scripts! Otherwise 1 datapoint is missing!! Ri += length Ra += length return scholl, xaxis
def sumDist(id1, biniter): distance=profileDistances(id1, biniter) xdistance=distance[0] ydistance=distance[1] zdistance=distance[2] tree = Display.getFront().getLayerSet().findById(id1) coords = Matrix(getNodeCoordinates(tree)) m=coords.getRowDimension() xdist=[] ydist=[] zdist=[] #Initialize interval size and fix iterations to a specific coordinate position xbinleft = -34600.0 ybinleft = -24200.0 zbinleft = 0 #----------PARAMETER FOR MACHINE LEARNING----- iterations =biniter #--------------------------------------------- xlength = int((35600.0+34600.0)/iterations + 0.5) ylength = int((21300.0+24200.0)/iterations + 0.5) zlength = int((22500)/iterations + 0.5) xbinright = xbinleft + xlength ybinright = ybinleft + ylength zbinright = zbinleft + zlength sumdist=0.0 for i in range(0, iterations): for i in range(0, len(xdistance)): if xdistance[i] <= xbinright and xdistance[i] >= xbinleft: sumdist += xdistance[i] xdist.append(sumdist) sumdist=0.0 xbinleft += xlength xbinright += xlength for i in range(0, iterations): for i in range(0, len(ydistance)): if ydistance[i] <= ybinright and ydistance[i] >= ybinleft: sumdist += ydistance[i] ydist.append(sumdist) sumdist=0.0 ybinleft += ylength ybinright += ylength for i in range(0, iterations): for i in range(0, len(zdistance)): if zdistance[i] <= zbinright and zdistance[i] >= zbinleft: sumdist += zdistance[i] zdist.append(sumdist) sumdist=0.0 zbinleft += zlength zbinright += zlength sumdistance=[] sumdistance= [xdist, ydist, zdist] return sumdistance