Learn R Programming

rNOMADS (version 1.0.0)

ModelGrid: Transform model data into an array

Description

This function takes output from ReadGrib and produces an array with dimensions: levels x variables x longitudes x latitudes. This greatly reduces the size of the data set as well as makes it easier to manipulate.

Usage

ModelGrid(model.data, lon.grid, lat.grid, 
    variables = NULL, levels = NULL, model.domain = NULL)

Arguments

model.data
Output from ReadGrib.
lon.grid
The spacing of the longitude grid.
lat.grid
The spacing of the latitude grid.
variables
The model variables to include in the grid, if NULL, include all of them.
levels
The model levels to include in grid, if NULL, include all of them.
model.domain
A vector c(LEFT LON, RIGHT LON, TOP LAT, BOTTOM LAT) of the region to include in output. If NULL, include everything.

Value

  • zAn array of dimensions levels x variables x lon x lat; each level x variable contains the model grid of data from that variable and level
  • xVector of longitudes
  • yVector of latitudes
  • variablesThe variables contained in the grid
  • levelsThe levels contained in the grid
  • model.run.dateWhen the forecast model was run
  • fcst.dateThe date of the forecast

Details

If you set the spacing of lon.grid and/or lat.grid coarser than the downloaded model grid, you can reduce the resolution of your model, possibly making it easier to handle.

See Also

ReadGrib

Examples

Run this code
#Get some model data outputted by ReadGrib
#This data is from late July and covers the state of North Carolina and nearby regions
data(GFS)

#Make it into an array
gfs.array <- ModelGrid(gfs.model.data, 0.5, 0.5)

#What variables and levels we have
print(gfs.array$levels)
print(gfs.array$variables)

#Find minimum temperature at the ground surface, and where it is
min.temp <- min(gfs.array$z[2, 1,,] - 273.15)
sprintf("%.1f", min.temp) #in Celsius 

ti <- which(gfs.array$z[2, 1,,] == min.temp + 273.15, arr.ind = TRUE)

#Turns out two locations get the minimum temperature prize.
#One of them is near Cumberland, Kentucky.
lat <- gfs.array$y[ti[1,2]]
lon <- gfs.array$x[ti[1,1]]

#Find maximum relative humidity at ground level
max.rh <- max(gfs.array$z[2, 2,,])
sprintf("%.1f", max.rh) 

#Find maximum temperature at 100 mb atmospheric pressure
max.temp <- max(gfs.array$z[1, 1,,]) - 273.15
sprintf("%.1f", max.temp) #Brrr!

Run the code above in your browser using DataLab