"seg in sec" is not the same as "seg in sec.allseg()"

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

Moderator: hines

"seg in sec" is not the same as "seg in sec.allseg()"

Postby vellamike » Fri Dec 10, 2010 1:28 pm

I just realised there is some kind of subtle difference here in that "seg in sec.allseg()" seems to iterate over the edges of the section also, or something like that, I'm still trying to understand it.

so...

Code: Select all
      for seg in sec.allseg():
            seg.diam=seg.diam*coefficient


will produce a different result to
Code: Select all
        for seg in sec:
            seg.diam=seg.diam*coefficient


Can someone explain to me exactly what the difference is here? I thought that each section had X number of segments, each of which could be set.

I think that aside from the nodes at segment centres there are also the nodes at the edges, which are not accessed when using "for seg in sec" but are if "seg in sec.allseg()" is used, is this correct?
vellamike
 
Posts: 41
Joined: Wed Nov 03, 2010 11:30 am
Location: Cambridge

Re: "seg in sec" is not the same as "seg in sec.allseg()"

Postby ted » Fri Dec 10, 2010 9:45 pm

vellamike wrote:
Code: Select all
      for seg in sec.allseg():
            seg.diam=seg.diam*coefficient


will produce a different result to
Code: Select all
        for seg in sec:
            seg.diam=seg.diam*coefficient

Which begs a question . . . can you please provide a specific example using a section that has, say, nseg == 3?
ted
Site Admin
 
Posts: 3589
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

Re: "seg in sec" is not the same as "seg in sec.allseg()"

Postby vellamike » Mon Dec 13, 2010 9:15 am

Sure, so here is some code which changes the diameters of the sections through some basic algorithm and the output of the code. The sections look different when using "for seg in sec" as opposed to "for seg in sec.allseg()":

Code: Select all
from neuron import h

testsection1 = h.Section()
testsection2 = h.Section()

testsection1.nseg=3
testsection2.nseg=3

i=0
j=0

print 'testsection1:'

for seg in testsection1:
   seg.diam=300+i
   i+=20
   print seg.diam

print 'testsection2:'
for seg in testsection2.allseg():
   seg.diam=300+j
   j+=20
   print seg.diam


the output is:

Code: Select all
testsection1:
300.0
320.0
340.0
testsection2:
300.0
320.0
340.0
360.0
380.0


Which seems to imply that section.allseg() means all nodes rather than all segments and produces the same result as for(x) in hoc?
vellamike
 
Posts: 41
Joined: Wed Nov 03, 2010 11:30 am
Location: Cambridge

Re: "seg in sec" is not the same as "seg in sec.allseg()"

Postby ted » Mon Dec 13, 2010 1:13 pm

section.allseg() means all nodes rather than all segments and produces the same result as for(x) in hoc?

True.
for seg in sec
iterates over the internal nodes of sec, i.e. nodes with range >0 and <1, just like hoc's
secname for (x,0)
for seg in sec.allseg()
iterates over all nodes of sec, including the nodes at 0 and 1, just like hoc's
secname for (x)

All that your example needs to prove the point beyond question is to print seg.x as well as seg.diam.

Iterating over all nodes, whether in hoc or Python, can produce identically misleading results, as is the case with your own example:
Code: Select all
testsection2:
300.0
320.0
340.0
360.0
380.0
After exiting the loop, 300 will not be the diam at 0, nor will 360 be the diam at 0.833 (i.e. at the last internal node. Check the diameters with
Code: Select all
for seg in sec.allseg():
    print sec.x, sec.diam
and you will discover that the actual outcome is
Code: Select all
0.0  320.0
0.166...  320.0
0.5  340.0
0.833...  380.0
1.0  380.0
Exactly the same results are generated by the hoc equivalent
Code: Select all
dend for (x) {
  diam(x) = 300+j
  j += 20
  print diam(x)
}
dend for (x) print diam(x)

The rule is that attempting to access a range variable at the 0 or 1 location actually accesses the range variable at the adjacent internal node.
ted
Site Admin
 
Posts: 3589
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

Re: "seg in sec" is not the same as "seg in sec.allseg()"

Postby vellamike » Tue Dec 14, 2010 7:14 am

Thanks for the clarifications!
vellamike
 
Posts: 41
Joined: Wed Nov 03, 2010 11:30 am
Location: Cambridge

Re: "seg in sec" is not the same as "seg in sec.allseg()"

Postby ted » Tue Dec 14, 2010 10:58 pm

Well, you pretty much figured it out. I just wanted to spell out the implications as clearly as possible for anyone else who might read this thread.
ted
Site Admin
 
Posts: 3589
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine


Return to NEURON + Python

Who is online

Users browsing this forum: No registered users and 1 guest