Skip to content

Commit f47b7de

Browse files
committed
calc_tcc_metrics(): example and tests
1 parent 1483837 commit f47b7de

4 files changed

Lines changed: 62 additions & 18 deletions

File tree

R/calc_tcc_metrics.R

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
#' estimate. These additional variables include:
3535
#'
3636
#' * individual subplot and microplot crown overlays via `calc_crown_overlay()`
37-
#' * a stand height metric (`meanTreeHtBAW`) via `calc_ht_metrics()`
38-
#' * plot-level counts of mature trees and saplings
37+
#' * a stand height metric (`meanTreeHtBAW`) and plot-level counts of mature
38+
#' trees and saplings via `calc_ht_metrics()`
3939
#' * descriptive spatial statistics for the overstory tree point pattern via
4040
#' `create_fia_ppp() |> spatstat.explore::Lest()`
4141
#'
@@ -82,8 +82,8 @@
8282
#' Statistical Society: Series B (Methodological)_, 39(2): 172–192.
8383
#' \url{https://doi.org/10.1111/j.2517-6161.1977.tb01615.x}.
8484
#'
85-
#' Stoyan, D., and Penttinen, A. (2000). Recent Applications of Point Process
86-
#' Methods in Forestry Statistics. _Statistical Science_, 15(1), 61–78.
85+
#' Stoyan, D., and Penttinen, A. (2000). Recent applications of point process
86+
#' methods in forestry statistics. _Statistical Science_, 15(1), 61–78.
8787
#' \url{http://www.jstor.org/stable/2676677}.
8888
#'
8989
#' Toney, C., J.D. Shaw and M.D. Nelson. 2009. A stem-map model for predicting
@@ -98,6 +98,8 @@
9898
#' [calc_crwidth()], [calc_crown_overlay()], [calc_ht_metrics()],
9999
#' [create_fia_ppp()]
100100
#'
101+
#' @examples
102+
#' calc_tcc_metrics(plantation)
101103
calc_tcc_metrics <- function(tree_list, stem_map = TRUE, full_output = TRUE,
102104
digits = 1) {
103105

@@ -131,7 +133,8 @@ calc_tcc_metrics <- function(tree_list, stem_map = TRUE, full_output = TRUE,
131133

132134
model_tcc <- NA_real_
133135
if (stem_map) {
134-
# implement the stem-map canopy cover model from Toney et al. (2009)
136+
# "stem-map" canopy cover model (Toney et al. 2009)
137+
135138
# subplot and microplot crown overlays
136139
subp_overlay <- rep(NA_real_, 4)
137140
micr_overlay <- rep(NA_real_, 4)
@@ -176,21 +179,23 @@ calc_tcc_metrics <- function(tree_list, stem_map = TRUE, full_output = TRUE,
176179
model_tcc <- subp_overlay_tcc + micr_overlay_tcc
177180
}
178181
else {
179-
# apply an adjustment to plot-level canopy cover based on crown
180-
# overlay to account for the sapling contribution
181-
182-
# estimated by linear regression using RMRS FIA line-intercept
183-
# data for all single-condition DESGNCD == 1 plots through 2005
184-
# with subp_overlay_tcc >= 10 (FORTYPCDs 925 and 926 omitted)
182+
# apply an adjustment to the plot-level canopy cover derived
183+
# from crown overlay to account for the sapling contribution
184+
185+
# linear regression model based on RMRS FIA line-intercept
186+
# field measurements for all single-condition DESIGNCD 1 plots
187+
# through 2005 that had subp_overlay_tcc >= 10 (FORTYPCDs 925
188+
# and 926 omitted)
189+
# Toney et al. (2009) Table 2
185190
sapling_component <-
186191
-8.036 +
187192
0.211 * micr_overlay_tcc +
188193
0.552 * ht_metrics$numSaplings +
189-
4.367 * log(ht_metrics$meanTreeHtBAW) +
190194
-0.131 * ht_metrics$numTrees +
195+
4.367 * log(ht_metrics$meanTreeHtBAW) +
191196
0.222 * L_mean
192197

193-
# do not allow negative sapling adjustment
198+
# constrain sapling adjustment >= 0
194199
sapling_component <- max(c(sapling_component, 0))
195200

196201
model_tcc <-
@@ -200,7 +205,9 @@ calc_tcc_metrics <- function(tree_list, stem_map = TRUE, full_output = TRUE,
200205
}
201206

202207
} else {
203-
# "FVS method" for percent canopy cover, assuming random tree locations
208+
# "FVS method" for tree canopy cover (Crookston and Stage 1999)
209+
# assumes random tree locations
210+
204211
if (!("TPA_UNADJ" %in% colnames(tree_list))) {
205212
stop("'TPA_UNADJ' is a required column in 'tree_list'",
206213
call. = FALSE)

man/calc_tcc_metrics.Rd

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
test_that("calc_tcc_metrics works", {
2+
# one sapling in each microplot
3+
# each sapling crown has half the area of the microplot
4+
subp <- c(1, 2, 3, 4)
5+
tree <- rep(1, 4)
6+
azimuth <- c(0, 90, 180, 270)
7+
dist <- c(1, -1, 1, -1)
8+
statuscd <- rep(1, 4)
9+
spcd <- rep(131, 4)
10+
dia <- rep(4.9, 4)
11+
ht <- rep(47, 4)
12+
actualht <- rep(47, 4)
13+
cclcd <- rep(5, 4)
14+
tpa_unadj <- rep(74.96528, 4)
15+
crwidth <- rep(9.616652, 4)
16+
tree_list <- data.frame(SUBP = subp, TREE = tree, AZIMUTH = azimuth,
17+
DIST = dist, STATUSCD = statuscd, SPCD = spcd,
18+
DIA = dia, HT = ht, ACTUALHT = actualht,
19+
CCLCD = cclcd, TPA_UNADJ = tpa_unadj,
20+
CRWIDTH = crwidth)
21+
22+
# stem-map method
23+
tcc_pred <- calc_tcc_metrics(tree_list, full_output = FALSE)
24+
expect_equal(tcc_pred, 50, tolerance = 0.1)
25+
26+
# FVS method
27+
tcc_pred <- calc_tcc_metrics(tree_list, stem_map = FALSE,
28+
full_output = FALSE)
29+
expect_equal(tcc_pred, 39.3, tolerance = 0.1)
30+
})

tests/testthat/test-crown_overlay_pct.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ test_that("calc_crown_overlay works", {
55
as.data.frame()
66
colnames(trees) <- c("AZIMUTH", "DIST", "CRWIDTH")
77
expect_equal(calc_crown_overlay(trees, 24, 0), 20)
8+
9+
# one tree with half the area of a subplot
10+
tree_list <- data.frame(DIST = 1, AZIMUTH = 0, CRWIDTH = 33.94113)
11+
expect_equal(calc_crown_overlay(tree_list, 24), 50, tolerance = 0.1)
812
})

0 commit comments

Comments
 (0)