/UYRW_data

R scripts for acquiring and processing data needed for streamflow models of the Upper Yellowstone River Watershed

Primary LanguageR

r code

This repository hosts the R codebase for our data analysis and modelling workflows. Most of our scripts (*.R) include some roxygen2-style commenting for generating markdown report files (*.knit.md), shared here to better document and organize our research.

data

R/get_data contains R scripts to fetch public datasets on the hydrology of UYR:

SWAT

The Soil and Water Assessment Tool (SWAT) is a widely-used river basin watershed model with a very long development history dating back to the early 90s. Read more about it here. These days SWAT has a large and active community of users running one of the two public-domain Fortran-based implementations maintained by the USDA and Texas A&M:

Both versions continue to be updated and patched regularly (don't be fooled by the "2012"). However, although the mathematical models behind the names are largely the same, their project files are not interchangeable as SWAT+ uses different variable names and file structures. Our project will focus on building extensions of the newest official release of SWAT+.

analysis

The R/analysis directory (in development) is for building, fitting and analysing SWAT+ models in R.

Using the output from /R/get_data, we plan to fit SWAT+ models sequentially on small catchments in the UYRW. Check back in the coming weeks as we add to this section to demonstrate the model building code:

  • make_subwatersheds partitions the UYRW area into subwatersheds with USGS gages at their outlets
  • helper_analysis utilities for creating and calibrating SWAT+ models in R

rswat

The parametrization of a SWAT model is not trivial. A typical use case will involve dozens of config files containing many thousands of model parameters. Fortunately, SWAT is largely made up of process-based components whose physically-based parameters can (at least initially) be set using empirical data.

For example after running get_dem to fetch our DEM, we can run the TauDEM workflow to define subbasins and construct a routing network connecting them. After running get_soils and get_landuse, we can then delineate HRUs and assign their plant/soil parameters to survey values. These steps are usually carried out using QSWAT/QSWAT+ (GUI-based QGIS plugins). Our code runs them programmatically from within R:

rswat is a set of tools for building SWAT+ models and managing their many files. This includes R wrappers for running the QSWAT+ workflow in PyQGIS, calling SWATEditor.exe to build model config files; reading, cataloging and modifying these files, executing simulations, and reading the outputs. The following vignettes demonstrate these features on a simple example catchment

rswat_docs is a small set of R functions that renders the inputs and outputs documentation PDFs as text and extracts a large, easily searchable table of name-definition pairs. See demo_rswat_docs for a vignette on searching the I/O PDF from within R.

We may polish some/all of this code and release it as an R package at some point. Those interested in script-based workflows for SWAT are encouraged to also check out the SWAT+AW and SWATPlusR projects.

about us

We are a team of mathematicians, statisticians, and ecologists, conducting a multi-year research project to develop an operational forecasting system for streamflow and water quality on the Upper Yellowstone River (UYR) and its tributaries. Our system will be based on SWAT+/gflow, a hybrid of the SWAT+ (Soil-Water-Assessment Tool) model for surface water dynamics, and gflow, physically-based groundwater flow module developed by Ryan Bailey to replace the current SWAT+ aquifer module.

funding

Our work is funded through a MITACS Accelerate International grant to Dean Koch, partnering the University of Alberta with R2CS LLC in Montana, and the Yellowstone Ecological Research Center. The project began on August 3, 2020.

gallery

R is a powerful data-retrieval, GIS, and visualization tool. These figures are generated by the scripts in our repo using the tmap package: