stellaminor
stellaminor

Reputation: 1

Why is January and most of February data missing from CDO API request

Using the Climate Data Online WebAPI, every request I make fails to return January data and most of February. Only February 28th (and 29th) will be present. I've tried breaking up the data into smaller chunks, multiple stations, and I'm not bumping up against the 1000 limit. If I only request January data then I get an empty frame. I've copied other people's code, still doesn't deliver Jan & Feb. I've downloaded directly from the site and the data is there.

import requests
import json
from datetime import datetime

token = ''
headers = {'token': token}
baseUrl= r"https://www.ncdc.noaa.gov/cdo-web/api/v2/"
years=list(range(2020,2022))
for i in years:

    startdate=datetime(i,1,1).date()
    enddate = datetime(i,3,1).date()

    url = "https://www.ncdc.noaa.gov/cdo-web/api/v2/data?" \
          "datasetid=GHCND&stationid=GHCND:USW00003893&" \
          "datatypeid=PRCP&" \
          "units=standard&startdate={}&enddate={}&limit=1000".format(startdate,enddate)
    response=requests.get(url, headers=headers)
    jsonresponse = json.loads(response.text, strict=False)

Upvotes: 0

Views: 179

Answers (2)

stellaminor
stellaminor

Reputation: 1

Someone from NOAA responded quickly and said the v2 may be unsupported and to use this:

resp = requests.get("https://www.ncei.noaa.gov/access/services/data/v1?dataset=daily-summaries&dataTypes=PRCP,TMAX,TMIN&stations=USW00003893&startDate=2022-01-01&endDate=2022-08-31&units=standard", headers={"Token": token})

Upvotes: 0

2e0byo
2e0byo

Reputation: 5954

This appears to be an issue with their API: no data is returned for january. I suggest raising it with them.

Your use of requests is very unidiomatic btw. The easy way would be something like:

import requests

token = "TOKEN"
url = "https://www.ncdc.noaa.gov/cdo-web/api/v2/data"
start = "2019-12-30"
end = "2020-01-05"
params = {
    "datasetid": "GHCND",
    "stationid": "GHCND:USW00003893",
    "datatypeid": "PRCP",
    "units": "standard",
    "startdate": start,
    "enddate": end,
    "limit": 1_000,
}
resp = requests.get(url, params=params, headers={"Token": token})
resp.raise_for_status()
print(resp.json())

However this doesn't return anything for january either.

Upvotes: 1

Related Questions