Skip to content

Commit 2811b45

Browse files
committed
add calc_landfire_stand_ht()
1 parent 48f1460 commit 2811b45

5 files changed

Lines changed: 146 additions & 8 deletions

File tree

‎NAMESPACE‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export(ac_to_ha)
77
export(calc_crown_overlay)
88
export(calc_crwidth)
99
export(calc_ht_metrics)
10+
export(calc_landfire_stand_ht)
1011
export(calc_tcc_metrics)
1112
export(cm_to_in)
1213
export(create_fia_owin)

‎R/calc_ht_metrics.R‎

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
#' Calculate stand height metrics from tree list data
22
#'
3+
#' These functions compute several stand height metrics from tree list data.
4+
#'
5+
#' @name calc_ht_metrics
6+
#' @details
7+
#'
38
#' `calc_ht_metrics()` computes several stand height metrics for a given tree
49
#' list.
510
#'
6-
#' @details
11+
#' `calc_landfire_stand_ht()` computes LANDFIRE stand height. This metric is
12+
#' computed separately since it depends on canopy cover estimates for the
13+
#' sapling and overstory layers derived overlaying modeled crowns.
14+
#'
715
#' Stand height metrics are based on live trees (`STATUSCD == 1`), and are
8-
#' are assigned `0` by definition if no live trees are present. Height metrics
9-
#' are returned in a named list with the following elements:
16+
#' are assigned `0` by definition if no live trees are present.
17+
#' `calc_ht_metrics()`returns a named list with the following elements:
1018
#' * `$numTrees`: number of live trees `>= 5.0` in. (`12.7` cm) diameter
1119
#' * `$meanTreeHt`: mean height of trees `>= 5.0` in. (`12.7` cm) diameter
1220
#' * `$meanTreeHtBAW`: basal-area weighted mean height of trees `>= 5.0` in.
@@ -30,6 +38,19 @@
3038
#' (co-dominant), but exclude trees with `CCLCD` of `4` (intermediate) or `5`
3139
#' (over-topped).
3240
#'
41+
#' LANDFIRE stand height is a metric computed for FIA plots used as reference
42+
#' data supporting development of the Existing Vegetation Height (EVH) raster
43+
#' product (\url{https://www.landfire.gov/vegetation/evh}). It is generally the
44+
#' basal-area weighted mean height of canopy dominant/co-dominant trees (i.e.,
45+
#' `meanTreeHtDomBAW`). However, this metric attempts to identify plots that may
46+
#' be best characterized as sapling stage, in which case stand height is the
47+
#' mean height of saplings (`meanSapHt`). Sapling-stage plots are defined using
48+
#' arbitrary thresholds of canopy cover, estimated separately for the sapling
49+
#' layer based on microplot data, and the overstory tree layer based on subplot
50+
#' measurements. See `calc_tcc_metrics()` for variable definitions. A plot is
51+
#' considered sapling stage if `subp_overlay_mean <= 10` and
52+
#' `micr_overlay_mean >= 3 * subp_overlay_mean`.
53+
#'
3354
#' @param tree_list A data frame with tree records for one FIA plot. Must have
3455
#' columns `DIA` (tree diameter), `HT` (tree height), `ACTUALHT` (tree actual
3556
#' height, `ACTUALHT < HT` indicating a broken top), `CCLCD` (FIA crown class
@@ -141,3 +162,43 @@ calc_ht_metrics <- function(tree_list, digits = 1) {
141162

142163
return(ht_metrics)
143164
}
165+
166+
#' @name calc_ht_metrics
167+
#' @export
168+
calc_landfire_stand_ht <- function(subp_overlay_mean, micr_overlay_mean,
169+
numTrees, meanTreeHtDomBAW, meanTreeHtBAW,
170+
meanSapHt) {
171+
172+
if (!(is.numeric(subp_overlay_mean) && is.numeric(micr_overlay_mean) &&
173+
is.numeric(numTrees) && is.numeric(meanTreeHtDomBAW) &&
174+
is.numeric(meanTreeHtBAW) && is.numeric(meanSapHt))) {
175+
176+
stop("all arguments are required and must be numeric vectors",
177+
call. = FALSE)
178+
}
179+
180+
input_vectors <- list(subp_overlay_mean, micr_overlay_mean, numTrees,
181+
meanTreeHtDomBAW, meanTreeHtBAW, meanSapHt)
182+
if (length(unique(sapply(input_vectors, length))) != 1) {
183+
stop("all inputs must have the same length", call. = FALSE)
184+
}
185+
186+
standHt <- rep(NA_real_, length(subp_overlay_mean))
187+
188+
for (i in seq_along(standHt)) {
189+
if (numTrees[i] > 0) {
190+
if (subp_overlay_mean[i] <= 10 &&
191+
micr_overlay_mean[i] >= 3 * subp_overlay_mean[i]) {
192+
standHt[i] = meanSapHt[i]
193+
} else if (meanTreeHtDomBAW[i] > meanTreeHtBAW[i]) {
194+
standHt[i] = meanTreeHtDomBAW[i]
195+
} else {
196+
standHt[i] = meanTreeHtBAW[i]
197+
}
198+
} else {
199+
standHt[i] = meanSapHt[i]
200+
}
201+
}
202+
203+
return(standHt)
204+
}

‎inst/extdata/test-tree_data.csv‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,24 @@ PLT_CN,SUBP,TREE,AZIMUTH,DIST,STATUSCD,SPCD,SPGRPCD,DIA,HT,ACTUALHT,CCLCD,TPA_UN
143143
3,4,14,291,6.2,1,6748,55,2.5,20,20,5,74.965282
144144
3,4,15,291,6.2,1,6748,55,1.8,18,18,5,74.965282
145145
3,4,16,353,6.3,1,313,41,3.1,25,25,5,74.965282
146+
4,3,19,33,5.4,1,935,43,1.7,20,20,5,74.965282
147+
4,3,18,30,5.5,1,935,43,1.5,21,21,4,74.965282
148+
4,3,21,155,2.5,1,375,41,1.8,23,23,4,74.965282
149+
4,3,22,160,5.3,1,371,30,2.7,25,25,3,74.965282
150+
4,3,23,178,5.9,1,761,43,2,20,20,4,74.965282
151+
4,3,24,220,5.8,1,375,41,1.6,25,25,4,74.965282
152+
4,3,25,246,5.7,1,761,43,1.9,24,24,3,74.965282
153+
4,3,26,260,5.8,1,761,43,1.2,20,20,5,74.965282
154+
4,3,27,13,6.5,1,375,41,1.5,23,23,3,74.965282
155+
4,3,28,50,4.7,1,761,43,1,17,17,5,74.965282
156+
4,3,29,61,4.2,1,371,30,1.4,21,21,4,74.965282
157+
4,3,30,182,6.4,1,371,30,1.7,21,21,5,74.965282
158+
4,3,31,200,2.9,1,375,41,1.1,16,16,5,74.965282
159+
4,3,32,227,5.5,1,375,41,1.1,20,20,5,74.965282
160+
4,3,33,265,1.1,1,761,43,1.5,17,17,3,74.965282
161+
4,3,34,280,5.8,1,371,30,1.2,18,18,5,74.965282
162+
4,3,35,323,2.3,1,12,6,1.3,10,10,5,74.965282
163+
4,4,17,28,22.8,1,12,6,8,30,30,2,6.018046
164+
4,3,16,14,4.5,1,371,30,1.8,20,20,4,74.965282
165+
4,3,17,27,4.1,1,761,43,2.4,22,22,3,74.965282
166+
4,3,20,90,5.7,1,371,30,1.6,24,24,4,74.965282

‎man/calc_ht_metrics.Rd‎

Lines changed: 33 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/testthat/test-calc_ht_metrics.R‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test_that("calc_ht_metrics works", {
1+
test_that("calc_ht_metrics and calc_landfire_stand_ht", {
22
expected <- vector(mode = "list", length = 10)
33
names(expected) <- c("numTrees", "meanTreeHt", "meanTreeHtBAW",
44
"meanTreeHtDom", "meanTreeHtDomBAW", "maxTreeHt",
@@ -16,4 +16,30 @@ test_that("calc_ht_metrics works", {
1616
expected$meanSapHt <- 34.5
1717
expected$maxSapHt <- 43
1818
expect_equal(calc_ht_metrics(plantation), expected, tolerance = 1e-3)
19+
20+
# LANDFIRE stand height
21+
tcc_pred <- calc_tcc_metrics(plantation, digits = 3)
22+
standHt <- calc_landfire_stand_ht(tcc_pred$subp_overlay_mean,
23+
tcc_pred$micr_overlay_mean,
24+
tcc_pred$numTrees,
25+
tcc_pred$meanTreeHtDomBAW,
26+
tcc_pred$meanTreeHtBAW,
27+
tcc_pred$meanSapHt)
28+
expect_equal(standHt, tcc_pred$meanTreeHtDomBAW, tolerance = 1e-3)
29+
30+
# sapling plot
31+
f <- system.file("extdata/test-tree_data.csv", package="FIAstemmap")
32+
tree_tbl <- load_tree_data(f)
33+
34+
tree_list_4 <- tree_tbl[tree_tbl$PLT_CN == "4", ]
35+
expect_equal(nrow(tree_list_4), 21)
36+
expect_no_error(
37+
tcc_pred <- calc_tcc_metrics(tree_list_4, digits = 3))
38+
standHt <- calc_landfire_stand_ht(tcc_pred$subp_overlay_mean,
39+
tcc_pred$micr_overlay_mean,
40+
tcc_pred$numTrees,
41+
tcc_pred$meanTreeHtDomBAW,
42+
tcc_pred$meanTreeHtBAW,
43+
tcc_pred$meanSapHt)
44+
expect_equal(standHt, tcc_pred$meanSapHt, tolerance = 1e-3)
1945
})

0 commit comments

Comments
 (0)