compile_trees: Compile tree data

View source: R/compile_trees.R

compile_treesR Documentation

Compile tree data

Description

Compute tree level attributes using optional and custom functions, e.g., ba, volume, Lorey's height

Usage

compile_trees(
  df_tree,
  tree_nms = c(tree_ids = "tree", dbh = "DIA", ht = "HT", spp = "SPCD", nstems =
    "nstems", acres = "acres", dbcl = "dbcl"),
  fns_compute = list(tpa, ba_ft, dbcl, dbcl_y, spp_y, dbcl_spp_y),
  do_debug = F,
  ...
)

ba_ft(x, tree_nms, ...)

tpa(x, tree_nms, ...)

tph(x, tree_nms, ...)

dbcl(x, tree_nms, db_breaks = c(seq(0, 32, 4), 50, 1000), ...)

dbcl_y(x, tree_nms, vars_group, ...)

spp_y(x, tree_nms, vars_group, ...)

dbcl_spp_y(x, tree_nms, vars_group, ...)

Arguments

df_tree

data frame of tree records

tree_nms

map expected tree column names onto df_tree. These are the minimum expected names: c( tree_ids = "tr_id", dbh = "DBH" , ht = "Ht" , spp = "spcd" ). Feel free to provide others used by custom functions.

fns_compute

sequential list of functions to apply to tree data, earlier results (e.g. ba) are available to later functions. Every function should accept an elipsis.

...

arguments to functions in fns_compute

db_breaks

<...> argument passed to optional dbcl_y function, passed generically by compile_trees through '...'

vars_group

<...> argument passed to optional dbcl_y, dbcl_spp_y, spp_y functions, passed generically by compile_trees through '...'

Details

Accepts a list of trees and a series of functions (some provided) and additively applies the functions to the tree list. Something like spp_y(dbcl_y(dbcl(ba_ft(tpa(treeList))))) ... A number of functions are provided - feel free to modify or update them to meet your needs

ba_ft(x, tree_nms, ...)

tpa(x, tree_nms, ...)

tph(x, tree_nms, ...)

dbcl(x, tree_nms, db_breaks = c(seq(0, 32, 4), 50, 1000), ...)

dbcl_y(x, tree_nms, vars_group, ...)

spp_y(x, tree_nms, vars_group, ...)

dbcl_spp_y(x, tree_nms, vars_group, ...)

This program is free software but it is provided WITHOUT WARRANTY and with ABSOLUTELY NO GUARANTEE of fitness or functionality for any purpose; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.


Revision History

1.0 6/10/2020 Created
1.1 10/09/2024 updated to be consistent with compile_plots

Value

typically an updated df_tree data.frame (compile_trees function argument) with additional columns. This behavior can be broken using fns_compute functions that behave improperly or have "features" to meet specific user objectives.

Author(s)

Jacob Strunk <jacob@somewhere.something>

See Also

dcast
melt
compile_plots

Examples


   #generate data
      test0 = data.frame(plot=1:10, id=1:50,dbh=1:50,spp=sample(letters[1:5],50,T),acres=0.1,ntrees=1)
      test0$ht = abs(75*test0$dbh/12 + rnorm(nrow(test0))*3)

    #compile trees : processes A and B are equivalent
     #A
      test1 = ba_ft(test0,tree_nms=c(tree_ids="id",dbh="dbh",dbcl="dbcl",spp="spp"))
      test2 = dbcl(test1,tree_nms=c(tree_ids="id",dbh="dbh",dbcl="dbcl",spp="spp") )
      test3 = dbcl_y(test2,tree_nms=c(tree_ids="id",dbh="dbh",dbcl="dbcl"), vars_group= c("ba_ft","dbh"))
      test4 = spp_y(test3,tree_nms=c(tree_ids="id",dbh="dbh",dbcl="dbcl",spp="spp"), vars_group= c("ba_ft"))

    #B
    test5 =
      compile_trees(
        #
        test0
        ,tree_nms = c(tree_ids="id",dbh="dbh",dbcl="dbcl",spp="spp",acres="acres")
        ,vars_group = c("ba_ft")
        #optional functions to run against tree data must accept elipsis argument: "..."
        ,fns_compute =
          list(
            tpa
            ,ba_ft
            ,dbcl
            ,dbcl_y
            ,spp_y
            ,dbcl_spp_y
          )

      )

  test5

  #compile plots
  res_pl =   compile_plots(
    df_tree = test5
    , tree_nms = list(plot_ids = c("plot") , tr_ids = c("id") , dbh = "dbh" , ht = "ht" , spp = "spp" , expansion = "TPA" )
    , plot_nms = list( plot_ids = c( "plot" ), plt_wt = NA )
    , dir_out= file.path("c:/temp/RSForInvt/Compile",format(Sys.Date()))
    , fns_compute = list(
      plot_lor_qmd
       ,plot_wtsum
    )
    ,return = T
    ,do_debug = F
    ,nclus = 1
    #arguments to custom functions - in this case plot_wtsum
    ,sum_nms = c("ntrees",grep("^ba",names(test5),value=T))
    ,append = F

  )




jstrunk001/RForInvt documentation built on April 17, 2025, 5:02 p.m.