diff --git a/DESCRIPTION b/DESCRIPTION index 005f5b7..d1cee6e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,6 +27,6 @@ Suggests: viridis VignetteBuilder: knitr License: GPL-3 -RoxygenNote: 7.1.1 +RoxygenNote: 7.2.3 URL: https://github.com/AustralianAntarcticDivision/palr BugReports: https://github.com/AustralianAntarcticDivision/palr/issues diff --git a/NEWS.md b/NEWS.md index c86625d..19625e4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # palr 0.4.0 +* `ice_pal()` now defaults to the more pleasing NSIDC blue palette (use `amsre = TRUE` to get the old behavour). +* Fixed a problem with missing values in `d_pal()`. # palr 0.3.0 * New function `d_pal()` and alias `data_pal()` to colour data values (like {colourvalues} but diff --git a/R/image_pal.R b/R/image_pal.R index dc15363..27bf59e 100644 --- a/R/image_pal.R +++ b/R/image_pal.R @@ -26,11 +26,10 @@ #' @export #' @importFrom grDevices hcl.colors #' @examples -#' set.seed(28) #' vals <- sort(rnorm(100)) -#' cols <- image_pal(vals, zlim = c(-2.4, 2)) -#' plot(vals, col = cols); abline(h = 2) -#' points(vals, pch = 19, cex = 0.1) ## zlim excluded some of the range +#' cols <- image_pal(vals, zlim = c(-2.4, .5)) +#' plot(vals, col = cols); abline(h = .5) +#' points(vals, pch = ".") ## zlim excluded some of the range image_pal <- function(x, col, ..., breaks = NULL, n = NULL, zlim = NULL) { if (missing(col)) { @@ -63,21 +62,6 @@ image_pal <- function(x, col, ..., breaks = NULL, n = NULL, zlim = NULL) { #' @name image_pal #' @export -#' @examples -#' if (requireNamespace("raster", quietly = TRUE)) { -#' im <- image_raster(volcano) -#' library(raster) -#' plotRGB(im) -#' \donttest{ -#' vv <- unique(quantile(volcano, seq(0, 1, length = 12))) -#' plotRGB(image_raster(volcano, breaks = vv)) -#' plotRGB(image_raster(volcano, breaks = vv[-c(4, 6)], col = gray.colors(9))) -#' plotRGB(image_raster(volcano, n = 4)) -#' plotRGB(image_raster(volcano, col = grey(seq(0.2, 0.8, by = 0.1)))) -#' -#' plotRGB(image_raster(volcano, col = viridis::magma(24))) -#' } -#' } image_raster <- function(x, col, ..., breaks = NULL, n = NULL, zlim = NULL) { if (!requireNamespace("raster", quietly = TRUE)) stop("raster package is required for 'image_raster()'") ## for matrix input @@ -91,17 +75,6 @@ image_raster <- function(x, col, ..., breaks = NULL, n = NULL, zlim = NULL) { } #' @name image_pal #' @export -#' @examples -#' if (!requireNamespace("stars", quietly = TRUE)) { -#' library(stars) -#' x <- st_as_stars(volcano) -#' plot(image_stars(x), rgb = 1:3) -#' \donttest{ -#' plot(image_stars(x, col = gray.colors), rgb = 1:3) -#' plot(image_stars(x)) -#' plot(image_stars(x, col = rainbow, breaks = c(94, 100, 120, 150, 195)), rgb = 1:3) -#' } -#' } image_stars <- function(x, col, ..., breaks = NULL, n = NULL, zlim = NULL) { if (!requireNamespace("stars", quietly = TRUE)) stop("stars package is required for 'image_stars()'") hex <- image_pal(as.vector(unclass(x[[1L]])), col = col, ..., breaks = breaks, n = n, zlim = zlim) ## we aint proxy yet diff --git a/R/palr.R b/R/palr.R index 528cea3..f623a54 100644 --- a/R/palr.R +++ b/R/palr.R @@ -276,7 +276,9 @@ col2hex <- function(x, alpha = 1) { #' @param palette logical, if \code{TRUE} return a list with matching colours and values #' @param alpha value in 0,1 to specify opacity #' @param ... currently ignored -#' @references Derived from \url{http://www.iup.uni-bremen.de/seaice/amsr/}. +#' @param amsre use old AMSRE colours (`FALSE` by default) +#' @references amsre colours derived from \url{http://www.iup.uni-bremen.de/seaice/amsr/}., +#' nsidc colours extracted in data-raw/. #' @return colours, palette, or function, see Details #' @export #' @examples @@ -288,9 +290,9 @@ col2hex <- function(x, alpha = 1) { #' plot(r, col = icp$col, zlim = range(icp$breaks), #' main = sprintf("NSIDC ice \\% %s", format(getZ(r)))) #' } -ice_pal <- function(x, palette = FALSE, alpha = 1, ...) { +ice_pal <- function(x, palette = FALSE, alpha = 1, ..., amsre = FALSE) { - cols <- head(.amsrecols(), 201) + if (amsre) cols <- head(.amsrecols(), 201) else cols <- .nsidc_colours breaks <- seq(0, 100, length = length(cols)) hexalpha <- as.hexmode(round(255 * alpha)) if (nchar(hexalpha) == 1L) hexalpha <- paste(rep(hexalpha, 2L), collapse = "") diff --git a/R/sysdata.rda b/R/sysdata.rda new file mode 100644 index 0000000..f33cff5 Binary files /dev/null and b/R/sysdata.rda differ diff --git a/data-raw/nsidc_colours.R b/data-raw/nsidc_colours.R new file mode 100644 index 0000000..7ee22be --- /dev/null +++ b/data-raw/nsidc_colours.R @@ -0,0 +1,5 @@ + r <- terra::rast("/vsicurl/https://noaadata.apps.nsidc.org/NOAA/G02135/south/daily/geotiff/2023/10_Oct/S_20231030_concentration_v3.0.tif") +.nsidc_coltab <- terra::coltab(r) [[1]][1:1001, ] + +.nsidc_colours <- rgb(.nsidc_coltab[["red"]], .nsidc_coltab[["green"]], .nsidc_coltab[["blue"]], maxColorValue = 255) +usethis::use_data(.nsidc_colours, internal = TRUE) diff --git a/man/ice_pal.Rd b/man/ice_pal.Rd index 91ec434..b3f5177 100644 --- a/man/ice_pal.Rd +++ b/man/ice_pal.Rd @@ -5,7 +5,7 @@ \alias{icePal} \title{Sea ice colours} \usage{ -ice_pal(x, palette = FALSE, alpha = 1, ...) +ice_pal(x, palette = FALSE, alpha = 1, ..., amsre = FALSE) icePal(x, palette = FALSE, alpha = 1, ...) } @@ -17,6 +17,8 @@ icePal(x, palette = FALSE, alpha = 1, ...) \item{alpha}{value in 0,1 to specify opacity} \item{...}{currently ignored} + +\item{amsre}{use old AMSRE colours (`FALSE` by default)} } \value{ colours, palette, or function, see Details @@ -41,5 +43,6 @@ main = sprintf("NSIDC ice \\\\\% \%s", format(getZ(r)))) } } \references{ -Derived from \url{http://www.iup.uni-bremen.de/seaice/amsr/}. +amsre colours derived from \url{http://www.iup.uni-bremen.de/seaice/amsr/}., + nsidc colours extracted in data-raw/. } diff --git a/man/image_pal.Rd b/man/image_pal.Rd index 5708b68..80f301f 100644 --- a/man/image_pal.Rd +++ b/man/image_pal.Rd @@ -46,33 +46,8 @@ other situations, for controlling exactly the kind of plots we can achieve and f to image formats such as 'GeoTIFF' or 'PNG'. } \examples{ -set.seed(28) vals <- sort(rnorm(100)) -cols <- image_pal(vals, zlim = c(-2.4, 2)) -plot(vals, col = cols); abline(h = 2) -points(vals, pch = 19, cex = 0.1) ## zlim excluded some of the range -if (requireNamespace("raster", quietly = TRUE)) { -im <- image_raster(volcano) -library(raster) -plotRGB(im) -\donttest{ -vv <- unique(quantile(volcano, seq(0, 1, length = 12))) -plotRGB(image_raster(volcano, breaks = vv)) -plotRGB(image_raster(volcano, breaks = vv[-c(4, 6)], col = gray.colors(9))) -plotRGB(image_raster(volcano, n = 4)) -plotRGB(image_raster(volcano, col = grey(seq(0.2, 0.8, by = 0.1)))) - -plotRGB(image_raster(volcano, col = viridis::magma(24))) -} -} -if (!requireNamespace("stars", quietly = TRUE)) { -library(stars) -x <- st_as_stars(volcano) -plot(image_stars(x), rgb = 1:3) -\donttest{ -plot(image_stars(x, col = gray.colors), rgb = 1:3) -plot(image_stars(x)) -plot(image_stars(x, col = rainbow, breaks = c(94, 100, 120, 150, 195)), rgb = 1:3) -} -} +cols <- image_pal(vals, zlim = c(-2.4, .5)) +plot(vals, col = cols); abline(h = .5) +points(vals, pch = ".") ## zlim excluded some of the range }