xrspatial.hillshade.hillshade#
- xrspatial.hillshade.hillshade(agg: DataArray, azimuth: int = 225, angle_altitude: int = 25, name: str | None = 'hillshade', shadows: bool = False, boundary: str = 'nan') DataArray[source]#
Calculates, for all cells in the array, an illumination value of each cell based on illumination from a specific azimuth and altitude.
- Parameters:
agg (xarray.DataArray or xr.Dataset) – 2D NumPy, CuPy, NumPy-backed Dask, or Cupy-backed Dask array of elevation values. If a Dataset is passed, the operation is applied to each data variable independently.
angle_altitude (int, default=25) – Altitude angle of the sun specified in degrees.
azimuth (int, default=225) – The angle between the north vector and the perpendicular projection of the light source down onto the horizon specified in degrees.
name (str, default='hillshade') – Name of output DataArray.
shadows (bool, default=False) – Whether to calculate shadows or not. Shadows are available only for Cupy-backed Dask arrays and only if rtxpy is installed and appropriate graphics hardware is available.
boundary (str, default='nan') – How to handle edges where the kernel extends beyond the raster.
'nan'— fill missing neighbours with NaN (default).'nearest'— repeat edge values.'reflect'— mirror at boundary.'wrap'— periodic / toroidal.
- Returns:
hillshade_agg – If agg is a DataArray, returns a DataArray of the same type. If agg is a Dataset, returns a Dataset with hillshade computed for each data variable. 2D aggregate array of illumination values.
- Return type:
xarray.DataArray or xr.Dataset
References
GDAL gdaldem hillshade: https://gdal.org/programs/gdaldem.html
GeoExamples: http://geoexamples.blogspot.com/2014/03/shaded-relief-images-using-gdal-python.html # noqa
Examples
>>> import numpy as np >>> import xarray as xr >>> from xrspatial import hillshade >>> data = np.array([ ... [0., 0., 0., 0., 0.], ... [0., 1., 0., 2., 0.], ... [0., 0., 3., 0., 0.], ... [0., 0., 0., 0., 0.], ... [0., 0., 0., 0., 0.]]) >>> n, m = data.shape >>> raster = xr.DataArray(data, dims=['y', 'x'], name='raster') >>> raster['y'] = np.arange(n)[::-1] >>> raster['x'] = np.arange(m) >>> hillshade_agg = hillshade(raster)