-
Notifications
You must be signed in to change notification settings - Fork 20
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
add new features in scale_to()
so user can run without an x-value
#289
Conversation
@@ -402,14 +402,16 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=0): | |||
|
|||
The y-value in the target at the closest specified x-value will be used as the factor to scale to. | |||
The entire array is scaled by this factor so that one object places on top of the other at that point. | |||
If multiple values of `q`, `tth`, or `d` are provided, or none are provided, an error will be raised. | |||
If none of `q`, `tth`, or `d` are provided, | |||
the scaling will be based on the maximal x-array value from both objects. |
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.
add new feature
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.
as above. Put this behavior first.
|
||
Parameters | ||
---------- | ||
target_diff_object: DiffractionObject | ||
the diffraction object you want to scale the current one onto | ||
|
||
q, tth, d : float, optional, must specify exactly one of them | ||
q, tth, d : float, optional, default is q with the maximal x-array value of the current object |
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.
edit description
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #289 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 8
Lines 408 496 +88
=========================================
+ Hits 408 496 +88
|
tests/test_diffraction_objects.py
Outdated
[ | ||
# Test expected errors produced from scale_to() with invalid inputs | ||
( # C1: none of q, tth, d, provided, expect ValueError | ||
( # C5: none of q, tth, d, provided, expect to scale on the maximal x-arrays |
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.
new test case
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.
put this one first? I think it is worth the extra effort as this is our new default behavior.
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.
Thanks @yucongalicechen !. please see inline comments.
@@ -117,6 +117,13 @@ For convenience, you can also apply an offset to the scaled new diffraction obje | |||
|
|||
scaled_and_offset_measured = measured.scale_to(calculated, q=5.5, offset=0.5) | |||
|
|||
You can call `scale_to()` without specifying a value for `q`, `tth`, or `d`. |
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.
This will be the default behavior so should go first in the docs. Then we can say something like "if this doesnlt give desirable results you can user....." and describe the other workflow.
To give even more flexibility to the user we may want to allow them to specify a separate xtype and xvalue for the target and the scaled DO. The hierarchy woiuld be:
- no xtype/xvalue
- if that doesn't give desirable results, specify xtype and xvalue for target. scale to the same (nearest) point in the scaled pattern
- if that doesn't give desirable results, specify xtype, and a different xvalue for target. and scaled DO, respectively. Scale the yvale of xvalue_scaled to yvalue of xvalue_target.
This last functionality is a new one and we should put it on a new issue (and a new PR if we want to implement it)
news/scaleto-max.rst
Outdated
@@ -0,0 +1,23 @@ | |||
**Added:** | |||
|
|||
* new feature in `scale_to()` to run without specifying an x-value |
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.
describe what it does, not what it doesn't do...i.e., scales to max value in each chase. You can also add that it allows this to be used without xvalue
@@ -402,14 +402,16 @@ def scale_to(self, target_diff_object, q=None, tth=None, d=None, offset=0): | |||
|
|||
The y-value in the target at the closest specified x-value will be used as the factor to scale to. | |||
The entire array is scaled by this factor so that one object places on top of the other at that point. | |||
If multiple values of `q`, `tth`, or `d` are provided, or none are provided, an error will be raised. | |||
If none of `q`, `tth`, or `d` are provided, | |||
the scaling will be based on the maximal x-array value from both objects. |
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.
as above. Put this behavior first.
tests/test_diffraction_objects.py
Outdated
[ | ||
# Test expected errors produced from scale_to() with invalid inputs | ||
( # C1: none of q, tth, d, provided, expect ValueError | ||
( # C5: none of q, tth, d, provided, expect to scale on the maximal x-arrays |
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.
put this one first? I think it is worth the extra effort as this is our new default behavior.
tests/test_diffraction_objects.py
Outdated
@@ -319,8 +303,25 @@ def test_scale_to(org_do_args, target_do_args, scale_inputs, expected): | |||
"d": None, | |||
"offset": 0, |
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.
this is a different issue, unrelated to what you are doing here, but I would rather have default offset to be None (set to zero if None). I think this is more logical for my brain. If I don't set an offset, the offset is None.
tests/test_diffraction_objects.py
Outdated
original_do = DiffractionObject(**org_do_args) | ||
target_do = DiffractionObject(**target_do_args) | ||
scaled_do = original_do.scale_to( | ||
target_do, q=scale_inputs["q"], tth=scale_inputs["tth"], d=scale_inputs["d"], offset=scale_inputs["offset"] |
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 need to fgure out a way only pass in what is needed, rather than passing in everything with some things set to default values. It may need more test functions written, but see if you can figure out how to do it with unpacking kwargs that are handed in.
… update tests for flexible inputs
@sbillinge ready for review |
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.
small tweaks
If multiple values of `q`, `tth`, or `d` are provided, an error will be raised. | ||
|
||
Parameters | ||
---------- | ||
target_diff_object: DiffractionObject | ||
the diffraction object you want to scale the current one onto | ||
|
||
q, tth, d : float, optional, default is q with the maximal x-array value of the current object | ||
q, tth, d : float, optional, default is the max q-value from each object |
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.
"default is None"
an offset to add to the scaled y-values | ||
|
||
Returns | ||
------- | ||
the rescaled DiffractionObject as a new object | ||
""" | ||
if offset is None: | ||
offset = 0 | ||
|
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.
remove empty line
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.
please see inline. I answered a question, and raised a new one.
@sbillinge ready for review! |
closes #287
@sbillinge reafy for review