library("knitr") hook_output <- knitr::knit_hooks$get("output") knitr::knit_hooks$set(output = function(x, options) { lines <- options$output.lines if (is.null(lines)) { return(hook_output(x, options)) # pass to default hook } x <- unlist(strsplit(x, "\n")) more <- "..." if (length(lines)==1) { # first n lines if (length(x) > lines) { # truncate the output, but add .... x <- c(head(x, lines), more) } } else { x <- c(if (abs(lines[1])>1) more else NULL, x[lines], if (length(x)>lines[abs(length(lines))]) more else NULL ) } # paste these lines together x <- paste(c(x, ""), collapse = "\n") hook_output(x, options) }) knitr::opts_chunk$set( comment = "#>", collapse = TRUE, warning = FALSE, message = FALSE, fig.width = 10, fig.path = "tools/", cache.path = "inst/cache/" )
rnoaa
is an R interface to many NOAA data sources. We don't cover all of them, but we include many commonly used sources, and add we are always adding new sources. We focus on easy to use interfaces for getting NOAA data, and giving back data in easy to use formats downstream. We currently don't do much in the way of plots or analysis.
There is a tutorial on the rOpenSci website, and there are many tutorials in the package itself, available in your R session, or on CRAN. The tutorials:
Functions to work with buoy data use netcdf files. You'll need the ncdf
package for those functions, and those only. ncdf
is in Suggests in this package, meaning you only need ncdf
if you are using the buoy functions. You'll get an informative error telling you to install ncdf
if you don't have it and you try to use the buoy functions. Installation of ncdf
should be straightforward on Mac and Windows, but on Linux you may have issues. See http://cran.r-project.org/web/packages/ncdf/INSTALL
There are many NOAA NCDC datasets. All data sources work, except NEXRAD2
and NEXRAD3
, for an unknown reason. This relates to ncdc_*()
functions only.
dat <- ncdc_datasets()$data dat <- dat[, !names(dat) %in% 'uid'] dat <- dat[, c('id', 'name', 'mindate', 'maxdate', 'datacoverage')] names(dat) <- c('Dataset', 'Description', 'Start Date', 'End Date', 'Data Coverage') knitr::kable(dat)
Each NOAA dataset has a different set of attributes that you can potentially get back in your search. See http://www.ncdc.noaa.gov/cdo-web/datasets for detailed info on each dataset. We provide some information on the attributes in this package; see the vignette for attributes to find out more
You'll need an API key to use the NOAA NCDC functions (those starting with ncdc*()
) in this package (essentially a password). Go to http://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.
a) Pass it inline with each function call (somewhat cumbersome)
ncdc(datasetid = 'PRECIP_HLY', locationid = 'ZIP:28801', datatypeid = 'HPCP', limit = 5, token = "YOUR_TOKEN")
b) Alternatively, you might find it easier to set this as an option, either by adding this line to the top of a script or somewhere in your .rprofile
options(noaakey = "KEY_EMAILED_TO_YOU")
c) You can always store in permamently in your .Rprofile
file.
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-bin
referenceThen 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("http://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
install.packages("rnoaa")
or development version from GitHub
devtools::install_github("ropensci/rnoaa")
Load rnoaa
library('rnoaa')
ncdc_locs(locationcategoryid='CITY', sortfield='name', sortorder='desc')
ncdc_stations(datasetid='GHCND', locationid='FIPS:12017', stationid='GHCND:USC00084289')
out <- ncdc(datasetid='NORMAL_DLY', stationid='GHCND:USW00014895', datatypeid='dly-tmax-normal', startdate = '2010-05-01', enddate = '2010-05-10')
head( out$data )
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")
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")
ncdc_datasets()
ncdc_datacats(locationid = 'CITY:US390029')
The function tornadoes()
simply gets all the data. So the call takes a while, but once done, is fun to play with.
shp <- tornadoes() library('sp') plot(shp)
In this example, search for metadata for a single station ID
homr(qid = 'COOP:046742')
Get storm data for the year 2010
storm_data(year = 2010)
Get forecast for a certain variable.
res <- gefs("Total_precipitation_surface_6_Hour_Accumulation_ens", lat = 46.28125, lon = -116.2188) head(res$data)
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")
Get daily mean water level data at Fairport, OH (9063053)
coops_search(station_name = 9063053, begin_date = 20150927, end_date = 20150928, product = "daily_mean", datum = "stnd", time_zone = "lst")
rnoaa
in R doing citation(package = 'rnoaa')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.