Skip to contents

This function interpolates weather data for a SWAT model and saves results into nested list format. The function uses Inverse Distance Weighting (IDW) interpolation method to fill gaps in weather data. This function uses sp and gstat packages for spatial operations. Please make sure that these packages are installed before using this function.

Usage

interpolate(
  meteo_lst,
  catchment_boundary_path,
  dem_data_path,
  grid_spacing,
  p_vector = c("PCP", "SLR", "RELHUM", "WNDSPD", "TMP_MAX", "TMP_MIN"),
  idw_exponent = 2
)

Arguments

meteo_lst

A nested list with dataframes. Nested structure: meteo_lst -> data -> Station ID -> Parameter -> Dataframe (DATE, PARAMETER), meteo_lst -> stations -> Dataframe (ID, Name, Elevation, Source, geometry, Long, Lat).

meteo_lst can be created using load_template function using 'xlsx' template file or it could to be created with load_swat_weather function loading information from SWAT+ model setup weather files.

catchment_boundary_path

Character, path to the basin boundary shape file.

dem_data_path

Character, path to DEM raster data in the same projection as the weather station.

grid_spacing

Numeric, value for the distance between grid points. Units of the coordinate system should be used.

p_vector

(optional) Character vector representing weather variables to interpolate. Default is all variables selected p_vector = c("PCP", "SLR", "RELHUM", "WNDSPD", "TMP_MAX", "TMP_MIN").

idw_exponent

(optional) Numeric value for the exponent parameter to be used in interpolation. Default idw_exponent = 2.

Value

A nested list with interpolation results. A nested list with dataframes. Nested structure: meteo_lst -> data -> Station ID -> Parameter -> Dataframe (DATE, PARAMETER), meteo_lst -> stations -> Dataframe (ID, Name, Elevation, Source, geometry, Long, Lat).

Examples

if (FALSE) {
  # Specify paths to weather  data, basing shapeand DEM
  temp_path <- system.file("extdata", "weather_data.xlsx", package = "SWATprepR")
  DEM_path <- system.file("extdata", "GIS/DEM.tif", package = "SWATprepR")
  basin_path <- system.file("extdata", "GIS/basin.shp", package = "SWATprepR")

  # Load weather data template
  met_lst <- load_template(temp_path, 3035)

  # Interpolate 
  met_lst_int <- interpolate(met_lst, basin_path, DEM_path, 2000) 
}