From 78450ae3602ff1674158812ef0a7d06da82dcbaa Mon Sep 17 00:00:00 2001
From: Delaigue Olivier <olivier.delaigue@irstea.priv>
Date: Thu, 30 Aug 2018 09:57:08 +0200
Subject: [PATCH] v1.0.13.11 warning in ErrorCrit* functions when Qobs = 0 or
 Qsim = 0 and epsilon = NULL

---
 DESCRIPTION        | 2 +-
 NEWS.rmd           | 6 ++++--
 R/ErrorCrit_KGE.R  | 8 ++++++++
 R/ErrorCrit_KGE2.R | 8 ++++++++
 R/ErrorCrit_NSE.R  | 8 ++++++++
 R/ErrorCrit_RMSE.R | 8 ++++++++
 6 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/DESCRIPTION b/DESCRIPTION
index 738d6bd9..280392e8 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.0.13.10
+Version: 1.0.13.11
 Date: 2018-08-31
 Authors@R: c(
   person("Laurent", "Coron", role = c("aut", "trl"), comment = c(ORCID = "0000-0002-1503-6204")),
diff --git a/NEWS.rmd b/NEWS.rmd
index 2357128c..445d9305 100644
--- a/NEWS.rmd
+++ b/NEWS.rmd
@@ -14,7 +14,7 @@ output:
 
 
 
-### 1.0.13.10 Release Notes (2018-08-31) 
+### 1.0.13.11 Release Notes (2018-08-31) 
 
 
 #### Deprectated and defunct
@@ -34,7 +34,9 @@ output:
 
 - <code>CreateInputsCrit()</code> now returns an error when <code>epsilon</code is not positive.
 
-- <code>CreateInputsCrit()</code> now returns a warning message if the era zeroes values in <code>Qobs<$code> and <code>epsilon = NULL</code>.
+- <code>CreateInputsCrit()</code> now returns a warning message if there are zeroes values in <code>Qobs</code> and <code>epsilon = NULL</code>.
+
+- <code>ErrorCrit*()</code> functions now return a warning message if there are zeroes values in <code>Qobs</code> or  <code>Qsim</code> and <code>epsilon = NULL</code>.
 
 
 #### Minor user-visible changes
diff --git a/R/ErrorCrit_KGE.R b/R/ErrorCrit_KGE.R
index 048b529c..7f45bfef 100644
--- a/R/ErrorCrit_KGE.R
+++ b/R/ErrorCrit_KGE.R
@@ -42,6 +42,14 @@ ErrorCrit_KGE <- function(InputsCrit, OutputsModel, warnings = TRUE, verbose = T
     VarSim[!InputsCrit$BoolCrit] <- NA
     
     ##Data_transformation
+    if (InputsCrit$transfo %in% c("log", "inv") & is.null(InputsCrit$epsilon) & verbose) {
+      if (any(VarObs %in% 0)) {
+        warning("zeroes detected in Qobs: the corresponding time-steps will be exclude from the criteria computation if the epsilon agrument of 'CreateInputsCrit' = NULL")
+      }
+      if (any(VarSim %in% 0)) {
+        warning("zeroes detected in Qsim: the corresponding time-steps will be exclude from the criteria computation if the epsilon agrument of 'CreateInputsCrit' = NULL")
+      }  
+    }
     if ("epsilon" %in% names(InputsCrit) & !is.null(InputsCrit$epsilon)) {
       VarObs <- VarObs + InputsCrit$epsilon
       VarSim <- VarSim + InputsCrit$epsilon
diff --git a/R/ErrorCrit_KGE2.R b/R/ErrorCrit_KGE2.R
index ebc4a942..9de2e220 100644
--- a/R/ErrorCrit_KGE2.R
+++ b/R/ErrorCrit_KGE2.R
@@ -42,6 +42,14 @@ ErrorCrit_KGE2 <- function(InputsCrit, OutputsModel, warnings = TRUE, verbose =
     VarSim[!InputsCrit$BoolCrit] <- NA
     
     ##Data_transformation
+    if (InputsCrit$transfo %in% c("log", "inv") & is.null(InputsCrit$epsilon) & verbose) {
+      if (any(VarObs %in% 0)) {
+        warning("zeroes detected in Qobs: the corresponding time-steps will be exclude from the criteria computation if the epsilon agrument of 'CreateInputsCrit' = NULL")
+      }
+      if (any(VarSim %in% 0)) {
+        warning("zeroes detected in Qsim: the corresponding time-steps will be exclude from the criteria computation if the epsilon agrument of 'CreateInputsCrit' = NULL")
+      }  
+    }
     if ("epsilon" %in% names(InputsCrit) & !is.null(InputsCrit$epsilon)) {
       VarObs <- VarObs + InputsCrit$epsilon
       VarSim <- VarSim + InputsCrit$epsilon
diff --git a/R/ErrorCrit_NSE.R b/R/ErrorCrit_NSE.R
index 9fe2658b..36d7bbfc 100644
--- a/R/ErrorCrit_NSE.R
+++ b/R/ErrorCrit_NSE.R
@@ -42,6 +42,14 @@ ErrorCrit_NSE <- function(InputsCrit, OutputsModel, warnings = TRUE, verbose = T
     VarSim[!InputsCrit$BoolCrit] <- NA
     
     ##Data_transformation
+    if (InputsCrit$transfo %in% c("log", "inv") & is.null(InputsCrit$epsilon) & verbose) {
+      if (any(VarObs %in% 0)) {
+        warning("zeroes detected in Qobs: the corresponding time-steps will be exclude from the criteria computation if the epsilon agrument of 'CreateInputsCrit' = NULL")
+      }
+      if (any(VarSim %in% 0)) {
+        warning("zeroes detected in Qsim: the corresponding time-steps will be exclude from the criteria computation if the epsilon agrument of 'CreateInputsCrit' = NULL")
+      }  
+    }
     if ("epsilon" %in% names(InputsCrit) & !is.null(InputsCrit$epsilon)) {
       VarObs <- VarObs + InputsCrit$epsilon
       VarSim <- VarSim + InputsCrit$epsilon
diff --git a/R/ErrorCrit_RMSE.R b/R/ErrorCrit_RMSE.R
index aed56617..9ac0256c 100644
--- a/R/ErrorCrit_RMSE.R
+++ b/R/ErrorCrit_RMSE.R
@@ -42,6 +42,14 @@ ErrorCrit_RMSE <- function(InputsCrit, OutputsModel, warnings = TRUE, verbose =
     VarSim[!InputsCrit$BoolCrit] <- NA
     
     ##Data_transformation
+    if (InputsCrit$transfo %in% c("log", "inv") & is.null(InputsCrit$epsilon) & verbose) {
+      if (any(VarObs %in% 0)) {
+        warning("zeroes detected in Qobs: the corresponding time-steps will be exclude from the criteria computation if the epsilon agrument of 'CreateInputsCrit' = NULL")
+      }
+      if (any(VarSim %in% 0)) {
+        warning("zeroes detected in Qsim: the corresponding time-steps will be exclude from the criteria computation if the epsilon agrument of 'CreateInputsCrit' = NULL")
+      }  
+    }
     if ("epsilon" %in% names(InputsCrit) & !is.null(InputsCrit$epsilon)) {
       VarObs <- VarObs + InputsCrit$epsilon
       VarSim <- VarSim + InputsCrit$epsilon
-- 
GitLab