neurom.view.view

Visualize morphologies.

Functions

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.

class neurom.view.view.COLS[source]

Bases: object

Column labels for internal data representation.

class neurom.view.view.Dendrogram(neurom_section)[source]

Bases: object

Dendrogram.

Dendrogram for NeuroM section tree.

Parameters

neurom_section (Neurite|Neuron|Section) – tree to build dendrogram for.

static get_coords(segment_lengths, segment_radii)[source]

Coordinates of dendrogram as polygon with respect to (0, 0) origin.

Parameters
  • segment_lengths – lengths of dendrogram segments

  • segment_radii – radii of dendrogram segments

Returns

(N,2) array of 2D x,y coordinates of Dendrogram polygon. N is the number of vertices.

class neurom.view.view.NeuriteType(value)[source]

Bases: enum.IntEnum

Type of neurite.

class neurom.view.view.SomaCylinders(morphio_soma)[source]

Bases: neurom.core.soma.Soma

Soma composed of cylinders (like in SWC).

points describe the locations of the cylinder start/end points, with their respective radii, much like how neurites are described:

ex:

             /)
            / o)
    ______ /  )
(|)      ) / /
( o )    o )/
(|)_____ )

Here we have a ‘side-view’, with each ‘o’ representing a point, and the radius is the height of a ‘|’ character, and the ‘)’ try and show the curvature of the cylinger

Note: when, as in the case above, the cylinder center points don’t lie in a line, then the overlap between cylinders isn’t taken into account for the area calculation

Initialize a SomaCyliners object.

neurom.view.view.get_size(positions)[source]

Get the size of bounding rectangle that embodies positions.

Parameters

(dict of Dendrogram (positions) – np.array): positions xy coordinates of dendrograms

Returns

Tuple of width and height of bounding rectangle.

neurom.view.view.iter_neurites(obj, mapfun=None, filt=None, neurite_order=<NeuriteIter.FileOrder: 1>)[source]

Iterator to a neurite, neuron or neuron population.

Applies optional neurite filter and mapping functions.

Parameters
  • obj – a neurite, neuron or neuron population.

  • mapfun – optional neurite mapping function.

  • filt – optional neurite filter function.

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

Examples

Get the number of points in each neurite in a neuron population

>>> from neurom.core.neuron import iter_neurites
>>> n_points = [n for n in iter_neurites(pop, lambda x : len(x.points))]

Get the number of points in each axon in a neuron population

>>> import neurom as nm
>>> from neurom.core.neuron import iter_neurites
>>> filter = lambda n : n.type == nm.AXON
>>> mapping = lambda n : len(n.points)
>>> n_points = [n for n in iter_neurites(pop, mapping, filter)]
neurom.view.view.iter_sections(neurites, iterator_type=<function Section.ipreorder>, neurite_filter=None, neurite_order=<NeuriteIter.FileOrder: 1>)[source]

Iterator to the sections in a neurite, neuron or neuron population.

Parameters
  • neurites – neuron, population, neurite, or iterable containing neurite objects

  • iterator_type – section iteration order within a given neurite. Must be one of: Section.ipreorder: Depth-first pre-order iteration of tree nodes Section.ipostorder: 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_filter – optional top level filter on properties of neurite neurite objects.

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

Examples

Get the number of points in each section of all the axons in a neuron population

>>> import neurom as nm
>>> from neurom.core.neuron import iter_sections
>>> filter = lambda n : n.type == nm.AXON
>>> n_points = [len(s.points) for s in iter_sections(pop,  neurite_filter=filter)]
neurom.view.view.iter_segments(obj, neurite_filter=None, neurite_order=<NeuriteIter.FileOrder: 1>)[source]

Return an iterator to the segments in a collection of neurites.

Parameters
  • obj – neuron, population, neurite, section, or iterable containing neurite objects

  • neurite_filter – optional top level filter on properties of neurite neurite objects

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

Note

This is a convenience function provided for generic access to neuron segments. It may have a performance overhead WRT custom-made segment analysis functions that leverage numpy and section-wise iteration.

neurom.view.view.layout_dendrogram(dendrogram, origin)[source]

Lays out dendrogram as an aesthetical pleasing tree.

Parameters
  • dendrogram (Dendrogram) – dendrogram

  • origin (np.array) – xy coordinates of layout origin

Returns

Dict of positions per each dendrogram node. When placed in those positions, dendrogram nodes will represent a nice tree structure.

neurom.view.view.move_positions(positions, to_origin)[source]

Move positions to a new origin.

Parameters
  • (dict of Dendrogram (positions) – np.array): positions

  • to_origin (np.array) – where to move. np.array of (2,) shape for x,y coordindates.

Returns

Moved positions.

neurom.view.view.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.view.view.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.view.view.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.view.view.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.view.view.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.view.view.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.view.view.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

neurom.view.view.segment_radius(seg)[source]

Return the mean radius of a segment.

Returns: arithmetic mean of the radii of the points in seg

neurom.view.view.tree_type_checker(*ref)[source]

Tree type checker functor.

Parameters
  • *ref (NeuriteType|tuple) – Either a single NeuriteType or a variable list of them or a tuple

  • them. (of) –

Returns

Functor that takes a tree, and returns true if that tree matches any of NeuriteTypes in ref

Ex:
>>> import neurom
>>> from neurom.core.types import NeuriteType, tree_type_checker
>>> from neurom.core.neuron import Section
>>> nrn = neurom.load_neuron('path')
>>>
>>> tree_filter = tree_type_checker(NeuriteType.axon, NeuriteType.basal_dendrite)
>>> nrn.i_neurites(Section.ipreorder, tree_filter=tree_filter)
>>>
>>> tree_filter = tree_type_checker((NeuriteType.axon, NeuriteType.basal_dendrite))
>>> nrn.i_neurites(Section.ipreorder, tree_filter=tree_filter)