From ea99a6e1fbcb9072fc184d194a582b419b898f8a Mon Sep 17 00:00:00 2001 From: nperez Date: Wed, 23 Sep 2020 16:25:50 +0200 Subject: [PATCH 01/20] attemp 1 Apply --- R/CST_RainFARM.R | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index 49065a97..fe8c07b1 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -238,11 +238,11 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, warning(paste("Selected time dim:", time_dim)) } # Check if slope is an array - if (length(slope) > 1) { - warning("Parameter 'slope' has length > 1 and only the first ", - "element will be used.") - slope <- as.numeric(slope[1]) - } + #if (length(slope) > 1) { + # warning("Parameter 'slope' has length > 1 and only the first ", + # "element will be used.") + # slope <- as.numeric(slope[1]) + #} # Perform common calls r <- lon_lat_fine(lon, lat, nf) @@ -259,10 +259,18 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, dim(data) <- c(cdim[ind], rainfarm_samples = prod(cdim[-ind])) # Repeatedly apply .RainFARM - result <- Apply(data, c(lon_dim, lat_dim, "rainfarm_samples"), .RainFARM, - weights, nf, nens, slope, kmin, - fglob, fsmooth, ncores = nprocs, verbose, - split_factor = "greatest")$output1 + if (length(weights) == 1 & length(slope) == 1) { + result <- Apply(data, c(lon_dim, lat_dim, "rainfarm_samples"), .RainFARM, + weights, nf, nens, slope, kmin, + fglob, fsmooth, ncores = nprocs, verbose, + split_factor = "greatest")$output1 + } else { + result <- Apply(list(data, weights, slope), + list(c(lon_dim, lat_dim, "rainfarm_samples"), NULL, NULL), .RainFARM, + nf, nens, kmin, + fglob, fsmooth, ncores = nprocs, verbose, + split_factor = "greatest")$output1 + } # result has dims: lon, lat, rainfarm_samples, realization, other dims # Expand back rainfarm_samples to compacted dims dim(result) <- c(dim(result)[1:2], cdim[-ind], dim(result)[-(1:3)]) -- GitLab From da50209cb2ef99ecf75cd98b65fa30010555d7fd Mon Sep 17 00:00:00 2001 From: nperez Date: Mon, 28 Sep 2020 18:36:55 +0200 Subject: [PATCH 02/20] CST_RainFARM allows slope vector and multi-dim weights --- R/CST_RainFARM.R | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index fe8c07b1..de06f353 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -212,8 +212,8 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, " lat: [", lat[1], ", ", lat[length(lat)], "]")) } if (!(length(dim(weights)) == 0) & - !(all(dim(weights) == c(dim(data)[lon_dim] * nf, - dim(data)[lat_dim] * nf)))) { + !(dim(weights)[lon_dim] == dim(data)[lon_dim] * nf) & + !(dim(weights)[lat_dim] == dim(data)[lat_dim] * nf)) { stop(paste("The dimensions of the weights matrix (", dim(weights)[1], "x", dim(weights)[2] , ") are not consistent with the size of the data (", @@ -266,9 +266,9 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, split_factor = "greatest")$output1 } else { result <- Apply(list(data, weights, slope), - list(c(lon_dim, lat_dim, "rainfarm_samples"), NULL, NULL), .RainFARM, - nf, nens, kmin, - fglob, fsmooth, ncores = nprocs, verbose, + list(c(lon_dim, lat_dim, "rainfarm_samples"), c(lon_dim, lat_dim), NULL), .RainFARM, + nf = nf, nens = nens, kmin = kmin, + fglob = fglob, fsmooth = fsmooth, ncores = nprocs, verbose = verbose, split_factor = "greatest")$output1 } # result has dims: lon, lat, rainfarm_samples, realization, other dims @@ -290,7 +290,6 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, if (drop_realization_dim) { cdim <- dim(result) if (nens == 1) { - # just drop it if only one member dim(result) <- cdim[-which(names(cdim) == "realization")[1]] } else if ("member" %in% names(cdim)) { # compact member and realization dimension if member dim exists, @@ -303,7 +302,6 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, names(dim(result))[ind] <- "member" } } - return(list(data = result, lon = lon_f, lat = lat_f)) } @@ -311,8 +309,8 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, #' @param pr Precipitation array to downscale with dimensions (lon, lat, time). #' @param weights Matrix with climatological weights which can be obtained using #' the \code{CST_RFWeights} function (default: \code{weights=1.} i.e. no weights). -#' @param nf Refinement factor for downscaling (the output resolution is increased by this factor). #' @param slope Prescribed spectral slope (default: \code{slope=0.} +#' @param nf Refinement factor for downscaling (the output resolution is increased by this factor). #' meaning that the slope is determined automatically over the dimensions specified by \code{time_dim}. #' @param kmin First wavenumber for spectral slope (default: \code{kmin=1}). #' @param nens Number of ensemble members to produce (default: \code{nens=1}). @@ -321,9 +319,19 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, #' @param verbose Logical for verbose output (default: FALSE). #' @return .RainFARM returns a downscaled array with dimensions (lon, lat, time, realization) #' @noRd -.RainFARM <- function(pr, weights, nf, nens, slope, kmin, +.RainFARM <- function(pr, weights, slope, nf, nens, kmin, fglob, fsmooth, verbose) { - +print(dim(pr)) +print(dim(weights)) +print(slope) +print(length(slope)) + + if (any(is.na(pr))) { + posna <- unlist(lapply(1:dim(pr)['rainfarm_samples'], + function(x){!is.na(pr[1, 1, x])})) + pr <- Subset(pr, 'rainfarm_samples', posna) + } +print(dim(pr)) if (slope == 0) { fxp <- fft2d(pr) sx <- fitslope(fxp, kmin = kmin) @@ -339,6 +347,13 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, r[, , , i] <- rainfarm(pr, sx, nf, weights, fglob = fglob, fsmooth = fsmooth, verbose = verbose) } + if (!is.null(posna)) { + result_dims['rainfarm_samples'] <- length(which(posna == FALSE)) + x <- array(1:prod(result_dims), result_dims) + r <- abind(r, x, along = 3) + names(dim(r)) <- names(result_dims) + warning("Missing values found in the samples.") + } return(r) } -- GitLab From a2d68faf549664fe3fcd07676520d7d568b0045d Mon Sep 17 00:00:00 2001 From: nperez Date: Mon, 28 Sep 2020 19:53:37 +0200 Subject: [PATCH 03/20] fixed examples --- R/CST_RainFARM.R | 4 ++-- man/CST_RainFARM.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index de06f353..74acdb25 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -51,7 +51,7 @@ #' #' @return CST_RainFARM() returns a downscaled CSTools object (i.e., of the #' class 's2dv_cube'). -#' If \code{nens>1} an additional dimension named "realization" is added to the +#' If \code{nens>1} an additional dimension named "realizatio"n is added to the #' \code{$data} array after the "member" dimension (unless #' \code{drop_realization_dim=TRUE} is specified). #' The ordering of the remaining dimensions in the \code{$data} element of the input object is maintained. @@ -68,7 +68,7 @@ #' dim(lat) <- c(lat = length(lat)) #' data <- list(data = exp, lon = lon, lat = lat) #' # Create a test array of weights -#' ww <- array(1., dim = c(8 * nf, 8 * nf)) +#' ww <- array(1., dim = c(lon = 8 * nf, lat = 8 * nf)) #' res <- CST_RainFARM(data, nf, ww, nens=3) #' str(res) #' #List of 3 diff --git a/man/CST_RainFARM.Rd b/man/CST_RainFARM.Rd index 1c609e08..462c1f70 100644 --- a/man/CST_RainFARM.Rd +++ b/man/CST_RainFARM.Rd @@ -72,7 +72,7 @@ with the following behaviour if set to TRUE: \value{ CST_RainFARM() returns a downscaled CSTools object (i.e., of the class 's2dv_cube'). -If \code{nens>1} an additional dimension named "realization" is added to the +If \code{nens>1} an additional dimension named "realizatio"n is added to the \code{$data} array after the "member" dimension (unless \code{drop_realization_dim=TRUE} is specified). The ordering of the remaining dimensions in the \code{$data} element of the input object is maintained. @@ -95,7 +95,7 @@ lat <- seq(40, 43.5, 0.5) dim(lat) <- c(lat = length(lat)) data <- list(data = exp, lon = lon, lat = lat) # Create a test array of weights -ww <- array(1., dim = c(8 * nf, 8 * nf)) +ww <- array(1., dim = c(lon = 8 * nf, lat = 8 * nf)) res <- CST_RainFARM(data, nf, ww, nens=3) str(res) #List of 3 -- GitLab From bd20380ca2b32667d547e3c24ede14d2e99772e8 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 29 Sep 2020 09:33:20 +0200 Subject: [PATCH 04/20] Initialize posna --- R/CST_RainFARM.R | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index 74acdb25..74c13c79 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -321,17 +321,12 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, #' @noRd .RainFARM <- function(pr, weights, slope, nf, nens, kmin, fglob, fsmooth, verbose) { -print(dim(pr)) -print(dim(weights)) -print(slope) -print(length(slope)) - + posna <- NULL if (any(is.na(pr))) { posna <- unlist(lapply(1:dim(pr)['rainfarm_samples'], function(x){!is.na(pr[1, 1, x])})) pr <- Subset(pr, 'rainfarm_samples', posna) } -print(dim(pr)) if (slope == 0) { fxp <- fft2d(pr) sx <- fitslope(fxp, kmin = kmin) -- GitLab From 3bf54d644c52d2a8a413c9e6158c32f4d030546e Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 29 Sep 2020 10:43:25 +0200 Subject: [PATCH 05/20] Fix for scalar slope --- R/CST_RainFARM.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index 74c13c79..438badcd 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -264,6 +264,13 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, weights, nf, nens, slope, kmin, fglob, fsmooth, ncores = nprocs, verbose, split_factor = "greatest")$output1 + } else if (length(slope) == 1 & length(weights) > 1 ) { + result <- Apply(list(data, weights), + list(c(lon_dim, lat_dim, "rainfarm_samples"), c(lon_dim, lat_dim)), + .RainFARM, slope = slope, + nf = nf, nens = nens, kmin = kmin, + fglob = fglob, fsmooth = fsmooth, ncores = nprocs, verbose = verbose, + split_factor = "greatest")$output1 } else { result <- Apply(list(data, weights, slope), list(c(lon_dim, lat_dim, "rainfarm_samples"), c(lon_dim, lat_dim), NULL), .RainFARM, @@ -274,7 +281,6 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, # result has dims: lon, lat, rainfarm_samples, realization, other dims # Expand back rainfarm_samples to compacted dims dim(result) <- c(dim(result)[1:2], cdim[-ind], dim(result)[-(1:3)]) - # Reorder as it was in original data # + realization dim after member if it exists ienspos <- which(names(cdim0) == "member") -- GitLab From c26c49a891c93f6bdee28e78263661610fa80d52 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 29 Sep 2020 11:10:55 +0200 Subject: [PATCH 06/20] Fix example --- R/CST_RainFARM.R | 2 +- man/RainFARM.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index 438badcd..fcbc9b5d 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -166,7 +166,7 @@ CST_RainFARM <- function(data, nf, weights = 1., slope = 0, kmin = 1, #' lon_mat <- seq(10, 13.5, 0.5) # could also be a 2d matrix #' lat_mat <- seq(40, 43.5, 0.5) #' # Create a test array of weights -#' ww <- array(1., dim = c(8 * nf, 8 * nf)) +#' ww <- array(1., dim = c(lon = 8 * nf, lat = 8 * nf)) #' # or create proper weights using an external fine-scale climatology file #' # Specify a weightsfn filename if you wish to save the weights #' \dontrun{ diff --git a/man/RainFARM.Rd b/man/RainFARM.Rd index 0db84679..c7bd9c45 100644 --- a/man/RainFARM.Rd +++ b/man/RainFARM.Rd @@ -107,7 +107,7 @@ dim(pr) <- c(lon = 8, lat = 8, ftime = 20) lon_mat <- seq(10, 13.5, 0.5) # could also be a 2d matrix lat_mat <- seq(40, 43.5, 0.5) # Create a test array of weights -ww <- array(1., dim = c(8 * nf, 8 * nf)) +ww <- array(1., dim = c(lon = 8 * nf, lat = 8 * nf)) # or create proper weights using an external fine-scale climatology file # Specify a weightsfn filename if you wish to save the weights \dontrun{ -- GitLab From 616d55673f12286fd819549f79312e538fa93124 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 29 Sep 2020 12:11:26 +0200 Subject: [PATCH 07/20] Fixing tests --- R/CST_RainFARM.R | 24 +++++++++++++++++++----- tests/testthat/test-CST_RainFARM.R | 4 ++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index fcbc9b5d..fd553df3 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -211,13 +211,28 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, warning(paste0("lon: [", lon[1], ", ", lon[length(lon)], "] ", " lat: [", lat[1], ", ", lat[length(lat)], "]")) } - if (!(length(dim(weights)) == 0) & - !(dim(weights)[lon_dim] == dim(data)[lon_dim] * nf) & - !(dim(weights)[lat_dim] == dim(data)[lat_dim] * nf)) { + if (length(dim(weights)) > 0) { + if (length(names(dim(weights))) == 0) { + stop("Parameter 'weights' must have dimension names when it is not a scalar.") + } else { + if (length(which(names(dim(weights)) == 'lon')) > 0 & + length(which(names(dim(weights)) == 'lat')) > 0) { + lonposw <- which(names(dim(weights)) == 'lon') + latposw <- which(names(dim(weights)) == 'lat') + } else { + stop("Parameter 'weights' must have dimension names 'lon' and 'lat' when", + " it is not a scalar.") + } + } + } + if (!(length(dim(weights)) == 0)) { + if (!(dim(weights)[lonposw] == dim(data)[lon_dim] * nf) & + !(dim(weights)[latposw] == dim(data)[lat_dim] * nf)) { stop(paste("The dimensions of the weights matrix (", dim(weights)[1], "x", dim(weights)[2] , ") are not consistent with the size of the data (", dim(data)[lon_dim], ") and the refinement factor (", nf, ")")) + } } # Check/detect time_dim if (is.null(time_dim)) { @@ -261,7 +276,7 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, # Repeatedly apply .RainFARM if (length(weights) == 1 & length(slope) == 1) { result <- Apply(data, c(lon_dim, lat_dim, "rainfarm_samples"), .RainFARM, - weights, nf, nens, slope, kmin, + weights, slope, nf, nens, kmin, fglob, fsmooth, ncores = nprocs, verbose, split_factor = "greatest")$output1 } else if (length(slope) == 1 & length(weights) > 1 ) { @@ -339,7 +354,6 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, } else { sx <- slope } - result_dims <- c(dim(pr)[1] * nf, dim(pr)[2] * nf, dim(pr)[3], realization = nens) r <- array(dim = result_dims) diff --git a/tests/testthat/test-CST_RainFARM.R b/tests/testthat/test-CST_RainFARM.R index 3608d4e8..d9414925 100644 --- a/tests/testthat/test-CST_RainFARM.R +++ b/tests/testthat/test-CST_RainFARM.R @@ -26,7 +26,7 @@ test_that("Sanity checks and simple use cases", { ) expect_error( res <- CST_RainFARM(exp, nf=8, weights=array(0,dim=c(2,2))), - "The dimensions of the weights matrix" + "Parameter 'weights' must have dimension names when it is not a scalar." ) dimexp=dim(exp$data) @@ -92,7 +92,7 @@ test_that("Sanity checks and simple use cases", { # Use climatological mean of PF precipitation to generate sythetic weights w <- rfweights(rpfm, res$lon, res$lat, exp$lon, exp$lat, 8, fsmooth=FALSE ) - + names(dim(w)) <- c('lon', 'lat') res <- CST_RainFARM(exppf, nf=8, time_dim=c("ftime", "sdate", "member"), nens=2, nproc=2, fsmooth=FALSE) resw <- CST_RainFARM(exppf, nf=8, time_dim=c("ftime", "sdate", "member"), -- GitLab From 55d4135b0846c33d7522d76427e6205684f689f1 Mon Sep 17 00:00:00 2001 From: nperez Date: Wed, 30 Sep 2020 12:54:32 +0200 Subject: [PATCH 08/20] documentation update --- R/CST_RainFARM.R | 50 +++++++++++++++++++++++++++++---------------- man/CST_RainFARM.Rd | 21 ++++++++++++------- man/RainFARM.Rd | 16 ++++++++++----- 3 files changed, 57 insertions(+), 30 deletions(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index fd553df3..e43e1535 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -21,11 +21,10 @@ #' the function will perform a subsetting to ensure this condition. #' @param weights Matrix with climatological weights which can be obtained using #' the \code{CST_RFWeights} function. If \code{weights=1.} (default) no weights are used. -#' The matrix should have dimensions (lon, lat) in this order. -#' The names of these dimensions are not checked. +#' The names of these dimensions must be at least 'lon' and 'lat'. #' @param nf Refinement factor for downscaling (the output resolution is increased by this factor). #' @param slope Prescribed spectral slope. The default is \code{slope=0.} -#' meaning that the slope is determined automatically over the dimensions specified by \code{time_dim}. +#' meaning that the slope is determined automatically over the dimensions specified by \code{time_dim}. A 1D array with named dimension can be provided (see details and examples) #' @param kmin First wavenumber for spectral slope (default: \code{kmin=1}). #' @param nens Number of ensemble members to produce (default: \code{nens=1}). #' @param fglob Logical to conserve global precipitation over the domain (default: FALSE). @@ -55,6 +54,7 @@ #' \code{$data} array after the "member" dimension (unless #' \code{drop_realization_dim=TRUE} is specified). #' The ordering of the remaining dimensions in the \code{$data} element of the input object is maintained. +#' @details Wether parameter 'slope' and 'weights' presents seasonality dependency, a dimension name should match between these parameters and the input data in parameter 'data'. See example 2 below where weights and slope vary with 'sdate' dimension. #' @import multiApply #' @import rainfarmr #' @examples @@ -69,7 +69,7 @@ #' data <- list(data = exp, lon = lon, lat = lat) #' # Create a test array of weights #' ww <- array(1., dim = c(lon = 8 * nf, lat = 8 * nf)) -#' res <- CST_RainFARM(data, nf, ww, nens=3) +#' res <- CST_RainFARM(data, nf = nf, weights = ww, nens=3) #' str(res) #' #List of 3 #' # $ data: num [1, 1:2, 1:3, 1:3, 1:4, 1:64, 1:64] 260 553 281 278 143 ... @@ -79,14 +79,19 @@ #' # dataset member realization sdate ftime lat lon #' # 1 2 3 3 4 64 64 #' +#' # Example 2: +#' slo <- array(c(0.1, 0.5, 0.7), c(sdate= 3)) +#' wei <- array(rnorm(8 * 8 * 3), c(lon = 8, lat = 8, sdate = 3)) +#' res <- CST_RainFARM(lonlat_prec, +#' weights = wei, slope = slo, nf = 2) #' @export -CST_RainFARM <- function(data, nf, weights = 1., slope = 0, kmin = 1, +CST_RainFARM <- function(data, weights = 1., slope = 0, nf, kmin = 1, nens = 1, fglob = FALSE, fsmooth = TRUE, nprocs = 1, time_dim = NULL, verbose = FALSE, drop_realization_dim = FALSE) { res <- RainFARM(data$data, data$lon, data$lat, - nf, weights, nens, slope, kmin, fglob, fsmooth, + nf = nf, weights = weights, nens, slope, kmin, fglob, fsmooth, nprocs, time_dim, lon_dim = "lon", lat_dim = "lat", drop_realization_dim, verbose) @@ -117,13 +122,12 @@ CST_RainFARM <- function(data, nf, weights = 1., slope = 0, kmin = 1, #' the function will perform a subsetting to ensure this condition. #' @param lon Vector or array of longitudes. #' @param lat Vector or array of latitudes. -#' @param weights Matrix with climatological weights which can be obtained using +#' @param weights multi-dimensional array with climatological weights which can be obtained using #' the \code{CST_RFWeights} function. If \code{weights=1.} (default) no weights are used. -#' The matrix should have dimensions (lon, lat) in this order. -#' The names of these dimensions are not checked. -#' @param nf Refinement factor for downscaling (the output resolution is increased by this factor). +#' The names of these dimensions must be at least 'lon' and 'lat'. +#' @param nf Refinement factor for downscaling (the output resolution is increased by this factor). #' @param slope Prescribed spectral slope. The default is \code{slope=0.} -#' meaning that the slope is determined automatically over the dimensions specified by \code{time_dim}. +#' meaning that the slope is determined automatically over the dimensions specified by \code{time_dim}. A 1D array with named dimension can be provided (see details and examples) #' @param kmin First wavenumber for spectral slope (default: \code{kmin=1}). #' @param nens Number of ensemble members to produce (default: \code{nens=1}). #' @param fglob Logical to conseve global precipitation over the domain (default: FALSE) @@ -153,6 +157,7 @@ CST_RainFARM <- function(data, nf, weights = 1., slope = 0, kmin = 1, #' If \code{nens>1} an additional dimension named "realization" is added to the output array #' after the "member" dimension (if it exists and unless \code{drop_realization_dim=TRUE} is specified). #' The ordering of the remaining dimensions in the \code{exp} element of the input object is maintained. +#' @details Wether parameter 'slope' and 'weights' presents seasonality dependency, a dimension name should match between these parameters and the input data in parameter 'data'. See example 2 below where weights and slope vary with 'sdate' dimension. #' @import multiApply #' @export #' @examples @@ -185,7 +190,11 @@ CST_RainFARM <- function(data, nf, weights = 1., slope = 0, kmin = 1, #' dim(res$data) #' # lon lat ftime realization #' # 64 64 20 2 -#' +#' # Example 2: +#' slo <- array(c(0.1, 0.5, 0.7), c(sdate= 3)) +#' wei <- array(rnorm(8*8*3), c(lon = 8, lat = 8, sdate = 3)) +#' res <- RainFARM(lonlat_prec$data, lon = lonlat_prec$lon, +#' lat = lonlat_prec$lat, weights = wei, slope = slo, nf = 2) RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, slope = 0, kmin = 1, fglob = FALSE, fsmooth = TRUE, nprocs = 1, time_dim = NULL, lon_dim = "lon", lat_dim = "lat", @@ -281,17 +290,22 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, split_factor = "greatest")$output1 } else if (length(slope) == 1 & length(weights) > 1 ) { result <- Apply(list(data, weights), - list(c(lon_dim, lat_dim, "rainfarm_samples"), c(lon_dim, lat_dim)), + list(c(lon_dim, lat_dim, "rainfarm_samples"), + c(lonposw, latposw)), .RainFARM, slope = slope, nf = nf, nens = nens, kmin = kmin, - fglob = fglob, fsmooth = fsmooth, ncores = nprocs, verbose = verbose, + fglob = fglob, fsmooth = fsmooth, ncores = nprocs, + verbose = verbose, split_factor = "greatest")$output1 } else { result <- Apply(list(data, weights, slope), - list(c(lon_dim, lat_dim, "rainfarm_samples"), c(lon_dim, lat_dim), NULL), .RainFARM, - nf = nf, nens = nens, kmin = kmin, - fglob = fglob, fsmooth = fsmooth, ncores = nprocs, verbose = verbose, - split_factor = "greatest")$output1 + list(c(lon_dim, lat_dim, "rainfarm_samples"), + c(lonposw, latposw), NULL), + fun = .RainFARM, + nf = nf, nens = nens, kmin = kmin, + fglob = fglob, fsmooth = fsmooth, ncores = nprocs, + verbose = verbose, + split_factor = "greatest")$output1 } # result has dims: lon, lat, rainfarm_samples, realization, other dims # Expand back rainfarm_samples to compacted dims diff --git a/man/CST_RainFARM.Rd b/man/CST_RainFARM.Rd index 462c1f70..f86ab89c 100644 --- a/man/CST_RainFARM.Rd +++ b/man/CST_RainFARM.Rd @@ -6,9 +6,9 @@ \usage{ CST_RainFARM( data, - nf, weights = 1, slope = 0, + nf, kmin = 1, nens = 1, fglob = FALSE, @@ -29,15 +29,14 @@ which can be specified by parameter \code{time_dim}. The number of longitudes and latitudes in the input data is expected to be even and the same. If not the function will perform a subsetting to ensure this condition.} -\item{nf}{Refinement factor for downscaling (the output resolution is increased by this factor).} - \item{weights}{Matrix with climatological weights which can be obtained using the \code{CST_RFWeights} function. If \code{weights=1.} (default) no weights are used. -The matrix should have dimensions (lon, lat) in this order. -The names of these dimensions are not checked.} +The names of these dimensions must be at least 'lon' and 'lat'.} \item{slope}{Prescribed spectral slope. The default is \code{slope=0.} -meaning that the slope is determined automatically over the dimensions specified by \code{time_dim}.} +meaning that the slope is determined automatically over the dimensions specified by \code{time_dim}. A 1D array with named dimension can be provided (see details and examples)} + +\item{nf}{Refinement factor for downscaling (the output resolution is increased by this factor).} \item{kmin}{First wavenumber for spectral slope (default: \code{kmin=1}).} @@ -84,6 +83,9 @@ downscaling method and accepts a CSTools object (an object of the class Adapted for climate downscaling and including orographic correction as described in Terzago et al. 2018. } +\details{ +Wether parameter 'slope' and 'weights' presents seasonality dependency, a dimension name should match between these parameters and the input data in parameter 'data'. See example 2 below where weights and slope vary with 'sdate' dimension. +} \examples{ #Example 1: using CST_RainFARM for a CSTools object nf <- 8 # Choose a downscaling by factor 8 @@ -96,7 +98,7 @@ dim(lat) <- c(lat = length(lat)) data <- list(data = exp, lon = lon, lat = lat) # Create a test array of weights ww <- array(1., dim = c(lon = 8 * nf, lat = 8 * nf)) -res <- CST_RainFARM(data, nf, ww, nens=3) +res <- CST_RainFARM(data, nf = nf, weights = ww, nens=3) str(res) #List of 3 # $ data: num [1, 1:2, 1:3, 1:3, 1:4, 1:64, 1:64] 260 553 281 278 143 ... @@ -106,6 +108,11 @@ dim(res$data) # dataset member realization sdate ftime lat lon # 1 2 3 3 4 64 64 +# Example 2: +slo <- array(c(0.1, 0.5, 0.7), c(sdate= 3)) +wei <- array(rnorm(8 * 8 * 3), c(lon = 8, lat = 8, sdate = 3)) +res <- CST_RainFARM(lonlat_prec, + weights = wei, slope = slo, nf = 2) } \references{ Terzago, S. et al. (2018). NHESS 18(11), 2825-2840. diff --git a/man/RainFARM.Rd b/man/RainFARM.Rd index c7bd9c45..ef4485c9 100644 --- a/man/RainFARM.Rd +++ b/man/RainFARM.Rd @@ -38,15 +38,14 @@ the function will perform a subsetting to ensure this condition.} \item{nf}{Refinement factor for downscaling (the output resolution is increased by this factor).} -\item{weights}{Matrix with climatological weights which can be obtained using +\item{weights}{multi-dimensional array with climatological weights which can be obtained using the \code{CST_RFWeights} function. If \code{weights=1.} (default) no weights are used. -The matrix should have dimensions (lon, lat) in this order. -The names of these dimensions are not checked.} +The names of these dimensions must be at least 'lon' and 'lat'.} \item{nens}{Number of ensemble members to produce (default: \code{nens=1}).} \item{slope}{Prescribed spectral slope. The default is \code{slope=0.} -meaning that the slope is determined automatically over the dimensions specified by \code{time_dim}.} +meaning that the slope is determined automatically over the dimensions specified by \code{time_dim}. A 1D array with named dimension can be provided (see details and examples)} \item{kmin}{First wavenumber for spectral slope (default: \code{kmin=1}).} @@ -96,6 +95,9 @@ References: Terzago, S. et al. (2018). NHESS 18(11), 2825-2840. http://doi.org/10.5194/nhess-18-2825-2018, D'Onofrio et al. (2014), J of Hydrometeorology 15, 830-843; Rebora et. al. (2006), JHM 7, 724. } +\details{ +Wether parameter 'slope' and 'weights' presents seasonality dependency, a dimension name should match between these parameters and the input data in parameter 'data'. See example 2 below where weights and slope vary with 'sdate' dimension. +} \examples{ # Example for the 'reduced' RainFARM function nf <- 8 # Choose a downscaling by factor 8 @@ -126,7 +128,11 @@ str(res) dim(res$data) # lon lat ftime realization # 64 64 20 2 - +# Example 2: +slo <- array(c(0.1, 0.5, 0.7), c(sdate= 3)) +wei <- array(rnorm(8*8*3), c(lon = 8, lat = 8, sdate = 3)) +res <- RainFARM(lonlat_prec$data, lon = lonlat_prec$lon, + lat = lonlat_prec$lat, weights = wei, slope = slo, nf = 2) } \author{ Jost von Hardenberg - ISAC-CNR, \email{j.vonhardenberg@isac.cnr.it} -- GitLab From 9150cf22347d7376c8b0b235f7bb50b4183f3a6d Mon Sep 17 00:00:00 2001 From: nperez Date: Wed, 30 Sep 2020 18:18:58 +0200 Subject: [PATCH 09/20] preserving lon and lat attributes --- R/CST_RainFARM.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index e43e1535..1890123d 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -94,10 +94,13 @@ CST_RainFARM <- function(data, weights = 1., slope = 0, nf, kmin = 1, nf = nf, weights = weights, nens, slope, kmin, fglob, fsmooth, nprocs, time_dim, lon_dim = "lon", lat_dim = "lat", drop_realization_dim, verbose) - + att_lon <- attributes(data)$lon + att_lat <- attributes(data)$lat data$data <- res$data data$lon <- res$lon + attributes(data)$lon <- att_lon data$lat <- res$lat + attributes(data)$lat <- att_lat return(data) } -- GitLab From 8f1b854c5351e1f614cd5076ffa1fe9976c3f69c Mon Sep 17 00:00:00 2001 From: nperez Date: Thu, 1 Oct 2020 12:45:11 +0200 Subject: [PATCH 10/20] fix in NA values --- R/CST_RainFARM.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index 1890123d..e9948b3b 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -374,18 +374,17 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, result_dims <- c(dim(pr)[1] * nf, dim(pr)[2] * nf, dim(pr)[3], realization = nens) r <- array(dim = result_dims) - for (i in 1:nens) { r[, , , i] <- rainfarm(pr, sx, nf, weights, fglob = fglob, fsmooth = fsmooth, verbose = verbose) } if (!is.null(posna)) { result_dims['rainfarm_samples'] <- length(which(posna == FALSE)) - x <- array(1:prod(result_dims), result_dims) + x <- array(rep(NA,prod(result_dims)), result_dims) r <- abind(r, x, along = 3) names(dim(r)) <- names(result_dims) warning("Missing values found in the samples.") - } + } return(r) } -- GitLab From aadbf2fde0a4d6b943aa035155f870967e3d273f Mon Sep 17 00:00:00 2001 From: nperez Date: Thu, 1 Oct 2020 14:23:27 +0200 Subject: [PATCH 11/20] NAs recovering original order --- R/CST_RainFARM.R | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index e9948b3b..39fc9e1b 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -379,10 +379,13 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, fsmooth = fsmooth, verbose = verbose) } if (!is.null(posna)) { - result_dims['rainfarm_samples'] <- length(which(posna == FALSE)) - x <- array(rep(NA,prod(result_dims)), result_dims) - r <- abind(r, x, along = 3) - names(dim(r)) <- names(result_dims) + #result_dims['rainfarm_samples'] <- 1 + #x <- array(rep(NA, prod(result_dims)), result_dims) + #r <- abind(r, x, along = 3) + pos <- which(posna == FALSE) + lapply(pos, function(x){ + r <- abind(r[,,1:(x - which(pos == x))], array(NA, result_dims))}) + names(dim(r)) <- names(result_dims) warning("Missing values found in the samples.") } return(r) -- GitLab From 33ec2440e49a51653c46020fcc45f5a1ee75757a Mon Sep 17 00:00:00 2001 From: nperez Date: Thu, 1 Oct 2020 16:12:06 +0200 Subject: [PATCH 12/20] fix correct rainfarm_sample dim --- R/CST_RainFARM.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index 39fc9e1b..c7f15cef 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -379,12 +379,9 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, fsmooth = fsmooth, verbose = verbose) } if (!is.null(posna)) { - #result_dims['rainfarm_samples'] <- 1 - #x <- array(rep(NA, prod(result_dims)), result_dims) - #r <- abind(r, x, along = 3) pos <- which(posna == FALSE) lapply(pos, function(x){ - r <- abind(r[,,1:(x - which(pos == x))], array(NA, result_dims))}) + r <- abind(r[,,1:(x - which(pos == x)),], array(NA, result_dims))}) names(dim(r)) <- names(result_dims) warning("Missing values found in the samples.") } -- GitLab From 072242c4dd9612bb567210e3e790d1a6ed05064f Mon Sep 17 00:00:00 2001 From: nperez Date: Fri, 2 Oct 2020 10:42:46 +0200 Subject: [PATCH 13/20] bug found --- R/CST_RainFARM.R | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index c7f15cef..c4547b98 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -375,13 +375,46 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, realization = nens) r <- array(dim = result_dims) for (i in 1:nens) { - r[, , , i] <- rainfarm(pr, sx, nf, weights, fglob = fglob, - fsmooth = fsmooth, verbose = verbose) + r[, , , i] <- invisible(rainfarm(pr, sx, nf, weights, fglob = fglob, + fsmooth = fsmooth, verbose = verbose)) } + # restoring NA values in their position: if (!is.null(posna)) { pos <- which(posna == FALSE) - lapply(pos, function(x){ - r <- abind(r[,,1:(x - which(pos == x)),], array(NA, result_dims))}) + if (pos[1] == 1) { + result_dims['rainfarm_samples'] <- 1 + x <- array(rep(NA,prod(result_dims)), result_dims) + r <- abind(x, r, along = 3) + names(dim(r)) <- names(result_dims) + pos <- pos[-1] + } + result_dims['rainfarm_samples'] <- 1 + if ((pos[1] - 1) < dim(r)['rainfarm_samples']) { + x <- max(which((pos - 1) < dim(r)['rainfarm_samples'])) + pos_internal <- pos[1:x] + if (pos[length(pos)] > pos[x]) { + pos <- pos[(xi + 1) : length(pos)] + } else { + pos <- NULL + } + } else { + pos_internal <- NULL + } + if (!is.null(pos_internal)) { + r <- lapply(pos_internal, + function(x) { + rrr <- Subset(r, along = 'rainfarm_samples', indices = 1:(x-1)) + rrrr <- Subset(r, along = 'rainfarm_samples', indices = x:dim(r)['rainfarm_samples']) + r <- abind(rrr, array(NA, result_dims), rrrr, along = 3) + names(dim(r)) <- names(result_dims) + return(r) + })[[length(pos)]] + } + if (!is.null(pos)) { + result_dims['rainfarm_samples'] <- length(pos) + x <- array(rep(NA,prod(result_dims)), result_dims) + r <- abind(r, x, along = 3) + } names(dim(r)) <- names(result_dims) warning("Missing values found in the samples.") } -- GitLab From d78e29467f45278d0db014dd999ec631c8373fa8 Mon Sep 17 00:00:00 2001 From: nperez Date: Fri, 2 Oct 2020 10:52:55 +0200 Subject: [PATCH 14/20] adding dependencies --- NAMESPACE | 2 ++ R/CST_RainFARM.R | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 9f9a0e34..3863e714 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -51,7 +51,9 @@ import(rainfarmr) import(s2dverification) import(stats) importFrom(ClimProjDiags,SelBox) +importFrom(ClimProjDiags,Subset) importFrom(RColorBrewer,brewer.pal) +importFrom(abind,abind) importFrom(data.table,CJ) importFrom(data.table,data.table) importFrom(data.table,setkey) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index c4547b98..1feaec33 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -162,6 +162,8 @@ CST_RainFARM <- function(data, weights = 1., slope = 0, nf, kmin = 1, #' The ordering of the remaining dimensions in the \code{exp} element of the input object is maintained. #' @details Wether parameter 'slope' and 'weights' presents seasonality dependency, a dimension name should match between these parameters and the input data in parameter 'data'. See example 2 below where weights and slope vary with 'sdate' dimension. #' @import multiApply +#' @importFrom ClimProjDiags Subset +#' @importFrom abind abind #' @export #' @examples #' # Example for the 'reduced' RainFARM function @@ -375,8 +377,8 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, realization = nens) r <- array(dim = result_dims) for (i in 1:nens) { - r[, , , i] <- invisible(rainfarm(pr, sx, nf, weights, fglob = fglob, - fsmooth = fsmooth, verbose = verbose)) + r[, , , i] <- rainfarm(pr, sx, nf, weights, fglob = fglob, + fsmooth = fsmooth, verbose = verbose) } # restoring NA values in their position: if (!is.null(posna)) { -- GitLab From 3db8ca061a93ed20c3855fd15951825d27acb2e1 Mon Sep 17 00:00:00 2001 From: nperez Date: Fri, 2 Oct 2020 11:33:14 +0200 Subject: [PATCH 15/20] fix attributes --- R/CST_RainFARM.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index 1feaec33..6d69dfe3 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -94,13 +94,13 @@ CST_RainFARM <- function(data, weights = 1., slope = 0, nf, kmin = 1, nf = nf, weights = weights, nens, slope, kmin, fglob, fsmooth, nprocs, time_dim, lon_dim = "lon", lat_dim = "lat", drop_realization_dim, verbose) - att_lon <- attributes(data)$lon - att_lat <- attributes(data)$lat + att_lon <- attributes(data$lon)[-1] + att_lat <- attributes(data$lat)[-1] data$data <- res$data data$lon <- res$lon - attributes(data)$lon <- att_lon + attributes(data$lon) <- att_lon data$lat <- res$lat - attributes(data)$lat <- att_lat + attributes(data$lat) <- att_lat return(data) } -- GitLab From ddaf3f294169320fc5639637f9c240738d075d38 Mon Sep 17 00:00:00 2001 From: nperez Date: Wed, 28 Oct 2020 11:24:02 +0100 Subject: [PATCH 16/20] NEWs updated --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index cf9eae22..7e18054c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,8 @@ + CST_RFSlope handless missing values in the temporal dimension and new 'ncores' parameter allows parallel computation + CST_RFWeights accepts s2dv_cube objects as input and new 'ncores' paramenter allows parallel computation + RFWeights is exposed to users + + CST_RainFARM accepts multi-dimensional slopes and weights and handless missing values in sample dimensions. + - Fixes: + PlotForecastPDF correctly displays terciles labels -- GitLab From e7c30b76a09b34a49be0eb8030286b10f10ad0e0 Mon Sep 17 00:00:00 2001 From: nperez Date: Wed, 28 Oct 2020 11:26:01 +0100 Subject: [PATCH 17/20] Fix parameter name --- R/CST_RFWeights.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/CST_RFWeights.R b/R/CST_RFWeights.R index 56d943da..b4aa0c3c 100644 --- a/R/CST_RFWeights.R +++ b/R/CST_RFWeights.R @@ -143,7 +143,7 @@ CST_RFWeights <- function(climfile, nf, lon, lat, varname = NULL, #' @export RF_Weights <- function(zclim, latin, lonin, nf, lat, lon, fsmooth = TRUE, lonname = 'lon', latname = 'lat', ncores = NULL) { - x <- Apply(list(zclim), target = c(lonname, latname), fun = rf_weights, + x <- Apply(list(zclim), target_dims = c(lonname, latname), fun = rf_weights, latin = latin, lonin = lonin, nf = nf, lat = lat, lon = lon, fsmooth = fsmooth, ncores = ncores)$output1 grid <- lon_lat_fine(lon, lat, nf) -- GitLab From 2112d734365777f22ceda5a8f184939a51f9e068 Mon Sep 17 00:00:00 2001 From: nperez Date: Wed, 28 Oct 2020 11:28:18 +0100 Subject: [PATCH 18/20] Remove innecessary parameter from RFWeights documentation --- R/CST_RFWeights.R | 1 - man/RF_Weights.Rd | 2 -- 2 files changed, 3 deletions(-) diff --git a/R/CST_RFWeights.R b/R/CST_RFWeights.R index b4aa0c3c..fa7eec75 100644 --- a/R/CST_RFWeights.R +++ b/R/CST_RFWeights.R @@ -124,7 +124,6 @@ CST_RFWeights <- function(climfile, nf, lon, lat, varname = NULL, #' @param lat Vector of latitudes. #' The number of longitudes and latitudes is expected to be even and the same. If not #' the function will perform a subsetting to ensure this condition. -#' @param varname Name of the variable to be read from \code{climfile}. #' @param fsmooth Logical to use smooth conservation (default) or large-scale box-average conservation. #' @param lonname a character string indicating the name of the longitudinal dimension set as 'lon' by default. #' @param latname a character string indicating the name of the latitudinal dimension set as 'lat' by default. diff --git a/man/RF_Weights.Rd b/man/RF_Weights.Rd index 7e8d735d..66e1ac51 100644 --- a/man/RF_Weights.Rd +++ b/man/RF_Weights.Rd @@ -39,8 +39,6 @@ the function will perform a subsetting to ensure this condition.} \item{latname}{a character string indicating the name of the latitudinal dimension set as 'lat' by default.} \item{ncores}{an integer that indicates the number of cores for parallel computations using multiApply function. The default value is one.} - -\item{varname}{Name of the variable to be read from \code{climfile}.} } \value{ An object of class 's2dv_cube' containing in matrix \code{data} the weights with dimensions (lon, lat). -- GitLab From 28f287f1e2f5c005b3cba528217bd1375ba4fcb9 Mon Sep 17 00:00:00 2001 From: nperez Date: Wed, 28 Oct 2020 12:05:56 +0100 Subject: [PATCH 19/20] fix mistyped --- R/CST_RainFARM.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index 6d69dfe3..72aae699 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -395,7 +395,7 @@ RainFARM <- function(data, lon, lat, nf, weights = 1., nens = 1, x <- max(which((pos - 1) < dim(r)['rainfarm_samples'])) pos_internal <- pos[1:x] if (pos[length(pos)] > pos[x]) { - pos <- pos[(xi + 1) : length(pos)] + pos <- pos[(x + 1) : length(pos)] } else { pos <- NULL } -- GitLab From 2e291cf40275ac6a05c1b719ce7fd6031c15c5de Mon Sep 17 00:00:00 2001 From: nperez Date: Wed, 28 Oct 2020 12:07:11 +0100 Subject: [PATCH 20/20] Subset from s2dverification --- R/CST_RainFARM.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/CST_RainFARM.R b/R/CST_RainFARM.R index 72aae699..73b075c4 100644 --- a/R/CST_RainFARM.R +++ b/R/CST_RainFARM.R @@ -162,7 +162,7 @@ CST_RainFARM <- function(data, weights = 1., slope = 0, nf, kmin = 1, #' The ordering of the remaining dimensions in the \code{exp} element of the input object is maintained. #' @details Wether parameter 'slope' and 'weights' presents seasonality dependency, a dimension name should match between these parameters and the input data in parameter 'data'. See example 2 below where weights and slope vary with 'sdate' dimension. #' @import multiApply -#' @importFrom ClimProjDiags Subset +#' @importFrom s2dverification Subset #' @importFrom abind abind #' @export #' @examples -- GitLab