R code - Handy routines for hydrologists
What is R?
R is an open source programming language and environment for data analysis. It has rich functionality for data processing, analysis and graphing. See the R home page for more information and to download the package. Be forewarned that R has a steep learning curve. However, once you gain proficiency in R, the time invested in learning R will be paid back many times over.
R and hydrology
Data analysis is an integral part of hydrology. Hydrologists frequently use techniques, such as regression analysis, which are incorporated into conventional statistical packages and spreadsheet software. However, many hydrological analyses are not, including intensity-duration-frequency analysis and flood frequency analysis. These analyses are relatively simple to code in R.
Three of my current/former students have a blog called "Headwater Analytics," which focuses on advanced applications using R, including web-based interactive mapping, processing MODIS snow cover data using Google Earth Engine, parallel processing and speeding up data input. It is well worth a look, and can be found at:
- Basic introduction (2016-Aug-20)
R scripts for specific hydrologic analyses
What I have included here are bits of R code that hydrologists may find useful. If you have written some code that you would like to share, please send it along and I'll consider posting it here.
- Catchment delineation with RSAGA and mapping using Spatial* and raster objects in R (2016-Aug-20)
- Flood frequency and rainfall intensity-duration frequency analysis
- Intensity-duration-frequency graph paper
- Flood frequency plotting on extreme value graph paper
- Intensity-duration-frequency analysis for Nanaimo Airport, Vancouver Island (NB: needs Gumplot-idf.r; see next script)
- Function to generate Extreme Value I (Gumbel) plot (called by Nanaimo-idf.r)
- Various older scripts
- Fitting a power-law relation between stream discharge and stage
- Binomial filter for regularly sampled time series
- Baseflow separation using a recursive low-pass filter (Nathan and McMahon, 1991, >WRR)
- Use of linear regression to fill in missing air temperature data, with separate regressions by month