r-lidar / lidR

Airborne LiDAR data manipulation and visualisation for forestry application
https://CRAN.R-project.org/package=lidR
GNU General Public License v3.0
598 stars 131 forks source link

normalize_height causes "NULL value passed as symbol address" #580

Closed Jean-Romain closed 2 years ago

Jean-Romain commented 2 years ago

Discussed in https://github.com/r-lidar/lidR/discussions/579

Originally posted by **kulpojke** May 5, 2022 I am using the lidR package to do some tree segmentation on a set of 561 km² tiles using the `LAScatalog` engine and the futures library for parallelization. I have successfully created the DTM, but when I attempt to normalize I get an error. I have read [this thread](https://github.com/r-lidar/lidR/discussions/547) already and it did not solve my problem. I am running inside of a container (`rocker/tidyverse:4.2`) with the following: ``` R version 4.2.0 (2022-04-22) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.4 LTS future_1.25.0 lidR_4.0.0 ``` Here is the code: ```r # import libraries library(lidR) library(future) plan(multisession) # define some paramaters, currently using ft :( chunk_size <-1000 # chunk size buff <- 50 # buffer size resolution <-2 # raster resolution # (1) path to data path <- '/data' # make las catalog ctg <- readLAScatalog(path) # set disk storage option by assigning a filename template to a function opt_output_files(ctg) <- paste0(tempdir(), "/{XCENTER}_{YCENTER}_{ID}") # create index files (lax) to index points within laz files. speeds up reads. lidR:::catalog_laxindex(ctg) # set the chunk buffer ofr ctg opt_chunk_buffer(ctg) <- buff # set the chunk size for ctg opt_chunk_size(ctg) <- chunk_size # make dtm opt_output_files(ctg) <- paste0(tempdir(), "/{XCENTER}_{YCENTER}_{ID}_dtm") dtm <- rasterize_terrain(ctg, resolution, tin()) # in my Rmd I plot the dtm here and it looks right # normalise ctg opt_output_files(ctg) <- paste0(tempdir(), "/{XCENTER}_{YCENTER}_{ID}_norm") ctg_norm <- normalize_height(ctg, dtm) ``` During the normalization I get the following warning, then error: ``` Processing [-----------------] 0% (0/1152) eta: ?sWarning: There are 3 points flagged 'withheld'. Processing [-----------------] 0% (1/1152) eta: 4hError: NULL value passed as symbol address ``` After reading [this thread](https://github.com/r-lidar/lidR/discussions/547). I tried disabling multisession and using set_lidr_threads, ```r # import libraries library(lidR) library(future) #plan(multisession) get_lidr_threads() ``` but the problem persists. Any insights would be greatly appreciated.
Jean-Romain commented 2 years ago

After reproducing with data of mine I get

Error : external pointer is not valid

Which is likely to be very similar to your error. SpatRaster are not serializable and I think this is what caused the error. However I do not have error with sequential processing because only one worker is implied and no serialization is involved. Are you sure you really disabled plan(multissesion). Did you start a fresh session or reset the strategy with plan(sequential)?

Edit: in another run I also go Error : NULL value passed as symbol address (with multisession)


Side note: plan(multisession) and s/get_lidr_threads() are doing very different things.

Jean-Romain commented 2 years ago

Fixed with a workaround. If user is using a parallel strategy SpatRaster are converted to RasterLayer. There is not way to work with SpatRaster

Ben-Shamgochian commented 2 years ago

Fixed with a workaround. If user is using a parallel strategy SpatRaster are converted to RasterLayer. There is not way to work with SpatRaster

Hi, I'm currently experiencing the same issue when attempting to normalize height and I don't quite understand this work around. Do you mind explaining in a little more depth?

Thanks!