RunModel_Lag: crash on simulation with supervisor and without warm-up period
In this particular case, the StateEnd Output will try do save the state of the upstream with delay resulting in this index calculation for picking up the data in Qupstream:
lastTS <- RunOptions$IndPeriod_Run[length(RunOptions$IndPeriod_Run)]
index_to_pick_up_in_Qupstream <- lastTS - floor(PT[x])
This is trigered as soon as the first time step because of the supervisor which run the model at each time step and unfortunately if the InputsModel time series start on the first step of simulation, we can get a negative index raising this error:
Error:
only 0's may be mixed with negative subscripts
Hide Traceback
2. airGRiwrm::RunModel(sv, RunOptions = RO_hydro, Param = yaml::read_yaml(TalanoaHydro::getCalibrationFilePath("params/params",
"yml", cfgH))) %>% suppressMessages() %>% suppressWarnings() at ModeleIntegreAude/R/runModeleIntegre.R:142:3
3. suppressWarnings(.)
4. withCallingHandlers(expr, warning = function(w) if (inherits(w,
classes)) tryInvokeRestart("muffleWarning"))
5. suppressMessages(.)
6. withCallingHandlers(expr, message = function(c) if (inherits(c,
classes)) tryInvokeRestart("muffleMessage"))
7. airGRiwrm::RunModel(sv, RunOptions = RO_hydro, Param = yaml::read_yaml(TalanoaHydro::getCalibrationFilePath("params/params",
"yml", cfgH)))
8. RunModel.Supervisor(sv, RunOptions = RO_hydro, Param = yaml::read_yaml(TalanoaHydro::getCalibrationFilePath("params/params",
"yml", cfgH)))
9. suppressWarnings(RunModel_Routing(x$InputsModel[[id]], RunOptions = RunOptions[[id]],
Param = Param[[id]], QcontribDown = QcontribDown))
10. withCallingHandlers(expr, warning = function(w) if (inherits(w,
classes)) tryInvokeRestart("muffleWarning"))
11. RunModel_Routing(x$InputsModel[[id]], RunOptions = RunOptions[[id]],
Param = Param[[id]], QcontribDown = QcontribDown)
12. RunModel_Lag_enhanced(x, RunOptions = RunOptions, Param = Param[1],
QcontribDown = QcontribDown)
13. lapply(seq(NbUpBasins), function(x) {
lastTS <- RunOptions$IndPeriod_Run[length(RunOptions$IndPeriod_Run)]
InputsModel$Qupstream[(lastTS - floor(PT[x])):lastTS, x]
The calculation of the index should be protected as it is done for the calculation of the initial state where the time series are extended with some dummy variable in order to get a code that works.