From a4625f08490a3feb64e133ef389b39d2e802f731 Mon Sep 17 00:00:00 2001 From: Adriaan Dokter Date: Fri, 6 Oct 2023 09:54:54 -0400 Subject: [PATCH 01/27] skip day instead of abort when no data available (fix #636) --- R/download_pvolfiles.R | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/R/download_pvolfiles.R b/R/download_pvolfiles.R index 4f319ecb..911a8d7b 100644 --- a/R/download_pvolfiles.R +++ b/R/download_pvolfiles.R @@ -97,7 +97,7 @@ download_pvolfiles <- function(date_min, date_max, radar, if (nrow(bucket_df) == 0) { # Check if date is correct prefix_tmp <- paste(gsub("-", "/", dates[i_d]), sep = "/") - assertthat::assert_that(assertthat::not_empty( + msg <- assertthat::validate_that(assertthat::not_empty( aws.s3::get_bucket_df(bucket = bucket, prefix = prefix_tmp, max = 1) ), msg = paste0( @@ -105,7 +105,11 @@ download_pvolfiles <- function(date_min, date_max, radar, ". Please check data availability for this date." ) ) - assertthat::assert_that(assertthat::not_empty( + if(msg != TRUE){ + warning(msg) + next + } + msg <- assertthat::validate_that(assertthat::not_empty( aws.s3::get_bucket_df(bucket = bucket, prefix = prefix, max = 1) ), msg = paste0( @@ -114,6 +118,10 @@ download_pvolfiles <- function(date_min, date_max, radar, " https://noaa-nexrad-level2.s3.amazonaws.com/index.html" ) ) + if(msg != TRUE){ + warning(msg) + next + } } # filter bucket with exact date @@ -130,12 +138,17 @@ download_pvolfiles <- function(date_min, date_max, radar, # throw out occasional NA keys, see e.g. 2015/03/01/KEPZ/ bucket_df %>% dplyr::filter(!is.na(.data$Key)) -> bucket_df - assertthat::assert_that(nrow(bucket_df) > 0, + msg <- assertthat::validate_that(nrow(bucket_df) > 0, msg = paste0( "No data available for ", radar, " on the ", dates[i_d], "within the selected datetime range. Check radar code and data availability on", " https://noaa-nexrad-level2.s3.amazonaws.com/index.html" )) + if(msg != TRUE){ + warning(msg) + next + } + # create progress bar message(paste0("\nDownloading pvol for ", prefix)) From f72993b85dab17981bba5052d3fc013ca2293248 Mon Sep 17 00:00:00 2001 From: Adriaan Dokter Date: Fri, 6 Oct 2023 11:22:22 -0400 Subject: [PATCH 02/27] change errors to warnings in unit test --- tests/testthat/test-download_pvolfiles.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-download_pvolfiles.R b/tests/testthat/test-download_pvolfiles.R index 03914607..46969b67 100644 --- a/tests/testthat/test-download_pvolfiles.R +++ b/tests/testthat/test-download_pvolfiles.R @@ -88,7 +88,7 @@ test_that("date input for download_pvolfiles() ", { regexp = "date_max is not greater or equal to date_min", fixed = TRUE ) - expect_error( + expect_warning( suppressMessages( download_pvolfiles( as.POSIXct("2046-10-02 20:00", tz = "UTC"), @@ -108,7 +108,7 @@ test_that("date input for download_pvolfiles() ", { test_that("Check radar code for download_pvolfiles() ", { skip_if_offline() - expect_error( + expect_warning( download_pvolfiles(date_min, date_max, c("KBBX", "KGHC"), @@ -117,7 +117,7 @@ test_that("Check radar code for download_pvolfiles() ", { "radar is not of length 1", fixed = TRUE ) - expect_error( + expect_warning( suppressMessages( download_pvolfiles(date_min, date_max, "ABCD", directory, overwrite) ), From aad39c884c202042ac7a09fc9c4e3b5e42f297ff Mon Sep 17 00:00:00 2001 From: iskandari Date: Tue, 17 Oct 2023 15:46:33 -0400 Subject: [PATCH 03/27] switch map function to use ggspatial::annotation_map_tile() --- DESCRIPTION | 2 ++ R/map.R | 92 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 61 insertions(+), 33 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e2479bca..2438bc4c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,6 +34,7 @@ Imports: fields, frictionless, ggplot2, + ggspatial, glue, graphics, jsonlite, @@ -44,6 +45,7 @@ Imports: readr, rhdf5, rlang, + rosm, sp, stats, suntools, diff --git a/R/map.R b/R/map.R index 5c6a38f9..cd54a08d 100644 --- a/R/map.R +++ b/R/map.R @@ -4,7 +4,7 @@ #' [ggmap::ggmap()]. #' #' @param x A `ppi` object. -#' @param map Basemap to use, result of a call to [download_basemap()]. +#' @param basemap Basemap to use, result of a call to [download_basemap()]. #' @param param Character. Scan parameter to plot, e.g. `DBZH` or `VRADH`. See #' [summary.param()] for commonly available parameters. #' @param alpha Numeric. Transparency of the data, value between 0 and 1. @@ -81,8 +81,8 @@ map <- function(x, ...) { #' @describeIn map Plot a `ppi` object on a map. #' @export -map.ppi <- function(x, map, param, alpha = 0.7, xlim, ylim, zlim = c(-20, 20), - ratio, radar_size = 3, radar_color = "red", n_color = 1000, +map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zlim = c(-20, 20), + ratio, radar_size = 3, radar_color = "#202020", n_color = 1000, palette = NA, ...) { stopifnot(inherits(x, "ppi")) @@ -110,13 +110,15 @@ map.ppi <- function(x, map, param, alpha = 0.7, xlim, ylim, zlim = c(-20, 20), if (is.na(raster::crs(x$data))) { stop("Not a projected ppi, map() expects a ppi generated by project_as_ppi() with argument project=TRUE") } - if (!attributes(map)$ppi) { - stop("Not a ppi map, use download_basemap() to download a map.") - } - if (all(attributes(map)$geo$lat != x$geo$lat) || - all(attributes(map)$geo$lon != x$geo$lon)) { - stop("Not a basemap for this radar location.") - } + + #if (!attributes(map)$ppi) { + # stop("Not a ppi map, use download_basemap() to download a map.") + #} + + #if (all(attributes(map)$geo$lat != x$geo$lat) || + # all(attributes(map)$geo$lon != x$geo$lon)) { + # stop("Not a basemap for this radar location.") + #} # set color scales and palettes if (!assertthat::are_equal(palette, NA)) { @@ -187,45 +189,69 @@ map.ppi <- function(x, map, param, alpha = 0.7, xlim, ylim, zlim = c(-20, 20), return(palette[output]) } + #return(r@data@values) # convert data values to hex color string values. r@data@values <- col_func(r@data@values, zlim) + rdf <- as.data.frame(r, xy = TRUE) + names(rdf) <- c("x", "y", "fill") + rdf$fill <- values(r) + # these declarations prevent generation of NOTE "no visible binding for # global variable" during package Check lon <- lat <- y <- z <- NA # extract unique radar locations - latlon_radar <- unique(data.frame(lat=c(x$geo$lat), lon=c(x$geo$lon))) + # symbols for the radar position # dummy is a hack to be able to include the ggplot2 color scale, # radarpoint is the actual plotting of radar positions. - dummy <- ggplot2::geom_point(ggplot2::aes(x = lon, y = lat, colour = z), - size = 0, - data = data.frame( - lon = latlon_radar$lon, - lat = latlon_radar$lat, - z = 0 - ) - ) + radarpoint <- ggplot2::geom_point(ggplot2::aes(x = lon, y = lat), colour = radar_color, size = radar_size, data = data.frame(lon = latlon_radar$lon, lat = latlon_radar$lat) ) - # bounding box - bboxlatlon <- attributes(map)$geo$bbox - # remove dimnames, otherwise ggmap will give a warning message below: - dimnames(bboxlatlon) <- NULL - if (missing(xlim)) xlim <- bboxlatlon[1, ] - if (missing(ylim)) ylim <- bboxlatlon[2, ] - # plot the data on the map - rlang::check_installed("ggmap",'to map ppi\'s', version = '3.0.0') + + radar_location = data.frame(lon = x$geo$lon, lat = x$geo$lat) %>% + st_as_sf(coords = c("lon", "lat")) %>% + st_set_crs(4326) %>% + st_transform(3857) + + radar_df <- data.frame(st_coordinates(radar_location)) + + dummy <- ggplot2::geom_point(ggplot2::aes(x = lon, y = lat, colour = z), + size = 0, + data = data.frame( + lon = radar_df$X, + lat = radar_df$Y, + z = 0 + )) + mymap <- suppressMessages( - ggmap::ggmap(map) + - ggmap::inset_raster(raster::as.matrix(r), e@xmin, e@xmax, e@ymin, e@ymax) + - dummy + colorscale + - radarpoint + - ggplot2::scale_x_continuous(limits = xlim, expand = c(0, 0)) + - ggplot2::scale_y_continuous(limits = ylim, expand = c(0, 0)) + ggplot() + + annotation_map_tile(type = basemap) + + geom_raster(data = rdf, aes(x = x, y = y, fill = fill), na.rm = TRUE, interpolate = FALSE) + + scale_fill_identity(na.value = "transparent") + + geom_point(data = radar_df, aes(x = X, y = Y), + shape = 21, + fill = "transparent", + colour = radar_color, + size = radar_size, + stroke = 1.5, + show.legend = FALSE) + + dummy + + colorscale + + labs(x="lon", y="lat") ) + + #mymap <- suppressMessages( + # ggmap::ggmap(map) + + # ggmap::inset_raster(raster::as.matrix(r), e@xmin, e@xmax, e@ymin, e@ymax) + + # dummy + colorscale + + # radarpoint + + # ggplot2::scale_x_continuous(limits = xlim, expand = c(0, 0)) + + # ggplot2::scale_y_continuous(limits = ylim, expand = c(0, 0)) + #) + suppressWarnings(mymap) } From cacebc94b4da19178342f79a07e57c0f16963e96 Mon Sep 17 00:00:00 2001 From: iskandari Date: Tue, 17 Oct 2023 15:47:09 -0400 Subject: [PATCH 04/27] switch map function to use ggspatial::annotation_map_tile() --- R/map.R | 9 --------- 1 file changed, 9 deletions(-) diff --git a/R/map.R b/R/map.R index cd54a08d..a6d90937 100644 --- a/R/map.R +++ b/R/map.R @@ -244,14 +244,5 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli labs(x="lon", y="lat") ) - #mymap <- suppressMessages( - # ggmap::ggmap(map) + - # ggmap::inset_raster(raster::as.matrix(r), e@xmin, e@xmax, e@ymin, e@ymax) + - # dummy + colorscale + - # radarpoint + - # ggplot2::scale_x_continuous(limits = xlim, expand = c(0, 0)) + - # ggplot2::scale_y_continuous(limits = ylim, expand = c(0, 0)) - #) - suppressWarnings(mymap) } From 6dc7198b0a05706f6dde6df96c70f8a4d5f742c1 Mon Sep 17 00:00:00 2001 From: iskandari Date: Tue, 17 Oct 2023 15:48:40 -0400 Subject: [PATCH 05/27] assert that basemap argument is one of rosm osm basemap types --- R/map.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/R/map.R b/R/map.R index a6d90937..e6b20de7 100644 --- a/R/map.R +++ b/R/map.R @@ -111,14 +111,14 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli stop("Not a projected ppi, map() expects a ppi generated by project_as_ppi() with argument project=TRUE") } - #if (!attributes(map)$ppi) { - # stop("Not a ppi map, use download_basemap() to download a map.") - #} - - #if (all(attributes(map)$geo$lat != x$geo$lat) || - # all(attributes(map)$geo$lon != x$geo$lon)) { - # stop("Not a basemap for this radar location.") - #} + assert_valid_basemap <- function(basemap) { + valid_types <- rosm::osm.types() + if (!(basemap %in% valid_types)) { + stop(paste("Invalid basemap argument. Must be one of:", paste(valid_types, collapse=", "))) + } + } + + assert_valid_basemap(basemap) # set color scales and palettes if (!assertthat::are_equal(palette, NA)) { From 38ce75785d1b2ba0fdbcfa2e2deb5dbf6d2b61c4 Mon Sep 17 00:00:00 2001 From: iskandari Date: Tue, 17 Oct 2023 15:49:37 -0400 Subject: [PATCH 06/27] clean up --- R/map.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/map.R b/R/map.R index e6b20de7..8432031f 100644 --- a/R/map.R +++ b/R/map.R @@ -189,7 +189,6 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli return(palette[output]) } - #return(r@data@values) # convert data values to hex color string values. r@data@values <- col_func(r@data@values, zlim) From dcf94c1657fe2e369684ce8723bf65458a3e16d9 Mon Sep 17 00:00:00 2001 From: iskandari Date: Tue, 17 Oct 2023 15:54:00 -0400 Subject: [PATCH 07/27] added documentation --- R/map.R | 7 ++++--- man/map.Rd | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/R/map.R b/R/map.R index 8432031f..16817876 100644 --- a/R/map.R +++ b/R/map.R @@ -4,7 +4,7 @@ #' [ggmap::ggmap()]. #' #' @param x A `ppi` object. -#' @param basemap Basemap to use, result of a call to [download_basemap()]. +#' @param basemap Basemap to use, one of `rosm::osm.types()` #' @param param Character. Scan parameter to plot, e.g. `DBZH` or `VRADH`. See #' [summary.param()] for commonly available parameters. #' @param alpha Numeric. Transparency of the data, value between 0 and 1. @@ -51,8 +51,9 @@ #' # Project a scan as a ppi #' ppi <- project_as_ppi(example_scan) #' \donttest{ -#' # Create a basemap that matches the extent of the ppi -#' basemap <- download_basemap(ppi, maptype = "toner-lite") +#' # Choose a basemap +#' rosm::osm.types() +#' basemap <- rosm::osm.types()[1] #' #' # Map the radial velocity of the ppi onto the basemap #' map(ppi, map = basemap, param = "VRADH") diff --git a/man/map.Rd b/man/map.Rd index ea9c5d59..b10a242c 100644 --- a/man/map.Rd +++ b/man/map.Rd @@ -9,7 +9,7 @@ map(x, ...) \method{map}{ppi}( x, - map, + basemap = "cartolight", param, alpha = 0.7, xlim, @@ -17,7 +17,7 @@ map(x, ...) zlim = c(-20, 20), ratio, radar_size = 3, - radar_color = "red", + radar_color = "#202020", n_color = 1000, palette = NA, ... @@ -28,7 +28,7 @@ map(x, ...) \item{...}{Arguments passed to \code{\link[ggmap:ggmap]{ggmap::ggmap()}}.} -\item{map}{Basemap to use, result of a call to \code{\link[=download_basemap]{download_basemap()}}.} +\item{basemap}{Basemap to use, one of \code{rosm::osm.types()}} \item{param}{Character. Scan parameter to plot, e.g. \code{DBZH} or \code{VRADH}. See \code{\link[=summary.param]{summary.param()}} for commonly available parameters.} @@ -90,8 +90,9 @@ model (ODIM), see Table 16 in the # Project a scan as a ppi ppi <- project_as_ppi(example_scan) \donttest{ -# Create a basemap that matches the extent of the ppi -basemap <- download_basemap(ppi, maptype = "toner-lite") +# Choose a basemap +rosm::osm.types() +basemap <- rosm::osm.types()[1] # Map the radial velocity of the ppi onto the basemap map(ppi, map = basemap, param = "VRADH") From 69897899a47df450cd368725837a84ce9de438eb Mon Sep 17 00:00:00 2001 From: iskandari Date: Tue, 17 Oct 2023 15:55:26 -0400 Subject: [PATCH 08/27] modified documentation --- NAMESPACE | 1 - R/download_basemap.R | 128 ---------------------------------------- man/download_basemap.Rd | 70 ---------------------- 3 files changed, 199 deletions(-) delete mode 100644 R/download_basemap.R delete mode 100644 man/download_basemap.Rd diff --git a/NAMESPACE b/NAMESPACE index 84377c78..217e8523 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -102,7 +102,6 @@ export(check_night) export(composite_ppi) export(convert_legacy) export(dbz_to_eta) -export(download_basemap) export(download_pvolfiles) export(download_vpfiles) export(doy) diff --git a/R/download_basemap.R b/R/download_basemap.R deleted file mode 100644 index 79c90662..00000000 --- a/R/download_basemap.R +++ /dev/null @@ -1,128 +0,0 @@ -#' Download a basemap for `map(ppi)` -#' -#' Downloads a basemap for [map.ppi()] from Stamen Maps or Google Maps using -#' [ggmap::get_map()]. To use Google Maps as `source`, you will have to register -#' with Google, enable billing and provide an API key to ggmap. See the [ggmap -#' README](https://github.com/dkahle/ggmap#attention) for details. -#' -#' @param x A `ppi` object. -#' @param verbose Logical. When `TRUE`, prints information to console. -#' @param zoom Integer. Optional zoom level from 3 (continent) to 21 (building), -#' see [ggmap::get_map()]. When undefined, the zoom level will be the one -#' matching the `ppi` extent. -#' @param alpha Numeric. Transparency of the basemap, value between 0 and 1. -#' @param source Character. Map service to be used: `stamen` or `google`. -#' @param maptype Character. Type of basemap to plot. For Stamen Maps: -#' `terrain`, `terrain-background`, `terrain-labels`, `terrain-lines`, -#' `toner`, `toner-2010`, `toner-2011`, `toner-background`, `toner-hybrid`, -#' `toner-labels`, `toner-lines`, `toner-lite` or `watercolor`. For Google -#' Maps: `terrain`, `satellite`, `roadmap` or `hybrid`. -#' @param ... Arguments to pass to [ggmap::get_map()]. -#' -#' @export -#' @returns A ggmap object for `map(ppi)` -#' @seealso -#' * [map.ppi()] -#' -#' @examples -#' # Project a scan as a ppi -#' ppi <- project_as_ppi(example_scan) -#' \donttest{ -#' # Create a basemap that matches the extent of the ppi -#' basemap <- download_basemap(ppi) -#' -#' # Map the radial velocity of the ppi onto the basemap -#' map(ppi, map = basemap, param = "VRADH") -#' -#' # Increase the transparency of the basemap -#' basemap <- download_basemap(ppi, alpha = 0.3) -#' map(ppi, map = basemap, param = "VRADH") -#' -#' # Download a different type of basemap, e.g. a gray-scale image. -#' # See get_map() in ggmap library for full documentation of the options. -#' basemap <- download_basemap(ppi, maptype = "toner-lite") -#' map(ppi, map = basemap, param = "VRADH") -#' } -download_basemap <- function(x, verbose = TRUE, zoom, alpha = 1, - source = "stamen", maptype = "terrain", ...) { - stopifnot(inherits(x, "ppi")) - rlang::check_installed("ggmap",'to run `download_basemap`', version = '3.0.0') - if(utils::packageVersion("ggmap") < numeric_version("3.0.0.903")){ - # not throw a true warning to pass CRAN checks - message("Warning message:\n ggmap not up-to-date (version < 3.0.0.903), upgrade is required using devtools::install_github(\"dkahle/ggmap\")") - } - - if (is.na(raster::crs(x$data))) { - stop("Not a projected ppi, download_basemap() expects a ppi generated by project_as_ppi() with argument project=TRUE") - } - - if (source != "google") { - location <- c(left = x$geo$bbox["lon", "min"], bottom = x$geo$bbox["lat", "min"], right = x$geo$bbox["lon", "max"], top = x$geo$bbox["lat", "max"]) - } else { - location <- c(lon = mean(x$geo$bbox["lon", ]), lat = mean(x$geo$bbox["lat", ])) - } - - if (!missing(zoom)) { - if (!is.numeric(zoom)) { - stop("zoom should be a numeric integer") - } - } - # check size of ppi and determine zoom - if (missing(zoom)) { - use_zoom <- ggmap::calc_zoom(x$geo$bbox["lon", ], x$geo$bbox["lat", ]) - } else { - use_zoom <- zoom - } - - if (verbose) { - message(paste("Downloading zoom =", use_zoom, "...")) - } - map <- ggmap::get_map( - location = location, - zoom = use_zoom, - source = source, - maptype = maptype, - ... - ) - bboxmap <- attributes(map)$bb - - if ((x$geo$bbox["lon", "max"] - x$geo$bbox["lon", "min"] > - bboxmap$ur.lon - bboxmap$ll.lon) || - (x$geo$bbox["lat", "max"] - x$geo$bbox["lat", "min"] > - bboxmap$ur.lat - bboxmap$ll.lat)) { - if (missing(zoom)) { - if (verbose) { - message(paste("Map too small, downloading zoom =", use_zoom - 1, "...")) - } - map <- ggmap::get_map( - location = location, - zoom = use_zoom - 1, - source = source, - maptype = maptype, - ... - ) - bboxmap <- attributes(map)$bb - if ((x$geo$bbox["lon", "max"] - x$geo$bbox["lon", "min"] > - bboxmap$ur.lon - bboxmap$ll.lon) || - (x$geo$bbox["lat", "max"] - x$geo$bbox["lat", "min"] > - bboxmap$ur.lat - bboxmap$ll.lat)) { - if (verbose) { - message(paste("Map still too small, downloading zoom =", use_zoom - 2, "...")) - } - map <- ggmap::get_map( - location = location, - zoom = use_zoom - 2, - source = source, - maptype = maptype, - ... - ) - } - } else { - warning("Map is smaller than ppi bounding box.") - } - } - attributes(map)$geo <- x$geo - attributes(map)$ppi <- TRUE - # add transparency - add_color_transparency(map, alpha = alpha) -} diff --git a/man/download_basemap.Rd b/man/download_basemap.Rd deleted file mode 100644 index 3ce48f85..00000000 --- a/man/download_basemap.Rd +++ /dev/null @@ -1,70 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/download_basemap.R -\name{download_basemap} -\alias{download_basemap} -\title{Download a basemap for \code{map(ppi)}} -\usage{ -download_basemap( - x, - verbose = TRUE, - zoom, - alpha = 1, - source = "stamen", - maptype = "terrain", - ... -) -} -\arguments{ -\item{x}{A \code{ppi} object.} - -\item{verbose}{Logical. When \code{TRUE}, prints information to console.} - -\item{zoom}{Integer. Optional zoom level from 3 (continent) to 21 (building), -see \code{\link[ggmap:get_map]{ggmap::get_map()}}. When undefined, the zoom level will be the one -matching the \code{ppi} extent.} - -\item{alpha}{Numeric. Transparency of the basemap, value between 0 and 1.} - -\item{source}{Character. Map service to be used: \code{stamen} or \code{google}.} - -\item{maptype}{Character. Type of basemap to plot. For Stamen Maps: -\code{terrain}, \code{terrain-background}, \code{terrain-labels}, \code{terrain-lines}, -\code{toner}, \code{toner-2010}, \code{toner-2011}, \code{toner-background}, \code{toner-hybrid}, -\code{toner-labels}, \code{toner-lines}, \code{toner-lite} or \code{watercolor}. For Google -Maps: \code{terrain}, \code{satellite}, \code{roadmap} or \code{hybrid}.} - -\item{...}{Arguments to pass to \code{\link[ggmap:get_map]{ggmap::get_map()}}.} -} -\value{ -A ggmap object for \code{map(ppi)} -} -\description{ -Downloads a basemap for \code{\link[=map.ppi]{map.ppi()}} from Stamen Maps or Google Maps using -\code{\link[ggmap:get_map]{ggmap::get_map()}}. To use Google Maps as \code{source}, you will have to register -with Google, enable billing and provide an API key to ggmap. See the \href{https://github.com/dkahle/ggmap#attention}{ggmap README} for details. -} -\examples{ -# Project a scan as a ppi -ppi <- project_as_ppi(example_scan) -\donttest{ -# Create a basemap that matches the extent of the ppi -basemap <- download_basemap(ppi) - -# Map the radial velocity of the ppi onto the basemap -map(ppi, map = basemap, param = "VRADH") - -# Increase the transparency of the basemap -basemap <- download_basemap(ppi, alpha = 0.3) -map(ppi, map = basemap, param = "VRADH") - -# Download a different type of basemap, e.g. a gray-scale image. -# See get_map() in ggmap library for full documentation of the options. -basemap <- download_basemap(ppi, maptype = "toner-lite") -map(ppi, map = basemap, param = "VRADH") -} -} -\seealso{ -\itemize{ -\item \code{\link[=map.ppi]{map.ppi()}} -} -} From 9591d75abc8b66f745d04c5326519a72700c9290 Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 01:08:51 -0400 Subject: [PATCH 09/27] added deprecated download_basemap to deprecated R file --- NAMESPACE | 1 + R/bioRad-deprecated.R | 12 +++++++++++- R/map.R | 6 ++++-- man/bioRad-deprecated.Rd | 11 +++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 217e8523..84377c78 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -102,6 +102,7 @@ export(check_night) export(composite_ppi) export(convert_legacy) export(dbz_to_eta) +export(download_basemap) export(download_pvolfiles) export(download_vpfiles) export(doy) diff --git a/R/bioRad-deprecated.R b/R/bioRad-deprecated.R index b702292b..f847da6e 100644 --- a/R/bioRad-deprecated.R +++ b/R/bioRad-deprecated.R @@ -40,4 +40,14 @@ vol2bird_version <- function(...) { warning("vol2bird_version has been moved to package vol2birdR") vol2birdR::vol2bird_version() } - +#' @section download_basemap: +#' This function has been deprecated +#' ggmap has been replaced by ggspatial which no longer requires a pre-downloaded raster basemap +#' +#' @rdname bioRad-deprecated +#' @export +#' @return No return value, called for warning message side effect only +download_basemap <- function(...) { + warning("download_basemap has been deprecated; ?bioRad::map for details") + return(TRUE) +} \ No newline at end of file diff --git a/R/map.R b/R/map.R index 16817876..f5bfc4df 100644 --- a/R/map.R +++ b/R/map.R @@ -21,9 +21,11 @@ #' @param n_color Numeric. Number of colors (>=1) to use in the palette. #' @param palette Character vector. Hexadecimal color values defining the plot #' color scale, e.g. output from [viridisLite::viridis()]. -#' @param ... Arguments passed to [ggmap::ggmap()]. +#' @param ... Arguments passed to [ggspatial::ggspatial()]. #' @importFrom methods as -#' @return A ggmap object (a classed raster object with a bounding +#' @return A ggplot object with +#' +#' (a classed raster object with a bounding #' box attribute). #' #' @details diff --git a/man/bioRad-deprecated.Rd b/man/bioRad-deprecated.Rd index 92b44eca..96dbd8fe 100644 --- a/man/bioRad-deprecated.Rd +++ b/man/bioRad-deprecated.Rd @@ -5,6 +5,7 @@ \alias{check_docker} \alias{update_docker} \alias{vol2bird_version} +\alias{download_basemap} \title{Deprecated bioRad functions and data} \usage{ check_docker(...) @@ -12,6 +13,8 @@ check_docker(...) update_docker(...) vol2bird_version(...) + +download_basemap(...) } \value{ \code{TRUE} @@ -19,6 +22,8 @@ vol2bird_version(...) No return value, called for warning message side effect only an object of class \link{numeric_version} + +No return value, called for warning message side effect only } \description{ The functions and data listed below are deprecated or renamed and will be @@ -40,4 +45,10 @@ This function has been deprecated This function has been moved to package vol2birdR } +\section{download_basemap}{ + +This function has been deprecated +ggmap has been replaced by ggspatial which no longer requires a pre-downloaded raster basemap +} + \keyword{internal} From 154523943fc1ee95bbcd0b66efee0259e2bd1763 Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 01:51:27 -0400 Subject: [PATCH 10/27] remove tests for deprecated functions --- R/color_scale.R | 59 ++++++++++++++++++++------------------- R/map.R | 14 +++++----- tests/testthat/test-map.R | 18 +----------- 3 files changed, 38 insertions(+), 53 deletions(-) diff --git a/R/color_scale.R b/R/color_scale.R index 32fabd8d..b1e6daf2 100644 --- a/R/color_scale.R +++ b/R/color_scale.R @@ -1,3 +1,33 @@ +# Color scale used in map plots: +colors_dbz <- c( + "lightblue", "darkblue", + "green", "yellow", "red", + "magenta" +) +colors_vrad <- c("blue", "white", "red") + +# Color scale used in vertical profile plots: +r_points <- c(1, 63, 82, 94, 146, 177, 192, 209, 256) +r_values <- c(255, 255, 163, 255, 255, 81, 81, 0, 0) +g_points <- c(1, 65, 80, 111, 143, 256) +g_values <- c(255, 255, 163, 163, 0, 0) +b_points <- c(1, 80, 97, 111, 128, 160, 207, 256) +b_values <- c(255, 0, 0, 82, 0, 0, 255, 0) +vpts_default_palette <- grDevices::rgb(approx( + r_points, r_values, + seq(1, 255, length.out = 255) +)$y, +approx( + g_points, g_values, + seq(1, 255, length.out = 255) +)$y, +approx( + b_points, b_values, + seq(1, 255, length.out = 255) +)$y, +maxColorValue = 255 +) + color_scale <- function(param, zlim, na.value = "transparent") { if (param %in% c("VRADH", "VRADV", "VRAD")) { colorscale <- ggplot2::scale_colour_gradient2( @@ -118,35 +148,6 @@ add_color_transparency <- function(color, alpha = 1) { } } -# Color scale used in map plots: -colors_dbz <- c( - "lightblue", "darkblue", - "green", "yellow", "red", - "magenta" -) -colors_vrad <- c("blue", "white", "red") - -# Color scale used in vertical profile plots: -r_points <- c(1, 63, 82, 94, 146, 177, 192, 209, 256) -r_values <- c(255, 255, 163, 255, 255, 81, 81, 0, 0) -g_points <- c(1, 65, 80, 111, 143, 256) -g_values <- c(255, 255, 163, 163, 0, 0) -b_points <- c(1, 80, 97, 111, 128, 160, 207, 256) -b_values <- c(255, 0, 0, 82, 0, 0, 255, 0) -vpts_default_palette <- grDevices::rgb(approx( - r_points, r_values, - seq(1, 255, length.out = 255) -)$y, -approx( - g_points, g_values, - seq(1, 255, length.out = 255) -)$y, -approx( - b_points, b_values, - seq(1, 255, length.out = 255) -)$y, -maxColorValue = 255 -) get_zlim <- function(param, zlim) { if (param %in% c("DBZH", "DBZV", "DBZ")) { diff --git a/R/map.R b/R/map.R index f5bfc4df..f385675e 100644 --- a/R/map.R +++ b/R/map.R @@ -58,25 +58,25 @@ #' basemap <- rosm::osm.types()[1] #' #' # Map the radial velocity of the ppi onto the basemap -#' map(ppi, map = basemap, param = "VRADH") +#' map(ppi, basemap = basemap, param = "VRADH") #' #' # Extend the plotting range of velocities, from -50 to 50 m/s -#' map(ppi, map = basemap, param = "VRADH", zlim = c(-50, 50)) +#' map(ppi, basemap = basemap, param = "VRADH", zlim = c(-50, 50)) #' #' # Map the reflectivity -#' map(ppi, map = basemap, param = "DBZH") +#' map(ppi, basemap = basemap, param = "DBZH") #' #' # Change the color palette to Viridis colors -#' map(ppi, map = basemap, param = "DBZH", palette = viridis::viridis(100), zlim=c(-10,10)) +#' map(ppi, basemap = basemap, param = "DBZH", palette = viridis::viridis(100), zlim=c(-10,10)) #' #' # Give the data more transparency -#' map(ppi, map = basemap, param = "DBZH", alpha = 0.3) +#' map(ppi, basemap = basemap, param = "DBZH", alpha = 0.3) #' #' # Change the appearance of the symbol indicating the radar location -#' map(ppi, map = basemap, radar_size = 5, radar_color = "blue") +#' map(ppi, basemap = basemap, radar_size = 5, radar_color = "blue") #' #' # Crop the map -#' map(ppi, map = basemap, xlim = c(12.4, 13.2), ylim = c(56, 56.5)) +#' map(ppi, basemap = basemap, xlim = c(12.4, 13.2), ylim = c(56, 56.5)) #' } map <- function(x, ...) { UseMethod("map", x) diff --git a/tests/testthat/test-map.R b/tests/testthat/test-map.R index 7f1113b9..caea350b 100644 --- a/tests/testthat/test-map.R +++ b/tests/testthat/test-map.R @@ -1,7 +1,7 @@ test_that("map() returns error on incorrect parameters", { skip_if_offline() ppi <- project_as_ppi(example_scan) - basemap <- download_basemap(ppi, maptype = "toner-lite") + basemap <- rosm::osm.types()[1] # return error when input object is not of class ppi expect_error( map("a"), @@ -34,22 +34,6 @@ test_that("map() returns error on incorrect parameters", { regexp = "Not a projected ppi, map() expects a ppi generated by project_as_ppi() with argument project=TRUE", fixed = TRUE ) - # basemap wasn't made with download_basemap() or download_basemap() is broken - basemap_no_ppi <- basemap - attr(basemap_no_ppi,"ppi") <- FALSE - expect_error( - map(ppi, map = basemap_no_ppi), - regexp = "Not a ppi map, use download_basemap() to download a map.", - fixed = TRUE - ) - # return error for basemap for different radar location - basemap_somewhere_else <- basemap - attributes(basemap_somewhere_else)$geo$lat <- 57 - expect_error( - map(ppi, map = basemap_somewhere_else), - regexp = "Not a basemap for this radar location.", - fixed = TRUE - ) # return error when palette isn't a character vector expect_error( map(ppi, map = basemap, palette = 123), From a8b5f49fd1a0c5219ae7ff3203d86f54f4e31f79 Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 02:30:41 -0400 Subject: [PATCH 11/27] remove argument passing to annotation_map_tile --- R/map.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/map.R b/R/map.R index f385675e..dbee76be 100644 --- a/R/map.R +++ b/R/map.R @@ -21,7 +21,6 @@ #' @param n_color Numeric. Number of colors (>=1) to use in the palette. #' @param palette Character vector. Hexadecimal color values defining the plot #' color scale, e.g. output from [viridisLite::viridis()]. -#' @param ... Arguments passed to [ggspatial::ggspatial()]. #' @importFrom methods as #' @return A ggplot object with #' From abb815857068a2e17063db7c10832db9624b6b68 Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 02:40:57 -0400 Subject: [PATCH 12/27] use sf::st_crs to avoid warning messages about proj format --- R/map.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/map.R b/R/map.R index dbee76be..57ccf366 100644 --- a/R/map.R +++ b/R/map.R @@ -137,8 +137,8 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli # extract the scan parameter data <- do.call(function(y) x$data[y], list(param)) - wgs84 <- sp::CRS("+proj=longlat +datum=WGS84") - epsg3857 <- sp::CRS("+init=epsg:3857") # this is the google mercator projection + wgs84 <- sf::st_crs(4326) + epsg3857 <- sf::st_crs(3857) # this is the google mercator projection mybbox <- suppressWarnings( sp::spTransform( sp::SpatialPoints(t(data@bbox), From 5718ecaf487afb5c6d59d3096e1f2066a3370299 Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 03:44:15 -0400 Subject: [PATCH 13/27] debugging --- R/map.R | 16 +++++++--------- man/map.Rd | 19 ++++++++----------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/R/map.R b/R/map.R index 57ccf366..f0347431 100644 --- a/R/map.R +++ b/R/map.R @@ -22,11 +22,7 @@ #' @param palette Character vector. Hexadecimal color values defining the plot #' color scale, e.g. output from [viridisLite::viridis()]. #' @importFrom methods as -#' @return A ggplot object with -#' -#' (a classed raster object with a bounding -#' box attribute). -#' +#' @return A ggplot object #' @details #' Available scan parameters for mapping can by printed to screen by #' `summary(x)`. Commonly available parameters are: @@ -137,8 +133,8 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli # extract the scan parameter data <- do.call(function(y) x$data[y], list(param)) - wgs84 <- sf::st_crs(4326) - epsg3857 <- sf::st_crs(3857) # this is the google mercator projection + wgs84 <- sp::CRS("+proj=longlat +datum=WGS84") + epsg3857 <- sp::CRS("+init=epsg:3857") # this is the google mercator projection mybbox <- suppressWarnings( sp::spTransform( sp::SpatialPoints(t(data@bbox), @@ -192,11 +188,13 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli } # convert data values to hex color string values. - r@data@values <- col_func(r@data@values, zlim) + #r@data@values <- col_func(r@data@values, zlim) + + return(r) rdf <- as.data.frame(r, xy = TRUE) names(rdf) <- c("x", "y", "fill") - rdf$fill <- values(r) + rdf$fill <- col_func(r@data@values, zlim) # these declarations prevent generation of NOTE "no visible binding for # global variable" during package Check diff --git a/man/map.Rd b/man/map.Rd index b10a242c..eb231b17 100644 --- a/man/map.Rd +++ b/man/map.Rd @@ -26,8 +26,6 @@ map(x, ...) \arguments{ \item{x}{A \code{ppi} object.} -\item{...}{Arguments passed to \code{\link[ggmap:ggmap]{ggmap::ggmap()}}.} - \item{basemap}{Basemap to use, one of \code{rosm::osm.types()}} \item{param}{Character. Scan parameter to plot, e.g. \code{DBZH} or \code{VRADH}. See @@ -57,8 +55,7 @@ position.} color scale, e.g. output from \code{\link[viridisLite:viridis]{viridisLite::viridis()}}.} } \value{ -A ggmap object (a classed raster object with a bounding -box attribute). +A ggplot object } \description{ Plots a plan position indicator (\code{ppi}) on a base layer using @@ -95,25 +92,25 @@ rosm::osm.types() basemap <- rosm::osm.types()[1] # Map the radial velocity of the ppi onto the basemap -map(ppi, map = basemap, param = "VRADH") +map(ppi, basemap = basemap, param = "VRADH") # Extend the plotting range of velocities, from -50 to 50 m/s -map(ppi, map = basemap, param = "VRADH", zlim = c(-50, 50)) +map(ppi, basemap = basemap, param = "VRADH", zlim = c(-50, 50)) # Map the reflectivity -map(ppi, map = basemap, param = "DBZH") +map(ppi, basemap = basemap, param = "DBZH") # Change the color palette to Viridis colors -map(ppi, map = basemap, param = "DBZH", palette = viridis::viridis(100), zlim=c(-10,10)) +map(ppi, basemap = basemap, param = "DBZH", palette = viridis::viridis(100), zlim=c(-10,10)) # Give the data more transparency -map(ppi, map = basemap, param = "DBZH", alpha = 0.3) +map(ppi, basemap = basemap, param = "DBZH", alpha = 0.3) # Change the appearance of the symbol indicating the radar location -map(ppi, map = basemap, radar_size = 5, radar_color = "blue") +map(ppi, basemap = basemap, radar_size = 5, radar_color = "blue") # Crop the map -map(ppi, map = basemap, xlim = c(12.4, 13.2), ylim = c(56, 56.5)) +map(ppi, basemap = basemap, xlim = c(12.4, 13.2), ylim = c(56, 56.5)) } } \seealso{ From a00fa2afd38c875324bd3c8fbc057440e5b7e7c3 Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 04:26:51 -0400 Subject: [PATCH 14/27] add raster to as.data.frame function --- R/map.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/R/map.R b/R/map.R index f0347431..e11c5f7a 100644 --- a/R/map.R +++ b/R/map.R @@ -190,9 +190,7 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli # convert data values to hex color string values. #r@data@values <- col_func(r@data@values, zlim) - return(r) - - rdf <- as.data.frame(r, xy = TRUE) + rdf <- raster::as.data.frame(r, xy = TRUE) names(rdf) <- c("x", "y", "fill") rdf$fill <- col_func(r@data@values, zlim) From 52ef2dbda4e035190c8c02fcb4e4708a03149225 Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 04:31:24 -0400 Subject: [PATCH 15/27] add package names before functions --- R/map.R | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/R/map.R b/R/map.R index e11c5f7a..00447db8 100644 --- a/R/map.R +++ b/R/map.R @@ -198,23 +198,17 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli # global variable" during package Check lon <- lat <- y <- z <- NA # extract unique radar locations - + latlon_radar <- unique(data.frame(lat=c(x$geo$lat), lon=c(x$geo$lon))) # symbols for the radar position # dummy is a hack to be able to include the ggplot2 color scale, # radarpoint is the actual plotting of radar positions. - radarpoint <- ggplot2::geom_point(ggplot2::aes(x = lon, y = lat), - colour = radar_color, - size = radar_size, - data = data.frame(lon = latlon_radar$lon, lat = latlon_radar$lat) - ) - radar_location = data.frame(lon = x$geo$lon, lat = x$geo$lat) %>% - st_as_sf(coords = c("lon", "lat")) %>% - st_set_crs(4326) %>% - st_transform(3857) + sf::st_as_sf(coords = c("lon", "lat")) %>% + sf::st_set_crs(4326) %>% + sf::st_transform(3857) - radar_df <- data.frame(st_coordinates(radar_location)) + radar_df <- data.frame(sf::st_coordinates(radar_location)) dummy <- ggplot2::geom_point(ggplot2::aes(x = lon, y = lat, colour = z), size = 0, From 463676668bf472f41d7cc2c80a23055386ca3ccd Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 04:34:34 -0400 Subject: [PATCH 16/27] add package names before functions --- R/map.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/map.R b/R/map.R index 00447db8..ca1e183f 100644 --- a/R/map.R +++ b/R/map.R @@ -219,11 +219,11 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli )) mymap <- suppressMessages( - ggplot() + - annotation_map_tile(type = basemap) + - geom_raster(data = rdf, aes(x = x, y = y, fill = fill), na.rm = TRUE, interpolate = FALSE) + - scale_fill_identity(na.value = "transparent") + - geom_point(data = radar_df, aes(x = X, y = Y), + ggplot2::ggplot() + + ggspatial::annotation_map_tile(type = basemap) + + ggplot2::geom_raster(data = rdf, ggplot2::aes(x = x, y = y, fill = fill), na.rm = TRUE, interpolate = FALSE) + + ggplot2::scale_fill_identity(na.value = "transparent") + + ggplot2::geom_point(data = radar_df, ggplot2::aes(x = X, y = Y), shape = 21, fill = "transparent", colour = radar_color, @@ -232,7 +232,7 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli show.legend = FALSE) + dummy + colorscale + - labs(x="lon", y="lat") + ggplot2::labs(x="lon", y="lat") ) suppressWarnings(mymap) From b5dc5df49d4b4106f6356da9455e3b00abf8b18d Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 13:48:11 -0400 Subject: [PATCH 17/27] removed download_basemap, rebuilt docs, added rosm.cache to ignore files --- .Rbuildignore | 1 + .gitignore | 2 ++ DESCRIPTION | 4 ++-- R/composite_ppi.R | 5 +---- R/integrate_to_ppi.R | 3 +-- R/map.R | 10 ++++------ man/composite_ppi.Rd | 5 +---- man/integrate_to_ppi.Rd | 3 +-- man/map.Rd | 4 ++-- tests/testthat/test-download_basemap.R | 22 ---------------------- vignettes/rad_aero_22.Rmd | 7 ++----- vignettes/range_correction.Rmd | 4 ++-- 12 files changed, 19 insertions(+), 51 deletions(-) delete mode 100644 tests/testthat/test-download_basemap.R diff --git a/.Rbuildignore b/.Rbuildignore index 8bf3a6ad..dd3bc837 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -17,3 +17,4 @@ inst/extdata/vpts.txt.zip ^CRAN-SUBMISSION$ ^doc$ ^Meta$ +^rosm\.cache$ diff --git a/.gitignore b/.gitignore index b3e1c080..2bb8d585 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,5 @@ pkgdown/* /doc/ /Meta/ +#ROSM basemaps +rosm.cache \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 2438bc4c..bafc7dec 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,7 +45,6 @@ Imports: readr, rhdf5, rlang, - rosm, sp, stats, suntools, @@ -55,9 +54,10 @@ Imports: viridisLite Suggests: aws.s3, - ggmap (>= 3.0.0), knitr, rmarkdown, + rosm, + prettymapr, sf, testthat (>= 3.0.0), tidyselect, diff --git a/R/composite_ppi.R b/R/composite_ppi.R index be88cab8..8f49f28e 100644 --- a/R/composite_ppi.R +++ b/R/composite_ppi.R @@ -74,11 +74,8 @@ #' # across the available scans at each geographic location #' composite <- composite_ppi(ppis, method = "max", res=1000) #' -#' # Download basemap -#' bm <- download_basemap(composite) -#' #' # Plot the calculated max product on the basemap -#' map(composite, bm) +#' map(composite) #' } composite_ppi <- function(x, diff --git a/R/integrate_to_ppi.R b/R/integrate_to_ppi.R index 556a8d78..05a659e4 100644 --- a/R/integrate_to_ppi.R +++ b/R/integrate_to_ppi.R @@ -119,8 +119,7 @@ #' plot(ppi, param = "VID", zlim = c(0, 200)) #' #' # Download a basemap and map the ppi -#' bm <- download_basemap(ppi) -#' map(ppi, bm) +#' map(ppi) #' #' # The ppi can also be projected on a user-defined raster, as follows: #' diff --git a/R/map.R b/R/map.R index ca1e183f..0a5fc234 100644 --- a/R/map.R +++ b/R/map.R @@ -21,6 +21,7 @@ #' @param n_color Numeric. Number of colors (>=1) to use in the palette. #' @param palette Character vector. Hexadecimal color values defining the plot #' color scale, e.g. output from [viridisLite::viridis()]. +#' @param ... Arguments passed to [ggplot2::ggplot()]. #' @importFrom methods as #' @return A ggplot object #' @details @@ -41,7 +42,6 @@ #' @export #' #' @seealso -#' * [download_basemap()] #' * [project_as_ppi()] #' #' @examples @@ -49,7 +49,6 @@ #' ppi <- project_as_ppi(example_scan) #' \donttest{ #' # Choose a basemap -#' rosm::osm.types() #' basemap <- rosm::osm.types()[1] #' #' # Map the radial velocity of the ppi onto the basemap @@ -196,10 +195,9 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli # these declarations prevent generation of NOTE "no visible binding for # global variable" during package Check - lon <- lat <- y <- z <- NA + fill <- lon <- lat <- X <- Y <- y <- z <- NA # extract unique radar locations - latlon_radar <- unique(data.frame(lat=c(x$geo$lat), lon=c(x$geo$lon))) - # symbols for the radar position + # dummy is a hack to be able to include the ggplot2 color scale, # radarpoint is the actual plotting of radar positions. @@ -218,7 +216,7 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli z = 0 )) - mymap <- suppressMessages( + mymap <- suppressWarnings( ggplot2::ggplot() + ggspatial::annotation_map_tile(type = basemap) + ggplot2::geom_raster(data = rdf, ggplot2::aes(x = x, y = y, fill = fill), na.rm = TRUE, interpolate = FALSE) + diff --git a/man/composite_ppi.Rd b/man/composite_ppi.Rd index 496a3342..58cb89f2 100644 --- a/man/composite_ppi.Rd +++ b/man/composite_ppi.Rd @@ -120,10 +120,7 @@ ppis <- lapply(pvol$scans, project_as_ppi, grid_size=1000) # across the available scans at each geographic location composite <- composite_ppi(ppis, method = "max", res=1000) -# Download basemap -bm <- download_basemap(composite) - # Plot the calculated max product on the basemap -map(composite, bm) +map(composite) } } diff --git a/man/integrate_to_ppi.Rd b/man/integrate_to_ppi.Rd index 20505ec3..65aa999a 100644 --- a/man/integrate_to_ppi.Rd +++ b/man/integrate_to_ppi.Rd @@ -179,8 +179,7 @@ ppi <- integrate_to_ppi(pvol, example_vp, res = 2000) plot(ppi, param = "VID", zlim = c(0, 200)) # Download a basemap and map the ppi -bm <- download_basemap(ppi) -map(ppi, bm) +map(ppi) # The ppi can also be projected on a user-defined raster, as follows: diff --git a/man/map.Rd b/man/map.Rd index eb231b17..93ebbabf 100644 --- a/man/map.Rd +++ b/man/map.Rd @@ -26,6 +26,8 @@ map(x, ...) \arguments{ \item{x}{A \code{ppi} object.} +\item{...}{Arguments passed to \code{\link[ggplot2:ggplot]{ggplot2::ggplot()}}.} + \item{basemap}{Basemap to use, one of \code{rosm::osm.types()}} \item{param}{Character. Scan parameter to plot, e.g. \code{DBZH} or \code{VRADH}. See @@ -88,7 +90,6 @@ model (ODIM), see Table 16 in the ppi <- project_as_ppi(example_scan) \donttest{ # Choose a basemap -rosm::osm.types() basemap <- rosm::osm.types()[1] # Map the radial velocity of the ppi onto the basemap @@ -115,7 +116,6 @@ map(ppi, basemap = basemap, xlim = c(12.4, 13.2), ylim = c(56, 56.5)) } \seealso{ \itemize{ -\item \code{\link[=download_basemap]{download_basemap()}} \item \code{\link[=project_as_ppi]{project_as_ppi()}} } } diff --git a/tests/testthat/test-download_basemap.R b/tests/testthat/test-download_basemap.R deleted file mode 100644 index cdcec990..00000000 --- a/tests/testthat/test-download_basemap.R +++ /dev/null @@ -1,22 +0,0 @@ -test_that("download_basemap() returns error on incorrect parameters", { - ppi <- project_as_ppi(example_scan) - expect_error( - download_basemap("a"), - regexp = 'inherits(x, "ppi") is not TRUE', - fixed = TRUE - ) - # CRS absent in ppi - ppi_no_crs <- ppi - raster::crs(ppi_no_crs$data) <- NA - expect_error( - download_basemap(ppi_no_crs), - regexp = "Not a projected ppi, download_basemap() expects a ppi generated by project_as_ppi() with argument project=TRUE", - fixed = TRUE - ) - # invalid value for zoom - expect_error( - download_basemap(ppi, zoom = "a"), - regexp = "zoom should be a numeric integer", - fixed = TRUE - ) -}) diff --git a/vignettes/rad_aero_22.Rmd b/vignettes/rad_aero_22.Rmd index 535c50cc..41f4b742 100644 --- a/vignettes/rad_aero_22.Rmd +++ b/vignettes/rad_aero_22.Rmd @@ -156,12 +156,9 @@ plot(my_ppi, param = "VRADH") ```{r, eval=SHOW_ANSWERS, warning=FALSE} # It is often informative to plot radar data on a base layer. -# first download the background image: -basemap <- download_basemap(my_ppi) -# plot the basemap: -plot(basemap) +# First choose a base layer from the list of rosm::osm.types() # then overlay the PPI on the basemap, restricting the color scale from -20 to 40 dBZ: -map(my_ppi, map = basemap, param = "DBZH", zlim = c(-20, 40)) +map(my_ppi, basemap = basemap, param = "DBZH", zlim = c(-20, 40)) ``` # Screening out weather diff --git a/vignettes/range_correction.Rmd b/vignettes/range_correction.Rmd index d68a3925..3a2c4e27 100644 --- a/vignettes/range_correction.Rmd +++ b/vignettes/range_correction.Rmd @@ -145,8 +145,8 @@ plot(my_corrected_ppi, param = "VIR") Or plot the vertically integrated density on a map: ```{r} -bm <- download_basemap(my_corrected_ppi) -map(my_corrected_ppi, bm, param = "VIR", alpha = .5) +bm <- "osm" +map(my_corrected_ppi, basemap=bm, param = "VIR", alpha = .5) ``` ## 6 Overlap between radiation profile and bird profile From ae0b39a00f1306455e0be4af9e224357bf365a25 Mon Sep 17 00:00:00 2001 From: Adriaan Dokter Date: Thu, 19 Oct 2023 15:04:59 -0400 Subject: [PATCH 18/27] warning to error --- tests/testthat/test-download_pvolfiles.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-download_pvolfiles.R b/tests/testthat/test-download_pvolfiles.R index 46969b67..095a46d9 100644 --- a/tests/testthat/test-download_pvolfiles.R +++ b/tests/testthat/test-download_pvolfiles.R @@ -108,7 +108,7 @@ test_that("date input for download_pvolfiles() ", { test_that("Check radar code for download_pvolfiles() ", { skip_if_offline() - expect_warning( + expect_error( download_pvolfiles(date_min, date_max, c("KBBX", "KGHC"), From bea834c4fdf0fc3c6e1a0d0aac6537c0a6db0252 Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 16:40:05 -0400 Subject: [PATCH 19/27] revert basemap argument to map --- DESCRIPTION | 2 +- R/map.R | 22 +++++++++++----------- man/map.Rd | 18 +++++++++--------- vignettes/rad_aero_22.Rmd | 3 ++- vignettes/range_correction.Rmd | 2 +- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bafc7dec..1bd329fc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -34,7 +34,6 @@ Imports: fields, frictionless, ggplot2, - ggspatial, glue, graphics, jsonlite, @@ -55,6 +54,7 @@ Imports: Suggests: aws.s3, knitr, + ggspatial, rmarkdown, rosm, prettymapr, diff --git a/R/map.R b/R/map.R index 0a5fc234..8769083d 100644 --- a/R/map.R +++ b/R/map.R @@ -4,7 +4,7 @@ #' [ggmap::ggmap()]. #' #' @param x A `ppi` object. -#' @param basemap Basemap to use, one of `rosm::osm.types()` +#' @param map Basemap to use, one of `rosm::osm.types()` #' @param param Character. Scan parameter to plot, e.g. `DBZH` or `VRADH`. See #' [summary.param()] for commonly available parameters. #' @param alpha Numeric. Transparency of the data, value between 0 and 1. @@ -52,25 +52,25 @@ #' basemap <- rosm::osm.types()[1] #' #' # Map the radial velocity of the ppi onto the basemap -#' map(ppi, basemap = basemap, param = "VRADH") +#' map(ppi, map = basemap, param = "VRADH") #' #' # Extend the plotting range of velocities, from -50 to 50 m/s -#' map(ppi, basemap = basemap, param = "VRADH", zlim = c(-50, 50)) +#' map(ppi, map = basemap, param = "VRADH", zlim = c(-50, 50)) #' #' # Map the reflectivity -#' map(ppi, basemap = basemap, param = "DBZH") +#' map(ppi, map = basemap, param = "DBZH") #' #' # Change the color palette to Viridis colors -#' map(ppi, basemap = basemap, param = "DBZH", palette = viridis::viridis(100), zlim=c(-10,10)) +#' map(ppi, map = basemap, param = "DBZH", palette = viridis::viridis(100), zlim=c(-10,10)) #' #' # Give the data more transparency -#' map(ppi, basemap = basemap, param = "DBZH", alpha = 0.3) +#' map(ppi, map = basemap, param = "DBZH", alpha = 0.3) #' #' # Change the appearance of the symbol indicating the radar location -#' map(ppi, basemap = basemap, radar_size = 5, radar_color = "blue") +#' map(ppi, map = basemap, radar_size = 5, radar_color = "blue") #' #' # Crop the map -#' map(ppi, basemap = basemap, xlim = c(12.4, 13.2), ylim = c(56, 56.5)) +#' map(ppi, map = basemap, xlim = c(12.4, 13.2), ylim = c(56, 56.5)) #' } map <- function(x, ...) { UseMethod("map", x) @@ -78,7 +78,7 @@ map <- function(x, ...) { #' @describeIn map Plot a `ppi` object on a map. #' @export -map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zlim = c(-20, 20), +map.ppi <- function(x, map="cartolight", param, alpha = 0.7, xlim, ylim, zlim = c(-20, 20), ratio, radar_size = 3, radar_color = "#202020", n_color = 1000, palette = NA, ...) { @@ -115,7 +115,7 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli } } - assert_valid_basemap(basemap) + assert_valid_basemap(map) # set color scales and palettes if (!assertthat::are_equal(palette, NA)) { @@ -218,7 +218,7 @@ map.ppi <- function(x, basemap="cartolight", param, alpha = 0.7, xlim, ylim, zli mymap <- suppressWarnings( ggplot2::ggplot() + - ggspatial::annotation_map_tile(type = basemap) + + ggspatial::annotation_map_tile(type = map) + ggplot2::geom_raster(data = rdf, ggplot2::aes(x = x, y = y, fill = fill), na.rm = TRUE, interpolate = FALSE) + ggplot2::scale_fill_identity(na.value = "transparent") + ggplot2::geom_point(data = radar_df, ggplot2::aes(x = X, y = Y), diff --git a/man/map.Rd b/man/map.Rd index 93ebbabf..0e5a51a4 100644 --- a/man/map.Rd +++ b/man/map.Rd @@ -9,7 +9,7 @@ map(x, ...) \method{map}{ppi}( x, - basemap = "cartolight", + map = "cartolight", param, alpha = 0.7, xlim, @@ -28,7 +28,7 @@ map(x, ...) \item{...}{Arguments passed to \code{\link[ggplot2:ggplot]{ggplot2::ggplot()}}.} -\item{basemap}{Basemap to use, one of \code{rosm::osm.types()}} +\item{map}{Basemap to use, one of \code{rosm::osm.types()}} \item{param}{Character. Scan parameter to plot, e.g. \code{DBZH} or \code{VRADH}. See \code{\link[=summary.param]{summary.param()}} for commonly available parameters.} @@ -93,25 +93,25 @@ ppi <- project_as_ppi(example_scan) basemap <- rosm::osm.types()[1] # Map the radial velocity of the ppi onto the basemap -map(ppi, basemap = basemap, param = "VRADH") +map(ppi, map = basemap, param = "VRADH") # Extend the plotting range of velocities, from -50 to 50 m/s -map(ppi, basemap = basemap, param = "VRADH", zlim = c(-50, 50)) +map(ppi, map = basemap, param = "VRADH", zlim = c(-50, 50)) # Map the reflectivity -map(ppi, basemap = basemap, param = "DBZH") +map(ppi, map = basemap, param = "DBZH") # Change the color palette to Viridis colors -map(ppi, basemap = basemap, param = "DBZH", palette = viridis::viridis(100), zlim=c(-10,10)) +map(ppi, map = basemap, param = "DBZH", palette = viridis::viridis(100), zlim=c(-10,10)) # Give the data more transparency -map(ppi, basemap = basemap, param = "DBZH", alpha = 0.3) +map(ppi, map = basemap, param = "DBZH", alpha = 0.3) # Change the appearance of the symbol indicating the radar location -map(ppi, basemap = basemap, radar_size = 5, radar_color = "blue") +map(ppi, map = basemap, radar_size = 5, radar_color = "blue") # Crop the map -map(ppi, basemap = basemap, xlim = c(12.4, 13.2), ylim = c(56, 56.5)) +map(ppi, map = basemap, xlim = c(12.4, 13.2), ylim = c(56, 56.5)) } } \seealso{ diff --git a/vignettes/rad_aero_22.Rmd b/vignettes/rad_aero_22.Rmd index 41f4b742..2456c1bf 100644 --- a/vignettes/rad_aero_22.Rmd +++ b/vignettes/rad_aero_22.Rmd @@ -157,8 +157,9 @@ plot(my_ppi, param = "VRADH") ```{r, eval=SHOW_ANSWERS, warning=FALSE} # It is often informative to plot radar data on a base layer. # First choose a base layer from the list of rosm::osm.types() +basemap = "osm" # then overlay the PPI on the basemap, restricting the color scale from -20 to 40 dBZ: -map(my_ppi, basemap = basemap, param = "DBZH", zlim = c(-20, 40)) +map(my_ppi, map = basemap, param = "DBZH", zlim = c(-20, 40)) ``` # Screening out weather diff --git a/vignettes/range_correction.Rmd b/vignettes/range_correction.Rmd index 3a2c4e27..01130134 100644 --- a/vignettes/range_correction.Rmd +++ b/vignettes/range_correction.Rmd @@ -146,7 +146,7 @@ Or plot the vertically integrated density on a map: ```{r} bm <- "osm" -map(my_corrected_ppi, basemap=bm, param = "VIR", alpha = .5) +map(my_corrected_ppi, map=bm, param = "VIR", alpha = .5) ``` ## 6 Overlap between radiation profile and bird profile From f10c64055127f5c8f9bc782061669321c96bf8fc Mon Sep 17 00:00:00 2001 From: Adriaan Dokter Date: Thu, 19 Oct 2023 16:42:26 -0400 Subject: [PATCH 20/27] reorder dependencies --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1bd329fc..811bfa94 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -53,11 +53,11 @@ Imports: viridisLite Suggests: aws.s3, - knitr, ggspatial, + knitr, + prettymapr, rmarkdown, rosm, - prettymapr, sf, testthat (>= 3.0.0), tidyselect, From 69e16eda951da514ad3a11a2d8d2fdc4a9995270 Mon Sep 17 00:00:00 2001 From: Adriaan Dokter Date: Thu, 19 Oct 2023 16:47:31 -0400 Subject: [PATCH 21/27] check for presence of suggested dependencies --- R/map.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/map.R b/R/map.R index 8769083d..d2edf2cb 100644 --- a/R/map.R +++ b/R/map.R @@ -1,7 +1,6 @@ #' Map a plan position indicator (`ppi`) on a map #' -#' Plots a plan position indicator (`ppi`) on a base layer using -#' [ggmap::ggmap()]. +#' Plots a plan position indicator (`ppi`) on a base layer #' #' @param x A `ppi` object. #' @param map Basemap to use, one of `rosm::osm.types()` @@ -108,6 +107,9 @@ map.ppi <- function(x, map="cartolight", param, alpha = 0.7, xlim, ylim, zlim = stop("Not a projected ppi, map() expects a ppi generated by project_as_ppi() with argument project=TRUE") } + # check that suggested dependencies are presetn + rlang::check_installed(c("ggspatial","prettymapr"),'to map ppi\'s') + assert_valid_basemap <- function(basemap) { valid_types <- rosm::osm.types() if (!(basemap %in% valid_types)) { From 586041465e4bdf521d67e5959a149dcf2b2811b5 Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 16:51:35 -0400 Subject: [PATCH 22/27] added NEWS.md for 0.8.0 release --- NEWS.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/NEWS.md b/NEWS.md index 09b21d2b..5a624711 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,19 @@ +# bioRad 0.8.0 + +## New features + +* Replaced the `ggmap` package with `ggspatial` for map visualizations. This change was made as `ggmap` no longer provides reliable open-source basemaps without the necessity to register for an API key. + +## Bugfixes + +* Corrected the radar attribute naming from `DBZH` to `dbz_all` to be in line with the VPTS CSV specification. Details on the specification can be found at [https://aloftdata.eu/vpts-csv/](https://aloftdata.eu/vpts-csv/). + +* Improved the VPTS file fetching mechanism from s3: now skips a day if there are issues with fetching instead of aborting the entire download. + +## Deprecations + +* `download_basemap()` has been deprecated and replaced by `ggspatial::annotation_map_tile()` + # bioRad 0.7.2 ## Bugfixes @@ -48,6 +64,8 @@ bioRad 0.7 includes a major backend overhaul that deprecates the use of Docker. ## Deprecations + + * Argument `local_install` in `calculate_vp()` and `apply_mistnet()` is now deprecated. * Functions `check_docker()` and `update_docker()` have been deprecated. From 54b34355b831b7e3522887453713f8ecb3264976 Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 16:58:27 -0400 Subject: [PATCH 23/27] return a basemap type in the deprecated download_basemap() function to ensure backward compatibility --- R/bioRad-deprecated.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/bioRad-deprecated.R b/R/bioRad-deprecated.R index f847da6e..8b205c6c 100644 --- a/R/bioRad-deprecated.R +++ b/R/bioRad-deprecated.R @@ -49,5 +49,5 @@ vol2bird_version <- function(...) { #' @return No return value, called for warning message side effect only download_basemap <- function(...) { warning("download_basemap has been deprecated; ?bioRad::map for details") - return(TRUE) + return("cartolight") } \ No newline at end of file From 0813c204cf48000e1d282be3517f2a75a1e006df Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 17:00:08 -0400 Subject: [PATCH 24/27] remove commented line --- R/map.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/map.R b/R/map.R index d2edf2cb..d85f2803 100644 --- a/R/map.R +++ b/R/map.R @@ -189,7 +189,6 @@ map.ppi <- function(x, map="cartolight", param, alpha = 0.7, xlim, ylim, zlim = } # convert data values to hex color string values. - #r@data@values <- col_func(r@data@values, zlim) rdf <- raster::as.data.frame(r, xy = TRUE) names(rdf) <- c("x", "y", "fill") From 81206a46821571e44aaab2cee48aca7a981e3751 Mon Sep 17 00:00:00 2001 From: iskandari Date: Thu, 19 Oct 2023 17:01:34 -0400 Subject: [PATCH 25/27] change release to minor 0.7.3 --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 5a624711..2f935844 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# bioRad 0.8.0 +# bioRad 0.7.3 ## New features From 9d115e974c47a1d7e5e45e39cdd9d365b0724e27 Mon Sep 17 00:00:00 2001 From: Adriaan Dokter Date: Thu, 19 Oct 2023 17:27:08 -0400 Subject: [PATCH 26/27] add issue numbers to NEWS --- NEWS.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2f935844..7d76929c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,17 +2,17 @@ ## New features -* Replaced the `ggmap` package with `ggspatial` for map visualizations. This change was made as `ggmap` no longer provides reliable open-source basemaps without the necessity to register for an API key. +* Replaced the `ggmap` package with `ggspatial` for map visualizations. This change was made as `ggmap` no longer provides reliable open-source basemaps without the necessity to register for an API key (#638). ## Bugfixes -* Corrected the radar attribute naming from `DBZH` to `dbz_all` to be in line with the VPTS CSV specification. Details on the specification can be found at [https://aloftdata.eu/vpts-csv/](https://aloftdata.eu/vpts-csv/). +* Corrected the radar attribute naming from `DBZH` to `dbz_all` to be in line with the VPTS CSV specification. Details on the specification can be found at [https://aloftdata.eu/vpts-csv/](https://aloftdata.eu/vpts-csv/) (#634). -* Improved the VPTS file fetching mechanism from s3: now skips a day if there are issues with fetching instead of aborting the entire download. +* Improved the VPTS file fetching mechanism from s3: now skips a day if there are issues with fetching instead of aborting the entire download (#636) ## Deprecations -* `download_basemap()` has been deprecated and replaced by `ggspatial::annotation_map_tile()` +* `download_basemap()` has been deprecated, function `map()` now automatically downloads a basemap (#638). # bioRad 0.7.2 From 0f33222be49fceb7134b3ad207563951675a2ec6 Mon Sep 17 00:00:00 2001 From: Adriaan Dokter Date: Thu, 19 Oct 2023 17:35:32 -0400 Subject: [PATCH 27/27] updating NEWS --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 7d76929c..6a2d9780 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,7 +6,7 @@ ## Bugfixes -* Corrected the radar attribute naming from `DBZH` to `dbz_all` to be in line with the VPTS CSV specification. Details on the specification can be found at [https://aloftdata.eu/vpts-csv/](https://aloftdata.eu/vpts-csv/) (#634). +* Corrected incorrect mapping of to `dbz_all` data column in [VPTS CSV](https://aloftdata.eu/vpts-csv/) format to corresponding `DBZH` data column in bioRad vpts object (#634). * Improved the VPTS file fetching mechanism from s3: now skips a day if there are issues with fetching instead of aborting the entire download (#636)