siibra.volumes.volume

A specific mesh or 3D array.

Module Contents

Classes

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_pointset(→ Volume)

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

merge(→ Volume)

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

Attributes

TypeDataset

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] = [])
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.

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
IMAGE_FORMATS = ['nii', 'zip/nii', 'neuroglancer/precomputed']
MESH_FORMATS = ['neuroglancer/precompmesh', 'neuroglancer/precompmesh/surface', 'gii-mesh', 'gii-label']
SUPPORTED_FORMATS
__eq__(other: Volume)

Required to provide comparison and making the object hashable

__hash__()

Return hash(self).

__repr__()

Return repr(self).

__str__()

Return str(self).

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 distribtution. Any keyword arguments are passed over to fetch()

evaluate_points(points: siibra.locations.point.Point | siibra.locations.pointset.PointSet, 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 (PointSet) –

  • 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(**kwargs)

Provide an iterator 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 fetchin 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.

abstract transform(affine: numpy.ndarray, space=None)

Returns a new location obtained by transforming the reference coordinates of this one with the given affine matrix.

Parameters:
  • affine (numpy 4x4 ndarray) – affine matrix

  • space (reference space (id, name, or Space)) – Target reference space which is reached after applying the transform. Note that the consistency of this cannot be checked and is up to the user.

union(other: siibra.locations.location.Location)

Reassigned at the locations module level for static typing and to avoid circular imports. See siibra.locations.__init__.reassign_union()

warp(space)

Generates a new location by warping the current one into another reference space.

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_pointset(points: siibra.locations.pointset.PointSet, 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 (pointset.PointSet) –

  • 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 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 exisiting values per volume.

Return type:

Volume

siibra.volumes.volume.TypeDataset