Page 1 of 1

Getting parent section in Python

Posted: Mon May 16, 2011 9:21 am
by vellamike
I am trying to find a way to get the parent section of a child in Python.

Using the h.parent_section() method (http://www.neuron.yale.edu/neuron/stati ... nt_section) gives me a pointer to the parent (see code example below), but I haven't been able to find in the Programmer's Reference how to point to the corresponding python object from this.

Any help would be appreciated.

Code: Select all

>>> a=h.Section()
>>> b=h.Section()
>>> c=h.Section()
>>> d=h.Section()
>>> c.connect(a)
<nrn.Section object at 0x7f88d8ecb480>
>>> b.connect(c)
<nrn.Section object at 0x7f88d8ecb3f0>
>>> d.connect(a)
<nrn.Section object at 0x7f88d8ecb450>
>>> h.topology()

|-|       PySec_7f88d8ec7e10(0-1)
   `|       PySec_7f88d8ecb480(0-1)
     `|       PySec_7f88d8ecb3f0(0-1)
   `|       PySec_7f88d8ecb450(0-1)

1.0
>>> h.parent_section(sec=b)
22979968.0
>>> 

Re: Getting parent section in Python

Posted: Mon May 16, 2011 10:12 am
by hines
This kind of information is best retreived from a SectionRef

Code: Select all

from neuron import h
h('create soma, dend')
h.dend.connect(h.soma(1))
h.topology()

parent = h.SectionRef(sec=h.dend).parent
print parent.name()
You should also look at the other
http://www.neuron.yale.edu/neuron/stati ... ecref.html
methods; expecially has_parent and trueparent. The parent and trueparent are different
only in circumstances like:

Code: Select all

h('create soma, dend, d')
h.dend.connect(h.soma(1))
h.d.connect(h.dend(0))
h.topology()
h.SectionRef(sec=h.d).parent.name()
h.SectionRef(sec=h.d).trueparent.name()


Re: Getting parent section in Python

Posted: Mon May 16, 2011 1:50 pm
by vellamike
Thank you hines! That's exactly what I needed.