Skip to content

Cover GriddedRegion on a 3D grid, the path #24's tests missed - #30

Draft
hdrake wants to merge 1 commit into
topology-overhaulfrom
test-griddedregion-3d-grid
Draft

Cover GriddedRegion on a 3D grid, the path #24's tests missed#30
hdrake wants to merge 1 commit into
topology-overhaulfrom
test-griddedregion-3d-grid

Conversation

@hdrake

@hdrake hdrake commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Adds the one case test_dimensionality.py was missing. Blocked on MOM6-community/sectionate#52 — it will fail CI until that fix lands. Draft until then.

Why

This file was written for #24: regionate.boundaries._pad_center iterated every axis of the grid while padding a field carrying only the horizontal tracer dims, so a 2-D mask on a 3-D grid raised

KeyError: "None of the DataArray's dims ('yh', 'xh') were found in axis coords."

That was fixed here, with the two tests in this file. Both go through connected_components and MaskRegions, which stay inside regionate.boundaries. Neither builds a GriddedRegion — and that is the path that calls sectionate.grid_section, and so sectionate.gridutils.build_neighbor_maps.

build_neighbor_maps had the identical bug: padding_width = {ax: (1, 1) for ax in grid.axes} on a horizontal-only index array, at three sites. So the same defect existed in both libraries, was diagnosed and fixed in this one, and survived untouched in the sibling — because the regression test stopped one function short of the boundary between them. I confirmed the existing two tests pass unchanged against stock sectionate 0.4.0rc1.

Coverage counts, for context: across regionate's tests and examples there are 15 xgcm.Grid constructions and this file holds the only one that registers a Z axis; across sectionate's 33, none do.

The test

test_gridded_region_ignores_unused_z_axis builds a GriddedRegion from the same lons/lats on initialize_spherical_grid() and on its _add_z_axis(...) counterpart, and requires identical i_c, j_c, lons_c, lats_c and mask — the same "an unused vertical axis changes nothing about horizontal topology" contract the existing tests assert, extended to the entry point that crosses into sectionate.

Status

stock sectionate 0.4.0rc1 with the sectionate#52 fix
existing 2 tests in this file pass pass
new test_gridded_region_ignores_unused_z_axis fails (KeyError) passes
full regionate suite 49 passed, 10 skipped

The 10 skips are the opt-in real-data tests (REGIONATE_REALDATA_TESTS=1), unrelated to this change.

CI installs sectionate from hdrake/sectionate@topology-driven-neighbors, which does not yet carry the fix — it is on fix-horizontal-only-padding (hdrake/sectionate#8). This should merge only after that one, which is why it is a draft. It is deliberately a cross-library contract test: its job is to fail if sectionate ever regresses this, which is precisely what nothing caught the first time.

Drafted with AI assistance (Claude Code). I have read the diff and ran the tests myself.

`test_dimensionality.py` was written for #24 -- `_pad_center` iterating every
grid axis while padding a horizontal-only field -- and covers
`connected_components` and `MaskRegions`. Both stay inside
`regionate.boundaries`, so neither reaches `GriddedRegion`, which traces its
boundary with `sectionate.grid_section`.

That is the gap that let the *same* bug survive in sectionate:
`sectionate.gridutils` requested a halo on every registered axis in exactly
the way `_pad_center` used to, so a 3D grid raised the same KeyError from
`grid_section` (MOM6-community/sectionate#52). One bug between two
libraries, fixed in only one of them.

Add the missing case: build a GriddedRegion from lons/lats on both the 2D
grid and its 3D counterpart and require identical indices, coordinates and
mask.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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