Browse Source

latest_radar()

master
boB Rudis 4 years ago
parent
commit
97ff8e826e
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 1
      .Rbuildignore
  2. 7
      DESCRIPTION
  3. 4
      NAMESPACE
  4. 3
      NEWS.md
  5. 75
      R/latest_radar.R
  6. 4
      R/mosaic.R
  7. 3
      R/rradar-package.R
  8. 33
      README.Rmd
  9. 35
      README.md
  10. BIN
      man/figures/README-left-coast-1.gif
  11. BIN
      man/figures/README-mosaic-1.gif
  12. BIN
      man/figures/README-right-coast-1.gif
  13. BIN
      man/figures/README-stars-1.png
  14. 39
      man/latest_radar.Rd

1
.Rbuildignore

@ -3,6 +3,7 @@
^\.Rproj\.user$
^\.travis\.yml$
^README\.*Rmd$
^README_cache$
^README\.*html$
^NOTES\.*Rmd$
^NOTES\.*html$

7
DESCRIPTION

@ -25,6 +25,9 @@ Imports:
httr,
magick,
rvest,
magrittr
magrittr,
stars,
sf,
utils
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.0.1
RoxygenNote: 7.0.2

4
NAMESPACE

@ -3,8 +3,12 @@
export("%>%")
export(animate_conus_mosaic)
export(animate_radar)
export(latest_radar)
export(stations)
import(httr)
import(magick)
import(rvest)
importFrom(magrittr,"%>%")
importFrom(sf,st_set_crs)
importFrom(stars,read_stars)
importFrom(utils,download.file)

3
NEWS.md

@ -1,3 +1,6 @@
0.2.0
* added `latest_radar()` to return regional mosaics as `stars` objects
0.1.2
* added conus animation

75
R/latest_radar.R

@ -0,0 +1,75 @@
set_names <- function(object = nm, nm) {
names(object) <- nm
object
}
set_names(
c("alaska", "centgrtlakes_radaronly", "hawaii_radaronly",
"latest_radaronly", "northeast_radaronly", "northrockies_radaronly",
"pacnorthwest_radaronly", "pacsouthwest_radaronly",
"southeast_radaronly", "southmissvly_radaronly",
"southplains_radaronly", "southrockies_radaronly",
"uppermissvly_radaronly"),
c("alaska", "centgrtlakes", "hawaii",
"latest", "northeast", "northrockies",
"pacnorthwest", "pacsouthwest",
"southeast", "southmissvly",
"southplains", "southrockies",
"uppermissvly")
) -> .reg_trans
#' Read latest NWS regional or ConUS radar mosaics as a `stars` object
#'
#' @param regional_mosaic one of the supported mosaics from [the official NWS list](https://radar.weather.gov/ridge/):
#' - "`alaska`": Alaska
#' - "`centgrtlakes`": Central Great Lakes
#' - "`hawaii`": Hawaii
#' - "`latest`": ConUS
#' - "`northeast`": Northeast
#' - "`northrockies`": Northern Rockies
#' - "`pacnorthwest`": Pacific Northwest
#' - "`pacsouthwest`": Pacific Southwest
#' - "`southeast`": Southeast
#' - "`southmissvly`": Southern Mississippi Valley
#' - "`southplains`": Southern Plains
#' - "`southrockies`": Southern Rockies
#' - "`uppermissvly`": Upper Mississippi Valley
#' @param quiet passed on to [utils::download.file()]
#' @return `stars` object with the raster composite with a CRS of EPSG:4326
#' @export
latest_radar <- function(regional_mosaic = c("alaska", "centgrtlakes", "hawaii",
"latest", "northeast", "northrockies",
"pacnorthwest", "pacsouthwest",
"southeast", "southmissvly",
"southplains", "southrockies",
"uppermissvly"), quiet = TRUE) {
regional_mosaic <- match.arg(tolower(regional_mosaic[1]), c("alaska", "centgrtlakes", "hawaii",
"latest", "northeast", "northrockies",
"pacnorthwest", "pacsouthwest",
"southeast", "southmissvly",
"southplains", "southrockies",
"uppermissvly"))
regional_mosaic <- .reg_trans[[regional_mosaic]]
td <- tempdir()
on.exit(unlink(td))
download.file(
c(
sprintf("https://radar.weather.gov/ridge/Conus/RadarImg/%s.gif", regional_mosaic),
sprintf("https://radar.weather.gov/ridge/Conus/RadarImg/%s.gfw", regional_mosaic)
),
file.path(td, paste(regional_mosaic, c(".gif", ".gfw"), sep = "")),
method = "libcurl",
quiet = quiet
)
out <- stars::read_stars(file.path(td, sprintf("%s.gif", regional_mosaic)))
sf::st_set_crs(out, 4326)
}

4
R/mosaic.R

@ -8,7 +8,7 @@ animate_conus_mosaic <- function(size = c("small", "large")) {
pre <- if (size == "small") "Nat_" else "NAT_"
ir <- possibly(image_read, NULL)
ir <- possibly(magick::image_read, NULL)
res <- httr::GET("https://radar.weather.gov/ridge/Conus/RadarImg/")
out <- httr::content(res)
@ -20,6 +20,6 @@ animate_conus_mosaic <- function(size = c("small", "large")) {
radar_imgs <- do.call(c, out)
image_animate(radar_imgs)
magick::image_animate(radar_imgs)
}

3
R/rradar-package.R

@ -9,4 +9,7 @@
#' @keywords internal
#' @author Bob Rudis (bob@@rud.is)
#' @import httr magick rvest
#' @importFrom stars read_stars
#' @importFrom sf st_set_crs
#' @importFrom utils download.file
"_PACKAGE"

33
README.Rmd

@ -49,18 +49,45 @@ filter(stations, state == "Maine")
filter(stations, state == "California")
```
```{r right-coast}
```{r right-coast, cache=TRUE}
animate_radar("GYX")
```
```{r left-coast}
```{r left-coast, cache=TRUE}
animate_radar("VBX")
```
```{r mosaic}
```{r mosaic, cache=TRUE}
animate_conus_mosaic("small")
```
```{r stars}
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) +
geom_stars(data = ne_radar) +
scale_fill_viridis_c(name = "dBZ", na.value = "#00000000") +
coord_sf(datum = NA) +
labs(
x = NULL, y = NULL,
title = "NWS Radar Mosaic — Northeast Sector",
subtitle = "1538 UTC 2019-12-07"
) +
theme_ipsum_es(grid="")
```
## rradar Metrics
```{r cloc, echo=FALSE}

35
README.md

@ -30,6 +30,8 @@ The following functions are implemented:
the the conterminus U.S.
- `animate_radar`: Create an animated weather image from a NOAA
station
- `latest_radar`: Read latest NWS regional or ConUS radar mosaics as a
stars object
- `stations`: NOAA U.S. Radar Stations
## Installation
@ -108,12 +110,41 @@ animate_conus_mosaic("small")
![](man/figures/README-mosaic-1.gif)<!-- -->
``` r
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) +
geom_stars(data = ne_radar) +
scale_fill_viridis_c(name = "dBZ", na.value = "#00000000") +
coord_sf(datum = NA) +
labs(
x = NULL, y = NULL,
title = "NWS Radar Mosaic — Northeast Sector",
subtitle = "1538 UTC 2019-12-07"
) +
theme_ipsum_es(grid="")
```
<img src="man/figures/README-stars-1.png" width="672" />
## rradar Metrics
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
| R | 7 | 0.88 | 184 | 0.93 | 23 | 0.51 | 41 | 0.53 |
| Rmd | 1 | 0.12 | 14 | 0.07 | 22 | 0.49 | 37 | 0.47 |
| R | 8 | 0.89 | 229 | 0.87 | 34 | 0.56 | 63 | 0.62 |
| Rmd | 1 | 0.11 | 34 | 0.13 | 27 | 0.44 | 39 | 0.38 |
## Code of Conduct

BIN
man/figures/README-left-coast-1.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 972 KiB

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
man/figures/README-mosaic-1.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.8 MiB

BIN
man/figures/README-right-coast-1.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.0 MiB

BIN
man/figures/README-stars-1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

39
man/latest_radar.Rd

@ -0,0 +1,39 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/latest_radar.R
\name{latest_radar}
\alias{latest_radar}
\title{Read latest NWS regional or ConUS radar mosaics as a \code{stars} object}
\usage{
latest_radar(
regional_mosaic = c("alaska", "centgrtlakes", "hawaii", "latest", "northeast",
"northrockies", "pacnorthwest", "pacsouthwest", "southeast", "southmissvly",
"southplains", "southrockies", "uppermissvly"),
quiet = TRUE
)
}
\arguments{
\item{regional_mosaic}{one of the supported mosaics from \href{https://radar.weather.gov/ridge/}{the official NWS list}:
\itemize{
\item "\code{alaska}": Alaska
\item "\code{centgrtlakes}": Central Great Lakes
\item "\code{hawaii}": Hawaii
\item "\code{latest}": ConUS
\item "\code{northeast}": Northeast
\item "\code{northrockies}": Northern Rockies
\item "\code{pacnorthwest}": Pacific Northwest
\item "\code{pacsouthwest}": Pacific Southwest
\item "\code{southeast}": Southeast
\item "\code{southmissvly}": Southern Mississippi Valley
\item "\code{southplains}": Southern Plains
\item "\code{southrockies}": Southern Rockies
\item "\code{uppermissvly}": Upper Mississippi Valley
}}
\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 regional or ConUS radar mosaics as a \code{stars} object
}
Loading…
Cancel
Save