Wrong behavior of h.parent_connection()

Suggestions for improvements to the NEURON Forum.
Post Reply
ziemek
Posts: 45
Joined: Thu May 23, 2019 8:02 am
Location: Warsaw, Poland
Contact:

Wrong behavior of h.parent_connection()

Post by ziemek »

The function h.parent_connection() has wrong description and behavior:

Code: Select all

child.connect(parent(0.7), 0.0)

h.parent_connection(child)
# returns 0.0

child.parentseg().x
# returns 0.7
Reference description of h.parent_connection() indeed points to the y value, however from the description you may expect that it returns x value.

The link to the reference:
https://www.neuron.yale.edu/neuron/stat ... connection
ted
Site Admin
Posts: 6287
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Wrong behavior of h.parent_connection()

Post by ted »

h.parent_connection() is doing exactly what it should do.

The example in the documentation syntax is

y = h.parent_connection(sec=child)

not

y = h.parent_connection(child)

The "sec=" part of the argument is not optional or a suggestion--it is necessary. If you leave it out, NEURON defaults to using the currently accessed section, which is parent. If parent has no parent section, the returned value will be 0.0 (parent's root node).

Consider this example:

Code: Select all

from neuron import h
parent = h.Section(name='parent')
child0 = h.Section(name='child0')
child1 = h.Section(name='child1')
parent.nseg = 5
child0.connect(parent(0.1), 0.0)
child1.connect(parent(0.9), 1.0)
h.topology()
The result confirms the sites to which child0 and child1 are attached

Code: Select all

|-----|       parent(0-1)
      `|       child1(1-0)
  `|       child0(0-1)
And parent_connection, called properly, returns the correct values.

Code: Select all

>>> h.parent_connection(sec = child0)
0.1
>>> h.parent_connection(sec = child1)
0.9
With regart to h.parent_connection, ramcdougal points out that
we should explicitly advise against using h.parent_connection in Python, as sec.parentseg() and sec.trueparentseg() are more useful.
And he's right.

With regard to the use of "sec=" in arguments, he points out that
things that work on a Section in HOC generally need to have sec= specified… You cannot in general drop the sec= and pass it as a positional argument, although a number of functions have been modified to allow that.
Fortunately,
with an extremely small set of exceptions having to do with thread identification (e.g. Vector.record, NetCon), everything that works on a Section has an equivalent Section method in Python, so besides the above there should be no need to ever use the functions that need a sec=
Post Reply