rweathernoaaropenscirnoaa

NOAA Daily Weather Extraction


I am really new to R and I am trying to use rnoaa to extract information.

I have a set of two dates:

and I need to extract daily weather values for Ann Arbor MI, New Haven CT and Los Angeles, CA. I have the station ID for each of these three cities and they are: USC00200230, US090004, US060013, respectively.

Can someone help me extract the values for Daily Min Temp, Max Temp, Humidity, Precipitation, and Sunshine?

So far I have just been able to access the data base:

library(rnoaa)  #get rnoaa from your R library to run
library(devtools)
options(noaakey= "mykey") 

I am aware that to obtain information I have to enter something in the following format:

noaa(datasetid='NORMAL_DLY', stationid='putinstationidhere', datacategoryid="TEMP")

I am just not knowledgeable of the schema of this data base as I have always used the online version and I am very new to coding in R. The documentation on this is also very sparse so I am hoping someone here knows how to use rnoaa well.


Solution

  • Here is my attempt at what you are asking for.

    The station ids have to have the datasetid as a prefix with a colon, so GHCND:USC00200230 instead of USC00200230

    You can't pass datacategoryid to the ncdc function. See the docs for the API here

    For example, get precipitation data:

    out <- ncdc(datasetid='GHCND', datatypeid = 'PRCP', stationid='GHCND:USC00200230', startdate = "2013-09-03", enddate = "2013-09-30", limit=30)
    head(out$data)
    
                 station value attributes datatype                date
    1  GHCND:USC00200230     0   ,,7,1800     PRCP 2013-09-03T00:00:00
    2  GHCND:USC00200230     0   ,,7,1800     PRCP 2013-09-04T00:00:00
    3  GHCND:USC00200230     0   ,,7,1800     PRCP 2013-09-05T00:00:00
    4  GHCND:USC00200230     0   ,,7,1800     PRCP 2013-09-06T00:00:00
    5  GHCND:USC00200230     8   ,,7,1800     PRCP 2013-09-07T00:00:00
    6  GHCND:USC00200230     0   ,,7,1800     PRCP 2013-09-08T00:00:00    
    

    Another example, get min temperature

    out <- ncdc(datasetid='GHCND', datatypeid = 'TMIN', stationid='GHCND:USC00200230', startdate = "2013-09-03", enddate = "2013-09-30", limit=30)
    head(out$data)
    
                 station value attributes datatype                date
    1  GHCND:USC00200230   139   ,,7,1800     TMIN 2013-09-03T00:00:00
    2  GHCND:USC00200230   128   ,,7,1800     TMIN 2013-09-04T00:00:00
    3  GHCND:USC00200230   111   ,,7,1800     TMIN 2013-09-05T00:00:00
    4  GHCND:USC00200230    83   ,,7,1800     TMIN 2013-09-06T00:00:00
    5  GHCND:USC00200230   139   ,,7,1800     TMIN 2013-09-07T00:00:00
    6  GHCND:USC00200230   183   ,,7,1800     TMIN 2013-09-08T00:00:00
    

    If you leave out the datatypeid you get data for all data types.