navis.downsample_neuron¶
- navis.downsample_neuron(x, downsampling_factor, inplace=False, preserve_nodes=None)[source]¶
Downsample neuron(s) by a given factor.
For skeletons: preserves root, leafs, branchpoints by default. Preservation of nodes with synapses can be toggled - see
preserve_nodes
parameter. Usedownsampling_factor=float('inf')
to get a skeleton consisting only of root, branch and end points.- Parameters:
x (single neuron | NeuronList) – Neuron(s) to downsample. Note that for MeshNeurons we use the first available backend.
downsampling_factor (int | float('inf')) – Factor by which downsample. For TreeNeuron, Dotprops and MeshNeurons this reduces the node, point and face count, respectively. For VoxelNeurons it reduces the dimensions by given factor.
preserve_nodes (str | list, optional) – Can be either list of node IDs to exclude from downsampling or a string to a DataFrame attached to the neuron (e.g. “connectors”). DataFrame must have node_id` column. Only relevant for TreeNeurons.
inplace (bool, optional) – If True, will modify original neuron. If False, we will operate and return o a copy.
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:
Same datatype as input.
- Return type:
TreeNeuron/Dotprops/VoxelNeurons/NeuronList
Examples
>>> import navis >>> n = navis.example_neurons(1) >>> n_ds = navis.downsample_neuron(n, ... downsampling_factor=5, ... inplace=False) >>> n.n_nodes > n_ds.n_nodes True
See also
navis.resample_skeleton()
This function resamples a neuron to given resolution. This will change node IDs!
navis.simplify_mesh()
This is the function used for
MeshNeurons
. Use directly for more control of the simplification.