siibra.volumes.volume

A specific mesh or 3D array.

Attributes

TypeDataset

Classes

ComponentSpatialProperties

Centroid and nonzero volume of an image.

FilteredVolume

A volume is a specific mesh or 3D array,

Subvolume

Wrapper class for exposing a z level of a 4D volume to be used like a 3D volume.

Volume

A volume is a specific mesh or 3D array,

Functions

from_array(→ Volume)

Builds a siibra volume from an array and an affine matrix.

from_file(→ Volume)

Builds a nifti volume from a filename.

from_nifti(→ Volume)

Builds a nifti volume from a Nifti image.

from_pointcloud(→ Volume)

Get the kernel density estimate as a volume from the points using their

merge(→ Volume)

Merge a list of nifti volumes in the same space into a single volume.

Module Contents

class siibra.volumes.volume.ComponentSpatialProperties

Centroid and nonzero volume of an image.

static compute_from_image(img: nibabel.Nifti1Image, space: str | siibra.core.space.Space, split_components: bool = True) List[ComponentSpatialProperties]

Find the center of an image in its (non-zero) voxel space and and its volume.

Parameters:
  • img (Nifti1Image) –

  • space (str, Space) –

  • split_components (bool, default: True) – If True, finds the spatial properties for each connected component found by skimage.measure.label.

centroid: siibra.locations.point.Point
volume: int
class siibra.volumes.volume.FilteredVolume(parent_volume: Volume, label: int = None, fragment: str = None, threshold: float = None)
Inheritance diagram of siibra.volumes.volume.FilteredVolume

A volume is a specific mesh or 3D array, which can be accessible via multiple providers in different formats.

fetch(format: str = None, **kwargs)

Fetch a volumetric or surface representation from one of the providers.

Parameters:

format (str, default=None) –

Requested format. If None, the first supported format matching in self.formats is tried, starting with volumetric formats. It can be explicitly specified as:

  • ’surface’ or ‘mesh’ to fetch a surface format

  • ’volumetric’ or ‘voxel’ to fetch a volumetric format

  • supported format types, see SUPPORTED_FORMATS. This includes

’nii’, ‘zip/nii’, ‘neuroglancer/precomputed’, ‘gii-mesh’, ‘neuroglancer/precompmesh’, ‘gii-label’

Returns:

An image (Nifti1Image) or mesh (Dict[‘verts’

Return type:

ndarray, ‘faces’: ndarray, ‘labels’: ndarray])

get_boundingbox(clip: bool = True, background: float = 0.0, **fetch_kwargs) siibra.locations.boundingbox.BoundingBox

Obtain the bounding box in physical coordinates of this volume.

Parameters:
  • clip (bool, default: True) – Whether to clip the background of the volume.

  • background (float, default: 0.0) – The background value to clip. .. note:: To use it, clip must be True.

  • fetch_kwargs – key word arguments that are used for fetching volumes, such as voi or resolution_mm. Currently, only possible for Neuroglancer volumes except for format.

Raises:

RuntimeError – If the volume provider does not have a bounding box calculator.

fragment = None
label = None
threshold = None
class siibra.volumes.volume.Subvolume(parent_volume: Volume, z: int)
Inheritance diagram of siibra.volumes.volume.Subvolume

Wrapper class for exposing a z level of a 4D volume to be used like a 3D volume.

class siibra.volumes.volume.Volume(space_spec: dict, providers: List[siibra.volumes.providers.provider.VolumeProvider], name: str = '', variant: str = None, datasets: List[TypeDataset] = [], bbox: siibra.locations.boundingbox.BoundingBox = None)
Inheritance diagram of siibra.volumes.volume.Volume

A volume is a specific mesh or 3D array, which can be accessible via multiple providers in different formats.

__eq__(other: Volume)
__hash__()
__repr__()
__str__()
compute_spatial_props(split_components: bool = True, **fetch_kwargs) List[ComponentSpatialProperties]

Find the center of this volume in its (non-zero) voxel space and and its volume.

Parameters:

split_components (bool, default: True) – If True, finds the spatial properties for each connected component found by skimage.measure.label.

draw_samples(N: int, sample_size: int = 100, e: float = 1, sigma_mm=None, invert=False, **kwargs)

Draw samples from the volume, by interpreting its values as an unnormalized empirical probability distributions. Any keyword arguments are passed over to fetch()

evaluate_points(points: siibra.locations.point.Point | siibra.locations.pointcloud.PointCloud, outside_value: int | float = 0, **fetch_kwargs) numpy.ndarray

Evaluate the image at the positions of the given points.

Note

Uses nearest neighbor interpolation. Other interpolation schemes are not yet implemented.

Note

If points are not on the same space as the map, they will be warped to the space of the volume.

Parameters:
  • points (PointCloud) –

  • outside_value (int, float. Default: 0) –

  • fetch_kwargs (dict) – Any additional arguments are passed to the fetch() call for retrieving the image data.

Returns:

values – The values of the volume at the voxels points correspond to.

Return type:

numpy.ndarray

Raises:

SpaceWarpingFailedError – If warping of the points fails.

fetch(format: str = None, **kwargs)

Fetch a volumetric or surface representation from one of the providers.

Parameters:

format (str, default=None) –

Requested format. If None, the first supported format matching in self.formats is tried, starting with volumetric formats. It can be explicitly specified as:

  • ’surface’ or ‘mesh’ to fetch a surface format

  • ’volumetric’ or ‘voxel’ to fetch a volumetric format

  • supported format types, see SUPPORTED_FORMATS. This includes

’nii’, ‘zip/nii’, ‘neuroglancer/precomputed’, ‘gii-mesh’, ‘neuroglancer/precompmesh’, ‘gii-label’

Returns:

An image (Nifti1Image) or mesh (Dict[‘verts’

Return type:

ndarray, ‘faces’: ndarray, ‘labels’: ndarray])

fetch_connected_components(**fetch_kwargs)

Provide an generator over masks of connected components in the volume

find_peaks(mindist=5, sigma_mm=0, **kwargs)

Find local peaks in the volume. Additional keyword arguments are passed over to fetch()

get_boundingbox(clip: bool = True, background: float = 0.0, **fetch_kwargs) siibra.locations.boundingbox.BoundingBox

Obtain the bounding box in physical coordinates of this volume.

Parameters:
  • clip (bool, default: True) – Whether to clip the background of the volume.

  • background (float, default: 0.0) – The background value to clip. .. note:: To use it, clip must be True.

  • fetch_kwargs – key word arguments that are used for fetching volumes, such as voi or resolution_mm. Currently, only possible for Neuroglancer volumes except for format.

Raises:

RuntimeError – If the volume provider does not have a bounding box calculator.

intersection(other: siibra.core.structure.BrainStructure, **fetch_kwargs) siibra.core.structure.BrainStructure

Compute the intersection of a location with this volume. This will fetch actual image data. Any additional arguments are passed to fetch.

IMAGE_FORMATS = ['nii', 'zip/nii', 'neuroglancer/precomputed']
MESH_FORMATS = ['neuroglancer/precompmesh', 'neuroglancer/precompmesh/surface', 'gii-mesh', 'gii-label',...
SUPPORTED_FORMATS = ['nii', 'zip/nii', 'neuroglancer/precomputed', 'neuroglancer/precompmesh',...
datasets = []
property formats: Set[str]
property fragments: Dict[str, List[str]]
property name

Allows derived classes to implement a lazy name specification.

property providers
property provides_image
property provides_mesh
property space
property species
variant = None
siibra.volumes.volume.from_array(data: numpy.ndarray, affine: numpy.ndarray, space: str | Dict[str, str], name: str) Volume

Builds a siibra volume from an array and an affine matrix.

siibra.volumes.volume.from_file(filename: str, space: str, name: str) Volume

Builds a nifti volume from a filename.

siibra.volumes.volume.from_nifti(nifti: nibabel.Nifti1Image, space: str, name: str) Volume

Builds a nifti volume from a Nifti image.

siibra.volumes.volume.from_pointcloud(points: siibra.locations.pointcloud.PointCloud, label: int = None, target: Volume = None, normalize=True, **kwargs) Volume

Get the kernel density estimate as a volume from the points using their average uncertainty on target volume.

Parameters:
  • points (pointcloud.PointCloud) –

  • label (int, default: None) – If None, finds the KDE for all points. Otherwise, selects the points labelled with this integer value.

  • target (Volume, default: None) – If None, the template of the space points are defined on will be used.

  • normalize (bool, default: True) –

Raises:

RuntimeError – If no points with labels found

siibra.volumes.volume.merge(volumes: List[Volume], labels: List[int] = [], **fetch_kwargs) Volume

Merge a list of nifti volumes in the same space into a single volume.

Note

In case of voxel conflicts, the volumes will be override the previous values in the given order.

Parameters:
  • volumes (List[Volume]) –

  • labels (List[int], optional) – Supply new labels to replace existing values per volume.

Return type:

Volume

siibra.volumes.volume.TypeDataset