Skip to content

Morphology

Functions related to analysing or manipulating neuron morpology.

Calculate synapse flow centrality for this neuron.

Please note that this implementation currently produces slightly different results than the implementation in navis. I'm not sure why that is but the differences seem to be negligible.

PARAMETER DESCRIPTION
node_ids
     Array of int32 node IDs.

TYPE: (N, ) array

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

TYPE: (N, ) array

presynapses
     Array of number of presynapses associated with each node.

TYPE: (N, ) uint32 array

postsynapses
     Array of number of postsynapses associated with each node.

TYPE: (N, ) uint32 array

mode
     The mode to calculate the flow centrality. "centrifugal" will
     calculate the flow from the root to the leaves, "centripetal"
     will calculate the flow from the leaves to the root, and "sum"
     will calculate the sum of both.

TYPE: "centrifugal" | "centripetal" | "sum" DEFAULT: 'sum'

RETURNS DESCRIPTION
cc

Synapse flow centrality for each node.

TYPE: (N, ) uint32 array

Calculcate Strahler Index.

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

method
            Method used to calculate Strahler indices: 'standard'
            will use the method described above; 'greedy' will
            always increase the index at converging branches
            whether these branches have the same index or not.

TYPE: 'standard' | 'greedy' DEFAULT: 'standard'

to_ignore
            List of node IDs to ignore. Must be the FIRST node
            of the branch. Excluded branches will not contribute
            to Strahler index calculations and instead be assigned
            the SI of their parent branch.

TYPE: iterable DEFAULT: None

min_twig_size
            If provided, will ignore twigs with fewer nodes than
            this. Instead, they will be assigned the SI of their
            parent branch.

TYPE: int DEFAULT: None

RETURNS DESCRIPTION
strahler_index

Strahler Index for each node.

TYPE: (N, ) int array

Examples:

>>> import navis_fastcore as fastcore
>>> import numpy as np
>>> node_ids = np.arange(8)
>>> parent_ids = np.array([-1, 0, 1, 2, 1, 4, 5, 5])
>>> fastcore.strahler_index(node_ids, parent_ids)
array([2, 2, 1, 1, 2, 2, 1, 1], dtype=int32)

Prune twigs shorter than a given threshold.

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

threshold
     Twigs shorter than this threshold will be pruned.

TYPE: float

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

mask
     Array of booleans to mask nodes that should not be pruned.
     Importantly, twigs with _any_ masked node will not be pruned.

TYPE: (N, ) bool array DEFAULT: None

RETURNS DESCRIPTION
keep

Node IDs to keep.

TYPE: (M, ) integer array

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.prune_twigs(node_ids, parent_ids, 2)
array([0, 1, 4, 5, 6])
>>> mask = np.array([True, True, True, False, True, True, True])
>>> fastcore.prune_twigs(node_ids, parent_ids, 2, mask=mask)