Skip to content

Fix interpolate_to_isosurface failing on xarray DataArray inputs - #4230

Open
1915rising wants to merge 1 commit into
Unidata:mainfrom
1915rising:fix/4228-isosurface-xarray
Open

1915rising wants to merge 1 commit into
Unidata:mainfrom
1915rising:fix/4228-isosurface-xarray

Conversation

@1915rising

Copy link
Copy Markdown

Fixes #4228.

interpolate_to_isosurface fails when level_var and interp_var are xarray DataArrays, as in the report's GFS example:

IndexError: Unlabeled multi-dimensional array cannot be used for indexing: isobaric

The function finds bounding indices with find_bounding_indices, which returns index arrays meant for direct NumPy-style indexing, and then applies them to the original inputs (level_var[above], etc.). That works for arrays and Quantities but not for a DataArray, whose __getitem__ rejects unlabeled multi-dimensional indexers. The reporter's workaround of passing .metpy.unit_array instead works, which points at the same cause.

Fix: decorate interpolate_to_isosurface with @preprocess_and_wrap(), the same wrapper find_bounding_indices and the interpolate_1d family already use, so DataArray inputs are downcast to Quantities before the indexing happens. Array and Quantity inputs are unchanged.

Reproduction: a synthetic version of the report (height and wind on an isobaric/latitude/longitude grid, wind linear in height) raises the exact IndexError above on current main; after the fix it returns the expected 6.0 m/s at the 6000 gpm surface, matching the .metpy.unit_array workaround.

Tests: new regression test test_interpolate_to_isosurface_xarray in tests/interpolate/test_grid.py (fails with the IndexError before, passes after). tests/interpolate/test_grid.py: 38 passed before, 39 passed after. Full tests/interpolate/: 107 passed, 3 skipped after.

@1915rising
1915rising requested a review from a team as a code owner November 26, 2026 23:24
@1915rising
1915rising requested review from dcamron and removed request for a team November 26, 2026 23:24

This branch has not been deployed

No deployments
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.

Interpolation to constant height coordinates fails

1 participant