cellmap_data.CellMapImage#

class cellmap_data.CellMapImage(path: str, target_class: str, target_scale: Sequence[float], target_voxel_shape: Sequence[int], pad: bool = False, pad_value: float | int = nan, interpolation: str = 'nearest', axis_order: str | Sequence[str] = 'zyx', value_transform: Callable | None = None, context: Context | None = None)[source]#

Initializes a CellMapImage object.

Parameters:
  • path (str) – The path to the image file.

  • target_class (str) – The label class of the image.

  • target_scale (Sequence[float]) – The scale of the image data to return in physical space.

  • target_voxel_shape (Sequence[int]) – The shape of the image data to return in voxels.

  • axis_order (str, optional) – The order of the axes in the image. Defaults to “zyx”.

  • value_transform (Optional[callable], optional) – A function to transform the image pixel data. Defaults to None.

  • context (Optional[tensorstore.Context], optional) – The context for the image data. Defaults to None.

  • pad (bool)

  • pad_value (float | int)

  • interpolation (str)

__init__(path: str, target_class: str, target_scale: Sequence[float], target_voxel_shape: Sequence[int], pad: bool = False, pad_value: float | int = nan, interpolation: str = 'nearest', axis_order: str | Sequence[str] = 'zyx', value_transform: Callable | None = None, context: Context | None = None) None[source]#

Initializes a CellMapImage object.

Parameters:
  • path (str) – The path to the image file.

  • target_class (str) – The label class of the image.

  • target_scale (Sequence[float]) – The scale of the image data to return in physical space.

  • target_voxel_shape (Sequence[int]) – The shape of the image data to return in voxels.

  • axis_order (str, optional) – The order of the axes in the image. Defaults to “zyx”.

  • value_transform (Optional[callable], optional) – A function to transform the image pixel data. Defaults to None.

  • context (Optional[tensorstore.Context], optional) – The context for the image data. Defaults to None.

  • pad (bool)

  • pad_value (float | int)

  • interpolation (str)

Return type:

None

Methods

__init__(path, target_class, target_scale, ...)

Initializes a CellMapImage object.

apply_spatial_transforms(coords)

Applies spatial transformations to the given coordinates.

find_level(target_scale)

Finds the multiscale level that is closest to the target scale.

return_data(coords)

Pulls data from the image based on the given coordinates, applying interpolation if necessary, and returns the data as an xarray DataArray.

rotate_coords(coords, angles)

Rotates the given coordinates by the given angles.

set_spatial_transforms(transforms)

Sets spatial transformations for the image data, for setting global transforms at the 'dataset' level.

to(device)

Sets what device returned image data will be loaded onto.

Attributes

array

Returns the image data as an xarray DataArray.

array_path

Returns the path to the single-scale image array.

bg_count

Returns the number of background pixels in the ground truth data, normalized by the resolution.

bounding_box

Returns the bounding box of the dataset in world units.

center

Returns the center of the image in world units.

class_counts

Returns the number of pixels for the contained class in the ground truth data, normalized by the resolution.

coordinateTransformations

Returns the coordinate transformations of the image, based on the multiscale metadata.

full_coords

Returns the full coordinates of the image's axes in world units.

group

Returns the zarr group object for the multiscale image.

multiscale_attrs

Returns the multiscale metadata of the image.

sampling_box

Returns the sampling box of the dataset (i.e. where centers can be drawn from and still have full samples drawn from within the bounding box), in world units.

scale_level

Returns the multiscale level of the image.

shape

Returns the shape of the image.

translation

Returns the translation of the image.

__getitem__(center: Mapping[str, float]) Tensor[source]#

Returns image data centered around the given point, based on the scale and shape of the target output image.

Parameters:

center (Mapping[str, float])

Return type:

Tensor

property shape: Mapping[str, int]#

Returns the shape of the image.

property center: Mapping[str, float]#

Returns the center of the image in world units.

property multiscale_attrs: MultiscaleMetadata#

Returns the multiscale metadata of the image.

property coordinateTransformations: tuple[VectorScale | PathScale] | tuple[VectorScale | PathScale, VectorTranslation | PathTranslation]#

Returns the coordinate transformations of the image, based on the multiscale metadata.

property full_coords: tuple[DataArray, ...]#

Returns the full coordinates of the image’s axes in world units.

property scale_level: str#

Returns the multiscale level of the image.

property group: Group#

Returns the zarr group object for the multiscale image.

property array_path: str#

Returns the path to the single-scale image array.

property array: DataArray#

Returns the image data as an xarray DataArray.

property translation: Mapping[str, float]#

Returns the translation of the image.

property bounding_box: Mapping[str, list[float]]#

Returns the bounding box of the dataset in world units.

property sampling_box: Mapping[str, list[float]]#

Returns the sampling box of the dataset (i.e. where centers can be drawn from and still have full samples drawn from within the bounding box), in world units.

property bg_count: float#

Returns the number of background pixels in the ground truth data, normalized by the resolution.

property class_counts: float#

Returns the number of pixels for the contained class in the ground truth data, normalized by the resolution.

to(device: str) None[source]#

Sets what device returned image data will be loaded onto.

Parameters:

device (str)

Return type:

None

find_level(target_scale: Mapping[str, float]) str[source]#

Finds the multiscale level that is closest to the target scale.

Parameters:

target_scale (Mapping[str, float])

Return type:

str

rotate_coords(coords: Mapping[str, Sequence[float]], angles: Mapping[str, float]) Mapping[str, tuple[Sequence[str], ndarray]] | Mapping[str, Sequence[float]][source]#

Rotates the given coordinates by the given angles.

Parameters:
  • coords (Mapping[str, Sequence[float]])

  • angles (Mapping[str, float])

Return type:

Mapping[str, tuple[Sequence[str], ndarray]] | Mapping[str, Sequence[float]]

set_spatial_transforms(transforms: Mapping[str, Any] | None) None[source]#

Sets spatial transformations for the image data, for setting global transforms at the ‘dataset’ level.

Parameters:

transforms (Mapping[str, Any] | None)

Return type:

None

apply_spatial_transforms(coords) Tensor[source]#

Applies spatial transformations to the given coordinates.

Return type:

Tensor

return_data(coords: Mapping[str, Sequence[float]] | Mapping[str, tuple[Sequence[str], ndarray]]) DataArray[source]#

Pulls data from the image based on the given coordinates, applying interpolation if necessary, and returns the data as an xarray DataArray.

Parameters:

coords (Mapping[str, Sequence[float]] | Mapping[str, tuple[Sequence[str], ndarray]])

Return type:

DataArray