asp_plot.terrain
================

.. py:module:: asp_plot.terrain

.. autoapi-nested-parse::

   Terrain attributes of a DEM at point locations.

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



Attributes
----------

.. autoapisummary::

   asp_plot.terrain.MAX_WINDOW_PIXELS
   asp_plot.terrain.SLOPE_BINS
   asp_plot.terrain.SLOPE_COLUMN
   asp_plot.terrain.SLOPE_MIN_POINTS
   asp_plot.terrain.SLOPE_SCALE_M


Functions
---------

.. autoapisummary::

   asp_plot.terrain.slope_at_points
   asp_plot.terrain.slope_bin_edges
   asp_plot.terrain.slope_bin_labels
   asp_plot.terrain.slope_pixel_size
   asp_plot.terrain.slope_source_label


Module Contents
---------------

.. py:function:: 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.

   :param dem_fn: 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.
   :type dem_fn: str
   :param points: Points, in any CRS (reprojected to the DEM's).
   :type points: geopandas.GeoDataFrame
   :param scale: 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.
   :type scale: float, optional

   :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``).
   :rtype: numpy.ndarray


.. py:function:: 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.


.. py:function:: slope_bin_labels(edges)

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


.. py:function:: slope_pixel_size(dem_fn, scale=None)

   The pixel size :func:`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.


.. py:function:: 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.


.. py:data:: MAX_WINDOW_PIXELS
   :value: 16000000


.. py:data:: SLOPE_BINS
   :value: (0, 5, 10, 20, 30, 90)


.. py:data:: SLOPE_COLUMN
   :value: 'slope_deg'


.. py:data:: SLOPE_MIN_POINTS
   :value: 10


.. py:data:: SLOPE_SCALE_M
   :value: 30


