Skip to contents

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.

Usage

setEnsemblePaths(
  settings,
  n_reps,
  input_type = "met",
  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. Variables in these expressions are resolved in this order:

  1. Variables defined in each site's run$site settings block (notably meaning {id} will contain the site id that is always present as run$site$id)

  2. Variables passed as named arguments in ... (these take the same value at every site)

  3. {n} is treated specially as a replicate number and replaced with the sequence 1:n_reps

If the same name is defined in both run$site and ..., uses the latter. All variables must have length either 1 or n_reps.

If inputs$<input_type> does not exist, it will be created with a path element that matches the requested pattern. If it does exist, any existing path element 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"
#> 
#> 
#> 

# using site-specific values in the path template:
m_bysite <- createMultiSiteSettings(
  templateSettings = s,
  siteIds = data.frame(id = c("a1", "b2"), grid_cell = c("35N81W", "42N80W"))
)
m2_bysite <- setEnsemblePaths(
  settings = m_bysite,
  n_reps = 2,
  input_type = "met",
  icdir = "some/long/path",
  GCM = c("CESM2", "MIROC6"),
  path_template = "{icdir}/{grid_cell}/{GCM}.nc"
)
m2_bysite$run$site.a1$inputs
#> $met
#> $met$path
#> $met$path$path1
#> [1] "some/long/path/35N81W/CESM2.nc"
#> 
#> $met$path$path2
#> [1] "some/long/path/35N81W/MIROC6.nc"
#> 
#> 
#> 
#> $poolinitcond
#> list()
#>