Skip to content

OME-Zarr container API reference

Open a container

ngio.open_ome_zarr_container

open_ome_zarr_container(
    store: StoreOrGroup,
    cache: bool = False,
    mode: AccessModeLiteral = "r+",
    axes_setup: AxesSetup | None = None,
    validate_arrays: bool = False,
) -> OmeZarrContainer

Open an OME-Zarr image.

Parameters:

  • store (StoreOrGroup) –

    The Zarr store or group holding the image.

  • cache (bool, default: False ) –

    Whether to cache the zarr group metadata.

  • mode (AccessModeLiteral, default: 'r+' ) –

    The access mode for the image.

  • axes_setup (AxesSetup | None, default: None ) –

    Axes setup to load ome-zarr with non-standard axes configurations.

  • validate_arrays (bool, default: False ) –

    Whether to open every level listed in the multiscale metadata up front, so a missing or malformed array fails here rather than on first access.

Source code in src/ngio/images/_ome_zarr_container.py
def open_ome_zarr_container(
    store: StoreOrGroup,
    cache: bool = False,
    mode: AccessModeLiteral = "r+",
    axes_setup: AxesSetup | None = None,
    validate_arrays: bool = False,
) -> OmeZarrContainer:
    """Open an OME-Zarr image.

    Args:
        store: The Zarr store or group holding the image.
        cache: Whether to cache the zarr group metadata.
        mode: The access mode for the image.
        axes_setup: Axes setup to load ome-zarr with non-standard axes
            configurations.
        validate_arrays: Whether to open every level listed in the multiscale
            metadata up front, so a missing or malformed array fails here
            rather than on first access.
    """
    handler = ZarrGroupHandler(store=store, cache=cache, mode=mode)
    return OmeZarrContainer(
        group_handler=handler,
        validate_arrays=validate_arrays,
        axes_setup=axes_setup,
    )

Create a container

ngio.create_empty_ome_zarr

create_empty_ome_zarr(
    store: StoreOrGroup,
    shape: Sequence[int],
    pixelsize: float | tuple[float, float],
    z_spacing: float = 1.0,
    time_spacing: float = 1.0,
    scaling_factors: Sequence[float]
    | Literal["auto"] = "auto",
    levels: int | list[str] = 5,
    translation: Sequence[float] | None = None,
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
    axes_names: Sequence[str] | None = None,
    channels_meta: Sequence[str | Channel] | None = None,
    name: str | None = None,
    axes_setup: AxesSetup | None = None,
    ngff_version: NgffVersions = DefaultNgffVersion,
    chunks: ChunksLike = "auto",
    shards: ShardsLike | None = None,
    dtype: str = "uint16",
    dimension_separator: Literal[".", "/"] = "/",
    compressors: CompressorLike = "auto",
    extra_array_kwargs: Mapping[str, Any] | None = None,
    overwrite: bool = False,
) -> OmeZarrContainer

Create an empty OME-Zarr image with the given shape and metadata.

Parameters:

  • store (StoreOrGroup) –

    The Zarr store or group to create the image in.

  • shape (Sequence[int]) –

    The shape of the image.

  • pixelsize (float | tuple[float, float] | None) –

    The pixel size in x and y dimensions. A value to write, not a lookup key; to select an existing level see pixel_size on the getters.

  • z_spacing (float, default: 1.0 ) –

    The spacing between z slices. Defaults to 1.0.

  • time_spacing (float, default: 1.0 ) –

    The spacing between time points. Defaults to 1.0.

  • scaling_factors (Sequence[float] | Literal['auto'], default: 'auto' ) –

    The down-scaling factors for the pyramid levels. Defaults to "auto".

  • levels (int | list[str], default: 5 ) –

    The number of levels in the pyramid or a list of level names. Defaults to 5.

  • translation (Sequence[float] | None, default: None ) –

    The translation for each axis. at the highest resolution level. Defaults to None.

  • space_unit (SpaceUnits, default: DefaultSpaceUnit ) –

    The unit of space. Defaults to DefaultSpaceUnit.

  • time_unit (TimeUnits, default: DefaultTimeUnit ) –

    The unit of time. Defaults to DefaultTimeUnit.

  • axes_names (Sequence[str] | None, default: None ) –

    The names of the axes. If None the canonical names are used. Defaults to None.

  • channels_meta (Sequence[str | Channel] | None, default: None ) –

    The channels metadata. Defaults to None.

  • name (str | None, default: None ) –

    The name of the image. Defaults to None.

  • axes_setup (AxesSetup | None, default: None ) –

    Axes setup to create ome-zarr with non-standard axes configurations. Defaults to None.

  • ngff_version (NgffVersions, default: DefaultNgffVersion ) –

    The version of the OME-Zarr specification. Defaults to DefaultNgffVersion.

  • chunks (ChunksLike, default: 'auto' ) –

    The chunk shape. Defaults to "auto".

  • shards (ShardsLike | None, default: None ) –

    The shard shape. Defaults to None.

  • dtype (str, default: 'uint16' ) –

    The data type of the image. Defaults to "uint16".

  • dimension_separator (Literal['.', '/'], default: '/' ) –

    The dimension separator to use. Defaults to "/".

  • compressors (CompressorLike, default: 'auto' ) –

    The compressor to use. Defaults to "auto".

  • extra_array_kwargs (Mapping[str, Any] | None, default: None ) –

    Extra arguments to pass to the zarr array creation. Defaults to None.

  • overwrite (bool, default: False ) –

    Whether to overwrite an existing image. Defaults to False.

Source code in src/ngio/images/_ome_zarr_container.py
def create_empty_ome_zarr(
    store: StoreOrGroup,
    shape: Sequence[int],
    pixelsize: float | tuple[float, float],
    z_spacing: float = 1.0,
    time_spacing: float = 1.0,
    scaling_factors: Sequence[float] | Literal["auto"] = "auto",
    levels: int | list[str] = 5,
    translation: Sequence[float] | None = None,
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
    axes_names: Sequence[str] | None = None,
    channels_meta: Sequence[str | Channel] | None = None,
    name: str | None = None,
    axes_setup: AxesSetup | None = None,
    ngff_version: NgffVersions = DefaultNgffVersion,
    chunks: ChunksLike = "auto",
    shards: ShardsLike | None = None,
    dtype: str = "uint16",
    dimension_separator: Literal[".", "/"] = "/",
    compressors: CompressorLike = "auto",
    extra_array_kwargs: Mapping[str, Any] | None = None,
    overwrite: bool = False,
) -> OmeZarrContainer:
    """Create an empty OME-Zarr image with the given shape and metadata.

    Args:
        store (StoreOrGroup): The Zarr store or group to create the image in.
        shape (Sequence[int]): The shape of the image.
        pixelsize (float | tuple[float, float] | None): The pixel size in x and y
            dimensions.
            A value to write, not a lookup key; to select an existing
            level see `pixel_size` on the getters.
        z_spacing (float): The spacing between z slices. Defaults to 1.0.
        time_spacing (float): The spacing between time points. Defaults to 1.0.
        scaling_factors (Sequence[float] | Literal["auto"]): The down-scaling factors
            for the pyramid levels. Defaults to "auto".
        levels (int | list[str]): The number of levels in the pyramid or a list of
            level names. Defaults to 5.
        translation (Sequence[float] | None): The translation for each axis.
            at the highest resolution level. Defaults to None.
        space_unit (SpaceUnits): The unit of space. Defaults to DefaultSpaceUnit.
        time_unit (TimeUnits): The unit of time. Defaults to DefaultTimeUnit.
        axes_names (Sequence[str] | None): The names of the axes. If None the
            canonical names are used. Defaults to None.
        channels_meta (Sequence[str | Channel] | None): The channels metadata.
            Defaults to None.
        name (str | None): The name of the image. Defaults to None.
        axes_setup (AxesSetup | None): Axes setup to create ome-zarr with
            non-standard axes configurations. Defaults to None.
        ngff_version (NgffVersions): The version of the OME-Zarr specification.
            Defaults to DefaultNgffVersion.
        chunks (ChunksLike): The chunk shape. Defaults to "auto".
        shards (ShardsLike | None): The shard shape. Defaults to None.
        dtype (str): The data type of the image. Defaults to "uint16".
        dimension_separator (Literal[".", "/"]): The dimension separator to use.
            Defaults to "/".
        compressors (CompressorLike): The compressor to use. Defaults to "auto".
        extra_array_kwargs (Mapping[str, Any] | None): Extra arguments to pass to
            the zarr array creation. Defaults to None.
        overwrite (bool): Whether to overwrite an existing image. Defaults to False.
    """
    handler, axes_setup = init_image_like(
        store=store,
        meta_type=NgioImageMeta,
        shape=shape,
        pixelsize=pixelsize,
        z_spacing=z_spacing,
        time_spacing=time_spacing,
        scaling_factors=scaling_factors,
        levels=levels,
        translation=translation,
        space_unit=space_unit,
        time_unit=time_unit,
        axes_names=axes_names,
        channels_meta=channels_meta,
        name=name,
        axes_setup=axes_setup,
        ngff_version=ngff_version,
        chunks=chunks,
        shards=shards,
        dtype=dtype,
        dimension_separator=dimension_separator,
        compressors=compressors,
        extra_array_kwargs=extra_array_kwargs,
        overwrite=overwrite,
    )

    return OmeZarrContainer(group_handler=handler, axes_setup=axes_setup)

ngio.create_ome_zarr_from_array

create_ome_zarr_from_array(
    store: StoreOrGroup,
    array: ndarray,
    pixelsize: float | tuple[float, float],
    z_spacing: float = 1.0,
    time_spacing: float = 1.0,
    scaling_factors: Sequence[float]
    | Literal["auto"] = "auto",
    levels: int | list[str] = 5,
    translation: Sequence[float] | None = None,
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
    axes_names: Sequence[str] | None = None,
    channels_meta: Sequence[str | Channel] | None = None,
    percentiles: tuple[float, float] = (0.1, 99.9),
    name: str | None = None,
    axes_setup: AxesSetup | None = None,
    ngff_version: NgffVersions = DefaultNgffVersion,
    chunks: ChunksLike = "auto",
    shards: ShardsLike | None = None,
    dimension_separator: Literal[".", "/"] = "/",
    compressors: CompressorLike = "auto",
    extra_array_kwargs: Mapping[str, Any] | None = None,
    overwrite: bool = False,
) -> OmeZarrContainer

Create an OME-Zarr image from a numpy array.

Parameters:

  • store (StoreOrGroup) –

    The Zarr store or group to create the image in.

  • array (ndarray) –

    The image data.

  • pixelsize (float | tuple[float, float] | None) –

    The pixel size in x and y dimensions. A value to write, not a lookup key; to select an existing level see pixel_size on the getters.

  • z_spacing (float, default: 1.0 ) –

    The spacing between z slices. Defaults to 1.0.

  • time_spacing (float, default: 1.0 ) –

    The spacing between time points. Defaults to 1.0.

  • scaling_factors (Sequence[float] | Literal['auto'], default: 'auto' ) –

    The down-scaling factors for the pyramid levels. Defaults to "auto".

  • levels (int | list[str], default: 5 ) –

    The number of levels in the pyramid or a list of level names. Defaults to 5.

  • translation (Sequence[float] | None, default: None ) –

    The translation for each axis. at the highest resolution level. Defaults to None.

  • space_unit (SpaceUnits, default: DefaultSpaceUnit ) –

    The unit of space. Defaults to DefaultSpaceUnit.

  • time_unit (TimeUnits, default: DefaultTimeUnit ) –

    The unit of time. Defaults to DefaultTimeUnit.

  • axes_names (Sequence[str] | None, default: None ) –

    The names of the axes. If None the canonical names are used. Defaults to None.

  • channels_meta (Sequence[str | Channel] | None, default: None ) –

    The channels metadata. Defaults to None.

  • percentiles (tuple[float, float], default: (0.1, 99.9) ) –

    The percentiles of the channels for computing display ranges. Defaults to (0.1, 99.9).

  • name (str | None, default: None ) –

    The name of the image. Defaults to None.

  • axes_setup (AxesSetup | None, default: None ) –

    Axes setup to create ome-zarr with non-standard axes configurations. Defaults to None.

  • ngff_version (NgffVersions, default: DefaultNgffVersion ) –

    The version of the OME-Zarr specification. Defaults to DefaultNgffVersion.

  • chunks (ChunksLike, default: 'auto' ) –

    The chunk shape. Defaults to "auto".

  • shards (ShardsLike | None, default: None ) –

    The shard shape. Defaults to None.

  • dimension_separator (Literal['.', '/'], default: '/' ) –

    The separator to use for dimensions. Defaults to "/".

  • compressors (CompressorLike, default: 'auto' ) –

    The compressors to use. Defaults to "auto".

  • extra_array_kwargs (Mapping[str, Any] | None, default: None ) –

    Extra arguments to pass to the zarr array creation. Defaults to None.

  • overwrite (bool, default: False ) –

    Whether to overwrite an existing image. Defaults to False.

Source code in src/ngio/images/_ome_zarr_container.py
def create_ome_zarr_from_array(
    store: StoreOrGroup,
    array: np.ndarray,
    pixelsize: float | tuple[float, float],
    z_spacing: float = 1.0,
    time_spacing: float = 1.0,
    scaling_factors: Sequence[float] | Literal["auto"] = "auto",
    levels: int | list[str] = 5,
    translation: Sequence[float] | None = None,
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
    axes_names: Sequence[str] | None = None,
    channels_meta: Sequence[str | Channel] | None = None,
    percentiles: tuple[float, float] = (0.1, 99.9),
    name: str | None = None,
    axes_setup: AxesSetup | None = None,
    ngff_version: NgffVersions = DefaultNgffVersion,
    chunks: ChunksLike = "auto",
    shards: ShardsLike | None = None,
    dimension_separator: Literal[".", "/"] = "/",
    compressors: CompressorLike = "auto",
    extra_array_kwargs: Mapping[str, Any] | None = None,
    overwrite: bool = False,
) -> OmeZarrContainer:
    """Create an OME-Zarr image from a numpy array.

    Args:
        store (StoreOrGroup): The Zarr store or group to create the image in.
        array (np.ndarray): The image data.
        pixelsize (float | tuple[float, float] | None): The pixel size in x and y
            dimensions.
            A value to write, not a lookup key; to select an existing
            level see `pixel_size` on the getters.
        z_spacing (float): The spacing between z slices. Defaults to 1.0.
        time_spacing (float): The spacing between time points. Defaults to 1.0.
        scaling_factors (Sequence[float] | Literal["auto"]): The down-scaling factors
            for the pyramid levels. Defaults to "auto".
        levels (int | list[str]): The number of levels in the pyramid or a list of
            level names. Defaults to 5.
        translation (Sequence[float] | None): The translation for each axis.
            at the highest resolution level. Defaults to None.
        space_unit (SpaceUnits): The unit of space. Defaults to DefaultSpaceUnit.
        time_unit (TimeUnits): The unit of time. Defaults to DefaultTimeUnit.
        axes_names (Sequence[str] | None): The names of the axes. If None the
            canonical names are used. Defaults to None.
        channels_meta (Sequence[str | Channel] | None): The channels metadata.
            Defaults to None.
        percentiles (tuple[float, float]): The percentiles of the channels for
            computing display ranges. Defaults to (0.1, 99.9).
        name (str | None): The name of the image. Defaults to None.
        axes_setup (AxesSetup | None): Axes setup to create ome-zarr with
            non-standard axes configurations. Defaults to None.
        ngff_version (NgffVersions): The version of the OME-Zarr specification.
            Defaults to DefaultNgffVersion.
        chunks (ChunksLike): The chunk shape. Defaults to "auto".
        shards (ShardsLike | None): The shard shape. Defaults to None.
        dimension_separator (Literal[".", "/"]): The separator to use for
            dimensions. Defaults to "/".
        compressors (CompressorLike): The compressors to use. Defaults to "auto".
        extra_array_kwargs (Mapping[str, Any] | None): Extra arguments to pass to
            the zarr array creation. Defaults to None.
        overwrite (bool): Whether to overwrite an existing image. Defaults to False.
    """
    if len(percentiles) != 2:
        raise NgioValueError(
            f"'percentiles' must be a tuple of two values. Got {percentiles}"
        )
    ome_zarr = create_empty_ome_zarr(
        store=store,
        shape=array.shape,
        pixelsize=pixelsize,
        z_spacing=z_spacing,
        time_spacing=time_spacing,
        scaling_factors=scaling_factors,
        levels=levels,
        translation=translation,
        space_unit=space_unit,
        time_unit=time_unit,
        axes_names=axes_names,
        channels_meta=channels_meta,
        name=name,
        axes_setup=axes_setup,
        ngff_version=ngff_version,
        chunks=chunks,
        shards=shards,
        dtype=str(array.dtype),
        dimension_separator=dimension_separator,
        compressors=compressors,
        extra_array_kwargs=extra_array_kwargs,
        overwrite=overwrite,
    )
    image = ome_zarr.get_image()
    image.set_array(array)
    image.consolidate()
    ome_zarr.set_channel_windows_with_percentiles(percentiles=percentiles)
    return ome_zarr

OmeZarrContainer

ngio.OmeZarrContainer

OmeZarrContainer(
    group_handler: ZarrGroupHandler,
    table_container: TablesContainer | None = None,
    label_container: LabelsContainer | None = None,
    axes_setup: AxesSetup | None = None,
    validate_arrays: bool = False,
)

This class is an object representation of an OME-Zarr image.

It provides methods to access
  • The multiscale image metadata
  • To open images at different levels of resolution
  • To access labels and tables associated with the image.
  • To derive new images, labels, and add tables to the image.
  • To modify the image metadata, such as axes units and channel metadata.

Attributes:

Initialize the OmeZarrContainer.

Parameters:

  • group_handler (ZarrGroupHandler) –

    The Zarr group handler.

  • table_container (TablesContainer | None, default: None ) –

    The tables container.

  • label_container (LabelsContainer | None, default: None ) –

    The labels container.

  • axes_setup (AxesSetup | None, default: None ) –

    Axes setup to load ome-zarr with non-standard axes configurations.

  • validate_arrays (bool, default: False ) –

    Whether to open every level listed in the multiscale metadata, so a missing or malformed array fails here rather than on first access.

Source code in src/ngio/images/_ome_zarr_container.py
@deprecated_alias(validate_paths="validate_arrays")
def __init__(
    self,
    group_handler: ZarrGroupHandler,
    table_container: TablesContainer | None = None,
    label_container: LabelsContainer | None = None,
    axes_setup: AxesSetup | None = None,
    validate_arrays: bool = False,
) -> None:
    """Initialize the OmeZarrContainer.

    Args:
        group_handler: The Zarr group handler.
        table_container: The tables container.
        label_container: The labels container.
        axes_setup: Axes setup to load ome-zarr with non-standard axes
            configurations.
        validate_arrays: Whether to open every level listed in the multiscale
            metadata, so a missing or malformed array fails here rather than
            on first access.
    """
    self._group_handler = group_handler
    self._images_container = ImagesContainer(
        self._group_handler,
        axes_setup=axes_setup,
        validate_arrays=validate_arrays,
    )
    self._labels_container = label_container
    self._tables_container = table_container

images_container property

images_container: ImagesContainer

Return the images container.

Returns:

labels_container property

labels_container: LabelsContainer

Return the labels container.

tables_container property

tables_container: TablesContainer

Return the tables container.

meta property

meta: NgioImageMeta

Return the image metadata.

axes_setup property

axes_setup: AxesSetup

Return the axes setup.

levels property

levels: int

Return the number of levels in the image.

level_paths property

level_paths: list[str]

Return the paths of the levels in the image.

is_3d property

is_3d: bool

Return True if the image is 3D.

is_2d property

is_2d: bool

Return True if the image is 2D.

is_time_series property

is_time_series: bool

Return True if the image is a time series.

is_2d_time_series property

is_2d_time_series: bool

Return True if the image is a 2D time series.

is_3d_time_series property

is_3d_time_series: bool

Return True if the image is a 3D time series.

is_multi_channels property

is_multi_channels: bool

Return True if the image is multichannel.

space_unit property

space_unit: str | None

Return the space unit of the image.

time_unit property

time_unit: str | None

Return the time unit of the image.

channel_labels property

channel_labels: list[str]

Return the channels of the image.

wavelength_ids property

wavelength_ids: list[str | None]

Return the list of wavelength of the image.

num_channels property

num_channels: int

Return the number of channels.

get_channel_idx

get_channel_idx(
    channel_label: str | None = None,
    wavelength_id: str | None = None,
) -> int

Get the index of a channel by its label or wavelength ID.

Source code in src/ngio/images/_ome_zarr_container.py
def get_channel_idx(
    self, channel_label: str | None = None, wavelength_id: str | None = None
) -> int:
    """Get the index of a channel by its label or wavelength ID."""
    return self.images_container.get_channel_idx(
        channel_label=channel_label, wavelength_id=wavelength_id
    )

set_channel_meta

set_channel_meta(
    channel_meta: ChannelsMeta | None = None,
) -> None

Set the channels metadata.

Parameters:

  • channel_meta (ChannelsMeta | None, default: None ) –

    The channels metadata to set. If None, a default metadata is created from the number of channels in the image.

Source code in src/ngio/images/_ome_zarr_container.py
def set_channel_meta(
    self,
    channel_meta: ChannelsMeta | None = None,
) -> None:
    """Set the channels metadata.

    Args:
        channel_meta: The channels metadata to set. If `None`, a default
            metadata is created from the number of channels in the image.
    """
    self._images_container.set_channel_meta(channel_meta=channel_meta)

set_channel_labels

set_channel_labels(labels: Sequence[str]) -> None

Update the labels of the channels.

Parameters:

  • labels (Sequence[str]) –

    The new labels for the channels.

Source code in src/ngio/images/_ome_zarr_container.py
def set_channel_labels(
    self,
    labels: Sequence[str],
) -> None:
    """Update the labels of the channels.

    Args:
        labels (Sequence[str]): The new labels for the channels.
    """
    self._images_container.set_channel_labels(labels=labels)

set_channel_colors

set_channel_colors(colors: Sequence[str]) -> None

Update the colors of the channels.

Parameters:

  • colors (Sequence[str]) –

    The new colors for the channels.

Source code in src/ngio/images/_ome_zarr_container.py
def set_channel_colors(
    self,
    colors: Sequence[str],
) -> None:
    """Update the colors of the channels.

    Args:
        colors (Sequence[str]): The new colors for the channels.
    """
    self._images_container.set_channel_colors(colors=colors)

set_channel_windows

set_channel_windows(
    starts_ends: Sequence[tuple[float, float]],
    min_max: Sequence[tuple[float, float]] | None = None,
) -> None

Update the channel windows.

These values are used by viewers to set the display range of each channel.

Parameters:

  • starts_ends (Sequence[tuple[float, float]]) –

    The start and end values for each channel.

  • min_max (Sequence[tuple[float, float]] | None, default: None ) –

    The min and max values for each channel. If None, the min and max values will not be updated.

Source code in src/ngio/images/_ome_zarr_container.py
def set_channel_windows(
    self,
    starts_ends: Sequence[tuple[float, float]],
    min_max: Sequence[tuple[float, float]] | None = None,
) -> None:
    """Update the channel windows.

    These values are used by viewers to set the display
    range of each channel.

    Args:
        starts_ends (Sequence[tuple[float, float]]): The start and end values
            for each channel.
        min_max (Sequence[tuple[float, float]] | None): The min and max values
            for each channel. If None, the min and max values will not be updated.
    """
    self._images_container.set_channel_windows(
        starts_ends=starts_ends,
        min_max=min_max,
    )

set_channel_windows_with_percentiles

set_channel_windows_with_percentiles(
    percentiles: tuple[float, float]
    | list[tuple[float, float]] = (0.1, 99.9),
) -> None

Update the channel windows using percentiles.

Parameters:

  • percentiles (tuple[float, float] | list[tuple[float, float]], default: (0.1, 99.9) ) –

    The start and end percentiles for each channel. If a single tuple is provided, the same percentiles will be used for all channels.

Source code in src/ngio/images/_ome_zarr_container.py
def set_channel_windows_with_percentiles(
    self,
    percentiles: tuple[float, float] | list[tuple[float, float]] = (0.1, 99.9),
) -> None:
    """Update the channel windows using percentiles.

    Args:
        percentiles (tuple[float, float] | list[tuple[float, float]]):
            The start and end percentiles for each channel.
            If a single tuple is provided,
            the same percentiles will be used for all channels.
    """
    self._images_container.set_channel_windows_with_percentiles(
        percentiles=percentiles
    )

set_axes_units

set_axes_units(
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
    set_labels: bool = True,
) -> None

Set the space and time units of the image axes.

Parameters:

  • space_unit (SpaceUnits, default: DefaultSpaceUnit ) –

    The unit of space.

  • time_unit (TimeUnits, default: DefaultTimeUnit ) –

    The unit of time.

  • set_labels (bool, default: True ) –

    Whether to set the units for the labels as well.

Source code in src/ngio/images/_ome_zarr_container.py
def set_axes_units(
    self,
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
    set_labels: bool = True,
) -> None:
    """Set the space and time units of the image axes.

    Args:
        space_unit: The unit of space.
        time_unit: The unit of time.
        set_labels: Whether to set the units for the labels as well.
    """
    if set_labels:
        for label_name in self.list_labels():
            label = self.get_label(label_name)
            label.set_axes_units(space_unit=space_unit, time_unit=time_unit)
    self._images_container.set_axes_units(
        space_unit=space_unit, time_unit=time_unit
    )

set_axes_names

set_axes_names(axes_names: Sequence[str]) -> None

Set the axes names of the image.

Parameters:

  • axes_names (Sequence[str]) –

    The axes names of the image.

Source code in src/ngio/images/_ome_zarr_container.py
def set_axes_names(
    self,
    axes_names: Sequence[str],
) -> None:
    """Set the axes names of the image.

    Args:
        axes_names (Sequence[str]): The axes names of the image.
    """
    self._images_container.set_axes_names(axes_names=axes_names)

set_name

set_name(name: str) -> None

Set the name of the image in the metadata.

This does not change the group name or any paths.

Parameters:

  • name (str) –

    The name of the image.

Source code in src/ngio/images/_ome_zarr_container.py
def set_name(
    self,
    name: str,
) -> None:
    """Set the name of the image in the metadata.

    This does not change the group name or any paths.

    Args:
        name (str): The name of the image.
    """
    self._images_container.set_name(name=name)

get_image

get_image(
    path: str | None = None,
    pixel_size: PixelSize | None = None,
    strict: bool = False,
) -> Image

Get an image at a specific level.

Parameters:

  • path (str | None, default: None ) –

    The path to the image in the ome_zarr file.

  • pixel_size (PixelSize | None, default: None ) –

    Select the pyramid level whose pixel size matches this one. A lookup key, not a value to write; to set a pixel size see pixelsize on the create/derive entry points.

  • strict (bool, default: False ) –

    Only used if the pixel size is provided. If True, the pixel size must match the image pixel size exactly. If False, the closest pixel size level will be returned.

Source code in src/ngio/images/_ome_zarr_container.py
def get_image(
    self,
    path: str | None = None,
    pixel_size: PixelSize | None = None,
    strict: bool = False,
) -> Image:
    """Get an image at a specific level.

    Args:
        path (str | None): The path to the image in the ome_zarr file.
        pixel_size: Select the pyramid level whose pixel size matches this one.
            A lookup key, not a value to write; to set a pixel size see
            `pixelsize` on the create/derive entry points.
        strict (bool): Only used if the pixel size is provided. If True, the
            pixel size must match the image pixel size exactly. If False, the
            closest pixel size level will be returned.

    """
    return self._images_container.get(
        path=path, pixel_size=pixel_size, strict=strict
    )

get_masked_image

get_masked_image(
    masking_label_name: str | None = None,
    masking_table_name: str | None = None,
    path: str | None = None,
    pixel_size: PixelSize | None = None,
    strict: bool = False,
) -> MaskedImage

Get a masked image at a specific level.

Parameters:

  • masking_label_name (str | None, default: None ) –

    The name of the masking label to use. If None, the masking table must be provided.

  • masking_table_name (str | None, default: None ) –

    The name of the masking table to use. If None, the masking label must be provided.

  • path (str | None, default: None ) –

    The path to the image in the ome_zarr file. If None, the first level will be used.

  • pixel_size (PixelSize | None, default: None ) –

    Select the pyramid level whose pixel size matches this one. A lookup key, not a value to write; to set a pixel size see pixelsize on the create/derive entry points. This is only used if path is None.

  • strict (bool, default: False ) –

    Only used if the pixel size is provided. If True, the pixel size must match the image pixel size exactly. If False, the closest pixel size level will be returned.

Source code in src/ngio/images/_ome_zarr_container.py
def get_masked_image(
    self,
    masking_label_name: str | None = None,
    masking_table_name: str | None = None,
    path: str | None = None,
    pixel_size: PixelSize | None = None,
    strict: bool = False,
) -> MaskedImage:
    """Get a masked image at a specific level.

    Args:
        masking_label_name (str | None): The name of the masking label to use.
            If None, the masking table must be provided.
        masking_table_name (str | None): The name of the masking table to use.
            If None, the masking label must be provided.
        path (str | None): The path to the image in the ome_zarr file.
            If None, the first level will be used.
        pixel_size: Select the pyramid level whose pixel size matches this one.
            A lookup key, not a value to write; to set a pixel size see
            `pixelsize` on the create/derive entry points.
            This is only used if path is None.
        strict (bool): Only used if the pixel size is provided. If True, the
            pixel size must match the image pixel size exactly. If False, the
            closest pixel size level will be returned.
    """
    image = self.get_image(path=path, pixel_size=pixel_size, strict=strict)
    masking_label, masking_table = self._find_matching_masking_label(
        masking_label_name=masking_label_name,
        masking_table_name=masking_table_name,
        pixel_size=image.pixel_size,
    )
    return MaskedImage(
        group_handler=image._group_handler,
        path=image.path,
        meta_handler=image.meta_handler,
        label=masking_label,
        masking_roi_table=masking_table,
    )

derive_image

derive_image(
    store: StoreOrGroup,
    ref_path: str | None = None,
    shape: Sequence[int] | None = None,
    pixelsize: float | tuple[float, float] | None = None,
    z_spacing: float | None = None,
    time_spacing: float | None = None,
    name: str | None = None,
    translation: Sequence[float] | None = None,
    channels_policy: Literal["squeeze", "same", "singleton"]
    | int = "same",
    channels_meta: Sequence[str | Channel] | None = None,
    ngff_version: NgffVersions | None = None,
    chunks: ChunksLike | None = None,
    shards: ShardsLike | None = None,
    dtype: str | None = None,
    dimension_separator: Literal[".", "/"] | None = None,
    compressors: CompressorLike | None = None,
    extra_array_kwargs: Mapping[str, Any] | None = None,
    overwrite: bool = False,
    copy_labels: bool = False,
    copy_tables: bool = False,
) -> OmeZarrContainer

Derive a new OME-Zarr container from the current image.

If a kwarg is not provided, the value from the reference image will be used.

Parameters:

  • store (StoreOrGroup) –

    The Zarr store or group to create the image in.

  • ref_path (str | None, default: None ) –

    The path to the reference image in the image container.

  • shape (Sequence[int] | None, default: None ) –

    The shape of the new image.

  • pixelsize (float | tuple[float, float] | None, default: None ) –

    The pixel size of the new image. A value to write, not a lookup key; to select an existing level see pixel_size on the getters.

  • z_spacing (float | None, default: None ) –

    The z spacing of the new image.

  • time_spacing (float | None, default: None ) –

    The time spacing of the new image.

  • name (str | None, default: None ) –

    The name of the new image.

  • translation (Sequence[float] | None, default: None ) –

    The translation for each axis at the highest resolution level. Defaults to None.

  • channels_policy (Literal['squeeze', 'same', 'singleton'] | int, default: 'same' ) –

    Possible policies: - If "squeeze", the channels axis will be removed (no matter its size). - If "same", the channels axis will be kept as is (if it exists). - If "singleton", the channels axis will be set to size 1. - If an integer is provided, the channels axis will be changed to have that size.

  • channels_meta (Sequence[str | Channel] | None, default: None ) –

    The channels metadata of the new image.

  • ngff_version (NgffVersions | None, default: None ) –

    The NGFF version to use.

  • chunks (ChunksLike | None, default: None ) –

    The chunk shape of the new image.

  • shards (ShardsLike | None, default: None ) –

    The shard shape of the new image.

  • dtype (str | None, default: None ) –

    The data type of the new image.

  • dimension_separator (Literal['.', '/'] | None, default: None ) –

    The separator to use for dimensions.

  • compressors (CompressorLike | None, default: None ) –

    The compressors to use.

  • extra_array_kwargs (Mapping[str, Any] | None, default: None ) –

    Extra arguments to pass to the zarr array creation.

  • overwrite (bool, default: False ) –

    Whether to overwrite an existing image. Defaults to False.

  • copy_labels (bool, default: False ) –

    Whether to copy the labels from the current image. Defaults to False.

  • copy_tables (bool, default: False ) –

    Whether to copy the tables from the current image. Defaults to False.

Returns:

Source code in src/ngio/images/_ome_zarr_container.py
def derive_image(
    self,
    store: StoreOrGroup,
    ref_path: str | None = None,
    # Metadata parameters
    shape: Sequence[int] | None = None,
    pixelsize: float | tuple[float, float] | None = None,
    z_spacing: float | None = None,
    time_spacing: float | None = None,
    name: str | None = None,
    translation: Sequence[float] | None = None,
    channels_policy: Literal["squeeze", "same", "singleton"] | int = "same",
    channels_meta: Sequence[str | Channel] | None = None,
    ngff_version: NgffVersions | None = None,
    # Zarr Array parameters
    chunks: ChunksLike | None = None,
    shards: ShardsLike | None = None,
    dtype: str | None = None,
    dimension_separator: Literal[".", "/"] | None = None,
    compressors: CompressorLike | None = None,
    extra_array_kwargs: Mapping[str, Any] | None = None,
    overwrite: bool = False,
    # Copy from current image
    copy_labels: bool = False,
    copy_tables: bool = False,
) -> "OmeZarrContainer":
    """Derive a new OME-Zarr container from the current image.

    If a kwarg is not provided, the value from the reference image will be used.

    Args:
        store (StoreOrGroup): The Zarr store or group to create the image in.
        ref_path (str | None): The path to the reference image in the image
            container.
        shape (Sequence[int] | None): The shape of the new image.
        pixelsize (float | tuple[float, float] | None): The pixel size of the new
            image.
            A value to write, not a lookup key; to select an existing
            level see `pixel_size` on the getters.
        z_spacing (float | None): The z spacing of the new image.
        time_spacing (float | None): The time spacing of the new image.
        name (str | None): The name of the new image.
        translation (Sequence[float] | None): The translation for each axis
            at the highest resolution level. Defaults to None.
        channels_policy (Literal["squeeze", "same", "singleton"] | int): Possible
            policies:
            - If "squeeze", the channels axis will be removed (no matter its size).
            - If "same", the channels axis will be kept as is (if it exists).
            - If "singleton", the channels axis will be set to size 1.
            - If an integer is provided, the channels axis will be changed to have
                that size.
        channels_meta (Sequence[str | Channel] | None): The channels metadata
            of the new image.
        ngff_version (NgffVersions | None): The NGFF version to use.
        chunks (ChunksLike | None): The chunk shape of the new image.
        shards (ShardsLike | None): The shard shape of the new image.
        dtype (str | None): The data type of the new image.
        dimension_separator (Literal[".", "/"] | None): The separator to use for
            dimensions.
        compressors (CompressorLike | None): The compressors to use.
        extra_array_kwargs (Mapping[str, Any] | None): Extra arguments to pass to
            the zarr array creation.
        overwrite (bool): Whether to overwrite an existing image. Defaults to False.
        copy_labels (bool): Whether to copy the labels from the current image.
            Defaults to False.
        copy_tables (bool): Whether to copy the tables from the current image.
            Defaults to False.

    Returns:
        OmeZarrContainer: The new derived OME-Zarr container.

    """
    new_container = self._images_container.derive(
        store=store,
        ref_path=ref_path,
        shape=shape,
        pixelsize=pixelsize,
        z_spacing=z_spacing,
        time_spacing=time_spacing,
        name=name,
        translation=translation,
        channels_meta=channels_meta,
        channels_policy=channels_policy,
        ngff_version=ngff_version,
        chunks=chunks,
        shards=shards,
        dtype=dtype,
        dimension_separator=dimension_separator,
        compressors=compressors,
        extra_array_kwargs=extra_array_kwargs,
        overwrite=overwrite,
    )
    new_ome_zarr = OmeZarrContainer(
        group_handler=new_container._group_handler,
        validate_arrays=False,
        axes_setup=new_container.meta.axes_handler.axes_setup,
    )

    if copy_labels:
        self.labels_container._group_handler.copy_group(
            new_ome_zarr.labels_container._group_handler.group
        )

    if copy_tables:
        self.tables_container._group_handler.copy_group(
            new_ome_zarr.tables_container._group_handler.group
        )
    return new_ome_zarr

list_tables

list_tables(
    filter_types: TypedTable | str | None = None,
) -> list[str]

List all tables in the image.

Source code in src/ngio/images/_ome_zarr_container.py
def list_tables(self, filter_types: TypedTable | str | None = None) -> list[str]:
    """List all tables in the image."""
    table_container = self._get_tables_container(create_mode=False)
    if table_container is None:
        return []

    return table_container.list(
        filter_types=filter_types,
    )

list_roi_tables

list_roi_tables() -> list[str]

List all ROI tables in the image.

Returns [] when the image has no tables, matching list_tables.

Source code in src/ngio/images/_ome_zarr_container.py
def list_roi_tables(self) -> list[str]:
    """List all ROI tables in the image.

    Returns `[]` when the image has no tables, matching `list_tables`.
    """
    table_container = self._get_tables_container(create_mode=False)
    if table_container is None:
        return []

    roi = table_container.list(filter_types="roi_table")
    masking_roi = table_container.list(filter_types="masking_roi_table")
    return roi + masking_roi

get_roi_table

get_roi_table(name: str) -> RoiTable

Get a ROI table from the image.

Parameters:

  • name (str) –

    The name of the table.

Source code in src/ngio/images/_ome_zarr_container.py
def get_roi_table(self, name: str) -> RoiTable:
    """Get a ROI table from the image.

    Args:
        name (str): The name of the table.
    """
    table = self.tables_container.get(name=name, strict=True)
    if not isinstance(table, RoiTable):
        raise NgioValueError(f"Table {name} is not a ROI table. Got {type(table)}")
    return table

get_masking_roi_table

get_masking_roi_table(name: str) -> MaskingRoiTable

Get a masking ROI table from the image.

Parameters:

  • name (str) –

    The name of the table.

Source code in src/ngio/images/_ome_zarr_container.py
def get_masking_roi_table(self, name: str) -> MaskingRoiTable:
    """Get a masking ROI table from the image.

    Args:
        name (str): The name of the table.
    """
    table = self.tables_container.get(name=name, strict=True)
    if not isinstance(table, MaskingRoiTable):
        raise NgioValueError(
            f"Table {name} is not a masking ROI table. Got {type(table)}"
        )
    return table

get_feature_table

get_feature_table(name: str) -> FeatureTable

Get a feature table from the image.

Parameters:

  • name (str) –

    The name of the table.

Source code in src/ngio/images/_ome_zarr_container.py
def get_feature_table(self, name: str) -> FeatureTable:
    """Get a feature table from the image.

    Args:
        name (str): The name of the table.
    """
    table = self.tables_container.get(name=name, strict=True)
    if not isinstance(table, FeatureTable):
        raise NgioValueError(
            f"Table {name} is not a feature table. Got {type(table)}"
        )
    return table

get_generic_roi_table

get_generic_roi_table(name: str) -> GenericRoiTable

Get a generic ROI table from the image.

Parameters:

  • name (str) –

    The name of the table.

Source code in src/ngio/images/_ome_zarr_container.py
def get_generic_roi_table(self, name: str) -> GenericRoiTable:
    """Get a generic ROI table from the image.

    Args:
        name (str): The name of the table.
    """
    table = self.tables_container.get(name=name, strict=True)
    if not isinstance(table, GenericRoiTable):
        raise NgioValueError(
            f"Table {name} is not a generic ROI table. Got {type(table)}"
        )
    return table

get_condition_table

get_condition_table(name: str) -> ConditionTable

Get a condition table from the image.

Parameters:

  • name (str) –

    The name of the table.

Source code in src/ngio/images/_ome_zarr_container.py
def get_condition_table(self, name: str) -> ConditionTable:
    """Get a condition table from the image.

    Args:
        name (str): The name of the table.
    """
    table = self.tables_container.get(name=name, strict=True)
    if not isinstance(table, ConditionTable):
        raise NgioValueError(
            f"Table {name} is not a condition table. Got {type(table)}"
        )
    return table

get_table

get_table(name: str) -> Table

Get a table from the image.

Parameters:

  • name (str) –

    The name of the table.

Source code in src/ngio/images/_ome_zarr_container.py
def get_table(self, name: str) -> Table:
    """Get a table from the image.

    Args:
        name (str): The name of the table.
    """
    return self.tables_container.get(name=name, strict=False)

get_table_as

get_table_as(
    name: str,
    table_cls: type[TableType],
    backend: TableBackend | None = None,
) -> TableType

Get a table from the image as a specific type.

Parameters:

  • name (str) –

    The name of the table.

  • table_cls (type[TableType]) –

    The type of the table.

  • backend (TableBackend | None, default: None ) –

    The backend to use. If None, the default backend is used.

Source code in src/ngio/images/_ome_zarr_container.py
def get_table_as(
    self,
    name: str,
    table_cls: type[TableType],
    backend: TableBackend | None = None,
) -> TableType:
    """Get a table from the image as a specific type.

    Args:
        name (str): The name of the table.
        table_cls (type[TableType]): The type of the table.
        backend (TableBackend | None): The backend to use. If None,
            the default backend is used.
    """
    return self.tables_container.get_as(
        name=name,
        table_cls=table_cls,
        backend=backend,
    )

build_image_roi_table

build_image_roi_table(
    name: str | None = "image",
) -> RoiTable

Compute the ROI table for an image.

Source code in src/ngio/images/_ome_zarr_container.py
def build_image_roi_table(self, name: str | None = "image") -> RoiTable:
    """Compute the ROI table for an image."""
    return self.get_image().build_image_roi_table(name=name)

build_masking_roi_table

build_masking_roi_table(label: str) -> MaskingRoiTable

Compute the masking ROI table for a label.

Source code in src/ngio/images/_ome_zarr_container.py
def build_masking_roi_table(self, label: str) -> MaskingRoiTable:
    """Compute the masking ROI table for a label."""
    return self.get_label(label).build_masking_roi_table()

add_table

add_table(
    name: str,
    table: Table,
    backend: TableBackend | None = None,
    overwrite: bool = False,
) -> None

Add a table to the image.

If backend is None (default), the table's own backend is preserved.

Source code in src/ngio/images/_ome_zarr_container.py
def add_table(
    self,
    name: str,
    table: Table,
    backend: TableBackend | None = None,
    overwrite: bool = False,
) -> None:
    """Add a table to the image.

    If `backend` is `None` (default), the table's own backend is preserved.
    """
    self.tables_container.add(
        name=name, table=table, backend=backend, overwrite=overwrite
    )

delete_table

delete_table(name: str, missing_ok: bool = False) -> None

Delete a table from the group.

Parameters:

  • name (str) –

    The name of the table to delete.

  • missing_ok (bool, default: False ) –

    If True, do not raise an error if the table does not exist.

Source code in src/ngio/images/_ome_zarr_container.py
def delete_table(self, name: str, missing_ok: bool = False) -> None:
    """Delete a table from the group.

    Args:
        name (str): The name of the table to delete.
        missing_ok (bool): If True, do not raise an error if the table does not
            exist.

    """
    table_container = self._get_tables_container(create_mode=False)
    if table_container is None and missing_ok:
        return
    if table_container is None:
        raise NgioValueError(
            f"No tables found in the image, cannot delete {name}. "
            "Set missing_ok=True to ignore this error."
        )
    table_container.delete(name=name, missing_ok=missing_ok)

list_labels

list_labels() -> list[str]

List all labels in the image.

Source code in src/ngio/images/_ome_zarr_container.py
def list_labels(self) -> list[str]:
    """List all labels in the image."""
    label_container = self._get_labels_container(create_mode=False)
    if label_container is None:
        return []
    return label_container.list()

get_label

get_label(
    name: str,
    path: str | None = None,
    pixel_size: PixelSize | None = None,
    strict: bool = False,
) -> Label

Get a label from the group.

Parameters:

  • name (str) –

    The name of the label.

  • path (str | None, default: None ) –

    The path to the image in the ome_zarr file.

  • pixel_size (PixelSize | None, default: None ) –

    Select the pyramid level whose pixel size matches this one. A lookup key, not a value to write; to set a pixel size see pixelsize on the create/derive entry points.

  • strict (bool, default: False ) –

    Only used if the pixel size is provided. If True, the pixel size must match the image pixel size exactly. If False, the closest pixel size level will be returned.

Source code in src/ngio/images/_ome_zarr_container.py
def get_label(
    self,
    name: str,
    path: str | None = None,
    pixel_size: PixelSize | None = None,
    strict: bool = False,
) -> Label:
    """Get a label from the group.

    Args:
        name (str): The name of the label.
        path (str | None): The path to the image in the ome_zarr file.
        pixel_size: Select the pyramid level whose pixel size matches this one.
            A lookup key, not a value to write; to set a pixel size see
            `pixelsize` on the create/derive entry points.
        strict (bool): Only used if the pixel size is provided. If True, the
            pixel size must match the image pixel size exactly. If False, the
            closest pixel size level will be returned.
    """
    return self.labels_container.get(
        name=name, path=path, pixel_size=pixel_size, strict=strict
    )

get_masked_label

get_masked_label(
    label_name: str,
    masking_label_name: str | None = None,
    masking_table_name: str | None = None,
    path: str | None = None,
    pixel_size: PixelSize | None = None,
    strict: bool = False,
) -> MaskedLabel

Get a masked image at a specific level.

Parameters:

  • label_name (str) –

    The name of the label.

  • masking_label_name (str | None, default: None ) –

    The name of the masking label.

  • masking_table_name (str | None, default: None ) –

    The name of the masking table.

  • path (str | None, default: None ) –

    The path to the image in the ome_zarr file.

  • pixel_size (PixelSize | None, default: None ) –

    Select the pyramid level whose pixel size matches this one. A lookup key, not a value to write; to set a pixel size see pixelsize on the create/derive entry points.

  • strict (bool, default: False ) –

    Only used if the pixel size is provided. If True, the pixel size must match the image pixel size exactly. If False, the closest pixel size level will be returned.

Source code in src/ngio/images/_ome_zarr_container.py
def get_masked_label(
    self,
    label_name: str,
    masking_label_name: str | None = None,
    masking_table_name: str | None = None,
    path: str | None = None,
    pixel_size: PixelSize | None = None,
    strict: bool = False,
) -> MaskedLabel:
    """Get a masked image at a specific level.

    Args:
        label_name (str): The name of the label.
        masking_label_name (str | None): The name of the masking label.
        masking_table_name (str | None): The name of the masking table.
        path (str | None): The path to the image in the ome_zarr file.
        pixel_size: Select the pyramid level whose pixel size matches this one.
            A lookup key, not a value to write; to set a pixel size see
            `pixelsize` on the create/derive entry points.
        strict (bool): Only used if the pixel size is provided. If True, the
            pixel size must match the image pixel size exactly. If False, the
            closest pixel size level will be returned.
    """
    label = self.get_label(
        name=label_name, path=path, pixel_size=pixel_size, strict=strict
    )
    masking_label, masking_table = self._find_matching_masking_label(
        masking_label_name=masking_label_name,
        masking_table_name=masking_table_name,
        pixel_size=label.pixel_size,
    )
    return MaskedLabel(
        group_handler=label._group_handler,
        path=label.path,
        meta_handler=label.meta_handler,
        label=masking_label,
        masking_roi_table=masking_table,
    )

delete_label

delete_label(name: str, missing_ok: bool = False) -> None

Delete a label from the group.

Parameters:

  • name (str) –

    The name of the label to delete.

  • missing_ok (bool, default: False ) –

    If True, do not raise an error if the label does not exist.

Source code in src/ngio/images/_ome_zarr_container.py
def delete_label(self, name: str, missing_ok: bool = False) -> None:
    """Delete a label from the group.

    Args:
        name (str): The name of the label to delete.
        missing_ok (bool): If True, do not raise an error if the label does not
            exist.

    """
    label_container = self._get_labels_container(create_mode=False)
    if label_container is None and missing_ok:
        return
    if label_container is None:
        raise NgioValueError(
            f"No labels found in the image, cannot delete {name}. "
            "Set missing_ok=True to ignore this error."
        )
    label_container.delete(name=name, missing_ok=missing_ok)

derive_label

derive_label(
    name: str,
    ref_image: Image | Label | None = None,
    shape: Sequence[int] | None = None,
    pixelsize: float | tuple[float, float] | None = None,
    z_spacing: float | None = None,
    time_spacing: float | None = None,
    translation: Sequence[float] | None = None,
    channels_policy: Literal["same", "squeeze", "singleton"]
    | int = "squeeze",
    ngff_version: NgffVersions | None = None,
    chunks: ChunksLike | None = None,
    shards: ShardsLike | None = None,
    dtype: str | None = None,
    dimension_separator: Literal[".", "/"] | None = None,
    compressors: CompressorLike | None = None,
    extra_array_kwargs: Mapping[str, Any] | None = None,
    overwrite: bool = False,
) -> Label

Derive a new label from an existing image or label.

If a kwarg is not provided, the value from the reference image will be used.

Parameters:

  • name (str) –

    The name of the new label.

  • ref_image (Image | Label | None, default: None ) –

    The reference image to derive the new label from. If None, the first level image will be used.

  • shape (Sequence[int] | None, default: None ) –

    The shape of the new label.

  • pixelsize (float | tuple[float, float] | None, default: None ) –

    The pixel size of the new label. A value to write, not a lookup key; to select an existing level see pixel_size on the getters.

  • z_spacing (float | None, default: None ) –

    The z spacing of the new label.

  • time_spacing (float | None, default: None ) –

    The time spacing of the new label.

  • translation (Sequence[float] | None, default: None ) –

    The translation for each axis at the highest resolution level. Defaults to None.

  • channels_policy (Literal['same', 'squeeze', 'singleton'] | int, default: 'squeeze' ) –

    Possible policies: - If "squeeze", the channels axis will be removed (no matter its size). - If "same", the channels axis will be kept as is (if it exists). - If "singleton", the channels axis will be set to size 1. - If an integer is provided, the channels axis will be changed to have that size. Defaults to "squeeze".

  • ngff_version (NgffVersions | None, default: None ) –

    The NGFF version to use.

  • chunks (ChunksLike | None, default: None ) –

    The chunk shape of the new label.

  • shards (ShardsLike | None, default: None ) –

    The shard shape of the new label.

  • dtype (str | None, default: None ) –

    The data type of the new label.

  • dimension_separator (Literal['.', '/'] | None, default: None ) –

    The separator to use for dimensions.

  • compressors (CompressorLike | None, default: None ) –

    The compressors to use.

  • extra_array_kwargs (Mapping[str, Any] | None, default: None ) –

    Extra arguments to pass to the zarr array creation.

  • overwrite (bool, default: False ) –

    Whether to overwrite an existing label. Defaults to False.

Returns:

  • Label ( Label ) –

    The new derived label.

Source code in src/ngio/images/_ome_zarr_container.py
def derive_label(
    self,
    name: str,
    ref_image: Image | Label | None = None,
    # Metadata parameters
    shape: Sequence[int] | None = None,
    pixelsize: float | tuple[float, float] | None = None,
    z_spacing: float | None = None,
    time_spacing: float | None = None,
    translation: Sequence[float] | None = None,
    channels_policy: Literal["same", "squeeze", "singleton"] | int = "squeeze",
    ngff_version: NgffVersions | None = None,
    # Zarr Array parameters
    chunks: ChunksLike | None = None,
    shards: ShardsLike | None = None,
    dtype: str | None = None,
    dimension_separator: Literal[".", "/"] | None = None,
    compressors: CompressorLike | None = None,
    extra_array_kwargs: Mapping[str, Any] | None = None,
    overwrite: bool = False,
) -> "Label":
    """Derive a new label from an existing image or label.

    If a kwarg is not provided, the value from the reference image will be used.

    Args:
        name (str): The name of the new label.
        ref_image (Image | Label | None): The reference image to derive the new
            label from. If None, the first level image will be used.
        shape (Sequence[int] | None): The shape of the new label.
        pixelsize (float | tuple[float, float] | None): The pixel size of the new
            label.
            A value to write, not a lookup key; to select an existing
            level see `pixel_size` on the getters.
        z_spacing (float | None): The z spacing of the new label.
        time_spacing (float | None): The time spacing of the new label.
        translation (Sequence[float] | None): The translation for each axis
            at the highest resolution level. Defaults to None.
        channels_policy (Literal["same", "squeeze", "singleton"] | int): Possible
            policies:
            - If "squeeze", the channels axis will be removed (no matter its size).
            - If "same", the channels axis will be kept as is (if it exists).
            - If "singleton", the channels axis will be set to size 1.
            - If an integer is provided, the channels axis will be changed to have
                that size.
            Defaults to "squeeze".
        ngff_version (NgffVersions | None): The NGFF version to use.
        chunks (ChunksLike | None): The chunk shape of the new label.
        shards (ShardsLike | None): The shard shape of the new label.
        dtype (str | None): The data type of the new label.
        dimension_separator (Literal[".", "/"] | None): The separator to use for
            dimensions.
        compressors (CompressorLike | None): The compressors to use.
        extra_array_kwargs (Mapping[str, Any] | None): Extra arguments to pass to
            the zarr array creation.
        overwrite (bool): Whether to overwrite an existing label. Defaults to False.

    Returns:
        Label: The new derived label.

    """
    if ref_image is None:
        ref_image = self.get_image()
    return self.labels_container.derive(
        name=name,
        ref_image=ref_image,
        shape=shape,
        pixelsize=pixelsize,
        z_spacing=z_spacing,
        time_spacing=time_spacing,
        translation=translation,
        channels_policy=channels_policy,
        ngff_version=ngff_version,
        chunks=chunks,
        shards=shards,
        dtype=dtype,
        dimension_separator=dimension_separator,
        compressors=compressors,
        extra_array_kwargs=extra_array_kwargs,
        overwrite=overwrite,
    )