Skip to content
Snippets Groups Projects
Commit d2408c65 authored by fima's avatar fima :beers:
Browse files

Merge branch 'zarr_cli' into 'main'

Zarr cli

See merge request !99
parents 4ce4e024 c88aa793
Branches
No related tags found
1 merge request!99Zarr cli
...@@ -20,6 +20,7 @@ class Convert: ...@@ -20,6 +20,7 @@ class Convert:
""" """
self.chunk_shape = kwargs.get("chunk_shape", (64, 64, 64)) self.chunk_shape = kwargs.get("chunk_shape", (64, 64, 64))
def convert(self, input_path, output_path): def convert(self, input_path, output_path):
# Stringify path in case it is not already a string # Stringify path in case it is not already a string
input_path = stringify_path(input_path) input_path = stringify_path(input_path)
...@@ -30,7 +31,7 @@ class Convert: ...@@ -30,7 +31,7 @@ class Convert:
if os.path.isfile(input_path): if os.path.isfile(input_path):
match input_ext, output_ext: match input_ext, output_ext:
case (".tif", ".zarr") | (".tiff", ".zarr"): case (".tif", ".zarr") | (".tiff", ".zarr"):
return self.convert_tif_to_zarr(input_path, output_path) return self.convert_tif_to_zarr(input_path, output_path, chunks=self.chunk_shape)
case _: case _:
raise ValueError("Unsupported file format") raise ValueError("Unsupported file format")
# Load a directory # Load a directory
......
import argparse import argparse
import webbrowser import webbrowser
import outputformat as ouf
from qim3d.gui import annotation_tool, data_explorer, iso3d, local_thickness from qim3d.gui import annotation_tool, data_explorer, iso3d, local_thickness
from qim3d.io.loading import DataLoader from qim3d.io.loading import DataLoader
from qim3d.utils import image_preview from qim3d.utils import image_preview
from qim3d import __version__ as version from qim3d import __version__ as version
import outputformat as ouf import qim3d.io
import qim3d
QIM_TITLE = ouf.rainbow( QIM_TITLE = ouf.rainbow(
f"\n _ _____ __ \n ____ _(_)___ ___ |__ /____/ / \n / __ `/ / __ `__ \ /_ </ __ / \n/ /_/ / / / / / / /__/ / /_/ / \n\__, /_/_/ /_/ /_/____/\__,_/ \n /_/ v{version}\n\n", f"\n _ _____ __ \n ____ _(_)___ ___ |__ /____/ / \n / __ `/ / __ `__ \ /_ </ __ / \n/ /_/ / / / / / / /__/ / /_/ / \n\__, /_/_/ /_/ /_/____/\__,_/ \n /_/ v{version}\n\n",
...@@ -14,6 +14,9 @@ QIM_TITLE = ouf.rainbow( ...@@ -14,6 +14,9 @@ QIM_TITLE = ouf.rainbow(
cmap="hot", cmap="hot",
) )
def parse_tuple(arg):
# Remove parentheses if they are included and split by comma
return tuple(map(int, arg.strip('()').split(',')))
def main(): def main():
parser = argparse.ArgumentParser(description="Qim3d command-line interface.") parser = argparse.ArgumentParser(description="Qim3d command-line interface.")
...@@ -87,6 +90,30 @@ def main(): ...@@ -87,6 +90,30 @@ def main():
help="By default set the maximum value to be 255 so the contrast is strong. This turns it off.", help="By default set the maximum value to be 255 so the contrast is strong. This turns it off.",
) )
# File Convert
convert_parser = subparsers.add_parser(
"convert",
help="Convert files to different formats without loading the entire file into memory",
)
convert_parser.add_argument(
"input_path",
type=str,
metavar="Input path",
help="Path to image that will be converted",
)
convert_parser.add_argument(
"output_path",
type=str,
metavar="Output path",
help="Path to save converted image",
)
convert_parser.add_argument(
"--chunks",
type=parse_tuple,
metavar="Chunk shape",
default=(64,64,64),
help="Chunk size for the zarr file. Defaults to (64, 64, 64).",
)
args = parser.parse_args() args = parser.parse_args()
if args.subcommand == "gui": if args.subcommand == "gui":
...@@ -118,7 +145,6 @@ def main(): ...@@ -118,7 +145,6 @@ def main():
interface = local_thickness.Interface() interface = local_thickness.Interface()
interface.launch(inbrowser=inbrowser, force_light_mode=False) interface.launch(inbrowser=inbrowser, force_light_mode=False)
elif args.subcommand == "viz": elif args.subcommand == "viz":
if not args.source: if not args.source:
print("Please specify a source file using the argument --source") print("Please specify a source file using the argument --source")
...@@ -139,6 +165,7 @@ def main(): ...@@ -139,6 +165,7 @@ def main():
elif args.subcommand == "preview": elif args.subcommand == "preview":
image = DataLoader().load(args.filename) image = DataLoader().load(args.filename)
image_preview( image_preview(
image, image,
image_width=args.resolution, image_width=args.resolution,
...@@ -147,6 +174,9 @@ def main(): ...@@ -147,6 +174,9 @@ def main():
relative_intensity=args.absolute_values, relative_intensity=args.absolute_values,
) )
elif args.subcommand == "convert":
qim3d.io.convert(args.input_path, args.output_path, chunk_shape=args.chunks)
elif args.subcommand is None: elif args.subcommand is None:
print(QIM_TITLE) print(QIM_TITLE)
welcome_text = ( welcome_text = (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment