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)
This part explains how to run the r airGR
hydrological models in only three simple steps with r airGRteaching
.
A data.frame
of daily hydrometeorological observations time series at the catchment scale is needed. The required fields are:
POSIXt
format 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:
ObsDF
: data.frame
of hydrometeorological observations time seriesHydroModel
: the name of the hydrological model you want to run (GR1A, GR2M, GR4J, GR5J, GR6J, GR4H or GR5H)CemaNeige
: if you want or not to use the snowmelt and accumulation modelIf you want to use CemaNeige, you also have to define:
ObsDF
or in TempMean
HypsoData
: a vector of 101 reals: min, quantiles (1 % to 99 %) and max of catchment elevation distribution [m]; if not defined a single elevation layer is used for CemaNeigeNLayers
: the number of elevation layers requested [-]PREP <- PrepGR(ObsDF = BasinObs, HydroModel = "GR5J", CemaNeige = FALSE)
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:
PrepGR
: the object returned by the PrepGR()
functionCalPer
: a vector of 2 dates to define the calibration periodYou can obviously define another objective function or warm-up period:
CalCrit
: name of the objective function ("NSE", "KGE", "KGE2", "RMSE"
)WupPer
: a vector of 2 dates to define the warm-up periodThe 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"))
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"))
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))
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, 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")
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:
ObsDF
: a (list of) data.frame
(or independant vector instead, see ?ShinyGR
)SimPer
: a (list of) vector(s) of 2 dates to define the simulation period(s)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).
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.