dbW_estimate_WGen_coefs: Estimate coefficients of the 'SOILWAT2' weather generator

View source: R/swWeatherGenerator.R

dbW_estimate_WGen_coefsR Documentation

Estimate coefficients of the SOILWAT2 weather generator

Description

Estimated coefficients correspond to what is required by the two files "mkv_covar.in" and "mkv_prob.in" for the first-order Markov weather generator in SOILWAT2 ⁠> v4.2.5⁠.

Usage

dbW_estimate_WGen_coefs(
  weatherData,
  WET_limit_cm = 0,
  propagate_NAs = FALSE,
  valNA = NULL,
  imputation_type = c("none", "mean", "locf"),
  imputation_span = 5L
)

Arguments

weatherData

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

WET_limit_cm

A numeric value. A day with more precipitation than this value is considered wet instead of dry. Default is 0. This values should be equal to the corresponding value used in SOILWAT2's function SW_MKV_today().

propagate_NAs

A logical value. If TRUE, then missing weather values in the input weatherData are excluded; if FALSE, then missing values are propagated to the estimation. See Details.

valNA

The (numerical) value of missing weather data. If NULL, then default values are interpreted as missing.

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.

Value

A list with two named elements:

  • "mkv_doy": A data frame with 366 rows (day of year) and 5 columns:

    • "DOY": Rows represent day of year.

    • "p_W_W": Probability that DOY is wet if the previous day (doy - 1) was wet.

    • "p_W_D": Probability that DOY is wet if the previous day (doy - 1) was dry.

    • "PPT_avg": Average amount of precipitation ⁠[cm]⁠ on DOY if wet.

    • "PPT_sd": Standard deviation of amount of precipitation ⁠[cm]⁠ on DOY if wet.

  • "mkv_woy": A data frame with 53 rows SOILWAT2 weeks of year (i.e., consecutive heptads of days) and 11 columns

    • "WEEK": Rows represent week of year.

    • "wTmax_C": Average daily maximum temperature ⁠[C]⁠ for week.

    • "wTmin_C": Average daily minimum temperature ⁠[C]⁠ for week.

    • "var_MAX": Variance of daily maximum temperature for week.

    • "cov_MAXMIN": Covariance of daily maximum and minimum temperatures for week.

    • "cov_MINMAX": Identical to "cov_MAXMIN".

    • "var_MIN": Variance of daily minimum temperature for week.

    • "CF_Tmax_wet": Difference between average daily maximum temperature ⁠[C]⁠ for wet days of week and "wTmax_C".

    • "CF_Tmax_dry": Difference between average daily maximum temperature ⁠[C]⁠ for dry days of week and "wTmax_C".

    • "CF_Tmin_wet": Same as "CF_Tmax_wet" but for daily minimum temperature.

    • "CF_Tmin_dry": Same as "CF_Tmax_dry" but for daily minimum temperature.

Notes

This code is a complete overhaul compared to the version from rSFSTEP2 on 2019-Feb-10.

This function will produce NAs in the output if there are insufficient weather observation in the input data weatherData for a specific day or week of the year. Such NAs will cause a SOILWAT2 run to fail (potentially non-graciously and with non-obvious error messages). To avoid that, this function offers imputation approaches in order to fill in those failed coefficient estimates; see rSW2utils::impute_df(), but please note that any such imputation likely introduces biases in the generated weather.

Details

Most users will likely want to set propagate_NAs to FALSE. Note: propagate_NAs corresponds to !na.rm from previous versions of this function with a different default value. Consider an example: a the 30-year long input weatherData is complete except for missing values on Jan 1, 2018.

  • If propagate_NAs is set to TRUE, then the coefficients for day 1 and week 1 of year will be NA – despite all the available data. In this case, the missing coefficients for day 1 and week 1 of year will be imputed.

  • If propagate_NAs is set to FALSE, then the coefficients for day 1 and week 1 of year will be calculated based on the non-missing values for that day respectively that week of year. No imputation occurs.

See Also

print_mkv_files() to print values to SOILWAT2 compatible files. swMarkov_Prob() and swMarkov_Conv() to extract/replace values in a rSOILWAT2 input object of class swInputData.

Examples

res1 <- dbW_estimate_WGen_coefs(rSOILWAT2::weatherData)
wdata <- data.frame(dbW_weatherData_to_dataframe(rSOILWAT2::weatherData))
res2 <- dbW_estimate_WGen_coefs(wdata)

sw_in <- rSOILWAT2::sw_exampleData
swMarkov_Prob(sw_in) <- res2[["mkv_doy"]]
swMarkov_Conv(sw_in) <- res2[["mkv_woy"]]


Burke-Lauenroth-Lab/Rsoilwat documentation built on Dec. 9, 2023, 12:41 a.m.