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

1""" 

2Command Line Entry Points Module 

3================================ 

4 

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""" 

9 

10from typing import Final 

11 

12# import pkg_resources # part of setup tools 

13from importlib.metadata import version 

14import recon3d.constants as cs 

15 

16# ANSI escape codes for formatting 

17BOLD = "\033[1m" 

18UNDERLINE = "\033[4m" 

19RESET = "\033[0m" 

20BLUE = "\033[34m" 

21DARK_GRAY = "\033[90m" 

22 

23CLI_DOCS: Final[ 

24 str 

25] = f""" 

26------- 

27recon3d 

28------- 

29 

30{BOLD}{UNDERLINE}{BLUE}recon3d{RESET} 

31 

32 (this command) Lists the recon3d command line entry points 

33 

34{BOLD}{UNDERLINE}{BLUE}binary_to_semantic{RESET} <path_to_file>.yml 

35 

36 Converts binary image stack to semantic image stack in a 

37 folder specified in the user input .yml file. 

38 

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 

43 

44{BOLD}{UNDERLINE}{BLUE}downscale{RESET} <path_to_file>.yml 

45 

46 Downscales images in a folder specified in the user input .yml file. 

47 

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 

52 

53{BOLD}{UNDERLINE}{BLUE}grayscale_image_stack_to_segmentation{RESET} <path_to_file>.yml 

54 

55 Converts a series of grayscale images to a segmentation. 

56 

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 

61 

62{BOLD}{UNDERLINE}{BLUE}hello{RESET} 

63 

64 Prints 'Hello world!' to the terminal to illustrate a command line entry point. 

65 

66{BOLD}{UNDERLINE}{BLUE}hdf_to_image{RESET} <path_to_file>.yml 

67 

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. 

71 

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 

76 

77{BOLD}{UNDERLINE}{BLUE}hdf_to_npy{RESET} <path_to_file>.yml 

78 

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. 

81 

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 

86 

87{BOLD}{UNDERLINE}{BLUE}image_to_hdf{RESET} <path_to_file>.yml 

88 

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. 

92 

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 

97 

98{BOLD}{UNDERLINE}{BLUE}image_to_npy{RESET} <path_to_file>.yml 

99 

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. 

102 

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 

107 

108{BOLD}{UNDERLINE}{BLUE}instance_analysis{RESET} <path_to_file>.yml 

109 

110 Digest a semantic segmentation accessible as a folder containing an image 

111 stack specified in the user input .yml file. 

112 

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 

117 

118{BOLD}{UNDERLINE}{BLUE}npy_to_mesh{RESET} <path_to_file>.yml 

119 

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/ 

123 

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 

128 

129{BOLD}{UNDERLINE}{BLUE}semantic_to_binary{RESET} <path_to_file>.yml 

130 

131 Converts semantic image stack to series of binary image stacks in 

132 a folder specified in the user input .yml file 

133 

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 

138 

139{BOLD}{UNDERLINE}{BLUE}void_descriptor{RESET} <path_to_file>.yml 

140 

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. 

145 

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""" 

151 

152 

153def recon3d(): 

154 """ 

155 Prints the command line documentation to the command window. 

156 

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. 

160 

161 Parameters 

162 ---------- 

163 None 

164 

165 Returns 

166 ------- 

167 None 

168 """ 

169 print(CLI_DOCS) 

170 

171 

172def hello() -> str: 

173 """ 

174 Simple example of a function hooked to a command line entry point. 

175 

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. 

178 

179 Parameters 

180 ---------- 

181 None 

182 

183 Returns 

184 ------- 

185 str 

186 The canonical "Hello world!" string. 

187 """ 

188 

189 return "Hello world!" 

190 

191 

192def module_version(): 

193 """ 

194 Prints the module version and the yml_schema_version. 

195 

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. 

199 

200 Parameters 

201 ---------- 

202 None 

203 

204 Returns 

205 ------- 

206 ver : str 

207 The version of the module. 

208 """ 

209 

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 

216 

217 

218def work_in_progress(): 

219 """ 

220 Prints the 'Work in Progress (WIP)' warning message. 

221 

222 This function prints a warning message indicating that the function is a 

223 work in progress and has not yet been implemented. 

224 

225 Parameters 

226 ---------- 

227 None 

228 

229 Returns 

230 ------- 

231 None 

232 """ 

233 print("Warning: Work in progress (WIP), function not yet implemented.")