extract_box: Create an operator to extract grid cells from a field by...

Description Usage Arguments Details Value

View source: R/datamunge.R

Description

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.

Usage

1
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.

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

Value

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


JGCRI/fldgen documentation built on July 18, 2020, 1:42 p.m.