crantpy.viz.skeletonize module#
Neuron skeletonization tools.
This module offers optional suppression of urllib3 connection pool warnings that can appear when downloading mesh data during skeletonization. These specific messages are cosmetic and do not affect functionality, but can be noisy. Suppression is opt-in via a function call or the environment variable “CRANTPY_SUPPRESS_URLLIB3_WARNINGS”.
- crantpy.viz.skeletonize.chunks_to_nm(xyz_ch, vol, voxel_resolution=[4, 4, 40])[source]#
Map a chunk location to Euclidean space. CV workaround Implemented here after Giacomo’s suggestion
- Parameters:
xyz_ch (array-like) – (N, 3) array of chunk indices.
vol (cloudvolume.CloudVolume) – CloudVolume object associated with the chunked space.
voxel_resolution (list, optional) – Voxel resolution.
- Returns:
(N, 3) array of spatial points.
- Return type:
np.array
- crantpy.viz.skeletonize.configure_urllib3_warning_suppression(enable=None)[source]#
Enable suppression of known cosmetic urllib3 warnings.
Trade-offs: Hiding warnings can make it harder to notice real connectivity issues. When enabled, only the specific connection pool message is filtered; other warnings remain visible. Does not call urllib3.disable_warnings().
Control via enable or environment variable CRANTPY_SUPPRESS_URLLIB3_WARNINGS.
Returns True if suppression is enabled, False otherwise.
- crantpy.viz.skeletonize.detect_soma_mesh(mesh)[source]#
Try detecting the soma based on vertex clusters.
Identifies dense vertex clusters that likely represent the soma.
- Parameters:
mesh (trimesh.Trimesh) – Coordinates in nanometers. Mesh must not be downsampled for accurate detection.
- Returns:
Array of vertex indices that belong to the detected soma region. Returns empty array if no soma is detected.
- Return type:
np.ndarray
- crantpy.viz.skeletonize.detect_soma_skeleton(s, min_rad=800, N=3)[source]#
Try detecting the soma based on radii.
Looks for consecutive nodes with large radii to identify soma. Includes additional checks to ensure the skeleton is valid.
- Parameters:
- Returns:
Node ID of the detected soma, or None if no soma found.
- Return type:
int or None
- crantpy.viz.skeletonize.divide_local_neighbourhood(mesh, radius)[source]#
Divide the mesh into locally connected patches of a given size (overlapping).
- crantpy.viz.skeletonize.get_skeletons(root_ids, dataset='latest', progress=True, omit_failures=None, max_threads=6, **kwargs)[source]#
Fetch skeletons for multiple neurons.
Tries to get precomputed skeletons first, then falls back to on-demand skeletonization if needed. if id more than one root_id, it will use the parallel skeletonization function.
- Parameters:
root_ids (list of int or np.ndarray) – Root IDs of neurons to fetch skeletons for.
dataset (str, default 'latest') – Dataset to query against.
progress (bool, default True) – Show progress during fetching.
omit_failures (bool, optional) – None: raise exception on failures True: skip failed neurons False: return empty TreeNeuron for failed cases
max_threads (int, default 6) – Number of parallel threads for fetching skeletons.
**kwargs – Additional arguments passed to skeletonization if needed.
- Returns:
List of successfully fetched/generated skeletons.
- Return type:
navis.NeuronList
- crantpy.viz.skeletonize.get_soma_from_annotations(root_id, client, dataset=None)[source]#
Try to get soma location from nucleus annotations.
- Parameters:
- Returns:
(x, y, z) coordinates of the soma in nanometers, or None if not found.
- Return type:
tuple or None
- crantpy.viz.skeletonize.skeletonize_neuron(client, root_id, shave_skeleton=True, remove_soma_hairball=False, assert_id_match=False, threads=2, save_to=None, progress=True, use_pcg_skel=False, **kwargs)[source]#
Skeletonize a neuron the main function.
- Parameters:
client (CAVEclient) – CAVE client for data access.
root_id (int) – Root ID of the neuron to skeletonize.
shave_skeleton (bool, default True) – Remove small protrusions and bristles from skeleton (from my understanding).
remove_soma_hairball (bool, default False) – Remove the hairball mesh from the soma
assert_id_match (bool, default False) – Verify skeleton nodes map to correct segment ID.
threads (int, default 2) – Number of parallel threads for mesh processing.
save_to (str, optional) – Save skeleton as SWC file to this path.
progress (bool, default True) – Show progress bars during processing.
use_pcg_skel (bool, default False) – Try pcg_skel first before skeletor (CAVE-client skeletonization).
**kwargs – Additional arguments for skeletonization algorithms.
- Returns:
navis.TreeNeuron – The skeletonized neuron.
# TODOs from fafbseg
# - Use synapse locations as constraints
# - Mesh preprocessing options
# - Chunked skeletonization for large meshes
# - Use soma annotations from external sources
# - Better error handling/logging
# - Allow user-supplied soma location/radius
# - Option to return intermediate results
# - Support more skeletonization algorithms
# - Merge disconnected skeletons
# - Custom node/edge attributes
- Return type:
navis.TreeNeuron | navis.NeuronList
- crantpy.viz.skeletonize.skeletonize_neurons_parallel(client, root_ids, n_cores=None, progress=True, color_map=None, **kwargs)[source]#
Skeletonize multiple neurons in parallel.
- Parameters:
client (CAVEclient) – CAVE client for data access.
root_ids (list of int or np.ndarray) – Root IDs of neurons to skeletonize.
n_cores (int, optional) – Number of cores to use. If None, uses half of available cores.
progress (bool, default True) – Show progress bars during processing.
color_map (str, optional) – Generate colors for each neuron using this colormap. Returns tuple of (neurons, colors) instead of just neurons.
**kwargs – Additional arguments passed to skeletonize_neuron.
- Returns:
NeuronList of skeletonized neurons, or tuple of (NeuronList, colors) if color_map is specified.
- Return type:
navis.NeuronList or tuple