scallops.zarr_io.write_zarr

scallops.zarr_io.write_zarr(grp, data, image_attrs, coords, dims, metadata=None, zarr_format='ome_zarr', compute=True)

Write data to a Zarr group with optional metadata and scaling.

Writes data to a specified Zarr group, with options for including metadata, and choosing between OME-Zarr and standard Zarr formats.

Parameters:
  • grp (Group) – The Zarr group to write the data to.

  • data (ndarray | Array | DataArray) – The data to write. If a Dask array is provided, it will be rechunked if necessary.

  • image_attrs (dict | None) – Attributes of the image DataArray. These will be stored as metadata.

  • coords (dict | None) – Coordinates of the DataArray.

  • dims (list[str] | tuple[Hashable, ...] | None) – Dimensions of the DataArray.

  • metadata (dict[str, Any] | None) – Additional metadata to store.

  • zarr_format (Literal['ome_zarr', 'zarr']) – Format to use for storing the data. Use “zarr” for non-OME Zarr compliant data with dimensions other than (t, c, z, y, x). Default is “ome_zarr”.

  • compute (bool) – If True, compute immediately. Otherwise, return a list of dask.delayed. Delayed objects representing the value to be computed by dask. Default is True.

Returns:

Empty list if the compute flag is True, otherwise a list of dask.delayed.Delayed objects.

Example:
import numpy as np
import dask.array as da
import zarr
from scallops.zarr_io import write_zarr, open_ome_zarr

# Create a Zarr group
root = open_ome_zarr("example.zarr")
grp = root.create_group("test_group")

# Write data to the Zarr group
write_zarr(
    grp,
    np.random.rand(100, 100),
    image_attrs={"description": "Test data"},
    coords=None,
    dims=["y", "x"],
)
Return type:

list[Delayed]