xrspatial.hillshade.hillshade

xrspatial.hillshade.hillshade(agg: xarray.core.dataarray.DataArray, azimuth: int = 225, angle_altitude: int = 25, name: Optional[str] = 'hillshade')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.

agg: xarray.DataArray

2D array of elevation values: NumPy, CuPy, NumPy-backed Dask, or Cupy-backed Dask array.

altitude: int (default: 30)

Altitude angle of the sun specified in degrees.

azimuth: int (default: 315)

The angle between the north vector and the perpendicular projection of the light source down onto the horizon specified in degrees.

name: str, optional (default = “hillshade”)

Name of output DataArray.

data: xarray.DataArray

2D array, of the same type as the input of calculated illumination

values.

Algorithm References: - GeoExamples, Shaded relief images using GDAL python, http://geoexamples.blogspot.com/2014/03/shaded-relief-images-using-gdal-python.html, Accessed Apr. 21, 2021. # noqa

Imports >>> import numpy as np >>> import xarray as xr >>> import xrspatial

Create Initial DataArray >>> agg = xr.DataArray(np.array([[0, 1, 0, 0], >>> [1, 1, 0, 0], >>> [0, 1, 2, 2], >>> [1, 0, 2, 0], >>> [0, 2, 2, 2]]), >>> dims = [“lat”, “lon”]) >>> height, width = agg.shape >>> _lon = np.linspace(0, width - 1, width) >>> _lat = np.linspace(0, height - 1, height) >>> agg[“lon”] = _lon >>> agg[“lat”] = _lat >>> print(agg) <xarray.DataArray (lat: 5, lon: 4)> array([[0, 1, 0, 0],

[1, 1, 0, 0], [0, 1, 2, 2], [1, 0, 2, 0], [0, 2, 2, 2]])

Coordinates:
  • lon (lon) float64 0.0 1.0 2.0 3.0

  • lat (lat) float64 0.0 1.0 2.0 3.0 4.0

Create Hillshade DataArray >>> hillshade = xrspatial.hillshade(agg) >>> print(hillshade) <xarray.DataArray ‘hillshade’ (lat: 5, lon: 4)> array([[ nan, nan, nan, nan],

[ nan, 0.54570079, 0.32044456, nan], [ nan, 0.96130094, 0.53406336, nan], [ nan, 0.67253318, 0.71130913, nan], [ nan, nan, nan, nan]])

Coordinates:
  • lon (lon) float64 0.0 1.0 2.0 3.0

  • lat (lat) float64 0.0 1.0 2.0 3.0 4.0