Coverage for src/recon3d/command_line.py: 88%
16 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-02 00:06 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-02 00:06 +0000
1"""
2Command Line Entry Points Module
3================================
5This module provides command line entry points for various functions
6and utilities. It serves as the interface between the command line
7and the underlying functionality of the application.
8"""
10from typing import Final
12# import pkg_resources # part of setup tools
13from importlib.metadata import version
14import recon3d.constants as cs
16CLI_DOCS: Final[
17 str
18] = """
19--------
20recon3d
21--------
23recon3d
24 (this command)
26binary_to_semantic <path_to_file>.yml
27 Converts binary image stack to semantic image stack in a
28 folder specified in the user input .yml file.
30 Example:
31 # Edit path variables in
32 # ~/recon3d/docs/userguide/src/binary_to_semantic/binary_to_semantic.yml
33 (.venv) recon3d> binary_to_semantic binary_to_semantic.yml
35downscale <path_to_file>.yml
36 Downscales images in a folder specified in the user input .yml file.
38 Example:
39 # Edit path variables in
40 # ~/recon3d/docs/userguide/src/downscale/downscale_thunder.yml
41 (.venv) recon3d> downscale downscale_thunder.yml
43grayscale_image_stack_to_segmentation <path_to_file>.yml
44 Converts a series of grayscale images to a segmentation.
46 Example:
47 # Edit path variables in
48 # ~/recon3d/docs/userguide/src/utilities/grayscale_image_stack_to_segmentation.yml
49 (.venv) recon3d> grayscale_image_stack_to_segmentation grayscale_image_stack_to_segmentation.yml
51hello
52 Prints 'Hello world!' to the terminal to illustrate command line
53 entry points.
55image_to_voxel <path_to_file>.yml
56 From a single image (or image stack) in a folder specified in the
57 user input .yml file, creates a hdf file in the specified
58 output folder.
60 Example:
61 # Edit path variables in
62 # ~/recon3d/docs/userguide/src/voxel_to_image/image_to_voxel.yml
63 (.venv) recon3d> image_to_voxel image_to_voxel.yml
65image_stack_to_array <path_to_file>.yml
66 From a series of images in a folder specified in the user input
67 .yml file, creates a npy file in the specified output folder.
69 Example:
70 # Edit path variables in
71 # ~/recon3d/docs/userguide/src/utilities/image_stack_to_array.yml
72 (.venv) recon3d> image_stack_to_array image_stack_to_array.yml
74instance_analysis <path_to_file>.yml
75 Digest a semantic segmentation accessible as a folder containing an image
76 stack specified in the user input .yml file.
78 Example:
79 # Edit path variables in
80 # ~/recon3d/docs/userguide/src/instance_analysis/instance_analysis.yml
81 (.venv) recon3d> instance_analysis instance_analysis.yml
83semantic_to_binary <path_to_file>.yml
84 Converts semantic image stack to series of binary image stacks in
85 a folder specified in the user input .yml file
87 Example:
88 # Edit path variables in
89 # ~/recon3d/docs/userguide/src/binary_to_semantic/semantic_to_binary.yml
90 (.venv) recon3d> semantic_to_binary semantic_to_binary.yml
92void_descriptor <path_to_file>.yml
93 Work in progress.
94 From a pore dataset contained within a hdf file specified by
95 the input .yml file, compute the void descriptor attributes
96 for the void descriptor function.
98 Example:
99 # Edit path variables in
100 # ~/recon3d/docs/userguide/src/void_descriptor/void_descriptor.yml
101 (.venv) recon3d> void_descriptor void_descriptor.yml
103voxel_to_image <path_to_file>.yml
104 From a dataset contained within a hdf file specified by the input
105 .yml file, creates an image stack with the same dataset name in
106 the specified parent output folder.
108 Example:
109 # Edit path variables in
110 # ~/recon3d/docs/userguide/src/voxel_to_image/voxel_to_image.yml
111 (.venv) recon3d> voxel_to_image voxel_to_image.yml
113voxel_to_mesh <path_to_file>.yml
114 Converts an instance or semantic segmentation, encoded as a .npy file,
115 to an Exodus II finite element mesh using automesh.
116 See https://autotwin.github.io/automesh/
118 Example:
119 # Edit path variables in
120 # ~/recon3d/docs/userguide/src/voxel_to_mesh/letter_f_3d.yml
121 (.venv) recon3d> voxel_to_mesh letter_f_3d.yml
124"""
127def recon3d():
128 """
129 Prints the command line documentation to the command window.
131 This function prints the contents of the global variable `CLI_DOCS` to the
132 command window. It is assumed that `CLI_DOCS` contains the necessary
133 documentation in string format.
135 Parameters
136 ----------
137 None
139 Returns
140 -------
141 None
142 """
143 print(CLI_DOCS)
146def hello() -> str:
147 """
148 Simple example of a function hooked to a command line entry point.
150 This function serves as an example of how to hook a function to a command
151 line entry point. When called, it returns the "Hello world!" string.
153 Parameters
154 ----------
155 None
157 Returns
158 -------
159 str
160 The canonical "Hello world!" string.
161 """
163 return "Hello world!"
166def module_version():
167 """
168 Prints the module version and the yml_schema_version.
170 This function retrieves the version of the module and the YAML schema
171 version from the `Constants` class in the `cs` module. It prints these
172 versions to the command window and returns the module version.
174 Parameters
175 ----------
176 None
178 Returns
179 -------
180 ver : str
181 The version of the module.
182 """
184 # ver = pkg_resources.require("recon3d")[0].version
185 module_name = cs.Constants().module_short_name
186 ver = version(module_name)
187 print(f"module version: {ver}")
188 print(f" yml_schema_version: {cs.Constants().YML_SCHEMA_VERSION}")
189 return ver
192def work_in_progress():
193 """
194 Prints the 'Work in Progress (WIP)' warning message.
196 This function prints a warning message indicating that the function is a
197 work in progress and has not yet been implemented.
199 Parameters
200 ----------
201 None
203 Returns
204 -------
205 None
206 """
207 print("Warning: Work in progress (WIP), function not yet implemented.")