navis.resample_skeleton¶
- navis.resample_skeleton(x, resample_to, inplace=False, method='linear', skip_errors=True)[source]¶
Resample skeleton(s) to given resolution.
Preserves root, leafs and branchpoints. Soma, connectors and node tags (if present) are mapped onto the closest node in the resampled neuron.
Important
- A few things to keep in mind:
This generates an entirely new set of node IDs! They will be unique within a neuron, but you may encounter duplicates across neurons.
Any non-standard node table columns (e.g. “labels”) will be lost.
Soma(s) will be pinned to the closest node in the resampled neuron.
Also: be aware that high-resolution neurons will use A LOT of memory.
- Parameters:
x (TreeNeuron | NeuronList) – Neuron(s) to resample.
resample_to (int | float | str) – Target sampling resolution, i.e. one node every N units of cable. Note that hitting the exact sampling resolution might not be possible e.g. if a branch is shorter than the target resolution. If neuron(s) have their .units parameter, you can also pass a string such as “1 micron”.
method (str, optional) – See
scipy.interpolate.interp1d
for possible options. By default, we’re using linear interpolation.inplace (bool, optional) – If True, will modify original neuron. If False, a resampled copy is returned.
skip_errors (bool, optional) – If True, will skip errors during interpolation and only print summary.
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:
Downsampled neuron(s).
- Return type:
TreeNeuron/List
Examples
>>> import navis >>> n = navis.example_neurons(1) >>> # Check sampling resolution (nodes/cable) >>> round(n.sampling_resolution) 60 >>> # Resample to 1 micron (example neurons are in 8x8x8nm) >>> n_rs = navis.resample_skeleton(n, ... resample_to=1000 / 8, ... inplace=False) >>> round(n_rs.sampling_resolution) 134
See also
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.
navis.resample_along_axis()
Resample neuron along a single axis such that nodes align with given 1-dimensional grid.