Commit fdeaff25 authored by unknown's avatar unknown
Browse files

v0.1.10.0 ObsGR function (and relatives arguments in CalGR and SimGR) has been...

v0.1.10.0 ObsGR function (and relatives arguments in CalGR and SimGR) has been renamed PrepGR  #5017
parent bd1f2e11
Package: airGRteaching
Type: Package
Title: Tools to Simplify the Use of the airGR Hydrological Package for Education (Including a Shiny Interface)
Version: 0.1.9.29
Version: 0.1.10.0
Date: 2018-01-29
Authors@R: c(person("Olivier", "Delaigue", role = c("aut", "cre"), email = "airGR@irstea.fr"), person("Laurent", "Coron", role = c("aut")), person("Pierre", "Brigode", role = c("aut")), person("Guillaume", "Thirel", role = c("ctb")))
Depends: airGR (>= 1.0.9.43)
......
......@@ -2,7 +2,7 @@
Modelling functions:
====================
ObsGR Creation of the inputs required to the CalGR
PrepGR Creation of the inputs required to the CalGR
and SimGR functions
CalGR Calibration algorithm optimises the error
criterion selected as objective function
......@@ -12,9 +12,9 @@ SimGR Run GR hydrological models
Plotting functions:
====================
dyplot Interactive time series plotting of ObsGR, CalGR
dyplot Interactive time series plotting of PrepGR, CalGR
and SimGR objects
plot.ObsGR Time series plotting GR objects from inputs
plot.PrepGR Time series plotting GR objects from inputs
plot.CalGR Plotting of the evolution of parameters and
objective function during the calibration step,
and time series plotting GR objects from calibration
......@@ -26,5 +26,4 @@ Shiny interface:
====================
ShinyGR Interactive Web applications to run the GR4J, GR5J
and GR6J
hydrological models whith or without CemaNeige
and GR6J hydrological models whith or without CemaNeige
......@@ -4,11 +4,11 @@
#####################################
## S3 methods ##
#####################################
S3method("plot","ObsGR")
S3method("plot","PrepGR")
S3method("plot","CalGR")
S3method("plot","SimGR")
S3method("dyplot","default")
S3method("dyplot","ObsGR")
S3method("dyplot","PrepGR")
S3method("dyplot","CalGR")
S3method("dyplot","SimGR")
......@@ -18,14 +18,14 @@ S3method("dyplot","SimGR")
## Export ##
#####################################
export(CalGR)
export(ObsGR)
export(PrepGR)
export(SimGR)
export(plot.ObsGR)
export(plot.PrepGR)
export(plot.CalGR)
export(plot.SimGR)
export(dyplot)
export(dyplot.default)
export(dyplot.ObsGR)
export(dyplot.PrepGR)
export(dyplot.CalGR)
export(dyplot.SimGR)
export(ShinyGR)
......
CalGR <- function(ObsGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
CalGR <- function(PrepGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
WupPer = NULL, CalPer, transfo = c("", "sqrt", "log", "inv", "sort"), verbose = TRUE) {
if (! any(class(ObsGR) %in% "ObsGR")) {
stop("Non convenient data for argument \"ObsGR\". Must be of class \"ObsGR\"")
if (! any(class(PrepGR) %in% "PrepGR")) {
stop("Non convenient data for argument \"PrepGR\". Must be of class \"PrepGR\"")
}
WupInd <- NULL
......@@ -11,10 +11,10 @@ CalGR <- function(ObsGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
if (any(is.na(WupPer))) {
stop("Non convenient date format for the warm-up period \"WupPer\"")
} else {
if (! (any(ObsGR$InputsModel$DatesR == WupPer[1]) & any(ObsGR$InputsModel$DatesR == WupPer[2]))) {
if (! (any(PrepGR$InputsModel$DatesR == WupPer[1]) & any(PrepGR$InputsModel$DatesR == WupPer[2]))) {
stop("Non convenient date for the warm-up period \"WupPer\"")
} else {
WupInd <- which(ObsGR$InputsModel$DatesR == WupPer[1]):which(ObsGR$InputsModel$DatesR == WupPer[2])
WupInd <- which(PrepGR$InputsModel$DatesR == WupPer[1]):which(PrepGR$InputsModel$DatesR == WupPer[2])
}
}
}
......@@ -23,10 +23,10 @@ CalGR <- function(ObsGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
if (any(is.na(CalPer))) {
stop("Non convenient date format for the calibration period \"CalPer\"")
} else {
if (! (any(ObsGR$InputsModel$DatesR == CalPer[1]) & any(ObsGR$InputsModel$DatesR == CalPer[2]))) {
if (! (any(PrepGR$InputsModel$DatesR == CalPer[1]) & any(PrepGR$InputsModel$DatesR == CalPer[2]))) {
stop("Non convenient date for the calibration period \"CalPer\"")
} else {
CalInd <- which(ObsGR$InputsModel$DatesR == CalPer[1]):which(ObsGR$InputsModel$DatesR == CalPer[2])
CalInd <- which(PrepGR$InputsModel$DatesR == CalPer[1]):which(PrepGR$InputsModel$DatesR == CalPer[2])
}
}
......@@ -44,31 +44,31 @@ CalGR <- function(ObsGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
transfo <- transfo[1L]
}
MOD_opt <- CreateRunOptions(FUN_MOD = get(ObsGR$TypeModel), InputsModel = ObsGR$InputsModel,
MOD_opt <- CreateRunOptions(FUN_MOD = get(PrepGR$TypeModel), InputsModel = PrepGR$InputsModel,
IndPeriod_WarmUp = WupInd, IndPeriod_Run = CalInd, verbose = FALSE)
MOD_crt <- CreateInputsCrit(FUN_CRIT = FUN_CRIT, InputsModel = ObsGR$InputsModel,
RunOptions = MOD_opt, Qobs = ObsGR$Qobs[CalInd], transfo = transfo)
MOD_crt <- CreateInputsCrit(FUN_CRIT = FUN_CRIT, InputsModel = PrepGR$InputsModel,
RunOptions = MOD_opt, Qobs = PrepGR$Qobs[CalInd], transfo = transfo)
CAL_opt <- CreateCalibOptions(FUN_MOD = get(ObsGR$TypeModel), FUN_CALIB = Calibration_Michel)
CAL_opt <- CreateCalibOptions(FUN_MOD = get(PrepGR$TypeModel), FUN_CALIB = Calibration_Michel)
CAL <- Calibration(InputsModel = ObsGR$InputsModel, RunOptions = MOD_opt,
CAL <- Calibration(InputsModel = PrepGR$InputsModel, RunOptions = MOD_opt,
InputsCrit = MOD_crt, CalibOptions = CAL_opt,
FUN_MOD = get(ObsGR$TypeModel), FUN_CRIT = FUN_CRIT,
FUN_MOD = get(PrepGR$TypeModel), FUN_CRIT = FUN_CRIT,
FUN_CALIB = Calibration_Michel, verbose = verbose)
SIM <- RunModel(InputsModel = ObsGR$InputsModel, RunOptions = MOD_opt,
Param = CAL$ParamFinalR, FUN_MOD = get(ObsGR$TypeModel))
SIM <- RunModel(InputsModel = PrepGR$InputsModel, RunOptions = MOD_opt,
Param = CAL$ParamFinalR, FUN_MOD = get(PrepGR$TypeModel))
CalGR <- list(OptionsCalib = MOD_opt, Qobs = ObsGR$Qobs[CalInd],
CalGR <- list(OptionsCalib = MOD_opt, Qobs = PrepGR$Qobs[CalInd],
OutputsCalib = CAL, OutputsModel = SIM,
TypeModel = ObsGR$TypeModel, CalCrit = CalCrit,
PeriodModel = list(WarmUp = as.POSIXct(ObsGR$InputsModel$DatesR[range(MOD_opt$IndPeriod_WarmUp)]),
TypeModel = PrepGR$TypeModel, CalCrit = CalCrit,
PeriodModel = list(WarmUp = as.POSIXct(PrepGR$InputsModel$DatesR[range(MOD_opt$IndPeriod_WarmUp)]),
Run = CalPer))
class(CalGR) <- c("CalGR", "GR")
return(CalGR)
......
ObsGR <- function(ObsBV = NULL, DatesR = NULL, Precip = NULL, PotEvap = NULL, Qobs = NULL, TempMean = NULL,
PrepGR <- function(ObsBV = NULL, DatesR = NULL, Precip = NULL, PotEvap = NULL, Qobs = NULL, TempMean = NULL,
ZInputs = NULL, HypsoData = NULL, NLayers = 5,
HydroModel, CemaNeige = FALSE) {
......@@ -63,8 +63,8 @@ ObsGR <- function(ObsBV = NULL, DatesR = NULL, Precip = NULL, PotEvap = NULL, Qo
ZInputs = ZInputs, HypsoData = HypsoData, NLayers = NLayers, verbose = FALSE)
ObsGR <- list(InputsModel = MOD_obs, Qobs = ObsBV$Qobs, TypeModel = TypeModel)
class(ObsGR) <- c("ObsGR", "GR")
return(ObsGR)
PrepGR <- list(InputsModel = MOD_obs, Qobs = ObsBV$Qobs, TypeModel = TypeModel)
class(PrepGR) <- c("PrepGR", "GR")
return(PrepGR)
}
SimGR <- function(ObsGR, CalGR = NULL, Param = NULL, EffCrit = c("NSE", "KGE", "KGE2", "RMSE"),
SimGR <- function(PrepGR, CalGR = NULL, Param = NULL, EffCrit = c("NSE", "KGE", "KGE2", "RMSE"),
WupPer = NULL, SimPer, transfo = c("", "sqrt", "log", "inv", "sort"), verbose = TRUE) {
if (! any(class(ObsGR) %in% "ObsGR")) {
stop("Non convenient data for argument \"ObsGR\". Must be of class \"ObsGR\"")
if (! any(class(PrepGR) %in% "PrepGR")) {
stop("Non convenient data for argument \"PrepGR\". Must be of class \"PrepGR\"")
}
if (! any(class(CalGR) %in% "CalGR") & !is.null(CalGR)) {
......@@ -22,10 +22,10 @@ SimGR <- function(ObsGR, CalGR = NULL, Param = NULL, EffCrit = c("NSE", "KGE", "
if (any(is.na(WupPer))) {
stop("Non convenient date format for the warm-up period \"WupPer\"")
} else {
if (! (any(ObsGR$InputsModel$DatesR == WupPer[1]) & any(ObsGR$InputsModel$DatesR == WupPer[1]))) {
if (! (any(PrepGR$InputsModel$DatesR == WupPer[1]) & any(PrepGR$InputsModel$DatesR == WupPer[1]))) {
stop("Non convenient date for the warm-up period \"WupPer\"")
} else {
WupInd <- which(ObsGR$InputsModel$DatesR == WupPer[1]):which(ObsGR$InputsModel$DatesR == WupPer[2])
WupInd <- which(PrepGR$InputsModel$DatesR == WupPer[1]):which(PrepGR$InputsModel$DatesR == WupPer[2])
}
}
}
......@@ -34,10 +34,10 @@ SimGR <- function(ObsGR, CalGR = NULL, Param = NULL, EffCrit = c("NSE", "KGE", "
if (any(is.na(SimPer))) {
stop("Non convenient date format for the simulation period \"SimPer\"")
} else {
if (! (any(ObsGR$InputsModel$DatesR == SimPer[1]) & any(ObsGR$InputsModel$DatesR == SimPer[2]))) {
if (! (any(PrepGR$InputsModel$DatesR == SimPer[1]) & any(PrepGR$InputsModel$DatesR == SimPer[2]))) {
stop("Non convenient date for the simulation period \"SimPer\"")
} else {
SimInd <- which(ObsGR$InputsModel$DatesR == SimPer[1]):which(ObsGR$InputsModel$DatesR == SimPer[2])
SimInd <- which(PrepGR$InputsModel$DatesR == SimPer[1]):which(PrepGR$InputsModel$DatesR == SimPer[2])
}
}
......@@ -55,25 +55,25 @@ SimGR <- function(ObsGR, CalGR = NULL, Param = NULL, EffCrit = c("NSE", "KGE", "
transfo <- transfo[1L]
}
MOD_opt <- CreateRunOptions(FUN_MOD = get(ObsGR$TypeModel), InputsModel = ObsGR$InputsModel,
MOD_opt <- CreateRunOptions(FUN_MOD = get(PrepGR$TypeModel), InputsModel = PrepGR$InputsModel,
IndPeriod_WarmUp = WupInd, IndPeriod_Run = SimInd, verbose = verbose)
MOD_crt <- CreateInputsCrit(FUN_CRIT = FUN_CRIT, InputsModel = ObsGR$InputsModel,
RunOptions = MOD_opt, Qobs = ObsGR$Qobs[SimInd], transfo = transfo)
MOD_crt <- CreateInputsCrit(FUN_CRIT = FUN_CRIT, InputsModel = PrepGR$InputsModel,
RunOptions = MOD_opt, Qobs = PrepGR$Qobs[SimInd], transfo = transfo)
SIM <- RunModel(InputsModel = ObsGR$InputsModel, RunOptions = MOD_opt,
Param = Param, FUN_MOD = get(ObsGR$TypeModel))
SIM <- RunModel(InputsModel = PrepGR$InputsModel, RunOptions = MOD_opt,
Param = Param, FUN_MOD = get(PrepGR$TypeModel))
CRT <- ErrorCrit(InputsCrit = MOD_crt, OutputsModel = SIM, FUN_CRIT = FUN_CRIT, verbose = verbose)
SimGR <- list(OptionsSimul = MOD_opt, OptionsCrit = MOD_crt, OutputsModel = SIM, Qobs = ObsGR$Qobs[SimInd],
TypeModel = ObsGR$TypeModel,
SimGR <- list(OptionsSimul = MOD_opt, OptionsCrit = MOD_crt, OutputsModel = SIM, Qobs = PrepGR$Qobs[SimInd],
TypeModel = PrepGR$TypeModel,
CalCrit = CalGR$CalCrit, EffCrit = CRT,
PeriodModel = list(WarmUp = as.POSIXct(ObsGR$InputsModel$DatesR[range(MOD_opt$IndPeriod_WarmUp)]),
PeriodModel = list(WarmUp = as.POSIXct(PrepGR$InputsModel$DatesR[range(MOD_opt$IndPeriod_WarmUp)]),
Run = SimPer))
class(SimGR) <- c("SimGR", "GR")
return(SimGR)
......
......@@ -34,7 +34,7 @@ if (getRversion() >= "2.15.1") {
if (!is.list(x)) {
x <- list(TypeModel = x)
}
if (any(class(x) %in% c("ObsGR", "CalGR", "SimGR")) || names(x) %in% "TypeModel") {
if (any(class(x) %in% c("PrepGR", "CalGR", "SimGR")) || names(x) %in% "TypeModel") {
x <- x$TypeModel
}
......
dyplot.ObsGR <- function(x, ...) {
dyplot.PrepGR <- function(x, ...) {
if (! any(class(x) %in% "ObsGR")) {
stop("Non convenient data for x argument. Must be of class \"ObsGR\"")
if (! any(class(x) %in% "PrepGR")) {
stop("Non convenient data for x argument. Must be of class \"PrepGR\"")
}
dyplot.default(x, ...)
......
......@@ -7,8 +7,8 @@ dyplot.default <- function(x, Qsup = NULL, Qsup.name = "Qsup",
# barChartPrecip <- scan(file = system.file("plugins/barChartPrecip.js", package = "airGRteaching"),
# what = "character", quiet = TRUE)
if (! any(class(x) %in% c("ObsGR", "CalGR", "SimGR"))) {
stop("Non convenient data for x argument. Must be of class \"ObsGR\", \"CalGR\" or \"SimGR\"")
if (! any(class(x) %in% c("PrepGR", "CalGR", "SimGR"))) {
stop("Non convenient data for x argument. Must be of class \"PrepGR\", \"CalGR\" or \"SimGR\"")
}
if (is.null(xlab)) {
......@@ -37,7 +37,7 @@ dyplot.default <- function(x, Qsup = NULL, Qsup.name = "Qsup",
}
if (any(class(x) %in% "ObsGR")) {
if (any(class(x) %in% "PrepGR")) {
data <- data.frame(DatesR = x$InputsModel$DatesR,
Precip = x$InputsModel$Precip,
Qobs = x$Qobs,
......
plot.ObsGR <- function(x, type = "l", col.Precip = "royalblue", col.Q = "black", col.na = "grey",
plot.PrepGR <- function(x, type = "l", col.Precip = "royalblue", col.Q = "black", col.na = "grey",
xlab = NULL, ylab = NULL, main = NULL, plot.na = TRUE, ...) {
if (! any(class(x) %in% "ObsGR")) {
stop("Non convenient data for x argument. Must be of class \"ObsGR\"")
if (! any(class(x) %in% "PrepGR")) {
stop("Non convenient data for x argument. Must be of class \"PrepGR\"")
}
if (is.null(xlab)) {
......
......@@ -33,7 +33,7 @@ shinyServer(function(input, output, session) {
# ObsBV <- get(input$Dataset)
ObsBV <- .ShinyGR.args$ObsBV[[input$Dataset]]
}
OBS <- ObsGR(ObsBV = ObsBV,
PREP <- PrepGR(ObsBV = ObsBV,
DatesR = .ShinyGR.args$DatesR,
Precip = .ShinyGR.args$Precip, PotEvap = .ShinyGR.args$PotEvap,
Qobs = .ShinyGR.args$Qobs, TempMean = .ShinyGR.args$TempMean,
......@@ -43,13 +43,13 @@ shinyServer(function(input, output, session) {
HydroModel = input$HydroModel,
CemaNeige = input$SnowModel == "CemaNeige")
WUPPER <- c(OBS$InputsModel$DatesR[1L], input$Period[1]-.TypeModelGR(OBS)$TimeLag)
WUPPER <- c(PREP$InputsModel$DatesR[1L], input$Period[1]-.TypeModelGR(PREP)$TimeLag)
if (WUPPER[2] < WUPPER[1]) {
WUPPER[2] <- WUPPER[1]
}
## Enable or disable automatic calibration (if there is Qobs or not)
isQobs <- !all(is.na(OBS$Qobs[OBS$InputsModel$Dates >= input$Period[1] & OBS$InputsModel$Dates <= input$Period[2]]))
isQobs <- !all(is.na(PREP$Qobs[PREP$InputsModel$Dates >= input$Period[1] & PREP$InputsModel$Dates <= input$Period[2]]))
if (isQobs | input$Period[1L] != input$Period[2L]) {
shinyjs::enable("CalButton")
}
......@@ -57,7 +57,7 @@ shinyServer(function(input, output, session) {
shinyjs::disable("CalButton")
}
return(list(TMGR = TMGR, OBS = OBS, WUPPER = WUPPER))
return(list(TMGR = TMGR, PREP = PREP, WUPPER = WUPPER))
})
......@@ -79,7 +79,7 @@ shinyServer(function(input, output, session) {
## Model calibration
CAL_opt <- list(Crit = gsub(" .*", "", input$TypeCrit),
Transfo = gsub("1", "inv", gsub("(\\D{3} \\[)(\\w{0,4})(\\W*Q\\W*\\])", "\\2", input$TypeCrit)))
CAL <- CalGR(ObsGR = getPrep()$OBS, CalCrit = CAL_opt$Crit, transfo = CAL_opt$Transfo,
CAL <- CalGR(PrepGR = getPrep()$PREP, CalCrit = CAL_opt$Crit, transfo = CAL_opt$Transfo,
WupPer = substr(getPrep()$WUPPER, 1, 10),
CalPer = substr(c(input$Period[1], input$Period[2]), 1, 10), verbose = FALSE)
PARAM <- CAL$OutputsCalib$ParamFinalR
......@@ -159,7 +159,7 @@ shinyServer(function(input, output, session) {
## Simulated flows computation
SIM <- SimGR(ObsGR = getPrep()$OBS, Param = PARAM,
SIM <- SimGR(PrepGR = getPrep()$PREP, Param = PARAM,
WupPer = substr(getPrep()$WUPPER, 1, 10),
SimPer = substr(c(input$Period[1], input$Period[2]), 1, 10), #substr(c(zzz1, zzz2), 1, 10), #
verbose = FALSE)
......@@ -208,9 +208,9 @@ shinyServer(function(input, output, session) {
isEqualTypeModel <- .GlobalEnv$.ShinyGR.hist[[1]]$TypeModel == .GlobalEnv$.ShinyGR.hist[[2]]$TypeModel
if (length(.GlobalEnv$.ShinyGR.hist[[1]]$Qsim) != length(.GlobalEnv$.ShinyGR.hist[[2]]$Qsim) |
(isEqualSumQsim & isEqualTypeModel)) {
OBSold <- getPrep()$OBS
OBSold <- getPrep()$PREP
OBSold$TypeModel <- .GlobalEnv$.ShinyGR.hist[[1]]$TypeModel
if (.TypeModelGR(OBSold)$CemaNeige & !.TypeModelGR(getPrep()$OBS)$CemaNeige | # present: No CemaNeige ; old: CemaNeige
if (.TypeModelGR(OBSold)$CemaNeige & !.TypeModelGR(getPrep()$PREP)$CemaNeige | # present: No CemaNeige ; old: CemaNeige
isEqualSumQsim & isEqualTypeModel) {
if (input$Dataset == "Unnamed watershed") {
ObsBV <- NULL
......@@ -218,7 +218,7 @@ shinyServer(function(input, output, session) {
# ObsBV <- get(input$Dataset)
ObsBV <- .ShinyGR.args$ObsBV[[input$Dataset]]
}
OBSold <- ObsGR(ObsBV = ObsBV,
OBSold <- PrepGR(ObsBV = ObsBV,
Precip = .ShinyGR.args$Precip, PotEvap = .ShinyGR.args$PotEvap,
Qobs = .ShinyGR.args$Qobs, TempMean = .ShinyGR.args$TempMean,
ZInputs = .ShinyGR.args$ZInputs[[input$Dataset]],
......@@ -227,7 +227,7 @@ shinyServer(function(input, output, session) {
HydroModel = input$HydroModel,
CemaNeige = input$SnowModel == "CemaNeige")
}
SIMold <- SimGR(ObsGR = OBSold,
SIMold <- SimGR(PrepGR = OBSold,
Param = .GlobalEnv$.ShinyGR.hist[[1]]$Param,
WupPer = substr(getPrep()$WUPPER, 1, 10),
SimPer = substr(c(input$Period[1], input$Period[2]), 1, 10),
......@@ -739,21 +739,21 @@ shinyServer(function(input, output, session) {
filename <- sprintf("airGR_%s_%s.csv", filename, gsub("(.*)( )(\\d{2})(:)(\\d{2})(:)(\\d{2})", "\\1_\\3h\\5m\\7s", Sys.time()))
},
content = function(file) {
OBS <- getPrep()$OBS
PREP <- getPrep()$PREP
SIM <- getSim()$SIM
if (input$SnowModel != "CemaNeige") {
PrecipSim <- NA
FracSolid <- NA
TempMean <- NA
} else {
PrecipSol <- rowMeans(as.data.frame(OBS$InputsModel$LayerPrecip) * as.data.frame(OBS$InputsModel$LayerFracSolidPrecip), na.rm = TRUE)
PrecipSim <- rowMeans(as.data.frame(OBS$InputsModel$LayerPrecip), na.rm = TRUE)
PrecipSol <- rowMeans(as.data.frame(PREP$InputsModel$LayerPrecip) * as.data.frame(PREP$InputsModel$LayerFracSolidPrecip), na.rm = TRUE)
PrecipSim <- rowMeans(as.data.frame(PREP$InputsModel$LayerPrecip), na.rm = TRUE)
FracSolid <- PrecipSol / PrecipSim
FracSolid <- ifelse(is.na(FracSolid) & PrecipSol == 0 & PrecipSim == 0, 0, FracSolid)
PrecipSim <- PrecipSim[SIM$OptionsSimul$IndPeriod_Run]
FracSolid <- FracSolid[SIM$OptionsSimul$IndPeriod_Run]
FracSolid <- round(FracSolid, digits = 3)
TempMean <- rowMeans(as.data.frame(OBS$InputsModel$LayerTempMean), na.rm = TRUE)
TempMean <- rowMeans(as.data.frame(PREP$InputsModel$LayerTempMean), na.rm = TRUE)
TempMean <- TempMean[SIM$OptionsSimul$IndPeriod_Run]
}
TabSim <- data.frame(Dates = SIM$OutputsModel$DatesR,
......@@ -766,7 +766,7 @@ shinyServer(function(input, output, session) {
Qsim = SIM$OutputsModel$Qsim)
colnames(TabSim) <- sprintf("%s [%s]", colnames(TabSim), c("-", rep("mm",3), "-", "°C", rep("mm", 2)))
colnames(TabSim) <- ifelse(grepl("mm", colnames(TabSim)),
gsub("mm", paste0("mm/", .TypeModelGR(OBS)$TimeUnit),colnames(TabSim)),
gsub("mm", paste0("mm/", .TypeModelGR(PREP)$TimeUnit),colnames(TabSim)),
colnames(TabSim))
write.table(TabSim, file = file, row.names = FALSE, sep = ";")
}
......
......@@ -59,7 +59,7 @@ 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 `ObsGR()` function. You have to define:
For this step, you just have to use the `PrepGR()` function. You have to define:
* `ObsBV`: `data.frame` of hydrometeorological observations time series
* `HydroModel`: the name of the hydrological model you want to run (GR1A, GR2M, GR4J, GR5J, GR6J or GR4H)
......@@ -72,7 +72,7 @@ If you want to use CemaNeige, you also have to define:
* `NLayers`: the number of elevation layers requested [-]
```{r, echo=TRUE, eval=TRUE}
OBS <- ObsGR(ObsBV = BasinObs, HydroModel = "GR5J", CemaNeige = FALSE)
PREP <- PrepGR(ObsBV = BasinObs, HydroModel = "GR5J", CemaNeige = FALSE)
```
<br>
......@@ -81,7 +81,7 @@ OBS <- ObsGR(ObsBV = 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:
* `ObsGR`: the object returned by the `ObsGR()` function
* `PrepGR`: the object returned by the `PrepGR()` function
* `CalPer`: a vector of 2 dates to define the calibration period
......@@ -93,7 +93,7 @@ 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) .
```{r, warning=FALSE}
CAL <- CalGR(ObsGR = OBS, CalCrit = "KGE",
CAL <- CalGR(PrepGR = PREP, CalCrit = "KGE",
WupPer = NULL, CalPer = c("1990-01-01", "1993-12-31"))
```
......@@ -101,10 +101,10 @@ CAL <- CalGR(ObsGR = OBS, CalCrit = "KGE",
#### Simulation step
The `ObsGR` and `WupPer` arguments 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 `CalGR` is the object returned by the `CalGR()` function.
The `PrepGR` and `WupPer` arguments 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 `CalGR` is the object returned by the `CalGR()` function.
```{r, warning=FALSE}
SIM <- SimGR(ObsGR = OBS, CalGR = CAL, EffCrit = "KGE2",
SIM <- SimGR(PrepGR = PREP, CalGR = CAL, EffCrit = "KGE2",
WupPer = NULL, SimPer = c("1994-01-01", "1998-12-31"))
```
......@@ -114,11 +114,11 @@ SIM <- SimGR(ObsGR = OBS, CalGR = CAL, EffCrit = "KGE2",
#### Static plots
The call of the `plot()` function with an `ObsGR` object draws the observed precipitation and discharge time series.
The call of the `plot()` function with an `PrepGR` object draws the observed precipitation and discharge time series.
```{r, echo=-1}
par(cex.lab = 0.6, cex.axis = 0.6)
plot(OBS, main = "Observation")
plot(PREP, main = "Observation")
```
......@@ -155,7 +155,7 @@ plot(SIM)
Dynamic plots, using the *dygraphs* JavaScript charting library, can be displayed by the package.
The `dyplot()` function can be applied on `ObsGR`, `CalGR` and `SimGR` objects and draws the time series of the observed precipitation, and the observed and simulated (except with `ObsGR` objects) flows.
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.
......@@ -181,7 +181,7 @@ The `ShinyGR()` function just needs:
By default, the objective function used is the Kling-Gupta criterion (KGE), and the warm-up period is automatically set (depending on model). You have to define:
* `ObsGR`: the object returned by the `ObsGR()` function
* `PrepGR`: the object returned by the `PrepGR()` function
* `CalPer`: a vector of 2 dates to define the calibration period
......
......@@ -5,14 +5,14 @@
\usage{
CalGR(ObsGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
CalGR(PrepGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
WupPer = NULL, CalPer,
transfo = c("", "sqrt", "log", "inv", "sort"), verbose = TRUE)
}
\arguments{
\item{ObsGR}{[object of class \code{ObsGR}] see \code{\link{ObsGR}} for details}
\item{PrepGR}{[object of class \code{PrepGR}] see \code{\link{PrepGR}} for details}
\item{CalCrit}{[character] name of the objective function (must be one of \code{"NSE"}, \code{"KGE"}, \code{"KGE2"} or \code{"RMSE"})}
......@@ -57,10 +57,10 @@ data(L0123001)
BasinObs2 <- BasinObs[, c("DatesR", "P", "E", "Qmm", "T")]
## Preparation of observed data for modelling
OBS <- ObsGR(ObsBV = BasinObs2, HydroModel = "GR4J", CemaNeige = TRUE)
PREP <- PrepGR(ObsBV = BasinObs2, HydroModel = "GR4J", CemaNeige = TRUE)
## Calibration step
CAL <- CalGR(ObsGR = OBS, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
CAL <- CalGR(PrepGR = PREP, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
WupPer = NULL, CalPer = c("1990-01-01", "1993-12-31"))
str(CAL)
}
......
\encoding{UTF-8}
\name{ObsGR}
\alias{ObsGR}
\name{PrepGR}
\alias{PrepGR}
\title{Creation of the inputs required to run the CalGR and SimGR functions}
\usage{
ObsGR(ObsBV = NULL, DatesR = NULL, Precip = NULL, PotEvap = NULL,
PrepGR(ObsBV = NULL, DatesR = NULL, Precip = NULL, PotEvap = NULL,
Qobs = NULL, TempMean = NULL,
ZInputs = NULL, HypsoData = NULL, NLayers = 5,
HydroModel, CemaNeige = FALSE)
......@@ -38,7 +38,7 @@ ObsGR(ObsBV = NULL, DatesR = NULL, Precip = NULL, PotEvap = NULL,
\value{
[list] object of class \code{ObsGR} containing the data required to evaluate the model outputs:
[list] object of class \code{PrepGR} containing the data required to evaluate the model outputs:
\item{InputsModel}{[list] object of class \emph{InputsModel} containing the data required to evaluate the model outputs (see: \code{\link{CreateInputsModel}} outputs)}
\item{Qobs}{[numeric] time series of observed discharges [mm/time step]}
\item{HydroModel}{[character] name of the function of the hydrological model used}
......@@ -67,7 +67,7 @@ data(L0123001)
BasinObs2 <- BasinObs[, c("DatesR", "P", "E", "Qmm", "T")]
## Preparation of observed data for modelling
OBS <- ObsGR(ObsBV = BasinObs2, HydroModel = "GR4J", CemaNeige = FALSE)
str(OBS)
PREP <- PrepGR(ObsBV = BasinObs2, HydroModel = "GR4J", CemaNeige = FALSE)
str(PREP)
}
......@@ -5,14 +5,14 @@
\usage{
SimGR(ObsGR, CalGR = NULL, Param = NULL, EffCrit = c("NSE", "KGE", "KGE2", "RMSE"),
SimGR(PrepGR, CalGR = NULL, Param = NULL, EffCrit = c("NSE", "KGE", "KGE2", "RMSE"),
WupPer = NULL, SimPer,
transfo = c("", "sqrt", "log", "inv", "sort"), verbose = TRUE)
}
\arguments{
\item{ObsGR}{[object of class \emph{ObsGR}] see \code{\link{ObsGR}} for details}
\item{PrepGR}{[object of class \emph{PrepGR}] see \code{\link{PrepGR}} for details}
\item{CalGR}{(optional) [object of class \emph{CalGR}] see \code{\link{CalGR}} and below for details}
......@@ -67,18 +67,18 @@ data(L0123001)
BasinObs2 <- BasinObs[, c("DatesR", "P", "E", "Qmm", "T")]
## Preparation of observed data for modelling
OBS <- ObsGR(ObsBV = BasinObs2, HydroModel = "GR4J", CemaNeige = FALSE)
PREP <- PrepGR(ObsBV = BasinObs2, HydroModel = "GR4J", CemaNeige = FALSE)
## Calibration step
CAL <- CalGR(ObsGR = OBS, CalCrit = "KGE2",
CAL <- CalGR(PrepGR = PREP, CalCrit = "KGE2",
WupPer = NULL, CalPer = c("1990-01-01", "1993-12-31"))
## Simulation step using the result of the automatic calibration method to set the model parameters
SIM <- SimGR(ObsGR = OBS, CalGR = CAL, EffCrit = "KGE2",
SIM <- SimGR(PrepGR = PREP, CalGR = CAL, EffCrit = "KGE2",
WupPer = NULL, SimPer = c("1994-01-01", "1998-12-31"))
## Simulation step using model parameters set by the user
SIM <- SimGR(ObsGR = OBS, Param = c(270.426, 0.984, 108.853, 2.149), EffCrit = "KGE2",
SIM <- SimGR(PrepGR = PREP, Param = c(270.426, 0.984, 108.853, 2.149), EffCrit = "KGE2",
WupPer = NULL, SimPer = c("1994-01-01", "1998-12-31"))
str(SIM)