morph_tool

Implementation of the morphology file converter.

class morph_tool.LogLevel

Members:

error

warning

info

debug

property name
exception morph_tool.MorphToolException

MorphTool exception.

class morph_tool.Morphology

Class that gives read access to a Morphology file.

Following RAII, this class is ready to use after the creation and will ensure release of resources upon destruction.

property annotations

Return the annotation object

as_mutable(self: morphio._morphio.Morphology) morphio::mut::Morphology
property cell_family

Return the cell family (neuron or glia)

property connectivity

Return the graph connectivity of the morphology where each section is seen as a node Note: -1 is the soma node

property diameters

Return a vector with all diameters from all sections (soma points are not included)

property endoplasmic_reticulum

Return the endoplasmic reticulum object

iter(self: morphio._morphio.Morphology, iter_type: morphio._morphio.IterType = <IterType.depth_first: 0>) Iterator

Section iterator that runs successively on every neurite

iter_type controls the order of iteration on sections of a given neurite. 2 values can be passed:

  • morphio.IterType.depth_first (default)

  • morphio.IterType.breadth_first

property markers

Return the markers

property mitochondria

Return the mitochondria object

property n_points

Returns the number of points from all sections (soma points are not included)

property perimeters

Return a vector with all perimeters from all sections

property points

Return a vector with all points from all sections (soma points are not included)

property root_sections

Return a vector of all root sections (sections whose parent ID are -1)

section(self: morphio._morphio.Morphology, section_id: int) morphio::Section

Return the Section with the given id.

Throws:

RawDataError if the id is out of range

property section_offsets

Returns a list with offsets to access data of a specific section in the points and diameters arrays.

Example: accessing diameters of n’th section will be located in the Morphology::diameters array from diameters[sectionOffsets(n)] to diameters[sectionOffsets(n+1)-1]

Note: for convenience, the last point of this array is the points() array size so that the above example works also for the last section.

property section_types

Return a vector with the section type of every section

property sections

Return the Section with the given id.

Throws:

RawDataError if the id is out of range

property soma

Return the soma object

property soma_type

Return the soma type

property version

Return the version

morph_tool.apical_point_position(neuron, tuft_percent=20)

Attempt to find the apical point in ‘tufted’ neurons.

Consider a neuron:

    |   /    | Tuft = 20%
    |--/     |
    |   /
    |--/
    |
----.-----

All endpoints in the top ‘tuft_percent’ are found, then their common branch segment, furthest from the soma, is identified.

Using the release from 2012 as the base, apical points were compared from the annotated versions, and using this algorithm. Of 239 morphologies that were annotated, 48 differed in the apical point choice by more than 1um in the y component. Many of the differences were morphologies that shoulnd’t have had apical points in the first place (ie: weren’t pyramidal cells, ex: C050398B-I4).

Parameters:
  • neuron (morphio.Morphology) – a neuron morphology

  • tuft_percent – percentage of the ‘height’ of the apical dendrite that would enclose the tuft, only leaves in this volume are considered as endpoints

Returns:

a point if it is found, or None otherwise

Return type:

neurom.core.dataformat.Point

morph_tool.apical_point_section_segment(neuron, tuft_percent=20)

Find the apical point’s section and segment.

Parameters:
  • neuron (morphio.Morphology) – a morphology

  • tuft_percent – percentage of the ‘height’ of the apical dendrite that would enclose the tuft, only leaves in this volume are considered as endpoints See apical_point_position for more details

Returns:

(NeuroM/MorphIO section ID, point ID) of the apical point. Since NeuroM v2, section ids of NeuroM and MorphIO are the same excluding soma.

Return type:

Tuple

morph_tool.axon_point_section(morph, direction=None, bbox=None, ignore_axis=2)

Estimate axon point as the terminal point of the main axon.

This point is defined as the point for which the sum of the angles with the direction vector is minimal. This corresponds to a main axon being a branch that follows best a straight line in the given direction. More constraints can be added with bbox argument, if incorrect axon is detected.

Parameters:
  • morph (morphio.Morphology) – morphology

  • direction (ndarray) – estimated direction of main axon, if None [0, -1, 0] is used

  • bbox (dict) – bbox of the form {‘x’: [-100, 100], ‘y’: [-500, -400]}

  • ignore_axis (int) – axis to ignore in the angle computation, if None, 3d directions are used

Returns:

MorphIO section ID for which the last point is the axon point

morph_tool.convert(input_file, output_file, recenter=False, nrn_order=False, single_point_soma=False, sanitize=False, ensure_NRN_area=False)

Run the appropriate converter.

Parameters:
  • input_file (str) – path to input file

  • output_file (str) – path to output file

  • recenter (bool) – whether to recenter the morphology based on the

  • soma (center of gravity of the) –

  • nrn_order (bool) – whether to traverse the neuron in the NEURON fashion

  • single_point_soma (bool) – For SWC only

  • sanitize (bool) – whether to sanitize the morphology

  • ensure_NRN_area (bool) – to ensure area is preserved in NEURON from swc point soma

morph_tool.diff(morph1, morph2, rtol=1e-05, atol=1e-08, *, skip_perimeters=False, all_diffs=False)

Returns a DiffResult object that is equivalent to True when morphologies differ.

Additional information about why they differ is stored in DiffResult.info Morphologies with different formats can be compared. Morphologies are considered different if one of the following property differ: - number of root sections - sections type - sections point array - sections diameter array - sections perimeter array - sections number of children The soma are NOT taken into consideration

Parameters:
  • morph1 (str|morphio.Morphology|morphio.mut.Morphology) – a morphology

  • morph2 (str|morphio.Morphology|morphio.mut.Morphology) – a morphology

  • rtol (float) – the relative tolerance used for comparing points (see numpy.isclose help)

  • atol (float) – the absolute tolerance used for comparing points (see numpy.isclose help)

  • skip_perimeters (bool) – do not check the perimeters if set to True

  • all_diffs (bool) – return all differences if set to True

morph_tool.point_to_section_segment(neuron, point, rtol=1e-05, atol=1e-08)

Find section and segment that matches the point.

Only the first point found with the exact same coordinates as the point argument is considered

Parameters:
  • neuron (morphio.Morphology) – neuron object

  • point (point) – value of the point to find in the h5 file

  • rtol (floats) – precision of np.isclose

  • atol (floats) – precision of np.isclose

Returns:

(NeuroM/MorphIO section ID, point ID) of the point the matches the input coordinates. Since NeuroM v2, section ids of NeuroM and MorphIO are the same excluding soma.

Return type:

Tuple