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.

plot_dendrogram

Plots Dendrogram of obj.

plot_neuron

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

plot_neuron3d

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

plot_soma

Generates a 2d figure of the soma.

plot_soma3d

Generates a 3d figure of the soma.

plot_tree

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

plot_tree3d

Generates a figure of the tree in 3d.

Classes

Neurite

Class representing a neurite tree.

Neuron

Class representing a simple neuron.

Soma

Base class for a soma.

Tree

Simple recursive tree class.

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.

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

Iteration over section nodes.

Parameters
  • order – section iteration order within a given neurite. Must be one of: Tree.ipreorder: Depth-first pre-order iteration of tree nodes Tree.ipreorder: Depth-first post-order iteration of tree nodes Tree.iupstream: Iterate from a tree node to the root nodes Tree.ibifurcation_point: Iterator to bifurcation points Tree.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

transform(trans)[source]

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

class neurom.viewer.Neuron(soma=None, neurites=None, sections=None, name='Neuron')[source]

Bases: object

Class representing a simple neuron.

exception neurom.viewer.NotDrawableError[source]

Bases: Exception

Exception class for things that aren’t drawable.

class neurom.viewer.Soma(points)[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.

iter()[source]

Iterator to soma contents.

class neurom.viewer.Tree[source]

Bases: object

Simple recursive tree class.

add_child(tree)[source]

Add a child to the list of this tree’s children.

This tree becomes the added tree’s parent

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

Iterator to bifurcation points. Returns a tree object.

Parameters
  • tree – the tree over which to iterate

  • iter_mode – iteration mode. Default: ipreorder.

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

Iterator to forking points. Returns a tree object.

Parameters
  • tree – the tree over which to iterate

  • 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 tree 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.

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.Tree) – neuron or tree

  • 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) – 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.Tree 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.Tree 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