diff --git a/NAMESPACE b/NAMESPACE index c98743b3f4790e5b9a2ffedef013717415f47f9f..9cf8783bf95a9607e34baa47f3b10cf0602cbd38 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -66,6 +66,7 @@ export(TransfoParam_GR5J) export(TransfoParam_GR6J) export(TransfoParam_Lag) export(.ErrorCrit) +export(.FeatModels) ##################################### diff --git a/R/Utils.R b/R/Utils.R index 79bc41e55fcf05b9a725b2f22939ca77b8fe3d7a..248a0f19400cbb92e9ac6eca27623100b30aa910 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -13,6 +13,47 @@ +## ================================================================================= +## function to extract model features +## ================================================================================= + +## table of feature models +.FeatModels <- function() { + path <- system.file("modelsFeatures/FeatModelsGR.csv", package = "airGR") + read.table(path, header = TRUE, sep = ";") +} + + +## function to extract model features +.GetFeatModel <- function(FUN_MOD) { + FeatMod <- .FeatModels() + FUN_MOD <- match.fun(FUN_MOD) + NameFunMod <- ifelse(test = FeatMod$Class %in% "GR", + yes = paste("RunModel", FeatMod$NameMod, sep = "_"), + no = FeatMod$NameMod) + FunMod <- lapply(NameFunMod, FUN = get) + IdMod <- which(sapply(FunMod, FUN = function(x) identical(FUN_MOD, x))) + if (length(IdMod) < 1) { + stop("'FUN_MOD' must be one of ", paste(NameFunMod, collapse = ", ")) + } else { + res <- as.list(FeatMod[IdMod, ]) + res$NameFunMod <- NameFunMod[IdMod] + res$TimeStep <- switch(res$TimeUnit, + hourly = 1, + daily = 24, + monthly = 28:31, + yearly = 365:366) + res$TimeStep <- res$TimeStep * 3600 + res$Class <- c(res$TimeUnit, res$Class) + if (grepl("CemaNeige", res$NameFunMod)) { + res$Class <- c(res$Class, "CemaNeige") + } + return(res) + } +} + + + ## ================================================================================= ## function to manage Fortran outputs ## ================================================================================= diff --git a/inst/modelsFeatures/FeatModelsGR.csv b/inst/modelsFeatures/FeatModelsGR.csv new file mode 100644 index 0000000000000000000000000000000000000000..482f6b13a256641dc552913ddc8452e4e81adda5 --- /dev/null +++ b/inst/modelsFeatures/FeatModelsGR.csv @@ -0,0 +1,14 @@ +CodeMod;NameMod;NbParam;TimeUnit;Id;Class;Pkg +GR1A;GR1A;1;yearly;NA;GR;airGR +GR2M;GR2M;2;monthly;NA;GR;airGR +GR4J;GR4J;4;daily;NA;GR;airGR +GR5J;GR5J;5;daily;NA;GR;airGR +GR6J;GR6J;6;daily;NA;GR;airGR +GR4H;GR4H;4;hourly;NA;GR;airGR +GR5H;GR5H;5;hourly;NA;GR;airGR +CemaNeige;CemaNeige;2;NA;NA;GR;airGR +CemaNeigeGR4J;CemaNeigeGR4J;6;daily;NA;GR;airGR +CemaNeigeGR5J;CemaNeigeGR5J;7;daily;NA;GR;airGR +CemaNeigeGR6J;CemaNeigeGR6J;8;daily;NA;GR;airGR +CemaNeigeGR4H;CemaNeigeGR4H;6;hourly;NA;GR;airGR +CemaNeigeGR5H;CemaNeigeGR5H;7;hourly;NA;GR;airGR