projectRaster consuming too much memory

强颜欢笑 提交于 2021-01-27 13:20:56

问题


I'm doing some spatial stuff in R and out of the blue some of my code will no longer work on a computer that I've been using for years, specifically because it's "running out of memory."

## Raster going in
xx <- raster(fatNames[[i]])
xx
class       : RasterLayer 
dimensions  : 5160, 14436, 74489760  (nrow, ncol, ncell)
resolution  : 0.008333333, 0.008333333  (x, y)
extent      : -172.3, -52, 23.5, 66.5  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : D:\Dropbox\wintor_aux\Results\myluFatReq_100_2_fat.inf.tif 
names       : myluFatReq_100_2_fat.inf 
values      : 0.1831425, 3.449095  (min, max)

## transform
x.rast <- projectRaster(xx,crs = CRS("+init=epsg:2955"))

Error: can not adequate vector of 4.2Gb.

Now I know this is a decent sized raster (Input raster size: 75.5 MB) however the machine has 32Gb of RAM, no other programs are running and I still swamp the memory. I've done things like this hundreds of times over the years and to the best of my knowledge nothing on the machine has changed since I did this last about a month ago.

I've tried restarting the session, restarting the computer and have googled around a bit but I still haven't had any luck in trying to trace down the issues. When I try the same code block on a machine with 1/2 the RAM I'm able to run it no problem (using ~ 8Gb ram max). Does anyone have any suggestions as to how I can chase this down?

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_New Zealand.1252  LC_CTYPE=English_New Zealand.1252   
[3] LC_MONETARY=English_New Zealand.1252 LC_NUMERIC=C                        
[5] LC_TIME=English_New Zealand.1252    

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

other attached packages:
[1] raster_2.6-7         rgdal_1.3-3          sp_1.3-1             sf_0.6-3            
[5] RevoUtils_11.0.1     RevoUtilsMath_11.0.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18    lattice_0.20-35 class_7.3-14    grid_3.5.1      spData_0.2.9.0 
 [6] DBI_1.0.0       magrittr_1.5    e1071_1.7-0     units_0.6-0     tools_3.5.1    
[11] yaml_2.2.0      compiler_3.5.1  classInt_0.2-3 

回答1:


You should first update the raster package to its current (CRAN) version. That might fix this. If not, this is probably a corner-case that you should be able to work-around by setting the memory parameters to a lower value. In the current version you could do rasterOptions(memfrac=.3). In the current and older versions you may try rasterOptions(maxmemory=1e+08)

By the way, your transformation to +proj=utm +zone=11 (please do not use espg codes in examples) seems rather questionable given that the input data has a longitude span of (172.3 - 52) = 120 degrees --- UTM is valid for a span of about 6 degrees.



来源:https://stackoverflow.com/questions/59493477/projectraster-consuming-too-much-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!