getWeatherData_folders: Reads daily weather data from files

View source: R/sw_dbW_WeatherDatabase.R

getWeatherData_foldersR Documentation

Reads daily weather data from files

Description

SOILWAT2 does not handle missing weather data. If you have missing data, then you have to impute yourself or use the built-in Markov weather generator (see examples for sw_exec).

Usage

getWeatherData_folders(
  LookupWeatherFolder,
  weatherDirName = NULL,
  filebasename = "weath",
  startYear = NULL,
  endYear = NULL,
  dailyInputFlags = c(rep(TRUE, 3L), rep(FALSE, 11L)),
  method = c("R", "C")
)

Arguments

LookupWeatherFolder

A character string. The path to the parent folder of weatherDirName.

weatherDirName

String. Name of the folder with the daily weather data files.

filebasename

String. File prefix for weather data. Usually weath.

startYear

Numeric. Extracted weather data will start with this year.

endYear

Numeric. Extracted weather data will end with this year.

dailyInputFlags

A logical vector of length MAX_INPUT_COLUMNS, see "weathsetup.in".

method

A character string. "R" uses code in R to read files as-is whereas "C" uses "SOILWAT2" code to read and process files.

Value

A list of elements of class swWeatherData.

Details

dbW_weather_to_SOILWATfiles() offers the inverse operation, i.e., writing weather data to disk files.

See Also

dbW_getWeatherData

Examples


path_demo <- system.file("extdata", "example1", package = "rSOILWAT2")

## ------ Simulation with data prepared beforehand and separate weather data
## Read inputs from files on disk (via SOILWAT2)
sw_in3 <- sw_inputDataFromFiles(dir = path_demo, files.in = "files.in")

## Read forcing weather data from files on disk (via SOILWAT2)
sw_weath3c <- getWeatherData_folders(
  LookupWeatherFolder = file.path(path_demo, "Input"),
  weatherDirName = "data_weather",
  filebasename = "weath",
  startYear = 1979,
  endYear = 2010,
  method = "C"
)

## Read forcing weather data from files on disk (via R)
sw_weath3r <- getWeatherData_folders(
  LookupWeatherFolder = file.path(path_demo, "Input"),
  weatherDirName = "data_weather",
  filebasename = "weath",
  startYear = 1979,
  endYear = 2010,
  method = "R"
)

## Weather data (for the non-calculated variables) should be identical
identical(
  sw_weath3c[[1L]]@data[, 1:4],
  rSOILWAT2::get_WeatherHistory(sw_in3)[[1L]]@data[, 1:4]
)
identical(
  sw_weath3r[[1L]]@data[, 1:4],
  rSOILWAT2::get_WeatherHistory(sw_in3)[[1L]]@data[, 1:4]
)

## List of the slots of the input objects of class 'swWeatherData'
utils::str(sw_weath3c, max.level = 1)
utils::str(sw_weath3r, max.level = 1)

## Execute the simulation run
sw_out3c <- sw_exec(inputData = sw_in3, weatherList = sw_weath3c)
sw_out3r <- sw_exec(inputData = sw_in3, weatherList = sw_weath3r)

all.equal(sw_out3c, sw_out3r)


Burke-Lauenroth-Lab/rSOILWAT2 documentation built on Dec. 9, 2023, 1:46 a.m.