GDAL
You’ll need GDAL installed first. You may want to use GDAL >= 0.9-1 since that version or later can read TopoJSON format files as well, which aren’t required here, but may be useful. Install GDAL:
sudo apt-get install gdal-binThen when you install the R package rgdal (rgeos also requires GDAL), you’ll most likely need to specify where you’re gdal-config file is on your machine, as well as a few other things. I have an OSX Mavericks machine, and this works for me (there’s no binary for Mavericks, so install the source version):
install.packages("https://cran.r-project.org/src/contrib/rgdal_0.9-1.tar.gz", repos = NULL, type="source", configure.args = "--with-gdal-config=/Library/Frameworks/GDAL.framework/Versions/1.10/unix/bin/gdal-config --with-proj-include=/Library/Frameworks/PROJ.framework/unix/include --with-proj-lib=/Library/Frameworks/PROJ.framework/unix/lib")The rest of the installation should be easy. If not, let us know.
Stable version from CRAN
or development version from GitHub
Load rnoaa
NCDC Authentication
You’ll need an API key to use the NOAA NCDC functions (those starting with ncdc*()) in this package (essentially a password). Go to https://www.ncdc.noaa.gov/cdo-web/token to get one. You can’t use this package without an API key.
Once you obtain a key, there are two ways to use it.
ncdc(datasetid = 'PRECIP_HLY', locationid = 'ZIP:28801', datatypeid = 'HPCP', limit = 5, token = "YOUR_TOKEN").rprofile.Rprofile file.Note that the value column has strangely large numbers for temperature measurements. By convention, rnoaa doesn’t do any conversion of values from the APIs and some APIs use seemingly odd units.
You have two options here:
Use the add_units parameter on ncdc to have rnoaa attempt to look up the units. This is a good idea to try first.
Consult the documentation for whiechever dataset you’re accessing. In this case, GHCND has a README which indicates TMAX is measured in tenths of degrees Celcius.
data.frame with unitsAs mentioned above, you can use the add_units parameter with ncdc() to ask rnoaa to attempt to look up units for whatever data you ask it to return. Let’s ask rnoaa to add units to some precipitation (PRCP) data:
with_units <- ncdc(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP', startdate = '2010-05-01', enddate = '2010-10-31', limit=500, add_units = TRUE)
head( with_units$data )From the above output, we can see that the units for PRCP values are “mm_tenths” which means tenths of a millimeter. You won’t always be so lucky and sometimes you will have to look up the documentation on your own.
out <- ncdc(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP', startdate = '2010-05-01', enddate = '2010-10-31', limit=500)
ncdc_plot(out, breaks="1 month", dateformat="%d/%m")Note that PRCP values are in units of tenths of a millimeter, as we found out above.
You can pass many outputs from calls to the noaa function in to the ncdc_plot function.
out1 <- ncdc(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP', startdate = '2010-03-01', enddate = '2010-05-31', limit=500)
out2 <- ncdc(datasetid='GHCND', stationid='GHCND:USW00014895', datatypeid='PRCP', startdate = '2010-09-01', enddate = '2010-10-31', limit=500)
ncdc_plot(out1, out2, breaks="45 days")The function tornadoes() simply gets all the data. So the call takes a while, but once done, is fun to play with.
In this example, search for metadata for a single station ID
Get forecast for a certain variable.
There are a suite of functions for Argo data, a few egs:
# Spatial search - by bounding box
argo_search("coord", box = c(-40, 35, 3, 2))
# Time based search
argo_search("coord", yearmin = 2007, yearmax = 2009)
# Data quality based search
argo_search("coord", pres_qc = "A", temp_qc = "A")
# Search on partial float id number
argo_qwmo(qwmo = 49)
# Get data
argo(dac = "meds", id = 4900881, cycle = 127, dtype = "D")