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

🩹 BUG: Fix Parsing Missing Omero Version NGFF Metadata #568

Merged
merged 16 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
34 changes: 32 additions & 2 deletions tests/test_wsireader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2034,11 +2034,11 @@ def test_ngff_empty_datasets_mpp(tmp_path):
assert wsi.info.mpp is None


def test_nff_no_scale_transforms_mpp(tmp_path):
def test_ngff_no_scale_transforms_mpp(tmp_path):
"""Test that mpp is None if no scale transforms are present."""
sample = _fetch_remote_sample("ngff-1")
# Create a copy of the sample with no axes
sample_copy = tmp_path / "ngff-1"
sample_copy = tmp_path / "ngff-1.zarr"
shutil.copytree(sample, sample_copy)
with open(sample_copy / ".zattrs", "r") as fh:
zattrs = json.load(fh)
Expand All @@ -2051,6 +2051,36 @@ def test_nff_no_scale_transforms_mpp(tmp_path):
assert wsi.info.mpp is None


def test_ngff_missing_omero_version(tmp_path):
"""Test that the reader can handle missing omero version."""
sample = _fetch_remote_sample("ngff-1")
# Create a copy of the sample
sample_copy = tmp_path / "ngff-1.zarr"
shutil.copytree(sample, sample_copy)
with open(sample_copy / ".zattrs", "r") as fh:
zattrs = json.load(fh)
# Remove the omero version
del zattrs["omero"]["version"]
with open(sample_copy / ".zattrs", "w") as fh:
json.dump(zattrs, fh, indent=2)
wsireader.WSIReader.open(sample_copy)


def test_ngff_non_numeric_version(tmp_path):
"""Test that the reader can handle non-numeric omero versions."""
sample = _fetch_remote_sample("ngff-1")
# Create a copy of the sample
sample_copy = tmp_path / "ngff-1.zarr"
shutil.copytree(sample, sample_copy)
with open(sample_copy / ".zattrs", "r") as fh:
zattrs = json.load(fh)
# Set the omero version to a non-numeric string
zattrs["omero"]["version"] = "0.5-dev"
with open(sample_copy / ".zattrs", "w") as fh:
json.dump(zattrs, fh, indent=2)
wsireader.WSIReader.open(sample_copy)


class TestReader:
scenarios = [
(
Expand Down
9 changes: 6 additions & 3 deletions tiatoolbox/wsicore/wsireader.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,14 @@ def is_ngff(path: pathlib.Path, min_version: Tuple[int, ...] = (0, 4)) -> bool:
tuple(int(part) for part in scale.get("version", "").split("."))
for scale in multiscales
)
omero_version = tuple(int(part) for part in omero.get("version", "").split("."))
omero_version = omero.get("verion")
John-P marked this conversation as resolved.
Show resolved Hide resolved
if omero_version:
John-P marked this conversation as resolved.
Show resolved Hide resolved
omero_version = tuple(omero_version.split("."))
if omero_version < min_version:
return False
if any(version < min_version for version in multiscales_versions):
return False
if omero_version < min_version:
return False

return is_zarr(path)


Expand Down
1 change: 1 addition & 0 deletions whitelist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Nx4
NxM
NxN
OME
Omero
Omnyx
OpenCV
Otsu's
Expand Down