PlateWriter

Writes a high-content-screening plate: a tree of plate/<row>/<column>/<field> images.

class ome_zarr_io.PlateWriter(path, rows, columns, name=None, acquisitions=None, overwrite=False, check_consistency=True)

Write an OME-Zarr plate: a tree of plate/<row>/<column>/<field> images.

Rows and columns are declared up front because their order defines each well’s rowIndex and columnIndex. Every field is written with Writer, and the well and plate metadata are rewritten after each add_field call, so an interrupted acquisition leaves a valid partial plate.

The plate metadata is only written once the first field exists, since the schema requires at least one well.

Example

>>> with PlateWriter("screen.ome.zarr", rows=["A", "B"], columns=["1", "2"]) as plate:
...     plate.add_field("A", "1", image, dims=["c", "y", "x"], axis_units=units)

Create the plate’s root group.

Parameters:
  • path (str | Path) – Where the plate will be written.

  • rows (Sequence[str]) – Row names in order, e.g. ["A", "B"]. Alphanumeric and unique.

  • columns (Sequence[str]) – Column names in order, e.g. ["1", "2", "3"]. Alphanumeric and unique.

  • name (str | None) – Optional plate name.

  • acquisitions (List[Dict[str, Any]] | None) – Optional list of acquisition dicts as defined by the spec (id required, a unique non-negative integer; name, description, maximumfieldcount, starttime, endtime optional). They are validated here, before anything is written. add_field(acquisition=...) must refer to one of these ids.

  • overwrite (bool) – Whether to replace an existing plate at path.

  • check_consistency (bool) – Require every field to match the first one in dims, axes and channels (count and labels). The spec allows mixed fields, but that is almost always a mistake; pass False to allow it.

add_field(row, column, image, dims, axis_units, *, field=None, acquisition=None, **writer_kwargs)

Write one field of view into a well and update the plate metadata.

Parameters:
  • row (str) – Row name; must have been declared in rows.

  • column (str) – Column name; must have been declared in columns.

  • image (Array | ndarray) – Dask or NumPy array for this field.

  • dims (List[str]) – Dimension names, as for Writer.

  • axis_units (Any) – Axis units, as for Writer.

  • field (int | None) – Field index within the well. Defaults to the next free index.

  • acquisition (int | None) – Acquisition id, which must be one of the plate’s declared acquisitions; it cannot be given if none were declared. Required when the plate declares more than one acquisition, as the spec demands.

  • **writer_kwargs (Any) – Any other Writer argument (downscale_levels, channels, …). overwrite is not accepted; it is controlled by the plate.

Returns:

The Writer that wrote the field, e.g. to call add_labels.

Return type:

Writer

close()

Validate the written plate and well metadata.

Raises:
  • ValueError – If no field was added (the plate would have no wells).

  • jsonschema.exceptions.ValidationError – If any metadata is invalid.

Return type:

None