|
| 1 | +import copy |
1 | 2 | from pathlib import Path |
2 | 3 |
|
3 | 4 | from diffpy.utils.tools import get_package_info, get_user_info |
4 | 5 |
|
5 | 6 | WAVELENGTHS = {"Mo": 0.71, "Ag": 0.59, "Cu": 1.54} |
6 | 7 | known_sources = [key for key in WAVELENGTHS.keys()] |
| 8 | +METADATA_KEYS_TO_EXCLUDE = ["output_correction", "force_overwrite", "input", "input_paths"] |
7 | 9 |
|
8 | 10 |
|
9 | 11 | def set_output_directory(args): |
@@ -110,7 +112,7 @@ def set_wavelength(args): |
110 | 112 |
|
111 | 113 | Returns |
112 | 114 | ------- |
113 | | - float: the wavelength value |
| 115 | + args argparse.Namespace |
114 | 116 |
|
115 | 117 | we raise an ValueError if the input wavelength is non-positive |
116 | 118 | or if the input anode_type is not one of the known sources |
@@ -214,3 +216,47 @@ def load_package_info(args): |
214 | 216 | metadata = get_package_info("diffpy.labpdfproc") |
215 | 217 | setattr(args, "package_info", metadata["package_info"]) |
216 | 218 | return args |
| 219 | + |
| 220 | + |
| 221 | +def preprocessing_args(args): |
| 222 | + """ |
| 223 | + Perform preprocessing on the provided argparse Namespace |
| 224 | +
|
| 225 | + Parameters |
| 226 | + ---------- |
| 227 | + args argparse.Namespace |
| 228 | + the arguments from the parser, default is None |
| 229 | +
|
| 230 | + Returns |
| 231 | + ------- |
| 232 | + the updated argparse Namespace with arguments preprocessed |
| 233 | + """ |
| 234 | + args = load_package_info(args) |
| 235 | + args = load_user_info(args) |
| 236 | + args = set_input_lists(args) |
| 237 | + args.output_directory = set_output_directory(args) |
| 238 | + args = set_wavelength(args) |
| 239 | + args = load_user_metadata(args) |
| 240 | + return args |
| 241 | + |
| 242 | + |
| 243 | +def load_metadata(args, filepath): |
| 244 | + """ |
| 245 | + Load relevant metadata from args |
| 246 | +
|
| 247 | + Parameters |
| 248 | + ---------- |
| 249 | + args argparse.Namespace |
| 250 | + the arguments from the parser |
| 251 | +
|
| 252 | + Returns |
| 253 | + ------- |
| 254 | + A dictionary with relevant arguments from the parser |
| 255 | + """ |
| 256 | + |
| 257 | + metadata = copy.deepcopy(vars(args)) |
| 258 | + for key in METADATA_KEYS_TO_EXCLUDE: |
| 259 | + metadata.pop(key, None) |
| 260 | + metadata["input_directory"] = str(filepath) |
| 261 | + metadata["output_directory"] = str(metadata["output_directory"]) |
| 262 | + return metadata |
0 commit comments