xrspatial.sky_view_factor.sky_view_factor#

xrspatial.sky_view_factor.sky_view_factor(agg: DataArray, max_radius: int = 10, n_directions: int = 16, cellsize_x: float | None = None, cellsize_y: float | None = None, name: str | None = 'sky_view_factor') DataArray[source]#

Compute the sky-view factor for each cell of a DEM.

SVF measures the fraction of the sky hemisphere visible from each cell on a scale from 0 (fully obstructed) to 1 (flat open terrain). Rays are cast at n_directions evenly spaced azimuths out to max_radius cells, and the maximum elevation angle along each ray determines the horizon obstruction.

The horizon angle along each ray uses true ground distance (cell_step * cellsize), so cell size must be in the same unit as the elevation values (e.g. meters for both). Ray azimuths are evenly spaced on the ground: with rectangular cells (cellsize_x != cellsize_y) each ray’s cell-index direction is adjusted so the ground azimuth spacing stays uniform. The spacing is nominal to within one cell of rounding, since rays sample whole cells; at extreme aspect ratios (roughly beyond 4:1) the sampled azimuths still quantize toward the grid axes.

Parameters:
  • agg (xarray.DataArray or xr.Dataset) – 2D NumPy, CuPy, NumPy-backed Dask, or CuPy-backed Dask xarray DataArray of elevation values. If a Dataset is passed, the operation is applied to each data variable independently.

  • max_radius (int, default=10) – Maximum search distance in cells along each ray direction.

  • n_directions (int, default=16) – Number of azimuth directions to sample, evenly spaced around 360 degrees.

  • cellsize_x (float, optional) – Ground distance per cell along the x axis, in the same unit as the elevation values. If not provided, it is read from agg.attrs['res'] or computed from the x coordinate.

  • cellsize_y (float, optional) – Ground distance per cell along the y axis, in the same unit as the elevation values. If not provided, it is read from agg.attrs['res'] or computed from the y coordinate.

  • name (str, default='sky_view_factor') – Name of the output DataArray.

Returns:

2D array of SVF values in [0, 1] with the same shape, coords, dims, and attrs as the input. Edge cells use truncated rays that stop at the raster boundary.

Return type:

xarray.DataArray or xr.Dataset

References

Zakek, K., Ostir, K., Kokalj, Z. (2011). Sky-View Factor as a Relief Visualization Technique. Remote Sensing, 3(2), 398-415.

Examples

>>> from xrspatial import sky_view_factor
>>> svf = sky_view_factor(dem, max_radius=100, n_directions=16)