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

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 

16CLI_DOCS: Final[ 

17 str 

18] = """ 

19-------- 

20recon3d 

21-------- 

22 

23recon3d 

24 (this command) 

25 

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. 

29 

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 

34 

35downscale <path_to_file>.yml 

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

37 

38 Example: 

39 # Edit path variables in 

40 # ~/recon3d/docs/userguide/src/downscale/downscale_thunder.yml 

41 (.venv) recon3d> downscale downscale_thunder.yml 

42 

43grayscale_image_stack_to_segmentation <path_to_file>.yml 

44 Converts a series of grayscale images to a segmentation. 

45 

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 

50 

51hello 

52 Prints 'Hello world!' to the terminal to illustrate command line 

53 entry points. 

54 

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. 

59 

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 

64 

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. 

68 

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 

73 

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. 

77 

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 

82 

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 

86 

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 

91 

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. 

97 

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 

102 

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. 

107 

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 

112 

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/ 

117 

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 

122 

123 

124""" 

125 

126 

127def recon3d(): 

128 """ 

129 Prints the command line documentation to the command window. 

130 

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. 

134 

135 Parameters 

136 ---------- 

137 None 

138 

139 Returns 

140 ------- 

141 None 

142 """ 

143 print(CLI_DOCS) 

144 

145 

146def hello() -> str: 

147 """ 

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

149 

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. 

152 

153 Parameters 

154 ---------- 

155 None 

156 

157 Returns 

158 ------- 

159 str 

160 The canonical "Hello world!" string. 

161 """ 

162 

163 return "Hello world!" 

164 

165 

166def module_version(): 

167 """ 

168 Prints the module version and the yml_schema_version. 

169 

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. 

173 

174 Parameters 

175 ---------- 

176 None 

177 

178 Returns 

179 ------- 

180 ver : str 

181 The version of the module. 

182 """ 

183 

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 

190 

191 

192def work_in_progress(): 

193 """ 

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

195 

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

197 work in progress and has not yet been implemented. 

198 

199 Parameters 

200 ---------- 

201 None 

202 

203 Returns 

204 ------- 

205 None 

206 """ 

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