:py:mod:`wolfhece.rem.REMMaker` =============================== .. py:module:: wolfhece.rem.REMMaker Module Contents --------------- .. py:data:: level .. py:data:: fmt :value: '[%(levelname)s] %(asctime)s - %(message)s' .. py:data:: start .. py:data:: usage :value: Multiline-String .. raw:: html
Show Value .. code-block:: python """ 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. """ .. raw:: html
.. py:function:: print_usage() .. py:function:: clear_osm_cache() Clear the OSM cache folder (./.osm_cache). This is useful if the OSM Editor has been used to update river centerlines. .. py:class:: 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') Bases: :py:obj:`object` Handler to automatically make a river REM from an input DEM. :param dem: path to input DEM raster. :type dem: str :param centerline_shp: (optional) river centerline shapefile to use. If given, overrides OpenStreetMap centerline. :type centerline_shp: str :param out_dir: output file directory. Defaults to current working directory. :type out_dir: str :param 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. :type interp_pts: int :param k: 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. :type k: int :param eps: fractional error tolerance for finding nearest neighbors in KD tree query. Higher values allow faster interpolation at the expense of accuracy. :type eps: float :param workers: number of CPU threads to use for interpolation. -1 uses all threads. :type workers: int :param cache_dir: cache directory :type cache_dir: str .. py:property:: dem .. py:property:: centerline_shp .. py:property:: bounds .. py:property:: out_dir .. py:property:: cache_dir .. py:method:: valid_input(dem) :staticmethod: .. py:method:: get_spatial_metadata() 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. .. py:method:: get_river_centerline() Find centerline of river(s) within DEM area using OSM Ways .. py:method:: lines2pts() Convert river centerline segment linestrings to a set of points to sample for interpolation. .. py:method:: make_river_shp() Make points along river centerline into a shapefile .. py:method:: read_centerline_input() Read user provided centerline shapefile instead of using OSM. .. py:method:: get_river_elev() Get DEM values along river centerline .. py:method:: get_sinuosity() Estimate sinuosity of the river using river centerline(s) length / distance between line endpoints .. py:method:: estimate_k() Determine the number of k nearest neighbors to use for interpolation .. py:method:: interp_river_elev() Interpolate elevation at river centerline across DEM extent. Time for KDTree query scales with log(k). .. py:method:: detrend_dem() Subtract interpolated river elevation from DEM elevation to get REM .. py:method:: make_rem() 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. :rtype: str .. py:method:: make_rem_viz(cmap='mako_r', z=4, blend_percent=25, make_png=True, make_kmz=False, *args, **kwargs) Create REM visualization by blending the REM color-relief with a DEM hillshade to make a pretty finished product. :param cmap: 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. :type cmap: str :param z: z factor for exaggerating vertical scale differences of hillshade. :type z: float >1 :param blend_percent: Percent weight of hillshdae in blended image, color-relief takes opposite weight. :type blend_percent: float [0-100] :returns: path to output raster :rtype: str .. py:method:: clean_up() .. py:data:: argv