neurom.viewer

Tools to visualize neuron morphological objects.

Examples

>>> from neurom import viewer
>>> nrn = ... # load a neuron
>>> viewer.draw(nrn)                    # 2d plot
>>> viewer.draw(nrn, mode='3d')         # 3d plot
>>> viewer.draw(nrn.neurites[0])        # 2d plot of neurite tree
>>> viewer.draw(nrn, mode='dendrogram') # dendrogram plot

Functions

draw

Draw a morphology object.

Exceptions

InvalidDrawModeError

Exception class to indicate invalid draw mode.

NotDrawableError

Exception class for things that aren’t drawable.

ViewerError

Base class for viewer exceptions.

exception neurom.viewer.InvalidDrawModeError[source]

Bases: neurom.viewer.ViewerError

Exception class to indicate invalid draw mode.

class neurom.viewer.Neurite(root_node)[source]

Bases: object

Class representing a neurite tree.

Constructor.

Parameters

root_node (morphio.Section) – root section

iter_sections(order=<function Section.ipreorder>, neurite_order=<NeuriteIter.FileOrder: 1>)[source]

Iteration over section nodes.

Parameters
  • order – section iteration order within a given neurite. Must be one of: Section.ipreorder: Depth-first pre-order iteration of tree nodes Section.ipreorder: Depth-first post-order iteration of tree nodes Section.iupstream: Iterate from a tree node to the root nodes Section.ibifurcation_point: Iterator to bifurcation points Section.ileaf: Iterator to all leaves of a tree

  • neurite_order – order upon which neurites should be iterated. Values: - NeuriteIter.FileOrder: order of appearance in the file - NeuriteIter.NRN: NRN simulator order: soma -> axon -> basal -> apical

class neurom.viewer.Neuron(filename, name=None)[source]

Bases: morphio._morphio.mut.Morphology

Class representing a simple neuron.

Neuron constructor.

Parameters
  • filename (str|Path) – a filename

  • name (str) – a option neuron name

transform(trans)[source]

Return a copy of this neuron with a 3D transformation applied.

exception neurom.viewer.NotDrawableError[source]

Bases: Exception

Exception class for things that aren’t drawable.

class neurom.viewer.Section(morphio_section)[source]

Bases: object

Simple recursive tree class.

The section constructor.

append_section(section)[source]

Appends a section to the current section object.

Parameters

section (morphio.Section|morphio.mut.Section|Section|morphio.PointLevel) – a section

ibifurcation_point(iter_mode=<function Section.ipreorder>)[source]

Iterator to bifurcation points.

Parameters

iter_mode – iteration mode. Default: ipreorder.

iforking_point(iter_mode=<function Section.ipreorder>)[source]

Iterator to forking points.

Parameters

iter_mode – iteration mode. Default: ipreorder.

ileaf()[source]

Iterator to all leaves of a tree.

ipostorder()[source]

Depth-first post-order iteration of tree nodes.

ipreorder()[source]

Depth-first pre-order iteration of tree nodes.

is_bifurcation_point()[source]

Is tree a bifurcation point?

is_forking_point()[source]

Is this section a forking point?

is_leaf()[source]

Is tree a leaf?

is_root()[source]

Is tree the root node?

iupstream()[source]

Iterate from a tree node to the root nodes.

class neurom.viewer.Soma(morphio_soma)[source]

Bases: object

Base class for a soma.

Holds a list of raw data rows corresponding to soma points and provides iterator access to them.

Constructor.

Parameters

morphio_soma (morphio.Soma) – instance of soma of MorphIO class

iter()[source]

Iterator to soma contents.

exception neurom.viewer.ViewerError[source]

Bases: Exception

Base class for viewer exceptions.

neurom.viewer.draw(obj, mode='2d', **kwargs)[source]

Draw a morphology object.

Parameters
  • obj – morphology object to be drawn (neuron, tree, soma).

  • mode (Optional[str]) – drawing mode (‘2d’, ‘3d’, ‘dendrogram’). Defaults to ‘2d’.

  • **kwargs – keyword arguments for underlying neurom.view.view functions.

Raises
  • InvalidDrawModeError if mode is not valid

  • NotDrawableError if obj is not drawable

  • NotDrawableError if obj type and mode combination is not drawable

Examples

>>> nrn = ... # load a neuron
>>> fig, _ = viewer.draw(nrn)             # 2d plot
>>> fig.show()
>>> fig3d, _ = viewer.draw(nrn, mode='3d') # 3d plot
>>> fig3d.show()
>>> fig, _ = viewer.draw(nrn.neurites[0]) # 2d plot of neurite tree
>>> dend, _ = viewer.draw(nrn, mode='dendrogram')
neurom.viewer.plot_dendrogram(ax, obj, show_diameters=True)[source]

Plots Dendrogram of obj.

Parameters
  • ax – matplotlib axes

  • obj (neurom.Neuron, neurom.Section) – neuron or section

  • show_diameters (bool) – whether to show node diameters or not

neurom.viewer.plot_neuron(ax, nrn, neurite_type=<NeuriteType.all: 32>, plane='xy', soma_outline=True, diameter_scale=1.0, linewidth=1.2, color=None, alpha=0.8, realistic_diameters=False)[source]

Plots a 2D figure of the neuron, that contains a soma and the neurites.

Parameters
  • ax (matplotlib axes) – on what to plot

  • neurite_type (NeuriteType|tuple) – an optional filter on the neurite type

  • nrn (neuron) – neuron to be plotted

  • soma_outline (bool) – should the soma be drawn as an outline

  • plane (str) – Any pair of ‘xyz’

  • diameter_scale (float) – Scale factor multiplied with segment diameters before plotting

  • linewidth (float) – all segments are plotted with this width, but only if diameter_scale=None

  • color (str or None) – Color of plotted values, None corresponds to default choice

  • alpha (float) – Transparency of plotted values

  • realistic_diameters (bool) – scale linewidths with axis data coordinates

neurom.viewer.plot_neuron3d(ax, nrn, neurite_type=<NeuriteType.all: 32>, diameter_scale=1.0, linewidth=1.2, color=None, alpha=0.8)[source]

Generates a figure of the neuron, that contains a soma and a list of trees.

Parameters
  • ax (matplotlib axes) – on what to plot

  • nrn (neuron) – neuron to be plotted

  • neurite_type (NeuriteType) – an optional filter on the neurite type

  • diameter_scale (float) – Scale factor multiplied with segment diameters before plotting

  • linewidth (float) – all segments are plotted with this width, but only if diameter_scale=None

  • color (str or None) – Color of plotted values, None corresponds to default choice

  • alpha (float) – Transparency of plotted values

neurom.viewer.plot_soma(ax, soma, plane='xy', soma_outline=True, linewidth=1.2, color=None, alpha=0.8)[source]

Generates a 2d figure of the soma.

Parameters
  • ax (matplotlib axes) – on what to plot

  • soma (neurom.core.Soma) – plotted soma

  • plane (str) – Any pair of ‘xyz’

  • soma_outline (bool) – should the soma be drawn as an outline

  • linewidth (float) – all segments are plotted with this width, but only if diameter_scale=None

  • color (str or None) – Color of plotted values, None corresponds to default choice

  • alpha (float) – Transparency of plotted values

neurom.viewer.plot_soma3d(ax, soma, color=None, alpha=0.8)[source]

Generates a 3d figure of the soma.

Parameters
  • ax (matplotlib axes) – on what to plot

  • soma (neurom.core.Soma) – plotted soma

  • color (str or None) – Color of plotted values, None corresponds to default choice

  • alpha (float) – Transparency of plotted values

neurom.viewer.plot_tree(ax, tree, plane='xy', diameter_scale=1.0, linewidth=1.2, color=None, alpha=0.8, realistic_diameters=False)[source]

Plots a 2d figure of the tree’s segments.

Parameters
  • ax (matplotlib axes) – on what to plot

  • tree (neurom.core.Section or neurom.core.Neurite) – plotted tree

  • plane (str) – Any pair of ‘xyz’

  • diameter_scale (float) – Scale factor multiplied with segment diameters before plotting

  • linewidth (float) – all segments are plotted with this width, but only if diameter_scale=None

  • color (str or None) – Color of plotted values, None corresponds to default choice

  • alpha (float) – Transparency of plotted values

  • realistic_diameters (bool) – scale linewidths with axis data coordinates

Note

If the tree contains one single point the plot will be empty since no segments can be constructed.

neurom.viewer.plot_tree3d(ax, tree, diameter_scale=1.0, linewidth=1.2, color=None, alpha=0.8)[source]

Generates a figure of the tree in 3d.

If the tree contains one single point the plot will be empty since no segments can be constructed.

Parameters
  • ax (matplotlib axes) – on what to plot

  • tree (neurom.core.Section or neurom.core.Neurite) – plotted tree

  • diameter_scale (float) – Scale factor multiplied with segment diameters before plotting

  • linewidth (float) – all segments are plotted with this width, but only if diameter_scale=None

  • color (str or None) – Color of plotted values, None corresponds to default choice

  • alpha (float) – Transparency of plotted values