how to display 3d coordinates of a segment

 Posts: 8
 Joined: Sun Jun 12, 2005 10:41 am
 Location: University of North Florida
how to display 3d coordinates of a segment
I would like to display the threedimensional coordinates of a position x in a section of a neuron model defined by a pt3d list. The particular model I'm using right now is the layer 2/3 pyramid from Mainen and Sejnowski's patdemo.zip, but I'd like to know how to do it in general. Can x3d, y3d, and z3d be made to do this?
Any help would be appreciated.
Thanks
John Anderson
Any help would be appreciated.
Thanks
John Anderson

 Site Admin
 Posts: 5989
 Joined: Wed May 18, 2005 4:50 pm
 Location: Yale University School of Medicine
 Contact:
Re: how to display 3d coordinates of a segment
Code: Select all
secname for i=0,n3d()1 print i, x3d(i), y3d(i), z3d(i), diam3d(i)

 Posts: 8
 Joined: Sun Jun 12, 2005 10:41 am
 Location: University of North Florida
Re: how to display 3d coordinates of a segment
Thanks for the prompt response. I want to know the xyz coordinates of segment centers.
ja
ja

 Site Admin
 Posts: 5989
 Joined: Wed May 18, 2005 4:50 pm
 Location: Yale University School of Medicine
 Contact:
Re: how to display 3d coordinates of a segment
The meaning of this concept is somewhat ambiguous. A simple operational definition that might be adequate for some applications starts by treating a section as a series of straight line segments whose endpoints are specified by the 3d points. Calculate the "range" (normalized distance from the 0 end) of each of these points. Then the xyz coordinates that correspond to any r in [0,1] can be found by this algorithm:the xyz coordinates of segment centers
Code: Select all
if r corresponds to the range of any 3d point, return the coordinates of that point
otherwise find the pair of 3d points whose line segment contains r, then apply linear interpolation to determine the xyz coordinates of r
http://www.neuron.yale.edu/ftp/ted/neur ... nd_rec.zip
The file interpxyz.hoc contains a procedure that finds the coordinates of internal nodes.

 Posts: 8
 Joined: Sun Jun 12, 2005 10:41 am
 Location: University of North Florida
Re: how to display 3d coordinates of a segment
What are the "nodes" referred to in interpxyz.hoc?

 Site Admin
 Posts: 5989
 Joined: Wed May 18, 2005 4:50 pm
 Location: Yale University School of Medicine
 Contact:
Re: how to display 3d coordinates of a segment
Points in space at which the system equations are solved. The macroscopic physical world appears to be continuous in both space and time, and is described by partial differential equations. In order to compute an approximate solution to these equations, they are first discretized in space to produce a set of ordinary differential equations. Each ODE governs the time course of a state variable at a particular location (node) in space. The approximate solution is then computed by numerical integration of the ODEs over a sequence of discrete instants in time.
Each section has its own discretization parameter nseg, which is a whole number that specifies how many internal nodes will be used to represent it (imagine chopping the section into nseg pieces or "segments" of equal length, and placing a node at the midpoint of each segment). For more information about nseg please see
http://www.neuron.yale.edu/neuron/stati ... .html#nseg
or read Chapters 4 and 5 of The NEURON Book, or
Hines, M.L. and Carnevale, N.T. The NEURON simulation environment. Neural Computation 9:11791209, 1997
which you can download from a link at http://www.neuron.yale.edu/neuron/bib/nrnpubs.html
So far we have been discussing only the internal nodes, at which numerical integration is performed. In addition there are nodes at the 0 and 1 ends; membrane potential at those locations is calculated by simple algebra from the potentials at adjacent internal nodes and the corresponding axial resistances.
Each section has its own discretization parameter nseg, which is a whole number that specifies how many internal nodes will be used to represent it (imagine chopping the section into nseg pieces or "segments" of equal length, and placing a node at the midpoint of each segment). For more information about nseg please see
http://www.neuron.yale.edu/neuron/stati ... .html#nseg
or read Chapters 4 and 5 of The NEURON Book, or
Hines, M.L. and Carnevale, N.T. The NEURON simulation environment. Neural Computation 9:11791209, 1997
which you can download from a link at http://www.neuron.yale.edu/neuron/bib/nrnpubs.html
So far we have been discussing only the internal nodes, at which numerical integration is performed. In addition there are nodes at the 0 and 1 ends; membrane potential at those locations is calculated by simple algebra from the potentials at adjacent internal nodes and the corresponding axial resistances.

 Posts: 8
 Joined: Sun Jun 12, 2005 10:41 am
 Location: University of North Florida
Re: how to display 3d coordinates of a segment
Ah. So the coordinates of the nodes would be the coordinates of the midpoints of the segments, which is what I want.
Thanks very much for your help. I will try to implement that algorithm in my model.
ja
Thanks very much for your help. I will try to implement that algorithm in my model.
ja
Re: how to display 3d coordinates of a segment
In case anybody is interested, I figured out how you can do this in Python:
The output is:
Code: Select all
from neuron import h
dend1 = h.Section()
dend2 = h.Section()
dend3 = h.Section()
h.pt3dadd(0,0,0,1,sec=dend1)
h.pt3dadd(1,0,0,1,sec=dend1)
h.pt3dadd(0,0,0,1,sec=dend3)
h.pt3dadd(0,1,0,1,sec=dend3)
for s in dend1,dend2,dend3:
print ''
print 'Printing coordinates for '+ h.secname(sec=s)
print ''
n3d = int(h.n3d(sec=s))
if n3d == 0:
print ' * No coordinates found * '
continue
for i in range(0,n3d):
print ' i: ' + str(i) + ' '
print 'x: ' + str(h.x3d(i,sec=s))
print 'y: ' + str(h.y3d(i,sec=s))
print 'z: ' + str(h.z3d(i,sec=s))
Code: Select all

Printing coordinates for PySec_0x21aa120

 i: 0 
x: 0.0
y: 0.0
z: 0.0
 i: 1 
x: 1.0
y: 0.0
z: 0.0

Printing coordinates for PySec_0x21aa390

* No coordinates found *

Printing coordinates for PySec_0x21aa3f0

 i: 0 
x: 0.0
y: 0.0
z: 0.0
 i: 1 
x: 0.0
y: 1.0
z: 0.0

 Posts: 11
 Joined: Sat Oct 17, 2020 3:08 pm
Re: how to display 3d coordinates of a segment
I've been trying to do this too. ahwillia, your code returns the n3d coordinates in python, but if you want the ~segment~ coordinates you need to do something a little more complicated. Here's a function that does exactly this for anyone looking for it.
Code: Select all
def returnSegmentCoordinates(section):
# Get section 3d coordinates and put in numpy array
n3d = section.n3d()
x3d = np.empty(n3d)
y3d = np.empty(n3d)
z3d = np.empty(z3d)
L = np.empty(n3d)
for i in range(n3d):
x3d[i]=section.x3d(i)
y3d[i]=section.y3d(i)
z3d[i]=section.z3d(i)
# Compute length of each 3d segment
for i in range(n3d):
if i==0:
L[i]=0
else:
L[i]=np.sqrt((x3d[i]x3d[i1])**2 + (y3d[i]y3d[i1])**2 + (z3d[i]z3d[i1])**2)
# Get cumulative length of 3d segments
cumLength = np.cumsum(L)
N = section.nseg
# Now upsample coordinates to segment locations
xCoord = np.empty(N)
yCoord = np.empty(N)
zCoord = np.empty(N)
dx = section.L / (N1)
for n in range(N):
if n==N1:
xCoord[n]=x3d[1]
yCoord[n]=y3d[1]
zCoord[n]=z3d[1]
else:
cIdxStart = np.where(n*dx >= cumLength)[0][1] # which idx of 3d segments are we starting at
cDistFrom3dStart = n*dx  cumLength[cIdxStart] # how far along that segment is this upsampled coordinate
cFraction3dLength = cDistFrom3dStart / L[cIdxStart+1] # what's the fractional distance along this 3d segment
# compute x and y positions
xCoord[n] = x3d[cIdxStart] + cFraction3dLength*(x3d[cIdxStart+1]  x3d[cIdxStart])
yCoord[n] = y3d[cIdxStart] + cFraction3dLength*(y3d[cIdxStart+1]  y3d[cIdxStart])
zCoord[n] = z3d[cIdxStart] + cFraction3dLength*(z3d[cIdxStart+1]  z3d[cIdxStart])
return xCoord, yCoord, zCoord

 Site Admin
 Posts: 5989
 Joined: Wed May 18, 2005 4:50 pm
 Location: Yale University School of Medicine
 Contact:
Re: how to display 3d coordinates of a segment
One question.
Does your method return the same values as those produced by interpxyz?
Does your method return the same values as those produced by interpxyz?