tylermorganwall / rayshader

R Package for 2D and 3D mapping and data visualization
https://www.rayshader.com/
2.06k stars 214 forks source link

Error in rayimage::plot_image [BUG] #299

Closed pmlefeuvre-met closed 10 months ago

pmlefeuvre-met commented 11 months ago

Describe the bug Running the dem_01.tif example, render_snapshot() triggers the following error:

render_snapshot()
Error in rayimage::plot_image(tempmap, keep_user_par = keep_user_par,  : 
  unused argument (keep_user_par = keep_user_par)

The error does not stop an rgl window to open and plotting, but I expected it to be dispayed in my Rstudio plot panel. Removing keep_user_par = keep_user_par could solve the issue (pull request 300) as it is not used in rayimage::plot_image() since the last commit d02fbc2.

For info, I upgraded to the latest R this week causing my installation of rayshader via CRAN to fail plotting due to some image size issue. I therefore installed the dependencies and latest version of rayshader as recommended in your repo's README.

For others, if you get the error below, you are missing libglu1-mesa-dev libgl1-mesa-dev

 render_snapshot()
Error in png::writePNG(newarray, temp) : libpng error: Invalid IHDR data
In addition: Warning message:
In png::writePNG(newarray, temp) :
  libpng warning: Image width is zero in IHDR

Session Info sessionInfo() R version 4.3.2 (2023-10-31) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 22.04.3 LTS

Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so; LAPACK version 3.10.0

locale: [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=nb_NO.UTF-8
[4] LC_COLLATE=en_GB.UTF-8 LC_MONETARY=nb_NO.UTF-8 LC_MESSAGES=en_GB.UTF-8
[7] LC_PAPER=nb_NO.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=nb_NO.UTF-8 LC_IDENTIFICATION=C

time zone: Europe/Oslo tzcode source: system (glibc)

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] rayshader_0.36.1 raster_3.6-26 sp_2.1-2

loaded via a namespace (and not attached): [1] utf8_1.2.4 generics_0.1.3 class_7.3-22 KernSmooth_2.23-22 lattice_0.22-5
[6] hms_1.1.3 digest_0.6.33 magrittr_2.0.3 rgl_1.2.9 grid_4.3.2
[11] iterators_1.0.14 fastmap_1.1.1 foreach_1.5.2 doParallel_1.0.17 jsonlite_1.8.8
[16] progress_1.2.3 e1071_1.7-14 DBI_1.1.3 fansi_1.0.6 scales_1.3.0
[21] codetools_0.2-19 cli_3.6.2 rlang_1.1.2 crayon_1.5.2 units_0.8-5
[26] munsell_0.5.0 base64enc_0.1-3 tools_4.3.2 parallel_4.3.2 rayimage_0.10.0
[31] dplyr_1.1.4 colorspace_2.1-0 png_0.1-8 vctrs_0.6.5 R6_2.5.1
[36] magick_2.8.1 proxy_0.4-27 lifecycle_1.0.4 classInt_0.4-10 htmlwidgets_1.6.4 [41] pkgconfig_2.0.3 terra_1.7-55 pillar_1.9.0 glue_1.6.2 Rcpp_1.0.11
[46] sf_1.0-14 xfun_0.41 tibble_3.2.1 tidyselect_1.2.0 rstudioapi_0.15.0 [51] knitr_1.45 htmltools_0.5.7 compiler_4.3.2 prettyunits_1.2.0

Reproducible Example

devtools::install_github("tylermorganwall/rayshader",force = T)
.rs.restartR()

library(rayshader)

#Here, I load a map with the raster package.
loadzip = tempfile() 
download.file("https://tylermw.com/data/dem_01.tif.zip", loadzip)

localtif = raster::raster(unzip(loadzip, "dem_01.tif"))
unlink(loadzip)

#And convert it to a matrix:
elmat = raster_to_matrix(localtif)

elmat %>%
+   sphere_shade(texture = "desert") %>%
+   add_water(detect_water(elmat), color = "desert") %>%
+   add_shadow(ray_shade(elmat, zscale = 3), 0.5) %>%
+   add_shadow(ambient_shade(elmat), 0) %>%
+   plot_3d(elmat, zscale = 10, fov = 0, theta = 135, zoom = 0.75, phi = 45, windowsize = c(1000, 800))
Sys.sleep(0.2)                                                                                            
render_snapshot()

Thanks for your help and what a fantastic package! I use rayshader to plot the terrain around our weather stations, it really helps us visualise and assess how representative is the station. I enjoy finding more applications to rayshader.

Cheers,

PiM

onurkurum commented 10 months ago

pmlefeuvre-met Solution works thank you.

richardtc commented 10 months ago

Hi, I'm also getting the same error when I attempt to run the above example. I've updated the Rayshader package with devtools.

I'm running this in RStudio Server - is this an issue?

I also run: options(rgl.useNULL = FALSE)

> render_snapshot()
Error in rayimage::plot_image(tempmap, keep_user_par = keep_user_par,  : 
 unused argument (keep_user_par = keep_user_par)

Here is my sessionInfo()

 version  R version 4.3.2 (2023-10-31)
 os       Ubuntu 22.04.3 LTS
 system   x86_64, linux-gnu
 ui       RStudio
 language (EN)
 collate  C.UTF-8
 ctype    C.UTF-8
 tz       Asia/Bangkok
 date     2024-01-06
 rstudio  2023.09.1+494 Desert Sunflower (server)
 pandoc   3.1.1 @ /usr/lib/rstudio-server/bin/quarto/bin/tools/ (via rmarkdown)

─ Packages 
 package       * version date (UTC) lib source
 base64enc       0.1-3   2015-07-28 [1] RSPM (R 4.3.0)
 bookdown        0.36    2023-10-16 [1] RSPM (R 4.3.1)
 cachem          1.0.8   2023-05-01 [1] RSPM (R 4.3.0)
 class           7.3-22  2023-05-03 [1] RSPM (R 4.3.0)
 classInt        0.4-10  2023-09-05 [1] RSPM (R 4.3.0)
 cli             3.6.2   2023-12-11 [1] RSPM (R 4.3.0)
 codetools       0.2-19  2023-02-01 [1] RSPM (R 4.3.0)
 colorspace      2.1-0   2023-01-23 [1] RSPM (R 4.3.0)
 crayon          1.5.2   2022-09-29 [1] RSPM (R 4.3.0)
 data.table      1.14.10 2023-12-08 [1] RSPM (R 4.3.0)
 DBI             1.2.0   2023-12-21 [1] RSPM (R 4.3.0)
 devtools      * 2.4.5   2022-10-11 [1] RSPM (R 4.3.0)
 digest          0.6.33  2023-07-07 [1] RSPM (R 4.3.0)
 doParallel      1.0.17  2022-02-07 [1] RSPM (R 4.3.0)
 dplyr           1.1.4   2023-11-17 [1] RSPM (R 4.3.0)
 e1071           1.7-14  2023-12-06 [1] RSPM (R 4.3.0)
 ellipsis        0.3.2   2021-04-29 [1] RSPM (R 4.3.0)
 evaluate        0.23    2023-11-01 [1] RSPM (R 4.3.0)
 fansi           1.0.6   2023-12-08 [1] RSPM (R 4.3.0)
 fastmap         1.1.1   2023-02-24 [1] RSPM (R 4.3.0)
 foreach         1.5.2   2022-02-02 [1] RSPM (R 4.3.0)
 fs              1.6.3   2023-07-20 [1] RSPM (R 4.3.0)
 gdalUtilities * 1.2.5   2023-08-10 [1] RSPM (R 4.3.0)
 generics        0.1.3   2022-07-05 [1] RSPM (R 4.3.0)
 glue            1.6.2   2022-02-24 [1] RSPM (R 4.3.0)
 hms             1.1.3   2023-03-21 [1] RSPM (R 4.3.0)
 htmltools       0.5.7   2023-11-03 [1] RSPM (R 4.3.0)
 htmlwidgets     1.6.4   2023-12-06 [1] RSPM (R 4.3.0)
 httpuv          1.6.12  2023-10-23 [1] RSPM (R 4.3.0)
 iterators       1.0.14  2022-02-05 [1] RSPM (R 4.3.0)
 jsonlite        1.8.8   2023-12-04 [1] RSPM (R 4.3.0)
 KernSmooth      2.23-22 2023-07-10 [1] RSPM (R 4.3.0)
 knitr           1.45    2023-10-30 [1] RSPM (R 4.3.0)
 later           1.3.1   2023-05-02 [1] RSPM (R 4.3.0)
 lattice         0.22-5  2023-10-24 [1] RSPM (R 4.3.0)
 lifecycle       1.0.4   2023-11-07 [1] RSPM (R 4.3.0)
 lubridate       1.9.3   2023-09-27 [1] RSPM (R 4.3.0)
 magick          2.8.1   2023-10-22 [1] RSPM (R 4.3.0)
 magrittr        2.0.3   2022-03-30 [1] RSPM (R 4.3.0)
 memoise         2.0.1   2021-11-26 [1] RSPM (R 4.3.0)
 mime            0.12    2021-09-28 [1] RSPM (R 4.3.0)
 miniUI          0.1.1.1 2018-05-18 [1] RSPM (R 4.3.0)
 munsell         0.5.0   2018-06-12 [1] RSPM (R 4.3.0)
 pillar          1.9.0   2023-03-22 [1] RSPM (R 4.3.0)
 pkgbuild        1.4.3   2023-12-10 [1] RSPM (R 4.3.0)
 pkgconfig       2.0.3   2019-09-22 [1] RSPM (R 4.3.0)
 pkgload         1.3.3   2023-09-22 [1] RSPM (R 4.3.0)
 png             0.1-8   2022-11-29 [1] RSPM (R 4.3.0)
 prettyunits     1.2.0   2023-09-24 [1] RSPM (R 4.3.0)
 profvis         0.3.8   2023-05-02 [1] RSPM (R 4.3.0)
 progress        1.2.3   2023-12-06 [1] RSPM (R 4.3.0)
 promises        1.2.1   2023-08-10 [1] RSPM (R 4.3.0)
 proxy           0.4-27  2022-06-09 [1] RSPM (R 4.3.0)
 purrr           1.0.2   2023-08-10 [1] RSPM (R 4.3.0)
 R6              2.5.1   2021-08-19 [1] RSPM (R 4.3.0)
 raster          3.6-26  2023-10-14 [1] RSPM (R 4.3.0)
 rayimage      * 0.10.0  2024-01-06 [1] Github (tylermorganwall/rayimage@8497883)
 rayshader     * 0.36.1  2024-01-06 [1] Github (tylermorganwall/rayshader@81f95cf)
 rayvertex       0.10.4  2024-01-02 [1] Github (tylermorganwall/rayvertex@a352f40)
 Rcpp            1.0.11  2023-07-06 [1] RSPM (R 4.3.0)
 remotes         2.4.2.1 2023-07-18 [1] RSPM (R 4.3.0)
 renv            1.0.3   2023-09-19 [1] RSPM (R 4.3.1)
 rgl             1.2.9   2024-01-02 [1] Github (dmurdoch/rgl@bee93ad)
 rlang           1.1.2   2023-11-04 [1] RSPM (R 4.3.0)
 rmarkdown       2.25    2023-09-18 [1] RSPM (R 4.3.0)
 rstudioapi      0.15.0  2023-07-07 [1] RSPM (R 4.3.0)
 scales          1.3.0   2023-11-28 [1] RSPM (R 4.3.0)
 sessioninfo     1.2.2   2021-12-06 [1] RSPM (R 4.3.0)
 sf              1.0-15  2023-12-24 [1] Github (r-spatial/sf@c880270)
 shiny           1.8.0   2023-11-17 [1] RSPM (R 4.3.0)
 sp              2.1-2   2023-11-26 [1] RSPM (R 4.3.0)
 stringi         1.8.3   2023-12-11 [1] RSPM (R 4.3.0)
 stringr         1.5.1   2023-11-14 [1] RSPM (R 4.3.0)
 suncalc       * 0.5.1   2022-09-29 [1] RSPM (R 4.3.0)
 terra         * 1.7-67  2024-01-01 [1] https://rspatial.r-universe.dev (R 4.3.2)
 tibble          3.2.1   2023-03-20 [1] RSPM (R 4.3.0)
 tidyselect      1.2.0   2022-10-10 [1] RSPM (R 4.3.0)
 timechange      0.2.0   2023-01-11 [1] RSPM (R 4.3.0)
 units           0.8-5   2023-11-28 [1] RSPM (R 4.3.0)
 urlchecker      1.0.1   2021-11-30 [1] RSPM (R 4.3.0)
 usethis       * 2.2.2   2023-07-06 [1] RSPM (R 4.3.0)
 utf8            1.2.4   2023-10-22 [1] RSPM (R 4.3.0)
 vctrs           0.6.5   2023-12-01 [1] RSPM (R 4.3.0)
 xfun            0.41    2023-11-01 [1] RSPM (R 4.3.0)
 xtable          1.8-4   2019-04-21 [1] RSPM (R 4.3.0)
 yaml            2.3.8   2023-12-11 [1] RSPM (R 4.3.0)
richardtc commented 10 months ago

I see the commit hasn't been approved yet. I modified the render_snapshot.R file and reinstalled as a local package and the render_snapshot() now works.

tylermorganwall commented 10 months ago

This has been fixed in the latest release.