boB Rudis
4 years ago
8 changed files with 139 additions and 7 deletions
@ -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) |
|||
|
|||
} |
|||
|
@ -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 |
|||
} |
Loading…
Reference in new issue