Skip to content

Add northness and eastness functions (#1039)#1041

Merged
brendancol merged 4 commits intomasterfrom
issue-1039
Mar 20, 2026
Merged

Add northness and eastness functions (#1039)#1041
brendancol merged 4 commits intomasterfrom
issue-1039

Conversation

@brendancol
Copy link
Contributor

Summary

  • Adds northness() and eastness() to xrspatial.aspect, computing cos(aspect) and sin(aspect)
  • Decomposes circular aspect (0-360 degrees) into linear variables that regression and clustering models can use directly
  • Both wrap aspect() internally, so all four backends and both methods (planar, geodesic) work with no new kernel code
  • Flat cells (aspect == -1) become NaN
  • Uses np.where on raw arrays instead of xarray's .where() method, which breaks on CuPy-backed DataArrays

Test plan

  • 28 tests in test_northness_eastness.py, all passing
  • Correctness verified against manual cos(aspect)/sin(aspect) reference
  • Cardinal direction spot checks (north-facing and east-facing slopes)
  • Flat surface produces NaN
  • NaN propagation from input
  • Output range in [-1, +1]
  • Backend parity: NumPy vs Dask+NumPy, CuPy, Dask+CuPy
  • Custom name parameter

Closes #1039

cos(aspect) and sin(aspect) wrappers for encoding aspect as linear
variables suitable for regression and clustering. Flat cells map to NaN.
Covers correctness, cardinal directions, flat-to-NaN, NaN propagation,
range checks, and backend parity (numpy, dask, cupy, dask+cupy).
Also fixes CuPy compat by using np.where on raw data instead of
xarray .where() method.
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 20, 2026
@brendancol brendancol merged commit 40fa429 into master Mar 20, 2026
11 checks 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.

Add northness and eastness functions (cos/sin of aspect)

1 participant