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

Els Ducheyne educheyne at avia-gis.be
Fri Sep 9 14:25:53 CEST 2011


Dear Alex
thanks for your reply - just something that I have noted
If I do :
>> input <- inputlist[datadisplay[i]:datadisplay[i+1]-1]
>> images <- brick(input)
>> images.celsius <- calc(images,fun=function(x){x - 273.15})
The class of images.celsius is a RasterLayer
On the other hand when I do the following:
>> input <- inputlist[datadisplay[i]:datadisplay[i+1]-1]
>> images <- brick(stack(input))
>> images.celsius <- calc(images,fun=function(x){x - 273.15})
ie. first make a stack, then a brick, the end result is a brick

any clues why? Nevertheless, I am now capable of processing the data in a more reasonable time using the brick option

Best
Els


On 9 Sep 2011, at 13:40, Alexander Arpaci wrote:

> The brick option will give you back a raster brick again 
> if understand correct what you want to do..
> 
> r <- raster(ncol=10, nrow=10)
> r[]=1:ncell(r)
> s <- brick(r,r,r,r,r,r)
> 
> rs2 <- calc(s, fun=function(x){x * 10})
> class(rs2)
> cheers 
> 
> ales
> 
> 
> 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 13.12 Uhr >>>
> Dear Alex
> thanks for this, I will try the cluster functionalities
> For the Brick option - I assumed that this will result only in a single RasterLayer instead of a new brick?
> 
> Best
> Els
> On 9 Sep 2011, at 12:58, Alexander Arpaci wrote:
> 
>> 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