Commit 76f3921c authored by Dorchies David's avatar Dorchies David
Browse files

feat(CreateInputsCrit): force the use of transfo paramater with Lavenne criterion

Closes #56
parent e611fca1
Pipeline #26915 passed with stage
in 5 minutes and 46 seconds
......@@ -11,9 +11,8 @@ CreateInputsCrit.GRiwrmInputsModel <- function(InputsModel,
# We invoke the mandatory arguments here for avoiding
# a messy error message on "get(x)" if an argument is missing
InputsModel
RunOptions
Obs
# We also list all arguments in order to check arguments even in "..."
arguments <- c(as.list(environment()), list(...))
# Checking argument classes
lVars2Check <- list(InputsModel = "GRiwrmInputsModel",
......@@ -36,6 +35,12 @@ CreateInputsCrit.GRiwrmInputsModel <- function(InputsModel,
if (length(unique(names(AprioriIds))) != length(names(AprioriIds))) {
stop("Each name of AprioriIds items must be unique: duplicate entry detected")
}
if ("Weights" %in% names(arguments)) {
stop("Argument 'Weights' cannot be used when using Lavenne criterion")
}
if (!"transfo" %in% names(arguments)) {
stop("Argument 'transfo' must be defined when using Lavenne criterion (Using \"sqrt\" is recommended)")
}
lapply(names(AprioriIds), function(id) {
if (!id %in% names(InputsModel)) {
stop("'Each item of names(AprioriIds) must be an id of a simulated node:",
......
......@@ -37,7 +37,8 @@ test_that("Calibration with regularisation is OK", {
"54057" = "54032",
"54032" = "54001",
"54001" = "54095"
)
),
transfo = "sqrt"
)
OC <- Calibration(
......@@ -59,7 +60,7 @@ test_that("Calibration with regularisation is OK", {
InputsCrit[[id]],
OM[[id]]
)$CritValue,
0.9
0.89
)
})
})
......@@ -25,11 +25,33 @@ test_that("Wrong argument class should throw error", {
regexp = "matrix or data.frame")
})
test_that("De Lavenne criterion is OK", {
IC <- CreateInputsCrit(InputsModel = InputsModel,
RunOptions = RunOptions,
Obs = Qobs[IndPeriod_Run,],
AprioriIds = c("54057" = "54032", "54032" = "54001", "54001" = "54095"))
test_that("Using Lavenne criterion with 'weight' should throw error", {
expect_error(
CreateInputsCrit(InputsModel = InputsModel,
RunOptions = RunOptions,
Obs = Qobs[IndPeriod_Run,],
AprioriIds = c("54057" = "54032", "54032" = "54001", "54001" = "54095"),
Weights = c(0.85)),
regexp = "Lavenne"
)
})
test_that("Lavenne criterion without defining `transfo` should throw error", {
expect_error(CreateInputsCrit(InputsModel = InputsModel,
RunOptions = RunOptions,
Obs = Qobs[IndPeriod_Run,],
AprioriIds = c("54057" = "54032")),
regexp = "transfo")
})
AprioriIds <- c("54057" = "54032", "54032" = "54001", "54001" = "54095")
IC <- CreateInputsCrit(InputsModel = InputsModel,
RunOptions = RunOptions,
Obs = Qobs[IndPeriod_Run,],
AprioriIds = AprioriIds,
transfo = "sqrt")
test_that("Lavenne criterion is OK", {
expect_s3_class(IC[["54057"]], "InputsCritLavenneFunction")
Lavenne_FUN <- attr(IC[["54057"]], "Lavenne_FUN")
IC57 <- Lavenne_FUN(ParamMichel[["54032"]], 0.9)
......@@ -49,7 +71,8 @@ test_that("Lavenne criterion: wrong sub-catchment order should throw error", {
CreateInputsCrit(InputsModel = InputsModel,
RunOptions = RunOptions,
Obs = Qobs[IndPeriod_Run,],
AprioriIds = c("54057" = "54032", "54032" = "54001", "54001" = "54029")),
AprioriIds = c("54057" = "54032", "54032" = "54001", "54001" = "54029"),
transfo = "sqrt"),
regexp = "is not upstream the node"
)
})
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