Skip to contents

Modifies the value of a single SWAT model parameter in one or more input files. Typically used for calibration or sensitivity analysis at the subbasin or global level. This function is used by change_multiple_parameters and supports calibrate_swat for multi-objective calibration workflows.

Usage

change_parameter(
  subbasins = NULL,
  component,
  parameter,
  value,
  method,
  version = "SWAT",
  plant_type = NULL
)

Arguments

subbasins

numeric. Vector of subbasin IDs where the parameter change should be applied. If `NULL` (default), changes are applied globally.

component

character. SWAT input component (e.g., `".gw"`, `".mgt"`, `"plant.dat"`, `"basins.bsn"`) for the corresponding parameter to modify. See get_swat_parameters.

parameter

character. Name of the SWAT parameter to modify within the defined `component`.

value

numeric. New value or adjustment factor for the parameter.

method

character. Method for applying the change:

  • `"v"`: Replace the value.

  • `"r"`: Relative change (e.g., `0.1` increases the current value by 10

version

character. SWAT version (`"SWAT"` or `"SWAT_T"`). Default is `"SWAT"`.

plant_type

character. Type of plant to modify. Required when `component = "plant.dat"`.

Value

A list (class `"changed_parameter"`) summarizing the applied changes, including all input arguments and the modified files.

Details

For component = ".wgn" and ".pcp", only method = "r" is supported. For component = "plant.dat", plant_type is required. The function expects to run inside the SWAT project's TxtInOut folder.

Examples

# \donttest{
tmpdir <- tempdir()

# Get example SWAT project
get_swat_example(tmpdir)
setwd(file.path(tmpdir, "TxtInOut"))

# Modify GW_DELAY in .gw globally
change_parameter(
  component = ".gw",
  parameter = "GW_DELAY",
  value = 30,
  method = "v"
)

# Apply a relative change to CN2 in .mgt for subbasins 1 and 2
change_parameter(
  subbasins = c(1, 2),
  component = ".mgt",
  parameter = "CN2",
  value = 0.1,
  method = "r"
)
# }