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

worldpop indicator #319

Closed KornTob closed 2 months ago

KornTob commented 2 months ago

Hi all, thanks for the mapme update! I'm unfortunately still running into problems when calculating the worldpop indicator. I get this error message:

versuche URL 'https://data.worldpop.org/GIS/Population/Global_2000_2020/2000/0_Mosaicked/ppp_2000_1km_Aggregated.tif' Content type 'image/tiff' length 1165526326 bytes (1111.5 MB) downloaded 1111.5 MB

Error in map2(.x, .y, .f, ..., .progress = .progress) : ℹ In index: 1. Caused by error in sf::gdal_utils(): ! gdal_utils translate: an error occured

This is the code I am using:

## Select Resources:  
options(timeout = 1000)
sources <- get_resources(x=mdg_grid, 
                         get_worldpop(years = 2000))

The object "mdg_grid" is a grid-shapefile for madagascar.

Am I doing something wrong here? The code worked great for computing other resources.

Thanks!

goergen95 commented 2 months ago

I am really sorry your are still experiencing this issue. Any chance you are running on Windows? If so, could you please try with this branch installed?

remotes::install_github("mapme-initiative/mapme.biodiversity", ref = "fix-worldpop")` 
KornTob commented 2 months ago

Hi Darius,

thanks for the quick response! I tried it again after installing the developer version, but get the same(?) error:

Error in map2(.x, .y, .f, ..., .progress = .progress) : 

  ℹ In index: 1.

Caused by error in `sf::gdal_utils()`:

! gdal_utils translate: an error occured

Zusätzlich: Warnmeldungen:

1: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :

  GDAL Message 1: C:\Users\Korn\AppData\Local\Temp\Rtmp2nsQ55\file4584440d48fc.tif: TIFFFetchNormalTag:ASCII value for tag "GDALMetadata" contains null byte in value; value incorrectly truncated during reading due to implementation limitations

2: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :

  GDAL Error 1: TIFFFetchDirectory:Sanity check on directory count failed, this is probably not a valid IFD offset

3: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :

  GDAL Error 1: TIFFReadDirectory:Failed to read directory at offset 867355646

4: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :

  GDAL Message 1: TIFFFetchNormalTag:ASCII value for tag "GDALMetadata" contains null byte in value; value incorrectly truncated during reading due to implementation limitations

5: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :

  GDAL Message 1: C:\Users\Korn\AppData\Local\Temp\Rtmp2nsQ55\file4584440d48fc.tif: GeoTIFF tags apparently corrupt, they are being ignored.

6: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :

  GDAL Error 1: TIFFFillTile:Read error at row 4294967295, col 4294967295, tile 0; got 0 bytes, expected 1865

7: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :

  GDAL Error 1: TIFFReadEncodedTile() failed.

8: In CPL_gdaltranslate(source, destination, options, oo, config_options,  :

  GDAL Error 1: C:\Users\Korn\AppData\Local\Temp\Rtmp2nsQ55\file4584440d48fc.tif, band 1: IReadBlock failed at X offset 0, Y offset 0: TIFFReadEncodedTile() failed.

Fehler in .check_footprints(resource, resource_name) : 

  Download for resource worldpop failed.

Returning unmodified portfolio.

I also tried running my script on another tower computer with stable internet. Weirdly enough, I get a new error there. I it seems to fail already before downloading any resources:

CRS of x is not EPSG:4326. Attempting to transform.

Fehler in if (is_http) { : Argument hat Länge 0

I’m running the same code as I posted on github on both computers, so I can’t explain where this is coming from. Any idea?

Best,

Tobias

Von: Darius Görgen @.> Gesendet: Freitag, 2. August 2024 09:02 An: mapme-initiative/mapme.biodiversity @.> Cc: KornTob @.>; Author @.> Betreff: [extern] Re: [mapme-initiative/mapme.biodiversity] worldpop indicator (Issue #319)

I am really sorry your are still experiencing this issue. Any chance you are running on Windows? If so, could you please try with this branch installed?

remotes::install_github("mapme-initiative/mapme.biodiversity", ref = "fix-worldpop")`

— Reply to this email directly, view it on GitHub https://github.com/mapme-initiative/mapme.biodiversity/issues/319#issuecomment-2264704585 , or unsubscribe https://github.com/notifications/unsubscribe-auth/BHDICNAOBZSFYYRH3EWPH2DZPMVE7AVCNFSM6AAAAABL32GJESVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRUG4YDINJYGU . You are receiving this because you authored the thread.Message ID: @.***>

goergen95 commented 2 months ago

I do not have access to your data. You could either share your data or use a geometry we all have access to in order to reproduce, e.g.:

read_sf(system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity"))

Could you also please report versions of GDAL, GEOS, PROJ? Either via library(sf) in a new R session or via sf::sf_extSoftVersion()

goergen95 commented 2 months ago

Please run the following code (you might need to install the {reprex} and {remotes} packages) and post your output here:

reprex::reprex({

  remotes::install_github("mapme-initiative/mapme.biodiversity", ref = "fix-worldpop")
  library(mapme.biodiversity)
  library(magrittr)
  library(sf)
  sf_extSoftVersion()

  options(timeout = 1000)
  x <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>%
    read_sf() %>% 
    get_resources(get_worldpop(years = 2000)) %>%
    calc_indicators(calc_population_count(engine = "extract", stats = "sum"))

  x$population_count

}, session_info = TRUE)
KornTob commented 2 months ago

Thank you. Here is the Output from running the code you suggested:

remotes::install_github("mapme-initiative/mapme.biodiversity", ref = "fix-worldpop")

> Downloading GitHub repo @.***

> rlang (1.1.3 -> 1.1.4 ) [CRAN]

> cli (3.6.2 -> 3.6.3 ) [CRAN]

> withr (3.0.0 -> 3.0.1 ) [CRAN]

> Rcpp (1.0.12 -> 1.0.13) [CRAN]

> wk (0.9.1 -> 0.9.2 ) [CRAN]

> parallelly (1.37.1 -> 1.38.0) [CRAN]

> digest (0.6.35 -> 0.6.36) [CRAN]

> s2 (1.1.6 -> 1.1.7 ) [CRAN]

> DBI (1.2.2 -> 1.2.3 ) [CRAN]

> openssl (2.1.2 -> 2.2.0 ) [CRAN]

> future (1.33.2 -> 1.34.0) [CRAN]

> terra (1.7-71 -> 1.7-78) [CRAN]

> Installing 12 packages: rlang, cli, withr, Rcpp, wk, parallelly, digest, s2, DBI, openssl, future, terra

> Installiere Pakete nach 'C:/Users/Korn/AppData/Local/R/win-library/4.4'

> (da 'lib' nicht spezifiziert)

> Paket 'rlang' erfolgreich ausgepackt und MD5 Summen abgeglichen

> Warning: kann alte Installation von Paket 'rlang' nicht entfernen

> Warning in file.copy(savedcopy, lib, recursive = TRUE): Problem

> C:\Users\Korn\AppData\Local\R\win-library\4.4\00LOCK\rlang\libs\x64\rlang.dll

> nach C:\Users\Korn\AppData\Local\R\win-library\4.4\rlang\libs\x64\rlang.dll zu

> kopieren: Permission denied

> Warning: 'rlang' wiederhergestellt

> Paket 'cli' erfolgreich ausgepackt und MD5 Summen abgeglichen

> Warning: kann alte Installation von Paket 'cli' nicht entfernen

> Warning in file.copy(savedcopy, lib, recursive = TRUE): Problem

> C:\Users\Korn\AppData\Local\R\win-library\4.4\00LOCK\cli\libs\x64\cli.dll nach

> C:\Users\Korn\AppData\Local\R\win-library\4.4\cli\libs\x64\cli.dll zu kopieren:

> Permission denied

> Warning: 'cli' wiederhergestellt

> Paket 'withr' erfolgreich ausgepackt und MD5 Summen abgeglichen

> Paket 'Rcpp' erfolgreich ausgepackt und MD5 Summen abgeglichen

> Warning: kann alte Installation von Paket 'Rcpp' nicht entfernen

> Warning in file.copy(savedcopy, lib, recursive = TRUE): Problem

> C:\Users\Korn\AppData\Local\R\win-library\4.4\00LOCK\Rcpp\libs\x64\Rcpp.dll

> nach C:\Users\Korn\AppData\Local\R\win-library\4.4\Rcpp\libs\x64\Rcpp.dll zu

> kopieren: Permission denied

> Warning: 'Rcpp' wiederhergestellt

> Paket 'wk' erfolgreich ausgepackt und MD5 Summen abgeglichen

> Paket 'parallelly' erfolgreich ausgepackt und MD5 Summen abgeglichen

> Paket 'digest' erfolgreich ausgepackt und MD5 Summen abgeglichen

> Warning: kann alte Installation von Paket 'digest' nicht entfernen

> Warning in file.copy(savedcopy, lib, recursive = TRUE): Problem

> C:\Users\Korn\AppData\Local\R\win-library\4.4\00LOCK\digest\libs\x64\digest.dll

> nach C:\Users\Korn\AppData\Local\R\win-library\4.4\digest\libs\x64\digest.dll

> zu kopieren: Permission denied

> Warning: 'digest' wiederhergestellt

> Paket 's2' erfolgreich ausgepackt und MD5 Summen abgeglichen

> Paket 'DBI' erfolgreich ausgepackt und MD5 Summen abgeglichen

> Paket 'openssl' erfolgreich ausgepackt und MD5 Summen abgeglichen

> Paket 'future' erfolgreich ausgepackt und MD5 Summen abgeglichen

> Paket 'terra' erfolgreich ausgepackt und MD5 Summen abgeglichen

> Warning: kann alte Installation von Paket 'terra' nicht entfernen

> Warning in file.copy(savedcopy, lib, recursive = TRUE): Problem

> C:\Users\Korn\AppData\Local\R\win-library\4.4\00LOCK\terra\libs\x64\terra.dll

> nach C:\Users\Korn\AppData\Local\R\win-library\4.4\terra\libs\x64\terra.dll zu

> kopieren: Permission denied

> Warning: 'terra' wiederhergestellt

>

> Die heruntergeladenen Binärpakete sind in

> C:\Users\Korn\AppData\Local\Temp\Rtmpkbmk5Q\downloaded_packages

> ── R CMD build ─────────────────────────────────────────────────────────────────

> checking for file 'C:\Users\Korn\AppData\Local\Temp\Rtmpkbmk5Q\remotes4df87c061aea\mapme-initiative-mapme.biodiversity-b4c06ab/DESCRIPTION' ... ✔ checking for file 'C:\Users\Korn\AppData\Local\Temp\Rtmpkbmk5Q\remotes4df87c061aea\mapme-initiative-mapme.biodiversity-b4c06ab/DESCRIPTION' (466ms)

> ─ preparing 'mapme.biodiversity': (1.3s)

> checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... ✔ checking DESCRIPTION meta-information

> ─ checking for LF line-endings in source and make files and shell scripts (691ms)

> ─ checking for empty or unneeded directories

> ─ building 'mapme.biodiversity_0.8.0.9007.tar.gz'

>

>

> Installiere Paket nach 'C:/Users/Korn/AppData/Local/R/win-library/4.4'

> (da 'lib' nicht spezifiziert)

library(mapme.biodiversity)

library(magrittr)

library(sf)

> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE

sf_extSoftVersion()

> GEOS GDAL proj.4 GDAL_with_GEOS USE_PROJ_H

> "3.12.1" "3.8.4" "9.3.1" "true" "true"

> PROJ

> "9.3.1"

options(timeout = 1000)

x <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>%

read_sf() %>% 

get_resources(get_worldpop(years = 2000)) %>%

calc_indicators(calc_population_count(engine = "extract", stats = "sum"))

>

> Attache Paket: 'purrr'

> Das folgende Objekt ist maskiert 'package:magrittr':

>

> set_names

x$population_count

> [[1]]

> # A tibble: 1 × 4

> datetime variable unit value

>

> 1 2000-01-01 00:00:00 population_sum count 5356.

Created on 2024-08-02 with reprex v2.1.1

Session info

sessioninfo::session_info()

> ─ Session info ───────────────────────────────────────────────────────────────

> setting value

> version R version 4.4.1 (2024-06-14 ucrt)

> os Windows 10 x64 (build 19045)

> system x86_64, mingw32

> ui RTerm

> language (EN)

> collate German_Germany.utf8

> ctype German_Germany.utf8

> tz Europe/Berlin

> date 2024-08-02

> pandoc 3.1.11 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)

>

> ─ Packages ───────────────────────────────────────────────────────────────────

> ! package * version date (UTC) lib source

> callr 3.7.6 2024-03-25 [1] CRAN (R 4.4.0)

> class 7.3-22 2023-05-03 [2] CRAN (R 4.4.1)

> classInt 0.4-10 2023-09-05 [1] CRAN (R 4.4.0)

> cli 3.6.2 2023-12-11 [1] CRAN (R 4.4.0)

> codetools 0.2-20 2024-03-31 [2] CRAN (R 4.4.1)

> curl 5.2.1 2024-03-01 [1] CRAN (R 4.4.0)

> DBI 1.2.3 2024-06-02 [1] CRAN (R 4.4.1)

> desc 1.4.3 2023-12-10 [1] CRAN (R 4.4.0)

> digest 0.6.35 2024-03-11 [1] CRAN (R 4.4.0)

> dplyr 1.1.4 2023-11-17 [1] CRAN (R 4.4.0)

> e1071 1.7-14 2023-12-06 [1] CRAN (R 4.4.0)

> evaluate 0.23 2023-11-01 [1] CRAN (R 4.4.0)

> fansi 1.0.6 2023-12-08 [1] CRAN (R 4.4.0)

> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.4.0)

> fs 1.6.4 2024-04-25 [1] CRAN (R 4.4.0)

> furrr 0.3.1 2022-08-15 [1] CRAN (R 4.4.0)

> future 1.34.0 2024-07-29 [1] CRAN (R 4.4.1)

> generics 0.1.3 2022-07-05 [1] CRAN (R 4.4.0)

> globals 0.16.3 2024-03-08 [1] CRAN (R 4.4.0)

> glue 1.7.0 2024-01-09 [1] CRAN (R 4.4.0)

> htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.4.0)

> httr 1.4.7 2023-08-15 [1] CRAN (R 4.4.0)

> jsonlite 1.8.8 2023-12-04 [1] CRAN (R 4.4.0)

> KernSmooth 2.23-22 2023-07-10 [1] CRAN (R 4.4.0)

> knitr 1.46 2024-04-06 [1] CRAN (R 4.4.0)

> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.4.0)

> listenv 0.9.1 2024-01-29 [1] CRAN (R 4.4.0)

> magrittr * 2.0.3 2022-03-30 [1] CRAN (R 4.4.0)

> mapme.biodiversity * 0.8.0.9007 2024-08-02 [1] Github @.***)

> parallelly 1.38.0 2024-07-27 [1] CRAN (R 4.4.1)

> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.4.0)

> pkgbuild 1.4.4 2024-03-17 [1] CRAN (R 4.4.0)

> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.4.0)

> processx 3.8.4 2024-03-16 [1] CRAN (R 4.4.0)

> progressr 0.14.0 2023-08-10 [1] CRAN (R 4.4.1)

> proxy 0.4-27 2022-06-09 [1] CRAN (R 4.4.0)

> ps 1.7.6 2024-01-18 [1] CRAN (R 4.4.0)

> purrr * 1.0.2 2023-08-10 [1] CRAN (R 4.4.0)

> R6 2.5.1 2021-08-19 [1] CRAN (R 4.4.0)

> Rcpp 1.0.12 2024-01-09 [1] CRAN (R 4.4.0)

> remotes 2.5.0 2024-03-17 [1] CRAN (R 4.4.1)

> reprex 2.1.1 2024-07-06 [1] CRAN (R 4.4.1)

> rlang 1.1.3 2024-01-10 [1] CRAN (R 4.4.0)

> rmarkdown 2.26 2024-03-05 [1] CRAN (R 4.4.0)

> rstudioapi 0.16.0 2024-03-24 [1] CRAN (R 4.4.0)

> s2 1.1.7 2024-07-17 [1] CRAN (R 4.4.1)

> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.4.0)

> sf * 1.0-16 2024-03-24 [1] CRAN (R 4.4.0)

> terra 1.7-71 2024-01-31 [1] CRAN (R 4.4.0)

> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.4.0)

> tidyr 1.3.1 2024-01-24 [1] CRAN (R 4.4.0)

> tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.4.0)

> units 0.8-5 2023-11-28 [1] CRAN (R 4.4.0)

> utf8 1.2.4 2023-10-22 [1] CRAN (R 4.4.0)

> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.4.0)

> V withr 3.0.0 2024-07-31 [1] CRAN (R 4.4.1) (on disk 3.0.1)

> wk 0.9.2 2024-07-09 [1] CRAN (R 4.4.1)

> xfun 0.43 2024-03-25 [1] CRAN (R 4.4.0)

> yaml 2.3.8 2023-12-11 [1] CRAN (R 4.4.0)

>

> [1] C:/Users/Korn/AppData/Local/R/win-library/4.4

> [2] C:/Program Files/R/R-4.4.1/library

>

> V ── Loaded and on-disk version mismatch.

>

> ──────────────────────────────────────────────────────────────────────────────

Von: Darius Görgen @.> Gesendet: Freitag, 2. August 2024 11:38 An: mapme-initiative/mapme.biodiversity @.> Cc: KornTob @.>; Author @.> Betreff: [extern] Re: [mapme-initiative/mapme.biodiversity] worldpop indicator (Issue #319)

Please run the following code (you might need to install the {reprex} and {remotes} packages) and post your output here:

reprex::reprex({

remotes::install_github("mapme-initiative/mapme.biodiversity", ref = "fix-worldpop") library(mapme.biodiversity) library(magrittr) library(sf) sf_extSoftVersion()

options(timeout = 1000) x <- system.file("extdata", "sierra_de_neiba_478140_2.gpkg", package = "mapme.biodiversity") %>% read_sf() %>% get_resources(get_worldpop(years = 2000)) %>% calc_indicators(calc_population_count(engine = "extract", stats = "sum"))

x$population_count

}, session_info = TRUE)

— Reply to this email directly, view it on GitHub https://github.com/mapme-initiative/mapme.biodiversity/issues/319#issuecomment-2264976013 , or unsubscribe https://github.com/notifications/unsubscribe-auth/BHDICNDWELWQ7PQNL5V74DLZPNHOBAVCNFSM6AAAAABL32GJESVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRUHE3TMMBRGM . You are receiving this because you authored the thread.Message ID: @.***>

goergen95 commented 2 months ago

Thanks!

There seem to be some artifacts of failed package installations in your library. If you wanted to update your packages you can head over to C:\Users\Korn\AppData\Local\R\win-library\4.4\ and manually delete directories starting with 00LOCK.

But, this does not seem the cause of the issue, since the resource download and indicator calculation runs successfully for the example code. In your real code, can you make sure you have write permissions to the value set by mapme_options(outdir="")?

At least the get_resource() step for worldpop should not directly be related to the features in x (e.g. invalid geometries). We currently assume EPSG:4326 for portfolios, so you might have to transform beforehand.

You said your real data is a grid on Madagscar? I adapted the example code, can you please run and share the output?

reprex::reprex({

  remotes::install_github("mapme-initiative/mapme.biodiversity", ref = "fix-worldpop", upgrade = FALSE)
  library(mapme.biodiversity)
  library(geodata)
  library(magrittr)
  library(sf)
  sf_extSoftVersion()

  world <- st_as_sf(geodata::world(path=tempdir()))
  mdg <- subset(world, NAME_0 == "Madagascar")
  mdg <- st_make_valid(mdg)
  grid <- st_sf(geometry = st_make_grid(mdg, n = c(4, 4)))
  grid <- st_intersection(grid, mdg)

  options(timeout = 1000)
  grid <- grid %>%
    get_resources(get_worldpop(years = 2000)) %>%
    calc_indicators(calc_population_count(engine = "exactextract", stats = "sum"))

  head(grid$population_count, 5)

}, session_info = TRUE)
KornTob commented 2 months ago

Hi Darius,

thanks for checking. Yes, I have writing permission for the directory I specify in outdir. I also tried setting EPSG = 4326 before using the get_resources() function, but this also didn’t help it. But the get_resources() function returns the message that it is converting my grid to 4326, so should be fine either way.

That is right, I use a Madagascar grid. Thanks for the new code example, the output is below. It throws an error that apparently “mixed-type geometries” are not supported. Maybe this brings us closer to the issue? Note that in a first iteration, it returned (after running for hours) an error that the exactextractr package is not installed. Maybe this is also relevant – the output below comes from a second try after in installed the exactextractr package:

remotes::install_github("mapme-initiative/mapme.biodiversity", ref = "fix-worldpop", upgrade = FALSE)

> Downloading GitHub repo @.***

> ── R CMD build ─────────────────────────────────────────────────────────────────

> checking for file 'C:\Users\Korn\AppData\Local\Temp\RtmpCoOPSI\remotes5e9835ca5949\mapme-initiative-mapme.biodiversity-441a11f/DESCRIPTION' ... checking for file 'C:\Users\Korn\AppData\Local\Temp\RtmpCoOPSI\remotes5e9835ca5949\mapme-initiative-mapme.biodiversity-441a11f/DESCRIPTION' ... ✔ checking for file 'C:\Users\Korn\AppData\Local\Temp\RtmpCoOPSI\remotes5e9835ca5949\mapme-initiative-mapme.biodiversity-441a11f/DESCRIPTION' (547ms)

> ─ preparing 'mapme.biodiversity': (1.3s)

> checking DESCRIPTION meta-information ... checking DESCRIPTION meta-information ... ✔ checking DESCRIPTION meta-information

> ─ checking for LF line-endings in source and make files and shell scripts (738ms)

> ─ checking for empty or unneeded directories

> ─ building 'mapme.biodiversity_0.8.0.9007.tar.gz'

>

>

> Installiere Paket nach 'C:/Users/Korn/AppData/Local/R/win-library/4.4'

> (da 'lib' nicht spezifiziert)

library(mapme.biodiversity)

library(geodata)

> Lade nötiges Paket: terra

> terra 1.7.71

library(magrittr)

>

> Attache Paket: 'magrittr'

> Die folgenden Objekte sind maskiert von 'package:terra':

>

> extract, inset

library(sf)

> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE

sf_extSoftVersion()

> GEOS GDAL proj.4 GDAL_with_GEOS USE_PROJ_H

> "3.12.1" "3.8.4" "9.3.1" "true" "true"

> PROJ

> "9.3.1"

world <- st_as_sf(geodata::world(path=tempdir()))

mdg <- subset(world, NAME_0 == "Madagascar")

mdg <- st_make_valid(mdg)

grid <- st_sf(geometry = st_make_grid(mdg, n = c(4, 4)))

grid <- st_intersection(grid, mdg)

> Warning: attribute variables are assumed to be spatially constant throughout

> all geometries

options(timeout = 1000)

grid <- grid %>%

get_resources(get_worldpop(years = 2000)) %>%

calc_indicators(calc_population_count(engine = "exactextract", stats = "sum"))

>

> Attache Paket: 'purrr'

> Das folgende Objekt ist maskiert 'package:magrittr':

>

> set_names

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

> Warning in .check_single_asset(result, chunk): Error in map(.x, .f, ...) : ℹ In index: 1.

> Caused by error:

> ! Mixed-type geometries not supported.

head(grid$population_count, 5)

> [[1]]

> # A tibble: 1 × 4

> datetime variable unit value

>

> 1 2000-01-01 00:00:00 population_sum count 754266.

>

> [[2]]

> # A tibble: 1 × 4

> datetime variable unit value

>

> 1 2000-01-01 00:00:00 population_sum count 856674.

>

> [[3]]

> # A tibble: 1 × 4

> datetime variable unit value

>

> 1 2000-01-01 00:00:00 population_sum count 762701.

>

> [[4]]

> # A tibble: 1 × 4

> datetime variable unit value

>

> 1 2000-01-01 00:00:00 population_sum count 333487.

>

> [[5]]

> # A tibble: 1 × 4

> datetime variable unit value

>

> 1 2000-01-01 00:00:00 population_sum count 1059866.

Created on 2024-08-09 with https://reprex.tidyverse.org/ reprex v2.1.1

Session info

Von: Darius Görgen @.> Gesendet: Mittwoch, 7. August 2024 12:39 An: mapme-initiative/mapme.biodiversity @.> Cc: KornTob @.>; Author @.> Betreff: [extern] Re: [mapme-initiative/mapme.biodiversity] worldpop indicator (Issue #319)

Thanks!

There seem to be some artifacts of failed package installations in your library. If you wanted to update your packages you can head over to C:\Users\Korn\AppData\Local\R\win-library\4.4\ and manually delete directories starting with 00LOCK.

But, this does not seem the cause of the issue, since the resource download and indicator calculation runs successfully for the example code. In your real code, can you make sure you have write permissions to the value set by mapme_options(outdir="")?

At least the get_resource() step for worldpop should not directly be related to the features in x (e.g. invalid geometries). We currently assume EPSG:4326 for portfolios, so you might have to transform beforehand.

You said your real data is a grid on Madagscar? I adapted the example code, can you please run and share the output?

reprex::reprex({

remotes::install_github("mapme-initiative/mapme.biodiversity", ref = "fix-worldpop", upgrade = FALSE) library(mapme.biodiversity) library(geodata) library(magrittr) library(sf) sf_extSoftVersion()

world <- st_as_sf(geodata::world(path=tempdir())) mdg <- subset(world, NAME_0 == "Madagascar") mdg <- st_make_valid(mdg) grid <- st_sf(geometry = st_make_grid(mdg, n = c(4, 4))) grid <- st_intersection(grid, mdg)

options(timeout = 1000) grid <- grid %>% get_resources(get_worldpop(years = 2000)) %>% calc_indicators(calc_population_count(engine = "exactextract", stats = "sum"))

head(grid$population_count, 5)

}, session_info = TRUE)

— Reply to this email directly, view it on GitHub https://github.com/mapme-initiative/mapme.biodiversity/issues/319#issuecomment-2273164078 , or unsubscribe https://github.com/notifications/unsubscribe-auth/BHDICNCMPHCOEXCGLLOYEADZQH2NRAVCNFSM6AAAAABL32GJESVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZTGE3DIMBXHA . You are receiving this because you authored the thread.Message ID: @.***>

goergen95 commented 2 months ago

Note that in a first iteration, it returned (after running for hours) an error that the exactextractr package is not installed.

Yes, my bad. We do not fail early in the case the package is not installed.

It is warnings you encounter for chunks of the input data which return invalid indicators. Consider increasing the chunk_size in mapme_options() (see details below).

Since you seem not to be able to reproduce your original issue, and in the light that it seems that you are now actually able to successfully get the data and calculate the indicator, I will close this issue now. Feel free to re-open this or another issue with a reproducible example, though.

A few general recommendations:

chunk_size <- max(as.numeric(st_area(grid))) / 10000 # in ha
mapme_options(chunk_size = chunk_size)