|
19 | 19 | #' equation presented by Gill et al. (2000) to estimate crown width for nine |
20 | 20 | #' tree species when their diameter is greater than 50 in. (127 cm). |
21 | 21 | #' |
22 | | -#' @param tree_list A data frame containing tree records. Must have columns |
| 22 | +#' @param tree_table A data frame containing tree records. Must have columns |
23 | 23 | #' `SPCD` (FIA integer species code), `STATUSCD` (FIA integer tree status code, |
24 | 24 | #' 1 = live) and `DIA` (FIA tree diameter in inches). |
25 | 25 | #' @param digits Optional integer indicating the number of digits to keep in the |
26 | 26 | #' return values (defaults to `1`). |
27 | 27 | #' @return |
28 | | -#' A numeric vector of length `nrow(tree_list)` with predicted crown width in |
| 28 | +#' A numeric vector of length `nrow(tree_table)` with predicted crown width in |
29 | 29 | #' feet for live trees. `NA` is returned for trees with `STATUSCD != 1`. |
30 | 30 | #' |
31 | 31 | #' @references |
|
47 | 47 | #' @examples |
48 | 48 | #' calc_crwidth(plantation) |
49 | 49 | #' @export |
50 | | -calc_crwidth <- function(tree_list, digits = 1) { |
51 | | - if (missing(tree_list) || is.null(tree_list)) |
52 | | - stop("'tree_list' is required", call. = FALSE) |
| 50 | +calc_crwidth <- function(tree_table, digits = 1) { |
| 51 | + if (missing(tree_table) || is.null(tree_table)) |
| 52 | + stop("'tree_table' is required", call. = FALSE) |
53 | 53 |
|
54 | | - if (!is.data.frame(tree_list)) |
55 | | - stop("'tree_list' must be a data frame", call. = FALSE) |
| 54 | + if (!is.data.frame(tree_table)) |
| 55 | + stop("'tree_table' must be a data frame", call. = FALSE) |
56 | 56 |
|
57 | 57 | required_cols <- c("SPCD", "STATUSCD", "DIA") |
58 | | - if (!all(required_cols %in% colnames(tree_list))) |
59 | | - stop("'tree_list' is missing required columns", call. = FALSE) |
| 58 | + if (!all(required_cols %in% colnames(tree_table))) |
| 59 | + stop("'tree_table' is missing required columns", call. = FALSE) |
60 | 60 |
|
61 | | - if (!is.numeric(tree_list$SPCD)) |
62 | | - stop("'tree_list$SPCD' must be numeric or integer", call. = FALSE) |
63 | | - if (any(is.na(tree_list$SPCD))) |
64 | | - stop("'tree_list$SPCD' cannot have missing values", call. = FALSE) |
| 61 | + if (!is.numeric(tree_table$SPCD)) |
| 62 | + stop("'SPCD' must be numeric or integer", call. = FALSE) |
| 63 | + if (any(is.na(tree_table$SPCD))) |
| 64 | + stop("'SPCD' cannot have missing values", call. = FALSE) |
65 | 65 |
|
66 | | - if (!is.numeric(tree_list$STATUSCD)) |
67 | | - stop("'tree_list$STATUSCD' must be numeric or integer", call. = FALSE) |
68 | | - if (any(is.na(tree_list$STATUSCD))) |
69 | | - stop("'tree_list$STATUSCD' cannot have missing values", call. = FALSE) |
| 66 | + if (!is.numeric(tree_table$STATUSCD)) |
| 67 | + stop("'STATUSCD' must be numeric or integer", call. = FALSE) |
| 68 | + if (any(is.na(tree_table$STATUSCD))) |
| 69 | + stop("'STATUSCD' cannot have missing values", call. = FALSE) |
70 | 70 |
|
71 | | - if (!is.numeric(tree_list$DIA)) |
72 | | - stop("'tree_list$DIA' must be numeric", call. = FALSE) |
73 | | - if (any(is.na(tree_list$DIA))) |
74 | | - stop("'tree_list$DIA' cannot have missing values", call. = FALSE) |
| 71 | + if (!is.numeric(tree_table$DIA)) |
| 72 | + stop("'DIA' must be numeric", call. = FALSE) |
| 73 | + if (any(is.na(tree_table$DIA[tree_table$STATUSCD == 1]))) |
| 74 | + stop("'DIA' has missing values for live trees", call. = FALSE) |
75 | 75 |
|
76 | 76 | if (is.null(digits)) |
77 | 77 | digits <- 1 |
78 | 78 |
|
79 | | - cw <- rep_len(NA_real_, nrow(tree_list)) |
| 79 | + cw <- rep_len(NA_real_, nrow(tree_table)) |
80 | 80 |
|
81 | 81 | # define a default equation to use in case a species-specific one is missing |
82 | 82 | # SPCD == 807, blue oak |
83 | 83 | b_default <- cw_coef[cw_coef$SPCD == 807, c("b0", "b1", "b2")] |
84 | 84 |
|
85 | 85 | # special case for large trees of certain species in the PNW region: |
86 | 86 | # use the "old growth" equation from Gill et al. (2000) |
87 | | - old_growth_trees <- tree_list$DIA > 50 & tree_list$STATUSCD == 1 & |
88 | | - tree_list$SPCD %in% c(11, 98, 108, 119, 122, 202, 242, 263, 264) |
| 87 | + old_growth_trees <- tree_table$DIA > 50 & tree_table$STATUSCD == 1 & |
| 88 | + tree_table$SPCD %in% c(11, 98, 108, 119, 122, 202, 242, 263, 264) |
89 | 89 |
|
90 | | - cw[old_growth_trees] <- 16.449 + 0.4067 * tree_list$DIA[old_growth_trees] |
| 90 | + cw[old_growth_trees] <- 16.449 + 0.4067 * tree_table$DIA[old_growth_trees] |
91 | 91 |
|
92 | 92 | # apply species-specific equations |
93 | 93 | # NB: crwidth of trees with DIA < 5 in. (i.e. "saplings") is predicted for |
94 | 94 | # DIA = 5 and then sapling crwidth adjustment factors are applied afterward |
95 | | - for (spcd in unique(tree_list$SPCD)) { |
| 95 | + for (spcd in unique(tree_table$SPCD)) { |
96 | 96 | b <- cw_coef[cw_coef$SPCD == spcd, c("b0", "b1", "b2")] |
97 | 97 | if (nrow(b) == 0) |
98 | 98 | b <- b_default |
99 | 99 |
|
100 | 100 | this_subset <- |
101 | | - tree_list$SPCD == spcd & tree_list$STATUSCD == 1 & is.na(cw) |
| 101 | + tree_table$SPCD == spcd & tree_table$STATUSCD == 1 & is.na(cw) |
102 | 102 |
|
103 | 103 | cw[this_subset] <- |
104 | | - b$b0 + b$b1 * pmax(5, tree_list$DIA[this_subset]) + |
105 | | - b$b2 * pmax(5, tree_list$DIA[this_subset])^2 |
| 104 | + b$b0 + b$b1 * pmax(5, tree_table$DIA[this_subset]) + |
| 105 | + b$b2 * pmax(5, tree_table$DIA[this_subset])^2 |
106 | 106 | } |
107 | 107 |
|
108 | 108 | # apply sapling crown width adjustment factors |
109 | | - saplings <- tree_list$DIA < 5 & tree_list$STATUSCD == 1 |
110 | | - sapling_spp <- unique(tree_list$SPCD[saplings]) |
| 109 | + saplings <- tree_table$DIA < 5 & tree_table$STATUSCD == 1 |
| 110 | + sapling_spp <- unique(tree_table$SPCD[saplings]) |
111 | 111 | # species-specific adjustment factors if any (based on Bragg 2001) |
112 | 112 | spcd_adj <- intersect(sapling_spp, cw_sapling_adj$SPCD) |
113 | 113 | for (spcd in spcd_adj) { |
114 | 114 | rowid <- which(cw_sapling_adj$SPCD == spcd) |
115 | 115 | # adjustment factors at 1, 2, 3, 4, 5 inches DIA: |
116 | 116 | adj_factors <- c(as.numeric(cw_sapling_adj[rowid, 2:5]), 1) |
117 | | - this_subset <- saplings & tree_list$SPCD == spcd |
| 117 | + this_subset <- saplings & tree_table$SPCD == spcd |
118 | 118 | # interpolated adjustment factors for the actual sapling diameters: |
119 | | - n <- trunc(tree_list$DIA[this_subset]) |
120 | | - cw_adj <- (tree_list$DIA[this_subset] - n) * |
| 119 | + n <- trunc(tree_table$DIA[this_subset]) |
| 120 | + cw_adj <- (tree_table$DIA[this_subset] - n) * |
121 | 121 | (adj_factors[n + 1] - adj_factors[n]) + adj_factors[n] |
122 | 122 | cw[this_subset] <- cw[this_subset] * cw_adj |
123 | 123 | } |
124 | 124 | # otherwise use avarage adjustment factors based on Bragg (2001) data |
125 | 125 | # average adjustment factors at 1, 2, 3, 4, 5 inches DIA: |
126 | 126 | adj_factors <- c(0.509, 0.644, 0.767, 0.885, 1.0) |
127 | | - this_subset <- saplings & !(tree_list$SPCD %in% cw_sapling_adj$SPCD) |
| 127 | + this_subset <- saplings & !(tree_table$SPCD %in% cw_sapling_adj$SPCD) |
128 | 128 | # interpolated adjustment factors for the actual sapling diameters: |
129 | | - n <- trunc(tree_list$DIA[this_subset]) |
130 | | - cw_adj <- (tree_list$DIA[this_subset] - n) * |
| 129 | + n <- trunc(tree_table$DIA[this_subset]) |
| 130 | + cw_adj <- (tree_table$DIA[this_subset] - n) * |
131 | 131 | (adj_factors[n + 1] - adj_factors[n]) + adj_factors[n] |
132 | 132 | cw[this_subset] <- cw[this_subset] * cw_adj |
133 | 133 |
|
|
0 commit comments