-
Notifications
You must be signed in to change notification settings - Fork 18
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
Changes from 2 commits
400851b
4f59c54
bdd29ae
0cbcee4
026984a
e165b41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| """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 | ||
|
|
@@ -85,4 +87,17 @@ 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 | ||
|
|
||
| low_extrap_x = x_squeezed[0] - self.x_morph_in[0] | ||
|
Collaborator
Author
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 the length of
Collaborator
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 most recent comment.
Collaborator
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 the best would just be to say something like: "Warning: all points below {low} and above {high} are extrapolated using cubic spline etc. etc." Make it clear that the low and high thresholds are for the grid (can't think of a proper way to word it right now). Best to mention the method of extrapolation used (cubic spline I believe). Edit for clarity: The low and high shouldn't be the lengths currently reported but rather the locations above/below which extrapolation is happening. |
||
| high_extrap_x = self.x_morph_in[-1] - x_squeezed[-1] | ||
| if low_extrap_x > 0 or high_extrap_x > 0: | ||
| wmsg = "Extrapolating the morphed function: " | ||
| if low_extrap_x > 0: | ||
| wmsg += f"extrapolating length in the lowe r {low_extrap_x} " | ||
|
Collaborator
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. Typo?
Contributor
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. @Sparks29032 is the implement ok, typo aside? Then @ycexiao can write a test.
Collaborator
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'd prefer the grid values above/below which extrapolation occur be reported rather than the extrapolation length since the former quantity if probably more useful (made a comment above about this). |
||
| if high_extrap_x > 0: | ||
| wmsg += f"extrapolating length in the high r {high_extrap_x} " | ||
| warnings.warn( | ||
| wmsg, | ||
| UserWarning, | ||
| ) | ||
| return self.xyallout | ||
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.