Skip to content

Commit 3f8b3fd

Browse files
authored
Merge pull request #112 from thewtex/version-0.1-to-0.3
version 0.1 to 0.3
2 parents a5e5220 + 5dd8110 commit 3f8b3fd

21 files changed

+1418
-21
lines changed

ngff_zarr/from_ngff_zarr.py

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections.abc import MutableMapping
22
from pathlib import Path
33
from typing import Union, Optional
4-
from packaging import version
4+
import packaging.version
55

66
import dask.array
77
import zarr
@@ -18,7 +18,7 @@
1818
from .v04.zarr_metadata import Axis, Dataset, Scale, Translation
1919
from .validate import validate as validate_ngff
2020

21-
zarr_version = version.parse(zarr.__version__)
21+
zarr_version = packaging.version.parse(zarr.__version__)
2222
zarr_version_major = zarr_version.major
2323

2424

@@ -48,7 +48,11 @@ def from_ngff_zarr(
4848

4949
format_kwargs = {}
5050
if version and zarr_version_major >= 3:
51-
format_kwargs = {"zarr_format": 2} if version == "0.4" else {"zarr_format": 3}
51+
format_kwargs = (
52+
{"zarr_format": 2}
53+
if packaging.version.parse(version) < packaging.version.parse("0.5")
54+
else {"zarr_format": 3}
55+
)
5256
root = zarr.open_group(store, mode="r", **format_kwargs)
5357
root_attrs = root.attrs.asdict()
5458

@@ -66,16 +70,22 @@ def from_ngff_zarr(
6670
else:
6771
metadata = root.attrs["multiscales"][0]
6872

69-
dims = [a["name"] for a in metadata["axes"]]
73+
if "axes" not in metadata:
74+
from .v04.zarr_metadata import supported_dims
75+
76+
dims = list(reversed(supported_dims))
77+
else:
78+
dims = [a["name"] if "name" in a else a for a in metadata["axes"]]
7079

7180
name = "image"
7281
if name in metadata:
7382
name = metadata["name"]
7483

7584
units = {d: None for d in dims}
76-
for axis in metadata["axes"]:
77-
if "unit" in axis:
78-
units[axis["name"]] = axis["unit"]
85+
if "axes" in metadata:
86+
for axis in metadata["axes"]:
87+
if "unit" in axis:
88+
units[axis["name"]] = axis["unit"]
7989

8090
images = []
8191
datasets = []
@@ -85,17 +95,18 @@ def from_ngff_zarr(
8595
scale = {d: 1.0 for d in dims}
8696
translation = {d: 0.0 for d in dims}
8797
coordinateTransformations = []
88-
for transformation in dataset["coordinateTransformations"]:
89-
if "scale" in transformation:
90-
scale = transformation["scale"]
91-
scale = dict(zip(dims, scale))
92-
coordinateTransformations.append(Scale(transformation["scale"]))
93-
elif "translation" in transformation:
94-
translation = transformation["translation"]
95-
translation = dict(zip(dims, translation))
96-
coordinateTransformations.append(
97-
Translation(transformation["translation"])
98-
)
98+
if "coordinateTransformations" in dataset:
99+
for transformation in dataset["coordinateTransformations"]:
100+
if "scale" in transformation:
101+
scale = transformation["scale"]
102+
scale = dict(zip(dims, scale))
103+
coordinateTransformations.append(Scale(transformation["scale"]))
104+
elif "translation" in transformation:
105+
translation = transformation["translation"]
106+
translation = dict(zip(dims, translation))
107+
coordinateTransformations.append(
108+
Translation(transformation["translation"])
109+
)
99110
datasets.append(
100111
Dataset(
101112
path=dataset["path"],
@@ -107,7 +118,27 @@ def from_ngff_zarr(
107118
images.append(ngff_image)
108119

109120
metadata.pop("@type", None)
110-
axes = [Axis(**axis) for axis in metadata["axes"]]
121+
if "axes" in metadata:
122+
if "name" in metadata["axes"][0]:
123+
axes = [Axis(**axis) for axis in metadata["axes"]]
124+
else:
125+
# v0.3
126+
type_dict = {
127+
"t": "time",
128+
"c": "channel",
129+
"z": "space",
130+
"y": "space",
131+
"x": "space",
132+
}
133+
axes = [Axis(name=axis, type=type_dict[axis]) for axis in metadata["axes"]]
134+
else:
135+
axes = [
136+
Axis(name="t", type="time"),
137+
Axis(name="c", type="channel"),
138+
Axis(name="z", type="space"),
139+
Axis(name="y", type="space"),
140+
Axis(name="x", type="space"),
141+
]
111142
coordinateTransformations = None
112143
if "coordinateTransformations" in metadata:
113144
coordinateTransformations = metadata["coordinateTransformations"]
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: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://ngff.openmicroscopy.org/0.1/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+
},
27+
"required": ["path"]
28+
}
29+
},
30+
"version": {
31+
"type": "string",
32+
"enum": [
33+
"0.1"
34+
]
35+
},
36+
"metadata": {
37+
"type": "object",
38+
"properties": {
39+
"method": {
40+
"type": "string"
41+
},
42+
"version": {
43+
"type": "string"
44+
}
45+
}
46+
}
47+
},
48+
"required": [
49+
"datasets"
50+
]
51+
},
52+
"minItems": 1,
53+
"uniqueItems": true
54+
},
55+
"omero": {
56+
"type": "object",
57+
"properties": {
58+
"channels": {
59+
"type": "array",
60+
"items": {
61+
"type": "object",
62+
"properties": {
63+
"window": {
64+
"type": "object",
65+
"properties": {
66+
"end": {
67+
"type": "number"
68+
},
69+
"max": {
70+
"type": "number"
71+
},
72+
"min": {
73+
"type": "number"
74+
},
75+
"start": {
76+
"type": "number"
77+
}
78+
},
79+
"required": [
80+
"start",
81+
"min",
82+
"end",
83+
"max"
84+
]
85+
},
86+
"label": {
87+
"type": "string"
88+
},
89+
"family": {
90+
"type": "string"
91+
},
92+
"color": {
93+
"type": "string"
94+
},
95+
"active": {
96+
"type": "boolean"
97+
}
98+
},
99+
"required": [
100+
"window",
101+
"color"
102+
]
103+
}
104+
}
105+
},
106+
"required": [
107+
"channels"
108+
]
109+
}
110+
},
111+
"required": [ "multiscales" ]
112+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://ngff.openmicroscopy.org/0.1/schemas/plate.schema",
4+
"title": "OME-NGFF plate schema",
5+
"description": "JSON from OME-NGFF Plate .zattrs",
6+
"type": "object",
7+
"properties": {
8+
"plate": {
9+
"type": "object",
10+
"properties": {
11+
"version": {
12+
"type": "string",
13+
"enum": [
14+
"0.1"
15+
]
16+
},
17+
"name": {
18+
"type": "string"
19+
},
20+
"columns": {
21+
"description": "Columns of the Plate grid",
22+
"type": "array",
23+
"items": {
24+
"type": "object",
25+
"properties": {
26+
"name": {
27+
"type": "string"
28+
}
29+
},
30+
"required": [
31+
"name"
32+
]
33+
},
34+
"minItems": 1,
35+
"uniqueItems": true
36+
},
37+
"rows": {
38+
"description": "Rows of the Plate grid",
39+
"type": "array",
40+
"items": {
41+
"type": "object",
42+
"properties": {
43+
"name": {
44+
"type": "string"
45+
}
46+
},
47+
"required": [
48+
"name"
49+
]
50+
},
51+
"minItems": 1,
52+
"uniqueItems": true
53+
},
54+
"wells": {
55+
"description": "Rows of the Plate grid",
56+
"type": "array",
57+
"items": {
58+
"type": "object",
59+
"properties": {
60+
"path": {
61+
"type": "string"
62+
}
63+
},
64+
"required": [
65+
"path"
66+
]
67+
},
68+
"minItems": 1,
69+
"uniqueItems": true
70+
},
71+
"field_count": {
72+
"description": "Maximum number of fields per view across all wells."
73+
},
74+
"acquisitions": {
75+
"description": "Rows of the Plate grid",
76+
"type": "array",
77+
"items": {
78+
"type": "object",
79+
"properties": {
80+
"id": {
81+
"type": "number"
82+
},
83+
"maximumfieldcount": {
84+
"type": "number"
85+
},
86+
"name": {
87+
"type": "string"
88+
},
89+
"description": {
90+
"type": "string"
91+
},
92+
"starttime": {
93+
"type": "number"
94+
}
95+
},
96+
"required": [
97+
"id"
98+
]
99+
},
100+
"minItems": 1,
101+
"uniqueItems": true
102+
}
103+
},
104+
"required": [
105+
"version", "columns", "rows", "wells"
106+
]
107+
}
108+
},
109+
"required": [
110+
"plate"
111+
]
112+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$id": "https://ngff.openmicroscopy.org/0.1/schemas/strict_image.schema",
3+
"allOf": [
4+
{
5+
"$ref": "https://ngff.openmicroscopy.org/0.1/schemas/image.schema"
6+
},
7+
{
8+
"properties": {
9+
"multiscales": {
10+
"items": {
11+
"required": [
12+
"version", "metadata", "type", "name"
13+
]
14+
}
15+
}
16+
}
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)