def density(points): '''scale is the slice thickness if 3D and non cubic then scale''' if size(shape(points)) != 2: print 'error in points dimensions' if shape(points)[1] != 3: if shape(points)[0] != 3: print 'something wrong' return else: #transpose print 'transposing' points = points.T distmat=zeros([size(points ,0), size(points ,0)]); for i in range(0,size(points,0)):# %get euclid dist between all pairs of points for ii in range(0,size(points ,0)): dist = 1/euclid.dist( points[i,0], points[ii,0],\ points[i,1], points[ii,1], \ points[i,2], points[ii,2]); if dist == inf: if i == ii: distmat[i,ii] = 0 else: distmat[i,ii] = 1 else: distmat[i,ii] = dist return distmat
def proximity(points, scale=None): '''scale is the slice thickness if 3D and non cubic then scale''' distmat=zeros([size(points ,0), size(points ,0)]); for i in range(0,size(points,0)):# %get euclid dist between all pairs of points for ii in range(0,size(points ,0)): distmat[i,ii] = 1/euclid.dist( points[i,0], points[ii,0],\ points[i,1], points[ii,1], \ points[i,2], points[ii,2]); return distmat
def sphere(location, gridsize, spacing): # , radius): """make 3d sphere grid with given location of center, gridsize, spacing, and radius g = grid.sphere(array([1,1,1]),12,.5) makes a grid (g) centered around location 1,1,1 of size 12, with a spacing of 1""" radius = (gridsize * spacing) / 2.0 cgrid = cube(location, gridsize, spacing) print cgrid.shape, location e = np.zeros(np.size(cgrid, 1)) g = np.copy(e) for i in range(0, np.size(cgrid, 1)): # e[:,i] = euclid.dist(location[0],cgrid[0][i],location[1],cgrid[1][i],location[2],cgrid[2][i]) e[i] = euclid.dist(location, cgrid[:, i]) # e = e*10 print "diameter", e.max(), "mm" sgrid = cgrid[:, e < radius].reshape([3, np.size(cgrid[:, e < radius]) / 3]) # cgrid[e > radius].reshape([3,np.size(cgrid[e > radius])/3]) == 0 return sgrid # ,cgrid
import math from gui.wx import file fn = file.open() from pdf2py import pdf p = pdf.read(fn[0]) p.data.setchannels('meg') p.data.getdata(0,p.data.pnts_in_file) p.data.channels.getposition() #chA1pos = p.data.channels.chlpos[0] centofsphere = array([0,0,.04]) #center of sphere chlpos_ = p.data.channels.chlpos - centofsphere chupos_ = p.data.channels.chupos - centofsphere from meg import euclid #Din = euclid.dist(centofsphere, p.data.channels.chlpos) Din = euclid.dist(array([0,0,0]), chlpos_) chmin = Din.argmin(); r_min = Din.min() #Dout = euclid.dist(centofsphere, p.data.channels.chupos) Dout = euclid.dist(array([0,0,0]), chupos_) chmax = Dout.argmax(); r_max = Dout.max() #x = chA1pos[0]; y = chA1pos[1]; z=chA1pos[2] #r = sqrt((x**2)+(y**2)+(z**2)) x = chlpos_[chmin][0]; y = chlpos_[chmin][1]; z=chlpos_[chmin][2] phi = math.atan2(z, sqrt(x**2 + y**2)); #phi = arccos(z/r) theta = math.atan2(y,x) def cart2sph(chpos): x = chpos[0]; y = chpos[1]; z=chpos[2] r = sqrt((x**2)+(y**2)+(z**2)) phi = math.atan2(z, sqrt(x**2 + y**2)); #phi = arccos(z/r)