Fix transport and regrid for non-lat/lon grids (e.g. stereographic) - #21
Merged
Merged
Conversation
The generic T-point path detected any 1-D y coordinate as a latitude axis and selected data via .sel(y=cell_lat, method='nearest'). For grids whose y coordinate is not latitude (e.g. TOPAZ's polar- stereographic y in the range -55..55), cell_lat values (~79°N) were all snapped to the coordinate maximum, selecting the wrong row for every section cell and producing exactly-zero transports. Fix: guard the coordinate-value selection branch with a range check — only use it when the resolved cell latitudes actually fall within the y coordinate range. When they don't, fall back to integer isel() with the resolved j/i indices, which is always correct. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
NoraLoose
marked this pull request as draft
August 14, 2026 14:10
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21 +/- ##
==========================================
+ Coverage 86.32% 86.46% +0.14%
==========================================
Files 11 11
Lines 2120 2157 +37
==========================================
+ Hits 1830 1865 +35
- Misses 290 292 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
NoraLoose
force-pushed
the
fix-transport
branch
from
August 27, 2026 06:59
e06b82d to
4b9ffa2
Compare
NoraLoose
marked this pull request as ready for review
August 27, 2026 07:02
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.
Two related fixes to support ocean model output on projected grids (stereographic, polar, etc.) where coordinates are not standard lat/lon.
Transport (
_transport.py)T-point selection was using coordinate-value
.sel()withmethod="nearest", which breaks on non-geographic y-coordinates like TOPAZ's stereographic y-axis (range ~−55 to 55, not −90 to 90). The fix adds a range check: if the section's lat values don't fall within the y-coordinate's range, fall back to integer.isel()instead. Also refactors the selection into a small_select()helper to avoid repeating the branch at every variable lookup.Regrid (
_regrid.py)regrid_horizontalonly handled 1-D lat/lon target grids. Extended it to accept 2-D (curvilinear) lon/lat arrays (e.g. a stereographic Arctic grid), building the xESMF target dataset with(y, x)dimensions. Conservative remapping is unsupported for curvilinear targets and falls back to bilinear with aUserWarning. Also skips the 1-D subsetting step in_subset_targetfor 2-D grids (ill-defined on curvilinear coordinates), and re-attaches geographic coordinates to the output after regridding since xESMF doesn't carry them through.Tests
tp5_stereo_subset.nc)test_regrid.py: round-trip regrid tests for 1-D and 2-D target gridsChecklist
docs/releases.mdunder[Unreleased]