Skip to content

Commit

Permalink
Be lenient about unspecified keys in ome_zarr.writer
Browse files Browse the repository at this point in the history
  • Loading branch information
sbesson committed Jan 9, 2022
1 parent d1311aa commit 12b341d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
8 changes: 4 additions & 4 deletions ome_zarr/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
21 changes: 15 additions & 6 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 12b341d

Please sign in to comment.