Skip to content

Commit 8a85586

Browse files
authored
Merge pull request #120 from thewtex/tensorstore-cli
tensorstore cli
2 parents cd941d1 + fe41d63 commit 8a85586

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

ngff_zarr/cli.py

+32-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
)
2626
from rich.spinner import Spinner
2727
from rich_argparse import RichHelpFormatter
28-
from zarr.storage import DirectoryStore
28+
import zarr.storage
29+
30+
if hasattr(zarr.storage, "DirectoryStore"):
31+
LocalStore = zarr.storage.DirectoryStore
32+
else:
33+
LocalStore = zarr.storage.LocalStore
2934

3035
from .cli_input_to_ngff_image import cli_input_to_ngff_image
3136
from .config import config
@@ -61,7 +66,18 @@ def _multiscales_to_ngff_zarr(
6166
)
6267
)
6368
return
64-
to_ngff_zarr(output_store, multiscales, progress=rich_dask_progress)
69+
if args.use_tensorstore:
70+
if hasattr(output_store, "root"):
71+
output_store = output_store.root
72+
else:
73+
output_store = output_store.path
74+
to_ngff_zarr(
75+
output_store,
76+
multiscales,
77+
progress=rich_dask_progress,
78+
use_tensorstore=args.use_tensorstore,
79+
version=args.ome_zarr_version,
80+
)
6581

6682

6783
def _ngff_image_to_multiscales(
@@ -191,6 +207,12 @@ def main():
191207
type=int,
192208
default=0,
193209
)
210+
metadata_group.add_argument(
211+
"--ome-zarr-version",
212+
help="OME-Zarr version",
213+
default="0.4",
214+
choices=["0.4", "0.5"],
215+
)
194216

195217
processing_group = parser.add_argument_group("processing", "Processing options")
196218
processing_group.add_argument(
@@ -226,6 +248,11 @@ def main():
226248
processing_group.add_argument(
227249
"--cache-dir", help="Directory to use for caching with large datasets"
228250
)
251+
processing_group.add_argument(
252+
"--use-tensorstore",
253+
action="store_true",
254+
help="Use the TensorStore library for I/O",
255+
)
229256

230257
args = parser.parse_args()
231258

@@ -236,7 +263,7 @@ def main():
236263
cache_dir = Path(args.cache_dir).resolve()
237264
if not cache_dir.exists():
238265
Path.makedirs(cache_dir, parents=True)
239-
config.cache_store = zarr.storage.DirectoryStore(cache_dir, **zarr_kwargs)
266+
config.cache_store = LocalStore(cache_dir, **zarr_kwargs)
240267

241268
console = Console()
242269
progress = RichProgress(
@@ -303,7 +330,7 @@ def shutdown_client(sig_id, frame): # noqa: ARG001
303330
)
304331
output_store = None
305332
if args.output and output_backend is ConversionBackend.NGFF_ZARR:
306-
output_store = DirectoryStore(args.output, **zarr_kwargs)
333+
output_store = LocalStore(args.output, **zarr_kwargs)
307334

308335
subtitle = "[red]generation"
309336
if not args.output:
@@ -332,7 +359,7 @@ def shutdown_client(sig_id, frame): # noqa: ARG001
332359
return
333360

334361
if input_backend is ConversionBackend.NGFF_ZARR:
335-
store = zarr.storage.DirectoryStore(args.input[0])
362+
store = LocalStore(args.input[0])
336363
multiscales = from_ngff_zarr(store)
337364
_multiscales_to_ngff_zarr(
338365
live, args, output_store, rich_dask_progress, multiscales

0 commit comments

Comments
 (0)