whichLayers: Select Layers

View source: R/whichLayers.R

whichLayersR Documentation

Select Layers

Description

Uses Layer metadata to return all Layers with a particular properties. For example only tree Layers, or only evergreen Layers.

Usage

whichLayers(x, criteria, return.ids = TRUE)

Arguments

x

Either a Field, or a list of Layer objects

criteria

A character string to use to select Layers. This compared to every the value of every slot of a Layer object. If one matches, the Layer is inlucded in the return.

return.ids

A logical, if TRUE (default) then return the the id of the Layers, if FALSE return the entire Layer objects

Value

Either a vector of characters (the ids of the Layers) or a list of Layer object (depending on argument return.ids)

Author(s)

Matthew Forrest matthew.forrest@senckenberg.de

Examples


## List Layers from a list of Layer objects

# make a list of Layers for selecting from 
layer.list <- GUESS@predefined.layers
print(layer.list)


# return Tree, Grass, Evergreen and Tropical PFTs
whichLayers(layer.list, criteria = "Tree")
whichLayers(layer.list, criteria = "Grass")
whichLayers(layer.list, criteria = "Evergreen")
whichLayers(layer.list, criteria = "Tropical")

# return Tropical PFTs as a list of Layers objects (not just the ids)
whichLayers(layer.list, criteria = "Tropical", return.ids = FALSE)


 
## List Layers from a Field object

# Load a multi-Layer (one layer per-PFT) Field from the example data
run.dir <- system.file("extdata", "LPJ-GUESS_Runs", "CentralEurope", package = "DGVMTools")
test.Source <- defineSource(id = "LPJ-GUESS_Example", dir = run.dir,  format = GUESS)
test.Field.perLayer <- getField(source = test.Source, quant = "lai") 

# Perform the same examples as above but with the Field instead of a list of Layers objects


# return Tree, Grass, Evergreen and Tropical Layers
whichLayers(test.Field.perLayer, criteria = "Tree")
whichLayers(test.Field.perLayer, criteria = "Grass")
whichLayers(test.Field.perLayer, criteria = "Evergreen")
whichLayers(test.Field.perLayer, criteria = "Tropical")

# return Tropical PFTs as a list of Layers objects (not just the ids)
whichLayers(test.Field.perLayer, criteria = "Tropical", return.ids = FALSE)




MagicForrest/DGVMTools documentation built on Aug. 23, 2024, 8:05 a.m.