Skip to content

Commit 2f53940

Browse files
committed
fix(ome_zarr): πŸ› strip TIFF-sequence chunk singletons at any position
The previous fix only stripped *leading* singleton dims from each file's own shape. A writer that puts the stray singleton at the end instead (e.g. (y, x, 1), a samples-per-pixel axis) would still hit "axes don't match array". Generalize to drop a singleton wherever it falls in the per-file shape, keeping whichever two dims are real.
1 parent ea209d3 commit 2f53940

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

β€Žsrc/patchworks/plugins/ome_zarr.pyβ€Ž

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -727,19 +727,23 @@ def _open_tiff_sequence(
727727
ts = tifffile.TiffSequence(pattern, pattern=sequence_pattern)
728728

729729
# Each file should be a single 2D (y, x) plane, but tifffile.imread can
730-
# report extra leading singleton dims (e.g. a page/sample axis) even for
731-
# a plain single-page TIFF β€” drop those so one file maps to exactly (y, x).
730+
# report extra singleton dims β€” leading, trailing, or both (e.g. a stray
731+
# page or samples-per-pixel axis) β€” even for a plain single-page TIFF.
732+
# Drop whichever ones are singleton so one file maps to exactly (y, x).
732733
chunkshape = tifffile.imread(ts[0]).shape
733-
lead = len(chunkshape) - 2
734-
if lead < 0 or any(s != 1 for s in chunkshape[:lead]):
734+
keep_chunk = [i for i, s in enumerate(chunkshape) if s != 1]
735+
if len(keep_chunk) != 2:
735736
raise ValueError(
736737
f"expected single 2D (y, x) planes per file, got shape "
737738
f"{chunkshape} for {ts[0]!r}"
738739
)
739740

740741
arr = da.from_zarr(zarr.open(store=ts.aszarr()))
741-
if lead:
742-
arr = arr[(slice(None),) * len(ts.axes) + (0,) * lead]
742+
n_seq = len(ts.axes)
743+
index = tuple(
744+
slice(None) if i in keep_chunk else 0 for i in range(len(chunkshape))
745+
)
746+
arr = arr[(slice(None),) * n_seq + index]
743747
full_axes = ts.axes.lower() + "yx"
744748

745749
# Canonicalise to patchworks' tczyx axis order regardless of the order

0 commit comments

Comments
Β (0)