anu_ctlab_io.zarr

Read and write data from/to the ANU CTLab zarr data format.

This is an optional extra module, and must be explicitly installed to be used (e.g., pip install anu_ctlab_io[zarr]).

Package Contents

class anu_ctlab_io.zarr.OMEZarrVersion(*args, **kwds)

Bases: enum.Enum

OME-Zarr specification version to use when writing.

v05 = '0.5'
anu_ctlab_io.zarr.dataset_to_zarr(dataset, path, datatype=None, dataset_id=None, ome_zarr_version=OMEZarrVersion.v05, max_shard_size_mb=1000.0, history=None, chunk_size_mb=10.0, chunks=None, shards=None, create_array_kwargs=None, **extra_attrs)

Write a Dataset to Zarr format.

Parameters:
  • dataset (anu_ctlab_io._dataset.Dataset) – The Dataset to write.

  • path (pathlib.Path | str) – Path to write the Zarr store.

  • datatype (anu_ctlab_io._datatype.DataType | str | None) – The data type identifier. If None, attempts to infer from dataset.

  • dataset_id (str | None) – Unique identifier for the dataset. Auto-generated if not provided.

  • ome_zarr_version (OMEZarrVersion | None) – OME-Zarr specification version to use. Set to OMEZarrVersion.v05 (default) to write OME-Zarr V0.5 group format. Set to None to write a simple Zarr V3 array with mango metadata.

  • max_shard_size_mb (float) – Maximum shard size in MB for Zarr v3 sharding. Default 1000 MB (1 GB). Shards group multiple chunks into indexed files for better filesystem performance. Mutually exclusive with chunks and shards parameters.

  • history (anu_ctlab_io._parse_history.History | None) – Dictionary of history entries to add. Keys should be identifiers, values are history strings.

  • chunk_size_mb (float) – Target chunk size in MB for automatic chunking. Default 10.0 MB. Mutually exclusive with chunks and shards parameters.

  • chunks (tuple[int, Ellipsis] | None) – Explicit chunk shape as a tuple (e.g., (10, 512, 512)). Must be provided together with shards. Cannot be used with chunk_size_mb or max_shard_size_mb. When provided, user is responsible for ensuring valid chunk/shard alignment.

  • shards (tuple[int, Ellipsis] | None) – Explicit shard shape as a tuple (e.g., (100, 512, 512)). Must be provided together with chunks. Cannot be used with chunk_size_mb or max_shard_size_mb. When provided, user is responsible for ensuring valid chunk/shard alignment.

  • create_array_kwargs (dict[str, Any] | None) – Additional keyword arguments to pass to zarr.create_array(). For example, to set compression: create_array_kwargs={'compressors': [ZstdCodec(level=5)]}.

  • extra_attrs (Any) – Additional attributes to include in mango metadata.

Return type:

None

anu_ctlab_io.zarr.dataset_from_zarr(path, **kwargs)

Loads a Dataset from the path to a zarr.

This method is used by Dataset.from_path, by preference call that constructor directly.

Parameters:
  • Path – The path to the zarr to be loaded

  • kwargs (Any) – Currently this method consumes no kwargs, but will pass provided kwargs to dask.Array.from_path.

  • path (pathlib.Path)

Return type:

anu_ctlab_io._dataset.Dataset