httomo-backends 2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- httomo_backends/methods_database/__init__.py +0 -0
- httomo_backends/methods_database/backends/httomolib/httomolib.yaml +34 -0
- httomo_backends/methods_database/backends/httomolib/httomolib_modules.yaml +4 -0
- httomo_backends/methods_database/backends/httomolibgpu/httomolibgpu.yaml +192 -0
- httomo_backends/methods_database/backends/httomolibgpu/httomolibgpu_modules.yaml +10 -0
- httomo_backends/methods_database/backends/tomopy/tomopy.yaml +454 -0
- httomo_backends/methods_database/backends/tomopy/tomopy_modules.yaml +10 -0
- httomo_backends/scripts/__init__.py +0 -0
- httomo_backends/scripts/yaml_templates_generator.py +249 -0
- httomo_backends/scripts/yaml_unsupported_tomopy_remove.py +105 -0
- httomo_backends/yaml_templates/__init__.py +0 -0
- httomo_backends/yaml_templates/httomo/httomo.data.hdf.loaders/standard_tomo.yaml +13 -0
- httomo_backends/yaml_templates/httomo/httomo.methods/calculate_stats.yaml +6 -0
- httomo_backends/yaml_templates/httomo/httomo.methods/save_intermediate_data.yaml +9 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/adjust_range.yaml +5 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/circ_mask.yaml +6 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/gaussian_filter.yaml +6 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/median_filter.yaml +5 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/median_filter3d.yaml +4 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/median_filter_nonfinite.yaml +5 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/remove_nan.yaml +4 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/remove_neg.yaml +4 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/remove_outlier.yaml +6 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/remove_outlier1d.yaml +6 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/remove_outlier3d.yaml +5 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/remove_ring.yaml +12 -0
- httomo_backends/yaml_templates/tomopy/tomopy.misc.corr/sobel_filter.yaml +4 -0
- httomo_backends-2.1.dist-info/LICENSE +201 -0
- httomo_backends-2.1.dist-info/METADATA +19 -0
- httomo_backends-2.1.dist-info/RECORD +32 -0
- httomo_backends-2.1.dist-info/WHEEL +5 -0
- httomo_backends-2.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# ---------------------------------------------------------------------------
|
|
4
|
+
# Copyright 2022 Diamond Light Source Ltd.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
# ---------------------------------------------------------------------------
|
|
18
|
+
# Created By : Tomography Team <scientificsoftware@diamond.ac.uk>
|
|
19
|
+
# Created Date: 14/October/2022
|
|
20
|
+
# version ='0.3'
|
|
21
|
+
# ---------------------------------------------------------------------------
|
|
22
|
+
"""Script that exposes all functions of a given software package as YAML templates.
|
|
23
|
+
|
|
24
|
+
Please run the generator as:
|
|
25
|
+
python -m yaml_templates_generator -i /path/to/modules.yml -o /path/to/output/
|
|
26
|
+
"""
|
|
27
|
+
import argparse
|
|
28
|
+
import importlib
|
|
29
|
+
import inspect
|
|
30
|
+
import os
|
|
31
|
+
import re
|
|
32
|
+
from typing import Any, List, Dict
|
|
33
|
+
|
|
34
|
+
import yaml
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def yaml_generator(path_to_modules: str, output_folder: str) -> int:
|
|
38
|
+
"""function that exposes all method of a given software package as YAML templates
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
path_to_modules: path to the list of modules yaml file
|
|
42
|
+
output_folder: path to output folder with saved templates
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
returns zero if the processing is succesfull
|
|
46
|
+
"""
|
|
47
|
+
discard_keys = _get_discard_keys()
|
|
48
|
+
no_data_out_modules = _get_discard_data_out()
|
|
49
|
+
|
|
50
|
+
# open YAML file with modules to inspect
|
|
51
|
+
with open(path_to_modules, "r") as stream:
|
|
52
|
+
try:
|
|
53
|
+
modules_list = yaml.safe_load(stream)
|
|
54
|
+
except yaml.YAMLError as exc:
|
|
55
|
+
print(exc)
|
|
56
|
+
|
|
57
|
+
# a loop over modules in the file
|
|
58
|
+
modules_no = len(modules_list)
|
|
59
|
+
for i in range(modules_no):
|
|
60
|
+
module_name = modules_list[i]
|
|
61
|
+
try:
|
|
62
|
+
imported_module = importlib.import_module(str(module_name))
|
|
63
|
+
except NameError:
|
|
64
|
+
print(
|
|
65
|
+
"Import of the module {} has failed, check if software installed".format(
|
|
66
|
+
module_name
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
methods_list = imported_module.__all__ # get all the methods in the module
|
|
70
|
+
methods_no = len(methods_list)
|
|
71
|
+
|
|
72
|
+
# a loop over all methods in the module
|
|
73
|
+
for m in range(methods_no):
|
|
74
|
+
method_name = methods_list[m]
|
|
75
|
+
print("Inspecting the signature of the {} method".format(method_name))
|
|
76
|
+
get_method_params = inspect.signature(
|
|
77
|
+
getattr(imported_module, methods_list[m])
|
|
78
|
+
)
|
|
79
|
+
# get method docstrings
|
|
80
|
+
get_method_docs = inspect.getdoc(getattr(imported_module, methods_list[m]))
|
|
81
|
+
|
|
82
|
+
# put the parameters in the dictionary
|
|
83
|
+
params_list: List = []
|
|
84
|
+
params_dict: Dict = {}
|
|
85
|
+
for name, value in get_method_params.parameters.items():
|
|
86
|
+
if value is not None:
|
|
87
|
+
append = True
|
|
88
|
+
for x in discard_keys:
|
|
89
|
+
if name == x:
|
|
90
|
+
append = False
|
|
91
|
+
break
|
|
92
|
+
if append:
|
|
93
|
+
_set_param_value(name, value, params_dict)
|
|
94
|
+
method_dict = {
|
|
95
|
+
"method": method_name,
|
|
96
|
+
"module_path": module_name,
|
|
97
|
+
"parameters": params_dict,
|
|
98
|
+
}
|
|
99
|
+
_set_dict_special_cases(method_dict, method_name)
|
|
100
|
+
params_list = [method_dict]
|
|
101
|
+
_save_yaml(module_name, method_name, params_list)
|
|
102
|
+
return 0
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _set_param_value(name: str, value: inspect.Parameter, params_dict: Dict[str, Any]):
|
|
106
|
+
"""Set param value for method inside dictionary
|
|
107
|
+
Args:
|
|
108
|
+
name: Parameter name
|
|
109
|
+
value: Parameter value
|
|
110
|
+
params_dict: Dict containing method's parameter names and values
|
|
111
|
+
"""
|
|
112
|
+
if value.default is inspect.Parameter.empty and name != "kwargs":
|
|
113
|
+
if name in ["proj1", "proj2"]:
|
|
114
|
+
params_dict[name] = "auto"
|
|
115
|
+
else:
|
|
116
|
+
params_dict[name] = "REQUIRED"
|
|
117
|
+
elif name == "kwargs":
|
|
118
|
+
# params_dict["#additional parameters"] = "AVAILABLE"
|
|
119
|
+
# parsing hashtag to yaml comes with quotes, for now we simply ignore the field
|
|
120
|
+
pass
|
|
121
|
+
elif name == "axis":
|
|
122
|
+
params_dict[name] = "auto"
|
|
123
|
+
elif name == "asynchronous":
|
|
124
|
+
params_dict[name] = True
|
|
125
|
+
elif name == "center":
|
|
126
|
+
# Temporary value
|
|
127
|
+
params_dict[name] = "${{centering.side_outputs.centre_of_rotation}}"
|
|
128
|
+
elif name == "glob_stats":
|
|
129
|
+
params_dict[name] = "${{statistics.side_outputs.glob_stats}}"
|
|
130
|
+
elif name == "overlap":
|
|
131
|
+
params_dict[name] = "${{centering.side_outputs.overlap}}"
|
|
132
|
+
else:
|
|
133
|
+
params_dict[name] = value.default
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _save_yaml(module_name: str, method_name: str, params_list: List[str]):
|
|
137
|
+
"""Save the list as a YAML file
|
|
138
|
+
Args:
|
|
139
|
+
module_name: Name of module
|
|
140
|
+
method_name: Name of method
|
|
141
|
+
params_list: List of parameters
|
|
142
|
+
"""
|
|
143
|
+
path_dir = output_folder + "/" + module_name
|
|
144
|
+
path_file = path_dir + "/" + str(method_name) + ".yaml"
|
|
145
|
+
|
|
146
|
+
if not os.path.exists(path_dir):
|
|
147
|
+
os.makedirs(path_dir)
|
|
148
|
+
|
|
149
|
+
with open(path_file, "w") as file:
|
|
150
|
+
outputs = yaml.dump(params_list, file, sort_keys=False)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _set_dict_special_cases(method_dict: Dict, method_name: str):
|
|
154
|
+
"""Dealing with special cases for "data_out"
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
method_dict: Dictionary of modules and parameters
|
|
158
|
+
method_name: Name of method
|
|
159
|
+
"""
|
|
160
|
+
if method_name in ["find_center_vo", "find_center_pc"]:
|
|
161
|
+
method_dict["id"] = "centering"
|
|
162
|
+
method_dict["side_outputs"] = {"cor": "centre_of_rotation"}
|
|
163
|
+
if method_name in "find_center_360":
|
|
164
|
+
method_dict["id"] = "centering"
|
|
165
|
+
method_dict["side_outputs"] = {
|
|
166
|
+
"cor": "centre_of_rotation",
|
|
167
|
+
"overlap": "overlap",
|
|
168
|
+
"side": "side",
|
|
169
|
+
"overlap_position": "overlap_position",
|
|
170
|
+
}
|
|
171
|
+
if method_name in "calculate_stats":
|
|
172
|
+
method_dict["id"] = "statistics"
|
|
173
|
+
method_dict["side_outputs"] = {"glob_stats": "glob_stats"}
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _get_discard_data_out() -> List[str]:
|
|
177
|
+
"""Discard data_out from certain modules
|
|
178
|
+
|
|
179
|
+
Returns: list of data_out to discard
|
|
180
|
+
"""
|
|
181
|
+
discard_data_out = ["save_to_images"]
|
|
182
|
+
return discard_data_out
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _get_discard_keys() -> List[str]:
|
|
186
|
+
"""Can work with any software in principle,
|
|
187
|
+
but for TomoPy and httomolib there are additional keys
|
|
188
|
+
that needed to be discarded in templates in order to let
|
|
189
|
+
httomo work smoothly.
|
|
190
|
+
|
|
191
|
+
Returns: List of keys to discard
|
|
192
|
+
"""
|
|
193
|
+
discard_keys = [
|
|
194
|
+
"in_file",
|
|
195
|
+
"data_in",
|
|
196
|
+
"tomo",
|
|
197
|
+
"arr",
|
|
198
|
+
"prj",
|
|
199
|
+
"data",
|
|
200
|
+
"ncore",
|
|
201
|
+
"nchunk",
|
|
202
|
+
"flats",
|
|
203
|
+
"flat",
|
|
204
|
+
"dark",
|
|
205
|
+
"darks",
|
|
206
|
+
"theta",
|
|
207
|
+
"out",
|
|
208
|
+
"ang",
|
|
209
|
+
"comm_rank",
|
|
210
|
+
"out_dir",
|
|
211
|
+
"angles",
|
|
212
|
+
"gpu_id",
|
|
213
|
+
"comm",
|
|
214
|
+
"offset",
|
|
215
|
+
]
|
|
216
|
+
return discard_keys
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def get_args():
|
|
220
|
+
parser = argparse.ArgumentParser(
|
|
221
|
+
description="Script that exposes all functions "
|
|
222
|
+
"of a given software package as YAML templates."
|
|
223
|
+
)
|
|
224
|
+
parser.add_argument(
|
|
225
|
+
"-i",
|
|
226
|
+
"--input",
|
|
227
|
+
type=str,
|
|
228
|
+
default=None,
|
|
229
|
+
help="A path to the list of modules yaml file"
|
|
230
|
+
"which is needed to be inspected and functions extracted.",
|
|
231
|
+
)
|
|
232
|
+
parser.add_argument(
|
|
233
|
+
"-o",
|
|
234
|
+
"--output",
|
|
235
|
+
type=str,
|
|
236
|
+
default="./",
|
|
237
|
+
help="Directory to save the yaml templates in.",
|
|
238
|
+
)
|
|
239
|
+
return parser.parse_args()
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
if __name__ == "__main__":
|
|
243
|
+
current_dir = os.path.basename(os.path.abspath(os.curdir))
|
|
244
|
+
args = get_args()
|
|
245
|
+
path_to_modules = args.input
|
|
246
|
+
output_folder = args.output
|
|
247
|
+
return_val = yaml_generator(path_to_modules, output_folder)
|
|
248
|
+
if return_val == 0:
|
|
249
|
+
print("The methods as YAML templates have been successfully generated!")
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# ---------------------------------------------------------------------------
|
|
4
|
+
# Copyright 2022 Diamond Light Source Ltd.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
# ---------------------------------------------------------------------------
|
|
18
|
+
# Created By : Daniil Kazantsev <scientificsoftware@diamond.ac.uk>
|
|
19
|
+
# Created Date: 13/April/2023
|
|
20
|
+
# version ='0.1'
|
|
21
|
+
# ---------------------------------------------------------------------------
|
|
22
|
+
"""After _all_ templates have been generated for TomoPy we need to remove the ones
|
|
23
|
+
that are not currently supported by httomo. We do that by looking into
|
|
24
|
+
the library file for TomoPy."""
|
|
25
|
+
|
|
26
|
+
import argparse
|
|
27
|
+
import importlib
|
|
28
|
+
import inspect
|
|
29
|
+
import os
|
|
30
|
+
import re
|
|
31
|
+
import shutil
|
|
32
|
+
from pathlib import Path
|
|
33
|
+
|
|
34
|
+
import yaml
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def templates_filter(path_to_modules: str, library_file: str) -> int:
|
|
38
|
+
"""function that removes unsupported by httomo YAML templates in TomoPy
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
path_to_modules (str): path to the list of modules yaml file
|
|
42
|
+
library_file (str): path to the library with the supported functions of TomoPy
|
|
43
|
+
|
|
44
|
+
Returns:
|
|
45
|
+
int: returns zero if the processing is succesfull
|
|
46
|
+
"""
|
|
47
|
+
software_name = "tomopy"
|
|
48
|
+
yaml_info_path = Path(library_file)
|
|
49
|
+
if not yaml_info_path.exists():
|
|
50
|
+
err_str = f"The YAML file {yaml_info_path} doesn't exist."
|
|
51
|
+
raise ValueError(err_str)
|
|
52
|
+
|
|
53
|
+
with open(yaml_info_path, "r") as f:
|
|
54
|
+
yaml_library = yaml.safe_load(f)
|
|
55
|
+
|
|
56
|
+
methods_list: list = []
|
|
57
|
+
for module, module_dict in yaml_library.items():
|
|
58
|
+
for module2, module_dict2 in module_dict.items():
|
|
59
|
+
for method_name in module_dict2:
|
|
60
|
+
methods_list.append(method_name)
|
|
61
|
+
|
|
62
|
+
subfolders = [f.path for f in os.scandir(path_to_modules) if f.is_dir()]
|
|
63
|
+
for folder in subfolders:
|
|
64
|
+
for filename in os.listdir(folder):
|
|
65
|
+
filename_short = filename.split(".")
|
|
66
|
+
if filename_short[0] not in methods_list:
|
|
67
|
+
print(f"Removed template: {filename_short[0]}")
|
|
68
|
+
file_path = os.path.join(folder, filename)
|
|
69
|
+
try:
|
|
70
|
+
if os.path.isfile(file_path) or os.path.islink(file_path):
|
|
71
|
+
os.unlink(file_path)
|
|
72
|
+
except Exception as e:
|
|
73
|
+
print("Failed to delete %s. Reason: %s" % (file_path, e))
|
|
74
|
+
return 0
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def get_args():
|
|
78
|
+
parser = argparse.ArgumentParser(
|
|
79
|
+
description="Removes unsupported by httomo templates in TomoPy."
|
|
80
|
+
)
|
|
81
|
+
parser.add_argument(
|
|
82
|
+
"-t",
|
|
83
|
+
"--templates",
|
|
84
|
+
type=str,
|
|
85
|
+
default=None,
|
|
86
|
+
help="A path to the folder where generated templates stored.",
|
|
87
|
+
)
|
|
88
|
+
parser.add_argument(
|
|
89
|
+
"-l",
|
|
90
|
+
"--library",
|
|
91
|
+
type=str,
|
|
92
|
+
default=None,
|
|
93
|
+
help="A path to the library YAML file with the supported functions.",
|
|
94
|
+
)
|
|
95
|
+
return parser.parse_args()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
current_dir = os.path.basename(os.path.abspath(os.curdir))
|
|
100
|
+
args = get_args()
|
|
101
|
+
path_to_modules = args.templates
|
|
102
|
+
library_file = args.library
|
|
103
|
+
return_val = templates_filter(path_to_modules, library_file)
|
|
104
|
+
if return_val == 0:
|
|
105
|
+
print("The templates have been filtered!")
|
|
File without changes
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
- method: standard_tomo
|
|
2
|
+
module_path: httomo.data.hdf.loaders
|
|
3
|
+
parameters:
|
|
4
|
+
name: REQUIRED
|
|
5
|
+
data_path: REQUIRED
|
|
6
|
+
dimension: REQUIRED
|
|
7
|
+
preview: REQUIRED
|
|
8
|
+
pad: REQUIRED
|
|
9
|
+
image_key_path: null
|
|
10
|
+
rotation_angles:
|
|
11
|
+
data_path: /entry1/tomo_entry/data/rotation_angle
|
|
12
|
+
ignore_darks: false
|
|
13
|
+
ignore_flats: false
|