Write OME-ZARR images
The principle entry-point for writing OME-NGFF images is ome_zarr.writer.write_image().
This takes an n-dimensional numpy array or dask array and writes it to the specified zarr group according
to the OME-NGFF specification.
By default, a pyramid of resolution levels will be created by down-sampling the data by a factor
of 2 in the X and Y dimensions.
For more custom control over the pyramid, see the more in-depth example on scaling functions and scale factors.
import numpy as np
from ome_zarr.writer import write_image
path = "test_ngff_image.ome.zarr"
size_xy = 128
size_z = 10
rng = np.random.default_rng(0)
data = rng.poisson(lam=10, size=(size_z, size_xy, size_xy)).astype(np.uint8)
write_image(
data, path, axes="zyx",scale={"z": 1.0, "y": 0.5, "x": 0.5},
axes_units={"z": "micrometer", "y": "micrometer", "x": "micrometer"},
)
[]
Alternatively, the ome_zarr.writer.write_multiscale() can be used,
which takes a “pyramid” of pre-computed numpy arrays.
The default version of OME-NGFF is v0.5, which is based on Zarr v3.
A zarr v3 group and store is created by zarr.open_group() below.
To write OME-NGFF v0.4 (Zarr v2), add the fmt=FormatV04() argument.
from ome_zarr.format import FormatV04
path = "test_ngff_image_v2.ome.zarr"
write_image(data, path, axes="zyx", fmt=FormatV04())
[]
To view the image, see tutorial on viewing images.