Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for new 3d styles, like soma outlines)
.. warning::
This assumes a 3d style exists. The safest way to call this is to call
h.define_shape() first
"""
# TODO: fix the issue described in the warning
# (when this was written, these objects were only under development)
n3d = int(h.n3d(sec=sec))
length = sec.L
arc3d = [h.arc3d(i, sec=sec) for i in range(n3d)]
x3d = numpy.array([h.x3d(i, sec=sec) for i in range(n3d)])
y3d = numpy.array([h.y3d(i, sec=sec) for i in range(n3d)])
z3d = numpy.array([h.z3d(i, sec=sec) for i in range(n3d)])
diam3d = numpy.array([h.diam3d(i, sec=sec) for i in range(n3d)])
dx = length / sec.nseg
objs = {}
for i in range(sec.nseg):
x_lo = i * dx
x_hi = (i + 1) * dx
pts = [x_lo] + _values_strictly_between(x_lo, x_hi, arc3d) + [x_hi]
local_x3d = numpy.interp(pts, arc3d, x3d)
local_y3d = numpy.interp(pts, arc3d, y3d)
local_z3d = numpy.interp(pts, arc3d, z3d)
local_diam3d = numpy.interp(pts, arc3d, diam3d)
local_objs = []
for j in range(len(pts) - 1):
x0, y0, z0, r0 = local_x3d[j], local_y3d[j], local_z3d[j], local_diam3d[j] / 2.
secDir = dir(sec)
for geomParam in standardGeomParams:
#if geomParam in secDir:
try:
secDic[secName]['geom'][geomParam] = sec.__getattribute__(geomParam)
except:
pass
# store 3d geometry
sec.push() # access current section so ismembrane() works
numPoints = int(h.n3d())
if numPoints:
points = []
for ipoint in range(numPoints):
x = h.x3d(ipoint)
y = h.y3d(ipoint)
z = h.z3d(ipoint)
diam = h.diam3d(ipoint)
points.append((x, y, z, diam))
secDic[secName]['geom']['pt3d'] = points
# store mechanisms
#varList = mechVarList() # list of properties for all density mechanisms and point processes
ignoreMechs = ['dist'] # dist only used during cell creation
ignoreVars = [] #
mechDic = {}
ionDic = {}
for mech in dir(sec(0.5)):
if h.ismembrane(mech) and mech not in ignoreMechs: # check if membrane mechanism
if not mech.endswith('_ion'): # exclude ions
mechDic[mech] = {} # create dic for mechanism properties
def retrieve_coordinate(self, sec):
"""Retrieve the coordinates of the section"""
coords = {}
sec.push()
coords['x0'] = h.x3d((h.n3d()- h.n3d()))
coords['x1'] = h.x3d((h.n3d()- 1))
coords['y0'] = h.y3d((h.n3d()- h.n3d()))
coords['y1'] = h.y3d((h.n3d()- 1))
coords['z0'] = h.z3d((h.n3d()- h.n3d()))
coords['z1'] = h.z3d((h.n3d()- 1))
h.pop_section()
return coords
p0 = np.zeros((3, nseg)) # hold the coordinates of segment starting points
p1 = np.zeros((3, nseg)) # hold the coordinates of segment end points
d0 = np.zeros(nseg)
d1 = np.zeros(nseg)
for sec in list(cell.secs.values()):
hSec = sec['hSec']
hSec.push()
n3d = int(h.n3d()) # get number of n3d points in each section
p3d = np.zeros((3, n3d)) # to hold locations of 3D morphology for the current section
l3d = np.zeros(n3d) # to hold locations of 3D morphology for the current section
diam3d = np.zeros(n3d) # to diameters
for i in range(n3d):
p3d[0, i] = h.x3d(i) - p3dsoma[0]
p3d[1, i] = h.y3d(i) - p3dsoma[1] # shift coordinates such to place soma at the origin.
p3d[2, i] = h.z3d(i) - p3dsoma[2]
diam3d[i] = h.diam3d(i)
l3d[i] = h.arc3d(i)
l3d /= hSec.L # normalize
nseg = hSec.nseg
l0 = np.zeros(nseg) # keep range of segment starting point
l1 = np.zeros(nseg) # keep range of segment ending point
for iseg, seg in enumerate(hSec):
l0[iseg] = seg.x - 0.5*1/nseg # x (normalized distance along the section) for the beginning of the segment
l1[iseg] = seg.x + 0.5*1/nseg # x for the end of the segment
p0[0, ix:ix+nseg] = np.interp(l0, l3d, p3d[0, :])
p0[1, ix:ix+nseg] = np.interp(l0, l3d, p3d[1, :])
def _posFromLoc(self, sec, x):
sec.push()
s = x * sec.L
numpts = int(h.n3d())
b = -1
for ii in range(numpts):
if h.arc3d(ii) >= s:
b = ii
break
if b == -1: print("an error occurred in pointFromLoc, SOMETHING IS NOT RIGHT")
if h.arc3d(b) == s: # shortcut
x, y, z = h.x3d(b), h.y3d(b), h.z3d(b)
else: # need to interpolate
a = b-1
t = (s - h.arc3d(a)) / (h.arc3d(b) - h.arc3d(a))
x = h.x3d(a) + t * (h.x3d(b) - h.x3d(a))
y = h.y3d(a) + t * (h.y3d(b) - h.y3d(a))
z = h.z3d(a) + t * (h.z3d(b) - h.z3d(a))
h.pop_section()
return x, y, z
def retrieve_coordinate(self, sec):
"""Retrieve the coordinates of the section"""
coords = {}
sec.push()
coords['x0'] = h.x3d((h.n3d()- h.n3d()))
coords['x1'] = h.x3d((h.n3d()- 1))
coords['y0'] = h.y3d((h.n3d()- h.n3d()))
coords['y1'] = h.y3d((h.n3d()- 1))
coords['z0'] = h.z3d((h.n3d()- h.n3d()))
coords['z1'] = h.z3d((h.n3d()- 1))
h.pop_section()
return coords
for geomParam in standardGeomParams:
# if geomParam in secDir:
try:
secDic[secName]['geom'][
geomParam] = sec.__getattribute__(geomParam)
except:
pass
# store 3d geometry
sec.push() # access current section so ismembrane() works
numPoints = int(h.n3d())
if numPoints:
points = []
for ipoint in range(numPoints):
x = h.x3d(ipoint)
y = h.y3d(ipoint)
z = h.z3d(ipoint)
diam = h.diam3d(ipoint)
points.append((x, y, z, diam))
secDic[secName]['geom']['pt3d'] = points
# store mechanisms
# list of properties for all density mechanisms and point processes
varList = mechVarList()
ignoreMechs = ['dist'] # dist only used during cell creation
ignoreVars = [] #
mechDic = {}
ionDic = {}
for mech in dir(sec(0.5)):
if h.ismembrane(mech) and mech not in ignoreMechs: # check if membrane mechanism
if not mech.endswith('_ion'): # exclude ions