[R-sig-Geo] Subsetting Raster Time Series

Verbesselt, Jan jan.verbesselt at wur.nl
Tue Aug 26 13:46:27 CEST 2014


You could use the calc() environment and define your own function where
you create a ts() object and then subset the ts() using window() to your
time period.

f_subset <- function(x) {
 x <- ts(x, start = c(1901, 1), frequency = 12)  # fill in the right values
 sx <- window(x, start = c(?,?), end = c(?,?)) ## fill in the right values
 return(sx)
}
result <- calc(temp, fun = f_subset)


Jan
www.wageningenur.nl/changemonitor


On 26/08/14 11:55, "Srinivas V" <srinivasv at feralindia.org> wrote:

>Hi,
>
>I would like to subset the CRU dataset to a particular time period
>(1980-2013) is there an option to do this within package raster? I can
>manually specifiy the layers to drop, but I would like to drop them
>based on a time period. I'm doing this to ensure two datasets are of the
>same time period.
>
>I would appreciate any advice on dealing with this issue. Thanks!
>
>library(raster)
>library(rgdal)
>library(ncdf)
>library(zoo)
>
>temp<-brick("/media/data/data_cru/tmp/cru_ts3.22.1901.2013.tmp.dat.nc")
>temp
>temp at z
>
>output
>+++++
> > temp
>class       : RasterBrick
>dimensions  : 360, 720, 259200, 1356  (nrow, ncol, ncell, nlayers)
>resolution  : 0.5, 0.5  (x, y)
>extent      : -180, 180, -90, 90  (xmin, xmax, ymin, ymax)
>coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
>data source : /media/data/data_cru/tmp/cru_ts3.22.1901.2013.tmp.dat.nc
>names       : X1901.01.16, X1901.02.15, X1901.03.16, X1901.04.16,
>X1901.05.16, X1901.06.16, X1901.07.16, X1901.08.16, X1901.09.16,
>X1901.10.16, X1901.11.16, X1901.12.16, X1902.01.16, X1902.02.15,
>X1902.03.16, ...
>Date        : 1901-01-16, 2013-12-16 (min, max)
>varname     : tmp
>
> > temp at z
>$Date
>  [1] "1901-01-16" "1901-02-15" "1901-03-16" "1901-04-16" "1901-05-16"
>"1901-06-16" "1901-07-16" "1901-08-16" "1901-09-16" "1901-10-16"
>
>[1351] "2013-07-16" "2013-08-16" "2013-09-16" "2013-10-16" "2013-11-16"
>"2013-12-16"
>
>
>
>-- 
>
>Srinivas Vaidyanathan
>Senior Research Fellow
>Foundation for Ecological Research, Advocacy & Learning
>Web: www.feralindia.org
>
>
>	[[alternative HTML version deleted]]
>
>_______________________________________________
>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