sumSeries | R Documentation |
Function to convert climatic series (provided as RasterStack
) into a
coarser time frequency series for a period of interest. This function transforms the RasterStack
into an xts
time series object to extract the values for the period of interest and
apply some summary function. It is mainly a wrapper from the apply.
function family
in the package xts (Ryan and Ulrich 2017).
sumSeries(r, p, yr0, l, fun = function(x) colMeans(x, na.rm = TRUE), freqin = "months",
freqout = "years")
r |
|
p |
|
yr0 |
|
l |
|
fun |
|
freqin |
|
freqout |
|
A RasterStack
with the new series.
Jorge Garcia Molinos
Ray and Ulrich. 2017. xts: eXtensible Time Series. R package version 0.10-1.
Bengtsson 2018. matrixStats: Functions that Apply to Rows and Columns
of Matrices (and to Vectors). R package version 0.53.1.
# Monthly mean SST (HadISST) data for Europe Jan-1950 to Dec-2010
?HSST
# Calculate mean annual monthly SST
yrSST <- sumSeries(HSST, p = "1969-01/2009-12", yr0 = "1955-01-01", l = nlayers(HSST),
fun = function(x) colMeans(x, na.rm = TRUE), freqin = "months", freqout = "years")
# Extract Jul Aug mean SST each year (xts months are indexed from 0 to 11)
myf = function(x, m = c(7,8)){
x[xts::.indexmon(x) %in% (m-1)]
}
JlAugSST <- sumSeries(HSST, p = "1969-01/2009-12", yr0 = "1950-01-01", l = raster::nlayers(HSST),
fun = myf, freqin = "months", freqout = "other")
# Same but calculating the annual variance of the two months
myf = function(x, m = c(7,8)){
x1 <- x[xts::.indexmon(x) %in% (m-1)]
xts::apply.yearly(x1, function(y) apply(y, 2, function(y){var(y, na.rm = TRUE)}))
}
meanJASST <- sumSeries(HSST, p = "1969-01/2009-12", yr0 = "1950-01-01", l = raster::nlayers(HSST),
fun = myf, freqin = "months", freqout = "other")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.