Getting parent section in Python

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
vellamike

Getting parent section in Python

Post by vellamike » Mon May 16, 2011 9:21 am

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
>>> 

hines
Site Admin
Posts: 1571
Joined: Wed May 18, 2005 3:32 pm

Re: Getting parent section in Python

Post by hines » Mon May 16, 2011 10:12 am

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()


vellamike

Re: Getting parent section in Python

Post by vellamike » Mon May 16, 2011 1:50 pm

Thank you hines! That's exactly what I needed.

Post Reply