navis.resample_along_axis¶
- navis.resample_along_axis(x, interval, axis=2, old_nodes='remove', inplace=False)[source]¶
Resample neuron such that nodes lie exactly on given 1d grid.
This function does not simply snap nodes to the closest grid line but instead adds new nodes where edges between existing nodes intersect with the planes defined by the grid.
- Parameters:
x (TreeNeuron | NeuronList) – Neuron(s) to resample.
interval (float | int | str) – Intervals defining a 1-dimensional grid along given axes (see examples). If neuron(s) have .units set, you can also pass a string such as “50 nm”.
axis (0 | 1 | 2) – Along which axes (x/y/z) to resample.
old_nodes ("remove" | "keep" | "snap") –
Existing nodes are unlikely to intersect with the planes as defined by the grid interval. There are three possible ways to deal with them:
”remove” (default) will simply drop old nodes: this guarantees all remaining nodes will lie on a plane
”keep” will keep old nodes without changing them
”snap” will snap those nodes to the closest coordinate on the grid without interpolation
inplace (bool) – If False, will resample and return a copy of the original. If True, will resample input neuron in place.
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:
The resampled neuron(s).
- Return type:
TreeNeuron/List
See also
navis.resample_skeleton()
Resample neuron such that edges between nodes have a given length.
navis.downsample_neuron()
This function reduces the number of nodes instead of resample to certain resolution. Useful if you are just after some simplification e.g. for speeding up your calculations or you want to preserve node IDs.
Examples
Resample neuron such that we have one node in every 40nm slice along z axis
>>> import navis >>> n = navis.example_neurons(1) >>> n.n_nodes 4465 >>> res = navis.resample_along_axis(n, interval='40 nm', ... axis=2, old_nodes='remove') >>> res.n_nodes < n.n_nodes True