Skip to content

Validate cellsize in curvature() (#1270)#1272

Open
brendancol wants to merge 1 commit intomainfrom
issue-1270
Open

Validate cellsize in curvature() (#1270)#1272
brendancol wants to merge 1 commit intomainfrom
issue-1270

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

Fixes #1270.

curvature() divided by cellsize * cellsize in every backend kernel with no zero guard. A raster whose res attribute was (0, 0) (or had one zero component) produced inf for every interior pixel instead of a clean error.

This validates cellsize_x and cellsize_y from get_dataarray_resolution(agg) in the public curvature() API before backend dispatch and raises ValueError when either component is zero or non-finite. Inner numba/cupy kernels are unchanged. All four backends (numpy, cupy, dask+numpy, dask+cupy) inherit the check.

Cat 3 (NaN/Inf as logic error) MEDIUM-severity finding from the recent security sweep.

Changes

  • xrspatial/curvature.py: validate cellsize in curvature() before dispatch, raise ValueError when either component is zero or non-finite.
  • xrspatial/tests/test_curvature.py: parametrized test covering res=(0, 0), (0, 1), (1, 0), (inf, 1), (1, nan).
  • .claude/sweep-security-state.json: record the curvature inspection.

Test plan

  • pytest xrspatial/tests/test_curvature.py -x (80 passed, 5 new)
  • Existing curvature tests still pass
  • New test confirms ValueError is raised instead of returning inf

curvature() divided by (cellsize * cellsize) in every backend kernel
without a zero guard, so a raster with attrs={'res': (0, 0)} returned
inf for every interior pixel instead of raising. Validate cellsize_x
and cellsize_y in the public API before backend dispatch and raise
ValueError when either is zero or non-finite. All four backends
(numpy, cupy, dask+numpy, dask+cupy) inherit the check.

Inner numba/cupy kernels are unchanged.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Apr 25, 2026
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.

curvature() returns inf when res=(0, 0) instead of raising ValueError

1 participant