Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC validation of NGFF with pydantic_ome_ngff #281

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[settings]
known_third_party = dask,numcodecs,numpy,pytest,scipy,setuptools,skimage,zarr
known_third_party = dask,numcodecs,numpy,pydantic_ome_ngff,pytest,scipy,setuptools,skimage,zarr
multi_line_output = 3
include_trailing_comma = True
force_grid_wrap = 0
Expand Down
6 changes: 6 additions & 0 deletions ome_zarr/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dask.array as da
import numpy as np
from dask import delayed
from pydantic_ome_ngff.v04.multiscales import Multiscale

from .axes import Axes
from .format import format_from_version
Expand Down Expand Up @@ -296,6 +297,11 @@ def __init__(self, node: Node) -> None:
node.metadata["coordinateTransformations"] = transformations
LOGGER.info("datasets %s", datasets)

for multi in multiscales:
# raises Exception if can't be parsed. Only v0.4 supported
if multi.get("version") == "0.4":
Multiscale.parse_obj(multi)

for resolution in self.datasets:
data: da.core.Array = self.array(resolution, version)
chunk_sizes = [
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def read(fname):
install_requires += (["requests"],)
install_requires += (["scikit-image"],)
install_requires += (["toolz"],)
install_requires += (["pydantic-ome-ngff"],)


setup(
Expand Down
28 changes: 28 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import random

import pytest
import zarr
from numpy import zeros
Expand Down Expand Up @@ -50,6 +52,32 @@ def test_invalid_version(self):
assert len(list(reader())) == 2
assert str(exe.value) == "Version invalid not recognized"

@pytest.mark.parametrize(
"axes",
[
[{"type": "space", "name": "x"}, {"type": "space", "name": "x"}],
[{"type": "time", "name": "t"}, {"type": "space", "name": "x"}],
[
{"type": "time", "name": "t"},
{"type": "time", "name": "time"},
{"type": "space", "name": "y"},
{"type": "space", "name": "x"},
],
],
)
def test_invalid_axes(self, tmpdir, axes):
# new dir each time - otherwise repeated read gives different node count
tmp_dir = tmpdir.mkdir(str(random.random()))
grp = create_zarr(str(tmp_dir))
attrs = grp.attrs.asdict()
attrs["multiscales"][0]["axes"] = axes
grp.attrs.put(attrs)
# should raise exception
with pytest.raises(ValueError):
reader = Reader(parse_url(str(tmp_dir)))
nodes = list(reader())
assert len(nodes) == 3


class TestHCSReader:
@pytest.fixture(autouse=True)
Expand Down