Detrend a piecewise Digital Elevation Model (DEM) of a river.
Detrended DEM is a valuable information for a variety of analyses in River Engineering such as flood simulations, sediments transports and river modelling.
However, most known software that remove the trend of DEMs require license.
Riodetrend is a open source tool that efficiently removes the trend of DEMs with approximately linear Thalweg. However, the tool is not limited to DEMs with approximately linear Thalwegs, since a DEM can be clipped into smaller pieces that have the desired linear overall shape.
In general terms, the algorithm first reads a raster (DEM) and a point shapefile (Thalweg) as a arrays. It fits a plane using the cardinal direction and elevation of Thalweg points. As a second step, DEM array and the plane are subtracted resulting in a detrended DEM array. Finally, the detrended array is converted back into a raster (see workflow below).
$ git clone https://github.com/ricardovobarros/riodetrend.git
matplotlib.pyplot
numpy
pandas
geopandas
gdal
os
glob
sys
time
logging
Before applying Riodetrend to your DEMs, you can run the provided example geodata_example
to get a feeling how the tool works.
To run the example, just run detrender.py
. The output (i.e., detrended rasters) will be saved inside the folder detrended_rasters
.
Additionally, graphs that demonstrate the process will be saved inside geodata_example/plots
.
During the running, warnings and the step-by-step computation are shown on the prompt.
Riodetrend require only two inputs to run:
- local file address containing as many DEMs (.tiff files) you want, AND
- local file address containing the corresponding Thalweg(s) (.shp files) to the DEMs.
In addition, the DEMS and shapefles, must be enumerated accordantly, as shown in the example folders geodata_example/rasters
and geodata_example/shapefiles
(e.g., raster_1 correponds to thalweg_1)
- DEM of the river should not have tributaries. It must have only on main path of the river.
- Clip your DEM in a optimized way. That means, this toll won't be able to detrend the DEM
if the clipped raster files are curved. Please see examples in the folder
geodata_example
.
Follow the step-by-step below to create a desirable shape file input to run Detrender Tool.
The shapefiles do not contain the information of the elevation (z). Then it will be necessary to obtain this data from the DEM and relate them to the corresponding coordinates (X,Y) from the shapefile. This process can be done using the Field Calculator, as shown in following steps:
- Open a piecewise DEM in (QGIS).
- Create a Shape Line with the same projection of DEM.
- Use the tool from SAGA
Gradient Vector from Surface
to create a gradient vector field on the DEM. - Use the provided
DEM_style
to paint the DEM. In raster file go to: properties>>style>>load style and chooseDEM_style
- Still in properties, inside Band Rendering, change the max and min values to better fit the style on the DEM. Press ok.
- With the help of the style and the gradient vector filed draw a Shape Line representing the Thalweg of the DEM.
- Use the Tool
Points Along Geometry
and choose the previous created line as Input Layer. Define the distance as the larger pixel size of the DEM - To save the elevation of the pixels immediately below the Shape points do the following:
- Select the created Shape Points and open Field Caculator (Upper part, on the right of "ToolBox" button)
- Inside Field Caculator create a new field, as shown in the Figure 1, with the following properties:
- Choose the function "Expression" >> "Rasters" >> "raster_value"
- raster_value(DEM name, DEM band number, XY value of Shape Points)
- Output field name = "z" (it must be letter 'z' in lower case)
- Output field type = Decimal number (real)
- Choose the function "Expression" >> "Rasters" >> "raster_value"
Figure 1. Creating Field named 'z' which saves
the elevation values of DEM's pixels located at
the exact Shape Point
python detrender.py [(rasters'_file), (shapes'_file), (print_boolean = 1) (band = 1), (detended_limit=10**(-3))]
- rasters' file: (STRING) path-like of the folder in the system that contains all raster files (.tif) to be detrended
- shapes' file: (STRING) path-like string of the folder in the system that contains all shape files (.shp)
- print_boolean: (Optional INT, default=1) choose 1 to plot all figures related to the de trend process. Choose 0 to not plot it.
- band: (Optional INT, default=1) band of the raster, in which is locates the elations of the pixels.
- detrended_limit: (Optional FLOAT, default=10**-3) limit used to validate a detrended raster is flat enough to be considered detrended.
One folder named detrend_rasters will be automatic created at the save location of the
folder containing the raster files.
If print_boolan = 1
, one folder named detrender_plotter will be automatic created at the save location fo the
folder containing the raster files.
The path to the folders should not have space on it.