Commit 94f6284d authored by Dorchies David's avatar Dorchies David
Browse files

feat: add check for negative observed flow in catchment

Refs #55
parent b7192087
Pipeline #33203 passed with stage
in 6 minutes and 51 seconds
......@@ -92,6 +92,11 @@ CreateInputsModel.GRiwrm <- function(x, DatesR,
for(id in getNodeRanking(x)) {
message("CreateInputsModel.GRiwrm: Treating sub-basin ", id, "...")
if (x$area[x$id == id] > 0 && any(Qobs[, id] < 0, na.rm = TRUE)) {
stop(sprintf("Negative flow found in 'Qobs[, \"%s\"]'. ", id),
"Catchment flow can't be negative, use `NA` for flow data gaps.")
}
InputsModel[[id]] <-
CreateOneGRiwrmInputsModel(id = id,
griwrm = x,
......
......@@ -159,3 +159,26 @@ test_that("must works with node not related to an hydrological model", {
expect_equal(colnames(IM[[2]]$Qupstream), c("Up1", "Up2"))
})
test_that("negative observed flow on catchment should throw error", {
l$Qobs[100, 1] <- -99
expect_error(CreateInputsModel(l$griwrm,
DatesR = l$DatesR,
Precip = l$Precip,
PotEvap = l$PotEvap,
Qobs = l$Qobs),
regexp = "Negative flow found")
l$griwrm$model[1] <- NA
expect_s3_class(suppressWarnings(
CreateInputsModel(
l$griwrm,
DatesR = l$DatesR,
Precip = l$Precip,
PotEvap = l$PotEvap,
Qobs = l$Qobs,
TempMean = l$TempMean,
ZInputs = l$ZInputs,
HypsoData = l$HypsoData
)
),
"GRiwrmInputsModel")
})
Markdown is supported
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