Skip to content
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
11c9855
fix member type hint
ziw-liu Jun 24, 2025
e3fc9e6
fix shape type hints
ziw-liu Jun 25, 2025
a0283b8
update imports
ziw-liu Jun 25, 2025
618efac
fix typo
ziw-liu Jun 25, 2025
ab7f1d3
stop allowing bytes as paths
ziw-liu Jun 25, 2025
b9e18eb
fix index type hints
ziw-liu Jun 25, 2025
67b5499
remove broken support for 0.1
ziw-liu Jun 25, 2025
fb71fea
multiscales is required
ziw-liu Jun 25, 2025
1ef196d
fix shape type hints
ziw-liu Jun 25, 2025
86a7d7d
fix version type hints
ziw-liu Jun 25, 2025
a823551
separate metadata dumping for positions
ziw-liu Jun 25, 2025
74237d5
add version testing
ziw-liu Jun 25, 2025
1d2aec9
fix compressor options for v3
ziw-liu Jun 25, 2025
e3b6f3e
fix create zeros for zarr v3
ziw-liu Jun 25, 2025
cae4577
add more tests
ziw-liu Jun 25, 2025
74c4402
fix test fixture
ziw-liu Jun 25, 2025
420dfa2
fix default value type
ziw-liu Jun 25, 2025
6f5e1d4
add overloads for open_ome_zarr
ziw-liu Jun 25, 2025
9672171
add return type hint for wells
ziw-liu Jun 26, 2025
b9942a7
centralize serialization logic of ome keys
ziw-liu Jun 26, 2025
a856f99
always create zeros first
ziw-liu Jun 26, 2025
d0c7363
more version tests
ziw-liu Jun 26, 2025
fd29254
fuzz test sharding
ziw-liu Jun 26, 2025
d7967b6
cast arguments to str
ziw-liu Jun 27, 2025
827c313
log validation error
ziw-liu Jun 27, 2025
2857edc
fix version dumping
ziw-liu Jun 27, 2025
0a6ece8
dump version for images metadata
ziw-liu Jun 27, 2025
fbb59cf
test round trip with ngff-zarr
ziw-liu Jun 27, 2025
e5533a4
replace default identity transform with concrete scales
ziw-liu Jun 27, 2025
1703cf4
fix scale length
ziw-liu Jun 27, 2025
f1cadbb
replace exact shard size with ratios
ziw-liu Jun 27, 2025
423630b
update test case
ziw-liu Jun 27, 2025
6fa1cb8
ensure dimension names
ziw-liu Jun 27, 2025
b381a7b
fix dimension separator for v2
ziw-liu Jun 27, 2025
339438d
fix plate versioning
ziw-liu Jun 28, 2025
37dcb8f
add example to convert to new version
ziw-liu Jul 1, 2025
7f76f40
fix format
ziw-liu Jul 1, 2025
04266ac
Merge branch 'zarr3-dev' into write-ome-zarr-v05
ziw-liu Jul 2, 2025
50ebd20
make acquire zarr testing optional
ziw-liu Jul 2, 2025
5e7e2c7
skip fixture with test
ziw-liu Jul 2, 2025
edd0737
fix tensorstore for zarr3
ziw-liu Jul 2, 2025
e727824
test acquire-zarr in CI
ziw-liu Jul 2, 2025
b92a60c
document aqz incompatibility with Bruno
ziw-liu Jul 2, 2025
7d4e99d
fix aquire-zarr version
ziw-liu Jul 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions docs/examples/run_update_ome_zarr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""
Update OME-Zarr Version
=======================

This script shows how to write the same OME-Zarr image
using a new version.
"""

# %%
from pathlib import Path
from tempfile import TemporaryDirectory

import numpy as np

from iohub.ngff import TransformationMeta, open_ome_zarr

# %%
# Set storage path
tmp_dir = TemporaryDirectory()
old_store_path = Path(tmp_dir.name) / "old.zarr"
new_store_path = Path(tmp_dir.name) / "new.zarr"

# %%
# Create a version 0.4 OME-Zarr dataset
random_image = np.random.randint(
0, np.iinfo(np.uint16).max, size=(10, 2, 32, 128, 128), dtype=np.uint16
)
scale = [2.0, 3.0, 4.0, 5.0, 6.0]


with open_ome_zarr(
old_store_path,
layout="hcs",
mode="w-",
channel_names=["DAPI", "GFP"],
version="0.4",
) as old_dataset:
position = old_dataset.create_position("A", "1", "0")
image = position.create_image(
"0",
random_image,
chunks=(1, 1, 4, 32, 32),
transform=[TransformationMeta(type="scale", scale=scale)],
)

# %%
# Write the same image with version 0.5 and sharding

with open_ome_zarr(old_store_path, mode="r", layout="hcs") as old_dataset:
with open_ome_zarr(
new_store_path,
layout="hcs",
mode="w",
channel_names=old_dataset.channel_names,
version="0.5",
) as new_dataset:
for name, old_position in old_dataset.positions():
row, col, fov = name.split("/")
new_position = new_dataset.create_position(row, col, fov)
old_image = old_position["0"]
new_image = new_position.create_image(
"0",
data=old_image.numpy(),
chunks=(1, 1, 4, 32, 32),
shards_ratio=(2, 1, 8, 4, 4),
transform=old_position.metadata.multiscales[0]
.datasets[0]
.coordinate_transformations,
)

# %%
# Read the new FOV to verify it was written correctly
with open_ome_zarr(new_store_path / "A/1/0", mode="r") as dataset:
assert dataset.scale == scale
image = dataset["0"]
assert image.shards == (2, 1, 32, 128, 128)
assert np.array_equal(image.numpy(), random_image)

# %%
# Clean up
tmp_dir.cleanup()
7 changes: 4 additions & 3 deletions iohub/ngff/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,7 @@ class VersionMeta(MetaBase):
"""OME-NGFF spec version. Default is the current version (0.4)."""

# SHOULD
version: Literal["0.1", "0.2", "0.3", "0.4", "0.5"] | None = Field(
default=None, exclude=lambda v: v is None
)
version: Literal["0.1", "0.2", "0.3", "0.4", "0.5"] | None = None


class MultiScaleMeta(VersionMeta):
Expand Down Expand Up @@ -302,6 +300,9 @@ class ImagesMeta(MetaBase):
multiscales: list[MultiScaleMeta]
# transitional, optional
omero: OMEROMeta | None = None
# only for OME-NGFF v0.5
version: Literal["0.5"] | None = None
model_config = ConfigDict(extra="allow")


class LabelsMeta(MetaBase):
Expand Down
Loading