Repository navigation
Make domain_stats use spatial_average and handle 0-360 longitudes - #495
Merged
brianpm-ucar merged 2 commits intoOct 3, 2026
Merged
Conversation
domain_stats picked its region with sel(lon=slice(west, east)), so the polar plots' [-180, 180, 45, 90] kept only longitudes 0 to 180 of the usual 0 to 360 data, and the header mean, max and min described half the cap. It also failed on latitude that runs north to south. Pick the region with masks on longitude modulo 360 and on latitude, and take the mean with spatial_average instead of a second copy of the cos(lat) weights. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The class-level numpy call ran at import time, and CI installs only PyYAML and pytest, so collection failed instead of skipping. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Closes #262.
domain_statsnow takes its mean withspatial_averageinstead of its own copy of thecos(lat)weights, as the issue asked.While doing that I found a bug in the same function.
make_polar_plotcalls it with[-180, 180, 45, 90], but the regridded data has longitude 0 to 360, and the oldsel(lon=slice(-180, 180))kept only longitudes 0 to 180. The Mean, Max and Min in the polar-map header therefore described half of the cap. The old code also returned an empty selection for latitude that runs north to south.Change
lon % 360and on latitude, so the longitude convention of the data and of the domain no longer has to match. If west is greater than east the box wraps through 0/360, and a span of 360 degrees or more is the whole circle.spatial_average(region). Min and max are as before.lib/test/unit_tests/test_domain_stats.py: same answer for 0-360 and -180-180 data, descending latitude, a box across 0/360, box edges on 0, 180 and 360, NaN points left out, and the global box equal tospatial_average. Each expected value is a separate numpy calculation. Against the old function, 5 of the 6 tests fail.Effect on real output (PS climatology from the t1 model-vs-model run, longitude 0 to 358.75; mean, max, min in hPa):
For data already on -180 to 180 with ascending latitude, old and new give identical values.
Checking
pytest lib/test/unit_tests: 269 passed.black --check lib/is clean.Not checked
make_polar_plot, passes 2-D seasonal fields.blackversion pinned for CI (I used the p12 environment's).Not changed here:
make_polar_plotstill fills the percent-difference panel with 0 before its statistics, and still selects latitude withsel(slice)for the plot itself.Claude-assisted: written with Claude Code.
🤖 Generated with Claude Code