From 5ae5c48b6685a5d4a86928efdb2ee802a51e18e0 Mon Sep 17 00:00:00 2001 From: Jaume Ramon Date: Mon, 29 May 2023 15:36:51 +0200 Subject: [PATCH] when observations are already given pointwise, there's no need to interpolate the observations to the point locations. This bug has been corrected for the 4nn method --- R/Analogs.R | 2 +- R/Intlr.R | 2 +- R/LogisticReg.R | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/R/Analogs.R b/R/Analogs.R index f0ebd61..c1dd4de 100644 --- a/R/Analogs.R +++ b/R/Analogs.R @@ -381,7 +381,7 @@ Analogs <- function(exp, obs, exp_lats, exp_lons, obs_lats, obs_lons, grid_exp, method_remap = "conservative", region = region, ncores = ncores) # If after interpolating 'obs' data the coordinates do not match, the exp data is interpolated to # the same grid to force the matching - if (!.check_coords(lat1 = obs_interpolated$lat, lat2 = exp_lats, lon1 = obs_interpolated$lon, lon2 = exp_lons)) { + if (!.check_coords(lat1 = as.numeric(obs_interpolated$lat), lat2 = exp_lats, lon1 = as.numeric(obs_interpolated$lon), lon2 = exp_lons)) { exp_interpolated <- Interpolation(exp = exp, lats = exp_lats, lons = exp_lons, target_grid = grid_exp, lat_dim = lat_dim, lon_dim = lon_dim, method_remap = "conservative", region = region, ncores = ncores)$data diff --git a/R/Intlr.R b/R/Intlr.R index f31b7d3..55bd70c 100644 --- a/R/Intlr.R +++ b/R/Intlr.R @@ -407,7 +407,7 @@ Intlr <- function(exp, obs, exp_lats, exp_lons, obs_lats, obs_lons, lr_method, t predictor <- .find_nn(coar = exp, lats_hres = obs_lats, lons_hres = obs_lons, lats_coar = exp_lats, lons_coar = exp_lons, lat_dim = lat_dim, lon_dim = lon_dim, nn = 4, ncores = ncores) - if (is.null(points)) { + if (is.null(points) | ("location" %in% names(dim(obs)))) { if (!is.null(target_grid)) { warning("Interpolating to the 'obs' grid") } diff --git a/R/LogisticReg.R b/R/LogisticReg.R index b41df33..0759d17 100644 --- a/R/LogisticReg.R +++ b/R/LogisticReg.R @@ -272,13 +272,13 @@ LogisticReg <- function(exp, obs, exp_lats, exp_lons, obs_lats, obs_lons, target stop("Parameter 'loocv' must be set to TRUE or FALSE") } - if (is.na(match(lon_dim, names(dim(exp)))) | is.na(match(lon_dim, names(dim(obs))))) { - stop("Missing longitude dimension in 'exp' and/or 'obs', or does not match the parameter ", + if (is.na(match(lon_dim, names(dim(exp))))) { + stop("Missing longitude dimension in 'exp', or does not match the parameter ", "'lon_dim'") } - if (is.na(match(lat_dim, names(dim(exp)))) | is.na(match(lat_dim, names(dim(obs))))) { - stop("Missing latitude dimension in 'exp' and/or 'obs', or does not match the parameter ", + if (is.na(match(lat_dim, names(dim(exp))))) { + stop("Missing latitude dimension in 'exp', or does not match the parameter ", "'lat_dim'") } @@ -351,6 +351,9 @@ LogisticReg <- function(exp, obs, exp_lats, exp_lons, obs_lats, obs_lons, target target_dims_predictor <- sdate_dim } else if (log_reg_method == "ens_mean_sd") { + + require(abind) + ens_mean_anom <- .get_ens_mean_anom(obj_ens = exp_interpolated$data, member_dim = member_dim, sdate_dim = sdate_dim, ncores = ncores) ens_sd <- .get_ens_sd(obj_ens = exp_interpolated$data, member_dim = member_dim, ncores = ncores) @@ -370,8 +373,8 @@ LogisticReg <- function(exp, obs, exp_lats, exp_lons, obs_lats, obs_lons, target # If after interpolating 'exp' data the coordinates do not match, the obs data is interpolated to # the same grid to force the matching - if ((!.check_coords(lat1 = exp_interpolated$lat, lat2 = obs_lats, - lon1 = exp_interpolated$lon, lon2 = obs_lons)) | !(point_obs)) { + if ((!.check_coords(lat1 = as.numeric(exp_interpolated$lat), lat2 = obs_lats, + lon1 = as.numeric(exp_interpolated$lon), lon2 = obs_lons)) | !(point_obs)) { obs_interpolated <- Interpolation(exp = obs, lats = obs_lats, lons = obs_lons, target_grid = target_grid, method_remap = int_method, points = points, source_file = source_file_obs, lat_dim = lat_dim, lon_dim = lon_dim, method_point_interp = method_point_interp, -- GitLab