Swen,

You do not provide much info (e.g. system.time() ) so I do not know where
the bottleneck is. It could be in the call to "stack" which you can speed
up with "quick=TRUE" (if you are sure that the rasters all line up). It
could also be that the bottleneck is reading the data from file.
Using ASCII is not a good idea (slow) in this type of application.
If you have enough RAM, you might try reading all files in one step,
instead of blocks:

X_01 <- stack(Files[which(substring(**Files,(nchar(Files)-9),nchar(**
Files)-6)==i)])
X_01 <- readAll(X_01)  # this will fail if you have insufficient RAM
X_01_sum <- mean((X_01))

Robert



On Mon, Nov 26, 2012 at 7:51 AM, Swen Meyer <s.meyer@lmu.de> wrote:

> Dear All,
> I´m trying to process a couple of ascii grids (daily grids): size of one
> grid (344kb). the header of the ascii grids look like this:
> ncols 288
> nrows 199
> xllcorner 506255
> yllcorner 4.35899e+006
> cellsize 30
>
> I have daily grids over 30 years and I like to find a fast way of
> calculating the monthly means for every month of those 30 years:
> the file structure is like this: grid1: "sb05_dem30m_20410101.024"
> grid2: "sb05_dem30m_20410102.024"
> grid3: "sb05_dem30m_20410103.024"
> ...
> gridn: "sb05_dem30m_YYYYMMdd.024"
> ...
> last grid: "sb05_dem30m_20701231.024"
>
> At the moment I´using R Vers. 2.15.1 on a Intel PC i5 CPU 760@ 2.80GHz
> 2.80GHz with 4GB RAM Windows7, and the raster package and this is my script:
> library(raster)
>
> setwd("G:\\hydro_modelling\\**Sardinia\\Wasim\\**RioCostara30m\\KNMI_REF\\
> **output30m\\RUN2\\UNSATZON\\")
> Path="G:\\hydro_modelling\\**Sardinia\\Wasim\\**RioCostara30m\\KNMI_REF\\*
> *output30m\\RUN2\\SOILMOIST\\"
>
>
> x="sb05_dem30m_"
> #list files of folder with string x
> Files=list.files(pattern=x)
> # select files to process
> Files=Files[which((substring(**Files,nchar(Files)-3,nchar(**
> Files)))==".024")]
>
> for( i in unique(substring(Files,(nchar(**Files)-9),nchar(Files)-6))){
> print(i)
> #stack files
> X_01 <- stack(Files[which(substring(**Files,(nchar(Files)-9),nchar(**
> Files)-6)==i)])
> #mean the grid with raster package
> X_01_sum <- mean((X_01))
> #Write monthly mean asci grid
> writeRaster(X_01_sum, filename=paste(Path,"**
> SoilMoisture_RM_Mean_",i,sep="**"), "ascii")
> }
>
> The script works, but it takes more than 30 min until the grids are
> precessed. Does anyone know of a faster way of meaning (summing) those
> grids and exporting them as a asci again?
> Best regards and thank you in advance,
> Swen
>
> --
> ------------------------------**------------------------------**--
> Dipl. - Geogr. Swen Meyer
> Department of Geography
> Physical Geography and Environmental Modeling Ludwig-Maximilian University
> of Munich
>
> Luisenstrasse 37
> 80333 Munich/Germany
> fon: +49 (0)89 2180-6665
> fax: +49 (0)89 2180-6675
> email: s.meyer@lmu.de
> web: www.geographie.uni-muenchen.de
>
> ______________________________**_________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/**listinfo/r-sig-geo<https://stat.ethz.ch/mailman/listinfo/r-sig-geo>
>

	[[alternative HTML version deleted]]

