Skip to content

Commit 81c9275

Browse files
authored
Merge pull request #107 from thewtex/validate-local
validate local
2 parents 3968030 + 7b35199 commit 81c9275

31 files changed

+1580
-193
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,7 @@ jobs:
2222
- name: Install dependencies
2323
run: |
2424
python -m pip install --upgrade pip
25-
python -m pip install -e ".[test,dask-image,itk,cli]"
26-
27-
- name: Install dependencies
28-
run: |
29-
python -m pip install --upgrade pip
30-
python -m pip install -e ".[test,dask-image,itk]"
31-
python -m pip install itkwasm-image-io
32-
33-
- name: Install dependencies
34-
run: |
35-
python -m pip install --upgrade pip
36-
python -m pip install -e ".[test,dask-image,itk,cli]"
25+
python -m pip install -e ".[test,dask-image,itk,cli,validate]"
3726
3827
- name: Test with pytest
3928
if: ${{ matrix.os != 'ubuntu-22.04' && matrix.os != 'macos-14' }}

ngff_zarr/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .to_multiscales import to_multiscales
1818
from .to_ngff_image import to_ngff_image
1919
from .to_ngff_zarr import to_ngff_zarr
20+
from .validate import validate
2021
from .zarr_metadata import (
2122
AxesType,
2223
SpatialDims,
@@ -51,6 +52,7 @@
5152
"detect_cli_io_backend",
5253
"ConversionBackend",
5354
"cli_input_to_ngff_image",
55+
"validate",
5456
"Metadata",
5557
"AxesType",
5658
"SpatialDims",

ngff_zarr/from_ngff_zarr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@
99
from .ngff_image import NgffImage
1010
from .to_multiscales import Multiscales
1111
from .zarr_metadata import Axis, Dataset, Metadata, Scale, Translation
12+
from .validate import validate as validate_ngff
1213

1314

1415
def from_ngff_zarr(
1516
store: Union[MutableMapping, str, Path, BaseStore],
17+
validate: bool = False,
1618
) -> Multiscales:
1719
"""
1820
Read an OME-Zarr NGFF Multiscales data structure from a Zarr store.
1921
2022
store : MutableMapping, str or Path, zarr.storage.BaseStore
2123
Store or path to directory in file system.
2224
25+
validate : bool
26+
If True, validate the NGFF metadata against the schema.
2327
2428
Returns
2529
-------
@@ -29,6 +33,8 @@ def from_ngff_zarr(
2933
"""
3034

3135
root = zarr.open_group(store, mode="r")
36+
if validate:
37+
validate_ngff(root.attrs.asdict())
3238
metadata = root.attrs["multiscales"][0]
3339

3440
dims = [a["name"] for a in metadata["axes"]]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Copyright © 2020-[YEAR]
2+
<a href="https://www.openmicroscopy.org/"><abbr title="Open Microscopy Environment">OME</abbr></a><sup>®</sup>
3+
(<a href="https://dundee.ac.uk/"><abbr title="University of Dundee">U. Dundee</abbr></a>).
4+
OME trademark rules apply.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://ngff.openmicroscopy.org/latest/schemas/bf2raw.schema",
4+
"title": "NGFF container produced by bioformats2raw",
5+
"description": "JSON from OME-NGFF .zattrs",
6+
"type": "object",
7+
"properties": {
8+
"bioformats2raw.layout": {
9+
"description": "The top-level identifier metadata added by bioformats2raw",
10+
"type": "number",
11+
"enum": [3]
12+
}
13+
}
14+
}
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://ngff.openmicroscopy.org/0.4/schemas/image.schema",
4+
"title": "NGFF Image",
5+
"description": "JSON from OME-NGFF .zattrs",
6+
"type": "object",
7+
"properties": {
8+
"multiscales": {
9+
"description": "The multiscale datasets for this image",
10+
"type": "array",
11+
"items": {
12+
"type": "object",
13+
"properties": {
14+
"name": {
15+
"type": "string"
16+
},
17+
"datasets": {
18+
"type": "array",
19+
"minItems": 1,
20+
"items": {
21+
"type": "object",
22+
"properties": {
23+
"path": {
24+
"type": "string"
25+
},
26+
"coordinateTransformations": {
27+
"$ref": "#/$defs/coordinateTransformations"
28+
}
29+
},
30+
"required": ["path", "coordinateTransformations"]
31+
}
32+
},
33+
"version": {
34+
"type": "string",
35+
"enum": [
36+
"0.4"
37+
]
38+
},
39+
"axes": {
40+
"$ref": "#/$defs/axes"
41+
},
42+
"coordinateTransformations": {
43+
"$ref": "#/$defs/coordinateTransformations"
44+
}
45+
},
46+
"required": [
47+
"datasets", "axes"
48+
]
49+
},
50+
"minItems": 1,
51+
"uniqueItems": true
52+
},
53+
"omero": {
54+
"type": "object",
55+
"properties": {
56+
"channels": {
57+
"type": "array",
58+
"items": {
59+
"type": "object",
60+
"properties": {
61+
"window": {
62+
"type": "object",
63+
"properties": {
64+
"end": {
65+
"type": "number"
66+
},
67+
"max": {
68+
"type": "number"
69+
},
70+
"min": {
71+
"type": "number"
72+
},
73+
"start": {
74+
"type": "number"
75+
}
76+
},
77+
"required": [
78+
"start",
79+
"min",
80+
"end",
81+
"max"
82+
]
83+
},
84+
"label": {
85+
"type": "string"
86+
},
87+
"family": {
88+
"type": "string"
89+
},
90+
"color": {
91+
"type": "string"
92+
},
93+
"active": {
94+
"type": "boolean"
95+
}
96+
},
97+
"required": [
98+
"window",
99+
"color"
100+
]
101+
}
102+
}
103+
},
104+
"required": [
105+
"channels"
106+
]
107+
}
108+
},
109+
"required": [ "multiscales" ],
110+
111+
"$defs": {
112+
"axes": {
113+
"type": "array",
114+
"uniqueItems": true,
115+
"minItems": 2,
116+
"maxItems": 5,
117+
"contains": {
118+
"type": "object",
119+
"properties": {
120+
"name": {
121+
"type": "string"
122+
},
123+
"type": {
124+
"type": "string",
125+
"enum": ["space"]
126+
},
127+
"unit": {
128+
"type": "string"
129+
}
130+
}
131+
},
132+
"minContains": 2,
133+
"maxContains": 3,
134+
"items": {
135+
"oneOf": [
136+
{
137+
"type": "object",
138+
"properties": {
139+
"name": {
140+
"type": "string"
141+
},
142+
"type": {
143+
"type": "string",
144+
"enum": ["channel", "time", "space"]
145+
}
146+
},
147+
"required": ["name", "type"]
148+
},
149+
{
150+
"type": "object",
151+
"properties": {
152+
"name": {
153+
"type": "string"
154+
},
155+
"type": {
156+
"type": "string",
157+
"not": {
158+
"enum": ["space", "time", "channel"]
159+
}
160+
}
161+
},
162+
"required": ["name"]
163+
}
164+
]
165+
}
166+
},
167+
"coordinateTransformations": {
168+
"type": "array",
169+
"minItems": 1,
170+
"contains": {
171+
"type": "object",
172+
"properties": {
173+
"type": {
174+
"type": "string",
175+
"enum": [
176+
"scale"
177+
]
178+
},
179+
"scale": {
180+
"type": "array",
181+
"minItems": 2,
182+
"items": {
183+
"type": "number"
184+
}
185+
}
186+
}
187+
},
188+
"maxContains": 1,
189+
"items": {
190+
"oneOf": [
191+
{
192+
"type": "object",
193+
"properties": {
194+
"type": {
195+
"type": "string",
196+
"enum": [
197+
"scale"
198+
]
199+
},
200+
"scale": {
201+
"type": "array",
202+
"minItems": 2,
203+
"items": {
204+
"type": "number"
205+
}
206+
}
207+
},
208+
"required": ["type", "scale"]
209+
},
210+
{
211+
"type": "object",
212+
"properties": {
213+
"type": {
214+
"type": "string",
215+
"enum": [
216+
"translation"
217+
]
218+
},
219+
"translation": {
220+
"type": "array",
221+
"minItems": 2,
222+
"items": {
223+
"type": "number"
224+
}
225+
}
226+
},
227+
"required": ["type", "translation"]
228+
}
229+
]
230+
}
231+
}
232+
}
233+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://ngff.openmicroscopy.org/0.4/schemas/label.schema",
4+
"title": "OME-NGFF labelled image schema",
5+
"description": "JSON from OME-NGFF .zattrs",
6+
"type": "object",
7+
"properties": {
8+
"image-label": {
9+
"type": "object",
10+
"properties": {
11+
"colors": {
12+
"description": "The colors for this label image",
13+
"type": "array",
14+
"items": {
15+
"type": "object",
16+
"properties": {
17+
"label-value": {
18+
"description": "The value of the label",
19+
"type": "number"
20+
},
21+
"rgba": {
22+
"description": "The RGBA color stored as an array of four integers between 0 and 255",
23+
"type": "array",
24+
"items": {
25+
"type": "integer",
26+
"minimum": 0,
27+
"maximum": 255
28+
},
29+
"minItems": 4,
30+
"maxItems": 4
31+
}
32+
},
33+
"required": [
34+
"label-value"
35+
]
36+
},
37+
"minItems": 1,
38+
"uniqueItems": true
39+
},
40+
"properties": {
41+
"description": "The properties for this label image",
42+
"type": "array",
43+
"items": {
44+
"type": "object",
45+
"properties": {
46+
"label-value": {
47+
"description": "The pixel value for this label",
48+
"type": "integer"
49+
}
50+
},
51+
"required": [
52+
"label-value"
53+
]
54+
},
55+
"minItems": 1,
56+
"uniqueItems": true
57+
},
58+
"source": {
59+
"description": "The source of this label image",
60+
"type": "object",
61+
"properties": {
62+
"image": {
63+
"type": "string"
64+
}
65+
}
66+
},
67+
"version": {
68+
"description": "The version of the specification",
69+
"type": "string",
70+
"enum": [
71+
"0.4"
72+
]
73+
}
74+
}
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)