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

add new features in scale_to() so user can run without an x-value #289

Merged
merged 11 commits into from
Dec 30, 2024

Conversation

yucongalicechen
Copy link
Contributor

@yucongalicechen yucongalicechen commented Dec 29, 2024

closes #287
@sbillinge reafy for review

@@ -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.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add new feature

Copy link
Contributor

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

Choose a reason for hiding this comment

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

edit description

Copy link

codecov bot commented Dec 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (3f2d0a4) to head (0691e54).
Report is 55 commits behind head on main.

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     
Files with missing lines Coverage Δ
tests/test_diffraction_objects.py 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

[
# 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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

new test case

Copy link
Contributor

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.

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.

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`.
Copy link
Contributor

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:

  1. no xtype/xvalue
  2. if that doesn't give desirable results, specify xtype and xvalue for target. scale to the same (nearest) point in the scaled pattern
  3. 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)

@@ -0,0 +1,23 @@
**Added:**

* new feature in `scale_to()` to run without specifying an x-value
Copy link
Contributor

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

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.

[
# 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
Copy link
Contributor

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.

@@ -319,8 +303,25 @@ def test_scale_to(org_do_args, target_do_args, scale_inputs, expected):
"d": None,
"offset": 0,
Copy link
Contributor

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.

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

@yucongalicechen
Copy link
Contributor Author

@sbillinge ready for review

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.

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

Choose a reason for hiding this comment

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

"default is None"

src/diffpy/utils/diffraction_objects.py Outdated Show resolved Hide resolved
an offset to add to the scaled y-values

Returns
-------
the rescaled DiffractionObject as a new object
"""
if offset is None:
offset = 0

Copy link
Contributor

Choose a reason for hiding this comment

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

remove empty line

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. I answered a question, and raised a new one.

src/diffpy/utils/diffraction_objects.py Show resolved Hide resolved
tests/test_diffraction_objects.py Outdated Show resolved Hide resolved
@yucongalicechen
Copy link
Contributor Author

@sbillinge ready for review!

@sbillinge sbillinge merged commit 88d8d73 into diffpy:main Dec 30, 2024
5 checks passed
@yucongalicechen yucongalicechen deleted the scaleto2 branch December 30, 2024 15:54
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.

DiffractionObject.scale_to() default is to scale to maxima
2 participants