Commit 3a23e2f1 authored by Dorchies David's avatar Dorchies David
Browse files

refactor: rename `DeLavenne` to `Lavenne`

Refs HYCAR-Hydro/airgr#111
parent 11ded839
Pipeline #25915 passed with stage
in 9 minutes and 19 seconds
......@@ -39,8 +39,8 @@ Calibration.GRiwrmInputsModel <- function(InputsModel,
IM <- UpdateQsimUpstream(IM, RunOptions[[IM$id]], OutputsModel)
}
if (inherits(InputsCrit[[IM$id]], "InputsCritDeLavenneFunction")) {
IC <- getInputsCrit_DeLavenne(IM$id, OutputsModel, InputsCrit)
if (inherits(InputsCrit[[IM$id]], "InputsCritLavenneFunction")) {
IC <- getInputsCrit_Lavenne(IM$id, OutputsModel, InputsCrit)
} else {
IC <- InputsCrit[[IM$id]]
}
......@@ -70,27 +70,27 @@ Calibration.GRiwrmInputsModel <- function(InputsModel,
#' Create InputsCrit for De Lavenne regularisation
#'
#' Internal function that run [airGR::CreateInputsCrit_DeLavenne] on-the-fly with a priori upstream
#' Internal function that run [airGR::CreateInputsCrit_Lavenne] on-the-fly with a priori upstream
#' sub-catchment parameters grabbed during network calibration process.
#'
#' @param id [character] the id of the current sub-catchment
#' @param OutputsModel \[GRiwrmOutputsModel\] object with simulation results of upstream sub-catchments run with calibrated parameters
#' @param InputsCrit \[InputsCritDeLavenneFunction\] object internally created by [CreateInputsCrit.GRiwrmInputsModel]
#' @param InputsCrit \[InputsCritLavenneFunction\] object internally created by [CreateInputsCrit.GRiwrmInputsModel]
#'
#' @return \[InputsCrit\] object with De Lavenne regularisation
#' @noRd
#'
getInputsCrit_DeLavenne <- function(id, OutputsModel, InputsCrit) {
if (!inherits(InputsCrit[[id]], "InputsCritDeLavenneFunction")) {
stop("'InputsCrit[[id]]' must be of class InputsCritDeLavenneFunction")
getInputsCrit_Lavenne <- function(id, OutputsModel, InputsCrit) {
if (!inherits(InputsCrit[[id]], "InputsCritLavenneFunction")) {
stop("'InputsCrit[[id]]' must be of class InputsCritLavenneFunction")
}
AprioriId <- attr(InputsCrit[[id]], "AprioriId")
DeLavenne_FUN <- attr(InputsCrit[[id]], "DeLavenne_FUN")
Lavenne_FUN <- attr(InputsCrit[[id]], "Lavenne_FUN")
AprParamR <- OutputsModel[[AprioriId]]$Param
if(!inherits(OutputsModel[[AprioriId]], "SD")) {
# Add neutral velocity parameter for upstream catchment
AprParamR <- c(NA, AprParamR)
}
AprCrit <- ErrorCrit(InputsCrit[[AprioriId]], OutputsModel[[AprioriId]])$CritValue
return(DeLavenne_FUN(AprParamR, AprCrit))
return(Lavenne_FUN(AprParamR, AprCrit))
}
......@@ -65,8 +65,8 @@ CreateInputsCrit.GRiwrmInputsModel <- function(InputsModel,
)
if (!is.null(AprioriIds) && IM$id %in% names(AprioriIds)) {
# De Lavenne regularisation for this sub-catchment
attr(InputsCrit[[IM$id]], "DeLavenne_FUN") <-
CreateDeLavenneFunction(
attr(InputsCrit[[IM$id]], "Lavenne_FUN") <-
CreateLavenneFunction(
InputsModel = IM,
FUN_CRIT = FUN_CRIT,
RunOptions = RunOptions[[IM$id]],
......@@ -75,16 +75,16 @@ CreateInputsCrit.GRiwrmInputsModel <- function(InputsModel,
...
)
attr(InputsCrit[[IM$id]], "AprioriId") <- AprioriIds[IM$id]
class(InputsCrit[[IM$id]]) <- c("InputsCritDeLavenneFunction", class(InputsCrit[[IM$id]]))
class(InputsCrit[[IM$id]]) <- c("InputsCritLavenneFunction", class(InputsCrit[[IM$id]]))
}
}
return(InputsCrit)
}
CreateDeLavenneFunction <- function(InputsModel, FUN_CRIT, RunOptions, Obs, k, ...) {
CreateLavenneFunction <- function(InputsModel, FUN_CRIT, RunOptions, Obs, k, ...) {
function(AprParamR, AprCrit) {
CreateInputsCrit_DeLavenne(FUN_CRIT = FUN_CRIT,
CreateInputsCrit_Lavenne(FUN_CRIT = FUN_CRIT,
InputsModel = InputsModel,
RunOptions = RunOptions,
Obs = Obs,
......
......@@ -7,7 +7,7 @@
#' @param RunOptions object of class \emph{RunOptions} or \emph{GRiwrmRunOptions}, see [CreateRunOptions]
#' @param Obs [numeric], [matrix] or [data.frame] series of observed flows, see details
#' @param AprioriIds (optional) named [list] or named [vector] of [character] used for the parameter regularisation (see details)
#' @param k (optional) [numeric] weight coefficient used in the parameter regularisation (See [airGR::CreateInputsCrit_DeLavenne])
#' @param k (optional) [numeric] weight coefficient used in the parameter regularisation (See [airGR::CreateInputsCrit_Lavenne])
#' @param ... arguments passed to [airGR::CreateInputsCrit], see details
#'
#' @details See [airGR::CreateInputsCrit] documentation for a complete list of arguments.
......@@ -16,7 +16,7 @@
#'
#' With a \emph{GRiwrmInputsModel} object, all arguments are applied on each sub-catchments of the network.
#'
#' Parameter regularisation consists of defining a priori parameters which are used in a composed criterion based on the formula proposed by de Lavenne et al. (2019) (See [airGR::CreateInputsCrit_DeLavenne]).
#' Parameter regularisation consists of defining a priori parameters which are used in a composed criterion based on the formula proposed by de Lavenne et al. (2019) (See [airGR::CreateInputsCrit_Lavenne]).
#' The parameter `AprioriIds` allows to define which upstream sub-catchment is used for providing a priori parameters. Its format is as follows: `AprioriIds <- c("Downstream sub-catchment 1" = "A priori upstream sub-catchment 1", ...)` where the quoted strings are the ids of the sub-catchments. See vignettes for more details.
#'
#' @return Depending on the class of `InputsModel` argument (respectively `InputsModel` and `GRiwrmInputsModel` object), the returned value is respectively:
......
......@@ -32,7 +32,7 @@ CreateInputsCrit(InputsModel, ...)
\item{AprioriIds}{(optional) named \link{list} or named \link{vector} of \link{character} used for the parameter regularisation (see details)}
\item{k}{(optional) \link{numeric} weight coefficient used in the parameter regularisation (See \link[airGR:CreateInputsCrit_DeLavenne]{airGR::CreateInputsCrit_DeLavenne})}
\item{k}{(optional) \link{numeric} weight coefficient used in the parameter regularisation (See \link[airGR:CreateInputsCrit_Lavenne]{airGR::CreateInputsCrit_Lavenne})}
\item{...}{arguments passed to \link[airGR:CreateInputsCrit]{airGR::CreateInputsCrit}, see details}
}
......@@ -53,7 +53,7 @@ See \link[airGR:CreateInputsCrit]{airGR::CreateInputsCrit} documentation for a c
With a \emph{GRiwrmInputsModel} object, all arguments are applied on each sub-catchments of the network.
Parameter regularisation consists of defining a priori parameters which are used in a composed criterion based on the formula proposed by de Lavenne et al. (2019) (See \link[airGR:CreateInputsCrit_DeLavenne]{airGR::CreateInputsCrit_DeLavenne}).
Parameter regularisation consists of defining a priori parameters which are used in a composed criterion based on the formula proposed by de Lavenne et al. (2019) (See \link[airGR:CreateInputsCrit_Lavenne]{airGR::CreateInputsCrit_Lavenne}).
The parameter \code{AprioriIds} allows to define which upstream sub-catchment is used for providing a priori parameters. Its format is as follows: \code{AprioriIds <- c("Downstream sub-catchment 1" = "A priori upstream sub-catchment 1", ...)} where the quoted strings are the ids of the sub-catchments. See vignettes for more details.
}
\references{
......
......@@ -47,12 +47,12 @@ test_that("Calibration with regularisation is OK", {
CalibOptions = CalibOptions
)
ParamDeLavenne <- lapply(OC, "[[", "ParamFinalR")
ParamLavenne <- lapply(OC, "[[", "ParamFinalR")
expect_equal(OC[["54095"]]$CritFinal, ErrorCrit(
InputsCrit[["54095"]],
RunModel(InputsModel, RunOptions, ParamDeLavenne)[["54095"]]
RunModel(InputsModel, RunOptions, ParamLavenne)[["54095"]]
)$CritValue)
OM <- RunModel(InputsModel, RunOptions, ParamDeLavenne)
OM <- RunModel(InputsModel, RunOptions, ParamLavenne)
lapply(names(OC), function(id) {
expect_gt(
ErrorCrit(
......
......@@ -30,9 +30,9 @@ test_that("De Lavenne criterion is OK", {
RunOptions = RunOptions,
Obs = Qobs[IndPeriod_Run,],
AprioriIds = c("54057" = "54032", "54032" = "54001", "54001" = "54095"))
expect_s3_class(IC[["54057"]], "InputsCritDeLavenneFunction")
DeLavenne_FUN <- attr(IC[["54057"]], "DeLavenne_FUN")
IC57 <- DeLavenne_FUN(ParamMichel[["54032"]], 0.9)
expect_s3_class(IC[["54057"]], "InputsCritLavenneFunction")
Lavenne_FUN <- attr(IC[["54057"]], "Lavenne_FUN")
IC57 <- Lavenne_FUN(ParamMichel[["54032"]], 0.9)
expect_s3_class(IC57, "InputsCrit")
expect_s3_class(IC57, "Compo")
})
......
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