def get_granules_below(p, glomid):
    bnd_up = misc.Ellipsoid(params.bulbCenter, params.granAxisUp)
    bnd_dw = misc.Ellipsoid(params.bulbCenter, params.granAxisDw)

    p_up = bnd_up.project(p)
    p_dw = bnd_dw.project(p)  #params.glomRealCoords[glomid])

    def get_neighbors(q):
        neighpt = []
        for dx, dy, dz in _gran_voxel:
            neighpt.append((q[0] + dx, q[1] + dy, q[2] + dz))
        return neighpt

    def get_p(x):
        d = params.gran_voxel
        return (int((p_dw[0] + x * (p_up[0] - p_dw[0])) / d) * d,
                int((p_dw[1] + x * (p_up[1] - p_dw[1])) / d) * d,
                int((p_dw[2] + x * (p_up[2] - p_dw[2])) / d) * d)

    pts = set()
    nmoves = 1 + int(misc.distance(p_up, p_dw) / params.gran_voxel)
    x = 0.0
    while x < 1:
        pts.update(get_neighbors(get_p(x)))
        x += 1.0 / nmoves
    return pts
def connect_to_granule(ci, rng, gconnected):
    up = misc.Ellipsoid(params.bulbCenter, params.granAxisUp)
    dw = misc.Ellipsoid(params.bulbCenter, params.granAxisDw)

    gvoxels = list(get_granules_below(ci[-1], mgid2glom(ci[0])))

    def inside_boundary(p):
        return up.normalRadius(p) < 1 and dw.normalRadius(p) >= 1

    def is_proper_type(cgid, gpos):
        gtype = pos2type[gpos]
        if ismitral(cgid):
            return gtype == 0 or gtype == 1
        elif ismtufted(cgid):
            return gtype == 1 or gtype == 2
        return False

    while True:
        # cannot connect
        if len(gvoxels) == 0:
            break

        index = int(rng.discunif(0, len(gvoxels) - 1))
        gpos = gvoxels[index]

        # the voxel is a granule
        if inside_boundary(gpos) and gpos not in gconnected and is_proper_type(
                ci[0], gpos):
            return granules.pos2ggid[gpos], 0, rng.uniform(0, 1), gpos

        del gvoxels[index]

    return None
def gc_is_superficial(ggid):
    p = granules.ggid2pos[ggid]
    # it fix the granule cells type
    up = misc.Ellipsoid(params.bulbCenter, params.granAxisUp)
    dw = misc.Ellipsoid(params.bulbCenter, params.granAxisDw)
    return (dw.normalRadius(p) - 1) / (dw.normalRadius(up.project(p)) -
                                       1) > 0.5
Example #4
0
def initgranules():
    global Ngranule
    global ngranule

    ggid2pos.clear()
    pos2ggid.clear()

    eup = misc.Ellipsoid(params.bulbCenter, params.somaAxis[0])
    edw = misc.Ellipsoid(params.bulbCenter, params.granAxisInf)

    for index in range(params.Nx_granule * params.Ny_granule *
                       params.Nz_granule):
        pos = [0.] * 3
        pos[0] = (
            (index % (params.Nx_granule * params.Ny_granule)) %
            params.Nx_granule) * params.grid_dim + params.granule_origin[0]
        pos[1] = int(
            (index % (params.Nx_granule * params.Ny_granule)) /
            params.Nx_granule) * params.grid_dim + params.granule_origin[1]
        pos[2] = int(index / (params.Nx_granule * params.Ny_granule)
                     ) * params.grid_dim + params.granule_origin[2]

        if eup.normalRadius(pos) < 1. and edw.normalRadius(pos) > 1.:
            pos = tuple(pos)
            ggid = len(ggid2pos) + params.gid_granule_begin

            ggid2pos.update({ggid: pos})
            pos2ggid.update({pos: ggid})

    Ngranule = len(ggid2pos)
    ngranule = Ngranule
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 init():
    from math import exp

    # it fix the granule cells type
    up = misc.Ellipsoid(params.bulbCenter, params.granAxisUp)
    dw = misc.Ellipsoid(params.bulbCenter, params.granAxisDw)

    for p, ggid in granules.pos2ggid.items():

        rng_type = params.ranstream(ggid, params.stream_granule_type)
        if rng_type.uniform(0, 1) < params.gc_type3_prob:
            #    if False:
            gtype = 1
        else:
            prob = (dw.normalRadius(p) - 1) / (dw.normalRadius(up.project(p)) -
                                               1)

            #if rng_type.uniform(0, 1) > prob:
            if prob <= 0.5:
                #      if not gc_is_superficial(ggid):
                gtype = 0  # right type for mitral only
            else:
                gtype = 2  # right type for mid. tufted only
        pos2type.update({p: gtype})

    # initialize the voxel grid to connect segment to granule cells
    d = params.gran_voxel
    ndepth = int(round(params.gran_connect_radius / d))
    old_moves = set([(0, 0, 0)])
    for idepth in range(ndepth):
        new_moves = set()
        for m in old_moves:
            for dx in range(-d, d + 1, d):
                for dy in range(-d, d + 1, d):
                    for dz in range(-d, d + 1, d):
                        p = (m[0] + dx, m[1] + dy, m[2] + dz)
                        new_moves.add(p)
                        _gran_voxel.add(p)
        old_moves = new_moves
Example #7
0
        def _select(self):
            SceneObject._select(self)

            # add apical
            if self.__apic == None:
                if self.gctype == 1:
                    axis = bulbdef.mid_tufted_dw
                else:
                    axis = bulbdef.bulb_axis

                self.__apic = graphmeat.get_line(self.pos, \
                                                 misc.Ellipsoid(bulbdef.bulb_center, axis).project(self.pos)
                                                 )

                self.__apic.property.color = self.selcolor
Example #8
0
        def _select(self):
            self.__soma = graphmeat.get_sphere(self.pos,
                                               bulbdef.gran_voxel / 2.0, 10)
            self.__soma.property.color = self.selcolor

            # add apical
            if self.__apic == None:
                if self.gctype == 1:
                    axis = bulbdef.mid_tufted_dw
                else:
                    axis = bulbdef.bulb_axis

                self.__apic = graphmeat.get_line(self.pos, \
                                                 misc.Ellipsoid(bulbdef.bulb_center, axis).project(self.pos)
                                                 )

                self.__apic.property.color = self.selcolor