Skip to content

Commit f289d42

Browse files
committed
usage examples [WIP]
1 parent d752d78 commit f289d42

6 files changed

Lines changed: 188 additions & 25 deletions

File tree

README.Rmd

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,16 @@ pak::pak("ctoney/FIAstemmap")
4747

4848
### Predict crown width
4949

50-
The data frame `cw_coef` provides a curated set of linear regression coefficients for predicting crown width from stem diameter of tree species in the conterminous US. The crown width prediction method also addresses potential issues in cases of extrapolation beyond the range of the model fitting data. Details are given in the documentation for `calc_crwidth()`. Input is a data frame of tree records which must have columns `SPCD` (FIA integer species code), `STATUSCD` (FIA integer tree status code, `1` = live) and `DIA` (FIA tree diameter in inches), here using the `plantation` example tree list.
50+
The data frame `cw_coef` provides a curated set of linear regression coefficients for predicting crown width from stem diameter of tree species in the conterminous US (see `?cw_coef`). The crown width prediction method also addresses potential issues in cases of extrapolation beyond the range of the model fitting data. Details are given in the documentation for `calc_crwidth()`. Input is a data frame of tree records which must have columns `SPCD` (FIA integer species code), `STATUSCD` (FIA integer tree status code, `1` = live) and `DIA` (FIA tree diameter in inches), here using the `plantation` example tree list.
5151

5252
```{r predict-crwidth}
5353
library(FIAstemmap)
5454
5555
# regression coefficients for estimating tree crown width from diameter
56+
# ?cw_coef
5657
head(cw_coef)
5758
58-
# add predicted crown widths to the plantation tree list
59+
# add predicted crown widths to the `plantation` tree list
5960
# `within()` to modify only a copy of the example dataset
6061
tree_list <- within(plantation, CRWIDTH <- calc_crwidth(plantation))
6162
str(tree_list)
@@ -67,42 +68,75 @@ Plot-level visualization and other exploratory analyses require input data with
6768

6869
```{r plot-crowns}
6970
# display modeled tree crowns projected vertically on the FIA plot boundary
70-
plot_crowns(tree_list, main = "plantation plot")
71+
plot_crowns(tree_list, main = "Loblolly pine plantation")
7172
7273
# individual subplot
73-
plot_crowns(tree_list, subplot = 4, main = "plantation subplot 4")
74+
plot_crowns(tree_list, subplot = 4,
75+
main = "Loblolly pine plantation subplot 4")
7476
7577
# or microplot
7678
plot_crowns(tree_list, subplot = 4, microplot = TRUE,
77-
main = "plantation microplot 4")
79+
main = "Loblolly pine plantation microplot 4")
7880
```
7981

80-
Helper functions are provided to facilitate analyzing FIA tree lists as Spatial Point Patterns using the **spatstat** library. `create_fia_ppp()` returns an object of class `"ppp"` representing the point pattern of an FIA tree list in the 2-D plane. This object can be used with functions of package **spatstat.explore** for additional plotting capability, computation of descriptive spatial statistics, and other exploratory data analysis.
82+
Helper functions are provided to facilitate analysis of FIA tree lists as Spatial Point Patterns using the **spatstat** library. `create_fia_ppp()` returns an object of class `"ppp"` representing the point pattern of an FIA tree list in the 2-D plane. This object can be used with functions of package **spatstat.explore** for additional plotting capability, computation of descriptive spatial statistics, and other exploratory data analysis.
8183

8284
```{r spatstat-explore}
8385
# point pattern object for the plantation tree list
8486
X <- create_fia_ppp(plantation)
8587
summary(X)
8688
87-
plot(X, pch = 16, background = "#EEE9DF", main = "Loblolly pine plantation")
89+
plot(X, pch = 16, background = "#EEE9DF", main = "plantation point pattern")
8890
8991
# compute Ripley's K-function applying isotropic edge correction
9092
K <- spatstat.explore::Kest(X, rmax = 12, correction = "isotropic")
9193
92-
# plot estimated K(r) along with theoretical values for a random (Poisson)
93-
# point process, suggests spatial regularity in this case
94+
# plot estimated K(r) along with theoretical values for a completely random
95+
# point process, spatial regularity suggested in this case
9496
plot(K, main = "Ripley's K for the plantation trees")
9597
```
9698

9799
### Compute stand structure metrics
98100

101+
```{r stand-structure}
102+
## compute fractional tree canopy cover of a specific sampled area by overlaying
103+
## modeled crowns
99104
105+
# subplot 1 of the `plantation` plot which contains only live trees
106+
tree_list[tree_list$SUBP == 1 & tree_list$DIA >= 5, ] |>
107+
calc_crown_overlay(sample_radius = 24)
100108
109+
## calculate stand height metrics, included by default in the output of
110+
## `calc_tcc_metrics()` (see below)
111+
112+
# calc_ht_metrics(plantation)
113+
114+
## predict plot-level canopy cover from individual tree measurements
115+
116+
# full output
117+
calc_tcc_metrics(plantation)
118+
119+
# return only the predicted TCC value (`$model_tcc`)
120+
calc_tcc_metrics(plantation, full_output = FALSE)
121+
122+
# using the "FVS method" which assumes random tree locations
123+
calc_tcc_metrics(plantation, stem_map = FALSE, full_output = FALSE)
124+
```
101125

102126
### Data processing
103127

128+
```{r data-proc}
129+
## load tree data from a file or database connection
130+
f <- system.file("extdata/mt_lnf_2022_1cond_tree.csv", package="FIAstemmap")
131+
tree <- load_tree_data(f)
132+
133+
head(tree)
104134
135+
## process tree data
105136
137+
# TODO...
138+
139+
```
106140

107141
## References
108142

README.md

Lines changed: 145 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,20 @@ pak::pak("ctoney/FIAstemmap")
6262

6363
The data frame `cw_coef` provides a curated set of linear regression
6464
coefficients for predicting crown width from stem diameter of tree
65-
species in the conterminous US. The crown width prediction method also
66-
addresses potential issues in cases of extrapolation beyond the range of
67-
the model fitting data. Details are given in the documentation for
68-
`calc_crwidth()`. Input is a data frame of tree records which must have
69-
columns `SPCD` (FIA integer species code), `STATUSCD` (FIA integer tree
70-
status code, `1` = live) and `DIA` (FIA tree diameter in inches), here
71-
using the `plantation` example tree list.
65+
species in the conterminous US (see `?cw_coef`). The crown width
66+
prediction method also addresses potential issues in cases of
67+
extrapolation beyond the range of the model fitting data. Details are
68+
given in the documentation for `calc_crwidth()`. Input is a data frame
69+
of tree records which must have columns `SPCD` (FIA integer species
70+
code), `STATUSCD` (FIA integer tree status code, `1` = live) and `DIA`
71+
(FIA tree diameter in inches), here using the `plantation` example tree
72+
list.
7273

7374
``` r
7475
library(FIAstemmap)
7576

7677
# regression coefficients for estimating tree crown width from diameter
78+
# ?cw_coef
7779
head(cw_coef)
7880
#> symbol SPCD common_name surrogate b0 b1 b2 reference
7981
#> 1 ABAM 11 Pacific silver fir <NA> 7.30 0.59 0.00 Bechtold (2004)
@@ -83,7 +85,7 @@ head(cw_coef)
8385
#> 5 ABLA 19 subalpine fir <NA> 3.96 0.64 0.00 Bechtold (2004)
8486
#> 6 ABMA 20 California red fir <NA> 6.67 0.43 0.00 Gill et al. (2000)
8587

86-
# add predicted crown widths to the plantation tree list
88+
# add predicted crown widths to the `plantation` tree list
8789
# `within()` to modify only a copy of the example dataset
8890
tree_list <- within(plantation, CRWIDTH <- calc_crwidth(plantation))
8991
str(tree_list)
@@ -112,15 +114,16 @@ and `DIST` (stem distance from subplot/microplot center).
112114

113115
``` r
114116
# display modeled tree crowns projected vertically on the FIA plot boundary
115-
plot_crowns(tree_list, main = "plantation plot")
117+
plot_crowns(tree_list, main = "Loblolly pine plantation")
116118
```
117119

118120
<img src="man/figures/README-plot-crowns-1.png" alt="" width="70%" />
119121

120122
``` r
121123

122124
# individual subplot
123-
plot_crowns(tree_list, subplot = 4, main = "plantation subplot 4")
125+
plot_crowns(tree_list, subplot = 4,
126+
main = "Loblolly pine plantation subplot 4")
124127
```
125128

126129
<img src="man/figures/README-plot-crowns-2.png" alt="" width="70%" />
@@ -129,13 +132,13 @@ plot_crowns(tree_list, subplot = 4, main = "plantation subplot 4")
129132

130133
# or microplot
131134
plot_crowns(tree_list, subplot = 4, microplot = TRUE,
132-
main = "plantation microplot 4")
135+
main = "Loblolly pine plantation microplot 4")
133136
```
134137

135138
<img src="man/figures/README-plot-crowns-3.png" alt="" width="70%" />
136139

137-
Helper functions are provided to facilitate analyzing FIA tree lists as
138-
Spatial Point Patterns using the **spatstat** library.
140+
Helper functions are provided to facilitate analysis of FIA tree lists
141+
as Spatial Point Patterns using the **spatstat** library.
139142
`create_fia_ppp()` returns an object of class `"ppp"` representing the
140143
point pattern of an FIA tree list in the 2-D plane. This object can be
141144
used with functions of package **spatstat.explore** for additional
@@ -164,7 +167,7 @@ summary(X)
164167
#> Unit of length: 1 foot
165168
#> Fraction of frame area: 0.124
166169

167-
plot(X, pch = 16, background = "#EEE9DF", main = "Loblolly pine plantation")
170+
plot(X, pch = 16, background = "#EEE9DF", main = "plantation point pattern")
168171
```
169172

170173
<img src="man/figures/README-spatstat-explore-1.png" alt="" width="70%" />
@@ -174,17 +177,143 @@ plot(X, pch = 16, background = "#EEE9DF", main = "Loblolly pine plantation")
174177
# compute Ripley's K-function applying isotropic edge correction
175178
K <- spatstat.explore::Kest(X, rmax = 12, correction = "isotropic")
176179

177-
# plot estimated K(r) along with theoretical values for a random (Poisson)
178-
# point process, suggests spatial regularity in this case
180+
# plot estimated K(r) along with theoretical values for a completely random
181+
# point process, spatial regularity suggested in this case
179182
plot(K, main = "Ripley's K for the plantation trees")
180183
```
181184

182185
<img src="man/figures/README-spatstat-explore-2.png" alt="" width="70%" />
183186

184187
### Compute stand structure metrics
185188

189+
``` r
190+
## compute fractional tree canopy cover of a specific sampled area by overlaying
191+
## modeled crowns
192+
193+
# subplot 1 of the `plantation` plot which contains only live trees
194+
tree_list[tree_list$SUBP == 1 & tree_list$DIA >= 5, ] |>
195+
calc_crown_overlay(sample_radius = 24)
196+
#> [1] 86.9
197+
198+
## calculate stand height metrics, included by default in the output of
199+
## `calc_tcc_metrics()` (see below)
200+
201+
# calc_ht_metrics(plantation)
202+
203+
## predict plot-level canopy cover from individual tree measurements
204+
205+
# full output
206+
calc_tcc_metrics(plantation)
207+
#> $model_tcc
208+
#> [1] 88.5
209+
#>
210+
#> $subp1_crown_overlay
211+
#> [1] 86.9
212+
#>
213+
#> $subp2_crown_overlay
214+
#> [1] 91.8
215+
#>
216+
#> $subp3_crown_overlay
217+
#> [1] 80.5
218+
#>
219+
#> $subp4_crown_overlay
220+
#> [1] 87.3
221+
#>
222+
#> $subp_overlay_mean
223+
#> [1] 86.625
224+
#>
225+
#> $micr1_crown_overlay
226+
#> [1] 0
227+
#>
228+
#> $micr2_crown_overlay
229+
#> [1] 0
230+
#>
231+
#> $micr3_crown_overlay
232+
#> [1] 19.4
233+
#>
234+
#> $micr4_crown_overlay
235+
#> [1] 22
236+
#>
237+
#> $micr_overlay_mean
238+
#> [1] 10.35
239+
#>
240+
#> $L_6ft
241+
#> [1] 3.868305
242+
#>
243+
#> $L_8ft
244+
#> [1] 6.627377
245+
#>
246+
#> $L_10ft
247+
#> [1] 7.300455
248+
#>
249+
#> $L_12ft
250+
#> [1] 11.35045
251+
#>
252+
#> $numTrees
253+
#> [1] 89
254+
#>
255+
#> $meanTreeHt
256+
#> [1] 45
257+
#>
258+
#> $meanTreeHtBAW
259+
#> [1] 45.4
260+
#>
261+
#> $meanTreeHtDom
262+
#> [1] 45
263+
#>
264+
#> $meanTreeHtDomBAW
265+
#> [1] 45.4
266+
#>
267+
#> $maxTreeHt
268+
#> [1] 51
269+
#>
270+
#> $predomTreeHt
271+
#> [1] 50.3
272+
#>
273+
#> $numSaplings
274+
#> [1] 2
275+
#>
276+
#> $meanSapHt
277+
#> [1] 33.5
278+
#>
279+
#> $maxSapHt
280+
#> [1] 42
281+
282+
# return only the predicted TCC value (`$model_tcc`)
283+
calc_tcc_metrics(plantation, full_output = FALSE)
284+
#> [1] 88.5
285+
286+
# using the "FVS method" which assumes random tree locations
287+
calc_tcc_metrics(plantation, stem_map = FALSE, full_output = FALSE)
288+
#> [1] 81.4
289+
```
290+
186291
### Data processing
187292

293+
``` r
294+
## load tree data from a file or database connection
295+
f <- system.file("extdata/mt_lnf_2022_1cond_tree.csv", package="FIAstemmap")
296+
tree <- load_tree_data(f)
297+
#> ! The data source does not have DIST and/or AZIMUTH
298+
#> ℹ Fetching tree data...
299+
#> ✔ Fetching tree data... [15ms]
300+
#>
301+
#> ℹ 910 tree records returned
302+
303+
head(tree)
304+
#> PLT_CN SUBP TREE STATUSCD SPCD DIA HT ACTUALHT CCLCD TPA_UNADJ
305+
#> 1 670951075126144 1 1 2 108 NA NA NA NA NA
306+
#> 2 670951075126144 1 2 1 108 1 9 9 3 74.96528
307+
#> 3 670951075126144 2 1 2 108 NA NA NA NA NA
308+
#> 4 670951075126144 2 2 2 108 NA NA NA NA NA
309+
#> 5 670951075126144 2 3 2 108 NA NA NA NA NA
310+
#> 6 670951075126144 2 4 2 108 NA NA NA NA NA
311+
312+
## process tree data
313+
314+
# TODO...
315+
```
316+
188317
## References
189318

190319
\[1\] Toney, Chris; Shaw, John D.; Nelson, Mark D. 2009. A stem-map
1.14 KB
Loading
1.04 KB
Loading
1.21 KB
Loading
-677 Bytes
Loading

0 commit comments

Comments
 (0)