fix calculation in time derivation#397
Merged
Merged
Conversation
…equirement in pyproject.toml
…394) * fix: normalize CF time units to canonical HH:MM:SS for WCRP ATTR004 * pre-commit format fix
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #397 +/- ##
=======================================
+ Coverage 74.3% 74.5% +0.2%
=======================================
Files 28 28
Lines 5200 5237 +37
Branches 953 961 +8
=======================================
+ Hits 3864 3901 +37
Misses 1113 1113
Partials 223 223
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rbeucher
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
tasmax/tasminmonthlytimecoordinate to month midpointSummary
The CMORised
timecoordinate for the monthly atmosphere variablestasmaxandtasminwas stamped at the end of each month instead of the midpoint ofthe
time_bndscell. CF/CMIP6 require a time-mean coordinate to equal themidpoint of its bounds, and the WCRP checker flagged this as a HIGH-priority
failure
[TIME001] Check Time Squareness(weight = 3). This PR fixes thetasmax/tasminderivation path sotime == midpoint(time_bnds).Root cause
tasmax→calculate_monthly_maximumandtasmin→calculate_monthly_minimum(in
derivations/calc_utils.py) resampled daily data withresample({time: "ME"}). Pandas"ME"(Month-End) labels each monthly bin atthe month-end timestamp.
Downstream,
calculate_time_boundsbuilds the correct[month-start, next-month-start)bounds (it uses only year/month), sotime_bndswas right — but the
timecoordinate sat at month-end, givingtime ≠ midpoint(time_bnds). Variables sourced from already-monthly data (e.g.tas) carry mid-month stamps and were never affected, matching the"only 2 of 86 files fail" observation.
Fix
Added a small helper
_monthly_midpoint_coordand applied it right after each"ME"resample to recentre the time coordinate to the midpoint of its monthlycell. Handles both
datetime64andcftimecalendars.Files changed
src/access_moppy/derivations/calc_utils.pycftime/pandasimports; add_monthly_midpoint_coord; apply after both"ME"resamples; update docstring notestests/unit/test_derivations_calc_utils.pyTestMonthlyTimeCoordinateMidpointregression tests