Repository navigation
Fix interpolate_to_isosurface failing on xarray DataArray inputs - #4230
Open
1915rising wants to merge 1 commit into
Open
1915rising wants to merge 1 commit into
1915rising wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Fixes #4228.
interpolate_to_isosurfacefails whenlevel_varandinterp_varare xarray DataArrays, as in the report's GFS example: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_arrayinstead works, which points at the same cause.Fix: decorate
interpolate_to_isosurfacewith@preprocess_and_wrap(), the same wrapperfind_bounding_indicesand theinterpolate_1dfamily 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/longitudegrid, 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_arrayworkaround.Tests: new regression test
test_interpolate_to_isosurface_xarrayin 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.