Skip to content

OmeZarrContainer: API Documentation

Open an OME-Zarr Container

ngio.open_ome_zarr_container

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

Open an OME-Zarr image.

Source code in ngio/images/_ome_zarr_container.py
741
742
743
744
745
746
747
748
749
750
751
752
def open_ome_zarr_container(
    store: StoreOrGroup,
    cache: bool = False,
    mode: AccessModeLiteral = "r+",
    validate_arrays: bool = True,
) -> OmeZarrContainer:
    """Open an OME-Zarr image."""
    handler = ZarrGroupHandler(store=store, cache=cache, mode=mode)
    return OmeZarrContainer(
        group_handler=handler,
        validate_paths=validate_arrays,
    )

Create an OME-Zarr Container

ngio.create_empty_ome_zarr

create_empty_ome_zarr(
    store: StoreOrGroup,
    shape: Sequence[int],
    xy_pixelsize: float,
    z_spacing: float = 1.0,
    time_spacing: float = 1.0,
    levels: int | list[str] = 5,
    xy_scaling_factor: float = 2,
    z_scaling_factor: float = 1.0,
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
    axes_names: Sequence[str] | None = None,
    name: str | None = None,
    chunks: Sequence[int] | None = None,
    dtype: str = "uint16",
    dimension_separator: DIMENSION_SEPARATOR = "/",
    compressor="default",
    channel_labels: list[str] | None = None,
    channel_wavelengths: list[str] | None = None,
    channel_colors: Sequence[str] | None = None,
    channel_active: Sequence[bool] | None = None,
    overwrite: bool = False,
    version: NgffVersions = DefaultNgffVersion,
) -> 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.

  • xy_pixelsize (float) –

    The pixel size in x and y dimensions.

  • 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.

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

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

  • xy_scaling_factor (float, default: 2 ) –

    The down-scaling factor in x and y dimensions. Defaults to 2.0.

  • z_scaling_factor (float, default: 1.0 ) –

    The down-scaling factor in z dimension. Defaults to 1.0.

  • 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.

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

    The name of the image. Defaults to None.

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

    The chunk shape. If None the shape is used. Defaults to None.

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

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

  • dimension_separator (DIMENSION_SEPARATOR, default: '/' ) –

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

  • compressor

    The compressor to use. Defaults to "default".

  • channel_labels (list[str] | None, default: None ) –

    The labels of the channels. Defaults to None.

  • channel_wavelengths (list[str] | None, default: None ) –

    The wavelengths of the channels. Defaults to None.

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

    The colors of the channels. Defaults to None.

  • channel_active (Sequence[bool] | None, default: None ) –

    Whether the channels are active. Defaults to None.

  • overwrite (bool, default: False ) –

    Whether to overwrite an existing image. Defaults to True.

  • version (NgffVersion, default: DefaultNgffVersion ) –

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

Source code in ngio/images/_ome_zarr_container.py
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
def create_empty_ome_zarr(
    store: StoreOrGroup,
    shape: Sequence[int],
    xy_pixelsize: float,
    z_spacing: float = 1.0,
    time_spacing: float = 1.0,
    levels: int | list[str] = 5,
    xy_scaling_factor: float = 2,
    z_scaling_factor: float = 1.0,
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
    axes_names: Sequence[str] | None = None,
    name: str | None = None,
    chunks: Sequence[int] | None = None,
    dtype: str = "uint16",
    dimension_separator: DIMENSION_SEPARATOR = "/",
    compressor="default",
    channel_labels: list[str] | None = None,
    channel_wavelengths: list[str] | None = None,
    channel_colors: Sequence[str] | None = None,
    channel_active: Sequence[bool] | None = None,
    overwrite: bool = False,
    version: NgffVersions = DefaultNgffVersion,
) -> 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.
        xy_pixelsize (float): The pixel size in x and y dimensions.
        z_spacing (float, optional): The spacing between z slices. Defaults to 1.0.
        time_spacing (float, optional): The spacing between time points.
            Defaults to 1.0.
        levels (int | list[str], optional): The number of levels in the pyramid or a
            list of level names. Defaults to 5.
        xy_scaling_factor (float, optional): The down-scaling factor in x and y
            dimensions. Defaults to 2.0.
        z_scaling_factor (float, optional): The down-scaling factor in z dimension.
            Defaults to 1.0.
        space_unit (SpaceUnits, optional): The unit of space. Defaults to
            DefaultSpaceUnit.
        time_unit (TimeUnits, optional): The unit of time. Defaults to
            DefaultTimeUnit.
        axes_names (Sequence[str] | None, optional): The names of the axes.
            If None the canonical names are used. Defaults to None.
        name (str | None, optional): The name of the image. Defaults to None.
        chunks (Sequence[int] | None, optional): The chunk shape. If None the shape
            is used. Defaults to None.
        dtype (str, optional): The data type of the image. Defaults to "uint16".
        dimension_separator (DIMENSION_SEPARATOR): The dimension
            separator to use. Defaults to "/".
        compressor: The compressor to use. Defaults to "default".
        channel_labels (list[str] | None, optional): The labels of the channels.
            Defaults to None.
        channel_wavelengths (list[str] | None, optional): The wavelengths of the
            channels. Defaults to None.
        channel_colors (Sequence[str] | None, optional): The colors of the channels.
            Defaults to None.
        channel_active (Sequence[bool] | None, optional): Whether the channels are
            active. Defaults to None.
        overwrite (bool, optional): Whether to overwrite an existing image.
            Defaults to True.
        version (NgffVersion, optional): The version of the OME-Zarr specification.
            Defaults to DefaultNgffVersion.
    """
    handler = create_empty_image_container(
        store=store,
        shape=shape,
        pixelsize=xy_pixelsize,
        z_spacing=z_spacing,
        time_spacing=time_spacing,
        levels=levels,
        yx_scaling_factor=xy_scaling_factor,
        z_scaling_factor=z_scaling_factor,
        space_unit=space_unit,
        time_unit=time_unit,
        axes_names=axes_names,
        name=name,
        chunks=chunks,
        dtype=dtype,
        dimension_separator=dimension_separator,
        compressor=compressor,
        overwrite=overwrite,
        version=version,
    )

    ome_zarr = OmeZarrContainer(group_handler=handler)
    ome_zarr.set_channel_meta(
        labels=channel_labels,
        wavelength_id=channel_wavelengths,
        percentiles=None,
        colors=channel_colors,
        active=channel_active,
    )
    return ome_zarr

ngio.create_ome_zarr_from_array

create_ome_zarr_from_array(
    store: StoreOrGroup,
    array: ndarray,
    xy_pixelsize: float,
    z_spacing: float = 1.0,
    time_spacing: float = 1.0,
    levels: int | list[str] = 5,
    xy_scaling_factor: float = 2.0,
    z_scaling_factor: float = 1.0,
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
    axes_names: Sequence[str] | None = None,
    channel_labels: list[str] | None = None,
    channel_wavelengths: list[str] | None = None,
    percentiles: tuple[float, float] | None = (0.1, 99.9),
    channel_colors: Sequence[str] | None = None,
    channel_active: Sequence[bool] | None = None,
    name: str | None = None,
    chunks: Sequence[int] | None = None,
    dimension_separator: DIMENSION_SEPARATOR = "/",
    compressor: str = "default",
    overwrite: bool = False,
    version: NgffVersions = DefaultNgffVersion,
) -> 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.

  • xy_pixelsize (float) –

    The pixel size in x and y dimensions.

  • 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.

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

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

  • xy_scaling_factor (float, default: 2.0 ) –

    The down-scaling factor in x and y dimensions. Defaults to 2.0.

  • z_scaling_factor (float, default: 1.0 ) –

    The down-scaling factor in z dimension. Defaults to 1.0.

  • 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.

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

    The name of the image. Defaults to None.

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

    The chunk shape. If None the shape is used. Defaults to None.

  • channel_labels (list[str] | None, default: None ) –

    The labels of the channels. Defaults to None.

  • channel_wavelengths (list[str] | None, default: None ) –

    The wavelengths of the channels. Defaults to None.

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

    The percentiles of the channels. Defaults to None.

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

    The colors of the channels. Defaults to None.

  • channel_active (Sequence[bool] | None, default: None ) –

    Whether the channels are active. Defaults to None.

  • dimension_separator (DIMENSION_SEPARATOR, default: '/' ) –

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

  • compressor (str, default: 'default' ) –

    The compressor to use. Defaults to "default".

  • overwrite (bool, default: False ) –

    Whether to overwrite an existing image. Defaults to True.

  • version (str, default: DefaultNgffVersion ) –

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

Source code in ngio/images/_ome_zarr_container.py
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
def create_ome_zarr_from_array(
    store: StoreOrGroup,
    array: np.ndarray,
    xy_pixelsize: float,
    z_spacing: float = 1.0,
    time_spacing: float = 1.0,
    levels: int | list[str] = 5,
    xy_scaling_factor: float = 2.0,
    z_scaling_factor: float = 1.0,
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
    axes_names: Sequence[str] | None = None,
    channel_labels: list[str] | None = None,
    channel_wavelengths: list[str] | None = None,
    percentiles: tuple[float, float] | None = (0.1, 99.9),
    channel_colors: Sequence[str] | None = None,
    channel_active: Sequence[bool] | None = None,
    name: str | None = None,
    chunks: Sequence[int] | None = None,
    dimension_separator: DIMENSION_SEPARATOR = "/",
    compressor: str = "default",
    overwrite: bool = False,
    version: NgffVersions = DefaultNgffVersion,
) -> 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.
        xy_pixelsize (float): The pixel size in x and y dimensions.
        z_spacing (float, optional): The spacing between z slices. Defaults to 1.0.
        time_spacing (float, optional): The spacing between time points.
            Defaults to 1.0.
        levels (int | list[str], optional): The number of levels in the pyramid or a
            list of level names. Defaults to 5.
        xy_scaling_factor (float, optional): The down-scaling factor in x and y
            dimensions. Defaults to 2.0.
        z_scaling_factor (float, optional): The down-scaling factor in z dimension.
            Defaults to 1.0.
        space_unit (SpaceUnits, optional): The unit of space. Defaults to
            DefaultSpaceUnit.
        time_unit (TimeUnits, optional): The unit of time. Defaults to
            DefaultTimeUnit.
        axes_names (Sequence[str] | None, optional): The names of the axes.
            If None the canonical names are used. Defaults to None.
        name (str | None, optional): The name of the image. Defaults to None.
        chunks (Sequence[int] | None, optional): The chunk shape. If None the shape
            is used. Defaults to None.
        channel_labels (list[str] | None, optional): The labels of the channels.
            Defaults to None.
        channel_wavelengths (list[str] | None, optional): The wavelengths of the
            channels. Defaults to None.
        percentiles (tuple[float, float] | None, optional): The percentiles of the
            channels. Defaults to None.
        channel_colors (Sequence[str] | None, optional): The colors of the channels.
            Defaults to None.
        channel_active (Sequence[bool] | None, optional): Whether the channels are
            active. Defaults to None.
        dimension_separator (DIMENSION_SEPARATOR): The separator to use for
            dimensions. Defaults to "/".
        compressor: The compressor to use. Defaults to "default".
        overwrite (bool, optional): Whether to overwrite an existing image.
            Defaults to True.
        version (str, optional): The version of the OME-Zarr specification.
            Defaults to DefaultNgffVersion.
    """
    handler = create_empty_image_container(
        store=store,
        shape=array.shape,
        pixelsize=xy_pixelsize,
        z_spacing=z_spacing,
        time_spacing=time_spacing,
        levels=levels,
        yx_scaling_factor=xy_scaling_factor,
        z_scaling_factor=z_scaling_factor,
        space_unit=space_unit,
        time_unit=time_unit,
        axes_names=axes_names,
        name=name,
        chunks=chunks,
        dtype=str(array.dtype),
        overwrite=overwrite,
        dimension_separator=dimension_separator,
        compressor=compressor,
        version=version,
    )

    ome_zarr = OmeZarrContainer(group_handler=handler)
    image = ome_zarr.get_image()
    image.set_array(array)
    image.consolidate()
    ome_zarr.set_channel_meta(
        labels=channel_labels,
        wavelength_id=channel_wavelengths,
        percentiles=percentiles,
        colors=channel_colors,
        active=channel_active,
    )
    return ome_zarr

OmeZarrContainer Class

ngio.OmeZarrContainer

OmeZarrContainer(
    group_handler: ZarrGroupHandler,
    table_container: TablesContainer | None = None,
    label_container: LabelsContainer | None = None,
    validate_paths: 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.

  • validate_paths (bool, default: False ) –

    Whether to validate the paths of the image multiscale

Source code in ngio/images/_ome_zarr_container.py
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def __init__(
    self,
    group_handler: ZarrGroupHandler,
    table_container: TablesContainer | None = None,
    label_container: LabelsContainer | None = None,
    validate_paths: bool = False,
) -> None:
    """Initialize the OmeZarrContainer.

    Args:
        group_handler (ZarrGroupHandler): The Zarr group handler.
        table_container (TablesContainer | None): The tables container.
        label_container (LabelsContainer | None): The labels container.
        validate_paths (bool): Whether to validate the paths of the image multiscale
    """
    self._group_handler = group_handler
    self._images_container = ImagesContainer(self._group_handler)

    self._labels_container = label_container
    self._tables_container = table_container

    if validate_paths:
        for level_path in self._images_container.levels_paths:
            self.get_image(path=level_path)

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.

image_meta property

image_meta: NgioImageMeta

Return the image metadata.

levels property

levels: int

Return the number of levels in the image.

levels_paths property

levels_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 ngio/images/_ome_zarr_container.py
236
237
238
239
240
241
242
243
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."""
    image = self.get_image()
    return image.channels_meta.get_channel_idx(
        channel_label=channel_label, wavelength_id=wavelength_id
    )

set_channel_meta

set_channel_meta(
    labels: Sequence[str] | int | None = None,
    wavelength_id: Sequence[str] | None = None,
    percentiles: tuple[float, float] | None = None,
    colors: Sequence[str] | None = None,
    active: Sequence[bool] | None = None,
    **omero_kwargs: dict,
) -> None

Create a ChannelsMeta object with the default unit.

Source code in ngio/images/_ome_zarr_container.py
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
def set_channel_meta(
    self,
    labels: Sequence[str] | int | None = None,
    wavelength_id: Sequence[str] | None = None,
    percentiles: tuple[float, float] | None = None,
    colors: Sequence[str] | None = None,
    active: Sequence[bool] | None = None,
    **omero_kwargs: dict,
) -> None:
    """Create a ChannelsMeta object with the default unit."""
    self._images_container.set_channel_meta(
        labels=labels,
        wavelength_id=wavelength_id,
        start=None,
        end=None,
        percentiles=percentiles,
        colors=colors,
        active=active,
        **omero_kwargs,
    )

set_channel_percentiles

set_channel_percentiles(
    start_percentile: float = 0.1,
    end_percentile: float = 99.9,
) -> None

Update the percentiles of the image.

Source code in ngio/images/_ome_zarr_container.py
266
267
268
269
270
271
272
273
274
def set_channel_percentiles(
    self,
    start_percentile: float = 0.1,
    end_percentile: float = 99.9,
) -> None:
    """Update the percentiles of the image."""
    self._images_container.set_channel_percentiles(
        start_percentile=start_percentile, end_percentile=end_percentile
    )

set_axes_units

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

Set the units of the image.

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 ngio/images/_ome_zarr_container.py
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
def set_axes_units(
    self,
    space_unit: SpaceUnits = DefaultSpaceUnit,
    time_unit: TimeUnits = DefaultTimeUnit,
    set_labels: bool = True,
) -> None:
    """Set the units of the image.

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

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 ) –

    The pixel size of the image.

  • 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 ngio/images/_ome_zarr_container.py
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
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 (PixelSize | None): The pixel size of the image.
        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 ) –

    The pixel size of the image. 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 ngio/images/_ome_zarr_container.py
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
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 (PixelSize | None): The pixel size of the image.
            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=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,
    labels: Sequence[str] | None = None,
    pixel_size: PixelSize | None = None,
    axes_names: Sequence[str] | None = None,
    name: str | None = None,
    chunks: Sequence[int] | None = None,
    dtype: str | None = None,
    dimension_separator: DIMENSION_SEPARATOR | None = None,
    compressor=None,
    copy_labels: bool = False,
    copy_tables: bool = False,
    overwrite: bool = False,
) -> OmeZarrContainer

Create an empty OME-Zarr container from an existing image.

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.

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

    The labels of the new image.

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

    The pixel size of the new image.

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

    The axes names of the new image.

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

    The chunk shape of the new image.

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

    The data type of the new image.

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

    The name of the new image.

  • dimension_separator (DIMENSION_SEPARATOR | None, default: None ) –

    The dimension separator to use. If None, the dimension separator of the reference image will be used.

  • compressor

    The compressor to use. If None, the compressor of the reference image will be used.

  • copy_labels (bool, default: False ) –

    Whether to copy the labels from the reference image.

  • copy_tables (bool, default: False ) –

    Whether to copy the tables from the reference image.

  • overwrite (bool, default: False ) –

    Whether to overwrite an existing image.

Returns:

Source code in ngio/images/_ome_zarr_container.py
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
def derive_image(
    self,
    store: StoreOrGroup,
    ref_path: str | None = None,
    shape: Sequence[int] | None = None,
    labels: Sequence[str] | None = None,
    pixel_size: PixelSize | None = None,
    axes_names: Sequence[str] | None = None,
    name: str | None = None,
    chunks: Sequence[int] | None = None,
    dtype: str | None = None,
    dimension_separator: DIMENSION_SEPARATOR | None = None,
    compressor=None,
    copy_labels: bool = False,
    copy_tables: bool = False,
    overwrite: bool = False,
) -> "OmeZarrContainer":
    """Create an empty OME-Zarr container from an existing image.

    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.
        labels (Sequence[str] | None): The labels of the new image.
        pixel_size (PixelSize | None): The pixel size of the new image.
        axes_names (Sequence[str] | None): The axes names of the new image.
        chunks (Sequence[int] | None): The chunk shape of the new image.
        dtype (str | None): The data type of the new image.
        name (str | None): The name of the new image.
        dimension_separator (DIMENSION_SEPARATOR | None): The dimension
            separator to use. If None, the dimension separator of the
            reference image will be used.
        compressor: The compressor to use. If None, the compressor of the
            reference image will be used.
        copy_labels (bool): Whether to copy the labels from the reference image.
        copy_tables (bool): Whether to copy the tables from the reference image.
        overwrite (bool): Whether to overwrite an existing image.

    Returns:
        OmeZarrContainer: The new image container.

    """
    _ = self._images_container.derive(
        store=store,
        ref_path=ref_path,
        shape=shape,
        labels=labels,
        pixel_size=pixel_size,
        axes_names=axes_names,
        name=name,
        chunks=chunks,
        dtype=dtype,
        dimension_separator=dimension_separator,
        compressor=compressor,
        overwrite=overwrite,
    )

    handler = ZarrGroupHandler(
        store, cache=self._group_handler.use_cache, mode=self._group_handler.mode
    )

    new_ome_zarr = OmeZarrContainer(
        group_handler=handler,
        validate_paths=False,
    )

    if copy_labels:
        self.labels_container._group_handler.copy_handler(
            new_ome_zarr.labels_container._group_handler
        )

    if copy_tables:
        self.tables_container._group_handler.copy_handler(
            new_ome_zarr.tables_container._group_handler
        )
    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 ngio/images/_ome_zarr_container.py
479
480
481
482
483
484
485
486
487
def list_tables(self, filter_types: TypedTable | str | None = None) -> list[str]:
    """List all tables in the image."""
    table_container = self._get_tables_container()
    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.

Source code in ngio/images/_ome_zarr_container.py
489
490
491
492
493
494
495
496
497
def list_roi_tables(self) -> list[str]:
    """List all ROI tables in the image."""
    masking_roi = self.tables_container.list(
        filter_types="masking_roi_table",
    )
    roi = self.tables_container.list(
        filter_types="roi_table",
    )
    return masking_roi + 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 ngio/images/_ome_zarr_container.py
499
500
501
502
503
504
505
506
507
508
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 ngio/images/_ome_zarr_container.py
510
511
512
513
514
515
516
517
518
519
520
521
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 ngio/images/_ome_zarr_container.py
523
524
525
526
527
528
529
530
531
532
533
534
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 ngio/images/_ome_zarr_container.py
536
537
538
539
540
541
542
543
544
545
546
547
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 ngio/images/_ome_zarr_container.py
549
550
551
552
553
554
555
556
557
558
559
560
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, check_type: TypedTable | None = None
) -> Table

Get a table from the image.

Parameters:

  • name (str) –

    The name of the table.

  • check_type (TypedTable | None, default: None ) –

    Deprecated. Please use 'get_table_as' instead, or one of the type specific get_*table() methods.

Source code in ngio/images/_ome_zarr_container.py
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
def get_table(self, name: str, check_type: TypedTable | None = None) -> Table:
    """Get a table from the image.

    Args:
        name (str): The name of the table.
        check_type (TypedTable | None): Deprecated. Please use
            'get_table_as' instead, or one of the type specific
            get_*table() methods.

    """
    if check_type is not None:
        warnings.warn(
            "The 'check_type' argument is deprecated, and will be removed in "
            "ngio=0.3. Use 'get_table_as' instead or one of the "
            "type specific get_*table() methods.",
            DeprecationWarning,
            stacklevel=2,
        )
    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 ngio/images/_ome_zarr_container.py
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
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 ngio/images/_ome_zarr_container.py
602
603
604
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 ngio/images/_ome_zarr_container.py
606
607
608
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 = DefaultTableBackend,
    overwrite: bool = False,
) -> None

Add a table to the image.

Source code in ngio/images/_ome_zarr_container.py
610
611
612
613
614
615
616
617
618
619
620
def add_table(
    self,
    name: str,
    table: Table,
    backend: TableBackend = DefaultTableBackend,
    overwrite: bool = False,
) -> None:
    """Add a table to the image."""
    self.tables_container.add(
        name=name, table=table, backend=backend, overwrite=overwrite
    )

list_labels

list_labels() -> list[str]

List all labels in the image.

Source code in ngio/images/_ome_zarr_container.py
622
623
624
625
626
627
def list_labels(self) -> list[str]:
    """List all labels in the image."""
    label_container = self._get_labels_container()
    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 ) –

    The pixel size of the image.

  • 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 ngio/images/_ome_zarr_container.py
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
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 (PixelSize | None): The pixel size of the image.
        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 ) –

    The pixel size of the image.

  • 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 ngio/images/_ome_zarr_container.py
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
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 (PixelSize | None): The pixel size of the image.
        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=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,
    )

derive_label

derive_label(
    name: str,
    ref_image: Image | Label | None = None,
    shape: Sequence[int] | None = None,
    pixel_size: PixelSize | None = None,
    axes_names: Sequence[str] | None = None,
    chunks: Sequence[int] | None = None,
    dtype: str = "uint32",
    dimension_separator: DIMENSION_SEPARATOR | None = None,
    compressor=None,
    overwrite: bool = False,
) -> Label

Create an empty OME-Zarr label from a reference image.

And add the label to the /labels group.

Parameters:

  • name (str) –

    The name of the new image.

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

    A reference image that will be used to create the new image.

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

    The shape of the new image.

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

    The pixel size of the new image.

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

    The axes names of the new image. For labels, the channel axis is not allowed.

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

    The chunk shape of the new image.

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

    The data type of the new label.

  • dimension_separator (DIMENSION_SEPARATOR | None, default: None ) –

    The dimension separator to use. If None, the dimension separator of the reference image will be used.

  • compressor

    The compressor to use. If None, the compressor of the reference image will be used.

  • overwrite (bool, default: False ) –

    Whether to overwrite an existing image.

Returns:

  • Label ( Label ) –

    The new label.

Source code in ngio/images/_ome_zarr_container.py
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
def derive_label(
    self,
    name: str,
    ref_image: Image | Label | None = None,
    shape: Sequence[int] | None = None,
    pixel_size: PixelSize | None = None,
    axes_names: Sequence[str] | None = None,
    chunks: Sequence[int] | None = None,
    dtype: str = "uint32",
    dimension_separator: DIMENSION_SEPARATOR | None = None,
    compressor=None,
    overwrite: bool = False,
) -> "Label":
    """Create an empty OME-Zarr label from a reference image.

    And add the label to the /labels group.

    Args:
        name (str): The name of the new image.
        ref_image (Image | Label | None): A reference image that will be used
            to create the new image.
        shape (Sequence[int] | None): The shape of the new image.
        pixel_size (PixelSize | None): The pixel size of the new image.
        axes_names (Sequence[str] | None): The axes names of the new image.
            For labels, the channel axis is not allowed.
        chunks (Sequence[int] | None): The chunk shape of the new image.
        dtype (str): The data type of the new label.
        dimension_separator (DIMENSION_SEPARATOR | None): The dimension
            separator to use. If None, the dimension separator of the
            reference image will be used.
        compressor: The compressor to use. If None, the compressor of the
            reference image will be used.
        overwrite (bool): Whether to overwrite an existing image.

    Returns:
        Label: The new label.

    """
    if ref_image is None:
        ref_image = self.get_image()
    return self.labels_container.derive(
        name=name,
        ref_image=ref_image,
        shape=shape,
        pixel_size=pixel_size,
        axes_names=axes_names,
        chunks=chunks,
        dtype=dtype,
        dimension_separator=dimension_separator,
        compressor=compressor,
        overwrite=overwrite,
    )