Skip to content
Snippets Groups Projects

Refactor for v0.4

1 file
+ 20
20
Compare changes
  • Side-by-side
  • Inline
+ 20
20
import argparse
import webbrowser
import outputformat as ouf
import qim3d.io
from qim3d.viz.preview import image_preview
from qim3d import __version__ as version
import qim3d
QIM_TITLE = ouf.rainbow(
f"\n _ _____ __ \n ____ _(_)___ ___ |__ /____/ / \n / __ `/ / __ `__ \ /_ </ __ / \n/ /_/ / / / / / / /__/ / /_/ / \n\__, /_/_/ /_/ /_/____/\__,_/ \n /_/ v{version}\n\n",
f"\n _ _____ __ \n ____ _(_)___ ___ |__ /____/ / \n / __ `/ / __ `__ \ /_ </ __ / \n/ /_/ / / / / / / /__/ / /_/ / \n\__, /_/_/ /_/ /_/____/\__,_/ \n /_/ v{qim3d.__version__}\n\n",
return_str=True,
cmap="hot",
)
@@ -42,9 +40,9 @@ def main():
"--no-browser", action="store_true", help="Do not launch browser."
)
# K3D
# Viz
viz_parser = subparsers.add_parser("viz", help="Volumetric visualization.")
viz_parser.add_argument("--source", default=False, help="Path to the image file")
viz_parser.add_argument("filename", default=False, help="Path to the image file")
viz_parser.add_argument(
"--destination", default="k3d.html", help="Path to save html file."
)
@@ -116,20 +114,20 @@ def main():
args = parser.parse_args()
if args.subcommand == "gui":
from qim3d.gui import annotation_tool, data_explorer, iso3d, local_thickness
import qim3d.gui
arghost = args.host
inbrowser = not args.no_browser # Should automatically open in browser
interface = None
if args.data_explorer:
interface_class = data_explorer.Interface
interface_class = qim3d.gui.data_explorer.Interface
elif args.iso3d:
interface_class = iso3d.Interface
interface_class = qim3d.gui.iso3d.Interface
elif args.annotation_tool:
interface_class = annotation_tool.Interface
interface_class = qim3d.gui.annotation_tool.Interface
elif args.local_thickness:
interface_class = local_thickness.Interface
interface_class = qim3d.gui.local_thickness.Interface
else:
print(
"Please select a tool by choosing one of the following flags:\n\t--data-explorer\n\t--iso3d\n\t--annotation-tool\n\t--local-thickness"
@@ -145,12 +143,12 @@ def main():
interface.launch(inbrowser=inbrowser, force_light_mode=False)
elif args.subcommand == "viz":
if not args.source:
print("Please specify a source file using the argument --source")
return
import qim3d.viz
import qim3d.io
# Load the data
print(f"Loading data from {args.source}")
volume = qim3d.io.load(str(args.source))
print(f"Loading data from {args.filename}")
volume = qim3d.io.load(str(args.filename))
print(f"Done, volume shape: {volume.shape}")
# Make k3d plot
@@ -163,9 +161,12 @@ def main():
webbrowser.open_new_tab(args.destination)
elif args.subcommand == "preview":
import qim3d.viz
import qim3d.io
image = qim3d.io.load(args.filename)
image_preview(
qim3d.viz.image_preview(
image,
image_width=args.resolution,
axis=args.axis,
@@ -174,6 +175,8 @@ def main():
)
elif args.subcommand == "convert":
import qim3d.io
qim3d.io.convert(args.input_path, args.output_path, chunk_shape=args.chunks)
elif args.subcommand is None:
@@ -188,9 +191,6 @@ def main():
parser.print_help()
print("\n")
elif args.subcommand == "convert":
qim3d.io.convert(args.input_path, args.output_path)
if __name__ == "__main__":
main()
Loading