Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
afae0b4
wip
aliddell Feb 27, 2025
63b3aa7
wip: 2025-02-27
aliddell Feb 27, 2025
dde33a0
Merge remote-tracking branch 'upstream/main' into 273-use-zarr-python-3
aliddell Mar 11, 2025
0c0837c
Undo reformatting
aliddell Mar 11, 2025
e4c87b4
Remove unused imports
aliddell Mar 11, 2025
abfd029
Fix miscellaneous failing tests.
aliddell Mar 11, 2025
61045d4
Get rename_well working.
aliddell Mar 11, 2025
9800d96
sort import
ziw-liu Apr 3, 2025
2516c9b
Read MMStack with Zarr v3 (#293)
ziw-liu Apr 4, 2025
1404000
Merge branch 'main' into 273-use-zarr-python-3
ziw-liu Apr 4, 2025
2a2f75f
add rich for zarr v3 print tree
ziw-liu Apr 4, 2025
26adb5e
skip tests that require ome-zarr-py
ziw-liu Apr 4, 2025
dd6d994
fix file list checking
ziw-liu Apr 4, 2025
b9c6ccd
fix commas
ziw-liu Apr 4, 2025
8a427c6
stringify path names
ziw-liu Apr 4, 2025
ce6e0a9
Merge branch 'main' into 273-use-zarr-python-3
ziw-liu Apr 4, 2025
f50efcb
detect ome key in reader
ziw-liu Apr 15, 2025
c48309f
allow multiscales to not have version
ziw-liu Apr 15, 2025
c7d4e1d
wip: allow reading v0.5 images
ziw-liu Apr 15, 2025
90ce666
normalize store path
ziw-liu Apr 15, 2025
8507fec
Merge branch 'zarr3-dev' into ome-zarr-0.5
ziw-liu May 19, 2025
6648e95
update docstring
ziw-liu May 29, 2025
7e94726
remove unused import
ziw-liu May 29, 2025
f7c86fe
remove zarr-python synchronizer
ziw-liu May 29, 2025
77146dd
allow empty zarr examples
ziw-liu May 29, 2025
d60ff07
add example json files
ziw-liu May 29, 2025
81e88f0
fixture for example v0.5 HCS dataset
ziw-liu May 29, 2025
27201c7
unify ome container unwrapping
ziw-liu May 29, 2025
8f811ab
run PR tests for all target branches
ziw-liu May 29, 2025
3aa13f6
test with absolute paths
ziw-liu May 29, 2025
31aa28d
avoid big endian test cases
ziw-liu May 29, 2025
3f03172
avoid yanked versions
ziw-liu May 29, 2025
63971f9
fix zarr-python breakage
ziw-liu May 29, 2025
a37a13f
revert keyword argument name
ziw-liu May 29, 2025
c19c80d
fix version detection after zarr-python breakage
ziw-liu May 30, 2025
c6bec61
test with absolute path
ziw-liu May 30, 2025
140b498
Merge branch 'zarr3-dev' into ome-zarr-0.5
ziw-liu May 30, 2025
c091eb9
Revert "allow empty zarr examples"
ziw-liu May 30, 2025
6160961
Test reading NGFF v0.5 with acquire-zarr
aliddell Jun 2, 2025
c20417f
Merge remote-tracking branch 'upstream/ome-zarr-0.5' into ome-zarr-0.5
aliddell Jun 2, 2025
4f37959
check binary values
ziw-liu Jun 2, 2025
d3ceea9
simplify file mode switch
ziw-liu Jun 2, 2025
2f1f00b
remove redundant deletion
ziw-liu Jun 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
6 changes: 3 additions & 3 deletions docs/examples/run_coordinate_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
) as dataset:
# Create and write to positions
# This affects the tile arrangement in visualization
position = dataset.create_position(0, 0, 0)
position = dataset.create_position("0", "0", "0")
position.create_image("0", tczyx_1, transform=[translation[0]])
position = dataset.create_position(0, 0, 1)
position = dataset.create_position("0", "0", "1")
position.create_image("0", tczyx_2, transform=[translation[1], scaling[0]])
# Print dataset summary
dataset.print_tree()
Expand All @@ -72,4 +72,4 @@

# %%
# Clean up
tmp_dir.cleanup()
tmp_dir.cleanup()
4 changes: 2 additions & 2 deletions docs/examples/run_multi_fov_hcs_ome_zarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

position_list = (
("A", "1", "0"),
("H", 1, "0"),
("H", "1", "0"),
("H", "12", "CannotVisualize"),
("Control", "Blank", 0),
("Control", "Blank", "0"),
)

with open_ome_zarr(
Expand Down
43 changes: 30 additions & 13 deletions iohub/_deprecated/singlepagetiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
import json
import logging
import os
from pathlib import Path

import natsort
import numpy as np
import tifffile as tiff
import zarr

from iohub._deprecated.reader_base import ReaderBase
from iohub.mmstack import _tiff_to_fsspec_store


class MicromanagerSequenceReader(ReaderBase):
def __init__(self, folder, extract_data=False):
def __init__(self, folder, extract_data=False, strict=False):
super().__init__()

"""
Expand All @@ -32,13 +34,16 @@ def __init__(self, folder, extract_data=False):
which contain singlepage tiff sequences
extract_data (bool)
True if zarr arrays should be extracted immediately
strict: (bool)
True if failures in getting images should raise exceptions
"""

if not os.path.isdir(folder):
raise NotImplementedError(
"supplied path for singlepage tiff sequence reader "
"is not a folder"
)
self._strict = strict

self.log = logging.getLogger(__name__)
self.positions = {}
Expand Down Expand Up @@ -206,20 +211,32 @@ def _create_stores(self, p):
if c[0] == p:
self.log.info(f"reading coord = {c} from filename = {fn}")
with tiff.imread(fn, aszarr=True) as store:
z[c[1], c[2], c[3]] = zarr.open(store)
try:
array = zarr.open(
_tiff_to_fsspec_store(
store, root_uri=Path(fn).parent.as_uri()
),
mode="r",
)[:]
z[c[1], c[2], c[3]] = array
except Exception:
self.log.error(
f"error reading file {fn} for coordinate {c}"
)

# check that the array was assigned
if z == zarr.zeros(
shape=(
self.frames,
self.channels,
self.slices,
self.height,
self.width,
),
chunks=(1, 1, 1, self.height, self.width),
):
raise IOError(f"array at position {p} can not be found")
if self._strict:
if z == zarr.zeros(
shape=(
self.frames,
self.channels,
self.slices,
self.height,
self.width,
),
chunks=(1, 1, 1, self.height, self.width),
):
raise IOError(f"array at position {p} can not be found")

self.positions[p] = z

Expand Down
15 changes: 5 additions & 10 deletions iohub/_deprecated/zarrfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import numpy as np
import zarr
import zarr.storage

from iohub._deprecated.reader_base import ReaderBase

Expand All @@ -27,7 +28,7 @@ class ZarrReader(ReaderBase):
"""

def __init__(
self, store_path: str, version: Literal["0.1", "0.4"] = "0.1"
self, store_path: str, version: Literal["0.1", "0.4", "0.5"] = "0.1"
):
super().__init__()

Expand All @@ -43,17 +44,11 @@ def __init__(
# zarr files (.zarr) are directories
if not os.path.isdir(store_path):
raise ValueError("file does not exist")
if version == "0.4":
dimension_separator = "/"
elif version == "0.1":
dimension_separator = "."
else:
if version not in ("0.1", "0.4", "0.5"):
raise ValueError(f"Invalid NGFF version: {version}")
try:
self.store = zarr.DirectoryStore(
store_path, dimension_separator=dimension_separator
)
self.root = zarr.open(self.store, "r")
self.store = zarr.storage.LocalStore(store_path)
self.root = zarr.open(self.store, mode="r")
except Exception:
raise FileNotFoundError("Supplies path is not a valid zarr root")
try:
Expand Down
4 changes: 3 additions & 1 deletion iohub/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ def _init_hcs_arrays(self, arr_kwargs):
def _init_grid_arrays(self, arr_kwargs):
for row, columns in enumerate(self.position_grid):
for column in columns:
self._create_zeros_array(row, column, "0", arr_kwargs)
self._create_zeros_array(
str(row), str(column), "0", arr_kwargs
)

def _create_zeros_array(
self, row_name: str, col_name: str, pos_name: str, arr_kwargs: dict
Expand Down
41 changes: 38 additions & 3 deletions iohub/mmstack.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from __future__ import annotations

import io
import json
import logging
from copy import copy
from pathlib import Path
from typing import TYPE_CHECKING, Iterable
from warnings import catch_warnings, filterwarnings

import dask.array as da
import fsspec
import numpy as np
import zarr
import zarr.storage
from natsort import natsorted
from numpy.typing import ArrayLike
from tifffile import TiffFile
from tifffile import TiffFile, ZarrTiffStore
from xarray import DataArray

from iohub.mm_fov import MicroManagerFOV, MicroManagerFOVMapping
Expand All @@ -31,6 +35,34 @@ def _normalize_mm_pos_key(key: str | int) -> int:
raise TypeError("Micro-Manager position keys must be integers.")


def _tiff_to_fsspec_store(
zarr_tiff_store: ZarrTiffStore, root_uri: str
) -> zarr.storage.FsspecStore:
"""Bridge tifffile (zarr-python v2 interface) with zarr-python v3.

Parameters
----------
zarr_tiff_store : ZarrTiffStore
Zarr (v2) wrapper for a TIFF series
root_uri : str
`file://` URI to the directory containing the TIFF files

Returns
-------
zarr.storage.FsspecStore
Zarr (v3) wrapper for a TIFF series
"""
spec_container = io.StringIO()
zarr_tiff_store.write_fsspec(spec_container, url=root_uri)
fs, _ = fsspec.url_to_fs(
"reference://",
fo=json.loads(spec_container.getvalue()),
target_protocol="file",
asynchronous=True,
)
return zarr.storage.FsspecStore(fs=fs)


def find_first_ome_tiff_in_mmstack(data_path: Path) -> Path:
if data_path.is_file():
if "ome.tif" in data_path.name:
Expand Down Expand Up @@ -124,9 +156,12 @@ def _parse_data(self):
self.width,
) = dims.values()
self._set_mm_meta(self._first_tif.micromanager_metadata)
self._store = series.aszarr()
zarr_tiff_store = series.aszarr(multiscales=True)
self._store = _tiff_to_fsspec_store(
zarr_tiff_store, root_uri=self._root.as_uri()
)
_logger.debug(f"Opened {self._store}.")
data = da.from_zarr(zarr.open(self._store))
data = da.from_zarr(zarr.open(self._store, mode="r")["0"])
self.dtype = data.dtype
img = DataArray(data, dims=raw_dims, name=self.dirname)
xarr = img.expand_dims(
Expand Down
4 changes: 3 additions & 1 deletion iohub/ngff/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ 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.4"
version: Literal["0.1", "0.2", "0.3", "0.4", "0.5"] | None = Field(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workaround for ome/ngff#309.

default=None, exclude=lambda v: v is None
)


class MultiScaleMeta(VersionMeta):
Expand Down
Loading