[R-sig-Geo] Antw: Calc function on a stack slow?

Alexander Arpaci alexander.arpaci at boku.ac.at
Fri Sep 9 12:58:09 CEST 2011


The package snow contains a function beginCluster () which helps to use if possible multicores for calculation of larger raster sets. Otherwise the use of brick could be helpful to speed things up..
hth

alex


MSc. Alexander Arpaci
Assistant researcher

Department of Forest - and Soil Sciences
Institute of Silviculture
Tel. +43-1-47654-4081
e-mail: alexander.arpaci at boku.ac.at
www.wabo.boku.ac.at 
>>> Els Ducheyne  09.09.11 12.46 Uhr >>>
Dear r-sig-geo list
I have a number of rasters with dim =  that I need to convert from Kelvin to Celsius. I though that stacking the layers and then perform a calculate would be the rrick. While this works, it is quite slow, so i wonder if there are faster ways in R to do this?

See below for code

Thanks for help

 R.Version()
$platform
[1] "i386-apple-darwin9.8.0"

$arch
[1] "i386"

$os
[1] "darwin9.8.0"

$system
[1] "i386, darwin9.8.0"

$status
[1] "Patched"

$major
[1] "2"

$minor
[1] "11.1"

$year
[1] "2010"

$month
[1] "08"

$day
[1] "30"

$`svn rev`
[1] "52862"

$language
[1] "R"

$version.string
[1] "R version 2.11.1 Patched (2010-08-30 r52862)"

and raster package 1.7-29

require(raster)
#get all the inputdata
start <- Sys.time()
inputlist <- list.files(pattern="lstday")
datadisplay <- seq(1,length(inputlist),16)
datadisplay <- c(datadisplay,length(inputlist))
n <- length(datadisplay)-1
for (i in 1:n){
input <- inputlist[datadisplay[i]:datadisplay[i+1]-1]
images <- stack(input)
images.celsius <- calc(images,fun=function(x){x - 273.15})
plot(images.celsius, zlim=c(-20,80),asp=1)
hist(images.celsius,xlim=c(-20,80),n=100)
}
end <- Sys.time()
print(end-start)

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



More information about the R-sig-Geo mailing list