diff --git a/qim3d/__init__.py b/qim3d/__init__.py index 2180bfafea2ae34c24b13889e071234624845642..beadf9df2d278b6ed9a99d1bb2d4989e22d7dd41 100644 --- a/qim3d/__init__.py +++ b/qim3d/__init__.py @@ -11,6 +11,6 @@ from . import models from . import processing -__version__ = "0.3.2" +__version__ = "0.3.5" examples = io.ImgExamples() io.logger.set_level_info() diff --git a/qim3d/utils/cli.py b/qim3d/utils/cli.py index 6ec221fa6223a0a4c7d38228f85c195f4ba5f187..2280f3af66d810172c91b57f948d123a22d92010 100644 --- a/qim3d/utils/cli.py +++ b/qim3d/utils/cli.py @@ -8,39 +8,82 @@ from qim3d.utils import image_preview def main(): - parser = argparse.ArgumentParser(description='Qim3d command-line interface.') - subparsers = parser.add_subparsers(title='Subcommands', dest='subcommand') + parser = argparse.ArgumentParser(description="Qim3d command-line interface.") + subparsers = parser.add_subparsers(title="Subcommands", dest="subcommand") # GUIs - gui_parser = subparsers.add_parser('gui', help = 'Graphical User Interfaces.') - - gui_parser.add_argument('--data-explorer', action='store_true', help='Run data explorer.') - gui_parser.add_argument('--iso3d', action='store_true', help='Run iso3d.') - gui_parser.add_argument('--annotation-tool', action='store_true', help='Run annotation tool.') - gui_parser.add_argument('--local-thickness', action='store_true', help='Run local thickness tool.') - gui_parser.add_argument('--host', default='0.0.0.0', help='Desired host.') - gui_parser.add_argument('--platform', action='store_true', help='Use QIM platform address') - gui_parser.add_argument('--no-browser', action='store_true', help='Do not launch browser.') - - # K3D - 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('--destination', default='k3d.html', help='Path to save html file.') - viz_parser.add_argument('--no-browser', action='store_true', help='Do not launch browser.') + gui_parser = subparsers.add_parser("gui", help="Graphical User Interfaces.") + + gui_parser.add_argument( + "--data-explorer", action="store_true", help="Run data explorer." + ) + gui_parser.add_argument("--iso3d", action="store_true", help="Run iso3d.") + gui_parser.add_argument( + "--annotation-tool", action="store_true", help="Run annotation tool." + ) + gui_parser.add_argument( + "--local-thickness", action="store_true", help="Run local thickness tool." + ) + gui_parser.add_argument("--host", default="0.0.0.0", help="Desired host.") + gui_parser.add_argument( + "--platform", action="store_true", help="Use QIM platform address" + ) + gui_parser.add_argument( + "--no-browser", action="store_true", help="Do not launch browser." + ) + + # K3D + 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( + "--destination", default="k3d.html", help="Path to save html file." + ) + viz_parser.add_argument( + "--no-browser", action="store_true", help="Do not launch browser." + ) # Preview - preview_parser = subparsers.add_parser('preview', help= 'Preview of the image in CLI') - preview_parser.add_argument('filename',type = str, metavar = 'FILENAME', help = 'Path to image that will be displayed') - preview_parser.add_argument('--slice',type = int, metavar ='S', default = None, help = 'Specifies which slice of the image will be displayed.\nDefaults to middle slice. If number exceeds number of slices, last slice will be displayed.' ) - preview_parser.add_argument('--axis', type = int, metavar = 'AX', default=0, help = 'Specifies from which axis will be the slice taken. Defaults to 0.') - preview_parser.add_argument('--resolution',type = int, metavar = 'RES', default = 80, help = 'Resolution of displayed image. Defaults to 80.') - preview_parser.add_argument('--absolute_values', action='store_false', help = 'By default set the maximum value to be 255 so the contrast is strong. This turns it off.') + preview_parser = subparsers.add_parser( + "preview", help="Preview of the image in CLI" + ) + preview_parser.add_argument( + "filename", + type=str, + metavar="FILENAME", + help="Path to image that will be displayed", + ) + preview_parser.add_argument( + "--slice", + type=int, + metavar="S", + default=None, + help="Specifies which slice of the image will be displayed.\nDefaults to middle slice. If number exceeds number of slices, last slice will be displayed.", + ) + preview_parser.add_argument( + "--axis", + type=int, + metavar="AX", + default=0, + help="Specifies from which axis will be the slice taken. Defaults to 0.", + ) + preview_parser.add_argument( + "--resolution", + type=int, + metavar="RES", + default=80, + help="Resolution of displayed image. Defaults to 80.", + ) + preview_parser.add_argument( + "--absolute_values", + action="store_false", + help="By default set the maximum value to be 255 so the contrast is strong. This turns it off.", + ) args = parser.parse_args() - if args.subcommand == 'gui': + if args.subcommand == "gui": arghost = args.host - inbrowser = not args.no_browser # Should automatically open in browser + inbrowser = not args.no_browser # Should automatically open in browser if args.data_explorer: if args.platform: data_explorer.run_interface(arghost) @@ -53,42 +96,74 @@ def main(): else: interface = iso3d.Interface() interface.launch(inbrowser=inbrowser) - + elif args.annotation_tool: if args.platform: annotation_tool.run_interface(arghost) else: interface = annotation_tool.Interface() - interface.launch(inbrowser=inbrowser) + interface.launch(inbrowser=inbrowser) elif args.local_thickness: if args.platform: local_thickness.run_interface(arghost) else: interface = local_thickness.Interface() interface.launch(inbrowser=inbrowser) - - - if args.subcommand == "viz": + elif args.subcommand == "viz": if not args.source: - print ("Please specify a source file using the argument --source") + print("Please specify a source file using the argument --source") return # Load the data - print (f"Loading data from {args.source}") + print(f"Loading data from {args.source}") volume = qim3d.io.load(str(args.source)) - print (f"Done, volume shape: {volume.shape}") + print(f"Done, volume shape: {volume.shape}") # Make k3d plot - print ("\nGenerating k3d plot...") + print("\nGenerating k3d plot...") qim3d.viz.vol(volume, show=False, save=str(args.destination)) - print (f"Done, plot available at <{args.destination}>") + print(f"Done, plot available at <{args.destination}>") if not args.no_browser: print("Opening in default browser...") webbrowser.open_new_tab(args.destination) - if args.subcommand == 'preview': + elif args.subcommand == "preview": image = DataLoader().load(args.filename) - image_preview(image, image_width = args.resolution, axis = args.axis, slice = args.slice, relative_intensity= args.absolute_values) - -if __name__ == '__main__': - main() \ No newline at end of file + image_preview( + image, + image_width=args.resolution, + axis=args.axis, + slice=args.slice, + relative_intensity=args.absolute_values, + ) + + elif args.subcommand is None: + welcome_text = ( + "\n" + " _ _____ __ \n" + " ____ _(_)___ ___ |__ /____/ / \n" + " / __ `/ / __ `__ \ /_ </ __ / \n" + "/ /_/ / / / / / / /__/ / /_/ / \n" + "\__, /_/_/ /_/ /_/____/\__,_/ \n" + " /_/ \n" + "\n" + "--- Welcome to qim3d command-line interface ---\n" + "qim3d is a Python package for 3D image processing and visualization.\n" + "For more information, please visit: https://platform.qim.dk/qim3d/\n" + f"Current version of qim3d: {qim3d.__version__}\n" + " \n" + "The qim3d command-line interface provides the following subcommands:\n" + "- gui: Graphical User Interfaces\n" + "- viz: Volumetric visualizations of volumes\n" + "- preview: Preview of an volume directly in the terminal\n" + " \n" + "For more information on each subcommand, type 'qim3d <subcommand> --help'.\n" + ) + print(welcome_text) + print("--- Help page for qim3d command-line interface shown below ---\n") + parser.print_help() + print("\n") + + +if __name__ == "__main__": + main()