Closed Jean-Romain closed 2 years ago
The example does not throw the error anymore but I does with my data and I found another related error and solution. In my case I was trying to use a SpaRaster
as a template and was failing. The solution is to convert that raster to a RasterLayer
with raster::raster()
.
This is a silly reproducible example to use the maximum height raster as a template for minimum heigh calculation:
library(lidR)
LASfile <- system.file("extdata", "Megaplot.laz", package="lidR")
ctg <- readLAScatalog(LASfile, select = "xyz", chunk_size = 140, chunk_buffer = 0)
opt_chunk_alignment(ctg) <- c(0,20)
plot(ctg, chunk = TRUE)
library(future)
plan(multisession, workers = 2)
m = pixel_metrics(ctg, ~max(Z), 20)
# Works
pixel_metrics(ctg, ~min(Z), m)
# Does not work
pixel_metrics(ctg, ~miin(Z), raster(m))
# Works
Honestly, I'm tired of fixing bugs coming from the fact that SpatRaster
are badly designed and are not serializable. My code contains several workarounds for that to a point that I'm not even sure where they are and what they are doing. You can process single core or use Raster
as a workaround as you did. Anyway, it is what I'm doing internally. Please open a new issue with your reproducible example, so I can remember to fix that one. Thanks
Minimal reproducible example
The problem comes from the fact that
SpatRaster
are not serializable and cannot be sent to nodes (or here be sent back to the main worker). As a consequence the following options are expected to work because noSpatRaster
is exchanged between nodes