Skip to content

Commit 15d9e3f

Browse files
authored
Updated tifffile for Zarr V3 support (#360)
updated tifffile for zarr v3 support
1 parent f5d7f7d commit 15d9e3f

File tree

3 files changed

+6
-46
lines changed

3 files changed

+6
-46
lines changed

iohub/_deprecated/singlepagetiff.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
import json
44
import logging
55
import os
6-
from pathlib import Path
76

87
import natsort
98
import numpy as np
109
import tifffile as tiff
1110
import zarr
1211

1312
from iohub._deprecated.reader_base import ReaderBase
14-
from iohub.mmstack import _tiff_to_fsspec_store
1513

1614

1715
class MicromanagerSequenceReader(ReaderBase):
@@ -210,14 +208,10 @@ def _create_stores(self, p):
210208
for c, fn in self.coord_to_filename.items():
211209
if c[0] == p:
212210
self.log.info(f"reading coord = {c} from filename = {fn}")
211+
# tifffile.zarr.ZarrTiffStore is a native zarr v3 store
213212
with tiff.imread(fn, aszarr=True) as store:
214213
try:
215-
array = zarr.open(
216-
_tiff_to_fsspec_store(
217-
store, root_uri=Path(fn).parent.as_uri()
218-
),
219-
mode="r",
220-
)[:]
214+
array = zarr.open(store, mode="r")[:]
221215
z[c[1], c[2], c[3]] = array
222216
except Exception:
223217
self.log.error(

iohub/mmstack.py

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
from __future__ import annotations
22

3-
import io
4-
import json
53
import logging
64
from copy import copy
75
from pathlib import Path
86
from typing import TYPE_CHECKING, Iterable
97
from warnings import catch_warnings, filterwarnings
108

119
import dask.array as da
12-
import fsspec
1310
import numpy as np
1411
import zarr
15-
import zarr.storage
1612
from natsort import natsorted
1713
from numpy.typing import ArrayLike
18-
from tifffile import TiffFile, ZarrTiffStore
14+
from tifffile import TiffFile
1915
from xarray import DataArray
2016

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

3733

38-
def _tiff_to_fsspec_store(
39-
zarr_tiff_store: ZarrTiffStore, root_uri: str
40-
) -> zarr.storage.FsspecStore:
41-
"""Bridge tifffile (zarr-python v2 interface) with zarr-python v3.
42-
43-
Parameters
44-
----------
45-
zarr_tiff_store : ZarrTiffStore
46-
Zarr (v2) wrapper for a TIFF series
47-
root_uri : str
48-
`file://` URI to the directory containing the TIFF files
49-
50-
Returns
51-
-------
52-
zarr.storage.FsspecStore
53-
Zarr (v3) wrapper for a TIFF series
54-
"""
55-
spec_container = io.StringIO()
56-
zarr_tiff_store.write_fsspec(spec_container, url=root_uri)
57-
fs, _ = fsspec.url_to_fs(
58-
"reference://",
59-
fo=json.loads(spec_container.getvalue()),
60-
target_protocol="file",
61-
asynchronous=True,
62-
)
63-
return zarr.storage.FsspecStore(fs=fs)
64-
65-
6634
def find_first_ome_tiff_in_mmstack(data_path: Path) -> Path:
6735
if data_path.is_file():
6836
if "ome.tif" in data_path.name:
@@ -152,10 +120,8 @@ def _parse_data(self):
152120
self.width,
153121
) = dims.values()
154122
self._set_mm_meta(self._first_tif.micromanager_metadata)
155-
zarr_tiff_store = series.aszarr(multiscales=True)
156-
self._store = _tiff_to_fsspec_store(
157-
zarr_tiff_store, root_uri=self._root.as_uri()
158-
)
123+
# tifffile.zarr.ZarrTiffStore is a native zarr v3 store
124+
self._store = series.aszarr(multiscales=True)
159125
_logger.debug(f"Opened {self._store}.")
160126
data = da.from_zarr(zarr.open(self._store, mode="r")["0"])
161127
self.dtype = data.dtype

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dependencies = [
2929
"pandas>=1.5.2",
3030
"pydantic>=2.8.2",
3131
"pydantic_extra_types>=2.9.0",
32-
"tifffile>=2024.1.30, <2025.5.21",
32+
"tifffile>=2025.5.21",
3333
"natsort>=7.1.1",
3434
"ndtiff>=2.2.1",
3535
"zarr>=3.0.8",

0 commit comments

Comments
 (0)