Reader¶
Reads an OME-Zarr 0.5 image. For a plate, open one of its fields.
- class ome_zarr_io.Reader(path)¶
Reads and validates an OME-Zarr 0.5 image (a Zarr group with
multiscales).Open an existing OME-Zarr image for reading.
- Parameters:
path (str | Path) – Path to the image group (the directory containing zarr.json). For a plate, pass one of its fields, e.g.
plate.zarr/A/1/0.- Raises:
FileNotFoundError – If no zarr group exists at
path.
- validate(strict=False)¶
Validate the image (and any attached labels) against the OME-Zarr 0.5 schema.
- get_validation_errors(strict=False)¶
Return a list of validation error messages instead of raising.
- report(strict=False)¶
Return a structured
FilesetReport(validity plus a summary of the image).Unlike
validate(), this never raises for invalid metadata; seeome_zarr_io.validatefor details.- Parameters:
strict (bool)
- Return type:
- get_channel(name, level=0, as_type='dask')¶
Get image data for a single channel, selected by name.
- Parameters:
- Returns:
Array with the channel (‘c’) axis removed.
- Raises:
KeyError – If no channel with that name exists, or the array listed for
levelis missing.ValueError – If the image has no channel (‘c’) axis.
IndexError – If
levelis out of range.
- Return type:
- resample(array, from_level, to_level, *, kind='image', method=None, as_type=None)¶
Resample an array from the grid of one pyramid level to another’s.
Typical use is to read data at one level, process it, and bring the result onto the grid of another level:
out = reader.resample(my_filter(reader.get_channel("DAPI", 2)), 2, 0) lbl = reader.resample(reader.get_label("nuclei", 0), 0, 3, kind="label")
Resampling factors come from the ratio of the levels’ scale transforms, and the output has exactly the stored shape of
to_levelalong spatial axes (excess is cropped, a shortfall is edge-padded). Axes other than z/y/x keep their size, and leading axes may be missing (e.g. the ‘c’ axis thatget_channelremoves). Levels refer to the image’s pyramid.- Parameters:
array (Array | ndarray) – NumPy or Dask array shaped like
from_level.from_level (int) – Pyramid level the array is on (negative counts from the end).
to_level (int) – Pyramid level to resample to.
kind (Literal['image', 'label']) – “label” always uses nearest neighbour so label ids are never invented; “image” is for intensity data.
method (Literal['nearest', 'mean', 'linear'] | None) – “nearest”, “mean” (downscaling only) or “linear” (upscaling only). Default: “nearest” for labels; “mean” down and “linear” up for images.
as_type (Literal['dask', 'numpy'] | None) – “dask” or “numpy”. Default: the type of
array.
- Raises:
TypeError – If a level is not an int.
IndexError – If a level is out of range.
ValueError – If
arraydoes not match the shape offrom_level, the levels are not related by an integer factor, ormethoddoes not fitkindor the direction of resampling.
- Return type:
- get_label(name, level=0, as_type='dask')¶
Get a label image by name.
- Parameters:
name (str) – Label name as listed in
label_names.level (int) – Multiscale pyramid level of the label to read (0 = full resolution; negative values count from the coarsest level).
as_type (Literal['dask', 'numpy']) – Return a “dask” (lazy) or “numpy” (in-memory) array.
- Raises:
KeyError – If no label with that name exists, or the array listed for
levelis missing.ValueError – If the label has no valid multiscales metadata.
IndexError – If
levelis out of range.
- Return type:
- property level_transforms: List[LevelTransform]¶
The coordinate transform of every pyramid level, finest first.
- get_level_transform(level)¶
Get the physical coordinate transform (metadata only) of one pyramid level.
This does not read any image data; use
get_channel(..., level=)for that.- Parameters:
level (int) – Integer index of the pyramid level (0 is the full resolution).
- Returns:
A
LevelTransformwith the composed scale and translation, the axis units, the voxel size and the downsampling factor relative to level 0.- Raises:
TypeError – If
levelis not an int.IndexError – If
levelis outside0..n_levels-1.
- Return type:
LevelTransform
- get_physical_size(level=0)¶
Get the physical pixel/voxel size for each spatial and time axis.
See
get_level_transformfor a richer result that also has translation and the downsampling factor.- Parameters:
level (int) – Multiscale pyramid level to compute sizes for.
- Returns:
Mapping of axis name (e.g. “z”, “y”, “x”, “t”) to a
PhysicalSize, for every non-channel axis.- Raises:
IndexError – If
levelis out of range.- Return type: