Skip to content

Commit 89a907a

Browse files
fix: put WAVELENGTHS into a json file, simplified logic for set_wavelength function
1 parent 64e7c4d commit 89a907a

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Mo": 0.71073,
3+
"MoKa1": 0.70930,
4+
"MoKa1Ka2": 0.71073,
5+
"Ag": 0.56087,
6+
"AgKa1": 0.55941,
7+
"AgKa1Ka2": 0.56087,
8+
"Cu": 1.54184,
9+
"CuKa1": 1.54056,
10+
"CuKa1Ka2": 1.54184
11+
}

src/diffpy/labpdfproc/tools.py

+12-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import copy
2+
import json
23
from pathlib import Path
34

45
from diffpy.utils.diffraction_objects import ANGLEQUANTITIES, QQUANTITIES, XQUANTITIES
@@ -7,17 +8,10 @@
78
# Reference values are taken from https://x-server.gmca.aps.anl.gov/cgi/www_dbli.exe?x0hdb=waves
89
# Ka1Ka2 values are calculated as: (Ka1 * 2 + Ka2) / 3
910
# 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)
2115
known_sources = [key for key in WAVELENGTHS.keys()]
2216

2317
# Exclude wavelength from metadata to prevent duplication,
@@ -146,22 +140,21 @@ def set_wavelength(args):
146140
args : argparse.Namespace
147141
The updated arguments with the wavelength.
148142
"""
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:
154144
matched_anode_type = next((key for key in WAVELENGTHS if key.lower() == args.anode_type.lower()), None)
155145
if matched_anode_type is None:
156146
raise ValueError(
157147
f"Anode type not recognized. Please rerun specifying an anode_type from {*known_sources, }."
158148
)
159149
args.anode_type = matched_anode_type
160150
args.wavelength = WAVELENGTHS[args.anode_type]
161-
elif not args.wavelength:
162-
args.wavelength = WAVELENGTHS["Mo"]
163151
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")
165158
return args
166159

167160

0 commit comments

Comments
 (0)