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

Don't handle exception in Multiscales init() #266

Merged
merged 3 commits into from
Apr 4, 2023
Merged
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
4 changes: 3 additions & 1 deletion ome_zarr/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def create_zarr(
label_name: str = "coins",
fmt: Format = CurrentFormat(),
chunks: Union[Tuple, List] = None,
) -> None:
) -> zarr.Group:
"""Generate a synthetic image pyramid with labels."""
pyramid, labels = method()

Expand Down Expand Up @@ -192,3 +192,5 @@ def create_zarr(
"properties": properties,
"source": {"image": "../../"},
}

return grp
40 changes: 18 additions & 22 deletions ome_zarr/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,28 +277,24 @@ def matches(zarr: ZarrLocation) -> bool:
def __init__(self, node: Node) -> None:
super().__init__(node)

try:
multiscales = self.lookup("multiscales", [])
version = multiscales[0].get(
"version", "0.1"
) # should this be matched with Format.version?
datasets = multiscales[0]["datasets"]
axes = multiscales[0].get("axes")
fmt = format_from_version(version)
# Raises ValueError if not valid
axes_obj = Axes(axes, fmt)
node.metadata["axes"] = axes_obj.to_list()
# This will get overwritten by 'omero' metadata if present
node.metadata["name"] = multiscales[0].get("name")
paths = [d["path"] for d in datasets]
self.datasets: List[str] = paths
transformations = [d.get("coordinateTransformations") for d in datasets]
if any(trans is not None for trans in transformations):
node.metadata["coordinateTransformations"] = transformations
LOGGER.info("datasets %s", datasets)
except Exception:
LOGGER.exception("Failed to parse multiscale metadata")
return # EARLY EXIT
multiscales = self.lookup("multiscales", [])
version = multiscales[0].get(
"version", "0.1"
) # should this be matched with Format.version?
datasets = multiscales[0]["datasets"]
axes = multiscales[0].get("axes")
fmt = format_from_version(version)
# Raises ValueError if not valid
axes_obj = Axes(axes, fmt)
node.metadata["axes"] = axes_obj.to_list()
# This will get overwritten by 'omero' metadata if present
node.metadata["name"] = multiscales[0].get("name")
paths = [d["path"] for d in datasets]
self.datasets: List[str] = paths
transformations = [d.get("coordinateTransformations") for d in datasets]
if any(trans is not None for trans in transformations):
node.metadata["coordinateTransformations"] = transformations
LOGGER.info("datasets %s", datasets)

for resolution in self.datasets:
data: da.core.Array = self.array(resolution, version)
Expand Down
18 changes: 18 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ def test_label(self):
assert len(list(reader())) == 3


class TestInvalid:
@pytest.fixture(autouse=True)
def initdir(self, tmpdir):
self.path = tmpdir.mkdir("data")

def test_invalid_version(self):
grp = create_zarr(str(self.path))
# update version to something invalid
attrs = grp.attrs.asdict()
attrs["multiscales"][0]["version"] = "invalid"
grp.attrs.put(attrs)
# should raise exception
with pytest.raises(ValueError) as exe:
reader = Reader(parse_url(str(self.path)))
assert len(list(reader())) == 2
assert str(exe.value) == "Version invalid not recognized"


class TestHCSReader:
@pytest.fixture(autouse=True)
def initdir(self, tmpdir):
Expand Down