Skip to contents

Combine VBC and the Method of fragments

Usage

vbc_tsub(
  mp,
  mc,
  rc,
  var_names = colnames(rc),
  margins_controls = list(mult = NULL, xmin = NaN, xmax = NaN, bw = NA, deg = 2, type =
    "c"),
  t_subs = list(list(hours = 0:23, month = 1:12)),
  overlap = 1,
  cores_t = NA,
  verbose = TRUE,
  ...
)

Arguments

mp

data.table
Simulation data from a climate model during projection period. Expects one column time.

mc

data.table
Simulation data from a climate model during calibration period. Expects one column time.

rc

data.table
Measured (and interpolated) observations during calibration period. Expects one column time.

var_names

character
Names of corrected climate data. Defaults to the column names of the observed data rc.

margins_controls

list
A list with arguments to be passed to kde1d::kde1d(). Currently, there can be

  • mult numeric vector of length one or d; all bandwidths for marginal kernel density estimation are multiplied with mult. Defaults to log(1 + d) where d is the number of climate variables.

  • xmin numeric vector of length d; see kde1d::kde1d().

  • xmax numeric vector of length d; see kde1d::kde1d().

  • bw numeric vector of length d; see kde1d::kde1d().

  • deg numeric vector of length one or d; kde1d::kde1d().

  • type character vector of length one or d; must be one of c, cont, continuous for continuous variables, one of d, disc, discrete for discrete integer variables, or one of zi, zinfl, zero-inflated for zero-inflated variables.

t_subs

list
A list of two lists: hours and month. Each list contains the temporal indicators to subset the data. The first list contains the hours of the day the length of list marks the number of fragments. The inner list contains the hour and monthly information to subset the data.

overlap

integer
The number of times to overlap the temporal indicators.

cores_t

integer
The number of cores to use for parallel processing of the temporal subsetting. Default is NA which means no parallel processing.

verbose

logical
Print messages during the temporal subsetting.

...


Arguments are passed to rvinecopulib::vinecop to specify the structure of vines and margins. Note that the ellipsis of observed and model data are specified with the same arguments.

Value

data.table
The corrected projection period data in mp. Additionally the data frame contains the attribute mvd with one list per temporal subset. In each subset vine_rc, kde_rc, vine_mp, and kde_mp which store the vine copula and kernel density estimation objects of the observed and model data. The time column is attached to the data.

References

Sharma, A.; Srikanthan, S. (2006): Continuous Rainfall Simulation: A Nonparametric Alternative. In: 30th Hydrology and Water Resources Symposium 4-7 December 2006, Launceston, Tasmania.

Westra, S.; Mehrotra, R.; Sharma, A.; Srikanthan, R. (2012): Continuous rainfall simulation. 1. A regionalized subdaily disaggregation approach. In: Water Resour. Res. 48 (1). DOI: 10.1029/2011WR010489.

Examples

#' \dontrun{
#' # Start with a simple example:
#' # There is one timeline that should be corrected and projection and 
#' # calibaration period are both in 2010.
#' set.seed(1234L)
#' library(VBC)
#' library(data.table)
#' library(patchwork)
#' data("climate")
#' margins_controls <- list(xmin = c(NaN, 0, NaN, 0, 0),
#'                          type = c("c", "zi", "c", "zi", "c"))
#'                   
#' climate_2010 = lapply(climate, function(data) data[year(time) == 2010, ])
#' 
#' mp_vbc = vbc(climate_2010$mp[, -"time"], climate_2010$mp[, -"time"],
#'              climate_2010$rp[, -"time"], margins_controls = margins_controls,
#'              family_set = "tll", trunc_lvl = Inf)                 
#' 
#' plot_tails(climate_2010$mp, "pr", scale_d = 0.1, mult = 4, xmin = 0) 
#' plot_tails(climate_2010$rp, "pr", scale_d = 1, mult = 4, xmin = 0)
#' plot_tails(round(mp_vbc, 3), "pr", scale_d = 1, mult = 3, xmin = 0)
#' calc_wasserstein(climate_2010$mp[, "pr"], climate_2010$rp[, "pr"])
#' calc_wasserstein(climate_2010$rp[, "pr"], mp_vbc[, "pr"])
#' 
#' calc_wasserstein(climate_2010$rp[, -"time"], climate_2010$mp[, -"time"])
#' calc_wasserstein(climate_2010$rp[, -"time"], mp_vbc)
#' 
#' # An example with temporal subsetting using the method of fragments
#'  
#' temp_subs <- list(DJF = list(hours = seq(0, 21, 3), month = c(12, 1, 2)),
#'                   MAM = list(hours = seq(0, 21, 3), month = 3:5),
#'                   JJA = list(hours = seq(0, 21, 3), month = 6:8),
#'                   SON = list(hours = seq(0, 21, 3), month = 9:11))  
#'                                  
#' mp_vbc = vbc_tsub(climate$mp, climate$mc, climate$rc, t_subs = temp_subs,
#'                   margins_controls = margins_controls, family_set = "tll",
#'                   trunc_lvl = Inf)
#' class(mp_vbc)
#' attr(mp_vbc, "mvd")
#' 
#' measure = lapply(temp_subs, function(sub) {
#'    idx = which(hour(mp_vbc$time) %in% sub$hour &
#'                   month(mp_vbc$time) %in% sub$month)
#'    idxrp = which(hour(climate$rp$time) %in% sub$hour &
#'                      month(climate$rp$time) %in% sub$month)
#'    mci = calc_mci(climate$mp[idx, -"time"], mp_vbc[idx, -"time"],
#'                     time = climate$mp$time[idx])
#'    mci = attr(mci, "global_mci")
#'    
#'    uncorrected = calc_wasserstein(climate$rp[idxrp, -"time"],
#'                                     climate$mp[idx, -"time"])
#'    corrected = calc_wasserstein(climate$rp[idxrp, -"time"],
#'                                 mp_vbc[idx, -"time"])
#'    data.table(
#'        ModelCorrectionInconsistancy = mci,
#'        Wasserstein2_uncorrected = uncorrected[2],
#'        Wasserstein2_corrected = corrected[2],
#'        Improvement_Wasserstein2 = uncorrected[2] - corrected[2], 
#'        month = paste(sub$month, collapse = "-")
#'        )
#' })
#' rbindlist(measure)
#' }