View source: R/swWeatherGenerator.R
dbW_fixWeather | R Documentation |
Missing values are "fixed"
with the following approach:
weatherData
is formatted for rSOILWAT2
, i.e., converted to a
Gregorian calendar and required but missing variables added.
Short spells of missing values
(consecutive days shorter than nmax_interp
) are linearly interpolated
from adjacent non-missing values
(meta data tag "interpolateLinear (<= X days)"
)
Short spells of missing precipitation values are
Linearly interpolated if precip_lt_nmax
is NA
Set to a fixed numeric value of precip_lt_nmax
(meta data tag "fixedValue"
)
Substituted with values from subData
if precip_lt_nmax
is Inf
(see next point)
Values from a second weather data object subData
are used to replace
(meta data tag substituteData"
):
Missing precipitation values (if precip_lt_nmax
is Inf
)
Values before first day with any non-missing values
Variables absent in weatherData
and present in subData
Long-term daily means are used to replace any remaining missing values
(meta data tag "longTermDailyMean"
);
for instance, this approach may be applied for
Values of variables that are present in weatherData
and
absent in subData
, before first day with any non-missing values
Values after end of available values in both weatherData
and
subData
dbW_fixWeather(
weatherData,
subData = NULL,
new_startYear = NULL,
new_endYear = NULL,
nmax_interp = 7L,
precip_lt_nmax = 0,
return_weatherDF = FALSE
)
weatherData |
A list of elements of class |
subData |
A weather data object. |
new_startYear |
An integer value. The first Calendar year of the new
time period. If |
new_endYear |
An integer value. The last Calendar year of the new
time period. If |
nmax_interp |
An integer value. Maximum spell length of missing values for which linear interpolation is applied. |
precip_lt_nmax |
A numeric value. Should short spells of
missing precipitation values be
linearly interpolated (if |
return_weatherDF |
A logical value. See section "Value". |
A list with two named elements
"weatherData"
: An updated copy of the input weatherData
where missing values have been replaced.
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
.
"meta"
: a data frame with the same dimensions as "weatherData"
with tags indicating which approach was used to replaced missing values
in corresponding cells of weatherData
(see section Details
)
dbW_imputeWeather()
, dbW_substituteWeather()
,
dbW_generateWeather()
x0 <- x <- dbW_weatherData_to_dataframe(rSOILWAT2::weatherData)
tmp <- x[, "Year"] == 1981
ids_to_interp <- tmp & x[, "DOY"] >= 144 & x[, "DOY"] <= 145
x[ids_to_interp, -(1:2)] <- NA
tmp <- x[, "Year"] == 1980
ids_to_sub <- tmp & x[, "DOY"] >= 153 & x[, "DOY"] <= 244
x[ids_to_sub, -(1:2)] <- NA
xf <- dbW_fixWeather(x, x0, return_weatherDF = TRUE)
all.equal(
xf[["weatherData"]][!ids_to_interp, ],
as.data.frame(x0)[!ids_to_interp, ]
)
table(xf[["meta"]])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.