diff --git a/DESCRIPTION b/DESCRIPTION index b41a249601cb24568db7bb238e7900551a884073..c22d773816f215d07f209cb1fe62df51ac943ae8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,12 +1,13 @@ Package: airGR Type: Package Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling -Version: 1.6.3.2 -Date: 2020-10-05 +Version: 1.6.3.3 +Date: 2020-10-06 Authors@R: c( person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), person("Olivier", "Delaigue", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7668-8468"), email = "airGR@inrae.fr"), person("Guillaume", "Thirel", role = c("aut"), comment = c(ORCID = "0000-0002-1444-1830")), + person("David", "Dorchies", role = c("aut"), comment = c(ORCID = "0000-0002-6595-7984")), person("Charles", "Perrin", role = c("aut", "ths"), comment = c(ORCID = "0000-0001-8552-1881")), person("Claude", "Michel", role = c("aut", "ths")), person("Vazken", "Andréassian", role = c("ctb", "ths"), comment = c(ORCID = "0000-0001-7124-9303")), @@ -20,7 +21,7 @@ Authors@R: c( person("Audrey", "Valéry", role = c("ctb")) ) Depends: R (>= 3.0.1) -Suggests: knitr, rmarkdown, coda, DEoptim, dplyr, FME, ggmcmc, hydroPSO, Rmalschains, testthat +Suggests: knitr, rmarkdown, coda, DEoptim, dplyr, FME, ggmcmc, hydroPSO, Rmalschains, testthat, imputeTS Description: Hydrological modelling tools developed at INRAE-Antony (HYCAR Research Unit, France). The package includes several conceptual rainfall-runoff models (GR4H, GR5H, GR4J, GR5J, GR6J, GR2M, GR1A), a snow accumulation and melt model (CemaNeige) and the associated functions for their calibration and evaluation. Use help(airGR) for package description and references. License: GPL-2 URL: https://hydrogr.github.io/airGR/ diff --git a/NEWS.md b/NEWS.md index 460eee0eabae7be8cafc4cb423bec5639f8c6d72..c731b7ee82d791110a6b8a961fab811f1064009d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,12 +1,13 @@ ## Release History of the airGR Package -### 1.6.3.2 Release Notes (2020-10-05) +### 1.6.3.3 Release Notes (2020-10-06) #### New features - Change order of parameters: LAG is now the first parameter instead of the last - Add argument checks in RunModel_LAG -- Add Documentation page with example for RunModel_LAG +- Add documentation page with example for RunModel_LAG +- Add vignette on SD model calibration ____________________________________________________________________________________ diff --git a/vignettes/V05_sd_model.Rmd b/vignettes/V05_sd_model.Rmd new file mode 100644 index 0000000000000000000000000000000000000000..e185cca344c2839275ac282d0778bd3c72c86c2a --- /dev/null +++ b/vignettes/V05_sd_model.Rmd @@ -0,0 +1,212 @@ +--- +title: "Simulating a reservoir with semi-distributed GR4J model" +bibliography: V00_airgr_ref.bib +output: rmarkdown::html_vignette +vignette: > + %\VignetteEngine{knitr::rmarkdown} + %\VignetteIndexEntry{Simulating a reservoir with semi-distributed GR4J model} + %\VignetteEncoding{UTF-8} +--- + +```{r, include=FALSE, fig.keep='none', results='hide'} +library(airGR) +options(digits = 3) +library(imputeTS) +``` + +# Introduction + +## Scope + +The **airGR** package implements semi-distributed model capabilities using a lag model between subcatchments. It allows to chain together several lumped models as well as integrating anthropogenic influence such as reservoirs or withdrawals. + +`RunModel_LAG` documentation gives an example of simulating the influence of a reservoir in a lumped model. Try `example(RunModel_LAG)` to get it. + +In this vignette, we show how to calibrate 2 sub-catchments in series with a semi-distributed model consisting of 2 GR4J models. For doing this we compare two strategies for calibrating the downstream subcatchment: + +- using upstream observed flows +- using upstream simulated flows + +We finally compare these calibrations with a theoretical set of parameters. + +## Model description + + +```{r, warning=FALSE, include=FALSE} +library(airGR) +options(digits = 3) +``` + +We use an example data set from the package that unfortunately contains data for only one catchment. + +```{r, warning=FALSE} +## loading catchment data +data(L0123001) +``` + +Let's imagine that this catchment of 360 km² is divided into 2 subcatchments: + +- An upstream subcatchment of 180 km² +- 100 km downstream another subcatchment of 180 km² + +We consider that meteorological data are homogeneous on the whole catchment, so we use the same pluviometry `BasinObs$P` and the same evapotranspiration `BasinObs$E` for the 2 subcatchments. + +For the observed flow at the downstream outlet, we generate it with the assumption that the upstream flow arrives at downstream with a constant delay of 2 days. + +```{r} +QObsDown <- (BasinObs$Qmm + c(0, 0, BasinObs$Qmm[1:(length(BasinObs$Qmm)-2)])) / 2 +summary(cbind(QObsUp = BasinObs$Qmm, QObsDown)) +``` + +# Calibration of the upstream subcatchment + +The operations are exactly the same as the ones for a GR4J lumped model. So we do exactly the same operations as in the [Get Started](V01_get_started.html) vignette. + +```{r} +InputsModelUp <- CreateInputsModel(FUN_MOD = RunModel_GR4J, DatesR = BasinObs$DatesR, + Precip = BasinObs$P, PotEvap = BasinObs$E) +Ind_Run <- seq(which(format(BasinObs$DatesR, format = "%Y-%m-%d") == "1990-01-01"), + which(format(BasinObs$DatesR, format = "%Y-%m-%d") == "1999-12-31")) +RunOptionsUp <- CreateRunOptions(FUN_MOD = RunModel_GR4J, + InputsModel = InputsModelUp, IndPeriod_Run = Ind_Run, + IniStates = NULL, IniResLevels = NULL, IndPeriod_WarmUp = NULL) +InputsCritUp <- CreateInputsCrit(FUN_CRIT = ErrorCrit_NSE, InputsModel = InputsModelUp, + RunOptions = RunOptionsUp, VarObs = "Q", Obs = BasinObs$Qmm[Ind_Run]) +CalibOptionsUp <- CreateCalibOptions(FUN_MOD = RunModel_GR4J, FUN_CALIB = Calibration_Michel) +OutputsCalibUp <- Calibration_Michel(InputsModel = InputsModelUp, RunOptions = RunOptionsUp, + InputsCrit = InputsCritUp, CalibOptions = CalibOptionsUp, + FUN_MOD = RunModel_GR4J) +``` + +And see the result of the simulation: + +```{r} +OutputsModelUp <- RunModel_GR4J(InputsModel = InputsModelUp, RunOptions = RunOptionsUp, + Param = OutputsCalibUp$ParamFinalR) +``` + + +# Calibration of the downstream subcatchment with upstream flow observations + +Observed flow data contain `NA` values and a complete time series is mandatory for running the LAG model. We propose to complete the observed upstream flow with linear interpolation: + +```{r} +QObsUp <- imputeTS::na_interpolation(BasinObs$Qmm) +``` + +we need to create the `InputsModel` object completed with upstream information: + +```{r} +InputsModelDown1 <- CreateInputsModel( + FUN_MOD = RunModel_GR4J, DatesR = BasinObs$DatesR, + Precip = BasinObs$P, PotEvap = BasinObs$E, + Qupstream = matrix(QObsUp, ncol = 1), # Upstream observed flow + LengthHydro = 100 * 1000, # Distance between upstream catchment outlet and the downstream one in m + BasinAreas = c(180, 180) # Upstream and downstream areas in km² +) +``` + +And then calibrate the combination of LAG model for upstream flow transfer and GR4J model for the runoff of the downstream subcatchment: + +```{r} +RunOptionsDown <- CreateRunOptions(FUN_MOD = RunModel_GR4J, + InputsModel = InputsModelDown1, IndPeriod_Run = Ind_Run, + IniStates = NULL, IniResLevels = NULL, IndPeriod_WarmUp = NULL) +InputsCritDown <- CreateInputsCrit(FUN_CRIT = ErrorCrit_NSE, InputsModel = InputsModelDown1, + RunOptions = RunOptionsDown, VarObs = "Q", Obs = QObsDown[Ind_Run]) +CalibOptionsDown <- CreateCalibOptions(FUN_MOD = RunModel_GR4J, + FUN_CALIB = Calibration_Michel, + IsSD = TRUE) # Don't forget to specify that it's an SD model here +OutputsCalibDown1 <- Calibration_Michel(InputsModel = InputsModelDown1, RunOptions = RunOptionsDown, + InputsCrit = InputsCritDown, CalibOptions = CalibOptionsDown, + FUN_MOD = RunModel_GR4J) +``` + +To run the complete model, we should substitute the observed upstream flow by the simulated one: + +```{r} +InputsModelDown2 <- InputsModelDown1 +InputsModelDown2$Qupstream[Ind_Run] <- OutputsModelUp$Qsim +``` + +`RunModel` is run in order to automatically combine GR4J and LAG models. + +```{r} +OutputsModelDown1 <- RunModel(InputsModel = InputsModelDown2, + RunOptions = RunOptionsDown, + Param = OutputsCalibDown1$ParamFinalR, + FUN_MOD = RunModel_GR4J) +``` + +Performance of the model validation is then: + +```{r} +CritDown1 <- ErrorCrit_NSE(InputsCritDown, OutputsModelDown1) +``` + + +# Calibration of the downstream subcatchment with upstream simulated flow + +We calibrate the model with the `InputsModel` object previously created for substituting the observed upstream flow with the simulated one: + +```{r} +OutputsCalibDown2 <- Calibration_Michel(InputsModel = InputsModelDown2, RunOptions = RunOptionsDown, + InputsCrit = InputsCritDown, CalibOptions = CalibOptionsDown, + FUN_MOD = RunModel_GR4J) +ParamDown2 <- OutputsCalibDown2$ParamFinalR +``` + + +# Discussion + +## Identification of LAG parameter + +The theoretical LAG parameter should be equal to: + +```{r} +LAG <- InputsModelDown1$LengthHydro / (2 * 86400) +paste(format(LAG), "m/s") +``` + +Both calibrations overestimate this parameter: + +```{r} +mLag <- matrix(c(LAG, OutputsCalibDown1$ParamFinalR[1], OutputsCalibDown2$ParamFinalR[1]), ncol = 1) +rownames(mLag) = c("theoretical", "calibrated with observed upstream flow", + "calibrated with simulated upstream flow") +colnames(mLag) = c("LAG parameter") +knitr::kable(mLag) +``` + +## Value of the performance criteria with theoretical calibration + +Theoretically, the parameters of the downstream GR4J model should be the same as the upstream one and we know the lag time. So this set of parameter should give a better performance criteria: + +```{r} +ParamDownTheo <- c(LAG, OutputsCalibUp$ParamFinalR) +OutputsModelDownTheo <- RunModel(InputsModel = InputsModelDown2, + RunOptions = RunOptionsDown, + Param = ParamDownTheo, + FUN_MOD = RunModel_GR4J) +CritDownTheo <- ErrorCrit_NSE(InputsCritDown, OutputsModelDownTheo) +``` + + + +## Parameters and performance of each subcatchment for all calibrations + +```{r} +comp <- matrix(c(0, OutputsCalibUp$ParamFinalR, rep(OutputsCalibDown1$ParamFinalR, 2), + OutputsCalibDown2$ParamFinalR, ParamDownTheo), ncol = 5, byrow = TRUE) +comp <- cbind(comp, c(OutputsCalibUp$CritFinal, OutputsCalibDown1$CritFinal, + CritDown1$CritValue, OutputsCalibDown2$CritFinal, CritDownTheo$CritValue)) +colnames(comp) <- c("LAG", paste0("x", 1:4), "NSE") +rownames(comp) <- c("Calibration of the upstream subcatchment", + "Calibration 1 with observed upstream flow", + "Validation 1 with simulated upstream flow", + "Calibration 2 with simulated upstream flow", + "Validation theoretical set of parameters") +knitr::kable(comp) +``` + +Even if calibration with observed upstream flows gives an improved performance criteria, in validation using simulated upstream flows the result is quite similar as the performance obtained with the calibration with upstream simulated flows. The theoretical set of parameters give also an equivalent performance but still underperforming the calibration 2 one.