Parallel calibration for several sites
Opened this issue · 0 comments
pepaaran commented
This is an example of how to simultaneously run the calibration for several sites (separately).
# Load data from Jiarui
load("~/Downloads/settings.Rda")
load("~/Downloads/driver.Rda")
load("~/Downloads/obs.Rda")
sitenames <- df_drivers2$sitename
params <- pgmcapply::pbmclapply(sitenames[1:3], function(x){
calib_sofun(drivers = df_drivers2 |>
filter(sitename == x),
obs = obs_3 |>
filter(sitename == x),
settings = settings
)
}) # parallelized version with progress bar
## Faster alternative creating a nested input object
# Fill first row of nested input
input <- tibble(drivers = df_drivers2 |>
filter(sitename == sitenames[1]) |>
list(),
obs = obs_3 |>
filter(sitename == sitenames[1]) |>
list(),
settings = settings |>
list())
for(s in sitenames[-1]){
input <- input |>
add_row(drivers = df_drivers2 |>
filter(sitename == s) |>
list(),
obs = obs_3 |>
filter(sitename == s) |>
list(),
settings = settings |>
list()
)
}
params <- apply(input, 1,
function(x) calib_sofun(x$drivers, x$obs, x$settings))
# this can also be parallelized with pbmcapply