Commit da421acb authored by Delaigue Olivier's avatar Delaigue Olivier
Browse files

feat(Utils); add a DatesR argument in the .GetFeatModel function in order to manage the TimeUnit

Refs #106
parent d21eece8
Pipeline #21787 canceled with stages
...@@ -25,10 +25,10 @@ ...@@ -25,10 +25,10 @@
## function to extract model features ## function to extract model features
.GetFeatModel <- function(FUN_MOD) { .GetFeatModel <- function(FUN_MOD, DatesR) {
FeatMod <- .FeatModels() FeatMod <- .FeatModels()
FUN_MOD <- match.fun(FUN_MOD) FUN_MOD <- match.fun(FUN_MOD)
NameFunMod <- ifelse(test = FeatMod$Class %in% "GR", NameFunMod <- ifelse(test = FeatMod$Pkg %in% "airGR",
yes = paste("RunModel", FeatMod$NameMod, sep = "_"), yes = paste("RunModel", FeatMod$NameMod, sep = "_"),
no = FeatMod$NameMod) no = FeatMod$NameMod)
FunMod <- lapply(NameFunMod, FUN = get) FunMod <- lapply(NameFunMod, FUN = get)
...@@ -38,15 +38,30 @@ ...@@ -38,15 +38,30 @@
} else { } else {
res <- as.list(FeatMod[IdMod, ]) res <- as.list(FeatMod[IdMod, ])
res$NameFunMod <- NameFunMod[IdMod] res$NameFunMod <- NameFunMod[IdMod]
DiffTimeStep <- as.numeric(difftime(DatesR[length(DatesR)],
DatesR[length(DatesR)-1],
units = "secs"))
if (is.na(res$TimeUnit)) {
if (any(DiffTimeStep %in% 3600:3601)) { # 3601: leap second
res$TimeUnit <- "hourly"
} else {
res$TimeUnit <- "daily"
}
}
res$TimeStep <- switch(res$TimeUnit, res$TimeStep <- switch(res$TimeUnit,
hourly = 1, hourly = 1,
daily = 24, daily = 24,
monthly = 28:31, monthly = 28:31,
yearly = 365:366) yearly = 365:366)
res$TimeStep <- res$TimeStep * 3600 res$TimeStep <- res$TimeStep * 3600
res$Class <- c(res$TimeUnit, res$Class) res$Class <- c(res$TimeUnit, res$Class)
if (grepl("CemaNeige", res$NameFunMod)) { if (grepl("CemaNeige", res$NameFunMod)) {
res$Class <- c(res$Class, "CemaNeige") res$Class <- unique(c(res$Class, "CemaNeige"))
}
if (DiffTimeStep != res$TimeStep) {
stop("the time step of the model inputs must be ", res$TimeUnit, "\n")
} }
return(res) return(res)
} }
......
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