Commit abeb0962 authored by aho's avatar aho
Browse files

Refine the code for masks

parent cc33fb19
Pipeline #5781 passed with stage
in 4 minutes and 8 seconds
......@@ -6,8 +6,9 @@
#'A colour bar (legend) can be plotted and adjusted. It is possible to draw
#'superimposed arrows, dots, symbols, contour lines and boxes. A number of
#'options is provided to adjust the position, size and colour of the
#'components. This plot function is compatible with figure layouts if colour
#'bar is disabled.
#'components. Some parameters are provided to add and adjust the masks that
#'include continents, oceans, and lakes. This plot function is compatible with
#'figure layouts if colour bar is disabled.
#'
#'@param var Array with the values at each cell of a grid on a regular
#' rectangular or gaussian grid. The array is expected to have two
......@@ -68,8 +69,7 @@
#'@param coast_width Line width of the coast line of the drawn projected
#' continents. Takes the value 1 by default.
#'@param lake_color Colour of the lake or other water body inside continents.
#' It is only functional when 'filled.continents = TRUE'. The default value is
#' 'white'. For now, it is only functional if longitude range is [0, 360].
#' The default value is NULL.
#'@param contours Array of same dimensions as 'var' to be added to the plot
#' and displayed with contours. Parameter 'brks2' is required to define the
#' magnitude breaks for each contour curve. Disregarded if 'square = FALSE'.
......@@ -419,7 +419,7 @@ PlotEquiMap <- function(var, lon, lat, varu = NULL, varv = NULL,
} else if (!is.logical(filled.continents)) {
continent_color <- filled.continents
filled.continents <- TRUE
} else if (filled.continents) {
} else {
continent_color <- gray(0.5)
}
......@@ -451,11 +451,11 @@ PlotEquiMap <- function(var, lon, lat, varu = NULL, varv = NULL,
}
# Check lake_color
if (is.null(lake_color)) {
if (filled.continents) {
lake_color <- 'white'
}
} else {
if (!is.null(lake_color)) {
# if (filled.continents) {
# lake_color <- 'white'
# }
# } else {
if (!.IsColor(lake_color)) {
stop("Parameter 'lake_color' must be a valid colour identifier.")
}
......@@ -826,30 +826,51 @@ PlotEquiMap <- function(var, lon, lat, varu = NULL, varv = NULL,
} else { # [0, 360]
xlim_conti <- c(0.01, 359.99)
}
coast <- map(continents, interior = FALSE, wrap = TRUE,
xlim = xlim_conti, ylim = c(-89.99, 89.99),
fill = filled.continents, add = TRUE, plot = FALSE)
if (filled.continents) {
old_lwd <- par('lwd')
par(lwd = coast_width)
if (min(lon) >= 0) {
ylat <- latmin:latmax
xlon <- lonmin:lonmax
proj <- GEOmap::setPROJ(1, LON0 = mean(xlon),
LAT0 = mean(ylat), LATS = ylat, LONS = xlon)
lakes <- which(coastmap$STROKES$col == "blue")
old_lwd <- par('lwd')
par(lwd = coast_width)
# If [0, 360], use GEOmap; if [-180, 180], use maps
if (min(lon) >= 0) {
ylat <- latmin:latmax
xlon <- lonmin:lonmax
proj <- GEOmap::setPROJ(1, LON0 = mean(xlon),
LAT0 = mean(ylat), LATS = ylat, LONS = xlon)
lakes <- which(coastmap$STROKES$col == "blue")
par(new = TRUE)
if (filled.continents) {
coastmap$STROKES$col[which(coastmap$STROKES$col != "blue")] <- continent_color
coastmap$STROKES$col[lakes] <- lake_color #"white"
par(new = TRUE)
if (is.null(lake_color)) {
coastmap$STROKES$col[lakes] <- continent_color
} else {
coastmap$STROKES$col[lakes] <- lake_color #"white"
}
GEOmap::plotGEOmap(coastmap, PROJ = proj, border = coast_color,
add = TRUE, lwd = coast_width)
} else {
polygon(coast, col = continent_color, border = coast_color, lwd = coast_width)
coastmap$STROKES$col[which(coastmap$STROKES$col != "blue")] <- coast_color
if (is.null(lake_color)) {
coastmap$STROKES$col[lakes] <- coast_color
} else {
coastmap$STROKES$col[lakes] <- lake_color #"white"
}
GEOmap::plotGEOmap(coastmap, PROJ = proj, #MAPcol = coast_color,
add = TRUE, lwd = coast_width, MAPstyle = 2)
}
par(lwd = old_lwd)
} else {
lines(coast, col = coast_color, lwd = coast_width)
# [-180, 180]
coast <- map(continents, interior = FALSE, wrap = TRUE,
xlim = xlim_conti, ylim = c(-89.99, 89.99),
fill = filled.continents, add = TRUE, plot = FALSE)
if (filled.continents) {
polygon(coast, col = continent_color, border = coast_color, lwd = coast_width)
} else {
lines(coast, col = coast_color, lwd = coast_width)
}
if (!is.null(lake_color)) {
map('lakes', add = TRUE, fill = filled.continents, col = lake_color)
}
}
par(lwd = old_lwd)
# filled.oceans
if (filled.oceans) {
......
......@@ -152,8 +152,7 @@ Takes the value gray(0.5) by default.}
continents. Takes the value 1 by default.}
\item{lake_color}{Colour of the lake or other water body inside continents.
It is only functional when 'filled.continents = TRUE'. The default value is
'white'. For now, it is only functional if longitude range is [0, 360].}
The default value is NULL.}
\item{contours}{Array of same dimensions as 'var' to be added to the plot
and displayed with contours. Parameter 'brks2' is required to define the
......@@ -315,8 +314,9 @@ grid cells. Only the region for which data has been provided is displayed.
A colour bar (legend) can be plotted and adjusted. It is possible to draw
superimposed arrows, dots, symbols, contour lines and boxes. A number of
options is provided to adjust the position, size and colour of the
components. This plot function is compatible with figure layouts if colour
bar is disabled.
components. Some parameters are provided to add and adjust the masks that
include continents, oceans, and lakes. This plot function is compatible with
figure layouts if colour bar is disabled.
}
\examples{
# See examples on Load() to understand the first lines in this example
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment