diff --git a/R/CST_QuantileMapping.R b/R/CST_QuantileMapping.R index cbb76c9937942d98254e625eb9c8637a26d34307..257b5b6203817b5a34c07add6981f55c3e6aaf20 100644 --- a/R/CST_QuantileMapping.R +++ b/R/CST_QuantileMapping.R @@ -8,18 +8,20 @@ #'@author Nuria Perez-Zanon, \email{nuria.perez@bsc.es} #'@param exp An object of class \code{s2dv_cube}. #'@param obs An object of class \code{s2dv_cube}. -#'@param exp_cor An object of class \code{s2dv_cube} in which the quantile -#' mapping correction should be applied. If it is not specified, the correction -#' is applied in object 'exp'. +#'@param exp_cor A multidimensional array with named dimensions in which the +#'quantile mapping correction should be applied. If it is not specified, the +#'correction is applied to object 'exp' using leave-one-out cross-validation. +#'This is useful to correct a forecast when the hindcast is provided in parameter 'exp'. #'@param sdate_dim A character string indicating the dimension name in which #' cross-validation would be applied when exp_cor is not provided. 'sdate' by #' default. #'@param memb_dim A character string indicating the dimension name where #' ensemble members are stored in the experimental arrays. It can be NULL if #' there is no ensemble member dimension. It is set as 'member' by default. -#'@param window_dim A character string indicating the dimension name where -#' samples have been stored. It can be NULL (default) in case all samples are -#' used. +#'@param window_dim A character string indicating the dimension name in which extra +#'samples are stored. This dimension is joined to the 'member' dimension. +#'This is useful to correct daily data, for which robust statistics can be obtained +#'by creating a window of dates around the target date. #'@param method A character string indicating the method to be used:'PTF', #' 'DIST', 'RQUANT', 'QUANT', 'SSPLIN'. By default, the empirical quantile #' mapping 'QUANT' is used. @@ -99,17 +101,19 @@ CST_QuantileMapping <- function(exp, obs, exp_cor = NULL, sdate_dim = 'sdate', #'@param obs A multidimensional array with named dimensions containing the #' reference dataset. #'@param exp_cor A multidimensional array with named dimensions in which the -#' quantile mapping correction should be applied. If it is not specified, the -#' correction is applied on object 'exp'. +#'quantile mapping correction should be applied. If it is not specified, the +#'correction is applied to object 'exp' using leave-one-out cross-validation. +#'This is useful to correct a forecast when the hindcast is provided in parameter 'exp'. #'@param sdate_dim A character string indicating the dimension name in which #' cross-validation would be applied when exp_cor is not provided. 'sdate' by #' default. #'@param memb_dim A character string indicating the dimension name where #' ensemble members are stored in the experimental arrays. It can be NULL if #' there is no ensemble member dimension. It is set as 'member' by default. -#'@param window_dim A character string indicating the dimension name where -#' samples have been stored. It can be NULL (default) in case all samples are -#' used. +#'@param window_dim A character string indicating the dimension name in which extra +#'samples are stored. This dimension is joined to the 'member' dimension. +#'This is useful to correct daily data, for which robust statistics can be obtained +#'by creating a window of dates around the target date. #'@param method A character string indicating the method to be used: 'PTF', #' 'DIST', 'RQUANT', 'QUANT', 'SSPLIN'. By default, the empirical quantile #' mapping 'QUANT' is used. @@ -126,14 +130,15 @@ CST_QuantileMapping <- function(exp, obs, exp_cor = NULL, sdate_dim = 'sdate', #'@seealso \code{\link[qmap]{fitQmap}} and \code{\link[qmap]{doQmap}} #'@examples #'# Use synthetic data -#'exp <- 1 : c(1 * 3 * 5 * 4 * 3 * 2) -#'dim(exp) <- c(dataset = 1, member = 3, sdate = 5, ftime = 4, -#' lat = 3, lon = 2) -#'obs <- 101 : c(100 + 1 * 1 * 5 * 4 * 3 * 2) -#'dim(obs) <- c(dataset = 1, member = 1, sdate = 5, ftime = 4, -#' lat = 3, lon = 2) -#'res <- QuantileMapping(exp, obs) -#' +#'set.seed(123) +#'exp <- as.numeric(1:prod(6,10,15)) +#'dim(exp) <- c(member = 6, syear = 10, window = 15) +#'obs <- as.numeric(rnorm(prod(1,10,15), 50)) +#'dim(obs) <- c(member = 1, syear = 10, window = 15) +#'fcst <- 100*(1:prod(8,1,1)) +#'dim(fcst) <- c(member = 8, syear = 1, swindow = 1) +#'res <- QuantileMapping(exp = exp, obs = obs, exp_cor = fcst, memb_dim = 'member', +#' sdate_dim = 'syear', window_dim = 'window') #'@import qmap #'@import multiApply #'@import s2dv diff --git a/man/CST_QuantileMapping.Rd b/man/CST_QuantileMapping.Rd index 0ca3423f9d64002f088417482ca195593cb8bdff..e20ecb561359cc96da57b62b2d79d5938bed92e0 100644 --- a/man/CST_QuantileMapping.Rd +++ b/man/CST_QuantileMapping.Rd @@ -22,9 +22,10 @@ CST_QuantileMapping( \item{obs}{An object of class \code{s2dv_cube}.} -\item{exp_cor}{An object of class \code{s2dv_cube} in which the quantile -mapping correction should be applied. If it is not specified, the correction -is applied in object 'exp'.} +\item{exp_cor}{A multidimensional array with named dimensions in which the +quantile mapping correction should be applied. If it is not specified, the +correction is applied to object 'exp' using leave-one-out cross-validation. +This is useful to correct a forecast when the hindcast is provided in parameter 'exp'.} \item{sdate_dim}{A character string indicating the dimension name in which cross-validation would be applied when exp_cor is not provided. 'sdate' by @@ -34,9 +35,10 @@ default.} ensemble members are stored in the experimental arrays. It can be NULL if there is no ensemble member dimension. It is set as 'member' by default.} -\item{window_dim}{A character string indicating the dimension name where -samples have been stored. It can be NULL (default) in case all samples are -used.} +\item{window_dim}{A character string indicating the dimension name in which extra +samples are stored. This dimension is joined to the 'member' dimension. +This is useful to correct daily data, for which robust statistics can be obtained +by creating a window of dates around the target date.} \item{method}{A character string indicating the method to be used:'PTF', 'DIST', 'RQUANT', 'QUANT', 'SSPLIN'. By default, the empirical quantile diff --git a/man/CST_Start.Rd b/man/CST_Start.Rd index b95f51ec415c8ef1aa1b9e57690406c2325fd99b..ce5c4119da4f654bdf11f45fda9a13dd1d376b8d 100644 --- a/man/CST_Start.Rd +++ b/man/CST_Start.Rd @@ -24,6 +24,11 @@ It receives any number of parameters (`...`) that are automatically forwarded to the `startR::Start` function. See details in `?startR::Start`. The auxiliary startR functions (e.g. indices(), values(), Sort(), CircularSort(), CDORemapper(), ...) can be used to define dimensions. + +CST_Start() uses as.s2dv_cube() to transform the output into an s2dv_cube +object. The as.s2dv_cube() function is designed to be used with data that +has been retrieved into memory. To avoid errors, please ensure that +CST_Start(..., retrieve = TRUE) is specified. } \examples{ \dontrun{ @@ -43,7 +48,7 @@ CDORemapper(), ...) can be used to define dimensions. latitude = c('lat', 'latitude')), return_vars = list(time = 'sdate', longitude = NULL, latitude = NULL), - retrieve = FALSE) + retrieve = TRUE) } \dontshow{ exp <- CSTools::lonlat_temp_st$exp diff --git a/man/QuantileMapping.Rd b/man/QuantileMapping.Rd index a1ff178de2c0170e6b2a675bf7a9747beb0b4ff2..ffd39f882ca21cd469bdfdd7ea84377d93df6e33 100644 --- a/man/QuantileMapping.Rd +++ b/man/QuantileMapping.Rd @@ -25,8 +25,9 @@ hindcast.} reference dataset.} \item{exp_cor}{A multidimensional array with named dimensions in which the -quantile mapping correction should be applied. If it is not specified, the -correction is applied on object 'exp'.} +quantile mapping correction should be applied. If it is not specified, the +correction is applied to object 'exp' using leave-one-out cross-validation. +This is useful to correct a forecast when the hindcast is provided in parameter 'exp'.} \item{sdate_dim}{A character string indicating the dimension name in which cross-validation would be applied when exp_cor is not provided. 'sdate' by @@ -36,9 +37,10 @@ default.} ensemble members are stored in the experimental arrays. It can be NULL if there is no ensemble member dimension. It is set as 'member' by default.} -\item{window_dim}{A character string indicating the dimension name where -samples have been stored. It can be NULL (default) in case all samples are -used.} +\item{window_dim}{A character string indicating the dimension name in which extra +samples are stored. This dimension is joined to the 'member' dimension. +This is useful to correct daily data, for which robust statistics can be obtained +by creating a window of dates around the target date.} \item{method}{A character string indicating the method to be used: 'PTF', 'DIST', 'RQUANT', 'QUANT', 'SSPLIN'. By default, the empirical quantile @@ -65,14 +67,15 @@ applied to the experiment itself or to a provided forecast. } \examples{ # Use synthetic data -exp <- 1 : c(1 * 3 * 5 * 4 * 3 * 2) -dim(exp) <- c(dataset = 1, member = 3, sdate = 5, ftime = 4, - lat = 3, lon = 2) -obs <- 101 : c(100 + 1 * 1 * 5 * 4 * 3 * 2) -dim(obs) <- c(dataset = 1, member = 1, sdate = 5, ftime = 4, - lat = 3, lon = 2) -res <- QuantileMapping(exp, obs) - +set.seed(123) +exp <- as.numeric(1:prod(6,10,15)) +dim(exp) <- c(member = 6, syear = 10, window = 15) +obs <- as.numeric(rnorm(prod(1,10,15), 50)) +dim(obs) <- c(member = 1, syear = 10, window = 15) +fcst <- 100*(1:prod(8,1,1)) +dim(fcst) <- c(member = 8, syear = 1, swindow = 1) +res <- QuantileMapping(exp = exp, obs = obs, exp_cor = fcst, memb_dim = 'member', + sdate_dim = 'syear', window_dim = 'window') } \seealso{ \code{\link[qmap]{fitQmap}} and \code{\link[qmap]{doQmap}} diff --git a/src/CSTools.so b/src/CSTools.so index dcf5b0f54c8bdae91f78059af38e8d98122296af..ad315c92a8c3dccf01592ea0c9f32b267a0490c5 100755 Binary files a/src/CSTools.so and b/src/CSTools.so differ