Closed rhabel closed 3 years ago
Hi Raphael,
this is a classic case for an error-routine.... In your custom version, you could use tryCatch()
to catch potential errors. This is also what the multi-run functions do in their foreach-loops: When a call of run_LWFB90()
fails, the error instead of the simulation results is appended to the list of results. There, you can identify the site by the name of the list entry.
Here an example with run_multi_LWFB90()
, but it works the same with run_multisite_LWB90()
.
library(LWFBrook90R)
data("slb1_meteo")
data("slb1_soil")
# Set up lists containing model control options and model parameters:
parms <- set_paramLWFB90()
opts <- set_optionsLWFB90(startdate = as.Date("2003-06-01"),
enddate = as.Date("2003-06-30"))
# Derive soil hydraulic properties from soil physical properties using pedotransfer functions
soil <- cbind(slb1_soil, hydpar_wessolek_tab(slb1_soil$texture))
#set up data.frame with variable parameters
n <- 2
set.seed(2021)
vary_parms <- data.frame(maxlai = runif(n,2,7))
#multi-run
b90.multi <- run_multi_LWFB90(paramvar = vary_parms,
param_b90 = parms,
options_b90 = opts,
climate = slb1_meteo,
soil = soil)
str(b90.multi)
# now the same simulation, but with psiini > 0 to provoque an error:
parms$psiini <- 0.1
b90.multi <- run_multi_LWFB90(paramvar = vary_parms,
param_b90 = parms,
options_b90 = opts,
climate = slb1_meteo,
soil = soil)
b90.multi
Hi,
The chk_errors()-function in L297 (as well as L408ff) of run_LWFB90() stops the code while throwing an error-message https://github.com/pschmidtwalter/LWFBrook90R/blob/e113798157b92cf997fc07ac5667d87cc3ebf287/R/runLWFB90.R#L297
when, say, we're running thousands of points automatically with run_multisite_LWFB90, there will inevitably be points that create errors of some kind. In this case, it would be useful if stopping the whole modelling process through an error would be an optional choice. In a local version of the run_LWFB90-function I wrote a workaround like this:
This way, all points get modelled and one can check which ones caused errors in the error-file. I know, this code-snippet is quite specific for my application (having an \code{id_custom} in the soil-dataframe plus \code{errorpath} in the additional arguments) but potentially the general optional-stopping-functionality might be useful to implement.