Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge() and mosaic(): R crashes #1650

Open
aloboa opened this issue Nov 22, 2024 · 2 comments
Open

merge() and mosaic(): R crashes #1650

aloboa opened this issue Nov 22, 2024 · 2 comments

Comments

@aloboa
Copy link

aloboa commented Nov 22, 2024

Given a list of SpatRaster objects of 512 * 512 * 204
that sequentially overlap in a ~25%, I try to make one
single object with merge() or mosaic().

While both merge() and mosaic() work with up to ~7 SpatRaster objects, eg

m <- merge(r01, r02, r03)
plotRGB(m,50,100,190,stretch="linear")

(as you can see, this a quick and dirty solution and a better result is being
worked out through more sophisticated automatic stitching)

image

either

m <- merge(r01, r02, r03, r04, r05, r06,r07, r08, r09, r10, r11, r12, r13, r14, r15, r16,
           filename=file.path(dirG,"SUM-ZON23-1B-1G_IQ.dat"), 
           wopt=list(filetype="ENVI",overwrite="TRUE"))

or

m <- mosaic(r01, r02, r03, r04, r05, r06,r07, r08, r09, r10, r11, r12, r13, r14, r15, r16, 
            fun="first", filename=file.path(dirG,"SUM-ZON23-1B-1G_IQ.dat"), 
            wopt=list(filetype="ENVI",overwrite="TRUE"))

make R and RStudio crash with a bomb:

All raster 
R Session Aborted
R encountered a fatal error
The session was terminated
Start New Session
...
[18134:18135:20241122,160519.936441ERROR elf_dynamic_array_reader.h:61] tag not found
[18134:18135:20241122,160519.936206:ERROR directroy_reader_postx.cc:42] opendir: No such file or directroy (2)

I understand this is a memory problem (although the process should end with an error message
and not a crash). Having stated the output file, I thought the object "m" would not make crash R,
as it is not needed to be in memory.

Any way around this problem?

> sessionInfo()
R version 4.4.2 (2024-10-31)
Platform: x86_64-pc-linux-gnu
Running under: Pop!_OS 22.04 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_US.UTF-8       LC_NUMERIC=C               LC_TIME=es_ES.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=es_ES.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=es_ES.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=es_ES.UTF-8 LC_IDENTIFICATION=C       

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

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

other attached packages:
[1] terra_1.8-1

loaded via a namespace (and not attached):
 [1] compiler_4.4.2    fastmap_1.2.0     cli_3.6.3         htmltools_0.5.8.1 tools_4.4.2       rstudioapi_0.15.0 yaml_2.3.10      
 [8] Rcpp_1.0.13-1     codetools_0.2-19  rmarkdown_2.28    knitr_1.48        xfun_0.49         digest_0.6.36     rlang_1.1.4      
[15] evaluate_0.24.0  
@aloboa
Copy link
Author

aloboa commented Nov 26, 2024

As an alternative, I am using gdalbuildvrt through system() to build a vrt and then read and write to ENVI format.

@rhijmans
Copy link
Member

That crash should not happen, and was probably due to a bug, not a memory limitation.

Can you try again? Note that there are now three algorithms (#3 is equivalent to your work-around)

For example

library(terra)
x <- rast(xmin=-110, xmax=-80, ymin=40, ymax=70, res=1, vals=1)
y <- rast(xmin=-85, xmax=-55, ymax=60, ymin=30, res=1, vals=2)
z <- rast(xmin=-60, xmax=-30, ymax=50, ymin=20, res=1, vals=3)
s <- sprc(x, y, z)

b1 <- merge(s, algo=1)
b2 <- merge(s, algo=2)
b3 <- merge(s, algo=3)
panel(c(b1,  b2,  b3))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants