-
Notifications
You must be signed in to change notification settings - Fork 21
test function on_xtype #192
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5a32de4
initial commit, raise value error if xtype is invalid
yucongalicechen 19efee8
merge main into this branch
yucongalicechen bf52078
change test intensity array to avoid duplication with x-arrays
yucongalicechen 1344a7d
merge updates from main
yucongalicechen 1f9f142
edit tests
yucongalicechen 11a15ee
add docstring and news
yucongalicechen 57465e2
edit tests
yucongalicechen 2e1853a
edit docstring
yucongalicechen 7eb0c0d
remove warning in error msg
yucongalicechen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
**Added:** | ||
|
||
* functionality to return the 2D array based on the specified xtype | ||
|
||
**Changed:** | ||
|
||
* <news item> | ||
|
||
**Deprecated:** | ||
|
||
* <news item> | ||
|
||
**Removed:** | ||
|
||
* <news item> | ||
|
||
**Fixed:** | ||
|
||
* <news item> | ||
|
||
**Security:** | ||
|
||
* <news item> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,16 +376,17 @@ def scale_to(self, target_diff_object, xtype=None, xvalue=None): | |
return scaled | ||
|
||
def on_xtype(self, xtype): | ||
""" | ||
f""" | ||
return a 2D np array with x in the first column and y in the second for x of type type | ||
|
||
Parameters | ||
---------- | ||
xtype | ||
xtype str | ||
the type of quantity for the independent variable from {*XQUANTITIES, } | ||
|
||
Returns | ||
------- | ||
|
||
a 2D np array with x and y data | ||
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. see above |
||
""" | ||
if xtype.lower() in ANGLEQUANTITIES: | ||
return self.on_tth() | ||
|
@@ -394,7 +395,7 @@ def on_xtype(self, xtype): | |
elif xtype.lower() in DQUANTITIES: | ||
return self.on_d() | ||
else: | ||
warnings.warn(_xtype_wmsg(xtype)) | ||
raise ValueError(_xtype_wmsg(xtype)) | ||
yucongalicechen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def dump(self, filepath, xtype=None): | ||
if xtype is None: | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import re | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
import pytest | ||
from freezegun import freeze_time | ||
|
||
from diffpy.utils.diffraction_objects import DiffractionObject | ||
from diffpy.utils.transforms import wavelength_warning_emsg | ||
from diffpy.utils.diffraction_objects import XQUANTITIES, DiffractionObject | ||
|
||
|
||
def compare_dicts(dict1, dict2): | ||
|
@@ -202,13 +202,24 @@ def test_diffraction_objects_equality(inputs1, inputs2, expected): | |
assert dicts_equal(diffraction_object1.__dict__, diffraction_object2.__dict__) == expected | ||
|
||
|
||
def _test_valid_diffraction_objects(actual_diffraction_object, function, expected_array): | ||
yucongalicechen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if actual_diffraction_object.wavelength is None: | ||
with pytest.warns(UserWarning) as warn_record: | ||
getattr(actual_diffraction_object, function)() | ||
assert str(warn_record[0].message) == wavelength_warning_emsg | ||
actual_array = getattr(actual_diffraction_object, function)() | ||
return np.allclose(actual_array, expected_array) | ||
def test_on_xtype(): | ||
test = DiffractionObject(wavelength=2 * np.pi, xarray=np.array([30, 60]), yarray=np.array([1, 2]), xtype="tth") | ||
assert np.allclose(test.on_xtype("tth"), [np.array([30, 60]), np.array([1, 2])]) | ||
sbillinge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert np.allclose(test.on_xtype("2theta"), [np.array([30, 60]), np.array([1, 2])]) | ||
assert np.allclose(test.on_xtype("q"), [np.array([0.51764, 1]), np.array([1, 2])]) | ||
assert np.allclose(test.on_xtype("d"), [np.array([12.13818, 6.28319]), np.array([1, 2])]) | ||
|
||
|
||
def test_on_xtype_bad(): | ||
test = DiffractionObject() | ||
with pytest.raises( | ||
ValueError, | ||
match=re.escape( | ||
f"WARNING: I don't know how to handle the xtype, 'invalid'. Please rerun specifying an " | ||
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 are now raising an exception, right? So this isn't a warning. Just remove |
||
f"xtype from {*XQUANTITIES, }" | ||
), | ||
): | ||
test.on_xtype("invalid") | ||
|
||
|
||
def test_dump(tmp_path, mocker): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we want to return a list of two 1D arrays