0

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

I have a set of two dates:

  • September 3rd-30th 2013
  • December 3rd-31st 2013

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.

www
  • 38,575
  • 12
  • 48
  • 84
kellis13
  • 13
  • 1
  • 4
  • 1
    Please show the code you've attempted so far to create [a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Thomas Feb 27 '14 at 14:15
  • please see above for the edits I made, thank you so much – kellis13 Feb 27 '14 at 19:01
  • hi @kellis13 I am the creator of the package. We are working on finishing a better version to get to CRAN with better documentation. Looking at your question now. – sckott Feb 27 '14 at 19:05

1 Answers1

2

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.

sckott
  • 5,755
  • 2
  • 26
  • 42
  • There doesn't appear to be any data for `NORMAL_DLY` for at the least the `USC00200230 ` station - Or do you know there is and for some reason our package isn't finding it? – sckott Feb 27 '14 at 20:09
  • Thank you so much, incredibly helpful! – kellis13 Feb 27 '14 at 20:25
  • do you know where to find what does these datatype mean? and how to read attributes...? I followed your steps to get data, but don't really know how to interpret them well...Tks! – linp May 01 '14 at 20:40
  • sorry for the confusion @linp The pkg is in early dev still. You can look at http://www.ncdc.noaa.gov/cdo-web/datasets for docs on each dataset. E.g., here's help on the `ANNUAL` dataset http://www1.ncdc.noaa.gov/pub/data/cdo/documentation/ANNUAL_documentation.pdf – sckott May 01 '14 at 21:24
  • Ah thanks @ScottChamberlain I wasn't expecting such a fast reply. I did find the documentation online yesterday. The package does it's work retrieving data, I just wish it could retrieve multiple datatype at the same time...:) – linp May 02 '14 at 14:24
  • You can get multiple datatypes in one call. E.g., Try omitting the `datatypeid` param `noaa(datasetid='GHCND', stationid='GHCND:USC00200230', startdate = "2013-09-03", enddate = "2013-09-30", limit=30)` – sckott May 02 '14 at 14:31
  • @sckott FYI: `noaa()` has been changed to `ncdc()` – Rafael Apr 04 '17 at 19:40
  • 1
    @RafaelMartins you are correct, i'll update the answer – sckott Apr 04 '17 at 19:56