From 0ae3d2fa76c3d03860d6a4db550a8f18e9cc3d02 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 26 Nov 2019 16:58:40 +0100 Subject: [PATCH 1/2] QuantileMapping working with NA values --- R/CST_QuantileMapping.R | 9 +++++++-- R/CST_SplitDim.R | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/R/CST_QuantileMapping.R b/R/CST_QuantileMapping.R index 6682e7aa..d8e2ec73 100644 --- a/R/CST_QuantileMapping.R +++ b/R/CST_QuantileMapping.R @@ -103,10 +103,10 @@ QuantileMapping <- function(exp, obs, exp_cor = NULL, sample_dims = 'ftime', stop("Parameter 'obs' must have dimension names.") } if (any(is.na(exp))) { - stop("Parameter 'exp' contains NA values.") + warning("Parameter 'exp' contains NA values.") } if (any(is.na(obs))) { - stop("Parameter 'obs' contains NA values.") + warning("Parameter 'obs' contains NA values.") } if (!is.null(exp_cor)) { exp_cordims <- names(dim(exp_cor)) @@ -326,6 +326,11 @@ qmapcor <- function(exp, obs, exp_cor = NULL, sample_length = NULL, method = 'QU } applied <- c(applied, doQmap(x = sample_cor, fobj = adjust, ...)) } + if (any(is.na(exp_cor))) { + pos <- which(!is.na(exp_cor)) + exp_cor[pos] <- applied + applied <- exp_cor + } dim(applied) <- dimensions return(applied) } diff --git a/R/CST_SplitDim.R b/R/CST_SplitDim.R index ce65e07f..46cd97cc 100644 --- a/R/CST_SplitDim.R +++ b/R/CST_SplitDim.R @@ -50,7 +50,7 @@ CST_SplitDim <- function(data, split_dim = 'time', indices = NULL, stop("Parameter 'split_dims' must be one of the dimension ", "names in parameter 'data'.") } - indices <- indices[1 : dim(data$data)[which(names(dim(data$data)) == + indices <- indices[1 : dim(data$data)[which(names(dim(data$data)) == split_dim)]] } } -- GitLab From a831939b1eec9b78656301ae6a955ee06c106dd1 Mon Sep 17 00:00:00 2001 From: nperez Date: Tue, 26 Nov 2019 17:31:13 +0100 Subject: [PATCH 2/2] corrected QuantileMapping test for NA values --- tests/testthat/test-CST_QuantileMapping.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-CST_QuantileMapping.R b/tests/testthat/test-CST_QuantileMapping.R index 4a317b5a..9a955447 100644 --- a/tests/testthat/test-CST_QuantileMapping.R +++ b/tests/testthat/test-CST_QuantileMapping.R @@ -72,13 +72,13 @@ library(qmap) "length of the timeseries will be used.") exp$data[1] <- NA - expect_error( + expect_warning( CST_QuantileMapping(exp = exp, obs = obs, sample_dims = 'time'), "Parameter 'exp' contains NA values.") exp$data[1] <- 1 obs$data[1] <- NA - expect_error( + expect_warning( CST_QuantileMapping(exp = exp, obs = obs, sample_dims = 'time'), "Parameter 'obs' contains NA values.") obs$data[1] <- 1 -- GitLab