xrspatial.aspect.aspect

xrspatial.aspect.aspect(agg: xarray.core.dataarray.DataArray, name: Optional[str] = 'aspect')xarray.core.dataarray.DataArray[source]

Calculates, for all cells in the array, the downward slope direction of each cell based on the elevation of its neighbors in a 3x3 grid. The value is measured clockwise in degrees with 0 and 360 at due north. Flat areas are given a value of -1. Values along the edges are not calculated.

agg: xarray.DataArray

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

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

Name of ouput DataArray.

xarray.DataArray

2D array, of the same type as the input, of calculated aspect values. All other input attributes are preserved.

Algorithm References: - esri, How Aspect Works, http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/how-aspect-works.htm#ESRI_SECTION1_4198691F8852475A9F4BC71246579FAA, Accessed Apr. 21, 2021. # noqa - Burrough, P. A., McDonnell, R., McDonnell, R. A., & Lloyd, C. D. (2015). Principles of geographical information systems. Oxford university press. pp 406. # noqa

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

Create Elevation 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

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

[nan, 0., 18.43494882, nan], [nan, 270., 341.56505118, nan], [nan, 288.43494882, 315., 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

Terrain Example: - makepath, User Guide, https://makepath.github.io/xarray-spatial/assets/examples/user-guide.html, Accessed Apr. 21, 2021 # noqa