[R-sig-Geo] How to calculate seasonal means in raster time series?

Bacou, Melanie mel at mbacou.com
Wed Aug 17 02:51:19 CEST 2016


Maybe create a function that takes a date as input and returns a 
meteorological season, and pass this function to `zapply(by=fun)`.
--Mel.

On 8/16/2016 8:38 PM, Thiago V. dos Santos via R-sig-Geo wrote:
> Dear all,
>
> I am using the raster package to calculate seasonal averages of climatic variables. I usually use zApply to perform temporal calculations on gridded time series.
>
> However, this time I need to calculate seasonal averages according to the meteorological nomenclature, with DJF (=winter in the southern hemisphere: December, January, February), MAM, JJA, and SON. It is similar to zoo's yearqtr, but with a offset of -1 month on each quarter.
>
> That means that December values comes from the previous year.
> This is a typical raster I work with:
>
> library(raster)
>
> # Create date sequence
> idx <- seq(as.Date("2001/1/1"), as.Date("2010/12/31"), by = "day")
>
> # Create raster stack and assign dates
> r <- raster(ncol=5, nrow=5)
> s <- stack(lapply(1:length(idx), function(x) setValues(r, runif(ncell(r)))))
> s <- setZ(s, idx)
>
>
> On a raster stack like this, what would be the best strategy to calculate "meteorological" seasonal means?
>   Thanks in advance,
>   -- Thiago V. dos Santos
>
> PhD student
> Land and Atmospheric Science
> University of Minnesota
>
> _______________________________________________
> 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