mapme-initiative / mapme.biodiversity

Efficient analysis of spatial biodiversity datasets for global portfolios
https://mapme-initiative.github.io/mapme.biodiversity/dev
GNU General Public License v3.0
33 stars 7 forks source link

Impossible to compute treecover_area indicator with min_size corresponding to FAO forest definition (0.5) #110

Closed fBedecarrats closed 1 year ago

fBedecarrats commented 1 year ago

To compute the treecover_area indicator, the calc_indicators() function takes two arguments: min_cover and min_size.

The problem is the current code for calc_treecover_area.R includes at line 115 :

min_cover <- as.integer(round(min_cover))

This rounds an argument of 0.5 for min_size to 0 and therefore returns NA values for treecover_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:

min_cover <- as.numeric(min_cover)

?

For reference, the FAO forest definition from 2000 is (bold text by me):

Land with tree crown cover (or equivalent stocking level) of more than 10 % and area of more than 0.5 ha. The trees should be able to reach a minimum height of 5 m at maturity in situ. May consist either of closed forest formations where trees of various storeys and undergrowth cover a high proportion of the ground; or open forest formations with a continuous vegetation cover in which tree crown cover exceeds 10 %. Young natural stands and all plantations established for forestry purposes which have yet to reach a crown density of 10 % or tree height of 5 m are included under forest, as are areas normally forming part of the forest area which are temporarily unstocked as a result of human intervention or natural causes but which are expected to revert to forest.

fBedecarrats commented 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)
goergen95 commented 1 year ago

Hi, so we have the two arguments (for all gfw-related indicators):

https://github.com/mapme-initiative/mapme.biodiversity/blob/71065aea3e642380a9938517063aa9242e0d8d46/R/calc_treecover_area.R#L13-L14

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