Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gfw 2023 from betsaka #277

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions R/calc_treecover_area.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
#' ) %>%
#' read_sf() %>%
#' get_resources(
#' get_gfw_treecover(version = "GFC-2022-v1.10"),
#' get_gfw_lossyear(version = "GFC-2022-v1.10")
#' get_gfw_treecover(version = "GFC-2023-v1.11"),
#' get_gfw_lossyear(version = "GFC-2023-v1.11")
#' ) %>%
#' calc_indicators(calc_treecover_area(years = 2016:2017, min_size = 1, min_cover = 30)) %>%
#' portfolio_long()
#'
#' aoi
#' }
calc_treecover_area <- function(years = 2000:2020,
calc_treecover_area <- function(years = 2000:2023,
min_size = 10,
min_cover = 35) {
check_namespace("exactextractr")
Expand Down Expand Up @@ -137,7 +137,7 @@ calc_treecover_area <- function(years = 2000:2020,

.sum_gfw <- function(data, what = "coverage_area") {
# calculate loss area by year
df <- data.frame(years = 2000:2022, var = 0)
df <- data.frame(years = 2000:2023, var = 0)
names(df)[2] <- what
my_sum <- by(data[[what]], data[["lossyear"]], sum, na.rm = TRUE)
sum_years <- as.numeric(names(my_sum))
Expand Down
6 changes: 3 additions & 3 deletions R/calc_treecover_area_and_emissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
#' ) %>%
#' read_sf() %>%
#' get_resources(
#' get_gfw_treecover(version = "GFC-2020-v1.8"),
#' get_gfw_lossyear(version = "GFC-2020-v1.8"),
#' get_gfw_treecover(version = "GFC-2023-v1.11"),
#' get_gfw_lossyear(version = "GFC-2023-v1.11"),
#' get_gfw_emissions()
#' ) %>%
#' calc_indicators(
Expand All @@ -54,7 +54,7 @@
#'
#' aoi
#' }
calc_treecover_area_and_emissions <- function(years = 2000:2020,
calc_treecover_area_and_emissions <- function(years = 2000:2023,
min_size = 10,
min_cover = 35) {
check_namespace("exactextractr")
Expand Down
6 changes: 3 additions & 3 deletions R/calc_treecoverloss_emissions.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
#' ) %>%
#' read_sf() %>%
#' get_resources(
#' get_gfw_treecover(version = "GFC-2020-v1.8"),
#' get_gfw_lossyear(version = "GFC-2020-v1.8"),
#' get_gfw_treecover(version = "GFC-2023-v1.11"),
#' get_gfw_lossyear(version = "GFC-2023-v1.11"),
#' get_gfw_emissions()
#' ) %>%
#' calc_indicators(
Expand All @@ -54,7 +54,7 @@
#'
#' aoi
#' }
calc_treecoverloss_emissions <- function(years = 2000:2020,
calc_treecoverloss_emissions <- function(years = 2000:2023,
min_size = 10,
min_cover = 35) {
check_namespace("exactextractr")
Expand Down
4 changes: 2 additions & 2 deletions R/get_gfw_lossyear.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#'
#' @name gfw_lossyear
#' @param version The version of the dataset to download. Defaults to
#' "GFC-2022-v1.10". Check \code{mapme.biodiversity:::.available_gfw_versions()}
#' "GFC-2023-v1.11". Check \code{mapme.biodiversity:::.available_gfw_versions()}
#' to get a list of available versions
#' @keywords resource
#' @returns A function that returns a character of file paths.
Expand All @@ -26,7 +26,7 @@
#' @source \url{https://data.globalforestwatch.org/documents/tree-cover-loss/explore}
#' @include register.R
#' @export
get_gfw_lossyear <- function(version = "GFC-2022-v1.10") {
get_gfw_lossyear <- function(version = "GFC-2023-v1.11") {
version <- .check_gfw_version(version)

function(x,
Expand Down
6 changes: 3 additions & 3 deletions R/get_gfw_treecover.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
#' @name gfw_treecover
#' @param version The version of the dataset to download. Defaults to
#' "GFC-2022-v1.10". Check mapme.biodiversity:::.available_gfw_versions()
#' "GFC-2023-v1.11". Check mapme.biodiversity:::.available_gfw_versions()
#' to get a list of available versions
#' @keywords resource
#' @returns A function that returns a character of file paths.
Expand All @@ -23,7 +23,7 @@
#' @source \url{https://data.globalforestwatch.org/documents/tree-cover-2000/explore}
#' @include register.R
#' @export
get_gfw_treecover <- function(version = "GFC-2022-v1.10") {
get_gfw_treecover <- function(version = "GFC-2023-v1.11") {
version <- .check_gfw_version(version)

function(x,
Expand Down Expand Up @@ -65,7 +65,7 @@ get_gfw_treecover <- function(version = "GFC-2022-v1.10") {
c(
"GFC-2015-v1.3", "GFC-2016-v1.4", "GFC-2017-v1.5",
"GFC-2018-v1.6", "GFC-2019-v1.7", "GFC-2020-v1.8",
"GFC-2021-v1.9", "GFC-2022-v1.10"
"GFC-2021-v1.9", "GFC-2022-v1.10", "GFC-2023-v1.11"
)
}

Expand Down
43 changes: 43 additions & 0 deletions data-raw/gfw_treecover.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
library(sf)
library(terra)
library(mapme.biodiversity)

tmp_loc <- tempfile()
dir.create(tmp_loc)
mapme_options(outdir = tmp_loc)

x <- system.file("extdata", "gfw_sample.gpkg",
package = "mapme.biodiversity"
)
x <- st_read(x)

get_resources(
x,
get_gfw_treecover(version = "GFC-2023-v1.11"),
get_gfw_lossyear(version = "GFC-2023-v1.11"),
get_gfw_emissions()
)

rs <- prep_resources(x)

unlink("inst/res/gfw_treecover", force = T, recursive = TRUE)
dir.create("inst/res/gfw_treecover/")
writeRaster(rs$gfw_treecover,
filename = "inst/res/gfw_treecover/Hansen_GFC-2023-v1.11_treecover2000_20N_080W.tif",
gdal = "COMPRESS=LZW", datatype = "INT1U"
)


unlink("inst/res/gfw_lossyear", force = T, recursive = TRUE)
dir.create("inst/res/gfw_lossyear/")
writeRaster(rs$gfw_lossyear,
filename = "inst/res/gfw_lossyear/Hansen_GFC-2023-v1.11_lossyear_20N_080W.tif",
gdal = "COMPRESS=LZW", datatype = "INT1U"
)

unlink("inst/res/gfw_emissions", force = T, recursive = TRUE)
dir.create("inst/res/gfw_emissions/")
writeRaster(rs$gfw_emissions,
filename = "inst/res/gfw_emissions/gfw_forest_carbon_gross_emissions_Mg_CO2e_px_20N_080W.tif",
gdal = c("COMPRESS=DEFLATE", "PREDICTOR=2"), datatype = "FLT4S"
)
1 change: 0 additions & 1 deletion inst/res/gfw_emissions/.gitignore

This file was deleted.

Binary file not shown.
1 change: 0 additions & 1 deletion inst/res/gfw_lossyear/.gitignore

This file was deleted.

Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion inst/res/gfw_treecover/.gitignore

This file was deleted.

Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions man/gfw_lossyear.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/gfw_treecover.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/treecover_area.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/treecover_area_and_emissions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/treecoverloss_emissions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/calc_treecover_area.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Code
result$value
Output
[1] 2054.559 2054.046 2052.358 2018.501 2009.106 2004.831
[1] 2054.614 2054.100 2052.412 2018.549 2009.154 2004.878

4 changes: 2 additions & 2 deletions tests/testthat/_snaps/calc_treecover_area_and_emissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
Code
result$value
Output
[1] 0.000 2054.559 7.000 2054.046 46.000 2052.358 1419.000 2018.501
[9] 528.000 2009.106 295.000 2004.831
[1] 0.0000 2054.6137 212.5268 2054.1000 619.3609 2052.4117
[7] 12932.7655 2018.5493 3676.1357 2009.1545 1731.4164 2004.8785

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/calc_treecoverloss_emissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Code
result$value
Output
[1] 0 7 46 1419 528 295
[1] 0.0000 212.5268 619.3609 12932.7655 3676.1357 1731.4164

Loading