tylermorganwall / rayshader

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

Error in hillshade[, , 1] * scales::rescale(shadowmap, c(max_darken, 1)) - again #232

Closed gsapijaszko closed 2 years ago

gsapijaszko commented 2 years ago

Hi, facing a strange issue:

running the script/examples in RStudio:

elmat %>%
  sphere_shade(texture = "desert") %>%
  add_water(detect_water(elmat), color = "desert") %>%
  add_shadow(ray_shade(elmat), 0.5) %>%
  plot_map()

receiving the error:

Error in hillshade[, , 1] * scales::rescale(shadowmap, c(max_darken, 1)) :                                               
  non-conformable arrays

without any output in Plots tab.

However when I tried to prepare an reprex, I got quite expected response:

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)

#And we can add a raytraced layer from that sun direction as well:
elmat %>%
  sphere_shade(texture = "desert") %>%
  add_water(detect_water(elmat), color = "desert") %>%
  plot_map()

elmat %>%
  sphere_shade(texture = "desert") %>%
  add_water(detect_water(elmat), color = "desert") %>%
  add_shadow(ray_shade(elmat), 0.5) %>%
  plot_map()

Created on 2022-05-17 by the reprex package (v2.0.1)

which looks good. Is there any missing step/config which I shall process to get it working in script/console?

Regards, Grzegorz

PS.

> sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=pl_PL.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=pl_PL.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=pl_PL.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=pl_PL.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] shiny_1.7.1      rayshader_0.28.2
Pecners commented 2 years ago

I've been dealing with the same error today, but I finally solved it. I tried remotes::install_github(), but no dice. Then after messing around some more, I tried reinstalling from github again, this time updating rayimage as well -- that did the trick.

tylermorganwall commented 2 years ago

Check out the following issues for a solution:

https://github.com/tylermorganwall/rayshader/issues?q=is%3Aissue++non-conformable+arrays+