Skip to content

Resample polish: fix cubic depth comment, tighten NaN threshold, add edge tests#1475

Merged
brendancol merged 4 commits intomainfrom
issue-1471
May 4, 2026
Merged

Resample polish: fix cubic depth comment, tighten NaN threshold, add edge tests#1475
brendancol merged 4 commits intomainfrom
issue-1471

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1471.

Changes

  • Reword the cubic _INTERP_DEPTH comment in xrspatial/resample.py. The previous comment claimed depth 10 brings the prefilter transient to "machine epsilon"; the actual value 0.268^10 is about 4e-7, closer to float32 epsilon. The constant 10 is unchanged because it remains correct for float32 output.
  • Raise the NaN-aware kernel-weight gate from z_wt > 0.01 to z_wt > 0.5 in _nan_aware_interp_np, _nan_aware_interp_cupy, _interp_block_np, and _interp_block_cupy. With the old threshold, an output pixel could pass through the gate when only a small fraction of the resampling kernel weight came from valid input pixels (one cubic sidelobe leaks about 5% from a single neighbour). The new threshold means more than half of the kernel weight must come from valid pixels. A short comment in _nan_aware_interp_np explains the choice; the other three sites point back to it.
  • Add a test for descending y coordinates: an 8x8 grid with row 0 = 100 and row 7 = 0 must resample to a 4x4 grid that still has descending y, with cell-centered y values 9.5, 7.5, 5.5, 3.5 and the high-value row at the top of the output.
  • Add tests that +inf and -inf propagate (not coerced to NaN) for bilinear, average, and nearest.
  • Add a test that the 3D-rejection error message includes "must be 2D".
  • Add a test that resample(...) produces bit-identical output across two consecutive calls for bilinear, cubic, and average.

Behavior change

The NaN threshold bump is the only behavior change. Output pixels in the [0.01, 0.5] kernel-weight band, which previously came back as a fractional value, now come back as NaN. This is a more conservative gate.

Test plan

  • pytest xrspatial/tests/test_resample.py (62 -> 70, all pass)
  • All eight new tests pass on the numpy backend

- Reword cubic _INTERP_DEPTH comment: depth 10 brings the boundary
  transient to ~1e-7, not float64 machine epsilon.
- Raise nan-aware kernel-weight gate from 0.01 to 0.5 in the numpy,
  cupy, and dask block variants. Pixels lit only by cubic-kernel
  sidelobes from a single neighbour now come back as NaN.
- Add tests for descending-y orientation, +/- inf input propagation,
  the 3D-rejection error message, and bit-identical repeat output for
  bilinear / cubic / average.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 4, 2026
@brendancol
Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Copilot AI and others added 3 commits May 4, 2026 20:35
# Conflicts:
#	xrspatial/tests/test_resample.py

Co-authored-by: brendancol <433221+brendancol@users.noreply.github.com>
…e tests into first class

Agent-Logs-Url: https://github.com/xarray-contrib/xarray-spatial/sessions/441b5d81-2d7b-4c7b-bb38-13afa95bbc77

Co-authored-by: brendancol <433221+brendancol@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in e5e4090. The conflict in xrspatial/tests/test_resample.py was between test classes added in this branch (TestCoordinateOrientation, TestInfHandling, TestDimensionRejection, TestReproducibility) and test classes added in main (TestDaskAggregateInlined, TestThreeDRasters, TestNodata, TestTargetResolutionTuple). All tests from both sides are now kept. Two follow-up fixes were also applied: TestDimensionRejection was updated to test 4D rejection (since main added 3D raster support), and a duplicate TestTargetResolutionTuple class was resolved by merging unique tests from both definitions into one class. All 105 tests pass.

@brendancol brendancol merged commit 645c00a into main May 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resample polish: fix cubic depth comment, tighten NaN threshold, add edge tests

2 participants