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

Fix mda8 misalignment #1322

Merged
merged 6 commits into from
Sep 11, 2024
Merged

Fix mda8 misalignment #1322

merged 6 commits into from
Sep 11, 2024

Conversation

thorbjoernl
Copy link
Collaborator

@thorbjoernl thorbjoernl commented Aug 22, 2024

Change Summary

Per discusion with @avaldebe, there is an issue where the mda8 calculation relies on undocumented xarray behaviour. This PR aims to make arguments explicit where possible as well as testing for the undocumented behaviour in xarray so that possible future regressions can be detected. This also fixes an issue where 8 hour average was left labeled instead of rightlabeled, resulting in the mda8 binning to be shifted by 8 hours from the defined window.

Related issue number

closes #1323

Checklist

  • Start with a draft-PR
  • The PR title is a good summary of the changes
  • PR is set to AeroTools and a tentative milestone
  • Documentation reflects the changes where applicable
  • Tests for the changes exist where applicable
  • Tests pass locally
  • Tests pass on CI
  • At least 1 reviewer is selected
  • Make PR ready to review

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.96%. Comparing base (9e48af9) to head (ce69c9c).
Report is 32 commits behind head on main-dev.

Additional details and impacted files
@@             Coverage Diff              @@
##           main-dev    #1322      +/-   ##
============================================
- Coverage     78.97%   78.96%   -0.01%     
============================================
  Files           136      136              
  Lines         20812    20813       +1     
============================================
  Hits          16436    16436              
- Misses         4376     4377       +1     
Flag Coverage Δ
unittests 78.96% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thorbjoernl thorbjoernl added this to the m2024-09 milestone Aug 23, 2024
@thorbjoernl thorbjoernl added the bug 🐛 Something isn't working label Aug 23, 2024
@thorbjoernl thorbjoernl marked this pull request as ready for review August 23, 2024 07:43
@thorbjoernl thorbjoernl changed the title Set defaults explicitly and test for undocumented xarray behaviour Fix mda8 misalignment Aug 23, 2024
Copy link
Collaborator

@avaldebe avaldebe left a comment

Choose a reason for hiding this comment

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

I'm not sure about the number of valid 8-hour means are correct for the first MDA8

new_arr = arr.rolling(time=8, min_periods=6).mean()
# Xarray labels the data left, while we want it to be labeled right, so we add 8h to
# the time index.
new_arr["time"] = new_arr.get_index("time") + pd.Timedelta("8h")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is the new_arr.get_index("time") needed?
Can it be written as

    new_arr["time"] += pd.Timedelta("8h")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

+= Doesn't work.

This is the documented way of doing time offset arithmetic: https://github.com/pydata/xarray/pull/8479/files

tests/stats/mda8/test_mda8.py Outdated Show resolved Hide resolved
tests/stats/mda8/test_mda8.py Outdated Show resolved Hide resolved
tests/stats/mda8/test_mda8.py Outdated Show resolved Hide resolved
@heikoklein heikoklein dismissed avaldebe’s stale review September 11, 2024 06:57

Alvaro is on leave, and his change requests have been addressed.

@heikoklein heikoklein merged commit 8ed621a into main-dev Sep 11, 2024
8 checks passed
@heikoklein heikoklein deleted the fix-mda8 branch September 11, 2024 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MDA daily binning misaligned due to mislabeled data in 8hour mean calculation
3 participants