Skip to contents

Evaluates SWAT model performance by comparing simulated and observed data using user-selected or all available goodness-of-fit (GOF) metrics at daily, monthly, and annual time steps.

Usage

evaluate_swat(
  rch_output,
  observed_data,
  target_id,
  variable,
  metrics,
  start_dates,
  end_dates,
  all_metrics = FALSE
)

Arguments

rch_output

data frame. SWAT model output for one or more reaches, typically generated with output_rch. Must include columns RCH (reach ID), MON (dates), and the simulated variable of interest (e.g., FLOW_OUTcms).

observed_data

data frame. Observed data for one or more reaches, including columns Date (observation date), value (observed values), and target_id (reach ID).

target_id

numeric. Reach ID to evaluate.

variable

character. Name of the variable to evaluate (e.g., "FLOW_OUTcms"). Use get_swat_vars("rch") to list available variables.

metrics

character vector. Goodness-of-fit metrics to compute (e.g., c("NSE","KGE","MAE","PBIAS")).

start_dates

character vector. Start dates for evaluation periods in "YYYY-MM-DD" format.

end_dates

character vector. End dates for evaluation periods in "YYYY-MM-DD" format. Must match length of start_dates.

all_metrics

logical. Whether to calculate all available metrics. Defaults to FALSE.

Value

A list of data frames:

  • evaluation_metric: Evaluation metrics for daily, monthly, and annual time steps. Daily metrics are included only if daily data are available.

  • daily_data: Daily observed and simulated values (if available).

  • monthly_data: Monthly observed and simulated values with the same structure as daily_data.

  • annual_data: Annual observed and simulated values with the same structure as daily_data. These three data frames (daily_data, monthly_data, annual_data) are designed for use with plot_timeseries.

  • mean_annual_cycle: Mean annual cycle of observed and simulated values. Columns: source, period, month, value. This object is used by plot_mean_annual_cycle.

  • daily_fdc_data: Daily data for flow duration curves (FDC). Columns: source, period, date, value. This object is used by plot_fdc.

Examples

tmpdir <- tempdir()
get_swat_example(tmpdir)
rch_file <- file.path(tmpdir, "TxtInOut", "output.rch")
rch_data <- output_rch(
  file = rch_file, variable = "FLOW_OUTcms",
  target_id = 3, time_step = "daily",
  output_start_date = "2011-01-01"
)

observed_data <- tibble::tibble(
  Date = qobserved$Date,
  value = qobserved$Flow,
  target_id = 3
)

evaluation_results <- evaluate_swat(
  rch_output = rch_data,
  observed_data = observed_data,
  target_id = 3,
  variable = "FLOW_OUTcms",
  metrics = c("NSE","KGE","MAE","PBIAS"),
  start_dates = c("2011-01-01","2014-01-01"),
  end_dates = c("2013-12-31","2015-12-31")
)
head(evaluation_results$evaluation_metric)