neurom

NeuroM neurom morphology analysis package.

Examples

Load a neuron

>>> import neurom as nm
>>> nrn = nm.load_neuron('some/data/path/morph_file.swc')

Obtain some morphometrics using the get function

>>> ap_seg_len = nm.get('segment_lengths', nrn, neurite_type=nm.APICAL_DENDRITE)
>>> ax_sec_len = nm.get('section_lengths', nrn, neurite_type=nm.AXON)

Load neurons from a directory. This loads all SWC, HDF5 or NeuroLucida .asc files it finds and returns a list of neurons

>>> import numpy as np  # For mean value calculation
>>> nrns = nm.load_neurons('some/data/directory')
>>> for nrn in nrns:
...     print 'mean section length', np.mean(nm.get('section_lengths', nrn))

Apply a function to a selection of neurites in a neuron or population. This example gets the number of points in each axon in a neuron population

>>> import neurom as nm
>>> filter = lambda n : n.type == nm.AXON
>>> mapping = lambda n : len(n.points)
>>> n_points = [n for n in nm.iter_neurites(nrns, mapping, filter)]

Functions

get

Obtain a feature from a set of morphology objects.

graft_neuron

Returns a neuron starting at root_section.

iter_neurites

Iterator to a neurite, neuron or neuron population.

iter_sections

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

iter_segments

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

load_neuron

Build section trees from an h5 or swc file.

load_neurons

Create a population object.

Classes

COLS

Column labels for internal data representation.

NeuriteType

Enum representing valid tree types.

Neuron

Class representing a simple neuron.

NeuronLoader

Caching morphology loader.

class neurom.COLS[source]

Bases: object

Column labels for internal data representation.

class neurom.NeuriteType(value)[source]

Bases: neurom.utils.OrderedEnum

Enum representing valid tree types.

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

Bases: object

Class representing a simple neuron.

class neurom.NeuronLoader(directory, file_ext=None, cache_size=None)[source]

Bases: object

Caching morphology loader.

Parameters
  • directory – path to directory with morphology files

  • file_ext – file extension to look for (if not set, will pick any of .swc|.h5|.asc)

  • cache_size – size of LRU cache (if not set, no caching done)

get(name)[source]

Get name morphology data.

neurom.get(feature, obj, **kwargs)[source]

Obtain a feature from a set of morphology objects.

Parameters
  • feature (string) – feature to extract

  • obj – a neuron, population or neurite tree

  • kwargs – parameters to forward to underlying worker functions

Returns

features as a 1D or 2D numpy array.

Features:
Neurite features (neurite, neuron, neuron population):
  • diameter_power_relation:

    Calculate the diameter power relation at a bifurcation point.

    Diameter power relation is defined in https://www.ncbi.nlm.nih.gov/pubmed/18568015

    This quantity gives an indication of how far the branching is from the Rall ratio (when =1).

  • local_bifurcation_angles:

    Get a list of local bifurcation angles in a collection of neurites.

  • neurite_lengths:

    Get the path length per neurite in a collection.

  • neurite_volume_density:

    Get the volume density per neurite.

    The volume density is defined as the ratio of the neurite volume and the volume of the neurite’s enclosing convex hull

  • neurite_volumes:

    Get the volume per neurite in a collection.

  • number_of_bifurcations:

    Number of bifurcation points in a collection of neurites.

  • number_of_forking_points:

    Number of forking points in a collection of neurites.

  • number_of_neurites:

    Number of neurites in a collection of neurites.

  • number_of_sections:

    Number of sections in a collection of neurites.

  • number_of_sections_per_neurite:

    Get the number of sections per neurite in a collection of neurites.

  • number_of_segments:

    Number of sections in a collection of neurites.

  • number_of_terminations:

    Number of leaves points in a collection of neurites.

  • partition:

    Partition at bifurcation points of a collection of neurites.

  • partition_asymmetry:

    Partition asymmetry at bifurcation points of a collection of neurites.

    Variant: length is a different definition, as the absolute difference in downstream path lenghts, relative to the total neurite path length

  • partition_asymmetry_length:

    Partition asymmetry at bifurcation points of a collection of neurites.

    Variant: length is a different definition, as the absolute difference in downstream path lenghts, relative to the total neurite path length

  • partition_pairs:

    Partition pairs at bifurcation points of a collection of neurites.

    Partition pair is defined as the number of bifurcations at the two daughters of the bifurcating section

  • principal_direction_extents:

    Principal direction extent of neurites in neurons.

  • remote_bifurcation_angles:

    Get a list of remote bifurcation angles in a collection of neurites.

  • section_areas:

    Section areas in a collection of neurites.

  • section_bif_branch_orders:

    Bifurcation section branch orders in a collection of neurites.

  • section_bif_lengths:

    Bifurcation section lengths in a collection of neurites.

  • section_bif_radial_distances:

    Get the radial distances of the bifurcation sections for a collection of neurites.

  • section_branch_orders:

    Section branch orders in a collection of neurites.

  • section_end_distances:

    Section end to end distances in a collection of neurites.

  • section_lengths:

    Section lengths in a collection of neurites.

  • section_path_distances:

    Path lengths of a collection of neurites.

  • section_radial_distances:

    Section radial distances in a collection of neurites.

    The iterator_type can be used to select only terminal sections (ileaf) or only bifurcations (ibifurcation_point).

  • section_strahler_orders:

    Inter-segment opening angles in a section.

  • section_taper_rates:

    Diameter taper rates of the sections in a collection of neurites from root to tip.

    Taper rate is defined here as the linear fit along a section. It is expected to be negative for neurons.

  • section_term_branch_orders:

    Termination section branch orders in a collection of neurites.

  • section_term_lengths:

    Termination section lengths in a collection of neurites.

  • section_term_radial_distances:

    Get the radial distances of the termination sections for a collection of neurites.

  • section_tortuosity:

    Section tortuosities in a collection of neurites.

  • section_volumes:

    Section volumes in a collection of neurites.

  • segment_areas:

    Areas of the segments in a collection of neurites.

  • segment_lengths:

    Lengths of the segments in a collection of neurites.

  • segment_meander_angles:

    Inter-segment opening angles in a section.

  • segment_midpoints:

    Return a list of segment mid-points in a collection of neurites.

  • segment_path_lengths:

    Returns pathlengths between all non-root points and their root point.

  • segment_radial_distances:

    Returns the list of distances between all segment mid points and origin.

  • segment_radii:

    Arithmetic mean of the radii of the points in segments in a collection of neurites.

  • segment_taper_rates:

    Diameters taper rates of the segments in a collection of neurites.

    The taper rate is defined as the absolute radii differences divided by length of the section

  • segment_volumes:

    Volumes of the segments in a collection of neurites.

  • sibling_ratio:

    Sibling ratios at bifurcation points of a collection of neurites.

    The sibling ratio is the ratio between the diameters of the smallest and the largest child. It is a real number between 0 and 1. Method argument allows one to consider mean diameters along the child section instead of diameter of the first point.

  • terminal_path_lengths_per_neurite:

    Get the path lengths to each terminal point per neurite in a collection.

  • total_area_per_neurite:

    Surface area in a collection of neurites.

    The area is defined as the sum of the area of the sections.

  • total_length:

    Get the total length of all sections in the group of neurons or neurites.

  • total_length_per_neurite:

    Get the path length per neurite in a collection.

Neuron features (neuron, neuron population):
  • sholl_frequency:

    Perform Sholl frequency calculations on a population of neurites.

    Args:

    nrn(morph): nrn or population neurite_type(NeuriteType): which neurites to operate on step_size(float): step size between Sholl radii

    Note:

    Given a neuron, the soma center is used for the concentric circles, which range from the soma radii, and the maximum radial distance in steps of step_size. When a population is given, the concentric circles range from the smallest soma radius to the largest radial neurite distance. Finally, each segment of the neuron is tested, so a neurite that bends back on itself, and crosses the same Sholl radius will get counted as having crossed multiple times.

  • soma_radii:

    Get the radii of the somata of a population of neurons.

    Note:

    If a single neuron is passed, a single element list with the radius of its soma member is returned.

  • soma_surface_areas:

    Get the surface areas of the somata in a population of neurons.

    Note:

    The surface area is calculated by assuming the soma is spherical.

    Note:

    If a single neuron is passed, a single element list with the surface area of its soma member is returned.

  • soma_volumes:

    Get the volume of the somata in a population of neurons.

    Note:

    If a single neuron is passed, a single element list with the volume of its soma member is returned.

  • trunk_angles:

    Calculates the angles between all the trunks of the neuron.

    The angles are defined on the x-y plane and the trees are sorted from the y axis and anticlock-wise.

  • trunk_origin_azimuths:

    Get a list of all the trunk origin azimuths of a neuron or population.

    The azimuth is defined as Angle between x-axis and the vector defined by (initial tree point - soma center) on the x-z plane.

    The range of the azimuth angle [-pi, pi] radians

  • trunk_origin_elevations:

    Get a list of all the trunk origin elevations of a neuron or population.

    The elevation is defined as the angle between x-axis and the vector defined by (initial tree point - soma center) on the x-y half-plane.

    The range of the elevation angle [-pi/2, pi/2] radians

  • trunk_origin_radii:

    Radii of the trunk sections of neurites in a neuron.

  • trunk_section_lengths:

    List of lengths of trunk sections of neurites in a neuron.

  • trunk_vectors:

    Calculates the vectors between all the trunks of the neuron and the soma center.

neurom.graft_neuron(root_section)[source]

Returns a neuron starting at root_section.

neurom.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.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.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.load_neuron(handle, reader=None)[source]

Build section trees from an h5 or swc file.

neurom.load_neurons(neurons, neuron_loader=<function load_neuron>, name=None, population_class=<class 'neurom.core.population.Population'>, ignored_exceptions=())[source]

Create a population object.

From all morphologies in a directory of from morphologies in a list of file names.

Parameters
  • neurons – directory path or list of neuron file paths

  • neuron_loader – function taking a filename and returning a neuron

  • population_class – class representing populations

  • name (str) – optional name of population. By default ‘Population’ or filepath basename depending on whether neurons is list or directory path respectively.

Returns

neuron population object