-
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 functions related to diffpy.utils
update
#151
Changes from 6 commits
da3340b
8264f17
f9a9eb1
eb5b771
e79a2fd
84d0e33
0cad788
0534810
b479cf2
5fecd14
402677b
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:** | ||
|
||
* Updated functions related to changes in `diffpy.utils` version 3.6.0. | ||
|
||
**Deprecated:** | ||
|
||
* <news item> | ||
|
||
**Removed:** | ||
|
||
* <news item> | ||
|
||
**Fixed:** | ||
|
||
* <news item> | ||
|
||
**Security:** | ||
|
||
* <news item> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,11 @@ | |
import pandas as pd | ||
from scipy.interpolate import interp1d | ||
|
||
from diffpy.utils.scattering_objects.diffraction_objects import XQUANTITIES, Diffraction_object | ||
from diffpy.utils.diffraction_objects import XQUANTITIES, DiffractionObject | ||
|
||
RADIUS_MM = 1 | ||
N_POINTS_ON_DIAMETER = 300 | ||
TTH_GRID = np.arange(1, 180.1, 0.1) | ||
TTH_GRID = np.round(np.arange(1, 180.1, 0.1), decimals=1) | ||
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.
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 ran the interpolation and coefficient lists using 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. mmm., this seems like a slightly dramatic fix to a small edge-case. Is there not a less intrusive fix for this? Let's think about this a bit more. 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. Yeah, maybe I can round down 180 only? 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. that's what I had in mind. |
||
CVE_METHODS = ["brute_force", "polynomial_interpolation"] | ||
|
||
# pre-computed datasets for polynomial interpolation (fast calculation) | ||
|
@@ -191,14 +191,14 @@ def _cve_brute_force(diffraction_data, mud): | |
muls = np.array(muls) / abs_correction.total_points_in_grid | ||
cve = 1 / muls | ||
|
||
cve_do = Diffraction_object(wavelength=diffraction_data.wavelength) | ||
cve_do.insert_scattering_quantity( | ||
TTH_GRID, | ||
cve, | ||
"tth", | ||
metadata=diffraction_data.metadata, | ||
name=f"absorption correction, cve, for {diffraction_data.name}", | ||
cve_do = DiffractionObject( | ||
yucongalicechen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
xarray=TTH_GRID, | ||
yarray=cve, | ||
xtype="tth", | ||
wavelength=diffraction_data.wavelength, | ||
scat_quantity="cve", | ||
name=f"absorption correction, cve, for {diffraction_data.name}", | ||
metadata=diffraction_data.metadata, | ||
) | ||
return cve_do | ||
|
||
|
@@ -211,22 +211,22 @@ def _cve_polynomial_interpolation(diffraction_data, mud): | |
if mud > 6 or mud < 0.5: | ||
raise ValueError( | ||
f"mu*D is out of the acceptable range (0.5 to 6) for polynomial interpolation. " | ||
f"Please rerun with a value within this range or specifying another method from {* CVE_METHODS, }." | ||
f"Please rerun with a value within this range or specifying another method from {*CVE_METHODS, }." | ||
) | ||
coeff_a, coeff_b, coeff_c, coeff_d, coeff_e = [ | ||
interpolation_function(mud) for interpolation_function in INTERPOLATION_FUNCTIONS | ||
] | ||
muls = np.array(coeff_a * MULS**4 + coeff_b * MULS**3 + coeff_c * MULS**2 + coeff_d * MULS + coeff_e) | ||
cve = 1 / muls | ||
|
||
cve_do = Diffraction_object(wavelength=diffraction_data.wavelength) | ||
cve_do.insert_scattering_quantity( | ||
TTH_GRID, | ||
cve, | ||
"tth", | ||
metadata=diffraction_data.metadata, | ||
name=f"absorption correction, cve, for {diffraction_data.name}", | ||
cve_do = DiffractionObject( | ||
xarray=TTH_GRID, | ||
yarray=cve, | ||
xtype="tth", | ||
wavelength=diffraction_data.wavelength, | ||
scat_quantity="cve", | ||
name=f"absorption correction, cve, for {diffraction_data.name}", | ||
metadata=diffraction_data.metadata, | ||
) | ||
return cve_do | ||
|
||
|
@@ -257,7 +257,7 @@ def compute_cve(diffraction_data, mud, method="polynomial_interpolation", xtype= | |
xtype str | ||
the quantity on the independent variable axis, allowed values are {*XQUANTITIES, } | ||
method str | ||
the method used to calculate cve, must be one of {* CVE_METHODS, } | ||
the method used to calculate cve, must be one of {*CVE_METHODS, } | ||
|
||
Returns | ||
------- | ||
|
@@ -270,14 +270,14 @@ def compute_cve(diffraction_data, mud, method="polynomial_interpolation", xtype= | |
global_xtype = cve_do_on_global_grid.on_xtype(xtype)[0] | ||
cve_on_global_xtype = cve_do_on_global_grid.on_xtype(xtype)[1] | ||
newcve = np.interp(orig_grid, global_xtype, cve_on_global_xtype) | ||
cve_do = Diffraction_object(wavelength=diffraction_data.wavelength) | ||
cve_do.insert_scattering_quantity( | ||
orig_grid, | ||
newcve, | ||
xtype, | ||
metadata=diffraction_data.metadata, | ||
name=f"absorption correction, cve, for {diffraction_data.name}", | ||
cve_do = DiffractionObject( | ||
xarray=orig_grid, | ||
yarray=newcve, | ||
xtype=xtype, | ||
wavelength=diffraction_data.wavelength, | ||
scat_quantity="cve", | ||
name=f"absorption correction, cve, for {diffraction_data.name}", | ||
metadata=diffraction_data.metadata, | ||
) | ||
return cve_do | ||
|
||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import copy | ||
from pathlib import Path | ||
|
||
from diffpy.labpdfproc.mud_calculator import compute_mud | ||
from diffpy.utils.scattering_objects.diffraction_objects import QQUANTITIES, XQUANTITIES | ||
from diffpy.utils.tools import get_package_info, get_user_info | ||
from diffpy.utils.diffraction_objects import ANGLEQUANTITIES, QQUANTITIES, XQUANTITIES | ||
from diffpy.utils.tools import compute_mud, get_package_info, get_user_info | ||
|
||
WAVELENGTHS = {"Mo": 0.71, "Ag": 0.59, "Cu": 1.54} | ||
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 think we want a few more sig figs on these 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 found for Mo and Cu the values should be around 0.7107 and 1.5406. I couldn't find the values for Ag though.. |
||
known_sources = [key for key in WAVELENGTHS.keys()] | ||
|
@@ -154,7 +153,9 @@ def set_xtype(args): | |
""" | ||
if args.xtype.lower() not in XQUANTITIES: | ||
raise ValueError(f"Unknown xtype: {args.xtype}. Allowed xtypes are {*XQUANTITIES, }.") | ||
args.xtype = "q" if args.xtype.lower() in QQUANTITIES else "tth" | ||
args.xtype = ( | ||
"q" if args.xtype.lower() in QQUANTITIES else "tth" if args.xtype.lower() in ANGLEQUANTITIES else "d" | ||
yucongalicechen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
return args | ||
|
||
|
||
|
@@ -236,10 +237,9 @@ def load_user_info(args): | |
the updated argparse Namespace with username and email inserted | ||
|
||
""" | ||
config = {"username": args.username, "email": args.email} | ||
config = get_user_info(config) | ||
args.username = config["username"] | ||
args.email = config["email"] | ||
config = get_user_info(owner_name=args.username, owner_email=args.email) | ||
args.username = config["owner_name"] | ||
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. is there a reason you are not using |
||
args.email = config["owner_email"] | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return args | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,11 @@ def user_filesystem(tmp_path): | |
f.write("good_data.xy \n") | ||
f.write(f"{str(input_dir.resolve() / 'good_data.txt')}\n") | ||
|
||
home_config_data = {"username": "home_username", "email": "[email protected]"} | ||
home_config_data = { | ||
"owner_name": "home_username", | ||
"owner_email": "[email protected]", | ||
"owner_orcid": "home_orcid", | ||
} | ||
with open(home_dir / "diffpyconfig.json", "w") as f: | ||
json.dump(home_config_data, f) | ||
|
||
|
This file was deleted.
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.
Can you try and think more precisely about how to say this. "Updated" is the same as "changed" so the message contains close to zero information.....