|
1 | 1 | import copy
|
| 2 | +import json |
2 | 3 | from pathlib import Path
|
3 | 4 |
|
4 | 5 | from diffpy.utils.diffraction_objects import ANGLEQUANTITIES, QQUANTITIES, XQUANTITIES
|
|
7 | 8 | # Reference values are taken from https://x-server.gmca.aps.anl.gov/cgi/www_dbli.exe?x0hdb=waves
|
8 | 9 | # Ka1Ka2 values are calculated as: (Ka1 * 2 + Ka2) / 3
|
9 | 10 | # For CuKa1Ka2: (1.54056 * 2 + 1.544398) / 3 = 1.54184
|
10 |
| -WAVELENGTHS = { |
11 |
| - "Mo": 0.71073, |
12 |
| - "MoKa1": 0.70930, |
13 |
| - "MoKa1Ka2": 0.71073, |
14 |
| - "Ag": 0.56087, |
15 |
| - "AgKa1": 0.55941, |
16 |
| - "AgKa1Ka2": 0.56087, |
17 |
| - "Cu": 1.54184, |
18 |
| - "CuKa1": 1.54056, |
19 |
| - "CuKa1Ka2": 1.54184, |
20 |
| -} |
| 11 | +CWD = Path(__file__).parent.resolve() |
| 12 | +WAVELENGTH_FILE_PATH = CWD / "data" / "wavelengths_config.json" |
| 13 | +with open(WAVELENGTH_FILE_PATH, "r") as file: |
| 14 | + WAVELENGTHS = json.load(file) |
21 | 15 | known_sources = [key for key in WAVELENGTHS.keys()]
|
22 | 16 |
|
23 | 17 | # Exclude wavelength from metadata to prevent duplication,
|
@@ -146,22 +140,21 @@ def set_wavelength(args):
|
146 | 140 | args : argparse.Namespace
|
147 | 141 | The updated arguments with the wavelength.
|
148 | 142 | """
|
149 |
| - if args.wavelength is not None and args.wavelength <= 0: |
150 |
| - raise ValueError( |
151 |
| - "No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength." |
152 |
| - ) |
153 |
| - elif not args.wavelength and args.anode_type: |
| 143 | + if args.wavelength is None: |
154 | 144 | matched_anode_type = next((key for key in WAVELENGTHS if key.lower() == args.anode_type.lower()), None)
|
155 | 145 | if matched_anode_type is None:
|
156 | 146 | raise ValueError(
|
157 | 147 | f"Anode type not recognized. Please rerun specifying an anode_type from {*known_sources, }."
|
158 | 148 | )
|
159 | 149 | args.anode_type = matched_anode_type
|
160 | 150 | args.wavelength = WAVELENGTHS[args.anode_type]
|
161 |
| - elif not args.wavelength: |
162 |
| - args.wavelength = WAVELENGTHS["Mo"] |
163 | 151 | else:
|
164 |
| - delattr(args, "anode_type") |
| 152 | + if args.wavelength <= 0: |
| 153 | + raise ValueError( |
| 154 | + "No valid wavelength. Please rerun specifying a known anode_type or a positive wavelength." |
| 155 | + ) |
| 156 | + else: |
| 157 | + delattr(args, "anode_type") |
165 | 158 | return args
|
166 | 159 |
|
167 | 160 |
|
|
0 commit comments