Skip to contents

This function allows to run a SWAT2012 project in R. Basic settings for the SWAT run such as the simulation period or the time interval for the outputs can be done directly. SWAT simulation outputs can be defined that are returned in a 'tidy' format in R. Functionality such as model parametrization, parallel execution of simulations, or incremental saving of simulation runs is provided.

Usage

run_swat2012(
  project_path,
  output,
  parameter = NULL,
  start_date = NULL,
  end_date = NULL,
  output_interval = NULL,
  years_skip = NULL,
  rch_out_var = NULL,
  sub_out_var = NULL,
  hru_out_var = NULL,
  hru_out_nr = NULL,
  run_index = NULL,
  run_path = NULL,
  n_thread = NULL,
  save_path = NULL,
  save_file = NULL,
  return_output = TRUE,
  add_parameter = TRUE,
  add_date = TRUE,
  refresh = TRUE,
  keep_folder = FALSE,
  quiet = FALSE
)

Arguments

project_path

Character string that provides the path to the SWAT project folder (i.e. TxtInOut).

output

Define the output variables to extract from the SWAT model runs. See function define_output help file to see how to define simulation outputs.

parameter

(optional) SWAT model parameters either provided as named vector or a tibble. The parameter changes provided with parameter are performed during the model execution accordingly. To learn how to modify parameters see the Get started page of SWATplusR.

start_date

(optional) Start date of the SWAT simulation. Provided as character string in a ymd format (e.g. 'yyyy-mm-dd') or in Date format.

end_date

(optional) End date of the SWAT simulation. Provided as character string in a ymd format (e.g. 'yyyy-mm-dd') or in Date format.

output_interval

(optional) Time interval in which the SWAT model outputs are written. Provided either as character string ("d" for daily, "m" for monthly, or "y" for yearly) or as SWAT input values (0 for monthly, 1 for daily, 2 for yearly).

years_skip

(optional) Integer value to define the number of simulation years that are skipped before writing SWAT model outputs.

rch_out_var

(optional) Numeric vector of maximum length = 20 for customized output of reach variables. For output codes see the SWAT I/O Documentation p.77ff.

sub_out_var

(optional) Numeric vector of maximum length = 15 for customized output of subbasin variables.For output codes see the SWAT I/O Documentation p.78ff.

hru_out_var

(optional) Numeric vector of maximum length = 20 for customized output of HRU variables.For output codes see the SWAT I/O Documentation p.79ff.

hru_out_nr

(optional) Numeric vector of maximum length = 20 for providing the HRU numbers for which the HRU variables are written. Optional if hru_out_nr = 'all', HRU variables are written for all HRU (caution, very large output files possible!)

run_index

(optional) Numeric vector (e.g.run_index = c(1:100, 110, 115)) to run a subset of the provided parameter sets. If NULL all provided parameter sets are used in the simulation.

run_path

(optional) Character string that provides the path where the '.model_run' folder is written and the SWAT models are executed. If NULL '.model_run' is built in the project folder.

n_thread

(optional) Number of threads to be used for the parallel model run. If not provided models are run on single core. The parameter is ineffective for single simulations.

save_path

(optional) Character string to define the path where the model runs are saved if save_file is defined. If save_path = NULL the folder save_file is saved in the project_path.

save_file

(optional) Character string to define the name of the folder where data bases are generated that store the simulations incrementally.

return_output

(optional) Logical. Whether outputs should be returned or not. Set return_out = FALSE and provide save_file if outputs should only be saved on the hard drive and not be returned in R. 'Default = TRUE

add_parameter

(optional) Logical. If add_parameter = TRUE, the values of the parameter changes and information on the changes are saved and/or returned together with the model outputs. Default = TRUE

add_date

(optional) Logical. If add_date = TRUE a date column is added to every simulation output table. Default = TRUE

refresh

(optional) Logical. refresh = TRUE always forces that '.model_run' is newly written when SWAT run ins started. Default = TRUE

keep_folder

(optional) Logical. If keep_folder = TRUE '.model_run' is kept and not deleted after finishing model runs. In this case '.model_run' is reused in a new model run if refresh = FALSE. Default = FALSE

quiet

(optional) Logical. If quiet = TRUE no messages are written. Default = FALSE

Value

Returns the simulation results for the defined output variables as a tibble. If more than one parameter set was provided a list of tibbles is returned where each column is a model run and each list entry is an output variable.

Examples

To learn the basics on how to use SWATplusR see the Get started page on the package's github page.