diff --git a/R/calc_treecover_area.R b/R/calc_treecover_area.R index 7b4ac392..6d304a3e 100644 --- a/R/calc_treecover_area.R +++ b/R/calc_treecover_area.R @@ -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") @@ -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)) diff --git a/R/calc_treecover_area_and_emissions.R b/R/calc_treecover_area_and_emissions.R index 4f5d7fcc..9e9e602c 100644 --- a/R/calc_treecover_area_and_emissions.R +++ b/R/calc_treecover_area_and_emissions.R @@ -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( @@ -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") diff --git a/R/calc_treecoverloss_emissions.R b/R/calc_treecoverloss_emissions.R index 29002dea..65bfe96f 100644 --- a/R/calc_treecoverloss_emissions.R +++ b/R/calc_treecoverloss_emissions.R @@ -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( @@ -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") diff --git a/R/get_gfw_lossyear.R b/R/get_gfw_lossyear.R index 27d1f8e6..bad64175 100644 --- a/R/get_gfw_lossyear.R +++ b/R/get_gfw_lossyear.R @@ -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. @@ -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, diff --git a/R/get_gfw_treecover.R b/R/get_gfw_treecover.R index d31c1257..4b3eed65 100644 --- a/R/get_gfw_treecover.R +++ b/R/get_gfw_treecover.R @@ -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. @@ -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, @@ -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" ) } diff --git a/data-raw/gfw_treecover.R b/data-raw/gfw_treecover.R new file mode 100644 index 00000000..dbca22ff --- /dev/null +++ b/data-raw/gfw_treecover.R @@ -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" +) diff --git a/inst/res/gfw_emissions/.gitignore b/inst/res/gfw_emissions/.gitignore deleted file mode 100644 index e4a54456..00000000 --- a/inst/res/gfw_emissions/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.gpkg diff --git a/inst/res/gfw_emissions/gfw_forest_carbon_gross_emissions_Mg_CO2e_px_20N_080W.tif b/inst/res/gfw_emissions/gfw_forest_carbon_gross_emissions_Mg_CO2e_px_20N_080W.tif index 546fe814..04e34f25 100644 Binary files a/inst/res/gfw_emissions/gfw_forest_carbon_gross_emissions_Mg_CO2e_px_20N_080W.tif and b/inst/res/gfw_emissions/gfw_forest_carbon_gross_emissions_Mg_CO2e_px_20N_080W.tif differ diff --git a/inst/res/gfw_lossyear/.gitignore b/inst/res/gfw_lossyear/.gitignore deleted file mode 100644 index e4a54456..00000000 --- a/inst/res/gfw_lossyear/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.gpkg diff --git a/inst/res/gfw_lossyear/Hansen_GFC-2020-v1.8_lossyear_20N_080W.tif b/inst/res/gfw_lossyear/Hansen_GFC-2020-v1.8_lossyear_20N_080W.tif deleted file mode 100644 index f4cad9c2..00000000 Binary files a/inst/res/gfw_lossyear/Hansen_GFC-2020-v1.8_lossyear_20N_080W.tif and /dev/null differ diff --git a/inst/res/gfw_lossyear/Hansen_GFC-2023-v1.11_lossyear_20N_080W.tif b/inst/res/gfw_lossyear/Hansen_GFC-2023-v1.11_lossyear_20N_080W.tif new file mode 100644 index 00000000..46239900 Binary files /dev/null and b/inst/res/gfw_lossyear/Hansen_GFC-2023-v1.11_lossyear_20N_080W.tif differ diff --git a/inst/res/gfw_treecover/.gitignore b/inst/res/gfw_treecover/.gitignore deleted file mode 100644 index e4a54456..00000000 --- a/inst/res/gfw_treecover/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.gpkg diff --git a/inst/res/gfw_treecover/Hansen_GFC-2020-v1.8_treecover2000_20N_080W.tif b/inst/res/gfw_treecover/Hansen_GFC-2020-v1.8_treecover2000_20N_080W.tif deleted file mode 100644 index bc5123e3..00000000 Binary files a/inst/res/gfw_treecover/Hansen_GFC-2020-v1.8_treecover2000_20N_080W.tif and /dev/null differ diff --git a/inst/res/gfw_treecover/Hansen_GFC-2023-v1.11_treecover2000_20N_080W.tif b/inst/res/gfw_treecover/Hansen_GFC-2023-v1.11_treecover2000_20N_080W.tif new file mode 100644 index 00000000..98b36660 Binary files /dev/null and b/inst/res/gfw_treecover/Hansen_GFC-2023-v1.11_treecover2000_20N_080W.tif differ diff --git a/man/gfw_lossyear.Rd b/man/gfw_lossyear.Rd index bda5605e..9aa16bbe 100644 --- a/man/gfw_lossyear.Rd +++ b/man/gfw_lossyear.Rd @@ -8,11 +8,11 @@ \url{https://data.globalforestwatch.org/documents/tree-cover-loss/explore} } \usage{ -get_gfw_lossyear(version = "GFC-2022-v1.10") +get_gfw_lossyear(version = "GFC-2023-v1.11") } \arguments{ \item{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} } \value{ diff --git a/man/gfw_treecover.Rd b/man/gfw_treecover.Rd index 9ed3ab74..0c83bab6 100644 --- a/man/gfw_treecover.Rd +++ b/man/gfw_treecover.Rd @@ -8,11 +8,11 @@ \url{https://data.globalforestwatch.org/documents/tree-cover-2000/explore} } \usage{ -get_gfw_treecover(version = "GFC-2022-v1.10") +get_gfw_treecover(version = "GFC-2023-v1.11") } \arguments{ \item{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} } \value{ diff --git a/man/treecover_area.Rd b/man/treecover_area.Rd index 6ac6cbd9..5172c100 100644 --- a/man/treecover_area.Rd +++ b/man/treecover_area.Rd @@ -5,7 +5,7 @@ \alias{calc_treecover_area} \title{Calculate treecover statistics} \usage{ -calc_treecover_area(years = 2000:2020, min_size = 10, min_cover = 35) +calc_treecover_area(years = 2000:2023, min_size = 10, min_cover = 35) } \arguments{ \item{years}{A numeric vector with the years for which to calculate treecover @@ -53,8 +53,8 @@ aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", ) \%>\% 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() diff --git a/man/treecover_area_and_emissions.Rd b/man/treecover_area_and_emissions.Rd index e1545b68..634c99e3 100644 --- a/man/treecover_area_and_emissions.Rd +++ b/man/treecover_area_and_emissions.Rd @@ -6,7 +6,7 @@ \title{Calculate treeloss statistics} \usage{ calc_treecover_area_and_emissions( - years = 2000:2020, + years = 2000:2023, min_size = 10, min_cover = 35 ) @@ -60,8 +60,8 @@ aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", ) \%>\% 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( diff --git a/man/treecoverloss_emissions.Rd b/man/treecoverloss_emissions.Rd index d2bcad5b..5be95067 100644 --- a/man/treecoverloss_emissions.Rd +++ b/man/treecoverloss_emissions.Rd @@ -5,7 +5,7 @@ \alias{calc_treecoverloss_emissions} \title{Calculate emission statistics} \usage{ -calc_treecoverloss_emissions(years = 2000:2020, min_size = 10, min_cover = 35) +calc_treecoverloss_emissions(years = 2000:2023, min_size = 10, min_cover = 35) } \arguments{ \item{years}{A numeric vector with the years for which to calculate emissions @@ -56,8 +56,8 @@ aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", ) \%>\% 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( diff --git a/tests/testthat/_snaps/calc_treecover_area.md b/tests/testthat/_snaps/calc_treecover_area.md index 170536cd..9d852144 100644 --- a/tests/testthat/_snaps/calc_treecover_area.md +++ b/tests/testthat/_snaps/calc_treecover_area.md @@ -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 diff --git a/tests/testthat/_snaps/calc_treecover_area_and_emissions.md b/tests/testthat/_snaps/calc_treecover_area_and_emissions.md index 5f097676..6c4e87f1 100644 --- a/tests/testthat/_snaps/calc_treecover_area_and_emissions.md +++ b/tests/testthat/_snaps/calc_treecover_area_and_emissions.md @@ -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 diff --git a/tests/testthat/_snaps/calc_treecoverloss_emissions.md b/tests/testthat/_snaps/calc_treecoverloss_emissions.md index e25e127b..1375f74d 100644 --- a/tests/testthat/_snaps/calc_treecoverloss_emissions.md +++ b/tests/testthat/_snaps/calc_treecoverloss_emissions.md @@ -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