Page 1 of 1

Guidance on plotting cell's geometry in Python?

Posted: Fri May 20, 2016 12:02 pm
by dgalt
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

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

Posted: Fri May 20, 2016 1:36 pm
by ted
Tried looking in the Programmer's Reference?

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

Posted: Fri May 20, 2016 2:25 pm
by dgalt
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?

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

Posted: Fri May 20, 2016 2:51 pm
by ramcdougal
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.

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

Posted: Wed Jun 12, 2019 8:43 pm
by JustasB
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...