asp_plot.terrain#

Terrain attributes of a DEM at point locations.

slope_at_points() gives the slope of a DEM at altimetry points, which asp_plot.dem_benchmark.DEMBenchmark and asp_plot.altimetry.Altimetry use to break altimetry-minus-DEM residuals down by slope class.

Attributes#

Functions#

slope_at_points(dem_fn, points[, scale])

Slope of a DEM in degrees at each point, by Horn's method.

slope_bin_edges(bins)

Slope class edges in degrees as a tuple of floats.

slope_bin_labels(edges)

Labels of the slope classes between edges, such as "5–10°".

slope_pixel_size(dem_fn[, scale])

The pixel size slope_at_points() takes slope at, in meters.

slope_source_label(dem_fn[, scale, name])

Axis label naming where slope came from, such as

Module Contents#

asp_plot.terrain.slope_at_points(dem_fn, points, scale=None)#

Slope of a DEM in degrees at each point, by Horn’s method.

Horn’s method is what gdaldem slope uses: the east and north gradients come from the 3 × 3 pixels around the pixel holding the point, with the centre row and column weighted twice. The DEM is not interpolated, so without scale the slope is that of the DEM at its own resolution: a 30 m Copernicus DEM gives the slope of the terrain over about one ATL06-SR segment, a 1 m DSM the slope of roofs and walls.

Parameters:
  • dem_fn (str) – DEM to take slope from. Heights are taken to be in meters; pixel sizes in degrees are converted to meters at each point’s latitude.

  • points (geopandas.GeoDataFrame) – Points, in any CRS (reprojected to the DEM’s).

  • scale (float, optional) – Length scale of the slope in meters. A DEM whose pixels are at most half this size is first averaged over blocks of whole pixels, the most that fit in scale, so a 1 m DSM with scale=30 gives the slope of its 30 m block means. A coarser DEM is used as it is. Default None: the DEM’s own resolution.

Returns:

Slope in degrees, NaN for a point outside the DEM or whose 3 × 3 neighbourhood touches nodata or the DEM edge (as gdaldem without -compute_edges).

Return type:

numpy.ndarray

asp_plot.terrain.slope_bin_edges(bins)#

Slope class edges in degrees as a tuple of floats.

Raises ValueError unless there are at least two increasing edges between 0 and 90.

asp_plot.terrain.slope_bin_labels(edges)#

Labels of the slope classes between edges, such as "5–10°".

asp_plot.terrain.slope_pixel_size(dem_fn, scale=None)#

The pixel size slope_at_points() takes slope at, in meters.

Returns (size, averaged): the larger of the pixel’s width and height (at the DEM’s centre, for a DEM in degrees) after any averaging for scale, and whether the DEM is averaged.

asp_plot.terrain.slope_source_label(dem_fn, scale=None, name=None)#

Axis label naming where slope came from, such as "Slope from cop30.tif (30 m)" or, for a DEM averaged for scale, "Slope from run-DEM.tif (averaged to 30 m)". name replaces the file name.

asp_plot.terrain.MAX_WINDOW_PIXELS = 16000000#
asp_plot.terrain.SLOPE_BINS = (0, 5, 10, 20, 30, 90)#
asp_plot.terrain.SLOPE_COLUMN = 'slope_deg'#
asp_plot.terrain.SLOPE_MIN_POINTS = 10#
asp_plot.terrain.SLOPE_SCALE_M = 30#