ngff_zarr.rfc9_zip¶
RFC-9: Zipped OME-Zarr (.ozx) support
This module provides utilities for reading and writing OME-Zarr hierarchies in ZIP archives according to RFC-9 specification.
Module Contents¶
Functions¶
Check if a path refers to a .ozx file. |
|
Return the filesystem root Path for a store, or None for non-filesystem stores. |
|
Enumerate all files under root_dir as forward-slash-separated relative paths. |
|
Order files per RFC-9: root zarr.json first, other zarr.json next, then rest sorted. |
|
Write the RFC-9 ZIP comment with version and jsonFirst flag. |
|
Write a zarr store to a ZIP archive following RFC-9 specification. |
|
Read the OME-Zarr version from a .ozx file’s ZIP comment. |
|
Read the jsonFirst flag from a .ozx file’s ZIP comment. |
API¶
- ngff_zarr.rfc9_zip.is_ozx_path(path: str | pathlib.Path) bool¶
Check if a path refers to a .ozx file.
Parameters
path : str or Path Path to check
Returns
bool True if path ends with .ozx extension
- ngff_zarr.rfc9_zip._get_store_root_path(source_store) pathlib.Path | None¶
Return the filesystem root Path for a store, or None for non-filesystem stores.
- ngff_zarr.rfc9_zip._enumerate_fs_files(root_dir: pathlib.Path) list[str]¶
Enumerate all files under root_dir as forward-slash-separated relative paths.
- ngff_zarr.rfc9_zip._order_files_rfc9(all_files: list[str]) list[str]¶
Order files per RFC-9: root zarr.json first, other zarr.json next, then rest sorted.
- ngff_zarr.rfc9_zip._write_rfc9_comment(zf: zipfile.ZipFile, version: str) None¶
Write the RFC-9 ZIP comment with version and jsonFirst flag.
- ngff_zarr.rfc9_zip.write_store_to_zip(
- source_store: zarr.storage.StoreLike | str | pathlib.Path,
- zip_path: str | pathlib.Path,
- version: str = '0.5',
- compression: int = zipfile.ZIP_STORED,
Write a zarr store to a ZIP archive following RFC-9 specification.
According to RFC-9:
Root-level zarr.json must be the first entry
Other zarr.json files should follow in breadth-first order
ZIP-level compression should be disabled (ZIP_STORED)
ZIP64 format should be used
A comment with OME-Zarr version should be added
Files are streamed one at a time from filesystem-backed stores so that peak memory stays proportional to the largest single file (typically one chunk or shard) rather than the entire dataset.
This function can be used to convert any existing zarr store (including HCS plates) to .ozx format after it has been written.
Parameters
source_store : zarr.storage.StoreLike, str, or Path Source zarr store to write from. Can be a store object (LocalStore, DirectoryStore) or a path string to a directory containing zarr data. zip_path : str or Path Path to output .ozx file version : str, optional OME-Zarr version string (e.g., “0.5”) compression : int, optional ZIP compression method (default: ZIP_STORED for no compression)
Examples
Convert an existing HCS plate to .ozx:
from ngff_zarr.rfc9_zip import write_store_to_zip
After writing plate with to_hcs_zarr or HCSPlateWriter
write_store_to_zip(“my_plate.ome.zarr”, “my_plate.ozx”, version=”0.5”)
- ngff_zarr.rfc9_zip.read_ozx_version(zip_path: str | pathlib.Path) str | None¶
Read the OME-Zarr version from a .ozx file’s ZIP comment.
Parameters
zip_path : str or Path Path to the .ozx file
Returns
str or None OME-Zarr version string if found, None otherwise
- ngff_zarr.rfc9_zip.read_ozx_json_first(zip_path: str | pathlib.Path) bool¶
Read the jsonFirst flag from a .ozx file’s ZIP comment.
The jsonFirst flag indicates that zarr.json files are ordered breadth-first in the central directory and precede other content.
Parameters
zip_path : str or Path Path to the .ozx file
Returns
bool True if jsonFirst is set to true in the ZIP comment, False otherwise