#Get the latest model date
model.date <- Sys.time()
#Get the forecast 6 hours from now - addition is defined in seconds
fcst.date <- model.date + 6 * 3600
#What region of the atmosphere to get data for
#2 meters above the ground and at 800 mb pressure
levels <- c("2 m above ground", "800 mb")
#What data to return
variables <- c("TMP", "RH") #Temperature and relative humidity
#What region of the world to get data for - omit this and you get the whole planet!
model.domain <- c(-84, -74, 37, 32) #Get the area around North Carolina, USA
file.name <- "fcst.grb" #Name of file to save downloaded data to
#Get the data
GribGrab(levels, variables, model.date = model.date,
fcst.date = fcst.date, model.domain = model.domain, file.name = file.name)
#Read the data, only capturing temperature at the 2 m above ground level
model.data <- ReadGrib(file.name, c("TMP"), c("2 m above ground"))
#Make it into an array
model.array <- ModelGrid(model.data, 0.5, 0.5)
#Make a contour plot of the temperature around North Carolina, USA:
contour(x = model.array$x, y = model.array$y, model.array$z[1,1,,] - 273.15,
xlab = "Latitude", ylab = "Longitude",
main = paste("North Carolina Temperatures for",
model.array$fcst.date, "GMT in Celsius"))
Run the code above in your browser using DataLab