Skip to content

Commit 853fdd2

Browse files
authored
Merge pull request #143 from thewtex/cli-sharding
ENH: CLI support for sharding
2 parents 4bf7166 + 561f5bd commit 853fdd2

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

ngff_zarr/cli.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252

5353
def _multiscales_to_ngff_zarr(
54-
live, args, output_store, rich_dask_progress, multiscales
54+
live, args, output_store, rich_dask_progress, multiscales, chunks_per_shard=None
5555
):
5656
if not args.output:
5757
if args.quiet:
@@ -74,6 +74,7 @@ def _multiscales_to_ngff_zarr(
7474
to_ngff_zarr(
7575
output_store,
7676
multiscales,
77+
chunks_per_shard=chunks_per_shard,
7778
progress=rich_dask_progress,
7879
use_tensorstore=args.use_tensorstore,
7980
version=args.ome_zarr_version,
@@ -223,6 +224,13 @@ def main():
223224
help="Dask array chunking specification, either a single integer or integer per dimension, e.g. 64 or 8 16 32",
224225
metavar="CHUNKS",
225226
)
227+
processing_group.add_argument(
228+
"--chunks-per-shard",
229+
nargs="+",
230+
type=int,
231+
help="Number of chunks along each axis in a shard. If not set, no sharding. Either a single integer or integer per dimension, e.g. 64 or 8 16 32",
232+
metavar="CHUNKS_PER_SHARD",
233+
)
226234
processing_group.add_argument(
227235
"-m",
228236
"--method",
@@ -344,6 +352,17 @@ def shutdown_client(sig_id, frame): # noqa: ARG001
344352
if args.quiet:
345353
initial = None
346354
with Live(initial, console=console) as live:
355+
chunks_per_shard = None
356+
if args.chunks_per_shard:
357+
if args.ome_zarr_version == "0.4":
358+
live.console.print(
359+
"[red]Sharding is only supported for OME-Zarr version 0.5 and greater"
360+
)
361+
sys.exit(1)
362+
if len(args.chunks_per_shard) == 1:
363+
chunks_per_shard = args.chunks_per_shard[0]
364+
else:
365+
chunks_per_shard = tuple(args.chunks_per_shard)
347366
if args.output and output_backend is ConversionBackend.ITK:
348367
import itk
349368

@@ -362,7 +381,12 @@ def shutdown_client(sig_id, frame): # noqa: ARG001
362381
store = LocalStore(args.input[0])
363382
multiscales = from_ngff_zarr(store)
364383
_multiscales_to_ngff_zarr(
365-
live, args, output_store, rich_dask_progress, multiscales
384+
live,
385+
args,
386+
output_store,
387+
rich_dask_progress,
388+
multiscales,
389+
chunks_per_shard=chunks_per_shard,
366390
)
367391
elif input_backend is ConversionBackend.TIFFFILE:
368392
try:
@@ -382,7 +406,12 @@ def shutdown_client(sig_id, frame): # noqa: ARG001
382406
method,
383407
)
384408
_multiscales_to_ngff_zarr(
385-
live, args, output_store, rich_dask_progress, multiscales
409+
live,
410+
args,
411+
output_store,
412+
rich_dask_progress,
413+
multiscales,
414+
chunks_per_shard=chunks_per_shard,
386415
)
387416
except ImportError:
388417
sys.stdout.write("[red]Please install the [i]tifffile[/i] package.\n")
@@ -394,7 +423,12 @@ def shutdown_client(sig_id, frame): # noqa: ARG001
394423
live, ngff_image, args, progress, rich_dask_progress, subtitle, method
395424
)
396425
_multiscales_to_ngff_zarr(
397-
live, args, output_store, rich_dask_progress, multiscales
426+
live,
427+
args,
428+
output_store,
429+
rich_dask_progress,
430+
multiscales,
431+
chunks_per_shard=chunks_per_shard,
398432
)
399433

400434

0 commit comments

Comments
 (0)