ReadGrib | R Documentation |
This function wraps wgrib2
and wgrib
, external grib file readers provided by the National Weather Service Climate Prediction Center (see http://www.cpc.ncep.noaa.gov/products/wesley/wgrib2/ and http://www.cpc.ncep.noaa.gov/products/wesley/wgrib.html).
ReadGrib
extracts forecast data into R.
It does this by building an argument string, executing a system call to the appropriate external grib file reader, and extracting the result.
Note that wgrib2
must be installed for ReadGrib
to work for current grib files, and wgrib
may need to be installed when looking at archived data.
ReadGrib(file.names, levels, variables,
forecasts = NULL, domain = NULL, domain.type = "latlon",
file.type = "grib2", missing.data = NULL)
file.names |
The path and file name of the grib files to read. |
levels |
The levels to extract. |
variables |
The variables to extract. |
forecasts |
Names of forecasts to extract.
If |
domain |
Include model nodes in the specified region: |
domain.type |
Either |
file.type |
Whether the file is in GRIB ( |
missing.data |
Replace missing data in grib archive with this value.
If |
This function constructs system calls to wgrib
and wgrib2
.
Therefore, you must have installed these programs and made it available on the system path.
Unless you are interested in accessing archive data that's more than a few years old, you can install
wgrib2 only.
A description of wgrib2
and installation links are available at http://www.cpc.ncep.noaa.gov/products/wesley/wgrib2/ and http://www.cpc.ncep.noaa.gov/products/wesley/wgrib.html.
Also, rNOMADS is focused towards GRIB2 files; I have included GRIB1 format support as a convenience.
model.data |
A structure with a series of elements containing data extracted from the grib files. |
Daniel C. Bowman danny.c.bowman@gmail.com
Ebisuzaki, W, Bokhorst, R., Hyvatti, J., Jovic, D., Nilssen, K, Pfeiffer, K., Romero, P., Schwarb, M., da Silva, A., Sondell, N., and Varlamov, S. (2011). wgrib2: read and write GRIB2 files. National Weather Service Climate Prediction Center, http://www.cpc.ncep.noaa.gov/products/wesley/wgrib2/
GribGrab
, ArchiveGribGrab
, ModelGrid
#Operational Forecast Data Extraction
#NCEP output is always in GRIB2 format - this makes things easy for us
#An example for the Global Forecast System 0.5 degree model
#Get the latest model url
## Not run:
urls.out <- CrawlModels(abbrev = "gfs_0p50", depth = 1)
#Get a list of forecasts, variables and levels
model.parameters <- ParseModelPage(urls.out[1])
#Figure out which one is the 6 hour forecast
#provided by the latest model run
#(will be the forecast from 6-12 hours from the current date)
my.pred <- model.parameters$pred[grep("06$", model.parameters$pred)]
#What region of the atmosphere to get data for
levels <- c("2 m above ground", "800 mb")
#What data to return
variables <- c("TMP", "RH") #Temperature and relative humidity
#Get the data
model.info <- GribGrab(urls.out[1], my.pred, levels, variables)
#Extract the data
model.data <- ReadGrib(model.info[[1]]$file.name, levels, variables)
#Reformat it
model.grid <- ModelGrid(model.data, c(0.5, 0.5))
#Show an image of world temperature at ground level
image(model.grid$z[2, 1,,])
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.