コード例 #1
0
ファイル: mayasyn.py プロジェクト: JustasB/Mig3DTest
def ConvertDirection(phi, theta, phir, thetar, transf):
  def mult(m, v):
    u = [ 0 ] * len(m)
    for i in range(len(m)):
      for j in range(len(m[i])):
        u[i] += v[j] * m[i][j]
    return u

  v = Spherical.xyz(1., phi, theta, [ 0 ] * 3)
  if transf:
    Rz = [ [ cos(phir), -sin(phir), 0. ],
    [ sin(phir), cos(phir), 0. ],
    [ 0., 0., 1. ] ]
    Ry = [ [ cos(thetar), 0., sin(thetar) ],
    [ 0., 1., 0. ],
    [ -sin(thetar), 0., cos(thetar) ] ]
    u = mult(Ry, v)
    u = mult(Rz, u)
  else:
    Rz = [ [ cos(-phir), -sin(-phir), 0. ],
    [ sin(-phir), cos(-phir), 0. ],
    [ 0., 0., 1. ] ]
    Ry = [ [ cos(-thetar), 0., sin(-thetar) ],
    [ 0., 1., 0. ],
    [ -sin(-thetar), 0., cos(-thetar) ] ]
    u = mult(Rz, v)
    u = mult(Ry, u)

  _rho, _phi, _theta = Spherical.to(u, [ 0 ] * 3)
  return _phi, _theta
コード例 #2
0
def ConvertDirection(phi, theta, phir, thetar, transf):
    def mult(m, v):
        u = [0] * len(m)
        for i in range(len(m)):
            for j in range(len(m[i])):
                u[i] += v[j] * m[i][j]
        return u

    v = Spherical.xyz(1., phi, theta, [0] * 3)
    if transf:
        Rz = [[cos(phir), -sin(phir), 0.], [sin(phir),
                                            cos(phir), 0.], [0., 0., 1.]]
        Ry = [[cos(thetar), 0., sin(thetar)], [0., 1., 0.],
              [-sin(thetar), 0., cos(thetar)]]
        u = mult(Ry, v)
        u = mult(Rz, u)
    else:
        Rz = [[cos(-phir), -sin(-phir), 0.], [sin(-phir),
                                              cos(-phir), 0.], [0., 0., 1.]]
        Ry = [[cos(-thetar), 0., sin(-thetar)], [0., 1., 0.],
              [-sin(-thetar), 0., cos(-thetar)]]
        u = mult(Rz, v)
        u = mult(Ry, u)

    _rho, _phi, _theta = Spherical.to(u, [0] * 3)
    return _phi, _theta
コード例 #3
0
 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)
コード例 #4
0
def gen_soma_pos(cfg, rng_sm, glompos, gid):
    upbnd = Ellipsoid(params.bulbCenter, cfg.somaAxisUp)
    dwbnd = Ellipsoid(params.bulbCenter, cfg.somaAxisDw)
    if ismitral(gid):
        import mcgrow
        ncell_per_glom = params.Nmitral_per_glom
    else:
        import mtgrow
        ncell_per_glom = params.Nmtufted_per_glom

    glpj_up = upbnd.project(glompos)
    somapos = glpj_up
    base_phi, base_theta = upbnd.toElliptical(glompos)[1:]
    base_phi = pi / 2 - base_phi
    base_theta = pi / 2 - base_theta

    radius = rng_sm.uniform(cfg.GLOM_DIST, cfg.GLOM_DIST)
    phi = (gid%ncell_per_glom)*2*pi/ncell_per_glom + \
          params.ranstream(mgid2glom(gid), stream_soma).uniform(0, 2*pi)

    theta = pi / 2
    absphi, abstheta = convert_direction(phi, theta, base_phi, base_theta)
    p = Spherical.xyz(radius, absphi, abstheta, glpj_up)
    p_up = upbnd.project(p)
    p_dw = dwbnd.project(p)
    x = rng_sm.uniform(0, 1)
    somapos = [
        x * (p_up[0] - p_dw[0]) + p_dw[0], x * (p_up[1] - p_dw[1]) + p_dw[1],
        x * (p_up[2] - p_dw[2]) + p_dw[2]
    ]

    return somapos  #, base_phi, base_theta
コード例 #5
0
    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
コード例 #6
0
def get_trunkcone(b, a):
    phi_base, theta_base = sph.to(a, b)[1:]

    quads = tvtk.CellArray()  #vtk.vtkCellArray()
    points = tvtk.Points()  #vtk.vtkPoints()
    Nface = 3
    for i in range(Nface + 1):
        # rotate
        phi, theta = convdir((i % Nface) * 2 * pi / Nface, pi * 0.5, phi_base,
                             theta_base)

        # generate  new points
        p = tuple(sph.xyz(a[3] * 0.5 * radius_factor, phi, theta, a[:3]))
        q = tuple(sph.xyz(b[3] * 0.5 * radius_factor, phi, theta, b[:3]))

        # insert points
        points.append(p)
        points.append(q)

        if i >= 1:
            # create a face
            quad = tvtk.Quad()
            n = points.number_of_points - 1

            quad.point_ids.set_id(0, n - 3)  # p
            quad.point_ids.set_id(1, n - 2)  # q
            quad.point_ids.set_id(2, n)  # q
            quad.point_ids.set_id(3, n - 1)  # p

            # insert the new face
            quads.insert_next_cell(quad)

    # create the actor
    polydata = tvtk.PolyData(points=points, polys=quads)
    if new_tvtk:
        mapper = tvtk.PolyDataMapper()
        configure_input(mapper, polydata)
    else:
        mapper = tvtk.PolyDataMapper(input=polydata)
    actor = tvtk.Actor(mapper=mapper)
    fig.scene.add_actor(actor)
    return actor
コード例 #7
0
            def bias():
                e = Ellipsoid(bulbCenter, bulbAxis)

                _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])

                if e.normalRadius(self.sec.points[-1][:3]) < e.normalRadius(p):
                    p, _phi, _theta = EllipsoidPression(
                        p, bulbAxis, True, self.cfg.GROW_RESISTANCE)
                    self.phi, self.theta = convert_direction(
                        _phi, _theta, self.basePhi, self.baseTheta, True)
コード例 #8
0
            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
コード例 #9
0
def initGrow(cfg, mid):
    nrn = Neuron()
    extrLs = []

    r = [
          ranstream(mid, stream_dend), \
          ranstream(mid, stream_apic), \
          ranstream(mid, stream_tuft) ]

    glomPos = glomCoord[mgid2glom(mid)]
    somaPos = mk_soma(cfg, ranstream(mid, stream_soma), mid,
                      nrn)  # initialize the

    mk_apic(cfg, somaPos, nrn)

    somaLvl = Ellipsoid(bulbCenter, cfg.somaAxisDw)
    phi_base, theta_base = somaLvl.toElliptical(somaPos)[1:]
    theta_base = pi / 2 - theta_base
    phi_base = pi / 2 - phi_base

    extr = Extreme()
    extr.cfg = cfg
    extr.r = r
    extr.nrn = nrn
    extr.glomPos = glomPos
    extr.sec = nrn.apic[0]

    extr.phi, extr.theta = Spherical.to(glomPos, somaPos)[1:]
    extr.phi, extr.theta = convert_direction(extr.phi, extr.theta, phi_base,
                                             theta_base, True)
    extr.extr_type = Extreme.APICAL
    extr.limit = cfg.APIC_LEN_MAX
    extr.basePhi = phi_base
    extr.baseTheta = theta_base

    extrLs.append(extr)

    rd = r[Extreme.DENDRITE]

    #if ismitral(mid):
    DENDRITES = int(
        rd.negexp(cfg.N_MEAN_DEND - cfg.N_MIN_DEND)) + cfg.N_MIN_DEND
    while DENDRITES > cfg.N_MAX_DEND:
        DENDRITES = int(rd.repick()) + cfg.N_MIN_DEND
    #else:
    #DENDRITES = int(rd.negexp(cfg.N_MEAN_DEND))
    #while DENDRITES < cfg.N_MIN_DEND or DENDRITES > cfg.N_MAX_DEND:
    #  DENDRITES = int(rd.repick())

    if ismitral(mid):
        ncell_per_glom = params.Nmitral_per_glom
        cell_index = (mid - params.gid_mitral_begin) % ncell_per_glom
    elif ismtufted(mid):
        ncell_per_glom = params.Nmtufted_per_glom
        cell_index = (mid - params.gid_mtufted_begin) % ncell_per_glom

    phi_phase = 2 * pi / cfg.N_MEAN_DEND / ncell_per_glom * cell_index

    for i in range(DENDRITES):

        sec, extr = mkDendrite(cfg, r, nrn, 0, nrn.soma[0])
        sec.points = [
            somaPos + [rd.uniform(cfg.diam_min_dend, cfg.diam_min_dend)]
        ]
        nrn.dend.append(sec)
        extr.phi = 2 * pi / DENDRITES * i + phi_phase
        extr.theta = cfg.init_theta
        extr.basePhi = phi_base
        extr.baseTheta = theta_base
        extrLs.append(extr)

    return nrn, extrLs
コード例 #10
0
    def grow(self):
        r = self.r[self.extr_type]

        if self.extr_type == Extreme.APICAL:

            def bias():
                pass
        elif self.extr_type == Extreme.TUFT:

            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)
        else:

            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 bias():
                e = Ellipsoid(bulbCenter, bulbAxis)

                _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])

                if e.normalRadius(self.sec.points[-1][:3]) < e.normalRadius(p):
                    p, _phi, _theta = EllipsoidPression(
                        p, bulbAxis, True, self.cfg.GROW_RESISTANCE)
                    self.phi, self.theta = convert_direction(
                        _phi, _theta, self.basePhi, self.baseTheta, True)

        bias()
        _phi, _theta = convert_direction(self.phi, self.theta, self.basePhi,
                                         self.baseTheta)
        _phi += rng_laplace(r, 0, self.cfg.NS_PHI_B, self.cfg.NS_PHI_MIN,
                            self.cfg.NS_PHI_MAX)
        _theta += rng_laplace(r, 0, self.cfg.NS_THETA_B, self.cfg.NS_THETA_MIN,
                              self.cfg.NS_THETA_MAX)
        p = Spherical.xyz(self.cfg.GRW_WALK_LEN, _phi, _theta,
                          self.sec.points[-1][:3]) + [self.diam()]
        self.__update(p)