tylermorganwall / rayshader

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

3-d plot not centered, error subscript out of bounds #202

Closed plinthite closed 2 years ago

plinthite commented 2 years ago

Hi @tylermorganwall, Apologies if this is a 'user' issue rather than code -- when calling plot_3d using your tutorial code, everything works until plot_3d, then I receive the error below, and the center of the plot appears to be pinned to the top centre of the window, so always incomplete. I am running this on my own tif, and all steps prior to plot_3d worked. Thanks for looking at this.

3D mapping

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)) Error in [<-(*tmp*, i, j, value = (dnorm(power x[i], mean = 0, sd = sd) : subscript out of bounds
tylermorganwall commented 2 years ago

You will need to provide me a fully reproducible example to help: I do not have enough information to debug this issue with what you have provided me so far.

alabarga commented 2 years ago

I am facing the same problem, with the attached file rasters_COP90.tar.gz

localtif = raster::raster('./pamplona_COP90.tif')
elmat = raster_to_matrix(localtif)

this will render the map

elmat %>%
sphere_shade(texture = "desert") %>%
plot_map()

but any attempt to use plot3d

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)

with different params will raise error

Error in `[<-`(`*tmp*`, i, j, value = (dnorm(power * x[i], mean = 0, sd = sd) *  :                          
  subíndice fuera de  los límites

not sure if it is just a dimensions problem?

wiesehahn commented 2 years ago

not sure if this is the same, but in the last tim I also encountered error subscript out of bounds regularly. But in my case it was not while running plot_3d(), but afterwards when trying to render_highquality(). Running exactly the same code in the same environment again then worked magically from time to time.

tapiamcclung commented 2 years ago

Hi, I updated from R version 4.0.5 to version 4.1.3, both with rayshader version 0.27.2, and started getting this error. The 3D plot is shown, but when using the water = TRUE and waterdepth = 50 options, no water layer is rendered. It works in R 4.0.5. I have ran the exact same code in several environments and have encountered the same issue. Any pointers?

tylermorganwall commented 2 years ago

This should be fixed in the latest version if you update to the latest version of rayimage and rayshader on Github.

options(repos = c(
  tylermorganwall = 'https://tylermorganwall.r-universe.dev',
  CRAN = 'https://cloud.r-project.org'))

# Install some packages
install.packages(c('rayshader','rayimage'))