From e93441dbdd4ba36294ff25ebb12c17558f48cc14 Mon Sep 17 00:00:00 2001 From: "alasdair.hunter" Date: Thu, 20 Apr 2017 17:15:47 +0200 Subject: [PATCH 1/3] Minor bugfix --- R/Corr.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/Corr.R b/R/Corr.R index 10858c29..4654db2c 100644 --- a/R/Corr.R +++ b/R/Corr.R @@ -149,8 +149,8 @@ Corr <- function(var_exp, var_obs, posloop = 1, poscor = 2, compROW = NULL, } } if (pval && (method == "pearson")) { - t <- CORR * sqrt((eno - 2) / (1 - (CORR ^ 2))) - p_val <- 1 - pt(t, eno - 2) + t <-sqrt(CORR * CORR * (eno - 2) / (1 - (CORR ^ 2))) + p_val <- pt(t, eno - 2, lower.tail = FALSE) } if (conf && (method == "pearson")) { conf_low <- (1 - siglev) / 2 -- GitLab From 5b5d7199e31e374aca4b6cc3b3e79b2d37bceabf Mon Sep 17 00:00:00 2001 From: Nicolau Manubens Date: Fri, 21 Apr 2017 11:51:57 +0200 Subject: [PATCH 2/3] Fix in PlotLayout for custom dimension orderings. Fixes #189. --- R/PlotLayout.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/PlotLayout.R b/R/PlotLayout.R index a3f67e56..7d5eee1e 100644 --- a/R/PlotLayout.R +++ b/R/PlotLayout.R @@ -432,8 +432,13 @@ PlotLayout <- function(fun, plot_dims, var, ..., special_args = NULL, } plot_number <<- plot_number + 1 } else { + if (is.character(plot_dims[[array_number]])) { + plot_dim_indices <- which(names(dim(x)) %in% plot_dims[[array_number]]) + } else { + plot_dim_indices <- plot_dims[[array_number]] + } # For each of the arrays provided in that array - apply(x, (1:length(dim(x)))[1:(length(dim(x)) - length(plot_dims[[array_number]]))], + apply(x, (1:length(dim(x)))[-plot_dim_indices], function(y) { # Do the plot fun_args <- c(list(y, toptitle = titles[plot_number]), list(...), -- GitLab From 8991ba0a9c9d871f36c395f862f40bdbe678fae8 Mon Sep 17 00:00:00 2001 From: Nicolau Manubens Date: Mon, 15 May 2017 17:30:45 +0200 Subject: [PATCH 3/3] Fixed bug when loading files with generic grids. Fixes #192. --- R/Load.R | 13 +++++++++---- R/Utils.R | 19 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/R/Load.R b/R/Load.R index 96b696a8..190872f3 100644 --- a/R/Load.R +++ b/R/Load.R @@ -268,14 +268,19 @@ Load <- function(var, exp = NULL, obs = NULL, sdates, nmember = NULL, # grid if (!is.null(grid)) { if (is.character(grid)) { - supported_grids <- list('r[0-9]{1,}x[0-9]{1,}', 't[0-9]{1,}grid') - grid_matches <- unlist(lapply(lapply(supported_grids, regexpr, grid), .IsFullMatch, grid)) - if (sum(grid_matches) < 1) { - stop("The specified grid in the parameter 'grid' is incorrect. Must be one of rx or tgrid.") + if (grid == 'none') { + grid <- NULL + } else { + supported_grids <- list('r[0-9]{1,}x[0-9]{1,}', 't[0-9]{1,}grid') + grid_matches <- unlist(lapply(lapply(supported_grids, regexpr, grid), .IsFullMatch, grid)) + if (sum(grid_matches) < 1) { + stop("The specified grid in the parameter 'grid' is incorrect. Must be one of rx or tgrid.") + } } } else { stop("Error: parameter 'grid' should be a character string, if specified.") } + } } # maskmod diff --git a/R/Utils.R b/R/Utils.R index ec154153..c748a508 100644 --- a/R/Utils.R +++ b/R/Utils.R @@ -220,6 +220,9 @@ # Here we read the grid type and its number of longitudes and latitudes file_info <- system(paste('cdo -s griddes', filein, '2> /dev/null'), intern = TRUE) grids_positions <- grep('# gridID', file_info) + if (length(grids_positions) < 1) { + stop("The grid should be defined in the files.") + } grids_first_lines <- grids_positions + 2 grids_last_lines <- c((grids_positions - 2)[-1], length(file_info)) grids_info <- as.list(1:length(grids_positions)) @@ -239,12 +242,14 @@ } else { NA } - if ((nlons == length(lon)) && - (nlats == length(lat))) { - TRUE - } else { - FALSE + result <- FALSE + if (!any(is.na(c(nlons, nlats)))) { + if ((nlons == length(lon)) && + (nlats == length(lat))) { + result <- TRUE + } } + result })) grids_matches <- grids_matches[which(grids_types %in% c('gaussian', 'lonlat'))] grids_info <- grids_info[which(grids_types %in% c('gaussian', 'lonlat'))] @@ -261,8 +266,10 @@ } else { stop("Error: Load() can't disambiguate: More than one lonlat/gaussian grids with the same size as the requested variable defined in ", filename) } - } else { + } else if (sum(grids_matches) == 1) { grid_type <- grids_types[which(grids_matches)] + } else { + stop("Unexpected error.") } grid_lons <- length(lon) grid_lats <- length(lat) -- GitLab