Use ground distance for sky_view_factor horizon angle (#1407)#1410
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
atan2(dz, r)withrin 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.cellsize_xandcellsize_yinto both kernels and compute the true ground distance per ray step:sqrt((sx - x) * csx)^2 + ((sy - y) * csy)^2).agg.attrs['res']or coordinate spacing viaget_dataarray_resolution. Add optionalcellsize_x/cellsize_yoverrides on the public API.Fixes #1407.
Test plan
test_cellsize_changes_horizon_angleconfirms halving the cell size lowers SVF on a uniform ramptest_cellsize_explicit_overrideconfirms explicit kwargs overrideattrs['res']test_anisotropic_cellsizecoverscellsize_x != cellsize_ytest_flat_surface_unaffected_by_cellsizeconfirms flat terrain still gives SVF=1 across cell sizes