From 1bba5078814bd930bf9caa5ee4766f282c134174 Mon Sep 17 00:00:00 2001 From: David <david.dorchies@inrae.fr> Date: Sat, 30 Mar 2024 16:29:32 +0100 Subject: [PATCH] fix(Qover): case with is.na(Qsim) Refs #144 --- R/RunModel.InputsModel.R | 6 +++--- man/RunModel.InputsModel.Rd | 4 +++- tests/testthat/test-RunModel.R | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/R/RunModel.InputsModel.R b/R/RunModel.InputsModel.R index 538c18c..952ae00 100644 --- a/R/RunModel.InputsModel.R +++ b/R/RunModel.InputsModel.R @@ -161,10 +161,10 @@ calcOverAbstraction <- function(O, WarmUp) { f <- lapply(f, function(x) paste0("WarmUp", x)) } if (!is.null(O[[f$sim]])) { - if (any(O[[f$sim]] < 0)) { + if (any(!is.na(O[[f$sim]]) & O[[f$sim]] < 0)) { O[[f$over]] <- rep(0, length(O[[f$sim]])) - O[[f$over]][O[[f$sim]] < 0] <- - O[[f$sim]][O[[f$sim]] < 0] - O[[f$sim]][O[[f$sim]] < 0] <- 0 + O[[f$over]][O[[f$sim]] < 0] <- - O[[f$sim]][!is.na(O[[f$sim]]) & O[[f$sim]] < 0] + O[[f$sim]][!is.na(O[[f$sim]]) & O[[f$sim]] < 0] <- 0 } } return(O) diff --git a/man/RunModel.InputsModel.Rd b/man/RunModel.InputsModel.Rd index f4afb51..32bec4a 100644 --- a/man/RunModel.InputsModel.Rd +++ b/man/RunModel.InputsModel.Rd @@ -35,6 +35,8 @@ is here completed by: \itemize{ \item an item \verb{$Qsim_m3} storing the simulated discharge series in m3/s \item an item \verb{$Qover_m3} storing the volumes of over abstraction which occurs -when \code{RunModel_Lag} warns for negative simulated flows. +when \code{RunModel_Lag} warns for negative simulated flows. The latter reflects the volume +that was planned to be drawn from the sub-basin but could not be drawn because +of the lack of water. } } diff --git a/tests/testthat/test-RunModel.R b/tests/testthat/test-RunModel.R index ba5055e..a4b24cc 100644 --- a/tests/testthat/test-RunModel.R +++ b/tests/testthat/test-RunModel.R @@ -257,7 +257,7 @@ test_that("RunModel should return water deficit (Qover_m3)", { ) g <- CreateGRiwrm(nodes) Qobs2 <- data.frame(P = rep(-2E6, length(DatesR))) - e <- setupRunModel(griwrm = g, runRunModel = TRUE, Qobs2 = Qobs2) + expect_warning(e <- setupRunModel(griwrm = g, runRunModel = TRUE, Qobs2 = Qobs2)) for(x in ls(e)) assign(x, get(x, e)) expect_false(any(OM_GriwrmInputs$`54001`$Qsim_m3 < 0)) expect_true(all(OM_GriwrmInputs$`54001`$Qover_m3 >= 0)) -- GitLab