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

fix(Utils): manage WarmUpQsim and Param in .ExtractOutputsModel

- return a RunOptions list from .GetOutputsModelGR (UtilsRunModel) with WarmUpQsim and Param, and remove the specific class of WarmUpQsim
Refs #137
parent d4af17d5
Pipeline #28364 failed with stages
in 14 minutes and 52 seconds
...@@ -6,7 +6,7 @@ CreateErrorCrit_GAPX <- function(FUN_TRANSFO) { ...@@ -6,7 +6,7 @@ CreateErrorCrit_GAPX <- function(FUN_TRANSFO) {
stop("'OutputsModel' must be of class 'OutputsModel'") stop("'OutputsModel' must be of class 'OutputsModel'")
} }
OutputsModel$ParamT <- FUN_TRANSFO(OutputsModel$Param, "RT") OutputsModel$RunOptions$ParamT <- FUN_TRANSFO(OutputsModel$RunOptions$Param, "RT")
EC <- .ErrorCrit(InputsCrit = InputsCrit, Crit = "GAPX", OutputsModel = OutputsModel, warnings = warnings) EC <- .ErrorCrit(InputsCrit = InputsCrit, Crit = "GAPX", OutputsModel = OutputsModel, warnings = warnings)
......
...@@ -48,10 +48,10 @@ RunModel_Lag <- function(InputsModel, RunOptions, Param, QcontribDown) { ...@@ -48,10 +48,10 @@ RunModel_Lag <- function(InputsModel, RunOptions, Param, QcontribDown) {
if (inherits(QcontribDown, "OutputsModel")) { if (inherits(QcontribDown, "OutputsModel")) {
OutputsModel <- QcontribDown OutputsModel <- QcontribDown
if (is.null(OutputsModel$WarmUpQsim)) { if (is.null(OutputsModel$RunOptions$WarmUpQsim)) {
OutputsModel$WarmUpQsim <- rep(NA, length(RunOptions$IndPeriod_WarmUp)) OutputsModel$RunOptions$WarmUpQsim <- rep(NA, length(RunOptions$IndPeriod_WarmUp))
} }
QsimDown <- c(OutputsModel$WarmUpQsim, OutputsModel$Qsim) QsimDown <- c(OutputsModel$RunOptions$WarmUpQsim, OutputsModel$Qsim)
} else if (is.vector(QcontribDown) && is.numeric(QcontribDown)) { } else if (is.vector(QcontribDown) && is.numeric(QcontribDown)) {
OutputsModel <- list() OutputsModel <- list()
class(OutputsModel) <- c("OutputsModel", class(RunOptions)[-1]) class(OutputsModel) <- c("OutputsModel", class(RunOptions)[-1])
...@@ -156,11 +156,11 @@ RunModel_Lag <- function(InputsModel, RunOptions, Param, QcontribDown) { ...@@ -156,11 +156,11 @@ RunModel_Lag <- function(InputsModel, RunOptions, Param, QcontribDown) {
# message("StateEnd: ", paste(OutputsModel$StateEnd$SD, collapse = ", ")) # message("StateEnd: ", paste(OutputsModel$StateEnd$SD, collapse = ", "))
} }
if ("WarmUpQsim" %in% RunOptions$Outputs_Sim) { if ("WarmUpQsim" %in% RunOptions$Outputs_Sim) {
OutputsModel$WarmUpQsim <- Qsim_m3[seq_len(length(RunOptions$IndPeriod_WarmUp))] / sum(InputsModel$BasinAreas, na.rm = TRUE) / 1e3 OutputsModel$RunOptions$WarmUpQsim <- Qsim_m3[seq_len(length(RunOptions$IndPeriod_WarmUp))] / sum(InputsModel$BasinAreas, na.rm = TRUE) / 1e3
} }
if ("Param" %in% RunOptions$Outputs_Sim) { if ("Param" %in% RunOptions$Outputs_Sim) {
OutputsModel$Param <- c(Param, OutputsModel$Param) OutputsModel$RunOptions$Param <- c(Param, OutputsModel$RunOptions$Param)
} }
class(OutputsModel) <- c(class(OutputsModel), "SD") class(OutputsModel) <- c(class(OutputsModel), "SD")
......
...@@ -213,6 +213,9 @@ ...@@ -213,6 +213,9 @@
} }
return(res0) return(res0)
}) })
if (!is.null(x$RunOptions)) {
res$RunOptions <- x$RunOptions
}
if (!is.null(x$StateEnd)) { if (!is.null(x$StateEnd)) {
res$StateEnd <- x$StateEnd res$StateEnd <- x$StateEnd
} }
...@@ -221,7 +224,7 @@ ...@@ -221,7 +224,7 @@
} }
.IndexOutputsModel <- function(x, i) { .IndexOutputsModel <- function(x, i) {
# '[.OutputsModel' <- function(x, i) { # '[.OutputsModel' <- function(x, i) {
if (!inherits(x, "OutputsModel")) { if (!inherits(x, "OutputsModel")) {
stop("'x' must be of class 'OutputsModel'") stop("'x' must be of class 'OutputsModel'")
} }
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
Q = OutputsModel$Qsim, Q = OutputsModel$Qsim,
SCA = rowMeans(sapply(OutputsModel$CemaNeigeLayers[InputsCrit$idLayer], FUN = "[[", "Gratio")), SCA = rowMeans(sapply(OutputsModel$CemaNeigeLayers[InputsCrit$idLayer], FUN = "[[", "Gratio")),
SWE = rowMeans(sapply(OutputsModel$CemaNeigeLayers[InputsCrit$idLayer], FUN = "[[", "SnowPack")), SWE = rowMeans(sapply(OutputsModel$CemaNeigeLayers[InputsCrit$idLayer], FUN = "[[", "SnowPack")),
ParamT = OutputsModel$ParamT ParamT = OutputsModel$RunOptions$ParamT
) )
VarSim[!InputsCrit$BoolCrit] <- NA VarSim[!InputsCrit$BoolCrit] <- NA
......
...@@ -39,18 +39,19 @@ ...@@ -39,18 +39,19 @@
} }
if ("WarmUpQsim" %in% RunOptions$Outputs_Sim) { if ("WarmUpQsim" %in% RunOptions$Outputs_Sim) {
OutputsModel$WarmUpQsim <- RESULTS$Outputs[seq_len(length(RunOptions$IndPeriod_WarmUp)), OutputsModel$RunOptions$WarmUpQsim <- RESULTS$Outputs[seq_len(length(RunOptions$IndPeriod_WarmUp)),
which(FortranOutputs == "Qsim")] which(FortranOutputs == "Qsim")]
class(OutputsModel$WarmUpQsim) <- c("WarmUpOutputsModelItem", class(OutputsModel$WarmUpQsim)) # class(OutputsModel$RunOptions$WarmUpQsim) <- c("WarmUpOutputsModelItem", class(OutputsModel$RunOptions$WarmUpQsim))
}
if ("Param" %in% RunOptions$Outputs_Sim) {
OutputsModel$RunOptions$Param <- Param
} }
if ("StateEnd" %in% RunOptions$Outputs_Sim) { if ("StateEnd" %in% RunOptions$Outputs_Sim) {
OutputsModel$StateEnd <- RESULTS$StateEnd OutputsModel$StateEnd <- RESULTS$StateEnd
} }
if ("Param" %in% RunOptions$Outputs_Sim) {
OutputsModel$Param <- Param
}
class(OutputsModel) <- c("OutputsModel", class(RunOptions)[-1]) class(OutputsModel) <- c("OutputsModel", class(RunOptions)[-1])
......
...@@ -122,7 +122,7 @@ For using upstream simulated flows, we should concatenate a vector with the simu ...@@ -122,7 +122,7 @@ For using upstream simulated flows, we should concatenate a vector with the simu
```{r} ```{r}
Qsim_upstream <- rep(NA, length(BasinObs$DatesR)) Qsim_upstream <- rep(NA, length(BasinObs$DatesR))
# Simulated flow during warm-up period (365 days before run period) # Simulated flow during warm-up period (365 days before run period)
Qsim_upstream[Ind_Run[seq_len(365)] - 365] <- OutputsModelUp$WarmUpQsim Qsim_upstream[Ind_Run[seq_len(365)] - 365] <- OutputsModelUp$RunOptions$WarmUpQsim
# Simulated flow during run period # Simulated flow during run period
Qsim_upstream[Ind_Run] <- OutputsModelUp$Qsim Qsim_upstream[Ind_Run] <- OutputsModelUp$Qsim
......
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