diff --git a/R/Calibration.R b/R/Calibration.R index a66c78154e42b49ab80a61db832a6327da4dd962..3cce7b368bb73854c59f6a6ab2cd91af40731302 100644 --- a/R/Calibration.R +++ b/R/Calibration.R @@ -3,17 +3,15 @@ Calibration <- function(InputsModel, InputsCrit, CalibOptions, FUN_MOD, - FUN_CRIT, # deprecated FUN_CALIB = Calibration_Michel, FUN_TRANSFO = NULL, verbose = TRUE, ...) { FUN_MOD <- match.fun(FUN_MOD) - if (!missing(FUN_CRIT)) { - FUN_CRIT <- match.fun(FUN_CRIT) - } + FUN_CALIB <- match.fun(FUN_CALIB) + if (!is.null(FUN_TRANSFO)) { FUN_TRANSFO <- match.fun(FUN_TRANSFO) } diff --git a/R/Calibration_Michel.R b/R/Calibration_Michel.R index 462cd26185a8d7b89f69269b36e8a40389d0359e..854ab723146e860f20b7e884b7523b68a570cd05 100644 --- a/R/Calibration_Michel.R +++ b/R/Calibration_Michel.R @@ -3,16 +3,12 @@ Calibration_Michel <- function(InputsModel, InputsCrit, CalibOptions, FUN_MOD, - FUN_CRIT, # deprecated FUN_TRANSFO = NULL, verbose = TRUE, ...) { FUN_MOD <- match.fun(FUN_MOD) - if (!missing(FUN_CRIT)) { - FUN_CRIT <- match.fun(FUN_CRIT) - } # Handling 'FUN_TRANSFO' from direct argument or provided by 'CaliOptions' if (!is.null(FUN_TRANSFO)) { @@ -56,9 +52,6 @@ Calibration_Michel <- function(InputsModel, if (!inherits(CalibOptions, "HBAN")) { stop("'CalibOptions' must be of class 'HBAN' if 'Calibration_Michel' is used") } - if (!missing(FUN_CRIT)) { - warning("argument 'FUN_CRIT' is deprecated. The error criterion function is now automatically get from the 'InputsCrit' object") - } ##_variables_initialisation ParamFinalR <- NULL diff --git a/R/CreateInputsCrit.R b/R/CreateInputsCrit.R index 049e89a037ab60bcec6fc11b082bd324459e8143..04e02e7386b93903e0257a804c5c88b9ce7f319a 100644 --- a/R/CreateInputsCrit.R +++ b/R/CreateInputsCrit.R @@ -1,16 +1,13 @@ CreateInputsCrit <- function(FUN_CRIT, InputsModel, RunOptions, - Qobs, # deprecated Obs, VarObs = "Q", BoolCrit = NULL, transfo = "", Weights = NULL, - Ind_zeroes = NULL, # deprecated epsilon = NULL, - warnings = TRUE, - verbose = TRUE) { # deprecated + warnings = TRUE) { ObjectClass <- NULL @@ -18,25 +15,6 @@ CreateInputsCrit <- function(FUN_CRIT, ## ---------- check arguments - if (!missing(Qobs)) { - if (missing(Obs)) { - if (warnings) { - warning("argument 'Qobs' is deprecated. Please use 'Obs' and 'VarObs' instead") - } - Obs <- Qobs - # VarObs <- "Qobs" - } else { - warning("argument 'Qobs' is deprecated. The values set in 'Obs' will be used instead") - } - } - if (!missing(Ind_zeroes) & warnings) { - warning("deprecated 'Ind_zeroes' argument") - } - if (!missing(verbose)) { - warning("deprecated 'verbose' argument. Use 'warnings', instead") - } - - ## check 'InputsModel' if (!inherits(InputsModel, "InputsModel")) { stop("'InputsModel' must be of class 'InputsModel'") diff --git a/R/ErrorCrit.R b/R/ErrorCrit.R index e6ef4b4ef3f858c286e68cb680fb23ac191646fb..291337d967744bc7ec2dc3b2fee177a48a92478a 100644 --- a/R/ErrorCrit.R +++ b/R/ErrorCrit.R @@ -1,4 +1,4 @@ -ErrorCrit <- function(InputsCrit, OutputsModel, FUN_CRIT, warnings = TRUE, verbose = TRUE) { +ErrorCrit <- function(InputsCrit, OutputsModel, warnings = TRUE, verbose = TRUE) { ## ---------- Arguments check @@ -9,10 +9,6 @@ ErrorCrit <- function(InputsCrit, OutputsModel, FUN_CRIT, warnings = TRUE, verbo if (!inherits(OutputsModel, "OutputsModel")) { stop("OutputsModel must be of class 'OutputsModel'") } - if (!missing(FUN_CRIT)) { - warning("deprecated 'FUN_CRIT' argument. The error criterion function is now automatically get from the 'InputsCrit' object", call. = FALSE) - } - ## ---------- Criterion computation diff --git a/man/Calibration.Rd b/man/Calibration.Rd index 7368556f2202b4d24ecfbc9badb85d888fd3fd3c..65d8ee7a3fcd5f91e8d6a57408ae4c2ee285bb85 100644 --- a/man/Calibration.Rd +++ b/man/Calibration.Rd @@ -15,7 +15,7 @@ Calibration algorithm that optimises the error criterion selected as objective f \usage{ Calibration(InputsModel, RunOptions, InputsCrit, CalibOptions, - FUN_MOD, FUN_CRIT, FUN_CALIB = Calibration_Michel, + FUN_MOD, FUN_CALIB = Calibration_Michel, FUN_TRANSFO = NULL, verbose = TRUE, ...) } @@ -31,8 +31,6 @@ Calibration(InputsModel, RunOptions, InputsCrit, CalibOptions, \item{FUN_MOD}{[function] hydrological model function (e.g. \code{\link{RunModel_GR4J}}, \code{\link{RunModel_CemaNeigeGR4J}})} -\item{FUN_CRIT}{[function] error criterion function (e.g. \code{\link{ErrorCrit_RMSE}}, \code{\link{ErrorCrit_NSE}})} - \item{FUN_CALIB}{(deprecated) [function] calibration algorithm function (e.g. \code{\link{Calibration_Michel}}), \code{default = Calibration_Michel}} \item{FUN_TRANSFO}{(optional) [function] model parameters transformation function, if the \code{FUN_MOD} used is native in the package \code{FUN_TRANSFO} is automatically defined} diff --git a/man/Calibration_Michel.Rd b/man/Calibration_Michel.Rd index 28de8c4424cc84889a83fdbd9a123d5329c7af3f..6befd8b0c9293d84e43fffe5490c594de3ddbd12 100644 --- a/man/Calibration_Michel.Rd +++ b/man/Calibration_Michel.Rd @@ -19,7 +19,7 @@ Then a steepest descent local search algorithm is performed, starting from the r \usage{ Calibration_Michel(InputsModel, RunOptions, InputsCrit, CalibOptions, - FUN_MOD, FUN_CRIT, FUN_TRANSFO = NULL, verbose = TRUE, ...) + FUN_MOD, FUN_TRANSFO = NULL, verbose = TRUE, ...) } @@ -34,8 +34,6 @@ Calibration_Michel(InputsModel, RunOptions, InputsCrit, CalibOptions, \item{FUN_MOD}{[function] hydrological model function (e.g. \code{\link{RunModel_GR4J}}, \code{\link{RunModel_CemaNeigeGR4J}})} -\item{FUN_CRIT}{(deprecated) [function] error criterion function (e.g. \code{\link{ErrorCrit_RMSE}}, \code{\link{ErrorCrit_NSE}})} - \item{FUN_TRANSFO}{(optional) [function] model parameters transformation function, if the \code{FUN_MOD} used is native in the package \code{FUN_TRANSFO} is automatically defined} \item{verbose}{(optional) [boolean] boolean indicating if the function is run in verbose mode or not, default = \code{TRUE}} diff --git a/man/CreateInputsCrit.Rd b/man/CreateInputsCrit.Rd index eed50f03672fc974f63264c022db962ef7a30433..8debd8f93f11e75c27e5234d256d1008da987307 100644 --- a/man/CreateInputsCrit.Rd +++ b/man/CreateInputsCrit.Rd @@ -9,16 +9,16 @@ \description{ -Creation of the \code{InputsCrit} object required to the \code{ErrorCrit_*} functions. This function is used to define whether the user wants to calculate a single criterion, multiple criteria in the same time, or a composite criterion, which averages several criteria. +Creation of the \code{InputsCrit} object required to the \code{ErrorCrit_*} functions. This function is used to define whether the user wants to calculate a single criterion, multiple criteria in the same time, or a composite criterion, which averages several criteria. } \usage{ CreateInputsCrit(FUN_CRIT, InputsModel, RunOptions, - Qobs, Obs, VarObs = "Q", BoolCrit = NULL, + Obs, VarObs = "Q", BoolCrit = NULL, transfo = "", Weights = NULL, - Ind_zeroes = NULL, epsilon = NULL, - warnings = TRUE, verbose = TRUE) + epsilon = NULL, + warnings = TRUE) } @@ -29,8 +29,6 @@ CreateInputsCrit(FUN_CRIT, InputsModel, RunOptions, \item{RunOptions}{[object of class \emph{RunOptions}] see \code{\link{CreateRunOptions}} for details} -\item{Qobs}{(deprecated) [numeric (atomic or list)] series of observed discharges [mm/time step]} - \item{Obs}{[numeric (atomic or list)] series of observed variable ([mm/time step] for discharge or SWE, [-] for SCA)} \item{VarObs}{(optional) [character (atomic or list)] names of the observed variable (\code{"Q"} by default, or one of \code{"SCA"}, \code{"SWE"}])} @@ -41,13 +39,9 @@ CreateInputsCrit(FUN_CRIT, InputsModel, RunOptions, \item{Weights}{(optional) [numeric (atomic or list)] vector of weights necessary to calculate a composite criterion (the same length as \code{FUN_CRIT}) giving the weights to use for elements of \code{FUN_CRIT} [-]. See details} -\item{Ind_zeroes}{(deprecated) [numeric] indices of the time steps where zeroes are observed} - \item{epsilon}{(optional) [numeric (atomic or list)] small value to add to all observations and simulations when \code{"log"} or \code{"inv"} transformations are used [same unit as \code{Obs}]. See details} \item{warnings}{(optional) [boolean] boolean indicating if the warning messages are shown, default = \code{TRUE}} - -\item{verbose}{(deprecated) [boolean] boolean indicating if the function is run in verbose mode or not, default = \code{TRUE}} } @@ -62,9 +56,9 @@ CreateInputsCrit(FUN_CRIT, InputsModel, RunOptions, \emph{$epsilon } \tab [numeric] small value to add to all observations and simulations when \code{"log"} or \code{"inv"} transformations are used [same unit as \code{Obs}] \cr \emph{$Weights } \tab [numeric] vector (same length as \code{VarObs}) giving the weights to use for elements of \code{FUN_CRIT} [-] \cr } - + When \code{Weights = NULL}, \code{CreateInputsCrit} returns an object of class \emph{Single} that is a list such as the one described above. \cr -When \code{Weights} contains at least one \code{NULL} value and \code{Obs} contains a list of observations, \code{CreateInputsCrit} returns an object of class \emph{Multi} that is a list of lists such as the one described above. The \code{\link{ErrorCrit}} function will then compute the different criteria prepared by \code{CreateInputsCrit}. \cr +When \code{Weights} contains at least one \code{NULL} value and \code{Obs} contains a list of observations, \code{CreateInputsCrit} returns an object of class \emph{Multi} that is a list of lists such as the one described above. The \code{\link{ErrorCrit}} function will then compute the different criteria prepared by \code{CreateInputsCrit}. \cr When \code{Weights} is a list of at least 2 numerical values, \code{CreateInputsCrit} returns an object of class \emph{Compo} that is a list of lists such as the one described above. This object will be useful to compute composite criterion with the \code{\link{ErrorCrit}} function. \cr To calculate composite or multiple criteria, it is necessary to use the \code{ErrorCrit} function. The other \code{ErrorCrit_*} functions (e.g. \code{\link{ErrorCrit_RMSE}}, \code{\link{ErrorCrit_NSE}}) can only use objects of class \emph{Single} (and not \emph{Multi} or \emph{Compo}). \cr } @@ -84,7 +78,7 @@ Transformations are simple functions applied to the observed and simulated varia \item \code{""}: no transformation is used (default case) \item \code{"sqrt"}: squared root transformation \item \code{"log"}: logarithmic transformation (see below regarding the specific case of KGE or KGE2) - \item \code{"inv"}: inverse transformation + \item \code{"inv"}: inverse transformation \item \code{"sort"}: sort transformation (the simulated and observed variables are sorted from lowest to highest) \item \code{"boxcox"}: Box-Cox transformation (see below for details) \item numeric: power transformation (see below for details) @@ -114,15 +108,15 @@ library(airGR) data(L0123001) ## preparation of the InputsModel object -InputsModel <- CreateInputsModel(FUN_MOD = RunModel_GR4J, DatesR = BasinObs$DatesR, +InputsModel <- CreateInputsModel(FUN_MOD = RunModel_GR4J, DatesR = BasinObs$DatesR, Precip = BasinObs$P, PotEvap = BasinObs$E) ## calibration period selection -Ind_Run <- seq(which(format(BasinObs$DatesR, format = "\%Y-\%m-\%d")=="1990-01-01"), +Ind_Run <- seq(which(format(BasinObs$DatesR, format = "\%Y-\%m-\%d")=="1990-01-01"), which(format(BasinObs$DatesR, format = "\%Y-\%m-\%d")=="1999-12-31")) ## preparation of RunOptions object -RunOptions <- CreateRunOptions(FUN_MOD = RunModel_GR4J, InputsModel = InputsModel, +RunOptions <- CreateRunOptions(FUN_MOD = RunModel_GR4J, InputsModel = InputsModel, IndPeriod_Run = Ind_Run) ## simulation @@ -144,7 +138,7 @@ InputsCritMulti <- CreateInputsCrit(FUN_CRIT = list(ErrorCrit_RMSE, ErrorCrit_NS Obs = list(BasinObs$Qmm[Ind_Run], BasinObs$Qmm[Ind_Run]), VarObs = list("Q", "Q"), transfo = list("", "sqrt"), Weights = NULL) -str(InputsCritMulti) +str(InputsCritMulti) invisible(ErrorCrit(InputsCrit = InputsCritMulti, OutputsModel = OutputsModel)) ## efficiency composite criterion: Nash-Sutcliffe Efficiency mixing @@ -154,7 +148,7 @@ InputsCritCompo <- CreateInputsCrit(FUN_CRIT = list(ErrorCrit_NSE, ErrorCrit_NSE Obs = list(BasinObs$Qmm[Ind_Run], BasinObs$Qmm[Ind_Run]), VarObs = list("Q", "Q"), transfo = list("", "log"), Weights = list(0.4, 0.6)) -str(InputsCritCompo) +str(InputsCritCompo) invisible(ErrorCrit(InputsCrit = InputsCritCompo, OutputsModel = OutputsModel)) } @@ -165,12 +159,12 @@ Olivier Delaigue, Laurent Coron, Guillaume Thirel \references{ -Pushpalatha, R., Perrin, C., Le Moine, N. and Andréassian, V. (2012). - A review of efficiency criteria suitable for evaluating low-flow simulations. +Pushpalatha, R., Perrin, C., Le Moine, N. and Andréassian, V. (2012). + A review of efficiency criteria suitable for evaluating low-flow simulations. Journal of Hydrology, 420-421, 171-182, doi: 10.1016/j.jhydrol.2011.11.055. \cr\cr -Santos, L., Thirel, G. and Perrin, C. (2018). - Technical note: Pitfalls in using log-transformed flows within the KGE criterion. +Santos, L., Thirel, G. and Perrin, C. (2018). + Technical note: Pitfalls in using log-transformed flows within the KGE criterion. Hydrol. Earth Syst. Sci., 22, 4583-4591, doi: 10.5194/hess-22-4583-2018. } diff --git a/man/ErrorCrit.Rd b/man/ErrorCrit.Rd index acb933c6b935ddb68b5ebdc23f6cbe7a736bf42c..f183997c7672c0e30692639d9a51903d03d58ef6 100644 --- a/man/ErrorCrit.Rd +++ b/man/ErrorCrit.Rd @@ -14,7 +14,7 @@ Function which computes an error criterion with the provided function. \usage{ -ErrorCrit(InputsCrit, OutputsModel, FUN_CRIT, warnings = TRUE, verbose = TRUE) +ErrorCrit(InputsCrit, OutputsModel, warnings = TRUE, verbose = TRUE) } @@ -23,8 +23,6 @@ ErrorCrit(InputsCrit, OutputsModel, FUN_CRIT, warnings = TRUE, verbose = TRUE) \item{OutputsModel}{[object of class \emph{OutputsModel}] see \code{\link{RunModel_GR4J}} or \code{\link{RunModel_CemaNeigeGR4J}} for details} -\item{FUN_CRIT}{(deprecated) [function] error criterion function (e.g. \code{\link{ErrorCrit_RMSE}}, \code{\link{ErrorCrit_NSE}})} - \item{warnings}{(optional) [boolean] boolean indicating if the warning messages are shown, default = \code{TRUE}} \item{verbose}{(optional) [boolean] boolean indicating if the function is run in verbose mode or not, default = \code{TRUE}} @@ -64,15 +62,15 @@ library(airGR) data(L0123001) ## preparation of the InputsModel object -InputsModel <- CreateInputsModel(FUN_MOD = RunModel_GR4J, DatesR = BasinObs$DatesR, +InputsModel <- CreateInputsModel(FUN_MOD = RunModel_GR4J, DatesR = BasinObs$DatesR, Precip = BasinObs$P, PotEvap = BasinObs$E) ## calibration period selection -Ind_Run <- seq(which(format(BasinObs$DatesR, format = "\%Y-\%m-\%d")=="1990-01-01"), +Ind_Run <- seq(which(format(BasinObs$DatesR, format = "\%Y-\%m-\%d")=="1990-01-01"), which(format(BasinObs$DatesR, format = "\%Y-\%m-\%d")=="1999-12-31")) ## preparation of RunOptions object -RunOptions <- CreateRunOptions(FUN_MOD = RunModel_GR4J, InputsModel = InputsModel, +RunOptions <- CreateRunOptions(FUN_MOD = RunModel_GR4J, InputsModel = InputsModel, IndPeriod_Run = Ind_Run) ## simulation @@ -85,7 +83,7 @@ InputsCritSingle <- CreateInputsCrit(FUN_CRIT = ErrorCrit_NSE, InputsModel = InputsModel, RunOptions = RunOptions, Obs = list(BasinObs$Qmm[Ind_Run]), VarObs = "Q", transfo = "", - Weights = NULL) + Weights = NULL) str(ErrorCrit(InputsCrit = InputsCritSingle, OutputsModel = OutputsModel)) ## 2 efficiency critera: RMSE and the Nash-Sutcliffe Efficiency @@ -93,7 +91,7 @@ InputsCritMulti <- CreateInputsCrit(FUN_CRIT = list(ErrorCrit_RMSE, ErrorCrit_NS InputsModel = InputsModel, RunOptions = RunOptions, Obs = list(BasinObs$Qmm[Ind_Run], BasinObs$Qmm[Ind_Run]), VarObs = list("Q", "Q"), transfo = list("", "sqrt"), - Weights = NULL) + Weights = NULL) str(ErrorCrit(InputsCrit = InputsCritMulti, OutputsModel = OutputsModel)) ## efficiency composite criterion: Nash-Sutcliffe Efficiency mixing @@ -102,7 +100,7 @@ InputsCritCompo <- CreateInputsCrit(FUN_CRIT = list(ErrorCrit_NSE, ErrorCrit_NSE InputsModel = InputsModel, RunOptions = RunOptions, Obs = list(BasinObs$Qmm[Ind_Run], BasinObs$Qmm[Ind_Run]), VarObs = list("Q", "Q"), transfo = list("", "log"), - Weights = list(0.4, 0.6)) + Weights = list(0.4, 0.6)) str(ErrorCrit(InputsCrit = InputsCritCompo, OutputsModel = OutputsModel)) }