diff --git a/src/ome_zarr_models/base.py b/src/ome_zarr_models/base.py index ece70b3..599a86e 100644 --- a/src/ome_zarr_models/base.py +++ b/src/ome_zarr_models/base.py @@ -13,3 +13,9 @@ class Config: validate_assignment = True extra = "allow" + # This allows fields with aliases to be populated by either + # their alias or class attribute name + # + # We use this so we can handle (at least) the "bioformats2raw.version" + # key - attributes in Python can't contain a "." + populate_by_name = True diff --git a/src/ome_zarr_models/v04/bioformats2raw.py b/src/ome_zarr_models/v04/bioformats2raw.py new file mode 100644 index 0000000..6c9c0d8 --- /dev/null +++ b/src/ome_zarr_models/v04/bioformats2raw.py @@ -0,0 +1,16 @@ +from typing import Any, Literal + +from pydantic import Field + +from ome_zarr_models.base import Base +from ome_zarr_models.v04.plate import Plate + + +class BioFormats2RawAttrs(Base): + """ + A model of the attributes contained in a bioformats2raw zarr group. + """ + + bioformats2raw_layout: Literal[3] = Field(..., alias="bioformats2raw.layout") + plate: Plate | None = None + series: Any | None = None diff --git a/tests/v04/data/bioformats2raw_example.json b/tests/v04/data/bioformats2raw_example.json new file mode 100644 index 0000000..33fb6b6 --- /dev/null +++ b/tests/v04/data/bioformats2raw_example.json @@ -0,0 +1,30 @@ +{ + "bioformats2raw.layout": 3, + "plate": { + "columns": [ + { + "name": "1" + } + ], + "name": "Plate Name 0", + "wells": [ + { + "path": "A/1", + "rowIndex": 0, + "columnIndex": 0 + } + ], + "field_count": 1, + "rows": [ + { + "name": "A" + } + ], + "acquisitions": [ + { + "id": 0 + } + ], + "version": "0.4" + } +} diff --git a/tests/v04/test_bioformats2raw.py b/tests/v04/test_bioformats2raw.py new file mode 100644 index 0000000..f488e71 --- /dev/null +++ b/tests/v04/test_bioformats2raw.py @@ -0,0 +1,33 @@ +from pathlib import Path + +from ome_zarr_models.v04.bioformats2raw import BioFormats2RawAttrs +from ome_zarr_models.v04.plate import ( + AcquisitionInPlate, + ColumnInPlate, + Plate, + RowInPlate, + WellInPlate, +) + + +def test_bioformats2raw_exmaple_json(): + with open(Path(__file__).parent / "data" / "bioformats2raw_example.json") as f: + model = BioFormats2RawAttrs.model_validate_json(f.read()) + + assert model == BioFormats2RawAttrs( + bioformats2raw_layout=3, + plate=Plate( + acquisitions=[ + AcquisitionInPlate( + id=0, maximumfieldcount=None, name=None, description=None + ) + ], + columns=[ColumnInPlate(name="1")], + field_count=1, + name="Plate Name 0", + rows=[RowInPlate(name="A")], + version="0.4", + wells=[WellInPlate(path="A/1", rowIndex=0, columnIndex=0)], + ), + series=None, + )