grib_select: Select multiple GRIB messages

View source: R/grib_select.R

grib_selectR Documentation

Select multiple GRIB messages

Description

grib_select selects all GRIB messages that match key/value pairs input by the user.

Usage

grib_select(gribObj, keyPairs)

Arguments

gribObj

GRIB class object.

keyPairs

a named list of key/value pairs that will be used to search through and match messages in the GRIB file using an index.

Details

grib_select is a function more robust than grib_get_message in that it can search through a GRIB file and get all matching messages given key(s)/value(s) pairs. This is achieved by making an index of the input GRIB file and then selecting keys that match user input in keyPairs. The values returned in the GRIB message are masked if they are coded as a missing value or the bitmap, if present, masks them.

All grid (latitude, longitude, values, etc.) are output as vectors for simplicity and flexibility. Many plotting functions want input in matrix form (e.g., image(), fields::image.plot() while others want input in long form data.frames or vectors (e.g., ggplot). Keeping vector form allows the most flexibility for the user to do what is needed to format the data appropriately. Some helper functions in this package will do some data formatting for you.

grib_select is meant as an easy way to grab the data you want. However, it can suffer from performance issues due to the overhead of searching through the GRIB file. If speed is important, knowing the message number in the file and using grib_get_message is the way to go.

Value

Returns a gribMessage or a list of gribMessage objects if more than one message is selected.

See Also

grib_get_message grib_list grib_expand_grids grib_latlons

Examples

g <- grib_open(system.file("extdata", "lfpw.grib1", package = "gribr"))
# select all mixing ratio messages
gm1 <- grib_select(g, list(shortName = "q"))
# select mixing ratio, but only at 1000 and 850 hPa
gm2 <- grib_select(g, list(shortName = "q", level = c(1000, 850)))
grib_close(g)

nawendt/rGRIB documentation built on Oct. 24, 2023, 6:21 a.m.