Skip to content

Use ground distance for sky_view_factor horizon angle (#1407)#1410

Merged
brendancol merged 2 commits into
mainfrom
issue-1407
May 2, 2026
Merged

Use ground distance for sky_view_factor horizon angle (#1407)#1410
brendancol merged 2 commits into
mainfrom
issue-1407

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • The CPU and GPU SVF kernels computed the horizon angle as atan2(dz, r) with r in cells, which silently assumes cell size 1. For any DEM whose cell size differs from the elevation unit (a 30 m DEM in meters, a sub-meter aerial DEM, etc.) the angle was wrong by a factor of cell size.
  • Pass cellsize_x and cellsize_y into both kernels and compute the true ground distance per ray step: sqrt((sx - x) * csx)^2 + ((sy - y) * csy)^2).
  • Read cell size from agg.attrs['res'] or coordinate spacing via get_dataarray_resolution. Add optional cellsize_x / cellsize_y overrides on the public API.

Fixes #1407.

Test plan

  • Existing 30 tests still pass
  • New test_cellsize_changes_horizon_angle confirms halving the cell size lowers SVF on a uniform ramp
  • New test_cellsize_explicit_override confirms explicit kwargs override attrs['res']
  • New test_anisotropic_cellsize covers cellsize_x != cellsize_y
  • New test_flat_surface_unaffected_by_cellsize confirms flat terrain still gives SVF=1 across cell sizes

brendancol added 2 commits May 1, 2026 17:41
The CPU and GPU kernels computed the horizon angle as
atan2(dz, r) where r was the integer ray-step index, treating cell
size as 1. For any DEM whose cell size differs from the elevation
unit (e.g. a 30 m DEM in meters), the angle was wrong by a factor
of cell_size, collapsing SVF toward 0 on coarse grids and inflating
it on fine grids.

The kernels now take cellsize_x and cellsize_y and use the true
ground distance sqrt((dx*csx)^2 + (dy*csy)^2). The public API reads
cell size from agg.attrs['res'] or the coordinate spacing via
get_dataarray_resolution, with optional cellsize_x / cellsize_y
overrides.

Tests cover non-unit cell size, anisotropic cell sizes, explicit
overrides, and confirm flat terrain still gives SVF=1 across cell
sizes.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 2, 2026
@brendancol brendancol merged commit 2ea3291 into main May 2, 2026
11 checks passed
@brendancol brendancol deleted the issue-1407 branch May 4, 2026 13:04
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.

sky_view_factor: horizon angle ignores cell size, wrong by factor of cell_size

1 participant