View source: R/swWeatherGenerator.R
dbW_generateWeather | R Documentation |
This function is a convenience wrapper for dbW_estimate_WGen_coefs()
.
dbW_generateWeather(
weatherData,
years = NULL,
wgen_coeffs = NULL,
imputation_type = "mean",
imputation_span = 5L,
return_weatherDF = FALSE,
digits = NA,
seed = NULL
)
weatherData |
A list of elements of class |
years |
An integer vector. The calendar years for which to generate
daily weather. If |
wgen_coeffs |
A list with two named elements |
imputation_type |
A text string. Passed to |
imputation_span |
An integer value. Passed to |
return_weatherDF |
A logical value. See section "Value". |
digits |
An integer value. The number of decimal places for rounding
weather values (or |
seed |
An integer value or |
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
.
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.
dbW_imputeWeather()
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.