navis.prune_twigs¶
- navis.prune_twigs(x, size, exact=False, inplace=False, recursive=False)[source]¶
Prune terminal twigs under a given size.
By default this function will simply drop all terminal twigs shorter than
size
. This is very fast but rather stupid: for example, if a twig is just 1 nanometer longer thansize
it will not be touched at all. If you require precision, setexact=True
which will prune exactlysize
off the terminals but is about an order of magnitude slower.- Parameters:
x (TreeNeuron | MeshNeuron | NeuronList) –
size (int | float | str) – Twigs shorter than this will be pruned. If the neuron has its .units set, you can also pass a string including the units, e.g. ‘5 microns’.
exact (bool) – See notes above.
inplace (bool, optional) – If False, pruning is performed on copy of original neuron which is then returned.
recursive (int | bool, optional) – If int will undergo that many rounds of recursive pruning. If True will prune iteratively until no more terminal twigs under the given size are left. Only relevant if
exact=False
.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(s).
- Return type:
TreeNeuron/List
Examples
Simple pruning
>>> import navis >>> n = navis.example_neurons(2) >>> # Prune twigs smaller than 5 microns >>> # (example neuron are in 8x8x8nm units) >>> n_pr = navis.prune_twigs(n, ... size=5000 / 8, ... recursive=float('inf'), ... inplace=False) >>> all(n.n_nodes > n_pr.n_nodes) True
Exact pruning
>>> n = navis.example_neurons(1) >>> # Prune twigs by exactly 5 microns >>> # (example neuron are in 8x8x8nm units) >>> n_pr = navis.prune_twigs(n, ... size=5000 / 8, ... exact=True, ... inplace=False) >>> n.n_nodes > n_pr.n_nodes True
Prune using units
>>> import navis >>> n = navis.example_neurons(1) >>> # Example neurons are in 8x8x8nm units... >>> n.units <Quantity(8, 'nanometer')> >>> # ... therefore we can use units for `size` >>> n_pr = navis.prune_twigs(n, ... size='5 microns', ... inplace=False) >>> n.n_nodes > n_pr.n_nodes True