Coverage for src/recon3d/command_line.py: 90%
21 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-09-23 14:20 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-09-23 14:20 +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
16# ANSI escape codes for formatting
17BOLD = "\033[1m"
18UNDERLINE = "\033[4m"
19RESET = "\033[0m"
20BLUE = "\033[34m"
21DARK_GRAY = "\033[90m"
23CLI_DOCS: Final[
24 str
25] = f"""
26-------
27recon3d
28-------
30{BOLD}{UNDERLINE}{BLUE}recon3d{RESET}
32 (this command) Lists the recon3d command line entry points
34{BOLD}{UNDERLINE}{BLUE}binary_to_semantic{RESET} <path_to_file>.yml
36 Converts binary image stack to semantic image stack in a
37 folder specified in the user input .yml file.
39 Example:
40 {DARK_GRAY}# Edit path variables in
41 # ~/recon3d/docs/userguide/src/binary_to_semantic/binary_to_semantic.yml{RESET}
42 (.venv) recon3d> binary_to_semantic binary_to_semantic.yml
44{BOLD}{UNDERLINE}{BLUE}downscale{RESET} <path_to_file>.yml
46 Downscales images in a folder specified in the user input .yml file.
48 Example:
49 {DARK_GRAY}# Edit path variables in
50 # ~/recon3d/docs/userguide/src/downscale/downscale_thunder.yml{RESET}
51 (.venv) recon3d> downscale downscale_thunder.yml
53{BOLD}{UNDERLINE}{BLUE}grayscale_image_stack_to_segmentation{RESET} <path_to_file>.yml
55 Converts a series of grayscale images to a segmentation.
57 Example:
58 {DARK_GRAY}# Edit path variables in
59 # ~/recon3d/docs/userguide/src/utilities/grayscale_image_stack_to_segmentation.yml{RESET}
60 (.venv) recon3d> grayscale_image_stack_to_segmentation grayscale_image_stack_to_segmentation.yml
62{BOLD}{UNDERLINE}{BLUE}hello{RESET}
64 Prints 'Hello world!' to the terminal to illustrate a command line entry point.
66{BOLD}{UNDERLINE}{BLUE}hdf_to_image{RESET} <path_to_file>.yml
68 From a dataset contained within a .hdf file specified by the input
69 .yml file, creates an image stack with the same dataset name in
70 the specified parent output folder.
72 Example:
73 {DARK_GRAY}# Edit path variables in
74 # ~/recon3d/docs/userguide/src/hdf_to_image/hdf_to_image.yml{RESET}
75 (.venv) recon3d> hdf_to_image hdf_to_image.yml
77{BOLD}{UNDERLINE}{BLUE}hdf_to_npy{RESET} <path_to_file>.yml
79 From a dataset contained within a .hdf file specified by the input
80 .yml file, creates a NumPy .npy file from the segmentation data.
82 Example:
83 {DARK_GRAY}# Edit path variables in
84 # ~/recon3d/docs/userguide/src/to_npy/hdf_to_npy.yml{RESET}
85 (.venv) recon3d> hdf_to_npy hdf_to_npy.yml
87{BOLD}{UNDERLINE}{BLUE}image_to_hdf{RESET} <path_to_file>.yml
89 From a single image (or image stack) in a folder specified in the
90 user input .yml file, creates a .hdf file in the specified
91 output folder.
93 Example:
94 {DARK_GRAY}# Edit path variables in
95 # ~/recon3d/docs/userguide/src/image_to_hdf/image_to_hdf.yml{RESET}
96 (.venv) recon3d> image_to_hdf image_to_hdf.yml
98{BOLD}{UNDERLINE}{BLUE}image_to_npy{RESET} <path_to_file>.yml
100 From a series of images in a folder specified in the user input
101 .yml file, creates a NumPy .npy file in the specified output folder.
103 Example:
104 {DARK_GRAY}# Edit path variables in
105 # ~/recon3d/docs/userguide/src/to_npy/image_to_npy.yml{RESET}
106 (.venv) recon3d> image_to_npy image_to_npy.yml
108{BOLD}{UNDERLINE}{BLUE}instance_analysis{RESET} <path_to_file>.yml
110 Digest a semantic segmentation accessible as a folder containing an image
111 stack specified in the user input .yml file.
113 Example:
114 {DARK_GRAY}# Edit path variables in
115 # ~/recon3d/docs/userguide/src/instance_analysis/instance_analysis.yml{RESET}
116 (.venv) recon3d> instance_analysis instance_analysis.yml
118{BOLD}{UNDERLINE}{BLUE}npy_to_mesh{RESET} <path_to_file>.yml
120 Converts an instance or semantic segmentation, encoded as a .npy file,
121 to an Exodus II finite element mesh using automesh.
122 See https://autotwin.github.io/automesh/
124 Example:
125 {DARK_GRAY}# Edit path variables in
126 # ~/recon3d/docs/userguide/src/npy_to_mesh/letter_f_3d.yml{RESET}
127 (.venv) recon3d> npy_to_mesh letter_f_3d.yml
129{BOLD}{UNDERLINE}{BLUE}semantic_to_binary{RESET} <path_to_file>.yml
131 Converts semantic image stack to series of binary image stacks in
132 a folder specified in the user input .yml file
134 Example:
135 {DARK_GRAY}# Edit path variables in
136 # ~/recon3d/docs/userguide/src/binary_to_semantic/semantic_to_binary.yml{RESET}
137 (.venv) recon3d> semantic_to_binary semantic_to_binary.yml
139{BOLD}{UNDERLINE}{BLUE}void_descriptor{RESET} <path_to_file>.yml
141 Work in progress, not yet implemented.
142 From a pore dataset contained within a hdf file specified by
143 the input .yml file, compute the void descriptor attributes
144 for the void descriptor function.
146 Example:
147 {DARK_GRAY}# Edit path variables in
148 # ~/recon3d/docs/userguide/src/void_descriptor/void_descriptor.yml{RESET}
149 (.venv) recon3d> void_descriptor void_descriptor.yml
150"""
153def recon3d():
154 """
155 Prints the command line documentation to the command window.
157 This function prints the contents of the global variable `CLI_DOCS` to the
158 command window. It is assumed that `CLI_DOCS` contains the necessary
159 documentation in string format.
161 Parameters
162 ----------
163 None
165 Returns
166 -------
167 None
168 """
169 print(CLI_DOCS)
172def hello() -> str:
173 """
174 Simple example of a function hooked to a command line entry point.
176 This function serves as an example of how to hook a function to a command
177 line entry point. When called, it returns the "Hello world!" string.
179 Parameters
180 ----------
181 None
183 Returns
184 -------
185 str
186 The canonical "Hello world!" string.
187 """
189 return "Hello world!"
192def module_version():
193 """
194 Prints the module version and the yml_schema_version.
196 This function retrieves the version of the module and the YAML schema
197 version from the `Constants` class in the `cs` module. It prints these
198 versions to the command window and returns the module version.
200 Parameters
201 ----------
202 None
204 Returns
205 -------
206 ver : str
207 The version of the module.
208 """
210 # ver = pkg_resources.require("recon3d")[0].version
211 module_name = cs.Constants().module_short_name
212 ver = version(module_name)
213 print(f"module version: {ver}")
214 print(f" yml_schema_version: {cs.Constants().YML_SCHEMA_VERSION}")
215 return ver
218def work_in_progress():
219 """
220 Prints the 'Work in Progress (WIP)' warning message.
222 This function prints a warning message indicating that the function is a
223 work in progress and has not yet been implemented.
225 Parameters
226 ----------
227 None
229 Returns
230 -------
231 None
232 """
233 print("Warning: Work in progress (WIP), function not yet implemented.")