Calculate basic DEM attributes

Contents

Calculate basic DEM attributes#

DEM attributes (or terrain attributes) can be derived from DEMs. Many of these attributes are derivatives that can be calculated for a specific pixel by operations on neighbor pixels such as the rate of change in elevation along a direction. TopoToolbox contains numerous GridObject methods that perform these calculations.

[1]:
import topotoolbox as tt3
import numpy as np
import matplotlib.pyplot as plt

Slope#

A primary DEM attribute is slope which is calculated by the function gradient8. gradient8 determines for each pixel the maximum downstream gradient. This approach is different from the numerical gradient used in other GIS systems but it has the advantage that it reflects the hydrological downstream gradient if the DEM is hydrologically correct.

[2]:
dem = tt3.load_dem('tibet')
g = dem.gradient8()

fig0,ax0 = plt.subplots(1,1)
im0 = ax0.imshow(g,cmap='magma')
plt.colorbar(im0);
../_images/tutorial_grid_3_0.png

Curvature#

Curvature is the second derivative and measures the rate of change of slope. Profile curvature is the rate of slope change in direction of the maximum gradient. Conversely, planform curvature measures the curvature of the contour lines. The function curvature allows calculating both types of curvature in addition to some additionally, less frequently used forms of curvature. Curvature is very sensitive to errors in the DEM. Thus, when plotting, we only plot the data between the 2nd and 98th percentile of the data using Numpy’s quantile function.

[3]:
cplan = dem.curvature(ctype='planc')
cprof = dem.curvature(ctype='profc');
[4]:
fig, (ax1, ax2) = plt.subplots(2,1,layout='constrained')
clims1 = np.quantile(cplan,[0.02,0.98])
im1 = ax1.imshow(cplan,vmin=clims1[0],vmax=clims1[1])
plt.colorbar(im1)

im2 = ax2.imshow(cprof)
clims2 = np.quantile(cprof,[0.02,0.98])
im2 = ax2.imshow(cprof,vmin=clims2[0],vmax=clims2[1])
plt.colorbar(im2);
../_images/tutorial_grid_6_0.png