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

Unable to download from traveltime #88

Closed fBedecarrats closed 2 years ago

fBedecarrats commented 2 years ago

Hello, I managed to get and process GFW datasets, but I systematically get errors when I try to get traveltime data. Here is a reproducible example!

library(mapme.biodiversity)
library(dplyr)
library(geodata)

# This is the code from the package Quickstart documentation
aoi_path <- system.file("extdata", "sierra_de_neiba_478140.gpkg", package = "mapme.biodiversity")
aoi <- read_sf(aoi_path)
aoi <- st_cast(aoi, to = "POLYGON")[1, ]
aoi_gridded <- st_make_grid(x = st_bbox(aoi),
                            n = c(10, 10),
                            square = FALSE) %>%
  st_intersection(aoi) %>%
  st_as_sf() %>%
  mutate(geom_type = st_geometry_type(x)) %>%
  filter(geom_type == "POLYGON") %>%
  select(-geom_type, geom = x) %>%
  st_as_sf()

metanames <- names(st_drop_geometry(aoi))
aoi_gridded[metanames] <- st_drop_geometry(aoi)

outdir <- file.path(tempdir(), "mapme.biodiversity")
dir.create(outdir)
resource_dir <- system.file("res", package = "mapme.biodiversity")
file.copy(resource_dir, outdir, recursive = TRUE)

# And now where I always get errors
sample_portfolio <- init_portfolio(x = aoi_gridded,
                                   years = 2000:2020,
                                   outdir = "data",
                                   tmpdir = tempdir(),
                                   add_resources = FALSE,
                                   cores = 1,
                                   verbose = TRUE)
plot(sample_portfolio["assetid"])

test <- get_resources(sample_portfolio, resource = "traveltime",
                     range_traveltime = c("500k_1mio"))

# Starting process to download resource 'traveltime'........
# Erreur : [rast] cannot open file: data/traveltime/traveltime-500k_1mio.tif
# De plus : Message d'avis :
# Dans new_CppObject_xp(fields$.module, fields$.pointer, ...) :
#   GDAL Error 4: data/traveltime/traveltime-500k_1mio.tif: No such file or directory

I guess it must be something with the way directories are specified, but I can't figure how doing it correctly. (by the way, the documentation still refers at this resource as nelson_et_al, although it seems to have been renamed traveltime)

Ohm-Np commented 2 years ago

Thank you for reporting this issue.

The traveltime is the name of the indicator and to calculate this indicator, we need the resource named nelson_et_al. So, if you replace this specific part of the script, it might work.

test <- get_resources(sample_portfolio, resource = "nelson_et_al",
                      range_traveltime = c("500k_1mio"))

Since the latest CRAN release, many things have been updated in the package like names of resources and indicators, so we would recommend you to install the development version of the package using: remotes::install_github("mapme-initiative/mapme.biodiversity").

And we can always check which indicators and resources are available in the current loaded version of mapme.biodiversity by: names(available_resources()) names(available_indicators())

fBedecarrats commented 2 years ago

Thanks a lot @Ohm-Np , it works indeed. I think had tried with resource = "nelson_et_al" with the CRAN version of {mapme.biodiversity}, but I'm not sure anymore. I'm closing the issue. Don't you think it would be useful to rename "nelson_et_al" to designate the name of the dataset instead of its authors? (eg. we have "gfw_lossyear" and not "hansen_et_al")