Skip to content

Segments

These functions

Breaking neurons into linear segments. This is the same toy skeleton used in the examples below.
Figure 1: Breaking neurons into linear segments. This is the same toy skeleton used in the examples below.

Generate Segments

Generate linear segments maximizing segment lengths.

PARAMETER DESCRIPTION
node_ids
     Array node IDs.

TYPE: (N, ) array

parent_ids
     Array of parent IDs for each node. Root nodes' parents
     must be -1.

TYPE: (N, ) array

weights
     Array of distances for each child -> parent connection.
     If ``None`` all node-to-node distances are set to 1.

TYPE: (N, ) float32 array DEFAULT: None

RETURNS DESCRIPTION
segments

Segments as list of arrays, sorted from longest to shortest. Each segment starts with a leaf and stops with a branch point or root node.

TYPE: list of arrays

Examples:

>>> import navis_fastcore as fastcore
>>> import numpy as np
>>> node_ids = np.arange(7)
>>> parent_ids = np.array([-1, 0, 1, 2, 1, 4, 5])
>>> fastcore.generate_segments(node_ids, parent_ids)
[array([6, 5, 4, 1, 0]), array([3, 2, 1])]

Segment Coordinates

Generate coordinates for linear segments.

This is useful for plotting the skeleton of a neuron.

PARAMETER DESCRIPTION
node_ids
        Array node IDs.

TYPE: (N, ) array

parent_ids
        Array of parent IDs for each node. Root nodes' parents
        must be -1.

TYPE: (N, ) array

coords
        Array of coordinates for each node.

TYPE: (N, 3) array

node_colors
        A color for each node in `node_ids`. If provided, will
        also return a list of colors sorted to match coordinates.

TYPE: (N, ) numpy.ndarray DEFAULT: None

RETURNS DESCRIPTION
seg_coords

TYPE: list of arrays

colors

If node_colors provided will return a copy of it sorted to match seg_coords.

TYPE: list of colors

Examples:

>>> import navis_fastcore as fastcore
>>> import numpy as np
>>> node_ids = np.arange(7)
>>> parent_ids = np.array([-1, 0, 1, 2, 1, 4, 5])
>>> coords = np.random.rand(7, 3)
>>> fastcore.segment_coords(node_ids, parent_ids, coords)
[array([[5.30713899e-01, 8.26450947e-01, 2.46805326e-01],
        [1.54144332e-04, 9.07823578e-01, 3.20199043e-01],
        [6.64580597e-01, 3.23724555e-01, 3.18361918e-01],
        [7.16579499e-01, 8.65568868e-02, 7.15686948e-01],
        [5.94874740e-01, 5.95528161e-01, 8.14234930e-01]]),
array([[0.47814894, 0.84468164, 0.2765942 ],
        [0.21748528, 0.36673489, 0.81449368],
        [0.7165795 , 0.08655689, 0.71568695]])]