compilePlots: Compile tree data by plot

View source: R/compilePlots.R

compilePlotsR Documentation

Compile tree data by plot

Description

Supply data.frame of tree data with plot ids and a data.frame of plot records. The function works by iterating through the tree data plot by plot. The compilePlots() function accepts a list of functions which compute attributes. Several example functions are provided, but they are probably not sufficient for operational usage. Hopefully more will be added over time. This function is meant to work hand in hand with compileTrees() but is still a work in progress.

Usage

compilePlots(
  dfTree = data.frame(PLT_CN = 1, year = 2020, dbh = NA, spcd = NA, ac = 0.1),
  dfPlot = list(NA, data.frame(PLT_CN = c(1, 2), PLOT = 1, YEAR = 2020, STATE = 1,
    COUNTY = 1, PROJECT = "Test"))[1],
  dfTreeNms = list(plotIDs = c("PLOT", "YEAR"), trIDs = c("tr_cn"), dbh = "DIA", ht =
    "HT", spcd = "SPCD", trWt = "TPA"),
  dfPlotNms = list(plotIDs = c("STATE", "COUNTY", "PROJECT", "PLOT", "YEAR"), pltWt =
    NA),
  plot_filter = c(NA,
    "select * from dfPlot where YEAR = 2018 and STATE = 'WA' and CONDITION = 1"),
  tree_filter = c(NA, "select * from dfTree where dbh > 2 "),
  dir_out = file.path("c:/temp/RSForInvt/Compile", format(Sys.Date())),
  nm_out = "plot_compile",
  fnCompute = list(plotWtMn, plotWtSum),
  return = F,
  doDebug = F,
  nclus = 4,
  ...
)

plotWtSum(trs, trNms, vSumNm, ...)

plotWtMn(trs, trNms, ...)

sppYplot(trs, trNms, nDomSpp = 3, sppY, ...)

Arguments

dfTree

data frame of tree records

dfPlot

data frame of plot records

dfTreeNms

map expected tree column names onto dfTree. These are the expected names: c( plotIDs = "?", trIDs = c("?","?") , dbh = "?" , ht = "?" , spcd = "?" , trWt = "?"). Feel free to provide others used by custom functions.

dfPlotNms

map expected plot column names onto dfPlot. These are the expected names: c( plotIDs = c("?","?"), pltWt = c(NA,"?")[1] ). Feel free to provide others used by custom functions.

plot_filter

sqldf string to filter out plots

tree_filter

sqldf string to filter out trees

dir_out

where to write results of plot level compilation

fnCompute

list of functions to compute plot level attributes. Functions typically accepting plot level tree list and list of tree / plot names and must return a data.frame. Functions must accept ... argument.

return

return compiled data

doDebug

stop and debug function

nclus

if nclus > 1 then nclus parallel nodes are split off to process in parallel

...

additional arguments provided to fnCompute e.g textString="hello" argument in silly function someFun = function(tl,tlNms,textString)data.frame(note=textString)

Details

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/12/2020 Created

Value

NULL (return=F) or a data.frame of plot attributes (return=T)

Author(s)

Jacob Strunk <Jstrunk@fs.fed.us>

See Also

compileTrees
parLapplyLB

Examples


  #build fake tree list
  set.seed=111
  nfake=50
  dbh_fk = 10*abs(rnorm(nfake))
  df_fake = data.frame(
    pltId = sample((1:7),nfake,replace=T)
    ,trid=1:50
    ,db= dbh_fk
    ,ht=75*dbh_fk + rnorm(nfake)*10
    ,spp = sample(c("df","wh","cw","ra") , nfake , T)
    ,acres = 0.1
    ,trees = round(1+ abs(rnorm(nfake)/3))

  )

  #compute tree level attributes for fake tree list
  testTL =
    compileTrees(
      df_fake
      ,trID = "trid"
      ,sppNm = "spp"
      ,dbNm = "db"
      ,htNm = "ht"
      ,dbclNm = "dbcl"
      ,dbcl = c(seq(0,32,4),50,1000)
      ,dbclY = c("ba_ft")
      ,sppY = c("ba_ft")
      ,sppDbclY = c("ba_ft")
      ,acresNm = "acres"
      ,nTreesNm = NA

      ,fnCompute =
        list(
          tpa
          ,ba_ft
          ,dbcl
          ,dbclY
          ,sppY
          ,dbclSppY
        )
    )

  testTL

  #compute plot level attributes from fake tree list
  res_pl =   compilePlots(

    dfTree = testTL
    ,dfTreeNms = c(plotIDs = c("pltId") , trIDs = c("trid") , dbh = "db" , ht = "ht" , spcd = "spp" , trWt = "TPA" )
    ,dir_out= file.path("c:/temp/RSForInvt/Compile",format(Sys.Date()))
    ,fnCompute = list(
      plotWtMn
      ,plotWtSum
    )

    ,return = T
    ,doDebug = F

    ,nclus = 1

    #' arguments to custom functions - in this case plotWtSum
    ,vSumNm = c("TPA",grep("^ba",names(testTL),value=T))

  )





jstrunk001/RSForInvt documentation built on April 18, 2022, 11:03 p.m.