Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the NOAA API to query past weather data for a given set of coordinates

I am trying to retrieve past NOAA data using latitudinal and longitudinal coordinates. I am interested both in historical time series and annual summaries for variables such as temperature, wind speed, cloud fraction, and precipitation.

EX: 2008-02-20 13:00 in (25.033972, 121.564493)

I hope to automate a process that achieves this for 900,000+ locations. Any ideas? Ideally this script would be written in R or Python.

like image 815
user1481941 Avatar asked Sep 16 '13 13:09

user1481941


People also ask

How do I get weather data from NOAA API?

You can access this file at https://api.weather.gov/openapi.json (in JSON format) or https://api.weather.gov/openapi.yaml (in YAML format). Much of the data returned from the API is in GeoJSON (RFC 7946) format.

How do I download historical data from NOAA?

Downloading weather from NOAA websiteSelect Weather Observation Type/Dataset and select Daily Summaries. Select Date Range using the calendar button (Be sure to get daily weather data for 365/366 days of the year). Search for and choose the appropriate search type you will be using (typically we select Stations).

Is there a weather API?

Overview. The National Weather Service (NWS) API allows developers access to critical forecasts, alerts, and observations, along with other weather data. The API was designed with a cache-friendly approach that expires content based upon the information life cycle.


2 Answers

  1. Figure out the endpoint/dataset that contains the information you want (or multiple ones)
  2. Convert lat/long into zip code
  3. Find the correct station for the zip code here
  4. For each endpoint, pull data for each location.
  5. ???
  6. Profit???
like image 123
Wayne Werner Avatar answered Sep 27 '22 19:09

Wayne Werner


NOAA is now on its second version of the NOAA web API. APIs are useful because you can essentially query a web service, using requests and a python dict of arguments that describe what you want. @Cravden has made a nice class that will get you started on GitHub. NOAA has nice documentation describing what you can get and how (you need to give them and email to get an access token). Other climate data aggregators also do this kind of thing.
Something as simple as this might get you started:

import requests


def get_noaa_data(url, data_type, header):

    r = requests.get(url, data_type, headers=header)
    print(r)


if __name__ == '__main__':

    token = 'gotowebsitetorequesttoken'
    creds = dict(token=token)
    dtype = 'dataset'
    url = 'https://www.ncdc.noaa.gov/cdo-web/api/v2/'

    get_noaa_data(url, dtype, creds)

If you are going for thousands of places, you might consider downloading gridded data, making a shapefile of the points, then extracting raster values to an attribute table as done here.

like image 26
dgketchum Avatar answered Sep 27 '22 21:09

dgketchum