neurom.core

Core functionality and data types of NeuroM.

Functions

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.

make_soma

Make a soma object from a set of points.

Classes

Neurite

Class representing a neurite tree.

NeuriteIter

Neurite iteration orders.

NeuriteType

Enum representing valid tree types.

Neuron

Class representing a simple neuron.

Population

Neuron Population Class.

Section

Class representing a neurite section.

Soma

Base class for a soma.

Tree

Simple recursive tree class.

Exceptions

SomaError

Exception for soma construction errors.

class neurom.core.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.core.NeuriteIter(value)[source]

Bases: neurom.utils.OrderedEnum

Neurite iteration orders.

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

Bases: neurom.utils.OrderedEnum

Enum representing valid tree types.

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

Bases: object

Class representing a simple neuron.

class neurom.core.Population(neurons, name='Population')[source]

Bases: object

Neuron Population Class.

Features:
  • flattened collection of neurites.

  • collection of somas, neurons.

  • iterable-like iteration over neurons.

class neurom.core.Section(points, section_id=None, section_type=<NeuriteType.undefined: 0>)[source]

Bases: neurom.core.tree.Tree

Class representing a neurite section.

class neurom.core.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.

exception neurom.core.SomaError[source]

Bases: neurom.exceptions.NeuroMError

Exception for soma construction errors.

class neurom.core.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.

neurom.core.graft_neuron(root_section)[source]

Returns a neuron starting at root_section.

neurom.core.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.core.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.core.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.core.make_soma(points, soma_check=None, soma_class='contour')[source]

Make a soma object from a set of points.

Infers the soma type (SomaSinglePoint, SomaSimpleContour) from the points and the ‘soma_class’

Parameters
  • points – collection of points forming a soma.

  • soma_check – optional validation function applied to points. Should

  • a SomaError if points not valid. (raise) –

  • soma_class (str) – one of ‘contour’ or ‘cylinder’ to specify the type

Raises
  • SomaError if no soma points found, points incompatible with soma, or

  • if soma_check(points) fails.