projectRaster 消耗太多内存 [英] projectRaster consuming too much memory

查看:72
本文介绍了projectRaster 消耗太多内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 R 中做一些空间方面的事情,突然之间我的一些代码将不再在我使用多年的计算机上运行,​​特别是因为它内存不足".

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"))

错误:无法提供足够的 4.2Gb 向量.

Error: can not adequate vector of 4.2Gb.

现在我知道这是一个大小合适的光栅(输入光栅大小:75.5 MB)但是机器有 32Gb 的 RAM,没有其他程序在运行,我仍然占用内存.多年来,我已经做了数百次这样的事情,据我所知,自从我大约一个月前做这件事以来,机器上的任何东西都没有改变.

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.

我已经尝试重新启动会话、重新启动计算机并在谷歌上搜索了一下,但我仍然没有任何运气试图追踪问题.当我在具有 1/2 RAM 的机器上尝试相同的代码块时,我可以毫无问题地运行它(最大使用 ~ 8Gb ram).有人对我如何解决这个问题有任何建议吗?

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 

推荐答案

您应该首先将栅格包更新为其当前 (CRAN) 版本.这可能会解决这个问题.如果不是,这可能是一种极端情况,您应该能够通过将内存参数设置为较低的值来解决该问题.在当前版本中,您可以执行 rasterOptions(memfrac=.3).在当前和旧版本中,您可以尝试 rasterOptions(maxmemory=1e+08)

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)

顺便说一下,鉴于输入数据的经度跨度为 (172.3- 52) = 120 度 --- UTM 适用于大约 6 度的跨度.

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.

这篇关于projectRaster 消耗太多内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆