formatGR      <- '<strong><font color="#0BA6AA">%s</font></strong>'
GR            <- sprintf(formatGR, "GR")
airGR         <- sprintf(formatGR, "airGR")
airGRteaching <- sprintf(formatGR, "airGRteaching")
knitr::opts_chunk$set(echo = TRUE)
library(airGRteaching)

Hydrological modelling in three steps

This part explains how to run the r airGR hydrological models in only three simple steps with r airGRteaching.

Preparation of input data

A data.frame of daily hydrometeorological observations time series at the catchment scale is needed. The required fields are:

data(L0123001, package = "airGR")
BasinObs <- BasinObs[, c("DatesR", "P", "E", "Qmm", "T")]
head(BasinObs)

Before running a model, r airGRteaching functions require data and options with specific formats.

For this step, you just have to use the PrepGR() function. You have to define:

If you want to use CemaNeige, you also have to define:

PREP <- PrepGR(ObsDF = BasinObs, HydroModel = "GR5J", CemaNeige = FALSE)


Calibration step

To calibrate a model, you just have to use the CalGR() function. By default, the objective function used is the Nash–Sutcliffe criterion ("NSE"), and the warm-up period is automatically set (depends on model). You just have to define:

You can obviously define another objective function or warm-up period:

The calibration algorithm has been developed by Claude Michel (Calibration_Michel() function in the r airGR package) .

CAL <- CalGR(PrepGR = PREP, CalCrit = "KGE2",
             WupPer = NULL, CalPer = c("1990-01-01", "1993-12-31"))


Simulation step

To run a model, please use the SimGR() function. The PrepGR and WupPer arguments of SimGR() are similar to the ones of the CalGR() function. Here, EffCrit is used to calculate the performance of the model over the simulation period SimPer and Param is the object returned by the CalGR() function.

SIM <- SimGR(PrepGR = PREP, Param = CAL, EffCrit = "KGE2",
             WupPer = NULL, SimPer = c("1994-01-01", "1998-12-31"))


Formating outputs

The call of the as.data.frame() function with PrepGR, CalGR or SimGR objects allows to coerce the outputs to a data frame.

head(as.data.frame(PREP))
head(as.data.frame(CAL))
head(as.data.frame(SIM))

Pre-defined graphical plots

Static plots

The call of the plot() function with a PrepGR object draws the observed precipitation and discharge time series.

par(cex.lab = 0.6, cex.axis = 0.6)
plot(PREP, main = "Observation")

By default (with the argument which = "synth"), the call of the plot() function with a CalGR object draws the classical r airGR plot diagnostics (observed and simulated time series together with diagnostic plot)

plot(CAL, which = "synth")
plot(CAL, which = "synth", cex.lab = 0.7, cex.axis = 0.7)

With the CalGR object, if the argument which is set to "iter", the plot() function draws the evolution of the parameters and the values of the objective function during the second step of the calibration (steepest descent local search algorithm):

plot(CAL, which = "iter")

With the CalGR object, if the argument which is set to "ts", the plot() function simply draws the time series of the observed precipitation, and the observed and simulated flows:

par(cex.lab = 0.7, cex.axis = 0.7)
plot(CAL, which = "ts", main = "Calibration")

The call of the plot() function with a SimGR object displays the classical r airGR plot diagnostics.

plot(SIM)

Dynamic plots

Dynamic plots, using the dygraphs JavaScript charting library, can be displayed by the package.

The dyplot() function can be applied on PrepGR, CalGR and SimGR objects and draws the time series of the observed precipitation, and the observed and simulated (except with PrepGR objects) flows.

The user can zoom on the plot device and can read the exact values.

With this function, users can easily explore the data time series and also explore and interpret the possible problems of the calibration or simulation steps.

dyplot(SIM, main = "Simulation")

Graphical user interface

The r airGRteaching package also provides the ShinyGR() function, which allows to launch a graphical user interface using the shiny package.

The ShinyGR() function needs at least:

ShinyGR(ObsDF = BasinObs, SimPer = c("1994-01-01", "1998-12-31"))

Only the monthly model (GR2M) and the daily models (GR4J, GR5J, GR6J + CemaNeige) are currently available.
If you want to use CemaNeige, you also have to define the same arguments desribed above for the PrepGR() function.

It is also possible to change the interface look; different themes are proposed (theme argument).



Try the airGRteaching package in your browser

Any scripts or data that you put into this service are public.

airGRteaching documentation built on July 26, 2023, 5:50 p.m.