Read OME-ZARR images

This sample code reads an image stored on remote s3 server, but the same code can be used to read data on a local file system. In either case, the data is exposed as dask arrays;

You can obtain a list of “nodes” which include all arrays stored in the group:

from ome_zarr.io import parse_url
from ome_zarr.reader import Reader

url = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.5/idr0062A/6001240_labels.zarr"

# read the image data
reader = Reader(parse_url(url))
# nodes may include images, labels etc
nodes = list(reader())
nodes
[https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.5/idr0062A/6001240_labels.zarr/ [zgroup],
 https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.5/idr0062A/6001240_labels.zarr/labels/ [zgroup] (hidden),
 https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.5/idr0062A/6001240_labels.zarr/labels/0/ [zgroup] (hidden)]

The first node will be the image pixel data; Since this group is again an ome-zarr multiscales object, it consists of several arrays that represent the different resolution levels:

image_node = nodes[0]

multiscales = image_node.data
multiscales
[dask.array<from-zarr, shape=(2, 236, 275, 271), dtype=uint16, chunksize=(1, 1, 256, 256), chunktype=numpy.ndarray>,
 dask.array<from-zarr, shape=(2, 236, 137, 135), dtype=uint16, chunksize=(1, 1, 137, 135), chunktype=numpy.ndarray>,
 dask.array<from-zarr, shape=(2, 236, 68, 67), dtype=uint16, chunksize=(1, 1, 68, 67), chunktype=numpy.ndarray>]

The first entry in this list represents the 0-th resolution level, and is the highest resolution data.

multiscales[0]
Array Chunk
Bytes 67.09 MiB 128.00 kiB
Shape (2, 236, 275, 271) (1, 1, 256, 256)
Dask graph 1888 chunks in 2 graph layers
Data type uint16 numpy.ndarray
2 1 271 275 236