siibra.volumes.volume
A specific mesh or 3D array.
Classes
Centroid and nonzero volume of an image. |
|
A volume is a specific mesh or 3D array, |
|
A volume is a specific mesh or 3D array, |
|
Wrapper class for exposing a z level of a 4D volume to be used like a 3D volume. |
|
A volume is a specific mesh or 3D array, |
|
A volume is a specific mesh or 3D array, |
Functions
|
Build a siibra volume from an array and affine matrix. |
|
Build a volume from local files. |
|
Build a siibra volume from a NIfTI image. |
|
Build a kernel-density volume from a point cloud. |
|
Build a volume from files served from online (https) sources. |
|
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.
- centroid: siibra.locations.point.Point
- volume: int
- class siibra.volumes.volume.FilteredVolume(parent_volume: Volume, label: int = None, fragment: str = None, threshold: float = None, timepoint: int | float = None)

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’
**kwargs –
resolution_mm: resolution in millimeters as float or a tuple of floats
format: the format of the volume, like “mesh” or “nii”
voi: a BoundingBox of interest
- 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
- timepoint = None
- class siibra.volumes.volume.ReducedVolume(source_volumes: List[Volume], new_labels: List[int] = None)

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’
**kwargs –
resolution_mm: resolution in millimeters as float or a tuple of floats
format: the format of the volume, like “mesh” or “nii”
voi: a BoundingBox of interest
- 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.
- property formats: Set[str]
- new_labels = None
- source_volumes
- class siibra.volumes.volume.Subvolume(parent_volume: Volume, z: int)

Wrapper class for exposing a z level of a 4D volume to be used like a 3D volume.
- class siibra.volumes.volume.TimeSeriesVolume(time: numpy.ndarray = None, **kwargs)

A volume is a specific mesh or 3D array, which can be accessible via multiple providers in different formats.
- __iter__() Iterable[FilteredVolume]
- fetch(format: str = None, timepoint: int | float | None = 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’
**kwargs –
resolution_mm: resolution in millimeters as float or a tuple of floats
format: the format of the volume, like “mesh” or “nii”
voi: a BoundingBox of interest
- Returns:
An image (Nifti1Image) or mesh (Dict[‘verts’
- Return type:
ndarray, ‘faces’: ndarray, ‘labels’: ndarray])
- get_timepoint(timepoint: int | float | None) FilteredVolume
- property time: numpy.ndarray
Time axis; inferred from the data if it was not specified.
- class siibra.volumes.volume.Volume(space_spec: dict, providers: List[siibra.volumes.providers.provider.VolumeProvider], name: str = '', variant: str = None, datasets: List[siibra.retrieval.datasets.EbrainsDataset] = [], bbox: siibra.locations.boundingbox.BoundingBox = None)

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:
- 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’
**kwargs –
resolution_mm: resolution in millimeters as float or a tuple of floats
format: the format of the volume, like “mesh” or “nii”
voi: a BoundingBox of interest
- 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', 'tif/2d']
- MESH_FORMATS = ['neuroglancer/precompmesh', 'neuroglancer/precompmesh/surface', 'gii-mesh', 'gii-label',...
- SUPPORTED_FORMATS = ['nii', 'zip/nii', 'neuroglancer/precomputed', 'tif/2d', 'neuroglancer/precompmesh',...
- datasets = []
- property formats: Set[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 = None, time: numpy.ndarray = None, *, cache: bool = True) Volume | TimeSeriesVolume
Build a siibra volume from an array and affine matrix.
The array is converted to a NIfTI image, written to the local siibra cache, and returned as a file-backed volume. The volume keeps the full-precision
affine, although NIfTI files store it in single precision. Ifnameis not provided, a stable name is generated from the array values, shape, dtype, and optional time axis.- Parameters:
data (numpy.ndarray) – Voxel data of the volume.
affine (numpy.ndarray) – 4x4 affine matrix mapping voxel coordinates to world coordinates.
space (str or dict[str, str]) – Reference space of the volume. If a mapping is provided, the first value is used as the space specification.
name (str, optional) – Name assigned to the resulting volume. If omitted, a deterministic name is generated from
dataandtime.time (numpy.ndarray, optional) – Time axis for 4D or time-resolved data. If given, a
TimeSeriesVolumeis returned.cache (bool) – Cache it on disk
- Returns:
File-backed siibra volume using a cached NIfTI image.
- Return type:
- siibra.volumes.volume.from_file(files: str | pathlib.Path | Dict[str, str | pathlib.Path], space: str, name: str = None, *, format: str = 'nii', time: numpy.ndarray = None)
Build a volume from local files.
- Parameters:
files (str, pathlib.Path, or dict[str, str | pathlib.Path]) – Local image file, or a mapping from fragment names to local image files. A single file is internally treated as an unfragmented image.
space (str) – Reference space of the volume.
format (str, default: "nii") – Examples include
"nii","gii-timeseries","gii-label", and"gii-mesh". See Volume.SUPPORTED_FORMATS.time (numpy.ndarray, optional) – Time axis. If given, a TimeSeriesVolume is returned.
- Returns:
TimeSeriesVolume if time values are provided, otherwise a Volume
- Return type:
- siibra.volumes.volume.from_nifti(nifti: nibabel.Nifti1Image, space: str, name: str, time: numpy.ndarray = None) Volume | TimeSeriesVolume
Build a siibra volume from a NIfTI image.
The image is written to the local siibra cache and returned as a file-backed volume. This avoids storing the image array directly in the provider and can reduce memory pressure for large or proxy-backed NIfTI images. The cache file is identified by the name, space, affine, and image data, so the image data is read once to compute its digest.
NIfTI files store the affine in single precision. The returned volume therefore uses the full-precision affine of
niftiinstead of the one read from the cached file.- Parameters:
nifti (nibabel.Nifti1Image) – NIfTI image to wrap as a siibra volume.
space (str) – Reference space of the volume.
name (str) – Name assigned to the resulting volume. Must be non-empty.
time (numpy.ndarray, optional) – Time axis for 4D or time-resolved data. If given, a
TimeSeriesVolumeis returned.
- Returns:
File-backed siibra volume using a cached NIfTI image.
- Return type:
- Raises:
ValueError – If
nameis empty.
- siibra.volumes.volume.from_pointcloud(points: siibra.locations.pointcloud.PointCloud, label: int = None, target: Volume = None, normalize: bool = True, *, clip_out_of_bounds: bool = False, **kwargs) Volume
Build a kernel-density volume from a point cloud.
The point coordinates are transformed into the voxel space of a target volume. A voxel-count image is created, smoothed with a Gaussian kernel using the average point uncertainty as bandwidth, optionally normalized, and returned as a cached file-backed siibra volume.
- Parameters:
points (pointcloud.PointCloud) – Point cloud used to generate the kernel-density estimate.
label (int, optional) – If provided, only points with this label are used. If omitted, all points are used.
target (Volume, optional) – Target volume defining the output grid and affine. If omitted, the template of
points.spaceis used.normalize (bool, default: True) – If True, divide the smoothed density image by its sum.
clip_out_of_bounds (bool, default: False) – If False, raise an error when transformed points fall outside the target volume. If True, discard out-of-bounds points.
**kwargs – Additional keyword arguments passed to
target.fetch.
- Returns:
File-backed siibra volume containing the point-cloud KDE.
- Return type:
- Raises:
ValueError – If
labelis provided but no points with that label are found.ValueError – If transformed points are outside the target volume and
clip_out_of_boundsis False.
- siibra.volumes.volume.from_url(urls: str | Dict[str, str], space: str, name: str = None, *, format: str = 'nii', time: numpy.ndarray = None)
Build a volume from files served from online (https) sources.
- Parameters:
urls (str or dict[str, str]) – URL to the online image data, or a mapping from fragment names to URLs. A single URL is internally treated as an unfragmented image.
space (str) – Reference space of the volume.
format (str, default: "nii") – Examples include
"nii","gii-timeseries","gii-label", and"gii-mesh". See Volume.SUPPORTED_FORMATS.time (numpy.ndarray, optional) – Time axis. If given, a TimeSeriesVolume is returned.
- Returns:
TimeSeriesVolume if time values are provided, otherwise a Volume
- Return type: