Skip to content

Fix transport and regrid for non-lat/lon grids (e.g. stereographic) - #21

Merged
NoraLoose merged 4 commits into
mainfrom
fix-transport
Aug 27, 2026
Merged

NoraLoose merged 4 commits into
mainfrom
fix-transport

Conversation

@NoraLoose

@NoraLoose NoraLoose commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator

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() with method="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_horizontal only 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 a UserWarning. Also skips the 1-D subsetting step in _subset_target for 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

  • New stereographic subset script and test NetCDF (tp5_stereo_subset.nc)
  • test_regrid.py: round-trip regrid tests for 1-D and 2-D target grids

Checklist

  • Tests added/updated for new functionality
  • Documentation updated if needed
  • Added an entry to docs/releases.md under [Unreleased]

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
NoraLoose marked this pull request as draft August 14, 2026 14:10
@codecov

codecov Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.46%. Comparing base (806803d) to head (4b9ffa2).
⚠️ Report is 11 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@NoraLoose NoraLoose changed the title Fix T-point transport selection for non-lat/lon 1-D coordinates Fix transport and regrid for non-lat/lon grids (e.g. stereographic/TOPAZ) Aug 27, 2026
@NoraLoose NoraLoose changed the title Fix transport and regrid for non-lat/lon grids (e.g. stereographic/TOPAZ) Fix transport and regrid for non-lat/lon grids (e.g. stereographic) Aug 27, 2026
@NoraLoose
NoraLoose marked this pull request as ready for review August 27, 2026 07:02
@NoraLoose
NoraLoose merged commit 27a3e1c into main Aug 27, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant