neurom.features.neuronfunc

Neuron features.

Any public function from this namespace can be called via features mechanism on a neuron, a neuron population:

>>> import neurom
>>> from neurom import features
>>> nrn = neurom.load_neuron('path/to/neuron')
>>> features.get('soma_surface_area', nrn)
>>> nrn_population = neurom.load_neurons('path/to/neurons')
>>> features.get('sholl_frequency', nrn_population)

Functions

sholl_crossings

Calculate crossings of neurites.

sholl_frequency

Perform Sholl frequency calculations on a population of neurites.

soma_radii

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

soma_surface_area

Get the surface area of a neuron’s soma.

soma_surface_areas

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

soma_volume

Get the volume of a neuron’s soma.

soma_volumes

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

total_length

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

trunk_angles

Calculates the angles between all the trunks of the neuron.

trunk_origin_azimuths

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

trunk_origin_elevations

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

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.

class neurom.features.neuronfunc.COLS[source]

Bases: object

Column labels for internal data representation.

class neurom.features.neuronfunc.NeuriteType(value)[source]

Bases: enum.IntEnum

Type of neurite.

class neurom.features.neuronfunc.Population(files, name='Population', ignored_exceptions=(), cache=False)[source]

Bases: object

Neuron Population Class.

Offers an iterator over neurons within population, neurites of neurons, somas of neurons. It does not store the loaded neuron in memory unless the neuron has been already passed as loaded (instance of Neuron).

Construct a neuron population.

Parameters
  • files (collections.abc.Sequence[str|Path|Neuron]) – collection of neuron files or paths to them or instances of Neuron.

  • name (str) – Optional name for this Population

  • ignored_exceptions (tuple) – NeuroM and MorphIO exceptions that you want to ignore when loading neurons.

  • cache (bool) – whether to cache the loaded neurons in memory. If false then a neuron will be loaded everytime it is accessed within the population. Which is good when population is big. If true then all neurons will be loaded upon the construction and kept in memory.

neurom.features.neuronfunc.is_type(*ref)

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)
neurom.features.neuronfunc.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.features.neuronfunc.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.features.neuronfunc.sholl_crossings(neurites, center, radii, neurite_type=<NeuriteType.all: 32>)[source]

Calculate crossings of neurites. The only function in this module that is not a feature.

Parameters
  • neurites (list) – morphology on which to perform Sholl analysis, or list of neurites

  • center (Point) – center point

  • radii (iterable of floats) – radii for which crossings will be counted

  • neurite_type (NeuriteType) – Type of neurite to use. By default NeuriteType.all is used.

Returns

Array of same length as radii, with a count of the number of crossings for the respective radius

This function can also be used with a list of sections, as follow:

secs = (sec for sec in nm.iter_sections(neuron) if complex_filter(sec))
sholl = nm.features.neuritefunc.sholl_crossings(secs,
                                                center=neuron.soma.center,
                                                radii=np.arange(0, 1000, 100))
neurom.features.neuronfunc.sholl_frequency(nrn, neurite_type=<NeuriteType.all: 32>, step_size=10, bins=None)[source]

Perform Sholl frequency calculations on a population of neurites.

Parameters
  • nrn (morph) – nrn or population

  • neurite_type (NeuriteType) – which neurites to operate on

  • step_size (float) – step size between Sholl radii

  • bins (iterable of floats) – custom binning to use for the Sholl radii. If None, it uses

  • of step_size between min and max radii of nrn. (intervals) –

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.

neurom.features.neuronfunc.soma_radii(nrn_pop, neurite_type=<NeuriteType.soma: 31>)[source]

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.

neurom.features.neuronfunc.soma_surface_area(nrn, neurite_type=<NeuriteType.soma: 31>)[source]

Get the surface area of a neuron’s soma.

Note

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

neurom.features.neuronfunc.soma_surface_areas(nrn_pop, neurite_type=<NeuriteType.soma: 31>)[source]

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.

neurom.features.neuronfunc.soma_volume(nrn)[source]

Get the volume of a neuron’s soma.

neurom.features.neuronfunc.soma_volumes(nrn_pop)[source]

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.

neurom.features.neuronfunc.total_length(nrn_pop, neurite_type=<NeuriteType.all: 32>)[source]

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

neurom.features.neuronfunc.trunk_angles(nrn, neurite_type=<NeuriteType.all: 32>)[source]

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.

neurom.features.neuronfunc.trunk_origin_azimuths(nrn, neurite_type=<NeuriteType.all: 32>)[source]

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

neurom.features.neuronfunc.trunk_origin_elevations(nrn, neurite_type=<NeuriteType.all: 32>)[source]

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

neurom.features.neuronfunc.trunk_origin_radii(nrn, neurite_type=<NeuriteType.all: 32>)[source]

Radii of the trunk sections of neurites in a neuron.

neurom.features.neuronfunc.trunk_section_lengths(nrn, neurite_type=<NeuriteType.all: 32>)[source]

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

neurom.features.neuronfunc.trunk_vectors(nrn, neurite_type=<NeuriteType.all: 32>)[source]

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