Learn R Programming

rNOMADS (version 1.2.0)

GribGrab: Download model data from the NOMADS server.

Description

This function interfaces with the programming API at http://nomads.ncep.noaa.gov/ to download NOMADS model data. The available models (54 in total) can be viewed by calling NOMADSList without arguments. The data arrives in grib (gridded binary) format that can be read with ReadGrib.

Usage

GribGrab(model.url, pred, levels, variables, 
    local.dir = ".", file.name = "fcst.grb",
    model.domain = NULL, tidy = FALSE, verbose = TRUE)

Arguments

model.url
The address of a model download page, probably from CrawlModels.
pred
The list of predictions (or model times) determined by the specific model from model.url
variables
A list of model variables to download.
levels
A list of model levels to download.
local.dir
Where to save the grib file, defaults to the current directory.
file.name
What to name the grib file, defaults to "fcst.grb".
model.domain
A vector of latitudes and longitudes that specify the area to return a forecast for. This is a rectangle with elements: west longitude, east longitude, north latitude, south latitude.
tidy
If TRUE, remove all files with the suffix ".grb" from local.dir prior to downloading a new grib file.
verbose
If TRUE, give information on connection status. Default TRUE

Value

  • file.namethe name of the grib file that was downloaded.

References

http://nomads.ncep.noaa.gov/

See Also

CrawlModels, ParseModelPage, ReadGrib

Examples

Run this code
#An example for the Global Forecast System 0.5 degree model

#Get the latest model url
urls.out <- CrawlModels(abbrev = "gfs0.5", 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
file.name <- GribGrab(urls.out[1], my.pred, levels, variables)

#Extract the data
model.data <- ReadGrib(file.name, levels, variables)

#Reformat it
model.grid <- ModelGrid(model.data)

#Show an image of world temperature at ground level
image(model.grid$z[2, 1,,])

Run the code above in your browser using DataLab