Skip to content

Add memory guard to geodesic slope/aspect (#1283)#1285

Merged
brendancol merged 1 commit into
mainfrom
issue-1283
Apr 27, 2026
Merged

Add memory guard to geodesic slope/aspect (#1283)#1285
brendancol merged 1 commit into
mainfrom
issue-1283

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

Closes #1283.

Test plan

  • pytest xrspatial/tests/test_geodesic_slope.py xrspatial/tests/test_geodesic_aspect.py -> 39 passed
  • pytest xrspatial/tests/test_slope.py xrspatial/tests/test_aspect.py -> 105 passed (no regression on the planar paths)
  • New TestGeodesicSlopeMemoryGuard and TestGeodesicAspectMemoryGuard cover: guard fires on oversized raster, normal-size raster passes, planar method skips guard

@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Apr 27, 2026
The geodesic method in slope() and aspect() allocates a (3, H, W) float64
stacked array (data, lat, lon) per call with no memory guard. A large
enough lat/lon-tagged raster passed to slope(method='geodesic') or
aspect(method='geodesic') will OOM the process.

Add _check_geodesic_memory(rows, cols, func_name) in xrspatial/geodesic.py,
modeled on _check_kernel_memory in xrspatial/morphology.py. It raises
MemoryError when the stacked float64 buffer plus the float32 output plus
a padding allowance exceeds 50% of available RAM. slope() and aspect()
call it in the geodesic branch before dispatch.

Tests cover the guard firing on an oversized raster, normal-sized rasters
passing through, and the planar method skipping the guard entirely.

Records the audit + fix in .claude/sweep-security-state.csv.
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.

Memory guard for geodesic slope/aspect

1 participant