From d1ac18158b47f74e6103769d58972750e1a88947 Mon Sep 17 00:00:00 2001 From: Martin Schorb <35071867+martinschorb@users.noreply.github.com> Date: Tue, 5 Mar 2024 21:19:43 +0100 Subject: [PATCH] implement NGFF source validation (#136) Implement NGFF source validation --------- Co-authored-by: Martin Schorb --- mobie/validation/metadata.py | 13 ++++++++++++- mobie/validation/utils.py | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mobie/validation/metadata.py b/mobie/validation/metadata.py index 63e9e75..fe09966 100644 --- a/mobie/validation/metadata.py +++ b/mobie/validation/metadata.py @@ -1,3 +1,4 @@ +import json import os # from elf.io import open_file @@ -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: @@ -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: diff --git a/mobie/validation/utils.py b/mobie/validation/utils.py index 6207e8e..dd008a1 100644 --- a/mobie/validation/utils.py +++ b/mobie/validation/utils.py @@ -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" }