From 597b48e1640186fa4f0eb15f0527f8bc1bf311a1 Mon Sep 17 00:00:00 2001 From: aho Date: Mon, 17 Jan 2022 12:58:38 +0100 Subject: [PATCH 1/3] Add 'useRaster = TRUE' in image() to avoid artifect lines --- R/PlotEquiMap.R | 2 +- R/PlotSection.R | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/PlotEquiMap.R b/R/PlotEquiMap.R index 3de30e9..db1829f 100644 --- a/R/PlotEquiMap.R +++ b/R/PlotEquiMap.R @@ -849,7 +849,7 @@ PlotEquiMap <- function(var, lon, lat, varu = NULL, varv = NULL, if (square) { image(lonb$x, latb$x, var[lonb$ix, latb$ix], col = c(col_inf_image, cols, col_sup_image), breaks = c(-.Machine$double.xmax, brks, .Machine$double.xmax), - axes = FALSE, xlab = "", ylab = "", add = TRUE) + axes = FALSE, xlab = "", ylab = "", add = TRUE, useRaster = TRUE) } else { .filled.contour(lonb$x, latb$x, var[lonb$ix, latb$ix], levels = c(.Machine$double.xmin, brks, .Machine$double.xmax), diff --git a/R/PlotSection.R b/R/PlotSection.R index 29bdd49..1cceaab 100644 --- a/R/PlotSection.R +++ b/R/PlotSection.R @@ -139,9 +139,9 @@ PlotSection <- function(var, horiz, depth, toptitle = '', sizetit = 1, mgp = c(2.5, 0.5, 0), las = 1) image(horizb$x, depthb$x, array(0, dims), col = 'grey', breaks = c(-1, 1), axes = FALSE, xlab = "", ylab = "", main = toptitle, - cex.main = 1.5 * sizetit) + cex.main = 1.5 * sizetit, useRaster = TRUE) image(horizb$x, depthb$x, var[horizb$ix, depthb$ix], col = cols, - breaks = brks, axes = FALSE, xlab = "", ylab = "", add = TRUE) + breaks = brks, axes = FALSE, xlab = "", ylab = "", add = TRUE, useRaster = TRU, useRaster = TRUE) if (axelab) { minhoriz <- ceiling(round(min(horizb$x), 0) / 10) * 10 maxhoriz <- floor(round(max(horizb$x), 0) / 10) * 10 @@ -158,7 +158,7 @@ PlotSection <- function(var, horiz, depth, toptitle = '', sizetit = 1, par(mar = c(1.5, ymargin, 2.5, 0.5), mgp = c(1.5, 0.3, 0), las = 1, cex = 1.2) image(1:length(cols), 1, t(t(1:length(cols))), axes = FALSE, col = cols, - xlab = units, ylab = '') + xlab = units, ylab = '', useRaster = TRUE) box() axis(1, at = seq(0.5, length(brks) - 0.5, 1), labels = brks, cex.axis = 1) } -- GitLab From 6b8c1e6e25e383039dbbfaef8d6a07d60c2fe706 Mon Sep 17 00:00:00 2001 From: aho Date: Mon, 17 Jan 2022 13:13:10 +0100 Subject: [PATCH 2/3] Remove 'useRaster = TRUE' in PlotSection because it only can be used with regular-spaced grid --- R/PlotSection.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/PlotSection.R b/R/PlotSection.R index 1cceaab..29bdd49 100644 --- a/R/PlotSection.R +++ b/R/PlotSection.R @@ -139,9 +139,9 @@ PlotSection <- function(var, horiz, depth, toptitle = '', sizetit = 1, mgp = c(2.5, 0.5, 0), las = 1) image(horizb$x, depthb$x, array(0, dims), col = 'grey', breaks = c(-1, 1), axes = FALSE, xlab = "", ylab = "", main = toptitle, - cex.main = 1.5 * sizetit, useRaster = TRUE) + cex.main = 1.5 * sizetit) image(horizb$x, depthb$x, var[horizb$ix, depthb$ix], col = cols, - breaks = brks, axes = FALSE, xlab = "", ylab = "", add = TRUE, useRaster = TRU, useRaster = TRUE) + breaks = brks, axes = FALSE, xlab = "", ylab = "", add = TRUE) if (axelab) { minhoriz <- ceiling(round(min(horizb$x), 0) / 10) * 10 maxhoriz <- floor(round(max(horizb$x), 0) / 10) * 10 @@ -158,7 +158,7 @@ PlotSection <- function(var, horiz, depth, toptitle = '', sizetit = 1, par(mar = c(1.5, ymargin, 2.5, 0.5), mgp = c(1.5, 0.3, 0), las = 1, cex = 1.2) image(1:length(cols), 1, t(t(1:length(cols))), axes = FALSE, col = cols, - xlab = units, ylab = '', useRaster = TRUE) + xlab = units, ylab = '') box() axis(1, at = seq(0.5, length(brks) - 0.5, 1), labels = brks, cex.axis = 1) } -- GitLab From b9763e1210a47ab4719770ddf63fa9e401da9436 Mon Sep 17 00:00:00 2001 From: aho Date: Mon, 17 Jan 2022 17:14:30 +0100 Subject: [PATCH 3/3] Add error handling for 'useRaster' --- R/PlotEquiMap.R | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/R/PlotEquiMap.R b/R/PlotEquiMap.R index db1829f..9981ed3 100644 --- a/R/PlotEquiMap.R +++ b/R/PlotEquiMap.R @@ -847,9 +847,19 @@ PlotEquiMap <- function(var, lon, lat, varu = NULL, varv = NULL, col_inf_image <- ifelse(is.null(col_inf), colNA, col_inf) col_sup_image <- ifelse(is.null(col_sup), colNA, col_sup) if (square) { - image(lonb$x, latb$x, var[lonb$ix, latb$ix], col = c(col_inf_image, cols, col_sup_image), - breaks = c(-.Machine$double.xmax, brks, .Machine$double.xmax), - axes = FALSE, xlab = "", ylab = "", add = TRUE, useRaster = TRUE) + # If lat and lon are both regular-spaced, "useRaster = TRUE" can avoid + # artifact white lines on the figure. If not, useRaster has to be FALSE (default) + tryCatch({ + image(lonb$x, latb$x, var[lonb$ix, latb$ix], + col = c(col_inf_image, cols, col_sup_image), + breaks = c(-.Machine$double.xmax, brks, .Machine$double.xmax), + axes = FALSE, xlab = "", ylab = "", add = TRUE, useRaster = TRUE) + }, error = function(x) { + image(lonb$x, latb$x, var[lonb$ix, latb$ix], + col = c(col_inf_image, cols, col_sup_image), + breaks = c(-.Machine$double.xmax, brks, .Machine$double.xmax), + axes = FALSE, xlab = "", ylab = "", add = TRUE) + }) } else { .filled.contour(lonb$x, latb$x, var[lonb$ix, latb$ix], levels = c(.Machine$double.xmin, brks, .Machine$double.xmax), -- GitLab