Some pieces of code

Here I keep a public list of software tools (mostly using R) that I have developed at some point and that may be useful to other people.

Shiny app to estimate river discharge

App developed in Shiny to measure discharge in streams using a slug injection. Code and more details in github.

This app is intended to measure discharge using a slug injection of salt, it requires data recorded with a HoBo conductivity logger, a correction coefficient of the response of conductivity against NaCl and the exact amount of salt injected.

The version 2 is to use with another method: by adding a measured volume of salt solution in water, with a known conductivity.

Example of the interface

Get river slope anywhere in the world

River slope is a very useful parameter in stream geomorphology, aquatic ecology, hydrology… but hard to obtain easily at any location in the globe. This R script can obtain the stream channel just providing a pair of coordinates of a stream. The workflow is as follows:

  • Download a high resolution digital elevation model (DEM) around the site, using the package “elevatr”.
  • Model the flow accumulation in the landscape to see the stream channels.
  • Snap the coordinates provided to the closest stream.
  • An algorithm then follows the stream channel upstream for a predetermined length, and estimates the slope as the elevation difference between the site and upstream divided by the distance.

Code and more details for this is in github.

An example of the algorithm working. The black point is the low site, and the red the site upstream. The raster shows the flow accumulation in the landscape