def get_below(p): def get_nears(q): npt = [] for dx, dy, dz in moves: npt.append((q[0] + dx, q[1] + dy, q[2] + dz)) return npt def get_p(x, u): dim = params.grid_dim o = params.granule_origin q = () for i in range(3): q += (int(round((p[i] + x * u[i] - o[i]) / dim) * dim + o[i]), ) return q # scroll the line from points to the center u = misc.versor(params.bulbCenter, p) L = misc.distance(p, params.bulbCenter) dx = L / params.grid_dim nnpts = set() x = 0. while x <= L: q = get_p(x, u) if q not in nnpts: nnpts.update(get_nears(q)) x += dx return nnpts
def Bifurcate(self): r = self.r[self.extr_type] _extrLs = [] if self.extr_type == Extreme.APICAL: if distance(self.sec.points[-1][:3], self.glomPos) != GLOM_RADIUS: pos = getP( distance(self.sec.points[-1][:3], self.glomPos) - GLOM_RADIUS, versor(self.glomPos, self.sec.points[-1][:3]), self.sec.points[-1][:3]) stretchSection(self.sec.points, pos) # orientation respect glomerulus gl_phi, gl_theta = Spherical.to(self.glomPos, self.sec.points[-1][:3])[1:] # make tuft TUFTS = int(r.discunif(self.cfg.N_MIN_TUFT, self.cfg.N_MAX_TUFT)) for i in range(TUFTS): sec = Section() sec.connect(self.nrn.apic[0]) self.nrn.tuft.append(sec) extr = Extreme() extr.sec = sec extr.phi, extr.theta = i * 2 * pi / TUFTS * ( 1 + 0.75 * r.uniform(-0.5 / TUFTS, 0.5 / TUFTS)), pi / 4 extr.basePhi, extr.baseTheta = self.basePhi, self.baseTheta extr.limit = r.uniform(self.cfg.TUFT_MIN_LEN, self.cfg.TUFT_MAX_LEN) extr.extr_type = Extreme.TUFT extr.glomPos = self.glomPos extr.cfg = self.cfg extr.r = self.r extr.nrn = self.nrn _extrLs.append(extr) elif self.extr_type == Extreme.DENDRITE: def get_phi(): phi = r.negexp(self.cfg.BIFURC_PHI_MU) while phi < self.cfg.BIFURC_PHI_MIN or phi > self.cfg.BIFURC_PHI_MAX: phi = r.repick() return phi for i in range(2): sec, extr = mkDendrite(self.cfg, self.r, self.nrn, self.depth + 1, self.sec) self.nrn.dend.append(sec) extr.phi = self.phi + ((-1)**i) * get_phi() extr.theta = self.theta extr.dist = self.dist extr.basePhi = self.basePhi extr.baseTheta = self.baseTheta _extrLs.append(extr) return _extrLs
def get_below(p): def get_nears(q): npt = [] for dx, dy, dz in moves: npt.append((q[0]+dx, q[1]+dy, q[2]+dz)) return npt def get_p(x, u): dim = params.grid_dim o = params.granule_origin q = () for i in range(3): q += (int(round((p[i] + x * u[i] - o[i])/dim)*dim+o[i]),) return q # scroll the line from points to the center u = misc.versor(params.bulbCenter, p) L = misc.distance(p, params.bulbCenter) dx = L / params.grid_dim nnpts = set() x = 0. while x <= L: q = get_p(x, u) if q not in nnpts: nnpts.update(get_nears(q)) x += dx return nnpts
def drawsoma(): pts = self.mitral.soma.points center = misc.centroid(pts) # calc. soma radius radius = 0. for p in pts: radius += misc.distance(p, center) radius /= len(pts) radius *= cone_factor # versor u = tuple( misc.versor(self.mitral.apic.points[0], self.mitral.apic.points[1])) src = tvtk.ConeSource(center=tuple(center[0:3]), radius=radius, height=radius, direction=u, resolution=20) mapper = tvtk.PolyDataMapper(input=src.output) actor = tvtk.Actor(mapper=mapper) fig.scene.add_actor(actor) actor.property.color = self.soma_color return actor
def gpo(ggid): import granules import misc import params p=granules.ggid2pos[ggid] pj=misc.Ellipsoid(params.bulbCenter,params.somaAxis[0]).project(p) u=misc.versor(p,params.bulbCenter) return list(p),u,list(pj)
def bias(): _phi, _theta = convert_direction(self.phi, self.theta, self.basePhi, self.baseTheta) p = Spherical.xyz(self.cfg.GRW_WALK_LEN, _phi, _theta, self.sec.points[-1][:3]) dglom = distance(p, self.glomPos) if dglom > GLOM_RADIUS * 0.9: _phi, _theta = Spherical.to( getP(dglom - GLOM_RADIUS * 0.9, versor(self.glomPos, p), p), self.sec.points[-1][:3])[1:] self.phi, self.theta = convert_direction( _phi, _theta, self.basePhi, self.baseTheta, True)
def fill_soma(sections, elements, cellid): points = [] for sec in sections: points += sec.points center = misc.centroid(points)[:3] radius = 0.0 for p in sec.points: radius += misc.distance(p[:3], center) radius /= len(points) verse = misc.versor(bulbdef.bulb_center, center) o = Soma(center, radius, verse) o.gids.append(cellid) elements.objs.append(o)
def EllipsoidPression(p, axis, up, k): e = Ellipsoid(bulbCenter, axis) h = e.normalRadius(p) q = None _lamb, _phi = e.toElliptical(p)[1:] F = h * k q = [ -F * sin(_lamb) * cos(_phi) + p[0], -F * cos(_lamb) * cos(_phi) + p[1], -F * sin(_phi) + p[2] ] vNew = versor(q, self.sec.points[-1][:3]) _p = getP(self.cfg.GRW_WALK_LEN, vNew, self.sec.points[-1][:3]) _phi, _theta = Spherical.to(_p, self.sec.points[-1][:3])[1:] return _p, _phi, _theta
def drawsoma(): pts = self.mitral.soma.points center = misc.centroid(pts) # calc. soma radius radius = 0. for p in pts: radius += misc.distance(p, center) radius /= len(pts) radius *= cone_factor # versor u = tuple(misc.versor(self.mitral.apic.points[0], self.mitral.apic.points[1])) src = tvtk.ConeSource(center=tuple(center[0:3]), radius=radius, height=radius, direction=u, resolution=20) mapper = tvtk.PolyDataMapper(input=src.output) actor = tvtk.Actor(mapper=mapper) fig.scene.add_actor(actor) actor.property.color = self.soma_color return actor
def granule_voxels(p1, p2): u = misc.versor(p2, p1) def nears(q): nn = [] for dx, dy, dz in moves: nn.append((q[0] + dx, q[1] + dy, q[2] + dz)) return nn def pt(x): p = ( p1[0] + x * u[0], p1[1] + x * u[1], p1[2] + x * u[2]) p = ( int(round((p[0] - params.granule_origin[0]) / params.grid_dim)) * params.grid_dim + params.granule_origin[0], \ int(round((p[1] - params.granule_origin[1]) / params.grid_dim)) * params.grid_dim + params.granule_origin[1], \ int(round((p[2] - params.granule_origin[2]) / params.grid_dim)) * params.grid_dim + params.granule_origin[2]) return p L = misc.distance(p1, p2) dx = L / params.grid_dim visited = set() x = 0. while x <= L: visited.add(pt(x)) x += dx nnpts = set() # near points for q in visited: nnpts.update(nears(q)) # return ggids ggids = set() for q in nnpts: if pos2gid.has_key(q): ggids.add(pos2gid[q]) return list(ggids)
def granule_voxels(p1, p2): u = misc.versor(p2, p1) def nears(q): nn = [] for dx, dy, dz in moves: nn.append((q[0] + dx, q[1] + dy, q[2] + dz)) return nn def pt(x): p = (p1[0] + x * u[0], p1[1] + x * u[1], p1[2] + x * u[2]) p = ( int(round((p[0] - params.granule_origin[0]) / params.grid_dim)) * params.grid_dim + params.granule_origin[0], \ int(round((p[1] - params.granule_origin[1]) / params.grid_dim)) * params.grid_dim + params.granule_origin[1], \ int(round((p[2] - params.granule_origin[2]) / params.grid_dim)) * params.grid_dim + params.granule_origin[2]) return p L = misc.distance(p1, p2) dx = L / params.grid_dim visited = set() x = 0. while x <= L: visited.add(pt(x)) x += dx nnpts = set() # near points for q in visited: nnpts.update(nears(q)) # return ggids ggids = set() for q in nnpts: if pos2gid.has_key(q): ggids.add(pos2gid[q]) return list(ggids)
def granule_position_orientation(gid): from misc import versor, ellipseLineIntersec as eli pos = list(ggid2pos[gid]) u = versor(pos, params.bulbCenter) proj = eli(u, pos, params.bulbCenter, params.somaAxis[1]) return pos, u, proj