diff --git a/.Rbuildignore b/.Rbuildignore index b8a7fc7f..dd3bc837 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -17,4 +17,4 @@ inst/extdata/vpts.txt.zip ^CRAN-SUBMISSION$ ^doc$ ^Meta$ -rosm.cache +^rosm\.cache$ diff --git a/DESCRIPTION b/DESCRIPTION index e2479bca..811bfa94 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -53,9 +53,11 @@ Imports: viridisLite Suggests: aws.s3, - ggmap (>= 3.0.0), + ggspatial, knitr, + prettymapr, rmarkdown, + rosm, sf, testthat (>= 3.0.0), tidyselect, diff --git a/NEWS.md b/NEWS.md index 09b21d2b..6a2d9780 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,19 @@ +# bioRad 0.7.3 + +## 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 (#638). + +## Bugfixes + +* 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) + +## Deprecations + +* `download_basemap()` has been deprecated, function `map()` now automatically downloads a basemap (#638). + # 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. diff --git a/R/bioRad-deprecated.R b/R/bioRad-deprecated.R index b702292b..8b205c6c 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("cartolight") +} \ No newline at end of file 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/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/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/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)) 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 5c6a38f9..d85f2803 100644 --- a/R/map.R +++ b/R/map.R @@ -1,10 +1,9 @@ #' 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, result of a call to [download_basemap()]. +#' @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. @@ -21,11 +20,9 @@ #' @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 [ggplot2::ggplot()]. #' @importFrom methods as -#' @return A ggmap object (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: @@ -44,15 +41,14 @@ #' @export #' #' @seealso -#' * [download_basemap()] #' * [project_as_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, maptype = "toner-lite") +#' # Choose a basemap +#' basemap <- rosm::osm.types()[1] #' #' # Map the radial velocity of the ppi onto the basemap #' map(ppi, map = basemap, param = "VRADH") @@ -81,8 +77,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, map="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,14 +106,19 @@ 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.") + + # 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)) { + stop(paste("Invalid basemap argument. Must be one of:", paste(valid_types, collapse=", "))) + } } + assert_valid_basemap(map) + # set color scales and palettes if (!assertthat::are_equal(palette, NA)) { if(!(is.character(palette) && length(palette) > 1)) stop("palette should be a character vector with hex color values") @@ -188,44 +189,50 @@ map.ppi <- function(x, map, param, alpha = 0.7, xlim, ylim, zlim = c(-20, 20), } # 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") + rdf$fill <- col_func(r@data@values, zlim) # 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. + + radar_location = data.frame(lon = x$geo$lon, lat = x$geo$lat) %>% + sf::st_as_sf(coords = c("lon", "lat")) %>% + sf::st_set_crs(4326) %>% + sf::st_transform(3857) + + radar_df <- data.frame(sf::st_coordinates(radar_location)) + 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') - 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)) + size = 0, + data = data.frame( + lon = radar_df$X, + lat = radar_df$Y, + z = 0 + )) + + mymap <- suppressWarnings( + ggplot2::ggplot() + + 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), + shape = 21, + fill = "transparent", + colour = radar_color, + size = radar_size, + stroke = 1.5, + show.legend = FALSE) + + dummy + + colorscale + + ggplot2::labs(x="lon", y="lat") ) + suppressWarnings(mymap) } 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} 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/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()}} -} -} 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 ea9c5d59..0e5a51a4 100644 --- a/man/map.Rd +++ b/man/map.Rd @@ -9,7 +9,7 @@ map(x, ...) \method{map}{ppi}( x, - map, + map = "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, ... @@ -26,9 +26,9 @@ map(x, ...) \arguments{ \item{x}{A \code{ppi} object.} -\item{...}{Arguments passed to \code{\link[ggmap:ggmap]{ggmap::ggmap()}}.} +\item{...}{Arguments passed to \code{\link[ggplot2:ggplot]{ggplot2::ggplot()}}.} -\item{map}{Basemap to use, result of a call to \code{\link[=download_basemap]{download_basemap()}}.} +\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.} @@ -57,8 +57,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 @@ -90,8 +89,8 @@ 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 +basemap <- rosm::osm.types()[1] # Map the radial velocity of the ppi onto the basemap map(ppi, map = basemap, param = "VRADH") @@ -117,7 +116,6 @@ map(ppi, map = 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/tests/testthat/test-download_pvolfiles.R b/tests/testthat/test-download_pvolfiles.R index 03914607..095a46d9 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"), @@ -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) ), 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), diff --git a/vignettes/rad_aero_22.Rmd b/vignettes/rad_aero_22.Rmd index 535c50cc..2456c1bf 100644 --- a/vignettes/rad_aero_22.Rmd +++ b/vignettes/rad_aero_22.Rmd @@ -156,10 +156,8 @@ 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() +basemap = "osm" # 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)) ``` diff --git a/vignettes/range_correction.Rmd b/vignettes/range_correction.Rmd index d68a3925..01130134 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, map=bm, param = "VIR", alpha = .5) ``` ## 6 Overlap between radiation profile and bird profile