xrspatial.hillshade.hillshade#
- xrspatial.hillshade.hillshade(agg: xarray.core.dataarray.DataArray, azimuth: int = 225, angle_altitude: int = 25, name: Optional[str] = 'hillshade', shadows: bool = False) xarray.core.dataarray.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) – 2D NumPy, CuPy, NumPy-backed Dask, or Cupy-backed Dask array of elevation values.
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.
- Returns
hillshade_agg – 2D aggregate array of illumination values.
- Return type
xarray.DataArray, of same type as agg
References
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) >>> print(hillshade_agg) <xarray.DataArray 'hillshade' (y: 5, x: 5)> array([[ nan, nan, nan, nan, nan], [ nan, 0.71130913, 0.44167341, 0.71130913, nan], [ nan, 0.95550163, 0.71130913, 0.52478473, nan], [ nan, 0.71130913, 0.88382559, 0.71130913, nan], [ nan, nan, nan, nan, nan]]) Coordinates: * y (y) int32 4 3 2 1 0 * x (x) int32 0 1 2 3 4