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

Add a rolling_statistics #1480

Closed
2 tasks done
RondeauG opened this issue Sep 19, 2023 · 2 comments · Fixed by #1643
Closed
2 tasks done

Add a rolling_statistics #1480

RondeauG opened this issue Sep 19, 2023 · 2 comments · Fixed by #1643
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@RondeauG
Copy link
Contributor

Addressing a Problem?

We already have statistics and thresholded_statistics, but a rolling_statistics would be very useful for anything related to hydrology and probably other domains too.

Use cases include for example computing the maximum 14-day mean flow (q14max), or the minimum 7-day mean flow (q7min).

Potential Solution

Possible code to be used:

def roll_stats(da: xr.DataArray, window: int, window_reducer: str, reducer: str, freq: str, **indexer) -> xr.DataArray:
    """Calculate a stat on a rolling stat."""
    rolled = getattr(da.rolling(time=window, center=True), window_reducer)()
    rolled_indexed = select_time(rolled, **indexer)
    out = getattr(rolled_indexed.resample(time=freq), reducer)()
    out.attrs["units"] = da.attrs["units"]  # on peut faire mieux
    return out

Additional context

No response

Contribution

  • I would be willing/able to open a Pull Request to contribute this feature.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@RondeauG RondeauG added the enhancement New feature or request label Sep 19, 2023
@Zeitsperre Zeitsperre self-assigned this Oct 10, 2023
@Zeitsperre
Copy link
Collaborator

@RondeauG Still willing to contribute this?

@RondeauG
Copy link
Contributor Author

Sorry I kinda abandoned this! Yes, I can contribute.

@RondeauG RondeauG mentioned this issue Feb 13, 2024
5 tasks
@Zeitsperre Zeitsperre added this to the v0.48.0 milestone Feb 14, 2024
RondeauG added a commit that referenced this issue Feb 19, 2024
<!--Please ensure the PR fulfills the following requirements! -->
<!-- If this is your first PR, make sure to add your details to the
AUTHORS.rst! -->
### Pull Request Checklist:
- [x] This PR addresses an already opened issue (for bug fixes /
features)
    - This PR fixes #1480
- [x] Tests for the changes have been added (for bug fixes / features)
- [x] (If applicable) Documentation has been added / updated (for bug
fixes / features)
- [x] CHANGES.rst has been updated (with summary of main changes)
- [x] Link to issue (:issue:`number`) and pull request (:pull:`number`)
has been added

### What kind of change does this PR introduce?

* Adds `xclim.indices.select_rolling_resample_op` that acts in a way
similar to `select_resample_op`, but with a rolling window beforehand.

### Does this PR introduce a breaking change?


### Other information:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants