SDM1 : Montane woodcreper - Gecomputation

One of the first action in Species Distribution Model is to record presence/absence of the species and then search for raster or vector files that store information about environment variables, that define the ecological niche. We will first concentrate on the collection of the environment variables.

Open the bash terminal, migrate in the directory, and open the jupter-notebook.ipynb

cd /media/sf_LVM_shared/my_SE_data/exercise
jupyter-notebook SDM1_MWood_gecomp.ipynb

Crop enviromental layers

First select a dataset that we can use to define the overall extent of the specie - the study area. We will therefore crop geodata using the species range as an extent and increase of 3 degree in N-S and W-E direction.

[1]:
%%bash
cd /media/sf_LVM_shared/my_SE_data/exercise
# test
# define north south weast owest extent
ulx=$(ogrinfo -al -so geodata/shp/cartodb-query.shp | grep Extent | awk '{ gsub("\\("," "); print int($2 -3)}')
uly=$(ogrinfo -al -so geodata/shp/cartodb-query.shp | grep Extent | awk '{ gsub("\\)"," "); print int($6 +3)}')
lrx=$(ogrinfo -al -so geodata/shp/cartodb-query.shp | grep Extent | awk '{ gsub("\\("," "); print int($5 +3)}')
lry=$(ogrinfo -al -so geodata/shp/cartodb-query.shp | grep Extent | awk '{ gsub("\\)"," "); print int($3 -3)}')

## Print the extent to confirm the lat long
echo $ulx $uly $lrx $lry
## croping
gdal_translate -projwin  $ulx $uly $lrx $lry -co COMPRESS=DEFLATE -co ZLEVEL=9 \
geodata/cloud/SA_intra.tif  geodata/cloud/SA_intra_crop.tif

gdal_translate -projwin  $ulx $uly $lrx $lry -co COMPRESS=DEFLATE -co ZLEVEL=9 \
geodata/cloud/SA_meanannual.tif  geodata/cloud/SA_meanannual_crop.tif

gdal_translate -projwin  $ulx $uly $lrx $lry -co COMPRESS=DEFLATE -co ZLEVEL=9 \
geodata/dem/SA_elevation_mn_GMTED2010_mn.tif  geodata/dem/SA_elevation_mn_GMTED2010_mn_crop.tif

gdal_translate -projwin  $ulx $uly $lrx $lry -co COMPRESS=DEFLATE -co ZLEVEL=9 \
geodata/vegetation/SA_tree_mn_percentage_GFC2013.tif  geodata/vegetation/SA_tree_mn_percentage_GFC2013_crop.tif

-82 14 -59 -21
Input file size is 5880, 8400
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 5880, 8400
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 5880, 8400
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 5880, 8400
0...10...20...30...40...50...60...70...80...90...100 - done.

Download climate layers

Dowonload climate data from https://chelsa-climate.org/ . Using the /vsicurl/ option in gdal is possible to download only the raster extend of your study area.

  1. Download and process climate data (grade 20%)

Proceed with the download also for tmin and prec. Build up the loop and also calculate mean and stdev. Consider that, pkstatprofile even giving the compression flag (-co COMPRESS=DEFLATE -co ZLEVEL=9) does not compress very well so insert a gdal_translate to perform the compression (and of course remove the intermediate files).

[2]:
%%bash
cd /media/sf_LVM_shared/my_SE_data/exercise
# download temperature tmin and tmax from https://envicloud.wsl.ch/#/?prefix=chelsa%2Fchelsa_V1
for var in tmin tmax ; do
for MM in 01 02 03 04 05 06 07 08 09 10 11 12 ; do
gdal_translate -projwin -82 14 -59 -21 -co COMPRESS=DEFLATE -co ZLEVEL=9  /vsicurl/https://os.zhdk.cloud.switch.ch/envicloud/chelsa/chelsa_V1/climatologies/${var}/CHELSA_${var}10_${MM}_1979-2013_V1.2_land.tif  geodata/climate/CHELSA_${var}10_${MM}_1979-2013_V1.2_land_crop.tif
done
done
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
[1]:
%%bash
cd /media/sf_LVM_shared/my_SE_data/exercise
# download precipitation from https://envicloud.wsl.ch/#/?prefix=chelsa%2Fchelsa_V1
for MM in 01 02 03 04 05 06 07 08 09 10 11 12 ; do
gdal_translate -projwin -82 14 -59 -21 -co COMPRESS=DEFLATE -co ZLEVEL=9 /vsicurl/https://os.zhdk.cloud.switch.ch/envicloud/chelsa/chelsa_V1/climatologies/prec/CHELSA_prec_${MM}_V1.2_land.tif  geodata/climate/CHELSA_prec_${MM}_V1.2_land_crop.tif
done
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 43200, 20880
0...10...20...30...40...50...60...70...80...90...100 - done.

Calculate annual mean and standard deviation with the monthly values.

[5]:
%%bash
cd /media/sf_LVM_shared/my_SE_data/exercise

# calculate mean and stdev for tmax,
for var in tmin tmax ; do
gdalbuildvrt -overwrite -separate geodata/climate/CHELSA_${var}10_1979-2013_V1.2_land_crop.vrt geodata/climate/CHELSA_${var}10_*_1979-2013_V1.2_land_crop.tif

pkstatprofile -co COMPRESS=DEFLATE -co ZLEVEL=9  -nodata -32768 -f  mean -i geodata/climate/CHELSA_${var}10_1979-2013_V1.2_land_crop.vrt -o geodata/climate/CHELSA_${var}10_1979-2013_V1.2_land_crop_mean_tmp.tif
pkstatprofile -co COMPRESS=DEFLATE -co ZLEVEL=9  -nodata -32768 -f stdev -i geodata/climate/CHELSA_${var}10_1979-2013_V1.2_land_crop.vrt -o geodata/climate/CHELSA_${var}10_1979-2013_V1.2_land_crop_stdev_tmp.tif

gdal_translate -co COMPRESS=DEFLATE -co ZLEVEL=9 geodata/climate/CHELSA_${var}10_1979-2013_V1.2_land_crop_mean_tmp.tif  geodata/climate/CHELSA_${var}10_1979-2013_V1.2_land_crop_mean.tif
gdal_translate -co COMPRESS=DEFLATE -co ZLEVEL=9 geodata/climate/CHELSA_${var}10_1979-2013_V1.2_land_crop_stdev_tmp.tif geodata/climate/CHELSA_${var}10_1979-2013_V1.2_land_crop_stdev.tif
rm -f geodata/climate/CHELSA_${var}10_1979-2013_V1.2_land_crop_stdev_tmp.tif geodata/climate/CHELSA_${var}10_1979-2013_V1.2_land_crop_mean_tmp.tif

done
0...10...20...30...40...50...60...70...80...90...100 - done.
0...10...20...30...40...50...60...70...80...90...100 - done.
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 2760, 4200
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 2760, 4200
0...10...20...30...40...50...60...70...80...90...100 - done.
0...10...20...30...40...50...60...70...80...90...100 - done.
0...10...20...30...40...50...60...70...80...90...100 - done.
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 2760, 4200
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 2760, 4200
0...10...20...30...40...50...60...70...80...90...100 - done.
[6]:
%%bash
cd /media/sf_LVM_shared/my_SE_data/exercise

gdalbuildvrt -overwrite -separate geodata/climate/CHELSA_prec_V1.2_land_crop.vrt geodata/climate/CHELSA_prec_*V1.2_land_crop.tif

pkstatprofile -co COMPRESS=DEFLATE -co ZLEVEL=9  -nodata -32768 -f  mean  -i geodata/climate/CHELSA_prec_V1.2_land_crop.vrt  -o geodata/climate/CHELSA_prec_V1.2_land_crop_mean_tmp.tif
pkstatprofile -co COMPRESS=DEFLATE -co ZLEVEL=9  -nodata -32768 -f  stdev -i geodata/climate/CHELSA_prec_V1.2_land_crop.vrt  -o geodata/climate/CHELSA_prec_V1.2_land_crop_stdev_tmp.tif

gdal_translate -co COMPRESS=DEFLATE -co ZLEVEL=9 geodata/climate/CHELSA_prec_V1.2_land_crop_mean_tmp.tif  geodata/climate/CHELSA_prec_V1.2_land_crop_mean.tif
gdal_translate -co COMPRESS=DEFLATE -co ZLEVEL=9 geodata/climate/CHELSA_prec_V1.2_land_crop_stdev_tmp.tif geodata/climate/CHELSA_prec_V1.2_land_crop_stdev.tif

rm geodata/climate/CHELSA_prec_V1.2_land_crop_mean_tmp.tif  geodata/climate/CHELSA_prec_V1.2_land_crop_stdev_tmp.tif
0...10...20...30...40...50...60...70...80...90...100 - done.
0...10...20...30...40...50...60...70...80...90...100 - done.
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 2760, 4200
0...10...20...30...40...50...60...70...80...90...100 - done.
Input file size is 2760, 4200
0...10...20...30...40...50...60...70...80...90...100 - done.

Building geomorphometric layers

  1. Geomorphometric layers (grade 20%)

Using the GMTED2010 DEM (geodata/dem/SA_elevation_mn_GMTED2010_mn_crop.tif) calculate “aspect” “slope” “Terrain Ruggedness Index” using gdal. I have opt for the uploding of “Multiple Attempts”, so in case you want upload another version of the homework now is possible - please do not send it by e-mail.

[10]:
%%bash
cd /media/sf_LVM_shared/my_SE_data/exercise

# To calculate the slope by gdaldem slope in lat long you need to setup corretly the scale flag.
# The slope scale value is 111120 at the equator and 0 at the north/south pole. In order to get the slope correctly
# you need first calculate the scale value in accordance to the latitudinal level of your dem
# gdalinfo geodata/dem/SA_elevation_mn_GMTED2010_mn_crop.tif
# Center      ( -70.5000000,  -3.5000000)
# 111120 - (111120 /90 * 3.5) = 106798

gdaldem slope  -co COMPRESS=DEFLATE -co ZLEVEL=9  -scale 106798 geodata/dem/SA_elevation_mn_GMTED2010_mn_crop.tif geodata/dem/SA_elevation_mn_GMTED2010_mn_crop_slope.tif
gdaldem aspect -co COMPRESS=DEFLATE -co ZLEVEL=9  geodata/dem/SA_elevation_mn_GMTED2010_mn_crop.tif geodata/dem/SA_elevation_mn_GMTED2010_mn_crop_aspect.tif
gdaldem TRI    -co COMPRESS=DEFLATE -co ZLEVEL=9  geodata/dem/SA_elevation_mn_GMTED2010_mn_crop.tif geodata/dem/SA_elevation_mn_GMTED2010_mn_crop_tri.tif
0...10...20...30...40...50...60...70...80...90...100 - done.
0...10...20...30...40...50...60...70...80...90...100 - done.
0...10...20...30...40...50...60...70...80...90...100 - done.

Masking

Many of the layers that we have downloaded have the same pixel values for the sea and also for the land (e.g. percent of vegation = 0% is given to desert area and also to the see). We can use an uncilary layers (/media/sf_LVM_shared/my_SE_data/exercise/geodata/mask/msk_1km.tif) to mask all the other layers and give a common no-data value.

[8]:
%%bash
cd /media/sf_LVM_shared/my_SE_data/exercise

pksetmask -ot Int16 -m geodata/mask/msk_1km.tif -msknodata 0 -nodata -9999 -i geodata/cloud/SA_meanannual_crop.tif -o geodata/cloud/SA_meanannual_crop_msk.tif
pksetmask -ot Int16 -m geodata/mask/msk_1km.tif -msknodata 0 -nodata -9999 -i geodata/cloud/SA_intra_crop.tif -o geodata/cloud/SA_intra_crop_msk.tif

pksetmask -ot Int16 -m geodata/mask/msk_1km.tif -msknodata 0 -nodata -9999 -i geodata/dem/SA_elevation_mn_GMTED2010_mn_crop.tif -o geodata/dem/SA_elevation_mn_GMTED2010_mn_crop_msk.tif
pksetmask -ot Int16 -m geodata/mask/msk_1km.tif -msknodata 0 -nodata -9999 -i geodata/vegetation/SA_tree_mn_percentage_GFC2013_crop.tif  -o geodata/vegetation/SA_tree_mn_percentage_GFC2013_crop_msk.tif
0...10...20...30...40...50...60...70...80...90...100 - done.
0...10...20...30...40...50...60...70...80...90...100 - done.
0...10...20...30...40...50...60...70...80...90...100 - done.
0...10...20...30...40...50...60...70...80...90...100 - done.
[ ]: