navis.longest_neurite¶
- navis.longest_neurite(x, n=1, reroot_soma=False, from_root=True, inverse=False, inplace=False)[source]¶
Return a neuron consisting of only the longest neurite(s).
Based on geodesic distances.
- Parameters:
x (TreeNeuron | NeuronList) – Neuron(s) to prune.
n (int | slice) –
- Number of longest neurites to preserve. For example:
n=1
keeps the longest neuritesn=2
keeps the two longest neuritesn=slice(1, None)
removes the longest neurite
reroot_soma (bool) – If True, neuron will be rerooted to soma.
from_root (bool) – If True, will look for longest neurite from root. If False, will look for the longest neurite between any two tips.
inverse (bool) – If True, will instead remove the longest neurite.
inplace (bool) – If False, copy of the neuron will be trimmed down to longest neurite and returned.
parallel (bool) – If True and input is NeuronList, use parallel processing. Requires pathos.
n_cores (int, optional) – Numbers of cores to use if
parallel=True
. Defaults to half the available cores.progress (bool) – Whether to show a progress bar. Overruled by
navis.set_pbars
.omit_failures (bool) – If True will omit failures instead of raising an exception. Ignored if input is single neuron.
- Returns:
Pruned neuron.
- Return type:
TreeNeuron/List
See also
split_into_fragments()
Split neuron into fragments based on longest neurites.
Examples
>>> import navis >>> n = navis.example_neurons(1) >>> # Keep only the longest neurite >>> ln1 = navis.longest_neurite(n, n=1, reroot_soma=True) >>> # Keep the two longest neurites >>> ln2 = navis.longest_neurite(n, n=2, reroot_soma=True) >>> # Keep everything but the longest neurite >>> ln3 = navis.longest_neurite(n, n=slice(1, None), reroot_soma=True)