Learn R Programming

rerddap (version 0.3.0)

griddap: Get ERDDAP griddap data.

Description

Get ERDDAP griddap data.

Usage

griddap(x, ..., fields = "all", stride = 1, fmt = "nc", ncdf = "ncdf",
  url = eurl(), store = disk(), read = TRUE, callopts = list())

Arguments

x
Anything coercable to an object of class info. So the output of a call to info, or a datasetid, which will internally be passed through info
...
Dimension arguments. See examples. Can be any 1 or more of the dimensions for the particular dataset - and the dimensions vary by dataset. For each dimension, pass in a vector of length two, with min and max value desired.
fields
(character) Fields to return, in a character vector.
stride
(integer) How many values to get. 1 = get every value, 2 = get every other value, etc. Default: 1 (i.e., get every value)
fmt
(character) One of csv or nc (for netcdf). Default: nc
ncdf
(character) One of ncdf or ncdf4. If ncdf, use the package ncdf to read netcdf files. If ncdf4, use the package ncdf4. ncdf package is required for th
url
A URL for an ERDDAP server. Default: http://upwell.pfeg.noaa.gov/erddap/
store
One of disk (default) or memory. You can pass options to disk
read
(logical) Read data into memory or not. Does not apply when store parameter is set to memory (which reads data into memory). For large csv, or especially netcdf files, you may want to set this to FALSE, which simply returns a sum
callopts
Pass on curl options to GET

Value

  • An object of class griddap_csv if csv chosen or griddap_nc if nc file format chosen. These two classes are a thin wrapper around a data.frame, so the data you get back is a data.frame with metadata attached as attributes, along with a summary of the netcdf file (if fmt="nc"). If read=FALSE, you get back an empty data.frame.

Dimensions and Variables

ERDDAP grid dap data has this concept of dimenions vs. variables. Dimensions are things like time, latitude, longitude, altitude, and depth. Whereas variables are the measured variables, e.g., temperature, salinity, air.

You can't separately adjust values for dimensions for different variables. So, here's how it's gonna work:

Pass in lower and upper limits you want for each dimension as a vector (e.g., c(1,2)), or leave to defaults (i.e., don't pass anything to a dimension). Then pick which variables you want returned via the fields parameter. If you don't pass in options to the fields parameter, you get all variables back.

To get the dimensions and variables, along with other metadata for a dataset, run info, and each will be shown, with their min and max values, and some other metadata.

Where does the data go?

You can choose where data is stored. Be careful though. You can easily get a single file of hundreds of MB's (upper limit: 2 GB) in size with a single request. To the store parameter, pass memory if you want to store the data in memory (saved as a data.frame), or pass disk if you want to store on disk in a file. Note that memory and disk are not character strings, but function calls. memory does not accept any inputs, while disk does. Possibly will add other options, like sql for storing in a SQL database.

Details

Details:

References

http://upwell.pfeg.noaa.gov/erddap/rest.html

Examples

Run this code
# single variable dataset
## You can pass in the outpu of a call to info
(out <- info('noaa_esrl_027d_0fb5_5d38'))
(res <- griddap(out,
 time = c('2012-01-01','2012-06-12'),
 latitude = c(21, 18),
 longitude = c(-80, -75)
))
## Or, pass in a dataset id
(res <- griddap('noaa_esrl_027d_0fb5_5d38',
 time = c('2012-01-01','2012-06-12'),
 latitude = c(21, 18),
 longitude = c(-80, -75)
))

# multi-variable dataset
(out <- info('noaa_gfdl_5081_7d4a_7570'))
(res <- griddap(out,
 time = c('2005-11-01','2006-01-01'),
 latitude = c(20, 21),
 longitude = c(10, 11),
 read = FALSE
))
(res <- griddap(out, time = c('2005-11-01','2006-01-01'), latitude = c(20, 21),
   longitude = c(10, 11), fields = 'uo'))
(res <- griddap(out, time = c('2005-11-01','2006-01-01'), latitude = c(20, 21),
   longitude = c(10, 11), fields = 'uo', stride = c(1,2,1,2)))
(res <- griddap(out, time = c('2005-11-01','2006-01-01'), latitude = c(20, 21),
   longitude = c(10, 11), fields = c('uo','so')))

# multi-variable dataset
(out <- info('noaa_gfdl_3c96_7879_a9d3'))
(res <- griddap(out,
 time = c('2005-11-01','2005-11-10'),
 latitude = c(20, 21),
 longitude = c(2, 3)
))

# Write to memory (within R), or to disk
(out <- info('erdQSwindmday'))
## disk, by default (to prevent bogging down system w/ large datasets)
## you can also pass in path and overwrite options to disk()
(res <- griddap(out,
 time = c('2006-07-11','2006-07-20'),
 longitude = c(166, 170),
 store = disk()
))
## the 2nd call is much faster as it's mostly just the time of reading in the table from disk
system.time( griddap(out,
 time = c('2006-07-11','2006-07-15'),
 longitude = c(10, 15),
 store = disk()
) )
system.time( griddap(out,
 time = c('2006-07-11','2006-07-15'),
 longitude = c(10, 15),
 store = disk()
) )

## memory
(res <- griddap("noaa_gfdl_3c96_7879_a9d3",
 time = c('2005-11-01','2005-11-10'),
 latitude = c(20, 21),
 longitude = c(4, 5),
 store = memory()
))

## Use ncdf4 package to parse data
info("hawaii_463b_5b04_35b7")
(res <- griddap("hawaii_463b_5b04_35b7",
 time = c('2015-01-01','2015-01-03'),
 latitude = c(14, 15),
 longitude = c(75, 76),
 ncdf = "ncdf4"
))

# Get data in csv format
## by default, we get netcdf format data
(res <- griddap('noaa_gfdl_5081_7d4a_7570',
 time = c('2005-11-01','2005-11-06'),
 latitude = c(20, 21),
 longitude = c(10, 11),
 fmt = "csv"
))

# Use a different ERDDAP server url
## NOAA IOOS PacIOOS
url = "http://oos.soest.hawaii.edu/erddap/"
out <- info("NOAA_DHW", url = url)
(res <- griddap(out,
 time = c('2005-11-01','2006-01-01'),
 latitude = c(21, 20),
 longitude = c(10, 11)
))
## pass directly into griddap()
griddap("NOAA_DHW", url = url,
 time = c('2005-11-01','2006-01-01'),
 latitude = c(21, 20),
 longitude = c(10, 11)
)

# You don't have to pass in all of the dimensions
## They do have to be named!
griddap(out, time = c('2005-11-01','2005-11-03'))

# Using 'last'
## with time
griddap('noaa_gfdl_5081_7d4a_7570',
 time = c('last-5','last'),
 latitude = c(21, 18),
 longitude = c(3, 5)
)
## with latitude
griddap('noaa_gfdl_5081_7d4a_7570',
  time = c('2008-01-01','2009-01-01'),
  latitude = c('last', 'last'),
  longitude = c(3, 5)
)
## with longitude
griddap('noaa_gfdl_5081_7d4a_7570',
 time = c('2008-01-01','2009-01-01'),
 latitude = c(21, 18),
 longitude = c('last', 'last')
)

Run the code above in your browser using DataLab