Morphology¶
Functions related to analysing or manipulating neuron morphology.
navis_fastcore.classify_nodes(node_ids, parent_ids)
¶
Classify nodes.
| PARAMETER | DESCRIPTION |
|---|---|
node_ids
|
TYPE:
|
parent_ids
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
node_type
|
Node types: - 0: root - 1: leaf - 2: branch point - 3: slab (intermediate node)
TYPE:
|
Examples:
navis_fastcore.synapse_flow_centrality(node_ids, parent_ids, presynapses, postsynapses, mode='sum')
¶
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
|
TYPE:
|
parent_ids
|
TYPE:
|
presynapses
|
TYPE:
|
postsynapses
|
TYPE:
|
mode
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
cc
|
Synapse flow centrality for each node.
TYPE:
|
navis_fastcore.strahler_index(node_ids, parent_ids, method='standard', to_ignore=None, min_twig_size=None)
¶
Calculcate Strahler Index.
| PARAMETER | DESCRIPTION |
|---|---|
node_ids
|
TYPE:
|
parent_ids
|
TYPE:
|
method
|
TYPE:
|
to_ignore
|
TYPE:
|
min_twig_size
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
strahler_index
|
Strahler Index for each node.
TYPE:
|
Examples:
navis_fastcore.subtree_height(node_ids, parent_ids, weights=None)
¶
Calculate the height of the subtree below each node.
A node's height is the geodesic distance from it down to the farthest leaf below it. Leafs therefore have a height of 0, and a root has the length of the longest root-to-leaf path in its component.
| PARAMETER | DESCRIPTION |
|---|---|
node_ids
|
TYPE:
|
parent_ids
|
TYPE:
|
weights
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
heights
|
Height of each node, in the same order as
TYPE:
|
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.subtree_height(node_ids, parent_ids)
array([4., 3., 1., 0., 2., 1., 0., 0.], dtype=float32)
See Also
:func:geodesic_farthest
Answers a different question: its directed mode looks towards
the root, and its undirected mode can leave the subtree entirely.
navis_fastcore.prune_twigs(node_ids, parent_ids, threshold, weights=None, mask=None)
¶
Prune twigs shorter than a given threshold.
| PARAMETER | DESCRIPTION |
|---|---|
node_ids
|
TYPE:
|
parent_ids
|
TYPE:
|
threshold
|
TYPE:
|
weights
|
TYPE:
|
mask
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
keep
|
Node IDs to keep.
TYPE:
|
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)
array([0, 1, 2, 3, 4, 5, 6])
navis_fastcore.betweenness(node_ids, parent_ids, directed=True)
¶
Calculate betweenness centrality.
| PARAMETER | DESCRIPTION |
|---|---|
node_ids
|
TYPE:
|
parent_ids
|
TYPE:
|
directed
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
betweenness
|
Number of shortest paths through each node, aligned with
TYPE:
|
Notes
O(N), not Brandes' O(VE): shortest paths in a tree are unique*, so the number passing through a node is a closed form rather than a search. Directed, a node lies on one path per (strict descendant, strict ancestor) pair. Undirected, removing it splits its component into its children's sub-trees plus everything above, and it lies between every pair drawn from two different parts.
Counts are int64 because they grow as the square of the component size - an
undirected 100k-node skeleton reaches ~5e9, which overflows int32.
Examples:
>>> import navis_fastcore as fastcore
>>> import numpy as np
>>> node_ids = np.arange(5)
>>> parent_ids = np.array([-1, 0, 1, 2, 3])
>>> fastcore.betweenness(node_ids, parent_ids)
array([0, 3, 4, 3, 0])
Leafs and roots are never between anything.
See Also
navis_fastcore.descendant_counts
What you want if you are counting how much hangs below a node
rather than how much routes through it.
navis_fastcore.descendant_counts(node_ids, parent_ids, targets=None)
¶
Count, for each node, how many nodes lie strictly below it.
| PARAMETER | DESCRIPTION |
|---|---|
node_ids
|
TYPE:
|
parent_ids
|
TYPE:
|
targets
|
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
counts
|
Aligned with
TYPE:
|
Notes
With targets=None this is each node's sub-tree size minus one.
This is what navis' betweeness_centrality(from_=...) actually computed,
under a name that suggested otherwise - see
navis_fastcore.betweenness.
Examples:
>>> import navis_fastcore as fastcore
>>> import numpy as np
>>> node_ids = np.arange(5)
>>> parent_ids = np.array([-1, 0, 1, 2, 1])
>>> fastcore.descendant_counts(node_ids, parent_ids)
array([4, 3, 1, 0, 0])
Counting only the leafs below each node: