From 33b82398e59b2649e370a81cc017faae70965577 Mon Sep 17 00:00:00 2001 From: Carlos Delgado Date: Fri, 8 Sep 2023 14:36:25 +0200 Subject: [PATCH 1/3] fixed indices_for_clim --- R/GetProbs.R | 4 +++- R/ROCSS.R | 3 +++ R/RPS.R | 4 +++- R/RPSS.R | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/R/GetProbs.R b/R/GetProbs.R index 59304b4..fed15ca 100644 --- a/R/GetProbs.R +++ b/R/GetProbs.R @@ -167,7 +167,9 @@ GetProbs <- function(data, time_dim = 'sdate', memb_dim = 'member', indices_for_ ## if data is exp: [sdate, memb] ## if data is obs: [sdate, (memb)] # weights: [sdate, (memb)], same as data - + + if (is.null(indices_for_quantiles)){indices_for_quantiles <- 1:dim(data)[time_dim]} + # Add dim [memb = 1] to data if it doesn't have memb_dim if (length(dim(data)) == 1) { dim(data) <- c(dim(data), 1) diff --git a/R/ROCSS.R b/R/ROCSS.R index 2ca0782..022df85 100644 --- a/R/ROCSS.R +++ b/R/ROCSS.R @@ -325,9 +325,11 @@ ROCSS <- function(exp, obs, ref = NULL, time_dim = 'sdate', memb_dim = 'member', ## if exp: [sdate, memb] ## if obs: [sdate, (memb)] exp_probs <- .GetProbs(data = ClimProjDiags::Subset(exp, dat_dim, exp_i, drop = 'selected'), + time_dim = time_dim, memb_dim = memb_dim, indices_for_quantiles = indices_for_clim, prob_thresholds = prob_thresholds, cross.val = cross.val) obs_probs <- .GetProbs(data = ClimProjDiags::Subset(obs, dat_dim, obs_i, drop = 'selected'), + time_dim = time_dim, memb_dim = memb_dim, indices_for_quantiles = indices_for_clim, prob_thresholds = prob_thresholds, cross.val = cross.val) ## exp_probs and obs_probs: [bin, sdate] @@ -343,6 +345,7 @@ ROCSS <- function(exp, obs, ref = NULL, time_dim = 'sdate', memb_dim = 'member', if (!is.null(ref)) { if (is.null(cat_dim)) { # calculate probs ref_probs <- .GetProbs(ClimProjDiags::Subset(ref, dat_dim, exp_i, drop = 'selected'), + time_dim = time_dim, memb_dim = memb_dim, indices_for_quantiles = indices_for_clim, prob_thresholds = prob_thresholds, cross.val = cross.val) } else { diff --git a/R/RPS.R b/R/RPS.R index c5ff5ba..e0a006b 100644 --- a/R/RPS.R +++ b/R/RPS.R @@ -254,7 +254,7 @@ RPS <- function(exp, obs, time_dim = 'sdate', memb_dim = 'member', cat_dim = NUL #--- if cat_dim: # exp: [sdate, bin, (dat)] # obs: [sdate, bin, (dat)] - + # Adjust dimensions to be [sdate, memb, dat] for both exp and obs if (!is.null(memb_dim)) { if (!memb_dim %in% names(dim(obs))) { @@ -293,9 +293,11 @@ RPS <- function(exp, obs, time_dim = 'sdate', memb_dim = 'member', cat_dim = NUL } exp_probs <- .GetProbs(data = exp_data, indices_for_quantiles = indices_for_clim, + time_dim = time_dim, memb_dim = memb_dim, prob_thresholds = prob_thresholds, weights = weights_data, cross.val = cross.val) # exp_probs: [bin, sdate] obs_probs <- .GetProbs(data = obs_data, indices_for_quantiles = indices_for_clim, + time_dim = time_dim, memb_dim = memb_dim, prob_thresholds = prob_thresholds, weights = NULL, cross.val = cross.val) # obs_probs: [bin, sdate] diff --git a/R/RPSS.R b/R/RPSS.R index 6299eb8..f71a3d0 100644 --- a/R/RPSS.R +++ b/R/RPSS.R @@ -405,6 +405,7 @@ RPSS <- function(exp, obs, ref = NULL, time_dim = 'sdate', memb_dim = 'member', obs_data <- obs[ , , j] if (is.null(dim(obs_data))) dim(obs_data) <- c(dim(obs)[1:2]) obs_probs <- .GetProbs(data = obs_data, indices_for_quantiles = indices_for_clim, + time_dim = time_dim, memb_dim = memb_dim, prob_thresholds = prob_thresholds, weights = NULL, cross.val = cross.val) # obs_probs: [bin, sdate] } else { -- GitLab From fd87f5bfb4fc15f695043c11dad18a6abbbe8c22 Mon Sep 17 00:00:00 2001 From: Carlos Delgado Date: Tue, 12 Sep 2023 11:04:16 +0200 Subject: [PATCH 2/3] Revert "fixed indices_for_clim" This reverts commit 33b82398e59b2649e370a81cc017faae70965577. --- R/GetProbs.R | 4 +--- R/ROCSS.R | 3 --- R/RPS.R | 4 +--- R/RPSS.R | 1 - 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/R/GetProbs.R b/R/GetProbs.R index fed15ca..59304b4 100644 --- a/R/GetProbs.R +++ b/R/GetProbs.R @@ -167,9 +167,7 @@ GetProbs <- function(data, time_dim = 'sdate', memb_dim = 'member', indices_for_ ## if data is exp: [sdate, memb] ## if data is obs: [sdate, (memb)] # weights: [sdate, (memb)], same as data - - if (is.null(indices_for_quantiles)){indices_for_quantiles <- 1:dim(data)[time_dim]} - + # Add dim [memb = 1] to data if it doesn't have memb_dim if (length(dim(data)) == 1) { dim(data) <- c(dim(data), 1) diff --git a/R/ROCSS.R b/R/ROCSS.R index 022df85..2ca0782 100644 --- a/R/ROCSS.R +++ b/R/ROCSS.R @@ -325,11 +325,9 @@ ROCSS <- function(exp, obs, ref = NULL, time_dim = 'sdate', memb_dim = 'member', ## if exp: [sdate, memb] ## if obs: [sdate, (memb)] exp_probs <- .GetProbs(data = ClimProjDiags::Subset(exp, dat_dim, exp_i, drop = 'selected'), - time_dim = time_dim, memb_dim = memb_dim, indices_for_quantiles = indices_for_clim, prob_thresholds = prob_thresholds, cross.val = cross.val) obs_probs <- .GetProbs(data = ClimProjDiags::Subset(obs, dat_dim, obs_i, drop = 'selected'), - time_dim = time_dim, memb_dim = memb_dim, indices_for_quantiles = indices_for_clim, prob_thresholds = prob_thresholds, cross.val = cross.val) ## exp_probs and obs_probs: [bin, sdate] @@ -345,7 +343,6 @@ ROCSS <- function(exp, obs, ref = NULL, time_dim = 'sdate', memb_dim = 'member', if (!is.null(ref)) { if (is.null(cat_dim)) { # calculate probs ref_probs <- .GetProbs(ClimProjDiags::Subset(ref, dat_dim, exp_i, drop = 'selected'), - time_dim = time_dim, memb_dim = memb_dim, indices_for_quantiles = indices_for_clim, prob_thresholds = prob_thresholds, cross.val = cross.val) } else { diff --git a/R/RPS.R b/R/RPS.R index e0a006b..c5ff5ba 100644 --- a/R/RPS.R +++ b/R/RPS.R @@ -254,7 +254,7 @@ RPS <- function(exp, obs, time_dim = 'sdate', memb_dim = 'member', cat_dim = NUL #--- if cat_dim: # exp: [sdate, bin, (dat)] # obs: [sdate, bin, (dat)] - + # Adjust dimensions to be [sdate, memb, dat] for both exp and obs if (!is.null(memb_dim)) { if (!memb_dim %in% names(dim(obs))) { @@ -293,11 +293,9 @@ RPS <- function(exp, obs, time_dim = 'sdate', memb_dim = 'member', cat_dim = NUL } exp_probs <- .GetProbs(data = exp_data, indices_for_quantiles = indices_for_clim, - time_dim = time_dim, memb_dim = memb_dim, prob_thresholds = prob_thresholds, weights = weights_data, cross.val = cross.val) # exp_probs: [bin, sdate] obs_probs <- .GetProbs(data = obs_data, indices_for_quantiles = indices_for_clim, - time_dim = time_dim, memb_dim = memb_dim, prob_thresholds = prob_thresholds, weights = NULL, cross.val = cross.val) # obs_probs: [bin, sdate] diff --git a/R/RPSS.R b/R/RPSS.R index f71a3d0..6299eb8 100644 --- a/R/RPSS.R +++ b/R/RPSS.R @@ -405,7 +405,6 @@ RPSS <- function(exp, obs, ref = NULL, time_dim = 'sdate', memb_dim = 'member', obs_data <- obs[ , , j] if (is.null(dim(obs_data))) dim(obs_data) <- c(dim(obs)[1:2]) obs_probs <- .GetProbs(data = obs_data, indices_for_quantiles = indices_for_clim, - time_dim = time_dim, memb_dim = memb_dim, prob_thresholds = prob_thresholds, weights = NULL, cross.val = cross.val) # obs_probs: [bin, sdate] } else { -- GitLab From a39d1518d36504719a320c90cf2fdc648f804302 Mon Sep 17 00:00:00 2001 From: Carlos Delgado Date: Tue, 12 Sep 2023 11:07:19 +0200 Subject: [PATCH 3/3] removed default value for indices_for_quantiles; also removed time_dim and memb_dim as arguments (they were not used) --- R/GetProbs.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/R/GetProbs.R b/R/GetProbs.R index 59304b4..9960c53 100644 --- a/R/GetProbs.R +++ b/R/GetProbs.R @@ -151,8 +151,6 @@ GetProbs <- function(data, time_dim = 'sdate', memb_dim = 'member', indices_for_ output_dims = c("bin", time_dim), fun = .GetProbs, # dat_dim = dat_dim, - time_dim = time_dim, - memb_dim = memb_dim, prob_thresholds = prob_thresholds, indices_for_quantiles = indices_for_quantiles, weights = weights, cross.val = cross.val, ncores = ncores)$output1 @@ -160,7 +158,7 @@ GetProbs <- function(data, time_dim = 'sdate', memb_dim = 'member', indices_for_ return(res) } -.GetProbs <- function(data, time_dim = 'sdate', memb_dim = 'member', indices_for_quantiles = NULL, +.GetProbs <- function(data, indices_for_quantiles, prob_thresholds = c(1/3, 2/3), weights = NULL, cross.val = FALSE) { # .GetProbs() is used in RPS, RPSS, ROCSS # data -- GitLab