Function to extract a subset of the full data in an LPJmLData object by applying selections along one or several of its dimensions.

# S3 method for LPJmLData
subset(x, ...)

Arguments

x

An LPJmLData object

...

One or several key-value combinations where keys represent the dimension names and values represent the requested elements along these dimensions. Subsets may either specify integer indices, e.g. cell = c(27411:27416), band = -c(14:16, 19:32), or character vectors if the dimension has a dimnames attribute, e.g. band = c("rainfed rice", "rainfed maize").\ Coordinate pairs of individual cells can be selected by providing a list or tibble in the form of coords = list(lon = ..., lat =...). Coordinate values need to be supplied as character vectors. The argument can also be called coordinates. When coordinates are supplied as character vectors to subset either along the lon or lat dimension or to subset by coordinate pair, the function matches the grid cells closest to the supplied coordinate value.

Value

An LPJmLData object with dimensions resulting from the selection in subset. Meta data are updated as well.

Examples

if (FALSE) {

vegc <- read_io(filename = "./vegc.bin.json")

# Subset cells by index
subset(vegc, cell = seq(27410, 27415))
# [...]
# $data |>
#   dimnames() |>
#     .$cell  "27409" "27410" "27411" "27412" "27413" "27414"
#     .$time  "1901-12-31" "1902-12-31" "1903-12-31" "1904-12-31" ...
#     .$band  "1"
# [...]

# Subset time by character vector
subset(vegc, time = c("2001-12-31", "2002-12-31", "2003-12-31"))
# [...]
# $data |>
#   dimnames() |>
#     .$cell  "0" "1" "2" "3" ... "67419"
#     .$time  "2001-12-31" "2002-12-31" "2003-12-31"
#     .$band  "1"
# [...]
}