-
Notifications
You must be signed in to change notification settings - Fork 6
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 weekly_to_daily functionality, move time handling functions to their own module #483
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #483 +/- ##
==========================================
+ Coverage 96.61% 96.67% +0.05%
==========================================
Files 41 42 +1
Lines 976 993 +17
==========================================
+ Hits 943 960 +17
Misses 33 33
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Thank you for your contribution @damonbayer 🚀! Your github-pages is ready for download 👉 here 👈! |
Why isn't the |
For |
The implementation looks okay to me. |
weekly |
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 @dylanhmorris for clarification, LGTM!
pyrenew/time.py
Outdated
if len(daily_values) < 7: | ||
raise ValueError("No complete weekly values available") | ||
|
||
weekly_values = jnp.convolve(daily_values, jnp.ones(7), mode="valid")[::7] |
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.
weekly_values = jnp.convolve(daily_values, jnp.ones(7), mode="valid")[::7] | |
trimmed = daily_values[:len(daily_values) // 7 * 7] | |
weekly_values = trimmed.reshape(-1, 7).sum(axis=1) |
Seems to be about 5x faster
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.
Nice, thanks! As written this function only accepts 1D inputs and will error with a greater than 1D input (because jnp.convolve
does). The new version also assumes 1D but doesn't verify. We can verify 1D input but even better would be to generalize.
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.
weekly_values = jnp.convolve(daily_values, jnp.ones(7), mode="valid")[::7] | |
n_weeks = daily_values.shape[0] // 7 | |
trimmed = daily_values[:n_weeks * 7] | |
weekly_values = trimmed.reshape(n_weeks, 7, *daily_values.shape[1:]).sum(axis=1) |
This works, assuming the 0th dimension is "time." It retains the speed benefit, as before.
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! Would you be up for contributing an edit to the tests to check the multi-dim (1st dim time) 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.
@dylanhmorris I pushed a test directly to this branch 7a85518
(#483)
Co-authored-by: Damon Bayer <[email protected]>
Summary
Breaking changes
This will introduce two breaking changes:
-
from pyrenew.convolve import daily_to_weekly
will need to becomefrom pyrenew.time import daily_to_weekly
.daily_to_weekly
now defaultsinput_data_first_dow
to the specifiedweek_start_dow
rather than to0
(Monday) ifinput_data_first_dow
is not specified. I think this is less surprising. The alternative would be to force the user always to specifyinput_data_first_dow
.We could go through a deprecation cycle but I think Pyrenew is a bit young for that. @damonbayer / @sbidari lmk if you disagree.