Closed fBedecarrats closed 1 year ago
I forgot to include a reproducible example. Here it is:
# Install the latest versions + updated dependencies
remotes::install_github("mapme-initiative/mapme.biodiversity",
upgrade = "always")
install.packages("wdpar")
library(dplyr)
library(sf)
library(mapme.biodiversity)
library(wdpar)
# Downloading Protected areas from Madagascar
PA_mada <- wdpa_fetch("Madagascar", wait = TRUE)
PA_test <- PA_mada %>%
filter(NAME == "Ambatovaky")
# Discard points and cast multipolygons as polygons
PA_poly <- PA_test %>%
filter(st_geometry_type(.) == "MULTIPOLYGON") %>%
st_cast("POLYGON")
# Create portfolio
PA_poly <- init_portfolio(x = PA_poly,
years = 2000:2020,
outdir = "data_test",
cores = 8,
add_resources = TRUE,
verbose = TRUE)
# Get GFW data
PA_poly <- get_resources(x = PA_poly,
resources = c("gfw_treecover", "gfw_lossyear"))
# Compute indicators : works with min_size = 1
PA_poly <- calc_indicators(x = PA_poly,
indicators = "treecover_area",
min_cover = 10, min_size = 1)
# Compute indicators : doesn't works with min_size = 0.5
PA_poly <- calc_indicators(x = PA_poly,
indicators = "treecover_area",
min_cover = 10, min_size = 0.5)
Hi,
so we have the two arguments (for all gfw
-related indicators):
The gfw_treecover
resource is actually encoded as Byte with values ranging from 0 to 100 indicating the percentage of tree cover. So, for the argument min_cover
I think it is actually fine to round to an integer value.
However, you are right about the min_size
argument, which currently also is set to an integer value here and should be adapted to allow specifying fractions of hectares:
https://github.com/mapme-initiative/mapme.biodiversity/blob/71065aea3e642380a9938517063aa9242e0d8d46/R/calc_treecover_area.R#L128
To compute the
treecover_area
indicator, thecalc_indicators()
function takes two arguments:min_cover
andmin_size
.The problem is the current code for calc_treecover_area.R includes at line 115 :
This rounds an argument of 0.5 for
min_size
to 0 and therefore returns NA values fortreecover_area
. There are cases when this value needs to be a fraction, for instance to reflect the FAO definition for forests (see below). Would it be possible to simply remove the line above, or remplace it with:?
For reference, the FAO forest definition from 2000 is (bold text by me):