Skip to content

Commit

Permalink
Add CurrentFormat = FormatV05 and tweak writing to give valid v0.5 image
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Dec 10, 2024
1 parent 499531f commit 080de7f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
13 changes: 12 additions & 1 deletion ome_zarr/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def format_implementations() -> Iterator["Format"]:
"""
Return an instance of each format implementation, newest to oldest.
"""
yield FormatV05()
yield FormatV04()
yield FormatV03()
yield FormatV02()
Expand Down Expand Up @@ -329,4 +330,14 @@ def validate_coordinate_transformations(
)


CurrentFormat = FormatV04
class FormatV05(FormatV04):
"""
Changelog: added FormatV05 (December 2024)
"""

@property
def version(self) -> str:
return "0.5"


CurrentFormat = FormatV05
5 changes: 4 additions & 1 deletion ome_zarr/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ def __init_metadata(self) -> None:
if self.__mode == "w":
# For now, let's support writing of zarr v2
# TODO: handle writing of zarr v2 OR zarr v3
zarr_format = 2
if self.__fmt.version in ("0.1", "0.2", "0.3", "0.4"):
zarr_format = 2
else:
zarr_format = 3
try:
group = zarr.open_group(
store=self.__store, path="/", mode=self.__mode, zarr_format=zarr_format
Expand Down
29 changes: 19 additions & 10 deletions ome_zarr/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,20 @@ def write_multiscale(

else:
# v2 arguments
options["shape"] = data.shape
options["chunks"] = chunks_opt
options["dimension_separator"] = "/"

# default to zstd compression
options["compressor"] = options.get(
"compressor", Blosc(cname="zstd", clevel=5, shuffle=Blosc.SHUFFLE)
)
if fmt.version in ("0.1", "0.2", "0.3", "0.4"):
options["chunks"] = chunks_opt
options["dimension_separator"] = "/"
# default to zstd compression
options["compressor"] = options.get(
"compressor", Blosc(cname="zstd", clevel=5, shuffle=Blosc.SHUFFLE)
)
else:
if axes is not None:
options["dimension_names"] = [
axis["name"] for axis in axes if isinstance(axis, dict)
]

options["shape"] = data.shape
# otherwise we get 'null'
options["fill_value"] = 0

Expand Down Expand Up @@ -380,7 +385,6 @@ def write_multiscales_metadata(
# (for {} this would silently over-write it, with dict() it explicitly fails)
multiscales = [
dict(
version=fmt.version,
datasets=_validate_datasets(datasets, ndim, fmt),
name=name if name else group.name,
**metadata,
Expand All @@ -389,7 +393,12 @@ def write_multiscales_metadata(
if axes is not None:
multiscales[0]["axes"] = axes

group.attrs["multiscales"] = multiscales
if fmt.version in ("0.1", "0.2", "0.3", "0.4"):
multiscales[0]["version"] = fmt.version
group.attrs["multiscales"] = multiscales
else:
# Zarr v3 metadata under 'ome' with top-level version
group.attrs["ome"] = {"version": fmt.version, "multiscales": multiscales}


def write_plate_metadata(
Expand Down

0 comments on commit 080de7f

Please sign in to comment.