Browse Source

latest_ridge()

master
boB Rudis 4 years ago
parent
commit
3399da2076
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 4
      DESCRIPTION
  2. 1
      NAMESPACE
  3. 4
      NEWS.md
  4. 6
      R/latest_radar.R
  5. 58
      R/latest_ridge.R
  6. 11
      README.md
  7. 33
      man/latest_ridge.Rd
  8. 29
      man/scale_fill_rradar.Rd

4
DESCRIPTION

@ -1,8 +1,8 @@
Package: rradar
Type: Package
Title: Animate NOAA NWSRadar Images by Station Id
Version: 0.3.0
Date: 2019-12-15
Version: 0.4.0
Date: 2019-12-17
Authors@R: c(
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5670-2640")),

1
NAMESPACE

@ -4,6 +4,7 @@ export("%>%")
export(animate_conus_mosaic)
export(animate_radar)
export(latest_radar)
export(latest_ridge)
export(scale_fill_rradar)
export(stations)
import(httr)

4
NEWS.md

@ -1,3 +1,7 @@
0.3.0
* added `latest_ridge()` to return regional mosaics as `stars` objects
* `scale_fill_rradar()`
0.2.0
* added `latest_radar()` to return regional mosaics as `stars` objects

6
R/latest_radar.R

@ -55,6 +55,8 @@ latest_radar <- function(regional_mosaic = c("alaska", "centgrtlakes", "hawaii",
regional_mosaic <- .reg_trans[[regional_mosaic]]
td <- tempdir()
if (!dir.exists(td)) dir.create(td)
on.exit(unlink(td))
download.file(
@ -67,6 +69,10 @@ latest_radar <- function(regional_mosaic = c("alaska", "centgrtlakes", "hawaii",
quiet = quiet
)
if (!all(file.exists(file.path(td, sprintf("%s.gif", regional_mosaic))))) {
stop("Something went wrong. File(s) do not appear to have downloaded or there is a permissions problem.", call.=FALSE)
}
out <- stars::read_stars(file.path(td, sprintf("%s.gif", regional_mosaic)))
sf::st_set_crs(out, 4326)

58
R/latest_ridge.R

@ -0,0 +1,58 @@
#' Read latest NWS ridge as a stars object
#'
#' @param station the abbreviated station name. See [stations].
#' @param ridge image type
#' - "`base`" for Base Reflectivity (out to 124 nm). **The default**.
#' - "`storm`" for Storm Relative Motion
#' - "`hour`" for One-Hour Precipitation
#' - "`composite`" for Composite Reflectivity
#' - "`storm_total`" for Storm Total Precipitation
#' - "`base_extended`" for Base Reflectivity (out to 248 nmi)
#' @param quiet passed on to [utils::download.file()]
#' @return `stars` object with the raster composite with a CRS of EPSG:4326
#' @export
latest_ridge <- function(station = "GYX",
ridge = c("base", "storm", "hour", "composite", "storm_total", "base_extended"),
quiet = TRUE) {
ridge <- match.arg(tolower(ridge[1]), c("base", "storm", "hour", "composite", "storm_total", "base_extended"))
station <- toupper(as.character(station[1]))
if (!(station %in% stations$station)) stop("Could not locate station '", station, "'.", call.=FALSE)
st_dir <- switch(
ridge,
base = "N0R",
storm = "N0S",
hour = "N1P",
composite = "NCR",
storm_total = "NTP",
base_extended = "N0Z"
)
td <- tempdir()
if (!dir.exists(td)) dir.create(td)
on.exit(unlink(td))
download.file(
c(
sprintf("https://radar.weather.gov/ridge/RadarImg/%s/%s_%s_0.gif", st_dir, station, st_dir),
sprintf("https://radar.weather.gov/ridge/RadarImg/%s/%s_%s_0.gfw", st_dir, station, st_dir)
),
file.path(td, paste(station, c(".gif", ".gfw"), sep = "")),
method = "libcurl",
quiet = quiet
)
if (!all(file.exists(file.path(td, sprintf("%s.gif", station))))) {
stop("Something went wrong. File(s) do not appear to have downloaded or there is a permissions problem.", call.=FALSE)
}
out <- stars::read_stars(file.path(td, sprintf("%s.gif", station)))
sf::st_set_crs(out, 4326)
}

11
README.md

@ -32,6 +32,7 @@ The following functions are implemented:
station
- `latest_radar`: Read latest NWS regional or ConUS radar mosaics as a
stars object
- `latest_ridge`: Read latest NWS ridge as a stars object
- `scale_fill_rradar`: Continuous fill scale for use with NWS raster
radar data
- `stations`: NOAA U.S. Radar Stations
@ -62,7 +63,7 @@ library(rradar)
# current version
packageVersion("rradar")
## [1] '0.3.0'
## [1] '0.4.0'
```
### Stations
@ -149,10 +150,10 @@ ggplot() +
## rradar Metrics
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | --: | --: | ---: | ----------: | ---: | -------: | ---: |
| R | 9 | 0.9 | 239 | 0.86 | 37 | 0.58 | 114 | 0.75 |
| Rmd | 1 | 0.1 | 40 | 0.14 | 27 | 0.42 | 39 | 0.25 |
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
| R | 10 | 0.91 | 276 | 0.87 | 51 | 0.65 | 127 | 0.77 |
| Rmd | 1 | 0.09 | 40 | 0.13 | 27 | 0.35 | 39 | 0.23 |
## Code of Conduct

33
man/latest_ridge.Rd

@ -0,0 +1,33 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/latest_ridge.R
\name{latest_ridge}
\alias{latest_ridge}
\title{Read latest NWS ridge as a stars object}
\usage{
latest_ridge(
station = "GYX",
ridge = c("base", "storm", "hour", "composite", "storm_total", "base_extended"),
quiet = TRUE
)
}
\arguments{
\item{station}{the abbreviated station name. See \link{stations}.}
\item{ridge}{image type
\itemize{
\item "\code{base}" for Base Reflectivity (out to 124 nm). \strong{The default}.
\item "\code{storm}" for Storm Relative Motion
\item "\code{hour}" for One-Hour Precipitation
\item "\code{composite}" for Composite Reflectivity
\item "\code{storm_total}" for Storm Total Precipitation
\item "\code{base_extended}" for Base Reflectivity (out to 248 nmi)
}}
\item{quiet}{passed on to \code{\link[utils:download.file]{utils::download.file()}}}
}
\value{
\code{stars} object with the raster composite with a CRS of EPSG:4326
}
\description{
Read latest NWS ridge as a stars object
}

29
man/scale_fill_rradar.Rd

@ -44,3 +44,32 @@ This \code{{ggplot2}} continuous fill scale is an adaptation of the \code{{virid
where the viridis scale mappings only start when dBZ values are around 5 dBZ. Values lower than that
receive light gray with a 5\% alpha (see the \code{low_dbz} parameter).
}
\examples{
\dontrun{
library(sf)
library(stars)
library(rradar)
library(rnaturalearth)
library(hrbrthemes)
library(tidyverse)
us <- ne_states(country = "united states of america", returnclass = "sf")
ne_radar <- latest_radar("northeast")
ne_us <- st_crop(us, st_bbox(ne_radar))
ggplot() +
geom_sf(data = ne_us, size = 0.125, fill = '#fefefe') +
geom_stars(data = ne_radar) +
coord_sf(datum = NA) +
scale_fill_rradar() +
labs(
x = NULL, y = NULL,
title = "NWS Radar Mosaic — Northeast Sector",
subtitle = "1538 UTC 2019-12-07"
) +
theme_ipsum_es(grid="") +
theme(legend.key.height = unit(5, "lines"))
}
}

Loading…
Cancel
Save