Skip to content

Commit

Permalink
implement NGFF source validation (#136)
Browse files Browse the repository at this point in the history
Implement NGFF source validation

---------

Co-authored-by: Martin Schorb <[email protected]>
  • Loading branch information
martinschorb and Martin Schorb authored Mar 5, 2024
1 parent 7613641 commit d1ac181
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion mobie/validation/metadata.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os

# from elf.io import open_file
Expand All @@ -21,10 +22,12 @@ def _check_bdv_n5_s3(xml, assert_true):

def _check_ome_zarr_s3(address, name, assert_true, assert_equal, channel):
try:
load_json_from_s3(os.path.join(address, ".zattrs"))
zattrs = load_json_from_s3(os.path.join(address, ".zattrs"))
except Exception:
assert_true(False, f"Can't find ome.zarr..s3file at {address}")

validate_with_schema(zattrs, "NGFF")

# we disable the name check for the time being since it seems to not be necessary,
# AND restricting the name in this fashion prevents embedding existing ome.zarr files in mobie projects
# if channel is None:
Expand Down Expand Up @@ -63,6 +66,14 @@ def bdv_check():
path = os.path.join(dataset_folder, storage["relativePath"])
assert_true(os.path.exists(path), f"Could not find data for {name} at {path}")

attr_path = os.path.join(path, ".zattrs")
assert_true(os.path.exists(attr_path), f"Could not find metadata for {name} at {path}")

with open(attr_path) as f:
zattrs = json.load(f)

validate_with_schema(zattrs, "NGFF")

# we disable the name check for the time being since it seems to not be necessary,
# AND restricting the name in this fashion prevents embedding existing ome.zarr files in mobie projects
# with open_file(path, "r", ext=".zarr") as f:
Expand Down
1 change: 1 addition & 0 deletions mobie/validation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"source": "https://raw.githubusercontent.com/mobie/mobie.github.io/master/schema/source.schema.json",
"view": "https://raw.githubusercontent.com/mobie/mobie.github.io/master/schema/view.schema.json",
"views": "https://raw.githubusercontent.com/mobie/mobie.github.io/master/schema/views.schema.json",
"NGFF": "https://raw.githubusercontent.com/ome/ngff/main/0.4/schemas/image.schema"
}


Expand Down

0 comments on commit d1ac181

Please sign in to comment.