-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-eq.R
170 lines (146 loc) · 2.84 KB
/
test-eq.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
test_that("height functions work", {
ht_est <- estimate_height(
spcd = 318,
dbh = 12,
site_index = 65,
top_dob = 4,
stand_basal_area = 88
)
expect_equal(
ht_est, 49.6419 - 1.2e-05
)
ht_coeffs <- dplyr::filter(
table1,
species_group == "Hard maple"
)
expect_equal(
apply_height_eq(
dbh = 12,
site_index = 65,
top_dob = 4,
stand_basal_area = 88,
b1 = ht_coeffs$b1,
b2 = ht_coeffs$b2,
b3 = ht_coeffs$b3,
b4 = ht_coeffs$b4,
b5 = ht_coeffs$b5,
b6 = ht_coeffs$b6
),
49.64189 - 1.95e-06
)
})
test_that("volume functions work", {
gross_vol_cuft <- estimate_volume(
spcd = 318,
dbh = 12,
height = 49.6,
vol_type = "cuft"
)
expect_equal(
gross_vol_cuft,
17.13073 + 4.4e-06
)
cuft_vol_coeffs <- dplyr::filter(
table2,
species_group == "Hard maple"
)
expect_equal(
apply_volume_eq(
dbh = 12,
height = 49.6,
b0 = cuft_vol_coeffs$b0,
b1 = cuft_vol_coeffs$b1
),
17.13073 + 4.4e-06
)
# sawtimber
saw_ht <- estimate_height(
spcd = 318,
dbh = 12,
site_index = 65,
top_dob = 9,
stand_basal_area = 88
)
gross_vol_bdft <- estimate_volume(
spcd = 318,
dbh = 12,
height = saw_ht,
vol_type = "bdft"
)
expect_equal(
gross_vol_bdft,
90.78875 - 1.48e-06
)
})
test_that("biomass functions work", {
gross_vol_cuft <- estimate_volume(
spcd = 318,
dbh = 12,
height = 49.6,
vol_type = "cuft"
)
# stump volume
stump_vol_cuft <- estimate_stump_volume(
spcd = 318,
dbh = 12
)
expect_equal(
stump_vol_cuft,
1.280736
)
# bark correction factor
bark_correction_factor <- get_bark_correction_factor(
spcd = 318,
dbh = 12
)
expect_equal(
bark_correction_factor,
0.97064
)
# bark weight
bark_weight_lbs <- estimate_bark_weight(
gross_vol_cuft = gross_vol_cuft,
stump_vol_cuft = stump_vol_cuft,
bark_correction_factor = bark_correction_factor
)
expect_equal(
bark_weight_lbs,
132.1303 - 1.44e-05
)
# bole weight
bole_weight_tons <- estimate_bole_weight(
spcd = 318,
gross_vol_cuft = gross_vol_cuft,
stump_vol_cuft = stump_vol_cuft,
bark_weight_lbs = bark_weight_lbs
)
expect_equal(
bole_weight_tons,
0.5815863
)
# top weight
top_weight_tons <- estimate_top_weight(
spcd = 318,
bark_weight_lbs = bark_weight_lbs,
gross_vol_cuft = gross_vol_cuft
)
expect_equal(
top_weight_tons,
0.2480323 + 3.34e-08
)
# small stem biomass
expect_equal(
apply_small_tree_biomass_eq(4),
0.05699241
)
# user facing function
expect_equal(
estimate_biomass(
spcd = 318,
dbh = c(12, 4),
site_index = 65,
stand_basal_area = 88
),
c(0.83023001, 0.05699241)
)
})