## Guidance on plotting cell's geometry in Python?

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

Moderator: hines

dgalt
Posts: 3
Joined: Wed May 11, 2016 11:34 am

### Guidance on plotting cell's geometry in Python?

I would like to generate a visual representation of my model cell's geometry, without relying on the GUI elements provided by neuron (i.e. no h.PlotShape).

I know there are some Python packages that aim to do this, but they far exceed the complexity of what I'm trying to do (which is basically draw what I would get out of h.PlotShape), and require the usage of GUI elements, which I'm trying to avoid.

Besides this line in the Python guide:
Note Matplotlib and Mayavi can also be used to generate 3D pictures of neurons. To use this, use h.allsec() to iterate over all the sections, read their 3D points, and use those to define their geometries.
I have not been able to find any more information on how to get the geometry information for a model cell. When iterating over all the sections using h.allsec(), what method(s) actually return the values for the 3D points? If I can just get the geometry values I can figure it out from there, but I can't seem to figure out how to actually do that.

thanks

ted
Posts: 5725
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

### Re: Guidance on plotting cell's geometry in Python?

Tried looking in the Programmer's Reference?

dgalt
Posts: 3
Joined: Wed May 11, 2016 11:34 am

### Re: Guidance on plotting cell's geometry in Python?

I'm guessing this is the primary section I need: https://www.neuron.yale.edu/neuron/stat ... t=geometry

which I hadn't read through, so I think I'll be able to figure it out from there.

one other question - one reason for my confusion here is that none of these methods are available to the section objects. Rather, each section is passed to h.method(sec=sec) (e.g. h.n3d(sec=sec) if looping over all sec in h.allsec())

This has tripped me up a couple times - i.e. where I expect methods to be associated with the section objects and instead they're accessed through the hoc object (my terminology here might be wrong). Is there some guiding rule as to why this is the case?

ramcdougal
Posts: 205
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

### Re: Guidance on plotting cell's geometry in Python?

where I expect methods to be associated with the section objects and instead they're accessed through the hoc object (my terminology here might be wrong). Is there some guiding rule as to why this is the case?
This is a legacy artifact of NEURON's transition from a HOC-based interface which did not treat sections as objects. If it was a HOC function before, it can still be used via h and specifying the sec= keyword argument.

You will be pleased to know that in the development version of NEURON 7.5, many methods have been migrated into the Section object, including x3d, y3d, z3d, arc3d, diam3d, n3d, and has_membrane.

An added benefit of this is that the return types are more Pythonic: section.has_membrane (analogous to h.ismembrane) returns True or False; section.n3d returns an int instead of a float.

JustasB
Posts: 28
Joined: Tue Dec 08, 2015 8:17 pm
Location: Tempe, AZ, USA
Contact:

### Re: Guidance on plotting cell's geometry in Python?

For anyone else who has a similar need to visualize cell model shape beyond what is available in NEURON, I've made tools that I used for such purpose available online. Consider the following options:
• Use a tool like hoc2swc to convert your cell model to the SWC morphology format. Then you can use any of the SWC viewers to visualize it.
• If you need more control over the final 3D rendered result, you can use a tool like BlenderNEURON to visualize cell/network morphology and activity in Blender. Once in Blender, the model can be saved as video/GIF, exported to VR/AR applications, embedded online, etc...