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

Stack and unstack periods #1558

Merged
merged 14 commits into from
Dec 15, 2023
Merged

Stack and unstack periods #1558

merged 14 commits into from
Dec 15, 2023

Conversation

aulemahal
Copy link
Collaborator

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
    • This PR fixes #xyz
  • Tests for the changes have been added (for bug fixes / features)
    • (If applicable) Documentation has been added / updated (for bug fixes / features)
  • CHANGES.rst has been updated (with summary of main changes)
    • Link to issue (:issue:number) and pull request (:pull:number) has been added

What kind of change does this PR introduce?

New stack_periods and it's reverse unstack_periods.

The basic idea is to have da.rolling(time=window).construct(dim, stride=stride), but with window and stride given as a multiple of a given freq, allowing the use of non-uniform temporal periods (like years or months). And to have a reverse method to go back to the linear timeseries.

We had sdba.construct_moving_yearly_window, this is the generalization of that logic for:

  • other frequencies than 'YS'
  • periods of different lengths (MS, QS)
  • non-uniform calendars
    Of course, the two latter points will generate an output where the "fake" time axis makes no sense at all, so this is to be use with precaution.

Does this PR introduce a breaking change?

Yes.

sdba.construct_moving_yearly_window is transparently sent to stack_periods with a warning.

sdba.unpack_moving_yearly_window also warns and calls unstack_periods but the append_ends argument is not available on the latter. The behaviour is that same as append_ends=True.

@aulemahal aulemahal added this to the v0.48.0 milestone Dec 11, 2023
@aulemahal aulemahal requested a review from coxipi December 11, 2023 21:29
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@github-actions github-actions bot added sdba Issues concerning the sdba submodule. docs Improvements to documenation labels Dec 11, 2023
@coveralls
Copy link

coveralls commented Dec 11, 2023

Coverage Status

coverage: 89.686% (-0.8%) from 90.447%
when pulling 40e1d9f on sdba-better-names
into b905e55 on master.

xclim/core/calendar.py Outdated Show resolved Hide resolved
xclim/core/calendar.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coxipi coxipi left a comment

Choose a reason for hiding this comment

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

Nice job. I think this kind of logic could be useful to replace map_blocks/map_groups operations if it can help some computations. Either to create arrays we directly work on, or to deduce time indices that can be used with the philosophy of groupies.

@github-actions github-actions bot added the approved Approved for additional tests label Dec 12, 2023
@aulemahal aulemahal merged commit 08e4ceb into master Dec 15, 2023
16 checks passed
@aulemahal aulemahal deleted the sdba-better-names branch December 15, 2023 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved for additional tests docs Improvements to documenation sdba Issues concerning the sdba submodule.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants