navis.distal_to¶
- navis.distal_to(x, a=None, b=None)[source]¶
Check if nodes A are distal to nodes B.
Important
Please note that if node A is not distal to node B, this does not automatically mean it is proximal instead: if nodes are on different branches, they are neither distal nor proximal to one another! To test for this case run a->b and b->a - if both return
False
, nodes are on different branches.Also: if a and b are the same node, this function will return
True
!- Parameters:
x (TreeNeuron) –
a (single node ID | list of node IDs | None, optional) – If no node IDs are provided, will consider all node. Note that for large sets of nodes it might be more efficient to use
navis.geodesic_matrix()
(see examples).b (single node ID | list of node IDs | None, optional) – If no node IDs are provided, will consider all node. Note that for large sets of nodes it might be more efficient to use
navis.geodesic_matrix()
(see examples).
- Return type:
Union
[bool
,DataFrame
]- Returns:
bool – If
a
andb
are single node IDs respectively.pd.DataFrame – If
a
and/orb
are lists of node IDs. Columns and rows (index) represent node IDs. Neuronsa
are rows, neuronsb
are columns.
Examples
>>> import navis >>> # Get a neuron >>> x = navis.example_neurons(1) >>> # Get a random node >>> n = x.nodes.iloc[100].node_id >>> # Check all nodes if they are distal or proximal to that node >>> df = navis.distal_to(x, n) >>> # Get the IDs of the nodes that are distal >>> dist = df.loc[n, df.loc[n]].index.values >>> len(dist) 101
For large neurons and/or large sets of a/b it can be much faster to use geodesic_matrix instead:
>>> import navis >>> import numpy as np >>> x = navis.example_neurons(1) >>> # Get an all-by-all distal_to >>> df = navis.geodesic_matrix(x, weight=None, directed=True) < np.inf >>> # Get distal_to for specific nodes >>> df = navis.geodesic_matrix(x, weight=None, directed=True) < np.inf >>> # Get distal_to for specific nodes >>> a, b = x.nodes.node_id.values[:100], x.nodes.node_id.values[-100:] >>> dist = navis.geodesic_matrix(x, weight=None, directed=True, from_=a) >>> distal_to = dist[b] < np.inf
See also
navis.geodesic_matrix()
Depending on your neuron and how many nodes you’re asking for, this function can be considerably faster! See examples.