Converting GPCC gridded rainfall 1901-2010@0.5° to monthly Geotiffs

GPCC rainfall data contains the largest database worldwide, with over 90 000 weather-stations interpolated to a 0.5° grid. It includes S. Nicholsons dataset for Africa and is thus a good source for gridded monthly precipitation. It covers the period 1901-2010, however, it comes in a strange dataformat and it is a long way until we get such diagrams for the desired location:

GPCC annual rainfall averaged over my study area in northern Senegal

GPCC annual rainfall averaged over my study area in northern Senegal

As I couldn’t handle with the format provided at the DWD download site, I used the climate explorer to generate a ncdf-file. Use this link to get the global dataset: GPCC-V6.

Then this file is loaded into R. After loading the packages, the working directory which contains the file is set:

library(raster)
library(rgdal)
library(ncdf)
setwd("~/Dissertation/GPCC/")

Then the variable “prcp” is loaded into R and my study area clipped. To find out the correct variable, use gdalinfo e.g.

gpcc = brick("gpcc_V6_05.nc", varname="prcp")
gpcc
plot(gpcc)
e <- extent(-20, 5, 9, 26)
gpccclip <- crop(gpcc, e)

Then it’s exported as a multilayer Geotiff:

writeRaster(gpccclip, filename="gpcc_v6_westafr.tif", format="GTiff")

now I extract the individual rasters and create 1320 single files. I exit R for this:

cd ~/Dissertation/GPCC/
gdalinfo gpcc_v6_westafr.tif
for ((i = 1; i<= 1320; i++)) do gdal_translate -b $i -of GTiff gpcc_v6_westafr.tif `basename $i`.tif; done

Finaly the files are renamed. This may not be an elegant way, but it works:

for ((i=1;$i<=1320;i++)) do echo "mv $i.tif gpcc_v6_$(( ($i-1) / 12 + 1901 ))_$(( ($i-1) % 12 + 1 )).tif"; done >Umbenennungsscript.sh
sed -i 's/_1.tif/_01.tif/g' Umbenennungsscript.sh
sed -i 's/_2.tif/_02.tif/g' Umbenennungsscript.sh
sed -i 's/_3.tif/_03.tif/g' Umbenennungsscript.sh
sed -i 's/_4.tif/_04.tif/g' Umbenennungsscript.sh
sed -i 's/_5.tif/_05.tif/g' Umbenennungsscript.sh
sed -i 's/_6.tif/_06.tif/g' Umbenennungsscript.sh
sed -i 's/_7.tif/_07.tif/g' Umbenennungsscript.sh
sed -i 's/_8.tif/_08.tif/g' Umbenennungsscript.sh
sed -i 's/_9.tif/_09.tif/g' Umbenennungsscript.sh
chmod 0755 Umbenennungsscript.sh
./Umbenennungsscript.sh

The final result are 1320 Geotiffs, named gpcc_v6_1901_01.tif until gpcc_v6_2010_12.tif with monthly rainfall for West Africa, ready to be used in any GIS. Now we can easily create beatiful maps like this:

Mean annual rainfall 1950-2010 (source: GPCC v6)

Mean annual rainfall 1950-2010 (source: GPCC v6)

 

Advertisements

3 thoughts on “Converting GPCC gridded rainfall 1901-2010@0.5° to monthly Geotiffs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s