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

calc_indicators should issue a warning for non-available extraction engine parameters #194

Closed karpfen closed 5 months ago

karpfen commented 1 year ago

For some indicators (e.g. treecover_area_and_emissions) it is not possible to select the preferred type of extraction engine yet. I think it would be useful to warn the user if they specify an engine that's not being used. Otherwise they end up with a plausible-looking result that's coming from an unexpected engine.

This works, for example, but you'd expect (or at least I would :) ) that different engines are being used:

library(mapme.biodiversity)
library(sf)
library(dplyr)

get_tc <- function(.engine) {
  tc <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>%
    sf::read_sf() %>%
    init_portfolio(
      years = 2016:2017,
      outdir = system.file("res", package = "mapme.biodiversity"),
      tmpdir = system.file("tmp", package = "mapme.biodiversity"),
      add_resources = FALSE,
      verbose = FALSE
    ) %>%
    get_resources(
      resources = c("gfw_treecover", "gfw_lossyear", "gfw_emissions"),
      vers_treecover = "GFC-2020-v1.8", vers_lossyear = "GFC-2020-v1.8"
    ) %>%
    calc_indicators("treecover_area_and_emissions", min_size = 1, min_cover = 30, engine = .engine) %>%
    tidyr::unnest(treecover_area_and_emissions) %>%
    st_drop_geometry() %>%
    select(treecover) %>%
    sum()
  return(tc)
}

tc1 <- get_tc("extract")
tc2 <- get_tc("exactextract")
tc3 <- get_tc("zonal")
tc4 <- get_tc("blabla")
tc5 <- get_tc(NULL)

all(
  tc1 == tc2,
  tc1 == tc3,
  tc1 == tc4,
  tc1 == tc5
) # TRUE

Any thoughts on this?

goergen95 commented 5 months ago

With the release of v.0.6.0 miss-specification of user-facing arguments are now directly checked. This includes engines.