Weather.gov API
The United States National Weather Service (NWS) offers an easy to use weather API. To fetch data for a given latitude and longitude, use the following query:
curl -H 'accept: application/geo+json' 'https://api.weather.gov/points/33.3815,-118.4332'
{
...
"properties": {
...
"gridId": "LOX",
"gridX": 142,
"gridY": 16,
"forecast": "https://api.weather.gov/gridpoints/LOX/142,16/forecast",
"forecastHourly": "https://api.weather.gov/gridpoints/LOX/142,16/forecast/hourly",
"forecastGridData": "https://api.weather.gov/gridpoints/LOX/142,16",
"observationStations": "https://api.weather.gov/gridpoints/LOX/142,16/stations",
...
}
}
The response is in GeoJSON format, but there's no need to know the details of that format to use the data.
The NWS operates a number of Weather Forecast Offices (WFO), each responsible for forecasts in a portion of the US. The WFO responsible for that latitude/longitude is .properties.gridId
. Each WFO splits the region it's responsible for into a grid. The grid cell corresponding to the requested latitude/longitude is [.properties.gridX, .properties.gridY]
.
To get the forecast in a machine-parsable, numeric format, use the URL under .properties.forecastGridData
. It is also available in human-readable format in 12-hour intervals under .properties.forecast
and 1-hour intervals under .properties.forecastHourly
. For now, we'll focus on the machine-readable forecast data:
curl -H 'accept: application/geo+json' 'https://api.weather.gov/gridpoints/LOX/142,16'
{
...
"properties": {
...
"temperature": {
"uom": "wmoUnit:degC",
"values": [
{
"validTime": "2020-06-26T04:00:00+00:00/PT2H",
"value": 14.444444444444445
},
{
"validTime": "2020-06-26T06:00:00+00:00/PT2H",
"value": 15
},
...
]
},
"windSpeed": {...},
"probabilityOfPrecipitation": {...},
...
}
}
The first thing you'll notice if you try this out is that there's a ton of data returned. Let's focus on one property, .properties.temperature
. The unit of the measurement is given under .properties.temperature.uom
(°C, in this case). The forecast for each time interval is under .properties.temperature.values
. The interval is given in ISO 8601 interval format.
In addition to forecasts, you can request raw observations. Recall that our first query gave a list of observation stations under .properties.observationStations
. Let's take a look:
curl -H 'accept: application/geo+json' 'https://api.weather.gov/gridpoints/LOX/142,16/stations'
{
...
"features": [
{
"id": "https://api.weather.gov/stations/KAVX",
"geometry": {
"type": "Point",
"coordinates": [
-118.41456,
33.40421
]
},
...
},
{
"id": "https://api.weather.gov/stations/AIDC1",
"geometry": {
"type": "Point",
"coordinates": [
-118.3305,
33.338
]
},
...
},
...
],
...
}
This list includes all the stations within the 2.5 km grid area. We can fetch the most recent observations made by a particular weather station like so:
curl -H 'accept: application/geo+json' 'https://api.weather.gov/stations/KAVX/observations?limit=1'
{
...
"features": [
{
...
"properties": {
...
"timestamp": "2020-06-26T10:08:00+00:00",
"temperature": {
"value": 13.9,
"unitCode": "unit:degC",
"qualityControl": "qc:V"
},
"dewpoint": {
"value": 12.8,
"unitCode": "unit:degC",
"qualityControl": "qc:V"
},
"windDirection": {
"value": 110,
"unitCode": "unit:degree_(angle)",
"qualityControl": "qc:V"
},
...
}
}
]
}
There's plenty of other data available, so be sure to take a look at the API documentation (click the "Specification" tab). Note that this API barely scratches the surface of what data the National Weather Service has to offer. If you take a look around their website, you'll find many different APIs run by various departments in the NWS, such as the GIS web services and the National Digital Forecast Database.