-
Notifications
You must be signed in to change notification settings - Fork 19
feat: add warning for extrapolation in morphsqueeze
#250
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 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
400851b
feat: add warning for extrapolation in `morphsqueeze`
ycexiao 4f59c54
[pre-commit.ci] auto fixes from pre-commit hooks
pre-commit-ci[bot] bdd29ae
chore: add news
ycexiao 0cbcee4
test: add test for warning extrapolation in `morphsqueeze`
ycexiao 026984a
chore: update warning message for extrapolation in `morphsqueeze.py`
ycexiao e165b41
test: add CLI test for extrapolation warning
ycexiao 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:** | ||
|
|
||
| * No news added: Add warning for extrapolation in morphsqueeze.py. | ||
|
|
||
| **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 |
|---|---|---|
| @@ -1,13 +1,22 @@ | ||
| """Class MorphSqueeze -- Apply a polynomial to squeeze the morph | ||
| function.""" | ||
|
|
||
| import warnings | ||
|
|
||
| import numpy as np | ||
| from numpy.polynomial import Polynomial | ||
| from scipy.interpolate import CubicSpline | ||
|
|
||
| from diffpy.morph.morphs.morph import LABEL_GR, LABEL_RA, Morph | ||
|
|
||
|
|
||
| def custom_formatwarning(msg, *args, **kwargs): | ||
| return f"{msg}\n" | ||
|
|
||
|
|
||
| warnings.formatwarning = custom_formatwarning | ||
|
|
||
|
|
||
| class MorphSqueeze(Morph): | ||
| """Squeeze the morph function. | ||
|
|
||
|
|
@@ -85,4 +94,22 @@ def morph(self, x_morph, y_morph, x_target, y_target): | |
| high_extrap = np.where(self.x_morph_in > x_squeezed[-1])[0] | ||
| self.extrap_index_low = low_extrap[-1] if low_extrap.size else None | ||
| self.extrap_index_high = high_extrap[0] if high_extrap.size else None | ||
|
|
||
| begin_end_sqeeze = min(x_squeezed), max(x_squeezed) | ||
| begin_end_in = min(self.x_morph_in), max(self.x_morph_in) | ||
| if not ( | ||
| begin_end_sqeeze[0] <= begin_end_in[0] | ||
| and begin_end_in[-1] >= begin_end_in[-1] | ||
| ): | ||
| wmsg = ( | ||
|
||
| "\nExtrapolating the morphed function via CubicSpline:\n" | ||
| f"Obtaining grid points between {begin_end_in[0]} and " | ||
| f"{begin_end_in[1]}.\n" | ||
| f"Points below {begin_end_sqeeze[0]} and " | ||
| f"above {begin_end_sqeeze[1]} will be extrapolated." | ||
| ) | ||
| warnings.warn( | ||
| wmsg, | ||
| UserWarning, | ||
| ) | ||
| return self.xyallout | ||
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
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.
Do we want to remove these few lines of code? I can't find other references to the variables defined here.
Uh oh!
There was an error while loading. Please reload this page.
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.
These were variables we made before to store what you have now called begin_end_squeeze. You can delete it if you prefer using begin_end_squeeze.
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 find these variables provide a handy interface to test the extrapolated effect in
test_morphsqueeze, so I think we should keep them.