Skip to content

Commit 3b91d16

Browse files
committed
fix: can't set chunk sizes and shard sizes for ozx conversion
Signed-off-by: Sricharan Reddy Varra <sricharan.varra@biohub.org>
1 parent f48eccd commit 3b91d16

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

src/iohub/cli/cli.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,25 @@ def convert(input, output, grid_layout, chunks, ome_zarr_version):
9797
"""
9898
src = pathlib.Path(input)
9999
dst = pathlib.Path(output)
100+
tiff_only = grid_layout or chunks != "XYZ"
100101

101102
if is_ozx_path(dst):
103+
# Pack: 1:1 file copy preserving source chunks. Re-chunking would
104+
# mean a full read+rewrite — a different operation, out of scope.
105+
if tiff_only:
106+
raise click.BadParameter(
107+
"--grid-layout and --chunks apply only to TIFF → Zarr conversion. "
108+
"Pack copies chunks 1:1 from the source."
109+
)
102110
out = pack_ozx(src, dst, version=ome_zarr_version)
103111
click.echo(f"packed: {out}")
104112
return
105113
if is_ozx_path(src):
114+
# Unpack: archive structure dictates everything; no flags apply.
115+
if tiff_only or ome_zarr_version is not None:
116+
raise click.BadParameter(
117+
"--grid-layout, --chunks, and --ome-zarr-version do not apply to .ozx → .zarr unpack."
118+
)
106119
out = unpack_ozx(src, dst)
107120
click.echo(f"unpacked: {out}")
108121
return

tests/cli/test_cli.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,43 @@ def test_cli_convert_zarr_to_ozx_and_back(tmpdir):
211211
np.testing.assert_array_equal(pos["0"][:], np.arange(16, dtype=np.uint8).reshape(1, 1, 1, 4, 4))
212212

213213

214+
@pytest.mark.parametrize(
215+
("flag", "value", "route"),
216+
[
217+
("--chunks", "XY", "pack"),
218+
("-g", None, "pack"),
219+
("--chunks", "XY", "unpack"),
220+
("-g", None, "unpack"),
221+
("--ome-zarr-version", "0.5", "unpack"),
222+
],
223+
)
224+
def test_cli_convert_rejects_irrelevant_flags(tmpdir, flag, value, route):
225+
"""TIFF-only flags on pack/unpack and version on unpack must error loudly."""
226+
import numpy as np
227+
228+
from tests.conftest import make_fov_zarr
229+
230+
src_zarr = Path(tmpdir) / "src.zarr"
231+
make_fov_zarr(src_zarr, np.zeros((1, 1, 1, 2, 2), dtype=np.uint8))
232+
if route == "pack":
233+
src, dst = src_zarr, Path(tmpdir) / "out.ozx"
234+
else:
235+
ozx = Path(tmpdir) / "src.ozx"
236+
from iohub.core.ozx import pack_ozx as _pack
237+
238+
_pack(src_zarr, ozx)
239+
src, dst = ozx, Path(tmpdir) / "out.zarr"
240+
241+
cmd = ["convert", "-i", str(src), "-o", str(dst), flag]
242+
if value is not None:
243+
cmd.append(value)
244+
245+
runner = CliRunner()
246+
res = runner.invoke(cli, cmd)
247+
assert res.exit_code != 0
248+
assert "do not apply" in res.output or "apply only" in res.output
249+
250+
214251
def test_cli_set_scale(caplog):
215252
with _temp_copy(hcs_ref) as store_path:
216253
store_path = Path(store_path)

0 commit comments

Comments
 (0)