crantpy.viz.mesh module#

Mesh module for CRANTBpy.

crantpy.viz.mesh.detect_soma(x, dataset=None, min_rad=800, N=3, progress=True)[source]#

Detect the soma (cell body) location of a neuron based on mesh radius.

This function attempts to identify the soma by finding regions of the mesh with a sufficiently large radius. It supports both single neurons and batch input.

Parameters:
  • x (int, str, trimesh.Trimesh, navis.MeshNeuron, or list/array-like) – Neuron ID, mesh, or list thereof. Meshes must not be downsampled. If a list/array is provided, returns coordinates for each.

  • dataset (str, optional) – Dataset to query. If None, falls back to the default dataset.

  • min_rad (float, optional) – Minimum radius for a node to be considered a soma candidate. Default is 800.

  • N (int, optional) – Number of consecutive vertices with radius > min_rad to consider as soma candidates. Default is 3.

  • progress (bool, optional) – Whether to show a progress bar for batch input. Default is True.

Returns:

If input is a single neuron, returns a (3,) array of x, y, z coordinates of the detected soma. If input is a list/array, returns (N, 3) array of coordinates for each neuron. If no soma is found, returns [None, None, None] for that neuron.

Return type:

np.ndarray

crantpy.viz.mesh.get_brain_mesh_scene(neurons, dataset=None, omit_failures=None, threads=5, progress=True, brain_mesh_color='grey', brain_mesh_alpha=0.1, neuron_mesh_alpha=1, neuron_mesh_colors=None, backend='client')[source]#

Create a 3D scene of the brain mesh with the specified neurons in random colors.

Parameters:
  • neurons (Union[int, str, tm.Trimesh, navis.MeshNeuron, navis.NeuronList, 'NeuronCriteria', List[Union[int, str, tm.Trimesh, navis.MeshNeuron, 'NeuronCriteria']]]) – The neurons to highlight in the scene.

  • dataset (Optional[str], optional) – The dataset to use for fetching neuron meshes, by default None

  • omit_failures (Optional[bool], optional) – Whether to omit neurons that fail to load, by default None

  • threads (int, optional) – The number of threads to use for loading meshes, by default 5

  • progress (bool, optional) – Whether to show a progress bar, by default True

  • brain_mesh_color (Optional[str], optional) – The color of the brain mesh, by default β€œgrey”

  • brain_mesh_alpha (Optional[float], optional) – The transparency of the brain mesh, by default 0.1

  • neuron_mesh_alpha (Optional[float], optional) – The transparency of the neuron meshes, by default 1

  • backend (Optional[str], optional) – The pyvista backend to use (β€˜static’, β€˜trame’, β€˜client’), by default β€˜client’

  • neuron_mesh_colors (list)

Returns:

The 3D scene containing the brain mesh and highlighted neurons.

Return type:

pv.Plotter

crantpy.viz.mesh.get_mesh_neuron(neurons, dataset=None, omit_failures=None, threads=5, progress=True)[source]#

Fetch one or more CRANTB neurons as navis.MeshNeuron objects.

This function retrieves mesh representations for the specified neuron(s) from the selected dataset. It supports batch queries, parallel fetching, and flexible error handling.

Parameters:
  • neurons (int, str, list of int/str, or NeuronCriteria) – Neuron root ID(s) or a NeuronCriteria instance specifying which neurons to fetch. Accepts a single ID, a list/array of IDs, or a NeuronCriteria object.

  • dataset (str, optional) – Dataset to fetch info from. If None, uses the default dataset.

  • omit_failures (bool, optional) –

    Behavior when mesh download fails:
    • None (default): raise an exception

    • True: skip the offending neuron (may result in empty NeuronList)

    • False: return an empty MeshNeuron for failed fetches

  • threads (int, optional) – Number of parallel threads to use for batch queries. Default is 5.

  • progress (bool, optional) – Whether to show a progress bar during batch fetching. Default is True.

Returns:

MeshNeuron if a single neuron is requested, or NeuronList for multiple neurons.

Return type:

navis.MeshNeuron or navis.NeuronList

crantpy.viz.mesh.load_whole_brain_mesh()[source]#

Download and decode a whole-brain tissue mesh.

Returns:

The whole-brain tissue mesh.

Return type:

trimesh.Trimesh