dbW_generateWeather: Generate daily weather data using SOILWAT2's weather...

View source: R/swWeatherGenerator.R

dbW_generateWeatherR Documentation

Generate daily weather data using SOILWAT2's weather generator

Description

This function is a convenience wrapper for dbW_estimate_WGen_coefs().

Usage

dbW_generateWeather(
  weatherData,
  years = NULL,
  wgen_coeffs = NULL,
  imputation_type = "mean",
  imputation_span = 5L,
  return_weatherDF = FALSE,
  digits = NA,
  seed = NULL
)

Arguments

weatherData

A list of elements of class swWeatherData or a data frame as returned by dbW_weatherData_to_dataframe().

years

An integer vector. The calendar years for which to generate daily weather. If NULL, then extracted from weatherData.

wgen_coeffs

A list with two named elements "mkv_doy" and "mkv_woy", i.e., the return value of dbW_estimate_WGen_coefs(). If NULL, then dbW_estimate_WGen_coefs() is called on weatherData.

imputation_type

A text string. Passed to rSW2utils::impute_df() for imputation of missing values in estimated weather generator coefficients.

imputation_span

An integer value. Passed to rSW2utils::impute_df() for imputation of missing values in estimated weather generator coefficients.

return_weatherDF

A logical value. See section "Value".

digits

An integer value. The number of decimal places for rounding weather values (or TRUE but no rounding if FALSE or not finite).

seed

An integer value or NULL. See base::set.seed().

Value

An updated copy of weatherData where missing values are imputed by the weather generator. If return_weatherDF is TRUE, then the result is converted to a data frame where columns represent weather variables. If return_weatherDF is FALSE, then the result is a list of elements of class swWeatherData.

Details

The current implementation of the weather generator produces values only for variables in weatherGenerator_dataColumns(). Values are generated for those days where at least one of the implemented variables is missing; if any value is missing, then values for that day of all implemented variables will be replaced by those produced by the weather generator.

See Also

dbW_imputeWeather()

Examples

# Load data for 1949-2010
wdata <- data.frame(dbW_weatherData_to_dataframe(rSOILWAT2::weatherData))

# Treat data for 2005-2010 as our 'dataset'
ids <- wdata[, "Year"] >= 2005
x <- wdata[ids, ]

# Set June-August of 2008 as missing
ids <- x[, "Year"] == 2008 & x[, "DOY"] >= 153 & x[, "DOY"] <= 244
x[ids, -(1:2)] <- NA

## Example 1: generate weather for any missing values in our 'dataset'
wout1 <- dbW_generateWeather(x, return_weatherDF = TRUE)

## Example 2: generate weather based on our 'dataset' but for
## years 2005-2015 and use estimated weather generator coefficients from
## a different dataset
wgen_coeffs <- dbW_estimate_WGen_coefs(
  wdata,
  imputation_type = "mean",
  imputation_span = 5
)

# Set seed to make output reproducible
wout2 <- dbW_generateWeather(
  x,
  years = 2005:2015,
  wgen_coeffs = wgen_coeffs,
  seed = 123
)

## Example 3: generate weather based only on estimated weather generator
## coefficients from a different dataset
x_empty <- weatherHistory()
wout3 <- dbW_generateWeather(
  x_empty,
  years = 2050:2055,
  wgen_coeffs = wgen_coeffs,
  seed = 123
)

## Compare input weather with generated weather
path <- tempdir()
compare_weather(
  ref_weather = x,
  weather = wout1,
  N = 1,
  path = path,
  tag = "Example1-WeatherGenerator"
)
unlink(list.files(path), force = TRUE)


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