Updates daily SWAT temperature files (`tmp*.tmp`) using alternative maximum and minimum temperature products provided as dataframes of subbasin time series, typically estimated with areal_mean. This enables forcing SWAT with different gridded temperature datasets instead of the original inputs.
Usage
tmp2swat(tmax, tmin, tmp, output_dir = getwd())Arguments
- tmax
A dataframe where the first column ('Date') contains dates in "yyyy-mm-dd" format, and the remaining columns contain subbasin maximum temperature values. This dataframe is typically produced by areal_mean.
- tmin
A dataframe with the same structure as `tmax`, but containing subbasin minimum temperature values.
- tmp
A vector of file paths to existing `tmp*.tmp` files, used as templates for writing the updated temperature data.
- output_dir
A character string specifying the directory where the updated files will be written. Defaults to the current working directory.
See also
Other Preprocessing tools:
areal_mean(),
pcp2swat(),
pcp2swat_editor(),
tmp2swat_editor()
Examples
# \donttest{
# Prepare example SWAT TxtInOut and NetCDF inputs
tmpdir <- tempdir()
txtinout <- get_swat_example(tmpdir)
tmp_files <- list.files(file.path(txtinout), pattern = "^tmp.*\\.tmp$", full.names = TRUE)
tmax_nc <- system.file("extdata", "tasmax.nc", package = "hydroSWAT")
tmin_nc <- system.file("extdata", "tasmin.nc", package = "hydroSWAT")
tmax_grid <- terra::rast(tmax_nc)
tmin_grid <- terra::rast(tmin_nc)
# Example subbasin polygons from the package
data(subs1, package = "hydroSWAT")
# Compute areal means
tmax_data <- areal_mean(tmax_grid, subs1, "2010-01-01", time_step = "day")
tmin_data <- areal_mean(tmin_grid, subs1, "2010-01-01", time_step = "day")
# Update tmp*.tmp files
outdir <- file.path(tmpdir, "updated_tmp")
dir.create(outdir)
tmp2swat(tmax_data, tmin_data, tmp_files, output_dir = outdir)
# }