Commit e47cc8e2 authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

Merge branch...

Merge branch '52-change-the-default-configuration-of-the-wupper-argument-simgr-and-calgr-functions' into 'dev'

Resolve "Change the default configuration of the "WupPer" argument (SimGR and CalGR functions)"

Closes #52

See merge request !33
2 merge requests!45Merge branch 'dev' into 'master',!33Resolve "Change the default configuration of the "WupPer" argument (SimGR and CalGR functions)"
Pipeline #38251 passed with stage
in 5 minutes and 54 seconds
Showing with 56 additions and 30 deletions
+56 -30
......@@ -7,7 +7,7 @@ Authors@R: c(
person("Olivier", "Delaigue", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7668-8468"), email = "airGR@inrae.fr"),
person("Laurent", "Coron", role = c("aut"), comment = c(ORCID = "0000-0002-1503-6204")),
person("Pierre", "Brigode", role = c("aut"), comment = c(ORCID = "0000-0001-8257-0741")),
person("Guillaume", "Thirel", role = c("ctb"), comment = c(ORCID = "0000-0002-1444-1830"))
person("Guillaume", "Thirel", role = c("aut"), comment = c(ORCID = "0000-0002-1444-1830"))
)
Depends:
R (>= 3.6.0),
......
......@@ -23,18 +23,22 @@ CalGR <- function(PrepGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
WupInd <- NULL
if (!is.null(WupPer)) {
WupPer <- as.POSIXct(WupPer, tz = "UTC")
if (length(WupPer) != 2) {
stop("Warm-up period \"WupPer\" must be of length 2")
}
if (any(is.na(WupPer))) {
stop("Non convenient date format for the warm-up period \"WupPer\"")
} else {
if (!any(PrepGR$InputsModel$DatesR == WupPer[1]) | !any(PrepGR$InputsModel$DatesR == WupPer[2])) {
stop("Non convenient date for the warm-up period \"WupPer\"")
if (!identical(WupPer, 0L)){
WupPer <- as.POSIXct(WupPer, tz = "UTC")
if (length(WupPer) != 2) {
stop("Warm-up period \"WupPer\" must be of length 2")
}
if (any(is.na(WupPer))) {
stop("Non convenient date format for the warm-up period \"WupPer\"")
} else {
WupInd <- which(PrepGR$InputsModel$DatesR == WupPer[1]):which(PrepGR$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(PrepGR$InputsModel$DatesR == WupPer[1]):which(PrepGR$InputsModel$DatesR == WupPer[2])
}
}
} else {
WupInd <- 0L
}
}
......@@ -55,7 +59,7 @@ CalGR <- function(PrepGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
MOD_opt <- CreateRunOptions(FUN_MOD = get(PrepGR$TypeModel), InputsModel = PrepGR$InputsModel,
IndPeriod_WarmUp = WupInd, IndPeriod_Run = CalInd, verbose = FALSE)
IndPeriod_WarmUp = WupInd, IndPeriod_Run = CalInd, verbose = TRUE)
MOD_crt <- CreateInputsCrit(FUN_CRIT = FUN_CRIT, InputsModel = PrepGR$InputsModel,
......
......@@ -39,18 +39,22 @@ SimGR <- function(PrepGR, CalGR = NULL, Param, EffCrit = c("NSE", "KGE", "KGE2",
WupInd <- NULL
if (!is.null(WupPer)) {
WupPer <- as.POSIXct(WupPer, tz = "UTC")
if (length(WupPer) != 2) {
stop("Warm-up period \"WupPer\" must be of length 2")
}
if (any(is.na(WupPer))) {
stop("Non convenient date format for the warm-up period \"WupPer\"")
} else {
if (!any(PrepGR$InputsModel$DatesR == WupPer[1]) | !any(PrepGR$InputsModel$DatesR == WupPer[2])) {
stop("Non convenient date for the warm-up period \"WupPer\"")
if (!identical(WupPer, 0L)){
WupPer <- as.POSIXct(WupPer, tz = "UTC")
if (length(WupPer) != 2) {
stop("Warm-up period \"WupPer\" must be of length 2")
}
if (any(is.na(WupPer))) {
stop("Non convenient date format for the warm-up period \"WupPer\"")
} else {
WupInd <- which(PrepGR$InputsModel$DatesR == WupPer[1]):which(PrepGR$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(PrepGR$InputsModel$DatesR == WupPer[1]):which(PrepGR$InputsModel$DatesR == WupPer[2])
}
}
} else {
WupInd <- 0L
}
}
......
......@@ -21,7 +21,7 @@ CalGR(PrepGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"),
\item{CalCrit}{[character] name of the objective function (must be one of \code{"NSE"}, \code{"KGE"}, \code{"KGE2"} or \code{"RMSE"})}
\item{WupPer}{(optional) [character] vector of 2 values to define the beginning and end of the warm-up period [\code{"YYYY-mm-dd"} or \code{"YYYY-mm-dd HH:MM:SS"}]. See details}
\item{WupPer}{(optional) [character] vector of 2 values to define the beginning and end of the warm-up period [\code{"YYYY-mm-dd"} or \code{"YYYY-mm-dd HH:MM:SS"}]; [0L] to disable the warm-up period. See details}
\item{CalPer}{[character] vector of 2 values to define the beginning and end of the calibration period [\code{"YYYY-mm-dd"} or \code{"YYYY-mm-dd HH:MM:SS"}]}
......@@ -53,11 +53,13 @@ airGR
functions
}
\details{
\code{WupPer = NULL} indicates that, if available, a period of one year immediately present before the \code{CalPer} period is used. In order to disable the warm up of the model, users have to make sure not to provide data before \code{CalPer} when preparing the data with \code{\link{PrepGR}}.
\code{WupPer = NULL} indicates that, if available, a period of one year immediately present before the CalPer period is used. \code{WupPer = 0L} allows to disable the warm up of the model.
}
\author{Olivier Delaigue}
\author{Olivier Delaigue, Guillaume Thirel}
\examples{
......
......@@ -25,7 +25,7 @@ SimGR(PrepGR, CalGR = NULL, Param, EffCrit = c("NSE", "KGE", "KGE2", "RMSE"),
\item{EffCrit}{[character] name of the efficiency criterion (must be one of \code{"NSE"}, \code{"KGE"}, \code{"KGE2"} or \code{"RMSE"})}
\item{WupPer}{(optional) [character] vector of 2 values to define the beginning and end of the warm-up period [\code{"YYYY-mm-dd"} or \code{"YYYY-mm-dd HH:MM:SS"}]}
\item{WupPer}{(optional) [character] vector of 2 values to define the beginning and end of the warm-up period [\code{"YYYY-mm-dd"} or \code{"YYYY-mm-dd HH:MM:SS"}]; [0L] to disable the warm-up period. See details}
\item{SimPer}{[character] vector of 2 values to define the beginning and end of the simulation period [\code{"YYYY-mm-dd"} or \code{"YYYY-mm-dd HH:MM:SS"}]}
......@@ -63,9 +63,12 @@ functions
\details{
The user can customize the parameters with the \code{Param} argument.
The user can also use the parameters resulting from a calibration. In this case, it is necessary to use the \code{\link{CalGR}} function.
\cr\cr
\code{WupPer = NULL} indicates that, if available, a period of one year immediately present before the CalPer period is used. \code{WupPer = 0L} allows to disable the warm up of the model.
}
\author{Olivier Delaigue}
\author{Olivier Delaigue, Guillaume Thirel}
\examples{
......
......@@ -4,10 +4,12 @@ context("SimGR")
data(L0123001, package = "airGR")
BasinObsSubNA <- BasinObs[, c("DatesR", "P", "E", "Qmm", "T")]
BasinObsUsual <- BasinObs[, c("DatesR", "P", "E", "Qmm", "T")]
BasinObsSubNA <- BasinObsUsual
BasinObsSubNA[BasinObsSubNA$DatesR >= "1994-01-01", ]$Qmm <- NA
BasinObsTotNA <- BasinObsSubNA[BasinObsSubNA$DatesR >= "1994-01-01", ]
PrepUsual <- PrepGR(ObsDF = BasinObsUsual, HydroModel = "GR4J", CemaNeige = FALSE)
PrepSubNA <- PrepGR(ObsDF = BasinObsSubNA, HydroModel = "GR4J", CemaNeige = FALSE)
PrepTotNA <- PrepGR(ObsDF = BasinObsTotNA, HydroModel = "GR4J", CemaNeige = FALSE)
......@@ -18,7 +20,7 @@ test_that("NA on a sub-period", {
object = SimGR(PrepGR = PrepSubNA, Param = c(270.426, 0.984, 108.853, 2.149), EffCrit = "KGE2",
WupPer = c("1994-01-01", "1994-12-31"), SimPer = c("1995-01-01", "1998-12-31"))
,
expected = "\"PrepGR\" does not contain any Qobs values on \"SimPer\". The efficiency criterion is not computed",
regexp = "\"PrepGR\" does not contain any Qobs values on \"SimPer\". The efficiency criterion is not computed",
)
})
......@@ -29,6 +31,17 @@ test_that("NA on the total period", {
object = SimGR(PrepGR = PrepTotNA, Param = c(270.426, 0.984, 108.853, 2.149), EffCrit = "KGE2",
WupPer = c("1994-01-01", "1994-12-31"), SimPer = c("1995-01-01", "1998-12-31"))
,
expected = "\"PrepGR\" does not contain any Qobs values. The efficiency criterion is not computed",
regexp = "\"PrepGR\" does not contain any Qobs values. The efficiency criterion is not computed",
)
})
# ----
test_that("Diasle warm-up period", {
expect_message(
object = SimGR(PrepGR = PrepUsual, Param = c(270.426, 0.984, 108.853, 2.149), EffCrit = "KGE2",
WupPer = 0L, SimPer = c("1995-01-01", "1998-12-31"))
,
regexp = "No warm up period is used",
)
})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment