Import and reproject bioclim data

Author: Paulo van Breugel
Updated on: 2017-03-30

The data

In this tutorial we'll be using bioclim raster layers listed in Table 1. They represent variables that are derived from the monthly temperature and rainfall values from the Worldclim dataset (Hijmans et al. 2005) in order to generate more biologically meaningful variables. The data can be downloaded from http://worldclim.org.

Table 1: Bioclimatic variables

Variable Description
bio 1 Annual Mean Temperature
bio 2 Mean Diurnal Range (Mean of monthly (max temp – min temp))
bio 3 Isothermality (BIO2/BIO7) (* 100)
bio 4 Temperature Seasonality (standard deviation *100)
bio 5 Max Temperature of Warmest Month
bio 6 Min Temperature of Coldest Month
bio 7 Temperature Annual Range (BIO5-BIO6)
bio 8 Mean Temperature of Wettest Quarter
bio 9 Mean Temperature of Driest Quarter
bio 10 Mean Temperature of Warmest Quarter
bio 11 Mean Temperature of Coldest Quarter
bio 12 Annual Precipitation
bio 13 Precipitation of Wettest Month
bio 14 Precipitation of Driest Month
bio 15 Precipitation Seasonality (Coefficient of Variation)
bio 16 Precipitation of Wettest Quarter
bio 17 Precipitation of Driest Quarter
bio 18 Precipitation of Warmest Quarter
bio 19 Precipitation of Coldest Quarter

The data can be downloaded from the website. Alternatively, you can use the wget command line function (a Linux tool, but also available for Windows). In the example below the command unzip uncompresses the data layers in the folder bio_2-5m_bil. After the files are decompressed, we move into the target folder using the cd command.

# Download data and import in a latlon (EPGS 4326) GRASS GIS database
# In this example, the data will be downloaded to my home directory
wget http://biogeo.ucdavis.edu/data/climate/worldclim/1_4/grid/cur/bio_2-5m_bil.zip

# Extract the data layers and change to directory with downloaded data
unzip bio_2-5m_bil.zip
cd bio_2-5m_bil

Importing and reprojecting

The coordinate reference system (CRS) of the data layers is latlon (WGS 84). However, in this tutorial we'll be working with the North Carolina (NC) sample GRASS database, which can be downloaded from the GRASS GIS website. The projection of this dataset is NAD83(HARN) / North Carolina (EPSG 3358). This means that the data needs to be reprojected. There are various ways one can do this. One option is to reproject the data first using other tools such as gdalwarp. A second option is to (i) import the data in a location/mapset with the same projection as the layers using r.in.gdal, and (ii) use r.proj to import and reproject the data from that location/mapset into the target location/mapset. A third option is to use the r.import function, which essentially combines the two steps of importing and reprojecting the data.

In this example we'll use the second option. We first import the data in the mapset PERMANENT of the location TmpLoc in the GRASS database GRASSdb. The location and mapset do not exist yet so they are created when opening GRASS GIS. This is done by setting the c flag. The projection of this new location is set by providing the EPSG code. The code for latlon WGS84 is EPS 4326.

# Start GRASS in the grass database GRASSdb, location TmpLoc and 
# mapset PERMANENT (the latter two will be created at startup of GRASS).
# Make sure to change the path to point to your GRASS database. 
grass -c EPSG:4326 ~/Data/GRASSdb/TmpLoc2/
for i in $(seq 1 19)
	r.in.gdal -l input=bio$i.bil output=bio$i

Next, we switch to the target location / mapset using the g.mapset function, and use the r.proj function to reproject the data layers into the location nc_spm_08_grass7. The c flag in the g.mapset function ensures that the given mapset is created if it doesn't exist already.

# Create new mapset in target location and go there
g.mapset -c mapset=tutorial location=nc_spm_08_grass7
g.region n=348000 s=-16000 w=124000 e=964000 res=4000 -a

# Import the layers in target mapset (this is equivalent to
# reprojecting the data from latlon to the target projection.
for i in $(seq 19)
	r.proj location=TmpLoc mapset=PERMANENT input=bio$i method=lanczos

# As a last step, we can remove the temporary location and the downloaded data
rm -r ~/Data/GRASSdb/TmpLoc 
rm -r ~/bio_2-5m_bil


Software: @grassgis @qgis
Subject: @bioclim @data_import @reproject