Skip to content

Commit abc2edc

Browse files
committed
ENH: Add OMERO metadata write support
1 parent ac51020 commit abc2edc

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

ngff_zarr/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
Transform,
3333
Dataset,
3434
Metadata,
35+
Omero,
36+
OmeroChannel,
37+
OmeroWindow,
3538
)
3639

3740
__all__ = [
@@ -67,4 +70,7 @@
6770
"Transform",
6871
"Dataset",
6972
"Metadata",
73+
"Omero",
74+
"OmeroChannel",
75+
"OmeroWindow",
7076
]

ngff_zarr/to_ngff_zarr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def _pop_metadata_optionals(metadata_dict):
4747
if metadata_dict["coordinateTransformations"] is None:
4848
metadata_dict.pop("coordinateTransformations")
4949

50+
if metadata_dict["omero"] is None:
51+
metadata_dict.pop("omero")
52+
5053
return metadata_dict
5154

5255

@@ -231,6 +234,9 @@ def to_ngff_zarr(
231234
**format_kwargs,
232235
)
233236

237+
if "omero" in metadata_dict:
238+
root.attrs["omero"] = metadata_dict.pop("omero")
239+
234240
if version != "0.4":
235241
# RFC 2, Zarr 3
236242
root.attrs["ome"] = {"version": version, "multiscales": [metadata_dict]}

test/test_omero.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
from ngff_zarr import from_ngff_zarr
1+
import numpy as np
2+
from zarr.storage import MemoryStore
3+
from ngff_zarr import (
4+
Omero,
5+
OmeroChannel,
6+
OmeroWindow,
7+
from_ngff_zarr,
8+
to_ngff_image,
9+
to_multiscales,
10+
to_ngff_zarr,
11+
)
212

313
from ._data import test_data_dir
414

@@ -53,3 +63,39 @@ def test_read_omero(input_images): # noqa: ARG001
5363
assert omero.channels[5].window.max == 65535.0
5464
assert omero.channels[5].window.start == 0.0
5565
assert omero.channels[5].window.end == 100.0
66+
67+
68+
def test_write_omero():
69+
data = np.random.randint(0, 256, 262144).reshape((2, 32, 64, 64)).astype(np.uint8)
70+
image = to_ngff_image(data, dims=["c", "z", "y", "x"])
71+
multiscales = to_multiscales(image, scale_factors=[2, 4], chunks=32)
72+
73+
omero = Omero(
74+
channels=[
75+
OmeroChannel(
76+
color="008000",
77+
window=OmeroWindow(min=0.0, max=255.0, start=10.0, end=150.0),
78+
),
79+
OmeroChannel(
80+
color="0000FF",
81+
window=OmeroWindow(min=0.0, max=255.0, start=30.0, end=200.0),
82+
),
83+
]
84+
)
85+
multiscales.metadata.omero = omero
86+
87+
store = MemoryStore()
88+
version = "0.4"
89+
to_ngff_zarr(store, multiscales, version=version)
90+
91+
multiscales_read = from_ngff_zarr(store, validate=True, version=version)
92+
read_omero = multiscales_read.metadata.omero
93+
94+
assert read_omero is not None
95+
assert len(read_omero.channels) == 2
96+
assert read_omero.channels[0].color == "008000"
97+
assert read_omero.channels[0].window.start == 10.0
98+
assert read_omero.channels[0].window.end == 150.0
99+
assert read_omero.channels[1].color == "0000FF"
100+
assert read_omero.channels[1].window.start == 30.0
101+
assert read_omero.channels[1].window.end == 200.0

0 commit comments

Comments
 (0)