r - Spatial data and memory -


i trying add geotiffs running memory issues. r using 32gb according the following r error...

in writevalues(y, x, start = 1) :   reached total allocation of 32710mb: see help(memory.size) 

i checked properties of r , 64 bit , target is...

"c:\program files\r\r-3.3.0\bin\x64\rgui.exe"

the version is

r.version()  $platform [1] "x86_64-w64-mingw32"  $arch [1] "x86_64"  $os [1] "mingw32"  $system [1] "x86_64, mingw32"  $status [1] ""  $major [1] "3"  $minor [1] "3.0"  $year [1] "2016"  $month [1] "05"  $day [1] "03"  $`svn rev` [1] "70573"  $language [1] "r"  $version.string [1] "r version 3.3.0 (2016-05-03)"  $nickname [1] "supposedly educational" 

so looks max memory being used r. tried use bigmemory package in r. in code below tried changing matrix big.matrix failed , error occurs when trying write output file. suggestions trying alter code less memory used or try work in package ff or bigmemory?

############  loop through age maps compile number of times cell burns during given span of time  #################### ## empirical fires print("1 of 3: 2010-2015")  burn.mat<- matrix(0,nrow,ncol) #create matrix of zero's, dimension of landscape  (row, col)  # read in historical fire maps (j in 2010:2015){ #year loop    age.tmp<- as.matrix(raster(paste('fr',j,'.tif',sep=''))) #read in age map    burn.mat<- burn.mat+(age.tmp==1) #when has burned in alfresco empirical fire history files, age=1. (age.tmp==0) 'logic' cmd, returning 0,1 map true/false    #write data geotiff   out <- raster(burn.mat,xmn=-1692148,xmx= 1321752, ymn = 490809.9, ymx = 2245610, crs = '+proj=aea +lat_1=55 +lat_2=65 +lat_0=50 +lon_0=-154 +x_0=0 +y_0=0 +ellps=grs80 +datum=nad83 +units=m +no_defs')   writeraster(out,filename=paste(outdir,'/burn.mat.hist.1950-2007.tif',sep=''),format = 'gtiff',options='compress=lzw',datatype='flt4s',overwrite=t) } 

the problem go away if use raster* objects rather matrices. like

library(raster) r <- raster('fr2010.tif')  burn.mat <- setvalues(r, 0)  (j in 2010:2015) {   age.tmp <- raster(paste0('fr', j, '.tif'))   burn.mat <- burn.mat + (age.tmp==1)   # if age.tmp has values of 0 , 1 use instead:    # burn.mat <- burn.mat + age.tmp  }  # write results outside of loop writeraster(burn.mat, filename=file.path(outdir, 'burn.mat.hist.1950-2007.tif'), options='compress=lzw',datatype='flt4s',overwrite=true) 

a more direct approach without loop

 files <- paste0('fr', 2010:2015, '.tif'))  s <- stack(files)  burn <- sum(s) 

or

 burn <- sum(s == 1) 

or write file in 1 step

 b <- calc(s, sum, filename=file.path(outdir, 'burn.mat.hist.1950-2007.tif'), options='compress=lzw', datatype='flt4s', overwrite=true) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -