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
rowIndexandcolumnIndex. Every field is written withWriter, and the well and plate metadata are rewritten after eachadd_fieldcall, 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:
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 (
idrequired, a unique non-negative integer;name,description,maximumfieldcount,starttime,endtimeoptional). 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
Falseto 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.
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
Writerargument (downscale_levels,channels, …).overwriteis not accepted; it is controlled by the plate.
- Returns:
The
Writerthat wrote the field, e.g. to calladd_labels.- Return type:
- 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