neurom.view.view¶
Visualize morphologies.
Functions
Get the size of bounding rectangle that embodies positions. |
|
Iterator to a neurite, neuron or neuron population. |
|
Iterator to the sections in a neurite, neuron or neuron population. |
|
Return an iterator to the segments in a collection of neurites. |
|
Lays out dendrogram as an aesthetical pleasing tree. |
|
Move positions to a new origin. |
|
Plots Dendrogram of obj. |
|
Plots a 2D figure of the neuron, that contains a soma and the neurites. |
|
Generates a figure of the neuron, that contains a soma and a list of trees. |
|
Generates a 2d figure of the soma. |
|
Generates a 3d figure of the soma. |
|
Plots a 2d figure of the tree’s segments. |
|
Generates a figure of the tree in 3d. |
|
Return the mean radius of a segment. |
|
Tree type checker functor. |
Classes
Column labels for internal data representation. |
|
Dendrogram. |
|
Enum representing valid tree types. |
|
Soma composed of cylinders (like in SWC). |
-
class
neurom.view.view.
Dendrogram
(neurom_section)[source]¶ Bases:
object
Dendrogram.
-
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.
-
static
-
class
neurom.view.view.
NeuriteType
(value)[source]¶ Bases:
neurom.utils.OrderedEnum
Enum representing valid tree types.
-
class
neurom.view.view.
SomaCylinders
(points)[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
-
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 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 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 Tree.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: Tree.ipreorder: Depth-first pre-order iteration of tree nodes Tree.ipostorder: 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_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 import ites_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.Tree) – neuron or tree
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) – 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.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.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.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
-
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.
- Returns
Functor that takes a tree, and returns true if that tree matches any of NeuriteTypes in ref
- Ex:
>>> from neurom.core.types import NeuriteType, tree_type_checker >>> tree_filter = tree_type_checker(NeuriteType.axon, NeuriteType.basal_dendrite) >>> nrn.i_neurites(tree.isegment, tree_filter=tree_filter)