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

Errors with vrt and warnings on unavailable resources with get_worldclim_precipitation and calc_precipitation_wc #302

Closed fBedecarrats closed 2 months ago

fBedecarrats commented 3 months ago

Hello, I'm runnning into some errors when running get_worldclim_precipitation and calc_precipitation_wc. The following code:

library(tidyverse)
library(sf)
library(mapme.biodiversity) # This is CRAN version
library(geodata)

mada <- gadm("Madagascar", level = 0, resolution = 2, path = ".")
mada_dt <- mada %>%
  st_as_sf() %>%
  st_cast("POLYGON")

mada_dt <- mada_dt %>%
  get_resources(get_worldclim_precipitation(years = 2000:2023)) %>%
  calc_indicators(calc_precipitation_wc(engine = "extract", stats = "mean"))

produces the following errors:

Some target years are not available for prec.
Found a column named 'assetid'. Overwritting its values with a unique identifier.
Error in (function (.x, .y, .f, ..., .progress = FALSE)  : 
  ℹ In index: 1.
Caused by error:
ℹ In index: 1.
Caused by error in `purrr::map()`:
ℹ In index: 1.
Caused by error:
! [vrt] cannot create vrt. Error #0
In addition: Warning messages:
1: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :
  GDAL Message 1: HTTP response code on https://biogeo.ucdavis.edu/data/worldclim/v2.1/hist/wc2.1_2.5m_prec_2000-2009.zip: 0
2: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :
  GDAL Message 1: HTTP response code on https://biogeo.ucdavis.edu/data/worldclim/v2.1/hist/wc2.1_2.5m_prec_2010-2018.zip: 0
3: In r@ptr$make_vrt(x, options, opt) :
  GDAL Error 4: /tmp/RtmpHHOenM/file94d2b521153/worldclim_precipitation/wc2.1_2.5m_prec_2000-01.tif: No such file or directory
4: In r@ptr$make_vrt(x, options, opt) :
  GDAL Message 1: Can't open /tmp/RtmpHHOenM/file94d2b521153/worldclim_precipitation/wc2.1_2.5m_prec_2000-01.tif. Skipping it
goergen95 commented 3 months ago

Hmm, the source seems to be unavailable. To me, this looks like a good opportunity to re-work the WorldClim resources/indicators to support any of the data sets listed here. Not sure yet when I will be able to do this.

Since you seem to be experimenting with the latest changes to the package I have some comments:

fBedecarrats commented 3 months ago

Well received, thanks!

duboisl-afd commented 2 months ago

Hi, I have the same error message when running get_nelson_et_al and calc_traveltime. Here is the error message I get when running this code :

 library(sf)
 library(mapme.biodiversity)
 outdir <- file.path(tempdir(), "mapme-data")
dir.create(outdir, showWarnings = FALSE)

 mapme_options(
     outdir = outdir,
    verbose = FALSE
 )

 aoi <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg",
                    package = "mapme.biodiversity"
 ) %>%
   read_sf() %>%
   get_resources(get_nelson_et_al()) 
Error in sf::gdal_utils(util = util, source = source, destination = destination,  : 
  gdal_utils translate: an error occured
Warning messages:
1: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :
  GDAL Error 1: TIFFFillStrip:Read error at scanline 9930; got 0 bytes, expected 19850
2: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :
  GDAL Error 1: TIFFReadEncodedStrip() failed.
3: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :
  GDAL Error 1: /vsicurl/https://figshare.com/ndownloader/files/14189831, band 1: IReadBlock failed at X offset 0, Y offset 9931: TIFFReadEncodedStrip() failed.
goergen95 commented 2 months ago

Hi @fBedecarrats, just merged #317 with which we now support different resolution for the whole historical timeseries from 1960-2021. FYI, please also find PR #318, which is going to add precipitation data from CHELSA which is reported to have lower biases in areas of high altitude and low gauge station density.

fBedecarrats commented 2 months ago

This is great! Thanks @goergen95 !

fBedecarrats commented 1 month ago

Just to report after re-implementing this: it works now! Many thanks @goergen95 ! A note : I think that the documentation on the corresponding resource and indicator would need more details. I'll propose something (not now).

goergen95 commented 1 month ago

Glad to hear that it works! Looking forward to your contribution. :+1:

On a related note, I am looking forward to harmonize the different precipitation indicators. I am dissatisfied with the current solution and am planning to calculate area-weighted average precipitation via exactextractr. Would love to hear your suggestions, but I'd guess a dedicated issue or a discussion would be the right place.