mapme-initiative / mapme.biodiversity

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

ESA Landcover returns 0-length tibble #215

Closed karpfen closed 7 months ago

karpfen commented 7 months ago

Continuing from the discussion in https://github.com/mapme-initiative/mapme.biodiversity/pull/211. This snippet produces a 0-length tibble for ESA landcover.

poly <- data.frame (
  id = 1,
  geom = "POLYGON ((46.303 38.9943, 46.3032 38.9942, 46.3035 38.9941, 46.3037 38.994, 46.304 38.9939, 46.3037 38.9941, 46.3032 38.9943, 46.303 38.9943))"
)
poly <- st_as_sf(poly, wkt = "geom", crs = 4326)
poly <- st_make_valid(poly)

pf_esa_lc <- poly %>%
  init_portfolio(
  2000:2023,
  verbose = TRUE) %>%
  get_resources("esalandcover")
dat_esa_lc <- calc_indicators(pf_esa_lc, c("landcover"))
goergen95 commented 7 months ago

I suspect the reason for that polygon to fail to be related to #208. Once we merge #212, a valid value should be returned. I have not merge it yet because it introduces slight changes to the numerical results for a number of indicators. We should discuss if it is ok to merge. Meanwhile, I'll improve the error handling for 0-tibble results. I would argue that the package should throw a warnig but return NA instead.

goergen95 commented 7 months ago

Hi, could you please check with remotes::install_github("mapme-initiative/mapme.biodiversity", ref = "improve-output-checks")?

karpfen commented 7 months ago

@goergen95 I just tried it, but I'm still getting the error.

goergen95 commented 7 months ago

You should get a warning instead of an error and an object is actually returned where the value is set to NA. If you now process a larger portfolio, the process no longer fails, but informs you which assets returned 0-length-tibbles and places NAs there. You see that too?

karpfen commented 7 months ago

@goergen95 I must have been mistaken yesterday or made some mistake when testing your fix. I'm now getting the warning and NA result as expected, thanks! :)