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

Better resample #265

Merged
merged 11 commits into from
Oct 9, 2023
Merged

Better resample #265

merged 11 commits into from
Oct 9, 2023

Conversation

aulemahal
Copy link
Collaborator

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
  • (If applicable) Documentation has been added / updated (for bug fixes / features).
  • (If applicable) Tests have been added.
  • This PR does not seem to break the templates.
  • HISTORY.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?

  • Extends resample to explicitly cover the case where the initial_frequency is coarser than "W", meaning that it has a non-uniform length.

    • Weights are the proportion of days of the total period contributed by each timesteps. Ex: MS to YS => weight = daysinmonth / 365 .
    • "weighted resample" is activated for methods : "wind_direction", "mean", "std", "var" and "median". Those are the methods from DataArray.resample for which a weighted version makes sense.
    • Implemented a generic version that uses resample(...).map(....weighted().op()) , with a special case for "median" since that's not a weighted op. Mapping a function is less performant, especially since flox can't be used.
    • Implemented a shortcut for method='mean' that simplifies to a simple resample().sum(), meaning it should be much more performant and able to use flox. Without dask and on the air dataset, I had a 3x speedup.
  • Extends resample to handle missing values with new missing arg:

    • mask : Mask incomplete periods (as in missing timesteps)
    • drop: Drop incomplete periods (same)
    • dict with method=<xclim missing method> : Mask periods failing specified xclim missing check.

Does this PR introduce a breaking change?

No.

Other information:

@aulemahal aulemahal requested review from mccrayc and RondeauG October 2, 2023 21:25
@github-actions github-actions bot added the docs label Oct 2, 2023
Copy link
Collaborator

@RondeauG RondeauG left a comment

Choose a reason for hiding this comment

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

LGTM!

xscen/extract.py Show resolved Hide resolved
xscen/extract.py Outdated Show resolved Hide resolved
xscen/extract.py Outdated Show resolved Hide resolved
@aulemahal aulemahal merged commit 66fc7af into main Oct 9, 2023
6 checks passed
@aulemahal aulemahal deleted the resample-from-ms branch October 9, 2023 14:37
Copy link
Collaborator

@mccrayc mccrayc left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Period-length ponderation in means Resample to seasons - exclude seasons with missing months
3 participants