Propagates a filename pattern into the relevant paths of a multi-site settings. For example if your files are named like "mymet/siteA/scenario1.nc" up through "mymet/siteZ/scenario50.nc", setEnsemblePaths(settings, n_reps = 50, "mymet/{id}/scenario{n}.nc") will add them all to your settings in one shot.

setEnsemblePaths(
  settings,
  n_reps,
  input_type = c("met", "poolinitcond", "soilinitcond"),
  path_template = "./{id}/{n}.nc",
  ...
)

Arguments

settings

a PEcAn MultiSettings object

n_reps

number of replicates to insert for each path.

input_type

subsection of the inputs settings to be edited

path_template

format for the paths to be inserted, as a glue string.

...

additional variables to be interpolated into path_template

Value

updated settings object

Details

Operates on one input section (met, poolinitcond, etc) at a time because it's common to have different path conventions for met vs IC.

The path template should be a string recognized by glue::glue(), with curly braces wrapping any expressions to be interpolated. {n} will be replaced with each value of 1:n_reps, {id} will be replaced with the siteid of each site, and any other variables need to be passed as named arguments in ....

Note that for consistency, every site in settings must contain an element named inputs$<input_type> before you call this. If inputs$<input_type>$path does not exist it will be created; if it does exist it will be overwritten.

Examples

s <- as.Settings(list(
  run = list(
    start.date = "TBD",
    site = list(),
    inputs = list(
      met = list(),
      poolinitcond = list()
    )
  )
))
m <- createMultiSiteSettings(s, c("a1", "b2"))
m1 <- setEnsemblePaths(m, 2)
m1$run$site.a1$inputs
#> $met
#> $met$path
#> $met$path$path1
#> [1] "./a1/1.nc"
#> 
#> $met$path$path2
#> [1] "./a1/2.nc"
#> 
#> 
#> 
#> $poolinitcond
#> list()
#> 
m2 <- setEnsemblePaths(
  m, 2, "poolinitcond",
  icdir = "some/long/path",
  path_template = "{icdir}/{id}/{n}.nc"
)
m2$run$site.a1$inputs
#> $met
#> list()
#> 
#> $poolinitcond
#> $poolinitcond$path
#> $poolinitcond$path$path1
#> [1] "some/long/path/a1/1.nc"
#> 
#> $poolinitcond$path$path2
#> [1] "some/long/path/a1/2.nc"
#> 
#> 
#>