The small example can be processed in memory, so any sensible function
will work.
library(raster)
r <- raster(ncols=10, nrows=10)
r[] <- runif(ncell(r)) * 1:ncell(r)
z <- r
z[] <- rep(1:5, each=20)
zonal(r, z, 'sd')
# simulate RAM limitation:
setOptions(todisk=TRUE)
zonal(r, z, 'sd')
# don't forget to turn this off.
setOptions(todisk=FALSE)
# perhaps you can overcome that by changing "maxmemory". See
showOptions()
setOptions(maxmemory=1e+10)
I will also add an "sd" function to zonal for large rasters. That is not
as simple as for min, max, and sum, but it can be done, as it is done in
cellStats. If you do not have too many zones, you could, for now, use a
loop with a combination of reclass/mask/cellStats to extract the sd for
each zone.
Robert
On Mon, Nov 5, 2012 at 7:35 AM, Rafael W?est <rafael.wueest at wsl.ch
<mailto:rafael.wueest at wsl.ch>> wrote:
Hi Christian
What version of raster do you use. Using my installation of raster
(version 2.0-12), 'sd' as a function in zonal works fine (see
example below).
r <- raster(ncols=10, nrows=10)
r[] <- runif(ncell(r)) * 1:ncell(r)
z <- r
z[] <- rep(1:5, each=20)
zonal(r, z, 'sd')
zone "sd"
[1,] 1 4.894058
[2,] 2 9.216353
[3,] 3 14.144341
[4,] 4 19.973913
[5,] 5 27.934773
I guess updating the raster package will solve the problem.
Best,
Rafael
On 02.11.2012, at 18:35, Christian Levers wrote:
> Hello,
>
> I am using the raster package to calculate zonal statistics for
my stack of ca. 50 rasters (each raster is about 33 mio. pixels) and
I am wondering if there is a simple way to calculate standard
deviations for the zones since "sd" is not implemented in the
presets for the "stat" argument. If not, I guess defining a function
which calculates std.dev is the easiest solution.
>
> Thanks in advance and a nice weekend,
> Christian
>
> --
> MSc Geogr. Christian Levers
> Doctoral Researcher
>
> Biogeography & Conservation Biology
> Geography Department | Humboldt-Universitaet zu Berlin
>
> eMail: christian.levers at geo.hu-berlin.de
<mailto:christian.levers at geo.hu-berlin.de>
> phone: +49 (0) 30 2093 9341 <tel:%2B49%20%280%29%2030%202093%209341>
> fax: +49 (0) 30 2093 6848 <tel:%2B49%20%280%29%2030%202093%206848>
> mail: Unter den Linden 6 | 10099 Berlin | Germany
> web: http://www.geographie.hu-berlin.de
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org <mailto:R-sig-Geo at r-project.org>
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo