Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallel calibration for several sites #127

Open
pepaaran opened this issue Jan 27, 2023 · 0 comments
Open

Parallel calibration for several sites #127

pepaaran opened this issue Jan 27, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@pepaaran
Copy link
Collaborator

pepaaran commented Jan 27, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants