diff --git a/DESCRIPTION b/DESCRIPTION index 00dc32b19ee1aa493e46c0b8ecc8a87dc295566e..14ce1ab73a11638bb27e6a01270af58a6f61241b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: airGRteaching Type: Package Title: Teaching Hydrological Modelling with the GR Rainfall-Runoff Models ('Shiny' Interface Included) -Version: 0.2.8.14 +Version: 0.2.8.15 Date: 2020-02-07 Authors@R: c( person("Olivier", "Delaigue", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-7668-8468"), email = "airGR@inrae.fr"), diff --git a/NEWS.md b/NEWS.md index 7f37b7ae50fdeffa4ed6a53c1c3e2b3050632e28..273927216ede4d0ebb9d7941d1f7e49e276b89ee 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ -### 0.2.8.14 Release Notes (2020-02-07) +### 0.2.8.15 Release Notes (2020-02-07) #### New features diff --git a/R/CalGR.R b/R/CalGR.R index aa66785ce4a5e515aeee5b621826082fccd44c59..915492b6fae19800b4c932742b546e2c98244518 100644 --- a/R/CalGR.R +++ b/R/CalGR.R @@ -5,6 +5,11 @@ CalGR <- function(PrepGR, CalCrit = c("NSE", "KGE", "KGE2", "RMSE"), stop("Non convenient data for argument \"PrepGR\". Must be of class \"PrepGR\"") } + isQobs <- !all(is.na(PrepGR$Qobs)) + if (!isQobs) { + stop("\"PrepGR\" does not contain any Qobs values. It is not possible to calibrate the model") + } + WupInd <- NULL if (!is.null(WupPer)) { WupPer <- as.POSIXct(WupPer, tz = "UTC") diff --git a/R/PrepGR.R b/R/PrepGR.R index 08d9e8253fcf0cd0f85d69f7563208a8d807e529..52506ecc74f7f01d62ef5cd393a4fcc048c1dfa3 100644 --- a/R/PrepGR.R +++ b/R/PrepGR.R @@ -3,7 +3,7 @@ PrepGR <- function(ObsDF = NULL, DatesR = NULL, Precip = NULL, PotEvap = NULL, Q HydroModel, CemaNeige = FALSE) { - if (is.null(ObsDF) && (is.null(DatesR) | is.null(Precip) | is.null(PotEvap) | is.null(Qobs))) { + if (is.null(ObsDF) && (is.null(DatesR) | is.null(Precip) | is.null(PotEvap))) { stop("Missing input data") } @@ -13,6 +13,12 @@ PrepGR <- function(ObsDF = NULL, DatesR = NULL, Precip = NULL, PotEvap = NULL, Q } } + if (!is.null(Qobs)) { + Qobs <- Qobs + } else { + Qobs <- NA + } + if (!is.null(TempMean)) { TempMean <- TempMean } else { diff --git a/R/SimGR.R b/R/SimGR.R index a4fb3d8ef2ed7b7ad630b3a0c4666ed2d35a9057..f940b83022baa20bf422636610961b0f298c94f2 100644 --- a/R/SimGR.R +++ b/R/SimGR.R @@ -5,10 +5,14 @@ SimGR <- function(PrepGR, CalGR = NULL, Param, EffCrit = c("NSE", "KGE", "KGE2", stop("Non convenient data for argument \"PrepGR\". Must be of class \"PrepGR\"") } + isQobs <- !all(is.na(PrepGR$Qobs)) + if (!isQobs) { + warning("\"PrepGR\" does not contain any Qobs values. The efficiency criterion is not computed") + } + if (!missing(CalGR)) { warning("Deprecated \"CalGR\" argument. Use \"Param\" instead") } - ### to remove when the CalGR will be removed if (missing(Param)) { Param <- NULL @@ -19,12 +23,10 @@ SimGR <- function(PrepGR, CalGR = NULL, Param, EffCrit = c("NSE", "KGE", "KGE2", if (is.null(CalGR) & is.null(Param)) { stop("Arguments \"CalGR\" and \"Param\" are missing, with no default. You must fill in one of these two arguments") } - if (is.null(Param)) { Param <- CalGR$OutputsCalib$ParamFinalR } ### - if (inherits(Param, "CalGR")) { Param <- Param$OutputsCalib$ParamFinalR } @@ -72,22 +74,32 @@ SimGR <- function(PrepGR, CalGR = NULL, Param, EffCrit = c("NSE", "KGE", "KGE2", stop("Non convenient transformation \"transfo\"") } else { transfo <- transfo[1L] - } + } + + MOD_opt <- CreateRunOptions(FUN_MOD = get(PrepGR$TypeModel), InputsModel = PrepGR$InputsModel, IndPeriod_WarmUp = WupInd, IndPeriod_Run = SimInd, verbose = verbose) + if (isQobs) { MOD_crt <- CreateInputsCrit(FUN_CRIT = FUN_CRIT, InputsModel = PrepGR$InputsModel, - RunOptions = MOD_opt, Obs = PrepGR$Qobs[SimInd], transfo = transfo) + RunOptions = MOD_opt, Obs = PrepGR$Qobs[SimInd], transfo = transfo) + } else { + MOD_crt <- NULL + } SIM <- RunModel(InputsModel = PrepGR$InputsModel, RunOptions = MOD_opt, Param = Param, FUN_MOD = get(PrepGR$TypeModel)) - CRT <- ErrorCrit(InputsCrit = MOD_crt, OutputsModel = SIM, verbose = verbose) - + if (isQobs) { + CRT <- ErrorCrit(InputsCrit = MOD_crt, OutputsModel = SIM, verbose = verbose) + } else { + CRT <- NULL + } + SimGR <- list(OptionsSimul = MOD_opt, OptionsCrit = MOD_crt, OutputsModel = SIM, Qobs = PrepGR$Qobs[SimInd], TypeModel = PrepGR$TypeModel,