-
Notifications
You must be signed in to change notification settings - Fork 17
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
Adding roll function for patches #382
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #382 +/- ##
=======================================
Coverage 99.54% 99.54%
=======================================
Files 97 97
Lines 7633 7647 +14
=======================================
+ Hits 7598 7612 +14
Misses 35 35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
Looks great!
|
||
roll_arr = np.roll(arr, value, axis=axis) | ||
|
||
return patch.new(data=roll_arr) |
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 need to update the coord as well? Or maybe just adding an optional update_coord argument so when is set True, the function will roll the coord as well?
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 need to update the coord as well? Or maybe just adding an optional update_coord argument so when is set True, the function will roll the coord as well
Ya, good point. Normally Patch.roll
would be used to create a new patch that will broadcast with the old one. For example, in cross correlation. In this case you wouldn't want to coords to update, you are purposefully "rolling" the data around stationary coordinates. However, I could also see a case where you might want to roll the coords as well, so an optional argument to do so makes sense.
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.
@Nik-P2, do you think you can implement this?
You need to add an optional keyword called update_coord
or roll_coord
which is False
by default. Then if it is True
do something like this (haven't tested but this should be enough to get you started):
...
if roll_coord: # Handle rolling coordinate if needed
coord = patch.get_coord(dim)
rolled_coord_array = np.roll(coord.values, value, axis)
new_coord = coord.update(values=rolled_coord_array)
patch = patch.update_coords(**{dim: new_coord})
return patch.new(data=roll_arr)
Make sure to write another test case that runs this logic.
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.
Yup, I will work on that now.
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.
Looks great. Thanks, @Nik-P2 !
Hey @Nik-P2, np.roll(coord.values, value, axis=axis) with this one: np.roll(coord.values, value, axis=0) and see if it works. |
All green, feel free to press the squash and merge button. |
Description
Adding in roll function for patches
based on numpy roll function
an example of this function
Checklist
I have (if applicable):