Skip to content
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

Merged
merged 11 commits into from
Jan 14, 2025

Conversation

yucongalicechen
Copy link
Collaborator

closes #129


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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.arrange causes the value at 180 degree to go above 180 slightly because of floating-point precision errors. I think we can round every value to 1 decimal place here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the interpolation and coefficient lists using np.arrange though... but after rerunning a few angles I believe this rounding error is so small that it can be ignored

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe I can round down 180 only?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what I had in mind.

@yucongalicechen
Copy link
Collaborator Author

@sbillinge ready for review. This PR includes all updates from diffpy.utils. No significant functionality changes. But it's causing a conflict because I removed the mud_calculator.

Copy link
Contributor

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exciting! please see inline.


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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@sbillinge
Copy link
Contributor

you will have to merge in main to resolve the conflict (or add the mud calculator back....)


RADIUS_MM = 1
N_POINTS_ON_DIAMETER = 300
TTH_GRID = np.arange(1, 180.1, 0.1)
# Round down the last element if it's slightly above 180 due to floating point precision
TTH_GRID[-1] = 180
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

round down 180 only

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe 180.00 so it is clear you want to keep it as a float?

Copy link

codecov bot commented Jan 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.27%. Comparing base (a9fbbe5) to head (402677b).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #151      +/-   ##
==========================================
- Coverage   99.31%   99.27%   -0.05%     
==========================================
  Files           6        5       -1     
  Lines         293      275      -18     
==========================================
- Hits          291      273      -18     
  Misses          2        2              
Files with missing lines Coverage Δ
tests/conftest.py 100.00% <100.00%> (ø)
tests/test_fixtures.py 100.00% <100.00%> (ø)
tests/test_functions.py 100.00% <100.00%> (ø)
tests/test_tools.py 98.61% <100.00%> (ø)

@yucongalicechen
Copy link
Collaborator Author

yucongalicechen commented Jan 14, 2025

@sbillinge ready for another review. I fixed the TTH_GRID and resolved the conflicts. I will open another PR on fixing docstrings and tests for username orcid etc. once this is merged.

Copy link
Contributor

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't quite finish the review and have to run, but I am posting this now so you can work on it.


**Changed:**

* Updated functions related to changes in `diffpy.utils` version 3.6.0.
Copy link
Contributor

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.....


RADIUS_MM = 1
N_POINTS_ON_DIAMETER = 300
TTH_GRID = np.arange(1, 180.1, 0.1)
# Round down the last element if it's slightly above 180 due to floating point precision
TTH_GRID[-1] = 180
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe 180.00 so it is clear you want to keep it as a float?

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 check_and_build_global_config, compute_mud, get_package_info, get_user_info

WAVELENGTHS = {"Mo": 0.71, "Ag": 0.59, "Cu": 1.54}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want a few more sig figs on these

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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..

config = get_user_info(config)
args.username = config["username"]
args.email = config["email"]
check_and_build_global_config()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since here we are allowing people to pass in this info as an arg, probably the workflow should be

  • if the arg is set, use the arg and don't even run the config updater

  • if the arg is not set, run the config updater

  • run get_user_info passing in the args if they are not None.

args.email = config["email"]
check_and_build_global_config()
config = get_user_info(owner_name=args.username, owner_email=args.email)
args.username = config["owner_name"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason you are not using config.get() here? That is usually better practice.


**Changed:**

* Functions related to diffraction_objects and tools modules in `diffpy.utils` to reflect changes in version 3.6.0.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better wording..?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really. None of the users reading this will have any idea about diffpy.utils 3.6.0.

Something like

* Functions that use DiffractionObject` in `diffpy.utils` to follow the new API.


WAVELENGTHS = {"Mo": 0.71, "Ag": 0.59, "Cu": 1.54}
WAVELENGTHS = {"Mo": 0.71073, "Ag": 0.55941, "Cu": 1.5406}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a little help on the value for Ag. I found it here https://x-server.gmca.aps.anl.gov/cgi/www_dbli.exe?x0hdb=waves but it's a bit off from our original value..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Cu", "CuKa1", "CuKa1Ka2"
CuKa1 : 1.54056
CuKa1Ka2 : =(1.54056*2 + 1.544398)/3 = 1.54184
Cu : 1.542

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yucongalicechen will need docs to explain what is going on.

@yucongalicechen
Copy link
Collaborator Author

@sbillinge ready for some more feedback. The error in the tests is related to the wavelength for Ag.

Copy link
Contributor

@sbillinge sbillinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see inline


**Changed:**

* Functions related to diffraction_objects and tools modules in `diffpy.utils` to reflect changes in version 3.6.0.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really. None of the users reading this will have any idea about diffpy.utils 3.6.0.

Something like

* Functions that use DiffractionObject` in `diffpy.utils` to follow the new API.


WAVELENGTHS = {"Mo": 0.71, "Ag": 0.59, "Cu": 1.54}
WAVELENGTHS = {"Mo": 0.71073, "Ag": 0.55941, "Cu": 1.5406}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Cu", "CuKa1", "CuKa1Ka2"
CuKa1 : 1.54056
CuKa1Ka2 : =(1.54056*2 + 1.544398)/3 = 1.54184
Cu : 1.542


WAVELENGTHS = {"Mo": 0.71, "Ag": 0.59, "Cu": 1.54}
WAVELENGTHS = {"Mo": 0.71073, "Ag": 0.55941, "Cu": 1.5406}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yucongalicechen will need docs to explain what is going on.

@sbillinge sbillinge merged commit 08032ab into diffpy:main Jan 14, 2025
4 of 5 checks passed
@yucongalicechen yucongalicechen deleted the utils-update branch January 15, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check updates from diffpy.utils
2 participants