-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: update wavelengths #155
Changes from 4 commits
c5c2da9
703b16a
64e7c4d
89a907a
63df4ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
import copy | ||
import json | ||
from pathlib import Path | ||
|
||
from diffpy.utils.diffraction_objects import ANGLEQUANTITIES, QQUANTITIES, XQUANTITIES | ||
from diffpy.utils.tools import check_and_build_global_config, compute_mud, get_package_info, 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 | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CWD = Path(__file__).parent.resolve() | ||
WAVELENGTH_FILE_PATH = CWD / "data" / "wavelengths_config.json" | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with open(WAVELENGTH_FILE_PATH, "r") as file: | ||
WAVELENGTHS = json.load(file) | ||
known_sources = [key for key in WAVELENGTHS.keys()] | ||
|
||
# Exclude wavelength from metadata to prevent duplication, | ||
|
@@ -133,21 +140,21 @@ 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. Please rerun specifying an anode_type from {*known_sources, }." | ||
) | ||
|
||
if args.wavelength: | ||
delattr(args, "anode_type") | ||
elif args.anode_type: | ||
if args.wavelength is None: | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
matched_anode_type = next((key for key in WAVELENGTHS if key.lower() == args.anode_type.lower()), None) | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if matched_anode_type is None: | ||
raise ValueError( | ||
f"Anode type not recognized. Please rerun specifying an anode_type from {*known_sources, }." | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do I understand that if the user enters both a valid wavelength and an anode type we default to the wavelength? Is there a good use-case where this makes sense? Otherwise it looks to me like magic and we should just crash if the user provides both (i.e., I can see that they would do htat by mistake, I can't see that they would do that on purpose, though there may be a UC that you have in mind. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes so if the user enters only wavelength=0.25 and leaves the anode type empty, it will be automatically loaded as anode type = Mo, but that's wrong. Maybe we can add a check box somewhere to allow user to remove anode type (or automatically remove it when user enters a wavelength, which is kind of what we're doing now)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would throw an error if both are specified. Unless you can think of a case where the user would intentionally do that for some reason. |
||
return args | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should just be in one of the python files. We don't want to have to maintain a dtabase-like json file separately. Is there a reason you moved this from tools.py? This seems like unnecessary infrastructure for us to maintain.