Directly accessing segment of Section() object

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

Moderator: hines

Post Reply
bear
Posts: 1
Joined: Fri Jun 15, 2012 12:00 pm

Directly accessing segment of Section() object

Post by bear »

Hi All,

I had a question regarding segment access in a Section() object in python. Considering the following (trivial) minimal example:

Code: Select all

from neuron import h

# create a section
sec = h.Section()

# change nseg
sec.nseg = 3

# iterate and run trivial operation on each segment of sec
for seg in sec:
    print seg

Now given this, a valid operation might be to create a list of segments in 'sec':

Code: Select all

>>> lseg = [seg for seg in sec]
>>> print lseg
[<nrn.Segment object at 0x10b7b04e0>, <nrn.Segment object at 0x10b7b0530>, <nrn.Segment object at 0x10b7b05d0>]
One could access these segs directly now:

Code: Select all

>>> print lseg[0]
<nrn.Segment object at 0x10b7b04e0>
However, I'm wondering if it would be possible to create the __getitem__ property for a Section() object so one could access segments directly:

Code: Select all

>>> sec[0]
<nrn.Segment object at 0x10b7b04e0>
In other words, a Section() object is iterable to access each individual section, but in some cases it might be very useful to access a particular segment directly. Any information or help here would be greatly appreciated!
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Directly accessing segment of Section() object

Post by ted »

In some aspects this is an interesting suggestion, but it runs counter to the entire "range variable" strategy, the main purpose of which was to escape from the pitfalls associated with having to think about particular "compartments" (or "segments"). A big problem with code that tries to refer to a particular segment is that the very existence of that segment depends on the resolution of the spatial grid in the section that contains the segment. Change the resolution of the spatial grid--as one must do in order to evaluate whether spatial discretization is fine enough to achieve the desired solution accuracy--and its segments are either split into multiple pieces, or are swallowed up with one or more neighbors into fewer, bigger pieces. It doesn't seem a good idea to write a model specification that is destroyed by testing the adequacy of temporal discretization; how would it be a good idea to write a model specification that is similarly vulnerable to spatial discretization?

If one's conceptual model includes an unbranched neurite A that contains some region B in which membrane and/or cytoplasm properties are "special" in some way, then instead of representing A with a single section a, it would be a better strategy to represent A with two or three shorter sections a1, b, and a2, in which a1 and a2 correspond to the parts of neurite A that are "ordinary," and b corresponds to the "special" region B. Then the "special" b can be accessed in its entirety without being concerned about how to access a particular segment of a, or whether that segment even exists.
Post Reply