Skip to content

fix(index_search): guard out-of-bounds cell indices in curvilinear_point_in_cell - #3067

Open
boomesh11 wants to merge 1 commit into
Parcels-code:mainfrom
boomesh11:fix/curvilinear-boundary-index-bounds
Open

boomesh11 wants to merge 1 commit into
Parcels-code:mainfrom
boomesh11:fix/curvilinear-boundary-index-bounds

Conversation

@boomesh11

Copy link
Copy Markdown

Fixes #3062.

Problem

In curvilinear_point_in_cell() (src/parcels/_core/index_search.py), grid.lon and grid.lat are indexed at (yi, xi), (yi, xi + 1), (yi + 1, xi + 1), and (yi + 1, xi). When an initial guess yi or xi falls on the last grid node (
y - 1 or
x - 1, such as on a symmetric MOM6 boundary) or is negative (e.g. GRID_SEARCH_ERROR on some particles while
p.any(xi) is True for others), indexing yi + 1 or xi + 1 raises IndexError instead of falling back to the spatial hash query.

Fix

  • In curvilinear_point_in_cell(), validate <= yi < ny - 1 and <= xi < nx - 1 before indexing the 2x2 cell corners.
  • Mark out-of-bounds indices as is_in_cell = 0 (coords = -1.0) so _search_indices_curvilinear_2d() falls back to grid.get_spatial_hash().query(...) cleanly.

Verification

  • Added est_curvilinear_point_in_cell_ignores_out_of_bounds_indices in ests/test_index_search.py.
  • Ran pytest tests/test_index_search.py tests/test_xgrid.py: 53 passed.

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

Status: Backlog

Development

Successfully merging this pull request may close these issues.

MOM6 symmetric grid causes interpolation issues

1 participant