# How to create a time series with a NetCDF raster from Ensembles E-OBS using GDAL, R, GRASS GIS or SAGA GIS

I downloaded a NetCDF file that contains daily precipitation values from 1-1-1950 to 30-6-2013. The raster has 23191 bands.

My goal is to analyze how precipitation values varied and relate the changes with the conservation of a forest ecosystem.

I'm unsure on how to proceed, but I think the first step should be to create a time series from the NetCDF raster.

How can I do this using GDAL, GRASS GIS or R?

• In R, start with library(raster);(ncdata <- brick("file.nc")) and report back on what you get. You'll need either ncdf4 or ncdf packages also installed for raster to use. Commented Mar 26, 2014 at 19:20
• Thanks @mdsumner. After giving up on GDAL, started looking for solutions in R and found them. Commented Mar 26, 2014 at 20:20

Answering to myself. Using R and package "rts" it is possible to create a time series:

``````library(raster)
library(ncdf)
library(stringr)
library(rts)

stack<-stack("pp_0.25deg_reg_v9.0.nc") #Create raster stack

datas<-c()
for (i in 1:length(stack@layers)) {
word<-str_sub(as.character(stack@layers[[i]]@data@names), start=2, end=11L)
word<-as.Date(format(as.Date(word,"%Y.%m.%d"),"%Y-%m-%d"))
datas[[length(datas)+1]] <- word
} ##extract the strings with the dates and format them according to as.Date() requirements

as.Date(datas)->datas
rt <- rts(stack,datas) #Create raster stack time series

apply.yearly(rt, mean)->y # calculate the mean (annual) precipitation value
``````