Skip to content

Commit 33da4d4

Browse files
committed
tree cover max year
1 parent eff658a commit 33da4d4

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

R/calc_treecover_area.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ calc_treecover_area <- function(years = 2000:2024,
155155
data[data[["patches"]] %in% keep_patches, ]
156156
}
157157

158-
.sum_gfw <- function(data, what = "coverage_area", max_year = 2023) {
158+
.sum_gfw <- function(data, what, max_year) {
159159
# calculate loss area by year
160160
df <- data.frame(years = 2000:max_year, var = 0)
161161
names(df)[2] <- what
@@ -244,7 +244,7 @@ calc_treecover_area <- function(years = 2000:2024,
244244
rcl<- matrix(c(NA, NA, 0,
245245
0, cover, 0,
246246
cover, 100.001, 1), ncol = 3, byrow = TRUE)
247-
# need vale > 100 to include 100 with 'right = FALSE'
247+
# need value > 100 to include 100 with 'right = FALSE'
248248
binary_treecover <- terra::classify(treecover,
249249
rcl = rcl,
250250
right = FALSE, others = NA)

R/calc_treecover_area_and_emissions.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ calc_treecover_area_and_emissions <- function(years = 2000:2024,
102102
data <- .prep_gfw_data(data, min_size)
103103
losses <- .sum_gfw(data, "coverage_area", max_year)
104104
names(losses)[2] <- "loss"
105-
emissions <- .sum_gfw(data, "emissions")
105+
emissions <- .sum_gfw(data, "emissions", max_year)
106106

107107
org_coverage <- sum(data[["coverage_area"]])
108108

tests/testthat/test-calc_treecover_area.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ test_that("test gfw utils", {
6363
"patches", "emissions", "coverage_area"
6464
))
6565

66-
expect_silent(area <- .sum_gfw(df, "coverage_area"))
66+
expect_silent(area <- .sum_gfw(df, "coverage_area", 2023))
6767
expect_equal(names(area), c("years", "coverage_area"))
68-
expect_silent(emis <- .sum_gfw(df, "emissions"))
68+
expect_silent(emis <- .sum_gfw(df, "emissions", 2023))
6969
expect_equal(names(emis), c("years", "emissions"))
7070
})
7171

0 commit comments

Comments
 (0)