
Restrict a model's written output to the variables of interest
Source:R/set_output_vars.R
set_output_vars.RdBy default every AEME model writes its full state at every output step.
When only a few variables are needed - as in calibration or sensitivity
analysis, where the objective is computed from one or two variables - the
rest is wasted disk I/O (and, for Simstrat and GOTM, wasted files).
set_output_vars() rewrites the output section of a model's configuration
so that only vars, plus the handful of internals AEME always needs to
read a result back (water level, the depth grid, temperature), are
written.
Arguments
- aeme
An
Aemeobject carrying a configuration formodel.- model
Character. A single model, one of
"glm_aed","gotm_wet","simstrat_aed","simstrat_aed2","dy_cd".- vars
Character. AEME variable names to keep, e.g.
c("HYD_temp", "CHM_oxy"). Mapped to each model's own output names viakey_naming; names with no mapping formodelare dropped with a warning.- mass_balance
Logical. For
"glm_aed"only: keep the GLMv4&mass_balancediagnostic CSV? DefaultTRUE. Ignored for other models.- ens_n
Integer. Ensemble member whose configuration slot is updated. Default
1.
Value
aeme, with its configuration() updated.
Details
The change is made on the in-memory configuration; call
write_configuration (or build_aeme) to write
it to disk. build_aeme's output_vars argument applies this
automatically at build time.
GLM always writes the full netCDF - its gridded variables cannot be sub-selected - so this only drops the
&outputcsv_point_*keys (disabling the fixed-depthWQ_*.csvfiles) and, whenmass_balance = FALSE, the whole&mass_balanceblock (disablingmass_balance.csv). The whole-lakelake.csv(csv_lake_fname) is left on: GLM 4.x only writes the netCDF diagnostic scalars (lake_level, ...) while that CSV is open, and AEME needslake_levelto read a GLM result back.Simstrat writes one
*_out.datper variable; this setsOutput$All = FALSEand lists only the needed variables.GOTM replaces the
/*(all-variables) output source with an explicit list.DYRESM has a fixed output form and is returned unchanged.
Examples
aeme <- readRDS(system.file("extdata/aeme.rds", package = "AEME"))
path <- tempdir()
aeme <- build_aeme(path = path, aeme = aeme, model = "glm_aed",
model_controls = get_model_controls(), ext_elev = 5)
#> Warning: ! `SIL_rsi`: SIL_rsi is constant across all rows -- this may be a placeholder
#> value.
#> ℹ Check raw data or unit conversion for this variable.
#>
#> ── Calculating water balance ──
#>
#> Resolving water level
#> ℹ Using observed water level
#> ! Missing values in observed water level
#> ℹ Estimating surface water temperature
#> ✔ Estimating surface water temperature [26ms]
#>
#> Estimating lake water levels for glm_aed
#> ℹ Optimizing parameters for water balance
#> ✔ Optimization Complete: C = 0.3343, h_inv = 23.4915, Final RMSE = 0.1431
#> ℹ Correcting water balance using estimated outflows (method = 2).
#>
#> ── Building GLM-AED for lake wainamu ──
#>
#> ✔ GLM nml validation completed - no issues detected.
aeme <- set_output_vars(aeme, "glm_aed", "HYD_temp", mass_balance = FALSE)
write_configuration(aeme, model = "glm_aed", path = path)