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

Thiago V. dos Santos thi_veloso at yahoo.com.br
Wed Aug 17 20:34:47 CEST 2016


Thanks Loïc,

I was almost there, but I was definitely missing "as.yearmon".
 
It works now.
 Greetings,
 -- Thiago V. dos Santos

PhD student
Land and Atmospheric Science
University of Minnesota



On Wednesday, August 17, 2016 10:37 AM, Loïc Dutrieux <loic.dutrieux at wur.nl> wrote:


On 17/08/2016 02:51, Bacou, Melanie wrote:
> 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)

Hi Thiago,

You can try to shift the aggregation indices.

library(zoo)
zApply(s, by = as.yearqtr(as.yearmon(idx) + 1/12), fun = mean)

Kind regards,
Loïc

>>
>>
>> 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
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


_______________________________________________
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