This function creates an operator for extracting a selection of grid cells identified by a latitude and longitude bounding box. The result is a logical vector with TRUE values in the indices corresponding to grid cells inside the bounding box.

extract_box(lat, lon, griddata)

Arguments

lat

A vector of length 2 giving the minimum and maximum latitude for the bounding box.

lon

A vector of length 2 giving the minimum and maximum longitude for the bounding box.

griddata

A griddata structure, which contains the latitude and longitude coordinates.

Value

Logical vector indicating which grid cells are in the bounding box.

Details

This operator can be used as an index to extract the desired grid cells, for example:

mask <- extract_box; fld_subset <- fld[ ,mask].

It can also be used to calculate averages over a specified area:

meantemp <- fld %*% as.numeric(mask).

Or, you could use it to mask out grid cells that are not in the region of interest:

fld[ ,!mask] <- NA