| Title: | Interact with the U.S. National Weather Service API |
|---|---|
| Description: | Enables interaction with the National Weather Service application programming web-interface for fetching of realtime meteorological data. Users can provide latitude and longitude, Automated Surface Observing System identifier, or Automated Weather Observing System identifier to fetch recent weather observations and recent forecasts for the given location or station. Additionally, auxiliary functions exist to identify stations nearest to a point, convert wind direction from character to degrees, and fetch active warnings. Results are returned as simple feature objects whenever possible. |
| Authors: | Jeffrey Fowler [aut, cre, cph] (ORCID: <https://orcid.org/0009-0003-9448-0980>) |
| Maintainer: | Jeffrey Fowler <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-16 05:49:39 UTC |
| Source: | https://github.com/jeffreyfowler/weathr |
Point Forecast Data and Local Timezone
..point_forecast(lat, lon, timezone = -1, dir_numeric = FALSE)..point_forecast(lat, lon, timezone = -1, dir_numeric = FALSE)
lat |
Latitude. |
lon |
Longitude. |
timezone |
The nominal timezone for the forecast. One of |
dir_numeric |
|
A list containing point forecast sf and the timezone.
..point_forecast(33, -80)..point_forecast(33, -80)
Get the JSON Data for a Point
.point_data(lat, lon).point_data(lat, lon)
lat |
Latitude of the point to fetch data for. |
lon |
Longitude of the point to fetch data for. |
A nested list containing NWS point data.
.point_data(lat = 40.71427000, lon = -74.00597000) %>% data.frame().point_data(lat = 40.71427000, lon = -74.00597000) %>% data.frame()
Raw JSON Point Forecast Data
.point_forecast(lat, lon).point_forecast(lat, lon)
lat |
Latitude. |
lon |
Longitude. |
Returns the json data as a nested list.
.point_forecast(33, -80).point_forecast(33, -80)
Raw JSON Station Metadata
.station_data(station_id).station_data(station_id)
station_id |
The station identifier (ex: KDEN, KBOS, KNYC, etc). |
Station data provided for the National Weather Service.
.station_data("KDEN").station_data("KDEN")
National Weather Service Alerts
alerts()alerts()
Dataframe containing various columns identifying and describing alerts.
# Get all the red flag warnings red_flags <- alerts() red_flags <- filter(red_flags, grepl("red flag", red_flags$headline, ignore.case = TRUE))# Get all the red flag warnings red_flags <- alerts() red_flags <- filter(red_flags, grepl("red flag", red_flags$headline, ignore.case = TRUE))
Convert Wind Direction from Numeric to Character
dir_as_char(direction)dir_as_char(direction)
direction |
Numeric degrees clockwise from north, (0 = N, 45 = NE, etc). |
Character direction (N, NNE, NE, etc).
dir_as_char(330)dir_as_char(330)
Convert Wind Direction from a Character to an Integer
dir_as_integer(direction)dir_as_integer(direction)
direction |
A direction, as a string (N, NNE, NE, ENE, E, ESE, etc). |
An integer representing degrees clockwise from north.
dir_as_integer("NNW")dir_as_integer("NNW")
Get NWS Metadata for a Point
point_data(lat, lon)point_data(lat, lon)
lat |
Latitude. |
lon |
Longitude. |
A simple features point object with NWS metadata.
point_data(lat = 40.71427000, lon = -74.00597000)point_data(lat = 40.71427000, lon = -74.00597000)
Point Forecast Data
point_forecast(lat, lon, timezone = -1, dir_numeric = FALSE)point_forecast(lat, lon, timezone = -1, dir_numeric = FALSE)
lat |
Latitude. |
lon |
Longitude. |
timezone |
The nominal timezone for the forecast. One of |
dir_numeric |
|
Simple features object with forecast meteorological values.
point_forecast(lat = 40.71427000, lon = -74.00597000, dir_numeric = TRUE)point_forecast(lat = 40.71427000, lon = -74.00597000, dir_numeric = TRUE)
Find Nearest ASOS/AWOS Station
point_station(lat, lon)point_station(lat, lon)
lat |
Latitude. |
lon |
Longitude. |
A string corresponding to an ASOS or AWOS station.
# Gets the observation data as an sf associated with a point point_station(lat = 42, lon = -80) %>% station_obs() %>% data.frame()# Gets the observation data as an sf associated with a point point_station(lat = 42, lon = -80) %>% station_obs() %>% data.frame()
Weather Observed Today at a Point
point_today(lat, lon, timezone = -1, dir_numeric = FALSE)point_today(lat, lon, timezone = -1, dir_numeric = FALSE)
lat |
Latitude. |
lon |
Longitude. |
timezone |
The nominal timezone for the forecast. One of |
dir_numeric |
|
Simple features point corresponding to the given station identifier with recent meteorological forecast values for today.
# Produce a GT summary of the weather thus far for a given lat/lon point_today(lat = 33, lon = -80) %>% as.data.frame() %>% dplyr::mutate(time = as.POSIXct(time) %>% format("%H:%M")) %>% dplyr::select(time, temp, dewpoint, humidity, wind_speed)# Produce a GT summary of the weather thus far for a given lat/lon point_today(lat = 33, lon = -80) %>% as.data.frame() %>% dplyr::mutate(time = as.POSIXct(time) %>% format("%H:%M")) %>% dplyr::select(time, temp, dewpoint, humidity, wind_speed)
Weather Forecast for Tomorrow at a Point
point_tomorrow(lat, lon, timezone = -1, dir_numeric = FALSE, short = TRUE)point_tomorrow(lat, lon, timezone = -1, dir_numeric = FALSE, short = TRUE)
lat |
Latitude. |
lon |
Longitude. |
timezone |
The nominal timezone for the forecast. One of |
dir_numeric |
|
short |
|
Simple features object with forecast meteorological values.
point_tomorrow(lat = 33, lon = -80)point_tomorrow(lat = 33, lon = -80)
Safe Collapse
safe_collapse(x)safe_collapse(x)
x |
A list to collapse. |
A comma delimited version of your input list, or NA when the input list is blank.
This is a helper function that is used to collapse a list into a string, and is used in building the active warnings dataset.
safe_collapse(c("This is one", "And this is another one"))safe_collapse(c("This is one", "And this is another one"))
Station Coordinates
station_coords(station_id)station_coords(station_id)
station_id |
The station identifier (ex: KDEN, KBOS, KNYC, etc). |
Named list with latitude and longitude like: c("lat" = x, "lon" = y).
station_coords("KBOS")station_coords("KBOS")
Station Forecast
station_forecast(station_id, timezone = -1, dir_numeric = FALSE)station_forecast(station_id, timezone = -1, dir_numeric = FALSE)
station_id |
Station identifier (ex: KDEN, KBOS, KNYC, etc). |
timezone |
The nominal timezone for the forecast. One of |
dir_numeric |
|
Simple features point corresponding to the given station identifier with recent meteorological forecast values.
station_forecast("KBOS") %>% data.frame() %>% dplyr::select(-geometry)station_forecast("KBOS") %>% data.frame() %>% dplyr::select(-geometry)
Station Observations
station_obs(station_id, timezone = -1, dir_numeric = FALSE)station_obs(station_id, timezone = -1, dir_numeric = FALSE)
station_id |
The station identifier (ex: KDEN, KBOS, KNYC, etc). |
timezone |
The nominal timezone for the forecast. One of |
dir_numeric |
|
Simple features corresponding to the given station identifier with recent meteorological observations.
station_obs("KBOS") %>% data.frame() %>% dplyr::select(-geometry) %>% dplyr::filter(temp == max(.$temp))station_obs("KBOS") %>% data.frame() %>% dplyr::select(-geometry) %>% dplyr::filter(temp == max(.$temp))
Station Coordinates as a Point
station_point(station_id)station_point(station_id)
station_id |
The station identifier (ex: KDEN, KBOS, KNYC, etc). |
Simple features point corresponding to the given station identifier.
station_point("KDEN")station_point("KDEN")
Weather Observed Today at a Station Identifier
station_today(station_id, timezone = -1, dir_numeric = FALSE)station_today(station_id, timezone = -1, dir_numeric = FALSE)
station_id |
The station identifier (ex: KDEN, KNYC, etc). |
timezone |
The nominal timezone for the forecast. One of |
dir_numeric |
|
Simple features object with timestamps and meteorological values.
station_today("KNYC")station_today("KNYC")
Tomorrows Forecast
station_tomorrow(station_id, timezone = -1, dir_numeric = FALSE, short = TRUE)station_tomorrow(station_id, timezone = -1, dir_numeric = FALSE, short = TRUE)
station_id |
Station identifier (ex: KDEN, KBOS, KNYC, etc). |
timezone |
The nominal timezone for the forecast. One of |
dir_numeric |
|
short |
|
Simple features point corresponding to the given station identifier with recent meteorological forecast values.
station_tomorrow("KBOS")station_tomorrow("KBOS")
Fetch Station Timezone
station_tz(station_id)station_tz(station_id)
station_id |
The station identifier (ex: KDEN, KBOS, KNYC, etc). |
A character corresponding to a timezone from OlsonNames().
Sys.time() %>% lubridate::force_tz(tzone = station_tz("KDEN"))Sys.time() %>% lubridate::force_tz(tzone = station_tz("KDEN"))
Find All Stations in a Point's Forecast Zone
stations_near(lat, lon)stations_near(lat, lon)
lat |
Latitude. |
lon |
Longitude. |
An sf object with station identifiers, geometry as coordinates, and their euclidian distance (in miles) to the station provided.
# Plot the a station with given points and the nearby stations in a tmap stations_near(lat = 33, lon = -80)# Plot the a station with given points and the nearby stations in a tmap stations_near(lat = 33, lon = -80)