Get attribute values from the nodes that are decomposing a node (e.g. the growing units decomposing an axis).

decompose(
  attribute,
  node = NULL,
  decomp_type = c("symbol", "scale"),
  scale = NULL,
  symbol = NULL,
  link = NULL,
  filter_fun = NULL
)

Arguments

attribute

Any node attribute (as a character)

node

The MTG node

decomp_type

Match the node scale or symbol for decomposition ? If symbol, the function will return all descendants until matching the same symbol than the node, if scale it will do the same until matching the same scale.

scale

An integer vector for filtering the .scale of the decomposing nodes (i.e. the SCALE column from the MTG classes).

symbol

A character vector for filtering the decomposing nodes by the name of their .symbol (i.e. the SYMBOL column from the MTG classes).

link

A character vector for filtering the .link with the descendant.

filter_fun

Any filtering function taking a node as input.

Value

The attribute values from the nodes decomposing the input node

Details

This function is mainly used to summarize attributes at a higher scale when they were measured at a lower scale. For example we can think of an mtg where the length was measured at the internode scale only, so this function can be used to summarize it at e.g. axis scale. The filters are used to get the nodes of interest only. For example an axis can be made of internodes and leaves, but the length of an axis is made from the cumulative length of the internodes only (not the leaves). A second example would be to summarize the total leaf area per axis, where we would only want to use the area of the leaves (not the internodes).

Note

This function is mainly intended to be used with mutate_mtg(). In this case, the node argument can be left empty (or you can put node = node equivalently).

Examples

filepath= system.file("extdata", "simple_plant_3.mtg", package = "XploRer") MTG = read_mtg(filepath)
#> Warning: the condition has length > 1 and only the first element will be used
#> Warning: the condition has length > 1 and only the first element will be used
#> Warning: the condition has length > 1 and only the first element will be used
#> Warning: the condition has length > 1 and only the first element will be used
decompose(".symbol", node = extract_node(MTG,"node_3"), decomp_type = "symbol")
#> node_4 node_5 node_9 #> "Internode" "Leaf" "Internode"
# using filters to remove nodes that we don't need: decompose(".symbol", node = extract_node(MTG,"node_3"), symbol = "Internode", decomp_type = "symbol")
#> node_4 node_9 #> "Internode" "Internode"
# We can check the function worked properly by printing the symbols of each nodes: print(MTG, ".symbol")
#> levelName .symbol #> 1 node_1 Scene #> 2 °--node_2 Individual #> 3 °--node_3 Axis #> 4 °--node_4 Internode #> 5 ¦--node_5 Leaf #> 6 ¦--node_6 Axis #> 7 ¦ °--node_7 Internode #> 8 ¦ °--node_8 Leaf #> 9 °--node_9 Internode #> 10 °--node_10 Axis #> 11 °--node_11 Internode #> 12 °--node_12 Leaf