Set paths to input file ensembles using a consistent pattern across sites
Source:R/setEnsemblePaths.R
setEnsemblePaths.RdPropagates 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",
...
)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 ....
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"
#>
#>
#>