Page 1 of 1

Accessing segment area

Posted: Tue May 13, 2014 6:53 pm
by sgratiy
How can I access the segment area form Python?

For example, I have a hoc objet L2_PC[0] and the the following does not work

Code: Select all

>>> h.L2_PC[0].dend[14](0.1).area
Traceback (most recent call last):
  File "stdin", line 1, in <module>
AttributeError: 'nrn.Segment' object has no attribute 'area'
I thought this is how the range variable should be accessed in Python

Code: Select all

sec(x).rangevar


What do I do wrong here?
Thanks

Re: Accessing segment area

Posted: Wed May 14, 2014 10:33 am
by ted
area is not a range variable--it is a function. hoc usage is
area(x)
returns area of the segment in the currently accessed section that contains location x.

Try this example (assumes dend is a section with nseg == 5):

Code: Select all

for seg in dend:
  seg.diam = 10*seg.x
Then

Code: Select all

for seg in dend:
  print seg.x, seg.diam, h.area(seg.x)
returns

Code: Select all

0.1 1.0 62.8318530718
0.3 3.0 188.495559215
0.5 5.0 314.159265359
0.7 7.0 439.822971503
0.9 9.0 565.486677646

Re: Accessing segment area

Posted: Thu May 15, 2014 1:02 pm
by sgratiy
it works, thanks.