wolfhece.rem.REMMaker

Module Contents

wolfhece.rem.REMMaker.level[source]
wolfhece.rem.REMMaker.fmt = '[%(levelname)s] %(asctime)s - %(message)s'[source]
wolfhece.rem.REMMaker.start[source]
wolfhece.rem.REMMaker.usage = Multiline-String[source]
Show Value
"""
Script to make river relative elevation model (REM) given a DEM raster as input.
This script can be called from Python using its class/methods or as a CLI utility.

CLI Usage:

"python REMMaker.py [-centerline_shp (default=None)] [-cmap (default=mako_r)] [-z (default=4)]
                    [-blend_percent (default=25)] [-interp_pts (default=1000)] [-k (default=auto)]
                    [-eps (default=0.1)] [-workers (default=4)] /path/to/dem"

Options:

    -centerline_shp: Path to user-provided river centerline shapefile. If used, overrides OpenStreetMap centerline.

    -cmap: Name of a matplotlib or seaborn colormap. Default "mako_r".
           (see https://matplotlib.org/stable/gallery/color/colormap_reference.html)

    - z: Vertical exaggeration scale factor for visualization. Default 4.

    - blend_percent: Percent of hillshade to blend in with color-relief REM. REM takes opposite weight. Default 25.

    -interp_pts: Max number of points to use for interpolation. Actual number of points is limited by number of
                 DEM pixels along centerline, so less points than this will be used for lower resolution DEMs.
                 Default is 1,000.

    -k: Number of nearest neighbor pixels to use for interpolation of river centerline elevations across DEM.
        If no value is supplied, the value of k is automatically estiamted. Higher values make smoother looking REMs
        at the expense of increased computation time.

    -eps: Error tolerance in nearest neighbor matching for approximate KD tree query interpolation.
          Higher values make the interpolation faster at the expense of accuracy.
          Approximate kth nearest neighbors are guaranteed to be no further than (1 + eps) times
          the distance to the true kth nearest neighbor.

    -workers: Number of CPU threads to use when making KD tree query/interpolation. Default is 4. -1 uses all threads.

    /path/to/dem: The path to the DEM raster used to make a derived REM.

Notes: River centerlines used to create REMs are retrieved from OpenStreetMap (OSM). If a desired river segment is
       not listed on OSM, a new river centerline can be created/edited at: https://www.openstreetmap.org/edit
       (clear the ./.osm_cache folder after using the OSM editor to get the updated centerline).

       For large/high resolution DEMs, the interpolation can take a long time. Additionally, it may be necessary
       to increase the value of k if interpolation artefacts (discrete linear breaks in REM coloring) are present.
"""
wolfhece.rem.REMMaker.print_usage()[source]
wolfhece.rem.REMMaker.clear_osm_cache()[source]

Clear the OSM cache folder (./.osm_cache). This is useful if the OSM Editor has been used to update river centerlines.

class wolfhece.rem.REMMaker.REMMaker(dem, centerline_shp=None, out_dir='./', bounds=None, count=None, pres=None, kd=True, interp_pts=1000, k=None, eps=0.1, workers=4, cache_dir='./.cache')[source]

Bases: object

Handler to automatically make a river REM from an input DEM.

Parameters:
  • dem (str) – path to input DEM raster.

  • centerline_shp (str) – (optional) river centerline shapefile to use. If given, overrides OpenStreetMap centerline.

  • out_dir (str) – output file directory. Defaults to current working directory.

  • bounds – (optional) [x_min,y_min,x_max,y_max] represents the extent wanted that has to be computed et plotted.

:type bounds : list :param count : (optional) geometry number in centerline_shp given that has to be computed and plotted. :type count : int :param pres : (optional) new resolution of the pixels DEM (length and width are the same). :type pres : float :param interp_pts: maximum number of points to use for interpolation of river centerline elevation. Actual number

of points is limited by number of DEM pixels along centerline, so less points may be used for lower resolution DEMs.

Parameters:
  • k (int) – number of nearest neighbors to use for IDW interpolation. If None, an appropriate value is estimated. The estimation routine uses k between 5-100 points (0.5-10% of the river length) depending on the sinuosity of the river of interest. Greater values of k are used for more sinuous rivers.

  • eps (float) – fractional error tolerance for finding nearest neighbors in KD tree query. Higher values allow faster interpolation at the expense of accuracy.

  • workers (int) – number of CPU threads to use for interpolation. -1 uses all threads.

  • cache_dir (str) – cache directory

property dem[source]
property centerline_shp[source]
property bounds[source]
property out_dir[source]
property cache_dir[source]
static valid_input(dem)[source]
get_spatial_metadata()[source]

Get various spatial metadata from DEM to use for processing: projection, EPSG code, DEM array, NoData Value, cell size, extent/bbox, function mapping array indices to x,y coordinates.

get_river_centerline()[source]

Find centerline of river(s) within DEM area using OSM Ways

lines2pts()[source]

Convert river centerline segment linestrings to a set of points to sample for interpolation.

make_river_shp()[source]

Make points along river centerline into a shapefile

read_centerline_input()[source]

Read user provided centerline shapefile instead of using OSM.

get_river_elev()[source]

Get DEM values along river centerline

get_sinuosity()[source]

Estimate sinuosity of the river using river centerline(s) length / distance between line endpoints

estimate_k()[source]

Determine the number of k nearest neighbors to use for interpolation

interp_river_elev()[source]

Interpolate elevation at river centerline across DEM extent. Time for KDTree query scales with log(k).

detrend_dem()[source]

Subtract interpolated river elevation from DEM elevation to get REM

make_rem()[source]

Make a relative elevation model (REM). Note that this method creates a raw REM raster and doesn’t apply color-relief/shading for visualization.

Returns:

path to output REM raster.

Return type:

str

make_rem_viz(cmap='mako_r', z=4, blend_percent=25, make_png=True, make_kmz=False, *args, **kwargs)[source]

Create REM visualization by blending the REM color-relief with a DEM hillshade to make a pretty finished product.

Parameters:
  • cmap (str) – name of matplotlib/seaborn named colormap to use for REM coloring (see https://matplotlib.org/stable/gallery/color/colormap_reference.html). Note the applied colormap is logarithmically scaled in order to emphasize elevations differences close to the river centerline.

  • z (float >1) – z factor for exaggerating vertical scale differences of hillshade.

  • blend_percent (float [0-100]) – Percent weight of hillshdae in blended image, color-relief takes opposite weight.

Returns:

path to output raster

Return type:

str

clean_up()[source]
wolfhece.rem.REMMaker.argv[source]