Author: Paulo van Breugel
Updated on: 2017-03-30
1. 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
|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 cd 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
2. 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 one big step.
2.2. Using r.in.gdal
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) do r.in.gdal -l input=bio$i.bil output=bio$i done
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. We will set the extent and resolution to match that of the elevation layer in the PERMANENT mapset.
# Create new mapset in target location and go there g.mapset -c mapset=tutorial location=nc_spm_08_grass7 g.region -a raster=elev_state_500m@PERMANENT # Import the layers in target mapset (this is equivalent to # reprojecting the data from latlon to the target projection. for i in $(seq 19) do r.proj location=TmpLoc mapset=PERMANENT input=bio$i method=lanczos done # 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
2.2. Using r.import
The other, arguably easier solution, is to use the r.import function. We can use the command line or, like in the example below, the GUI. To open a larger version of the images below, click on them. Use the return botton of your browser to return to the tutorial page.
Step 1 - Create new mapset
The first step is to create a new mapset (Figure 1) in which we will import the bioclim layers. You can of course decide to import them in an existing mapset if you like. This will ultimately depend on how you want to organize your data layers.
Next, we set the region (extent and resolution) to match that of the elevation layer in the PERMANENT mapset (Figure 2). If you are not familiar with the concept of the region, read this first.
After setting the region, you can check the details such as extent and resolution by using the g.region -p function. You can type this on the command line, or find it in the settings menu (Figure 3).
Step 2 - Download the data
At Worldclim, you can also download the bioclim variables per tile (this is only true for version 1.4, for version 2 only global data layers are available). Go to the Worldclim site http://www.worldclim.org/tiles.php and select tile 13. Next, use the download link to download the data (Figure 1).
Figure 4. Screenshot of the download page of the Worldclim tiles. To download the bioclim data layers for tile 13, (1) click the tile 13 on on the map (blue circle) and next, use the download link to download the bioclim data layers (red circle).
Step 3 - Import the data in the GRASS GIS database
After downloading the zip file, unzip it in any location. Now, the data can be imported in GRASS GIS. Now, we can use the r.import function to import the layers. First, open the r.import window (Figure 5).
Next, find the folder with the downloaded bioclim raster layers, and use the context menu (right click anywhere in the window) to select all layers (Figure 6). You can optionally change the names of the output GRASS maps by double clicking a name. For example, you can remove the suffix '_13' from the default map names.
In the 'Import settings' tab there are further options, such as the resampling method to use for reprojection, output raster map extent, resolution of the output maps, amongst others. Here we only set the extent and resolution to match that of the region. Remember that we defined the region in step 1 above.
Now you can hit the Import button (Figure 6). When the projection of your layer(s) are different from that of the location in which you want to import your layers, you will be shown another screen, the 'Reprojection' screen (Figure 8), in which you need to confirm that you want to reproject the layers. As mentioned, right click to select or unselect layers.
Hit the Import & reproject button and the import will start. Progress will be shows in the Console window (Figure 9). You can use this to check if the import has been successful.
Software: @grassgis @qgis
Subject: @bioclim @data_import @reproject