library(werptoolkitr)
Scenario controller
Load the package
The controller primarily sets the paths to scenarios, calls the modules, and saves the output and metadata. In normal use, we set the directory and any other needed parameters (e.g. point at a config file), and the controller functions auto-generate the folder structure, run the ewr, and output the results. This can be taken up a level to the the whole toolkit, where the controller and subsequent steps are all run at once. A detailed stepthrough of what happens in the controller is also available, useful to see what is happening under the hood.
Setup
There are a few bits of info the user needs to set for a particular run. These can be set here, or done in a parameters .yaml
file (though that’s still buggy). These needed bits of information for the controller are the location of the data and the sort of output desired.
Set paths
We need to set the path to this demonstration. This should all be in a single outer directory project_dir
, and there should be an inner directory with the input data /hydrographs
. These would typically point to external shared directories. For this simple example though, we put the data inside the repo to make it self contained. The saved data goes to project_dir/module_output
automatically. The /hydrographs
subdirectory could be made automatic as well, but I’m waiting for the input data format to firm up.
= file.path('more_scenarios')
project_dir = file.path(project_dir, 'hydrographs') hydro_dir
Control output and return
To determine what to save and what to return to the active session, use outputType
and returnType
, respectively. Each of them can take a list of any of 'none'
, 'summary'
, 'annual'
, 'all'
, with more I need to add to reflect new EWR functionality (e.g. returnType = list('summary', 'all')
in R or returnType = ['summary', 'all]
in python). These have to be lists to work right- To make a list
in python, need to have unnamed lists in R.
There’s an issue with 'annual'
in py-ewr- I’m getting an error inside the EWR tool. Until I updated the EWR version, skip that.
<- list('summary', 'all')
returnType
# We use outputtype to save, so only save outputs if params$REBUILD_DATA is TRUE
# To make a list in python, need to have unnamed lists in R
if (!params$REBUILD_DATA) {
<- list('none')
outputType
}if (params$REBUILD_DATA) {
<- list('summary', 'all')
outputType }
Run and save
The above is all user parameters. All the formatting, running, and saving is then handled with the wrapper function prep_run_save_ewrs
. See stepthrough for an expanded version used to run test data and expand each step to make testing/changes more transparent. This is not actually run here for speed- the same thing is done in a notebook for the full toolkit.
<- prep_run_save_ewrs_R(scenario_dir = hydro_dir,
ewr_out output_dir = project_dir,
outputType = outputType,
returnType = returnType)
Now we have a summary
and all
. Because the chunk above is not run (#| eval: false
), these dataframes are not available here, but would be.
$summary ewr_out
$all ewr_out
Next steps
This now has the EWR outputs saved into scenario_dir/module_output/EWR
and available for further processing with the aggregator.