From a07ee63cdb154b92b06de3d5e248bbe688d9b925 Mon Sep 17 00:00:00 2001 From: Delaigue Olivier <olivier.delaigue@irstea.fr> Date: Mon, 11 Jan 2021 17:56:52 +0100 Subject: [PATCH] v1.6.9.13 refactor: change warning message returned by .ErrorCrit when a criterion is computed on few time-steps Refs #83 --- DESCRIPTION | 2 +- NEWS.md | 3 ++- R/UtilsErrorCrit.R | 51 ++++++++++++++++++---------------------------- 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f2f73b43..9e72edfc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: airGR Type: Package Title: Suite of GR Hydrological Models for Precipitation-Runoff Modelling -Version: 1.6.9.12 +Version: 1.6.9.13 Date: 2021-01-11 Authors@R: c( person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")), diff --git a/NEWS.md b/NEWS.md index 1f8b389a..5df64ca9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,7 @@ -### 1.6.9.12 Release Notes (2021-01-11) +### 1.6.9.13 Release Notes (2021-01-11) #### New features @@ -45,6 +45,7 @@ - `RunModel_GR1A()` now uses the Fortran version of the model code. This code is no longer duplicated: the R version which was used was removed. ([#65](https://gitlab.irstea.fr/HYCAR-Hydro/airgr/-/issues/65)) - Character argument verification now use partial matching in `PE_Oudin()` and `SeriesAggreg()` functions. ([#37](https://gitlab.irstea.fr/HYCAR-Hydro/airgr/-/issues/37)) - `RunModel_*()` funcions were cleaned up, with no effect on their outputs. ([#14](https://gitlab.irstea.fr/HYCAR-Hydro/airgr/-/issues/14)) +- `.ErrorCrit()` function now returns a warning message when a criterion computed on less than 10 time-steps (whatever the unit of the time step). ([#14](https://gitlab.irstea.fr/HYCAR-Hydro/airgr/-/issues/14)) #### Version control and issue tracking diff --git a/R/UtilsErrorCrit.R b/R/UtilsErrorCrit.R index d16a57e5..95ca18fc 100644 --- a/R/UtilsErrorCrit.R +++ b/R/UtilsErrorCrit.R @@ -3,7 +3,7 @@ ## ================================================================================= .ErrorCrit <- function(InputsCrit, Crit, OutputsModel, warnings) { - + ## Arguments check if (!inherits(InputsCrit, "InputsCrit")) { stop("'InputsCrit' must be of class 'InputsCrit'", call. = FALSE) @@ -15,8 +15,8 @@ stop(paste0("'InputsCrit' must be of class 'Single'. Use the 'ErrorCrit' function on objects of class 'Multi' or 'Compo' with ", Crit), call. = FALSE) } } - - + + ## Initialisation CritName <- NA CritVar <- InputsCrit$VarObs @@ -43,8 +43,8 @@ CritBestValue <- +1 Multiplier <- -1 } - - + + ## Data preparation VarObs <- InputsCrit$Obs VarObs[!InputsCrit$BoolCrit] <- NA @@ -58,8 +58,8 @@ VarSim <- rowMeans(sapply(OutputsModel$CemaNeigeLayers[InputsCrit$idLayer], FUN = "[[", "SnowPack")) } VarSim[!InputsCrit$BoolCrit] <- NA - - + + ## Data transformation if (InputsCrit$transfo %in% c("log", "inv") & is.null(InputsCrit$epsilon) & warnings) { if (any(VarObs %in% 0)) { @@ -67,7 +67,7 @@ } if (any(VarSim %in% 0)) { warning("zeroes detected in 'Qsim': the corresponding time-steps will be excluded from the criteria computation if the epsilon argument of 'CreateInputsCrit' = NULL", call. = FALSE) - } + } } if ("epsilon" %in% names(InputsCrit) & !is.null(InputsCrit$epsilon) & !(InputsCrit$transfo == "boxcox")) { VarObs <- VarObs + InputsCrit$epsilon @@ -102,44 +102,33 @@ VarObs <- VarObs^transfoPow VarSim <- VarSim^transfoPow } - - + + ## TS_ignore TS_ignore <- !is.finite(VarObs) | !is.finite(VarSim) | !InputsCrit$BoolCrit Ind_TS_ignore <- which(TS_ignore) if (length(Ind_TS_ignore) == 0) { Ind_TS_ignore <- NULL } - if (sum(!TS_ignore) == 0 | (sum(!TS_ignore) == 1 & Crit %in% c("KGE", "KGE2"))) { + if (sum(!TS_ignore) == 0 | (sum(!TS_ignore) == 1 & Crit %in% c("KGE", "KGE2"))) { CritCompute <- FALSE } else { CritCompute <- TRUE } - if (inherits(OutputsModel, "hourly")) { - WarningTS <- 365 - } - if (inherits(OutputsModel, "daily")) { - WarningTS <- 365 - } - if (inherits(OutputsModel, "monthly")) { - WarningTS <- 12 - } - if (inherits(OutputsModel, "yearly")) { - WarningTS <- 3 - } + WarningTS <- 10 if (sum(!TS_ignore) < WarningTS & warnings) { warning("\t criterion computed on less than ", WarningTS, " time-steps", call. = FALSE) } - - + + ## Outputs OutputsCritCheck <- list(WarningTS = WarningTS, - VarObs = VarObs, - VarSim = VarSim, - CritBestValue = CritBestValue, - Multiplier = Multiplier, - CritName = CritName, - CritVar = CritVar, + VarObs = VarObs, + VarSim = VarSim, + CritBestValue = CritBestValue, + Multiplier = Multiplier, + CritName = CritName, + CritVar = CritVar, CritCompute = CritCompute, TS_ignore = TS_ignore, Ind_TS_ignore = Ind_TS_ignore) -- GitLab