Skip to content

Commit

Permalink
Merge pull request #155 from yucongalicechen/wavelength
Browse files Browse the repository at this point in the history
fix: update wavelengths
  • Loading branch information
sbillinge authored Jan 30, 2025
2 parents 983a7b0 + 63df4ff commit f805fe3
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 21 deletions.
23 changes: 23 additions & 0 deletions news/wavelength.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* <news item>

**Changed:**

* Increased the number of significant figures for wavelength and separated values for Ka1 and Ka2.

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
58 changes: 38 additions & 20 deletions src/diffpy/labpdfproc/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@
get_user_info,
)

WAVELENGTHS = {"Mo": 0.71073, "Ag": 0.59, "Cu": 1.5406}
# Reference values are taken from
# https://x-server.gmca.aps.anl.gov/cgi/www_dbli.exe?x0hdb=waves
# Ka1Ka2 values are calculated as: (Ka1 * 2 + Ka2) / 3
# For CuKa1Ka2: (1.54056 * 2 + 1.544398) / 3 = 1.54184
WAVELENGTHS = {
"Mo": 0.71073,
"MoKa1": 0.70930,
"MoKa1Ka2": 0.71073,
"Ag": 0.56087,
"AgKa1": 0.55941,
"AgKa1Ka2": 0.56087,
"Cu": 1.54184,
"CuKa1": 1.54056,
"CuKa1Ka2": 1.54184,
}
known_sources = [key for key in WAVELENGTHS.keys()]

# Exclude wavelength from metadata to prevent duplication,
Expand Down Expand Up @@ -166,28 +180,32 @@ def set_wavelength(args):
args : argparse.Namespace
The updated arguments with the wavelength.
"""
if args.wavelength is not None and args.wavelength <= 0:
raise ValueError(
"No valid wavelength. "
"Please rerun specifying a known anode_type "
"or a positive wavelength."
)
if (
not args.wavelength
and args.anode_type
and args.anode_type not in WAVELENGTHS
):
raise ValueError(
f"Anode type not recognized. "
f"Please rerun specifying an anode_type from {*known_sources, }."
if args.wavelength is None:
matched_anode_type = next(
(
key
for key in WAVELENGTHS
if key.lower() == args.anode_type.lower()
),
None,
)

if args.wavelength:
delattr(args, "anode_type")
elif args.anode_type:
if matched_anode_type is None:
raise ValueError(
f"Anode type not recognized. "
f"Please rerun specifying an anode_type "
f"from {*known_sources, }."
)
args.anode_type = matched_anode_type
args.wavelength = WAVELENGTHS[args.anode_type]
else:
args.wavelength = WAVELENGTHS["Mo"]
if args.wavelength <= 0:
raise ValueError(
"No valid wavelength. "
"Please rerun specifying a known anode_type "
"or a positive wavelength."
)
else:
delattr(args, "anode_type")
return args


Expand Down
45 changes: 44 additions & 1 deletion tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,52 @@ def test_set_output_directory_bad(user_filesystem):
@pytest.mark.parametrize(
"inputs, expected",
[
# C1: nothing passed in, expect default is Mo
([], {"wavelength": 0.71073, "anode_type": "Mo"}),
(["--anode-type", "Ag"], {"wavelength": 0.59, "anode_type": "Ag"}),
# C2: only a valid anode type was entered (case independent),
# expect to match the corresponding wavelength
# and preserve the correct case anode type
(["--anode-type", "Mo"], {"wavelength": 0.71073, "anode_type": "Mo"}),
(
["--anode-type", "MoKa1"],
{"wavelength": 0.70930, "anode_type": "MoKa1"},
),
(
["--anode-type", "MoKa1Ka2"],
{"wavelength": 0.71073, "anode_type": "MoKa1Ka2"},
),
(["--anode-type", "Ag"], {"wavelength": 0.56087, "anode_type": "Ag"}),
(
["--anode-type", "AgKa1"],
{"wavelength": 0.55941, "anode_type": "AgKa1"},
),
(
["--anode-type", "AgKa1Ka2"],
{"wavelength": 0.56087, "anode_type": "AgKa1Ka2"},
),
(["--anode-type", "Cu"], {"wavelength": 1.54184, "anode_type": "Cu"}),
(
["--anode-type", "CuKa1"],
{"wavelength": 1.54056, "anode_type": "CuKa1"},
),
(
["--anode-type", "CuKa1Ka2"],
{"wavelength": 1.54184, "anode_type": "CuKa1Ka2"},
),
(
["--anode-type", "moKa1Ka2"],
{"wavelength": 0.71073, "anode_type": "MoKa1Ka2"},
),
(["--anode-type", "ag"], {"wavelength": 0.56087, "anode_type": "Ag"}),
(
["--anode-type", "cuka1"],
{"wavelength": 1.54056, "anode_type": "CuKa1"},
),
# C3: only a valid wavelength was entered,
# expect to include the wavelength only and anode type is None
(["--wavelength", "0.25"], {"wavelength": 0.25, "anode_type": None}),
# C4: both valid anode type and wavelength were entered,
# expect to remove the anode type and preserve wavelength only
(
["--wavelength", "0.25", "--anode-type", "Ag"],
{"wavelength": 0.25, "anode_type": None},
Expand Down

0 comments on commit f805fe3

Please sign in to comment.