[R-sig-Geo] Faster way to get raster average?

Thiago V. dos Santos thi_veloso at yahoo.com.br
Wed May 6 04:08:04 CEST 2015


Oh, I forgot to mention that I work on a quad-core Mac with 12GB.
So, if multi-core can potentially accelerate cellStats, or whatever function is faster to get a raster average, I would be glad to see some examples on how to implement it. Greetings,
--
Thiago V. dos Santos
PhD student
Land and Atmospheric Science
University of Minnesota
http://www.laas.umn.edu/CurrentStudents/MeettheStudents/ThiagodosSantos/index.htm
Phone: (612) 323 9898 


     On Tuesday, May 5, 2015 8:48 PM, Thiago V. dos Santos <thi_veloso at yahoo.com.br> wrote:
   

 Hi all,
I am working with some terabytes of CMIP5 climate files. Each file is a netcdf with multiple layers (timesteps) representing monthly data. 
For each file, I need to extract the average value of the raster and put all values in a data frame. This is my current approach:---------------
library(raster)
# make up some datacmip <- brick(nc=150, nr=114, nl=1872)cmip <- setValues(cmip, matrix(rep(1:17100, 1872), nc=1872))
# get mean values (area average) as data framescmip.mean <- as.data.frame(cellStats(cmip, mean, na.rm=T))---------------
which works pretty fast in this example:
> system.time(as.data.frame(cellStats(cmip, mean, na.rm=T)))
  user  system elapsed 
  0.069  0.012  0.081 
However, the calculation with my actual data is substantially slower:
> system.time(as.data.frame(cellStats(cmip, mean, na.rm=T)))
  user  system elapsed 
  4.600  1.105  5.704 
Since I will have to deal with thousands of files, here comes my question: is there a faster way to get a the average value of a raster ? 
Many thanks,
--
Thiago V. dos Santos
PhD student
Land and Atmospheric Science
University of Minnesota
http://www.laas.umn.edu/CurrentStudents/MeettheStudents/ThiagodosSantos/index.htm
Phone: (612) 323 9898
    [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


  
	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list