diff --git a/ome_zarr/writer.py b/ome_zarr/writer.py index a8f0b79b..28c6d1b7 100644 --- a/ome_zarr/writer.py +++ b/ome_zarr/writer.py @@ -80,8 +80,8 @@ def _validate_well_images(images: List, fmt: Format = CurrentFormat()) -> None: if isinstance(image, str): images[index] = {"path": str(image)} elif isinstance(image, dict): - if not all(e in VALID_KEYS for e in image.keys()): - raise ValueError(f"{image} contains invalid keys") + if any(e not in VALID_KEYS for e in image.keys()): + LOGGER.debug("f{image} contains unspecified keys") if "path" not in image: raise ValueError(f"{image} must contain a path key") if not isinstance(image["path"], str): @@ -109,8 +109,8 @@ def _validate_plate_acquisitions( for acquisition in acquisitions: if not isinstance(acquisition, dict): raise ValueError(f"{acquisition} must be a dictionary") - if not all(e in VALID_KEYS for e in acquisition.keys()): - raise ValueError(f"{acquisition} contains invalid keys") + if not any(e not in VALID_KEYS for e in acquisition.keys()): + LOGGER.debug("f{acquisition} contains unspecified keys") if "id" not in acquisition: raise ValueError(f"{acquisition} must contain an id key") if not isinstance(acquisition["id"], int): diff --git a/tests/test_writer.py b/tests/test_writer.py index 1ef7b05d..2f0897ef 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -347,11 +347,10 @@ def test_acquisitions_maximal(self): [{"id": "0"}, {"id": "1"}], ), ) - def test_invalid_acquisitions(self, acquisitions): - with pytest.raises(ValueError): - write_plate_metadata( - self.root, ["A"], ["1"], ["A/1"], acquisitions=acquisitions - ) + def test_unspecified_acquisition_keys(self, acquisitions): + a = [{"id": 0, "invalid_key": "0"}] + write_plate_metadata(self.root, ["A"], ["1"], ["A/1"], acquisitions=a) + assert "plate" in self.root.attrs class TestWellMetadata: @@ -413,10 +412,20 @@ def test_multiple_acquisitions(self): [{"acquisition": 0}, {"acquisition": 1}], [{"path": "0", "acquisition": "0"}, {"path": "1", "acquisition": "1"}], [{"path": 0}, {"path": 1}], - [{"path": "0", "name": "0"}, {"path": "1", "name": "1"}], [0, 1], ), ) def test_invalid_images(self, images): with pytest.raises(ValueError): write_well_metadata(self.root, images) + + def test_unspecified_images_keys(self): + images = [ + {"path": "0", "acquisition": 1, "unspecified_key": "alpha"}, + {"path": "1", "acquisition": 2, "unspecified_key": "beta"}, + {"path": "2", "acquisition": 3, "unspecified_key": "gamma"}, + ] + write_well_metadata(self.root, images) + assert "well" in self.root.attrs + assert self.root.attrs["well"]["images"] == images + assert self.root.attrs["well"]["version"] == CurrentFormat().version