Skip to content

fix: reject incomplete NTv2 bicubic stencils at subgrid edges - #172

Open
timothyanderson096-ocdealcheck wants to merge 1 commit into
GeoscienceAustralia:masterfrom
timothyanderson096-ocdealcheck:fix/ntv2-bicubic-boundaries
Open

timothyanderson096-ocdealcheck wants to merge 1 commit into
GeoscienceAustralia:masterfrom
timothyanderson096-ocdealcheck:fix/ntv2-bicubic-boundaries

Conversation

@timothyanderson096-ocdealcheck

Copy link
Copy Markdown

Problem

Bicubic NTv2 interpolation assumes a complete 4x4 neighbourhood without checking that it stays inside the selected subgrid. Near the edges, this can wrap into another row, interpret header or neighbouring-subgrid bytes as nodes, or read beyond EOF. Issue #170 reports incorrect coordinate shifts and binary read failures.

Change

Validate row and column bounds in SubGrid.ntv2_bicubic before any file access. Incomplete stencils now raise an actionable ValueError directing callers to method='bilinear'. The requested interpolation method is not silently changed. Interior bicubic calculations, subgrid selection and existing north/west extent exclusions are preserved.

Document the boundary behaviour in the interpolation and transformation APIs and the NTv2 guide.

Validation

  • Existing baseline: 74 unittest tests passed.
  • Seven new regression tests use generated NTv2 binary fixtures: edge bands and corners in first/last subgrids, small grids, direct-method file access, nonlinear interior interpolation, extent semantics and the ntv2_2d wrapper.
  • Before the fix, the new suite produced 19 failing and 8 erroring subtests.
  • After the fix: all 81 unittest tests passed.
  • Black applied to the new tests and changed Python regions; git diff --check passed.

Validation used synthetic grids. The reporter's real-grid examples and deployed government services were not tested. This fixes invalid stencil reads; it does not implement one-sided bicubic interpolation at boundaries.

Fixes #170

Prepared by Tim Anderson, Spotted Ridge Engineering / OC Labs, Australia, with OpenAI Codex assistance.

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.

NTv2 bicubic method could benefit from better error catching in 'edge' cases.

1 participant