Project

General

Profile

« Previous | Next » 

Revision 73e9d9c6

Added by Giuseppe over 11 years ago

setting git repository for dem_variables folder

View differences:

terrain/procedures/dem_variables/dem90_res_x10/sc1_dem_variables.sh
1
# variables derived from the dem following commands in http://www.gdal.org/gdaldem.html#gdaldem_slope 
2
# to check ls tif/Smoothed*.tif  | xargs -n 1 -P 30 bash -c $' gdalinfo  -mm $1 |grep Max  | awk \'{ gsub("[=,]", " ") ;  print $3,$4  }\'  ' _ 
3

  
4

  
5
# find /mnt/data2/dem_variables/{altitude,aspect,roughness,slope,tpi,tri}  -name *.tif | xargs -n 1 -P 10 rm ; 
6

  
7
# ls /mnt/data/jetzlab/Data/environ/global/dem/tiles/Smoothed_*.bil | xargs -n 1 -P 12 bash  /mnt/data2/dem_variables/scripts/sc1_dem_variables.sh
8

  
9
# scandinavia 
10
# ls /mnt/data/jetzlab/Data/environ/global/dem/tiles/Smoothed_N{55,60,65,70}E0{05,10,15,20,25,30}.bil | xargs -n 1 -P 12 bash /mnt/data2/dem_variables/scripts/sc1_dem_variables.sh
11

  
12
export OUTDIR=/mnt/data2/dem_variables
13
export file=$1
14
export filename=`basename $file .bil` 
15

  
16
(
17

  
18
# gdal_translate -ot Int16  -co COMPRESS=LZW  $file $OUTDIR/tif/$filename.tif
19

  
20
echo altitude variables with file    $OUTDIR/tif/$filename.tif
21

  
22
# # median 
23
# pkfilter -m -32768   -dx 10 -dy 10   -f median -d 10 -i  $OUTDIR/tif/$filename.tif    -o  $OUTDIR/altitude/median/tiles/$filename.tif     -co COMPRESS=LZW -ot Int16  
24
# # stdev
25
# pkfilter -m -32768 -dx 10 -dy 10   -f var -d 10 -i $OUTDIR/tif/$filename.tif   -o  $OUTDIR/altitude/stdev/tiles/tmp_$filename.tif  -co COMPRESS=LZW -ot Int32   # max 1552385.000 sqrt(1245.947)
26
# gdal_calc.py -A  $OUTDIR/altitude/stdev/tiles/tmp_$filename.tif --calc="sqrt(A)" --type Int16 --overwrite --outfile $OUTDIR/altitude/stdev/tiles/$filename.tif
27
# rm -f   $OUTDIR/altitude/stdev/tiles/tmp_$filename
28
# # min 
29
# pkfilter -m -32768  -dx 10 -dy 10   -f min -d 10 -i $OUTDIR/tif/$filename.tif   -o  $OUTDIR/altitude/min/tiles/$filename.tif    -co COMPRESS=LZW -ot Int16  
30
# # max
31
# pkfilter -m -32768 -dx 10 -dy 10   -f max -d 10 -i $OUTDIR/tif/$filename.tif   -o  $OUTDIR/altitude/max/tiles/$filename.tif    -co COMPRESS=LZW -ot Int16  
32
# # mean
33
# pkfilter -m -32768 -dx 10 -dy 10   -f mean -d 10 -i $OUTDIR/tif/$filename.tif   -o  $OUTDIR/altitude/mean/tiles/$filename.tif  -co COMPRESS=LZW  -ot Int16  
34

  
35
# # starting to use gdaldem to compute variables. Gdaldem use -9999 as no data. 
36

  
37
# echo  slope with file   $OUTDIR/tif/$filename.tif
38
# gdaldem slope  -s 111120 -co COMPRESS=LZW   $OUTDIR/tif/$filename.tif  $OUTDIR/slope/tiles/$filename.tif  # -s to consider xy in degree and z in meters
39
# # slope median 
40
# pkfilter -m -9999 -dx 10 -dy 10 -f median  -d 10 -i $OUTDIR/slope/tiles/$filename.tif -o $OUTDIR/slope/median/tiles/$filename.tif -co COMPRESS=LZW -ot Byte
41
# # slope stdev 
42
# pkfilter -m -9999 -dx 10 -dy 10 -f var -d 10 -i $OUTDIR/slope/tiles/$filename.tif -o  $OUTDIR/slope/stdev/tiles/tmp_$filename.tif -co COMPRESS=LZW -ot Int32
43
# gdal_calc.py -A  $OUTDIR/slope/stdev/tiles/tmp_$filename.tif --calc="sqrt(A)" --type Int16 --overwrite --outfile $OUTDIR/slope/stdev/tiles/$filename.tif
44
# rm -f  $OUTDIR/slope/stdev/tiles/tmp_$filename
45
# # slope min 
46
# pkfilter -m -9999  -dx 10 -dy 10 -f min -d 10 -i $OUTDIR/slope/tiles/$filename.tif -o  $OUTDIR/slope/min/tiles/$filename.tif -co COMPRESS=LZW   -ot Byte 
47
# # slope max
48
# pkfilter -m -9999 -dx 10 -dy 10 -f max -d 10 -i $OUTDIR/slope/tiles/$filename.tif -o  $OUTDIR/slope/max/tiles/$filename.tif -co COMPRESS=LZW   -ot Byte 
49
# # slope mean
50
# pkfilter -m -9999 -dx 10 -dy 10 -f mean -d 10 -i $OUTDIR/slope/tiles/$filename.tif -o  $OUTDIR/slope/mean/tiles/$filename.tif -co COMPRESS=LZW  -ot Byte 
51

  
52
# rm -f  $OUTDIR/slope/tiles/$filename.tif
53

  
54
# echo  generate a Terrain Ruggedness Index TRI  with file   $file
55
# gdaldem TRI  -co COMPRESS=LZW   $OUTDIR/tif/$filename.tif  $OUTDIR/tri/tiles/$filename.tif
56
# # tri median 
57
# pkfilter -m -9999 -dx 10 -dy 10 -f median -d 10 -i $OUTDIR/tri/tiles/$filename.tif -o $OUTDIR/tri/median/tiles/$filename.tif -co COMPRESS=LZW -ot Int16  
58
# # tri stdev 
59
# pkfilter -m -9999 -dx 10 -dy 10 -f var -d 10 -i $OUTDIR/tri/tiles/$filename.tif -o  $OUTDIR/tri/stdev/tiles/tmp_$filename.tif -co COMPRESS=LZW 
60
# gdal_calc.py -A  $OUTDIR/tri/stdev/tiles/tmp_$filename.tif --calc="sqrt(A)" --type Int16 --overwrite --outfile $OUTDIR/tri/stdev/tiles/$filename.tif
61
# rm -f  $OUTDIR/tri/stdev/tiles/tmp_$filename
62
# # tri min 
63
# pkfilter -m -9999 -dx 10 -dy 10 -f min -d 10 -i $OUTDIR/tri/tiles/$filename.tif -o  $OUTDIR/tri/min/tiles/$filename.tif -co COMPRESS=LZW -ot Int16  
64
# # tri max
65
# pkfilter -m -9999 -dx 10 -dy 10 -f max -d 10 -i $OUTDIR/tri/tiles/$filename.tif -o  $OUTDIR/tri/max/tiles/$filename.tif -co COMPRESS=LZW -ot Int16
66
# # tri mean
67
# pkfilter -m -9999 -dx 10 -dy 10 -f mean -d 10 -i $OUTDIR/tri/tiles/$filename.tif -o  $OUTDIR/tri/mean/tiles/$filename.tif -co COMPRESS=LZW -ot Int16
68

  
69
# rm -f  $OUTDIR/tri/tiles/$filename.tif
70

  
71

  
72
echo  generate a Topographic Position Index TPI  with file   $OUTDIR/tif/$filename.tif
73
# gdaldem TPI  -co COMPRESS=LZW   $OUTDIR/tif/$filename.tif  $OUTDIR/tpi/tiles/$filename.tif       # tpi has negative number 
74

  
75
oft-calc -ot Float32   $OUTDIR/tpi/tiles/$filename.tif $OUTDIR/tpi/tiles/$filename"_t10.tif"  &> /dev/null    <<EOF
76
1
77
#1 10 *
78
EOF
79

  
80
# tpi median 
81
pkfilter -m -9999 -dx 10 -dy 10 -f median -d 10 -i $OUTDIR/tpi/tiles/$filename"_t10.tif"  -o $OUTDIR/tpi/median/tiles/$filename.tif -co COMPRESS=LZW -ot Int16
82
echo tpi stdev 
83
pkfilter -m -9999 -dx 10 -dy 10 -f var -d 10 -i $OUTDIR/tpi/tiles/$filename"_t10.tif"  -o $OUTDIR/tpi/stdev/tiles/tmp_$filename.tif -co COMPRESS=LZW 
84
gdal_calc.py -A  $OUTDIR/tpi/stdev/tiles/tmp_$filename.tif  --calc="sqrt(A)" --type Int32 --overwrite --outfile $OUTDIR/tpi/stdev/tiles/$filename.tif
85
rm -f  $OUTDIR/tpi/stdev/tiles/tmp_$filename
86
# tpi min 
87
pkfilter -m -9999 -dx 10 -dy 10 -f min -d 10  -i $OUTDIR/tpi/tiles/$filename"_t10.tif" -o $OUTDIR/tpi/min/tiles/$filename.tif   -co COMPRESS=LZW -ot Int16
88
# tpi max
89
pkfilter -m -9999 -dx 10 -dy 10 -f max -d 10  -i $OUTDIR/tpi/tiles/$filename"_t10.tif" -o $OUTDIR/tpi/max/tiles/$filename.tif   -co COMPRESS=LZW -ot Int16
90
# tpi mean
91
pkfilter -m -9999 -dx 10 -dy 10 -f mean -d 10 -i $OUTDIR/tpi/tiles/$filename"_t10.tif" -o $OUTDIR/tpi/mean/tiles/$filename.tif  -co COMPRESS=LZW -ot Int16
92

  
93

  
94

  
95

  
96

  
97
# echo  generate roughness   with file   $OUTDIR/tif/$filename.tif
98

  
99
# gdaldem  roughness  -co COMPRESS=LZW   $OUTDIR/tif/$filename.tif  $OUTDIR/roughness/tiles/$filename.tif
100

  
101
# # roughness median 
102
# pkfilter -m -9999 -dx 10 -dy 10 -f median -d 10 -i $OUTDIR/roughness/tiles/$filename.tif -o $OUTDIR/roughness/median/tiles/$filename.tif -co COMPRESS=LZW -ot Int16
103
# echo roughness stdev 
104
# pkfilter -m -9999 -dx 10 -dy 10 -f var  -d 10 -i $OUTDIR/roughness/tiles/$filename.tif -o $OUTDIR/roughness/stdev/tiles/tmp_$filename.tif -co COMPRESS=LZW 
105
# gdal_calc.py -A  $OUTDIR/roughness/stdev/tiles/tmp_$filename.tif --calc="sqrt(A)" --type Int32 --overwrite --outfile $OUTDIR/roughness/stdev/tiles/$filename.tif
106

  
107
# rm -f  $OUTDIR/roughness/stdev/tiles/tmp_$filename
108

  
109
# # roughness min 
110
# pkfilter -m -9999 -dx 10 -dy 10 -f min -d 10 -i $OUTDIR/roughness/tiles/$filename.tif -o $OUTDIR/roughness/min/tiles/$filename.tif    -co COMPRESS=LZW -ot Int16
111
# # roughness max
112
# pkfilter -m -9999 -dx 10 -dy 10 -f max -d 10 -i $OUTDIR/roughness/tiles/$filename.tif -o $OUTDIR/roughness/max/tiles/$filename.tif    -co COMPRESS=LZW -ot Int16
113
# # roughness mean
114
# pkfilter -m -9999 -dx 10 -dy 10 -f mean -d 10 -i $OUTDIR/roughness/tiles/$filename.tif -o $OUTDIR/roughness/mean/tiles/$filename.tif  -co COMPRESS=LZW -ot Int16
115

  
116
# rm -f   $OUTDIR/roughness/tiles/$filename.tif
117

  
118

  
119

  
120
echo  aspect  with file   $OUTDIR/tif/$filename.tif
121

  
122
gdaldem aspect  -zero_for_flat -co COMPRESS=LZW   $OUTDIR/tif/$filename.tif  $OUTDIR/aspect/tiles/$filename.tif
123

  
124
# r1 aspect , r2 slope 
125

  
126
gdal_calc.py --NoDataValue -9999 -A $OUTDIR/aspect/tiles/$filename.tif --calc="(sin(A))" --outfile   $OUTDIR/aspect/tiles/$filename"_sin.tif" --overwrite --type Float32
127
gdal_calc.py --NoDataValue -9999 -A $OUTDIR/aspect/tiles/$filename.tif --calc="(cos(A))" --outfile   $OUTDIR/aspect/tiles/$filename"_cos.tif" --overwrite --type Float32
128

  
129
gdal_calc.py --NoDataValue -9999 -A $OUTDIR/slope/tiles/$filename.tif -B  $OUTDIR/aspect/tiles/$filename"_sin.tif"  --calc="((sin(A))*B)" --outfile   $OUTDIR/aspect/tiles/$filename"_Ew.tif" --overwrite --type Float32
130
gdal_calc.py --NoDataValue -9999 -A $OUTDIR/slope/tiles/$filename.tif -B  $OUTDIR/aspect/tiles/$filename"_cos.tif"  --calc="((sin(A))*B)" --outfile   $OUTDIR/aspect/tiles/$filename"_Nw.tif" --overwrite --type Float32
131

  
132
echo  aspect sin   cos  Ew  Nw   median 
133
# sin
134
pkfilter -m -9999 -dx 10 -dy 10 -f median -d 10 -i   $OUTDIR/aspect/tiles/$filename"_sin.tif" -o   $OUTDIR/aspect/median/tiles/$filename"_sin_f.tif" -co COMPRESS=LZW -ot Float32
135
oft-calc -ot Int16   $OUTDIR/aspect/median/tiles/$filename"_sin_f.tif"  $OUTDIR/aspect/median/tiles/$filename"_sin_t10k_tmp.tif"  &> /dev/null    <<EOF
136
1
137
#1 10000 *
138
EOF
139
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/median/tiles/$filename"_sin_t10k_tmp.tif" $OUTDIR/aspect/median/tiles/$filename"_sin_t10k.tif"  
140
rm  $OUTDIR/aspect/median/tiles/$filename"_sin_t10k_tmp.tif" 
141
# cos
142
pkfilter -m -9999 -dx 10 -dy 10 -f median -d 10 -i   $OUTDIR/aspect/tiles/$filename"_cos.tif" -o   $OUTDIR/aspect/median/tiles/$filename"_cos_f.tif" -co COMPRESS=LZW -ot Float32
143
oft-calc  -ot Int16   $OUTDIR/aspect/median/tiles/$filename"_cos_f.tif"  $OUTDIR/aspect/median/tiles/$filename"_cos_t10k_tmp.tif"  &> /dev/null   <<EOF
144
1
145
#1 10000 *
146
EOF
147
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/median/tiles/$filename"_cos_t10k_tmp.tif" $OUTDIR/aspect/median/tiles/$filename"_cos_t10k.tif" 
148
rm  $OUTDIR/aspect/median/tiles/$filename"_cos_t10k_tmp.tif" 
149
# Ew
150
pkfilter -m -9999 -dx 10 -dy 10 -f median -d 10 -i   $OUTDIR/aspect/tiles/$filename"_Ew.tif" -o   $OUTDIR/aspect/median/tiles/$filename"_Ew_f.tif" -co COMPRESS=LZW -ot Float32
151
oft-calc -ot Int16   $OUTDIR/aspect/median/tiles/$filename"_Ew_f.tif"  $OUTDIR/aspect/median/tiles/$filename"_Ew_t10k_tmp.tif"  &> /dev/null   <<EOF
152
1
153
#1 10000 *
154
EOF
155
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/median/tiles/$filename"_Ew_t10k_tmp.tif" $OUTDIR/aspect/median/tiles/$filename"_Ew_t10k.tif" 
156
rm  $OUTDIR/aspect/median/tiles/$filename"_Ew_t10k_tmp.tif" 
157
# Nw
158
pkfilter -m -9999 -dx 10 -dy 10 -f median -d 10 -i   $OUTDIR/aspect/tiles/$filename"_Nw.tif" -o   $OUTDIR/aspect/median/tiles/$filename"_Nw_f.tif" -co COMPRESS=LZW -ot Float32
159
oft-calc  -ot Int16  $OUTDIR/aspect/median/tiles/$filename"_Nw_f.tif"  $OUTDIR/aspect/median/tiles/$filename"_Nw_t10k_tmp.tif"  &> /dev/null   <<EOF
160
1
161
#1 10000 *
162
EOF
163
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/median/tiles/$filename"_Nw_t10k_tmp.tif" $OUTDIR/aspect/median/tiles/$filename"_Nw_t10k.tif" 
164
rm  $OUTDIR/aspect/median/tiles/$filename"_Nw_t10k_tmp.tif" 
165

  
166

  
167
echo aspect sin   cos  Ew  Nw   mean
168
# sin
169
pkfilter -m -9999 -dx 10 -dy 10 -f mean -d 10 -i   $OUTDIR/aspect/tiles/$filename"_sin.tif" -o   $OUTDIR/aspect/mean/tiles/$filename"_sin_f.tif" -co COMPRESS=LZW -ot Float32
170
oft-calc -ot Int16   $OUTDIR/aspect/mean/tiles/$filename"_sin_f.tif"  $OUTDIR/aspect/mean/tiles/$filename"_sin_t10k_tmp.tif" &> /dev/null  <<EOF
171
1
172
#1 10000 *
173
EOF
174
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/mean/tiles/$filename"_sin_t10k_tmp.tif" $OUTDIR/aspect/mean/tiles/$filename"_sin_t10k.tif"  
175
rm  $OUTDIR/aspect/mean/tiles/$filename"_sin_t10k_tmp.tif" 
176
# cos
177
pkfilter -m -9999 -dx 10 -dy 10 -f mean -d 10 -i   $OUTDIR/aspect/tiles/$filename"_cos.tif" -o   $OUTDIR/aspect/mean/tiles/$filename"_cos_f.tif" -co COMPRESS=LZW -ot Float32
178
oft-calc -ot Int16   $OUTDIR/aspect/mean/tiles/$filename"_cos_f.tif"  $OUTDIR/aspect/mean/tiles/$filename"_cos_t10k_tmp.tif"  &> /dev/null   <<EOF
179
1
180
#1 10000 *
181
EOF
182
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/mean/tiles/$filename"_cos_t10k_tmp.tif" $OUTDIR/aspect/mean/tiles/$filename"_cos_t10k.tif" 
183
rm  $OUTDIR/aspect/mean/tiles/$filename"_cos_t10k_tmp.tif" 
184
# Ew
185
pkfilter -m -9999 -dx 10 -dy 10 -f mean -d 10 -i   $OUTDIR/aspect/tiles/$filename"_Ew.tif" -o   $OUTDIR/aspect/mean/tiles/$filename"_Ew_f.tif" -co COMPRESS=LZW -ot Float32
186
oft-calc -ot Int16   $OUTDIR/aspect/mean/tiles/$filename"_Ew_f.tif"  $OUTDIR/aspect/mean/tiles/$filename"_Ew_t10k_tmp.tif"  &> /dev/null  <<EOF
187
1
188
#1 10000 *
189
EOF
190
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/mean/tiles/$filename"_Ew_t10k_tmp.tif" $OUTDIR/aspect/mean/tiles/$filename"_Ew_t10k.tif" 
191
rm  $OUTDIR/aspect/mean/tiles/$filename"_Ew_t10k_tmp.tif" 
192
# Nw
193
pkfilter -m -9999 -dx 10 -dy 10 -f mean -d 10 -i   $OUTDIR/aspect/tiles/$filename"_Nw.tif" -o   $OUTDIR/aspect/mean/tiles/$filename"_Nw_f.tif" -co COMPRESS=LZW -ot Float32
194
oft-calc  -ot Int16  $OUTDIR/aspect/mean/tiles/$filename"_Nw_f.tif"  $OUTDIR/aspect/mean/tiles/$filename"_Nw_t10k_tmp.tif"  &> /dev/null   <<EOF
195
1
196
#1 10000 *
197
EOF
198
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/mean/tiles/$filename"_Nw_t10k_tmp.tif" $OUTDIR/aspect/mean/tiles/$filename"_Nw_t10k.tif" 
199
rm  $OUTDIR/aspect/mean/tiles/$filename"_Nw_t10k_tmp.tif" 
200

  
201
echo aspect sin   cos  Ew  Nw   max
202
# sin
203
pkfilter -m -9999 -dx 10 -dy 10 -f max -d 10 -i   $OUTDIR/aspect/tiles/$filename"_sin.tif" -o   $OUTDIR/aspect/max/tiles/$filename"_sin_f.tif" -co COMPRESS=LZW -ot Float32
204
oft-calc -ot Int16  $OUTDIR/aspect/max/tiles/$filename"_sin_f.tif"  $OUTDIR/aspect/max/tiles/$filename"_sin_t10k_tmp.tif"   &> /dev/null  <<EOF
205
1
206
#1 10000 *
207
EOF
208
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/max/tiles/$filename"_sin_t10k_tmp.tif" $OUTDIR/aspect/max/tiles/$filename"_sin_t10k.tif"  
209
rm  $OUTDIR/aspect/max/tiles/$filename"_sin_t10k_tmp.tif" 
210
# cos
211
pkfilter -m -9999 -dx 10 -dy 10 -f max -d 10 -i   $OUTDIR/aspect/tiles/$filename"_cos.tif" -o   $OUTDIR/aspect/max/tiles/$filename"_cos_f.tif" -co COMPRESS=LZW -ot Float32
212
oft-calc  -ot Int16  $OUTDIR/aspect/max/tiles/$filename"_cos_f.tif"  $OUTDIR/aspect/max/tiles/$filename"_cos_t10k_tmp.tif"  &> /dev/null  <<EOF
213
1
214
#1 10000 *
215
EOF
216
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/max/tiles/$filename"_cos_t10k_tmp.tif" $OUTDIR/aspect/max/tiles/$filename"_cos_t10k.tif" 
217
rm  $OUTDIR/aspect/max/tiles/$filename"_cos_t10k_tmp.tif" 
218
# Ew
219
pkfilter -m -9999 -dx 10 -dy 10 -f max -d 10 -i   $OUTDIR/aspect/tiles/$filename"_Ew.tif" -o   $OUTDIR/aspect/max/tiles/$filename"_Ew_f.tif" -co COMPRESS=LZW -ot Float32
220
oft-calc  -ot Int16   $OUTDIR/aspect/max/tiles/$filename"_Ew_f.tif"  $OUTDIR/aspect/max/tiles/$filename"_Ew_t10k_tmp.tif" &> /dev/null   <<EOF
221
1
222
#1 10000 *
223
EOF
224
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/max/tiles/$filename"_Ew_t10k_tmp.tif" $OUTDIR/aspect/max/tiles/$filename"_Ew_t10k.tif" 
225
rm  $OUTDIR/aspect/max/tiles/$filename"_Ew_t10k_tmp.tif" 
226
# Nw
227
pkfilter -m -9999 -dx 10 -dy 10 -f max -d 10 -i   $OUTDIR/aspect/tiles/$filename"_Nw.tif" -o   $OUTDIR/aspect/max/tiles/$filename"_Nw_f.tif" -co COMPRESS=LZW -ot Float32
228
oft-calc  -ot Int16   $OUTDIR/aspect/max/tiles/$filename"_Nw_f.tif"  $OUTDIR/aspect/max/tiles/$filename"_Nw_t10k_tmp.tif"  &> /dev/null   <<EOF
229
1
230
#1 10000 *
231
EOF
232
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/max/tiles/$filename"_Nw_t10k_tmp.tif" $OUTDIR/aspect/max/tiles/$filename"_Nw_t10k.tif" 
233
rm  $OUTDIR/aspect/max/tiles/$filename"_Nw_t10k_tmp.tif" 
234

  
235
echo aspect sin   cos  Ew  Nw   min 
236
# sin
237
pkfilter -m -9999 -dx 10 -dy 10 -f min -d 10 -i   $OUTDIR/aspect/tiles/$filename"_sin.tif" -o   $OUTDIR/aspect/min/tiles/$filename"_sin_f.tif" -co COMPRESS=LZW -ot Float32
238
oft-calc  -ot Int16   $OUTDIR/aspect/min/tiles/$filename"_sin_f.tif"  $OUTDIR/aspect/min/tiles/$filename"_sin_t10k_tmp.tif"  &> /dev/null   <<EOF
239
1
240
#1 10000 *
241
EOF
242
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/min/tiles/$filename"_sin_t10k_tmp.tif" $OUTDIR/aspect/min/tiles/$filename"_sin_t10k.tif"  
243
rm  $OUTDIR/aspect/min/tiles/$filename"_sin_t10k_tmp.tif" 
244
# cos
245
pkfilter -m -9999 -dx 10 -dy 10 -f min -d 10 -i   $OUTDIR/aspect/tiles/$filename"_cos.tif" -o   $OUTDIR/aspect/min/tiles/$filename"_cos_f.tif" -co COMPRESS=LZW -ot Float32
246
oft-calc  -ot Int16   $OUTDIR/aspect/min/tiles/$filename"_cos_f.tif"  $OUTDIR/aspect/min/tiles/$filename"_cos_t10k_tmp.tif"  &> /dev/null  <<EOF
247
1
248
#1 10000 *
249
EOF
250
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/min/tiles/$filename"_cos_t10k_tmp.tif" $OUTDIR/aspect/min/tiles/$filename"_cos_t10k.tif" 
251
rm  $OUTDIR/aspect/min/tiles/$filename"_cos_t10k_tmp.tif" 
252
# Ew
253
pkfilter -m -9999 -dx 10 -dy 10 -f min -d 10 -i   $OUTDIR/aspect/tiles/$filename"_Ew.tif" -o   $OUTDIR/aspect/min/tiles/$filename"_Ew_f.tif" -co COMPRESS=LZW -ot Float32
254
oft-calc -ot Int16   $OUTDIR/aspect/min/tiles/$filename"_Ew_f.tif"  $OUTDIR/aspect/min/tiles/$filename"_Ew_t10k_tmp.tif" &> /dev/null   <<EOF
255
1
256
#1 10000 *
257
EOF
258
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/min/tiles/$filename"_Ew_t10k_tmp.tif" $OUTDIR/aspect/min/tiles/$filename"_Ew_t10k.tif" 
259
rm  $OUTDIR/aspect/min/tiles/$filename"_Ew_t10k_tmp.tif" 
260
# Nw
261
pkfilter -m -9999 -dx 10 -dy 10 -f min -d 10 -i   $OUTDIR/aspect/tiles/$filename"_Nw.tif" -o   $OUTDIR/aspect/min/tiles/$filename"_Nw_f.tif" -co COMPRESS=LZW -ot Float32
262
oft-calc -ot Int16   $OUTDIR/aspect/min/tiles/$filename"_Nw_f.tif"  $OUTDIR/aspect/min/tiles/$filename"_Nw_t10k_tmp.tif"  &> /dev/null   <<EOF
263
1
264
#1 10000 *
265
EOF
266
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/min/tiles/$filename"_Nw_t10k_tmp.tif" $OUTDIR/aspect/min/tiles/$filename"_Nw_t10k.tif" 
267
rm  $OUTDIR/aspect/min/tiles/$filename"_Nw_t10k_tmp.tif" 
268

  
269
echo aspect sin   cos  Ew  Nw   stdev
270
# stdev   
271
pkfilter -m -9999 -dx 10 -dy 10 -f var -d 10 -i   $OUTDIR/aspect/tiles/$filename"_sin.tif" -o   $OUTDIR/aspect/stdev/tiles/$filename"_sin_f.tif" -co COMPRESS=LZW -ot Float32
272
gdal_calc.py -A  $OUTDIR/aspect/stdev/tiles/$filename"_sin_f.tif"  --calc="(sqrt(A))*10000" --type Int16 --overwrite --outfile  $OUTDIR/aspect/stdev/tiles/$filename"_sin_t10k_tmp.tif"
273
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/stdev/tiles/$filename"_sin_t10k_tmp.tif" $OUTDIR/aspect/stdev/tiles/$filename"_sin_t10k.tif"  
274
rm  $OUTDIR/aspect/stdev/tiles/$filename"_sin_t10k_tmp.tif" 
275
# cos
276
pkfilter -m -9999 -dx 10 -dy 10 -f var -d 10 -i   $OUTDIR/aspect/tiles/$filename"_cos.tif" -o   $OUTDIR/aspect/stdev/tiles/$filename"_cos_f.tif" -co COMPRESS=LZW -ot Float32
277
gdal_calc.py -A  $OUTDIR/aspect/stdev/tiles/$filename"_cos_f.tif"  --calc="(sqrt(A))*10000" --type Int16 --overwrite --outfile  $OUTDIR/aspect/stdev/tiles/$filename"_cos_t10k_tmp.tif"
278
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/stdev/tiles/$filename"_cos_t10k_tmp.tif" $OUTDIR/aspect/stdev/tiles/$filename"_cos_t10k.tif" 
279
rm  $OUTDIR/aspect/stdev/tiles/$filename"_cos_t10k_tmp.tif" 
280
# Ew
281
pkfilter -m -9999 -dx 10 -dy 10 -f var -d 10 -i   $OUTDIR/aspect/tiles/$filename"_Ew.tif" -o   $OUTDIR/aspect/stdev/tiles/$filename"_Ew_f.tif" -co COMPRESS=LZW -ot Float32
282
gdal_calc.py -A  $OUTDIR/aspect/stdev/tiles/$filename"_Ew_f.tif"  --calc="(sqrt(A))*10000" --type Int16 --overwrite --outfile  $OUTDIR/aspect/stdev/tiles/$filename"_Ew_t10k_tmp.tif"
283
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/stdev/tiles/$filename"_Ew_t10k_tmp.tif" $OUTDIR/aspect/stdev/tiles/$filename"_Ew_t10k.tif" 
284
rm  $OUTDIR/aspect/stdev/tiles/$filename"_Ew_t10k_tmp.tif" 
285
# Nw
286
pkfilter -m -9999 -dx 10 -dy 10 -f var -d 10 -i   $OUTDIR/aspect/tiles/$filename"_Nw.tif" -o   $OUTDIR/aspect/stdev/tiles/$filename"_Nw_f.tif" -co COMPRESS=LZW -ot Float32
287
gdal_calc.py -A  $OUTDIR/aspect/stdev/tiles/$filename"_Nw_f.tif"  --calc="(sqrt(A))*10000" --type Int16 --overwrite --outfile  $OUTDIR/aspect/stdev/tiles/$filename"_Nw_t10k_tmp.tif"
288
gdal_translate  -co COMPRESS=LZW  -ot Int16  $OUTDIR/aspect/stdev/tiles/$filename"_Nw_t10k_tmp.tif" $OUTDIR/aspect/stdev/tiles/$filename"_Nw_t10k.tif" 
289
rm  $OUTDIR/aspect/stdev/tiles/$filename"_Nw_t10k_tmp.tif" 
290

  
291
) 2>&1 | tee   /mnt/data2/dem_variables/log.txt
terrain/procedures/dem_variables/dem90_res_x10/sc1_slope_treshold_percent.sh
1
# calculate slope or area percent above a specific treshold   eg 0-4.9 put 0 ; 5-9.9 put 5
2
# for this case the treshold is set every 5 degrees  
3
# geting the integer of the altitued / 100
4

  
5
# ls /mnt/data/jetzlab/Data/environ/global/dem_variables/slope/tiles/Smoothed_N*E*.tif  | xargs -n 1 -P 36  bash /mnt/data/jetzlab/Data/environ/global/dem_variables/scripts/sc1_slope_treshold_percent.sh
6
# too check 
7
# ny=45 ; for n in `seq 1 9` ;do echo ` gdallocationinfo -valonly tiles/Smoothed_N00E005.tif 2$n $ny` `gdallocationinfo  -valonly  class/class/Smoothed_N00E005_class.tif 2$n $ny` ; done 
8

  
9
export file=$1
10
export filename=`basename $file .tif`
11
(
12
INDIR=/mnt/data/jetzlab/Data/environ/global/dem_variables/slope/tiles
13
OUTDIR=/mnt/data/jetzlab/Data/environ/global/dem_variables/slope/class/class
14

  
15
# calcualte slope every 5 degree using the the Int16 factors
16

  
17
oft-calc  -ot Byte $INDIR/$filename.tif $OUTDIR/$filename"_class_tmp1.tif"    <<EOF
18
1
19
#1 2.5 - 5 /
20
EOF
21

  
22
oft-calc  -inv -ot Byte  $OUTDIR/$filename"_class_tmp1.tif"  $OUTDIR/$filename"_class_tmp2.tif"     <<EOF
23
1
24
#1 5 *
25
EOF
26

  
27
oft-calc  -inv -ot Byte  $OUTDIR/$filename"_class_tmp2.tif"  $OUTDIR/$filename"_class_tmp3.tif"    <<EOF
28
1
29
#1 0 < 0 #1 ?
30
EOF
31

  
32
gdal_translate -co COMPRESS=LZW -co ZLEVEL=9 $OUTDIR/$filename"_class_tmp3.tif" $OUTDIR/$filename"_class.tif"
33
rm $OUTDIR/$filename"_class_tmp1.tif"  $OUTDIR/$filename"_class_tmp2.tif" $OUTDIR/$filename"_class_tmp3.tif"
34

  
35
gdalinfo -mm $OUTDIR/$filename"_class.tif"  | grep Computed | awk '{ gsub ("[=,]"," "); print int($(NF-1)), int($(NF))}' > $OUTDIR/txt/$filename"_min_max.txt"
36

  
37
for class in $(seq `awk '{ print $1}'  $OUTDIR/txt/${filename}_min_max.txt` 5  `awk '{ print $2}' $OUTDIR/txt/${filename}_min_max.txt`) ; do 
38

  
39
    class_start=$class
40
    class_end=$(awk '{ print $2}' $OUTDIR/txt/$filename"_min_max.txt")
41
    class_string=$(for class_unique in $(seq $class_start 5  $class_end  ) ; do echo -n "-class $class_unique "  ; done) 
42

  
43
    echo applaid the filter for the classes  $class_string
44

  
45
    pkfilter -dx 10 -dy 10  $class_string -f density -d 10 -i $OUTDIR/$filename"_class.tif" -o $OUTDIR/../class$class/$filename"_C"$class"Perc.tif" -co COMPRESS=LZW -co ZLEVEL=9   -ot Byte 
46

  
47
done 
48

  
49

  
50
) 2>&1 | tee  /mnt/data/jetzlab/Data/environ/global/tif_tmp/log_of_$filename".txt"
terrain/procedures/dem_variables/dem90_res_x10/sc2_dem_merge.sh
1
# calculate different variables for the dem 
2
# for dir1  in altitude  ; do for dir2 in stdev ; do echo $dir1/$dir2 ; done ; done  | xargs -n 1 -P 5 bash /mnt/data2/dem_variables/scripts/sc2_dem_merge.sh
3
# for dir1  in altitude slope tri tpi roughness ; do for dir2 in max mean median min stdev; do echo $dir1/$dir2 ; done ; done  | xargs -n 1 -P 12  bash /mnt/data2/dem_variables/scripts/sc2_dem_merge.sh
4

  
5

  
6
OUTDIR=/mnt/data2/dem_variables/resol_x10
7

  
8
DIR=$1
9
dir1=$(echo ${DIR%/*})   # cancel the part after  /
10
dir2=$(echo ${DIR#*/})   # cancel the part before /
11

  
12

  
13
if [ $dir1 = altitude ]  ; then type=Int16 ; fi 
14
if [ $dir1 = aspect ]    ; then type=Int16 ; fi 
15
if [ $dir1 = slope ]     ; then type=Byte ; fi  
16
if [ $dir1 = tri ]       ; then type=Int16 ; fi 
17
if [ $dir1 = tpi ]       ; then type=Int16 ; fi   
18
if [ $dir1 = roughness ] ; then type=Int16 ; fi 
19

  
20
if [ $dir1 != aspect ]; then 
21

  
22
echo processing merging tiles in $dir1   
23
           
24
rm -f $OUTDIR/$DIR/$dir1"_"$dir2.tif
25
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_NW".tif  
26
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_NE".tif  
27
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_SW".tif  
28
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_SE".tif
29

  
30
gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2"_NW".tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/tiles/Smoothed_N*W*.tif 
31
gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2"_NE".tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/tiles/Smoothed_N*E*.tif 
32
gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2"_SW".tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/tiles/Smoothed_S*W*.tif  
33
gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2"_SE".tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/tiles/Smoothed_S*E*.tif  
34

  
35
exit
36

  
37
rm -f  $OUTDIR/$DIR/$dir1"_"$dir2.tif
38

  
39
gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2.tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/$dir1"_"$dir2"_NW".tif  $OUTDIR/$DIR/$dir1"_"$dir2"_NE".tif  $OUTDIR/$DIR/$dir1"_"$dir2"_SW".tif  $OUTDIR/$DIR/$dir1"_"$dir2"_SE".tif 
40

  
41
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_NW".tif  
42
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_NE".tif  
43
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_SW".tif  
44
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_SE".tif
45

  
46
else  # just applaied to the aspect variables 
47

  
48
echo processing merging tiles for the different aspect variables in $dir1   
49

  
50
for aspect_var in "_sin_t10k" "_cos_t10k" "_Ew_t10k" "_Nw_t10k" ; do 
51

  
52
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_NW"$aspect_var.tif
53
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_NE"$aspect_var.tif
54
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_SW"$aspect_var.tif
55
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_SE"$aspect_var.tif
56

  
57
gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2"_NW"$aspect_var.tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/tiles/Smoothed_N*W*$aspect_var.tif
58
gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2"_NE"$aspect_var.tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/tiles/Smoothed_N*E*$aspect_var.tif 
59
gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2"_SW"$aspect_var.tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/tiles/Smoothed_S*W*$aspect_var.tif
60
gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2"_SE"$aspect_var.tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/tiles/Smoothed_S*E*$aspect_var.tif
61

  
62
rm -f  $OUTDIR/$DIR/$dir1"_"$dir2$aspect_var.tif
63

  
64
gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2$aspect_var.tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/$dir1"_"$dir2"_NW"$aspect_var.tif  $OUTDIR/$DIR/$dir1"_"$dir2"_NE"$aspect_var.tif  $OUTDIR/$DIR/$dir1"_"$dir2"_SW"$aspect_var.tif  $OUTDIR/$DIR/$dir1"_"$dir2"_SE"$aspect_var.tif
65

  
66
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_NW"$aspect_var.tif  
67
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_NE"$aspect_var.tif  
68
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_SW"$aspect_var.tif  
69
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_SE"$aspect_var.tif
70

  
71
done
72

  
73
fi 
74

  
75

  
76

  
terrain/procedures/dem_variables/dem90_res_x10/sc2_dem_treshold_density_merge.sh
1

  
2

  
3
# for dir in `seq -600 100 8700` ; do echo $dir ; done |  xargs -n 1 -P 36 bash /mnt/data/jetzlab/Data/environ/global/dem_class/sc2_dem_treshold_density_merge.sh
4

  
5
DIR=$1
6

  
7
INDIR=/mnt/data/jetzlab/Data/environ/global/dem_class/class$DIR
8
OUTDIR=/mnt/data/jetzlab/Data/environ/global/dem_class/percent
9

  
10
rm  $INDIR/file_processed_sc1.txt  # the file has ben processed by the script sc1_dem_treshold_percent.sh
11

  
12
for tile in `cat $OUTDIR/../geo_file/list_tiles.txt  ` ; do 
13

  
14
# for tile in `grep -e N45E09*  -e  N50E09* -e N55E09*   $OUTDIR/../list_tiles.txt`  ; do 
15

  
16
    if [ -f $INDIR/$tile"_C"$DIR"Perc.tif" ] ; then 
17

  
18
	echo the file  $INDIR/$tile"_C"$DIR"Perc.tif"   exist and will be merged as it is
19
	echo $tile"_C"$DIR"Perc.tif" >>  $INDIR/file_processed_sc1.txt # usefull to list file processed by script sc1, in case of delatio use this.
20

  
21
    else
22

  
23
max=$( awk '{print $2 * 100  }'  /mnt/data/jetzlab/Data/environ/global/dem_class/txt/$tile"_min_max.txt")
24
min=$( awk '{print $1 * 100  }'  /mnt/data/jetzlab/Data/environ/global/dem_class/txt/$tile"_min_max.txt")
25

  
26
echo $min and $max compare to $DIR
27

  
28
if [ $max -lt $DIR ]  ;  then 
29
      echo building the $INDIR/$tile"_C"$DIR"Perc.tif"  with 0 value
30
      pkgetmask -min 100 -max 101  -t 0 -ot Byte -i $INDIR/../class/$tile"_class.tif" -co COMPRESS=LZW  -o $INDIR/$tile"_C"$DIR"Perc.tif" 
31
      gdalwarp -tr 0.00833333333333 -0.00833333333333 -co COMPRESS=LZW   -ot Byte $INDIR/$tile"_C"$DIR"Perc_tmp.tif" $INDIR/$tile"_C"$DIR"Perc.tif" 
32
      rm $INDIR/$tile"_C"$DIR"Perc_tmp.tif" 
33
fi 
34

  
35
if [ $min -gt $DIR ] ; then 
36
      echo building the $INDIR/$tile"_C"$DIR"Perc.tif"  with 100 value 
37
      pkgetmask -min 100 -max 101  -t 0 -f 100  -ot Byte  -co COMPRESS=LZW  -i $INDIR/../class/$tile"_class.tif"  -o $INDIR/$tile"_C"$DIR"Perc.tif" 
38
      gdalwarp -tr 0.00833333333333 -0.00833333333333 -co COMPRESS=LZW   -ot Byte $INDIR/$tile"_C"$DIR"Perc_tmp.tif" $INDIR/$tile"_C"$DIR"Perc.tif" 
39
      rm $INDIR/$tile"_C"$DIR"Perc_tmp.tif" 
40
fi 
41

  
42
fi  
43

  
44
done
45

  
46
# pkcrop -ulx -180  -uly  83  -lrx  180  -lry -60    -ot Byte  -co COMPRESS=LZW  -o $OUTDIR/perc_$DIR.tif  $(for file in $INDIR/Smoothed_N*E*_C$DIR"Perc.tif" ; do echo -n "-i $file " ; done)
47

  
48
gdal_merge.py -ul_lr  -180  83  180  -60  -ps -0.008333333333330  -0.008333333333330   -ot Byte  -o $OUTDIR/perc_NE_$DIR.tif  $INDIR/Smoothed_N*E*_C$DIR"Perc.tif" 
49
gdal_merge.py -ul_lr  -180  83  180  -60  -ps -0.008333333333330  -0.008333333333330   -ot Byte  -o $OUTDIR/perc_NW_$DIR.tif  $INDIR/Smoothed_N*W*_C$DIR"Perc.tif" 
50
gdal_merge.py -ul_lr  -180  83  180  -60  -ps -0.008333333333330  -0.008333333333330   -ot Byte  -o $OUTDIR/perc_SE_$DIR.tif  $INDIR/Smoothed_S*E*_C$DIR"Perc.tif" 
51
gdal_merge.py -ul_lr  -180  83  180  -60  -ps -0.008333333333330  -0.008333333333330   -ot Byte  -o $OUTDIR/perc_SW_$DIR.tif  $INDIR/Smoothed_S*W*_C$DIR"Perc.tif" 
52

  
53
gdal_merge.py -ul_lr  -180  83  180 -60   -co COMPRESS=LZW   -ps -0.008333333333330  -0.008333333333330 -ot Byte -o $OUTDIR/perc_$DIR.tif  $INDIR/Smoothed_N*E*_C$DIR"Perc.tif" $INDIR/Smoothed_N*W*_C$DIR"Perc.tif" $INDIR/Smoothed_S*E*_C$DIR"Perc.tif" $INDIR/Smoothed_S*W*_C$DIR"Perc.tif" 
54

  
terrain/procedures/dem_variables/dem90_res_x5/sc1_dem_variables_x5.sh
1
# variables derived from the dem following commands in http://www.gdal.org/gdaldem.html#gdaldem_slope 
2
# to check ls tif/Smoothed*.tif  | xargs -n 1 -P 30 bash -c $' gdalinfo  -mm $1 |grep Max  | awk \'{ gsub("[=,]", " ") ;  print $3,$4  }\'  ' _ 
3

  
4

  
5
# find /mnt/data2/dem_variables/{altitude,aspect,roughness,slope,tpi,tri}  -name *.tif | xargs -n 1 -P 10 rm ; 
6

  
7
# ls /mnt/data/jetzlab/Data/environ/global/dem/tiles/Smoothed_*.bil | xargs -n 1 -P 12 bash  /mnt/data2/dem_variables/scripts/sc1_dem_variables_x5.sh
8

  
9
# scandinavia 
10
# ls /mnt/data/jetzlab/Data/environ/global/dem/tiles/Smoothed_N{55,60,65,70}E0{05,10,15,20,25,30}.bil | xargs -n 1 -P 12 bash /mnt/data2/dem_variables/scripts/sc1_dem_variables.sh
11

  
12
export INDIR=/mnt/data2/dem_variables
13
export OUTDIR=/mnt/data2/dem_variables/resol_x5
14
export file=$1
15
export filename=`basename $file .bil` 
16

  
17
(
18

  
19
# gdal_translate -ot Int16  -co COMPRESS=LZW  $file $OUTDIR/tif/$filename.tif
20

  
21
echo altitude variables with file    $INDIR/tif/$filename.tif
22

  
23
# median 
24
pkfilter -m -32768 -dx 5 -dy 5   -f median -d 5 -i  $INDIR/tif/$filename.tif    -o  $OUTDIR/altitude/median/tiles/$filename.tif     -co COMPRESS=LZW -ot Int16  
25
 
26
# stdev
27
pkfilter -m -32768 -dx 5 -dy 5   -f var -d 5 -i $INDIR/tif/$filename.tif   -o  $OUTDIR/altitude/stdev/tiles/tmp_$filename.tif  -co COMPRESS=LZW -ot Int32   # max 1552385.000 sqrt(1245.947)
28
gdal_calc.py -A  $OUTDIR/altitude/stdev/tiles/tmp_$filename.tif --calc="sqrt(A)" --type Int16 --overwrite --outfile $OUTDIR/altitude/stdev/tiles/$filename.tif
29
rm -f   $OUTDIR/altitude/stdev/tiles/tmp_$filename
30
# min 
31
pkfilter -m -32768  -dx 5 -dy 5   -f min -d 5 -i $INDIR/tif/$filename.tif   -o  $OUTDIR/altitude/min/tiles/$filename.tif    -co COMPRESS=LZW -ot Int16  
32
# max
33
pkfilter -m -32768 -dx 5 -dy 5   -f max -d 5 -i $INDIR/tif/$filename.tif   -o  $OUTDIR/altitude/max/tiles/$filename.tif    -co COMPRESS=LZW -ot Int16  
34
# mean
35
pkfilter -m -32768 -dx 5 -dy 5   -f mean -d 5 -i $INDIR/tif/$filename.tif   -o  $OUTDIR/altitude/mean/tiles/$filename.tif  -co COMPRESS=LZW  -ot Int16  
36

  
37
# starting to use gdaldem to compute variables. Gdaldem use -9999 as no data. 
38

  
39
echo  slope with file   $INDIR/tif/$filename.tif
40
gdaldem slope  -s 111120 -co COMPRESS=LZW   $INDIR/tif/$filename.tif  $OUTDIR/slope/tiles/$filename.tif  # -s to consider xy in degree and z in meters
41
# slope median 
42
pkfilter -m -9999 -dx 5 -dy 5 -f median  -d 5 -i $OUTDIR/slope/tiles/$filename.tif -o $OUTDIR/slope/median/tiles/$filename.tif -co COMPRESS=LZW -ot Byte
43
# slope stdev 
44
pkfilter -m -9999 -dx 5 -dy 5 -f var -d 5 -i $OUTDIR/slope/tiles/$filename.tif -o  $OUTDIR/slope/stdev/tiles/tmp_$filename.tif -co COMPRESS=LZW -ot Int32
45
gdal_calc.py -A  $OUTDIR/slope/stdev/tiles/tmp_$filename.tif --calc="sqrt(A)" --type Int16 --overwrite --outfile $OUTDIR/slope/stdev/tiles/$filename.tif
46
rm -f  $OUTDIR/slope/stdev/tiles/tmp_$filename
47
# slope min 
48
pkfilter -m -9999  -dx 5 -dy 5 -f min -d 5 -i $OUTDIR/slope/tiles/$filename.tif -o  $OUTDIR/slope/min/tiles/$filename.tif -co COMPRESS=LZW   -ot Byte 
49
# slope max
50
pkfilter -m -9999 -dx 5 -dy 5 -f max -d 5 -i $OUTDIR/slope/tiles/$filename.tif -o  $OUTDIR/slope/max/tiles/$filename.tif -co COMPRESS=LZW   -ot Byte 
51
# slope mean
52
pkfilter -m -9999 -dx 5 -dy 5 -f mean -d 5 -i $OUTDIR/slope/tiles/$filename.tif -o  $OUTDIR/slope/mean/tiles/$filename.tif -co COMPRESS=LZW  -ot Byte 
53

  
54
rm -f  $OUTDIR/slope/tiles/$filename.tif
55

  
56
echo  generate a Terrain Ruggedness Index TRI  with file   $file
57
gdaldem TRI  -co COMPRESS=LZW   $INDIR/tif/$filename.tif  $OUTDIR/tri/tiles/$filename.tif
58
# tri median 
59
pkfilter -m -9999 -dx 5 -dy 5 -f median -d 5 -i $OUTDIR/tri/tiles/$filename.tif -o $OUTDIR/tri/median/tiles/$filename.tif -co COMPRESS=LZW -ot Int16  
60
# tri stdev 
61
pkfilter -m -9999 -dx 5 -dy 5 -f var -d 5 -i $OUTDIR/tri/tiles/$filename.tif -o  $OUTDIR/tri/stdev/tiles/tmp_$filename.tif -co COMPRESS=LZW 
62
gdal_calc.py -A  $OUTDIR/tri/stdev/tiles/tmp_$filename.tif --calc="sqrt(A)" --type Int16 --overwrite --outfile $OUTDIR/tri/stdev/tiles/$filename.tif
63
rm -f  $OUTDIR/tri/stdev/tiles/tmp_$filename
64
# tri min 
65
pkfilter -m -9999 -dx 5 -dy 5 -f min -d 5 -i $OUTDIR/tri/tiles/$filename.tif -o  $OUTDIR/tri/min/tiles/$filename.tif -co COMPRESS=LZW -ot Int16  
66
# tri max
67
pkfilter -m -9999 -dx 5 -dy 5 -f max -d 5 -i $OUTDIR/tri/tiles/$filename.tif -o  $OUTDIR/tri/max/tiles/$filename.tif -co COMPRESS=LZW -ot Int16
68
# tri mean
69
pkfilter -m -9999 -dx 5 -dy 5 -f mean -d 5 -i $OUTDIR/tri/tiles/$filename.tif -o  $OUTDIR/tri/mean/tiles/$filename.tif -co COMPRESS=LZW -ot Int16
70

  
71
rm -f  $OUTDIR/tri/tiles/$filename.tif
72

  
73
echo  generate a Topographic Position Index TPI  with file   $INDIR/tif/$filename.tif
74
gdaldem TPI  -co COMPRESS=LZW   $INDIR/tif/$filename.tif  $OUTDIR/tpi/tiles/$filename.tif       # tpi has negative number 
75
# tpi median 
76
pkfilter -m -9999 -dx 5 -dy 5 -f median -d 5 -i $OUTDIR/tpi/tiles/$filename.tif -o $OUTDIR/tpi/median/tiles/$filename.tif -co COMPRESS=LZW -ot Int16
77
echo tpi stdev 
78
pkfilter -m -9999 -dx 5 -dy 5 -f var -d 5 -i $OUTDIR/tpi/tiles/$filename.tif -o $OUTDIR/tpi/stdev/tiles/tmp_$filename.tif -co COMPRESS=LZW 
79
gdal_calc.py -A  $OUTDIR/tpi/stdev/tiles/tmp_$filename.tif --calc="sqrt(A)" --type Int32 --overwrite --outfile $OUTDIR/tpi/stdev/tiles/$filename.tif
80
rm -f  $OUTDIR/tpi/stdev/tiles/tmp_$filename
81
# tpi min 
82
pkfilter -m -9999 -dx 5 -dy 5 -f min -d 5 -i $OUTDIR/tpi/tiles/$filename.tif -o $OUTDIR/tpi/min/tiles/$filename.tif    -co COMPRESS=LZW -ot Int16
83
# tpi max
84
pkfilter -m -9999 -dx 5 -dy 5 -f max -d 5 -i $OUTDIR/tpi/tiles/$filename.tif -o $OUTDIR/tpi/max/tiles/$filename.tif    -co COMPRESS=LZW -ot Int16
85
# tpi mean
86
pkfilter -m -9999 -dx 5 -dy 5 -f mean -d 5 -i $OUTDIR/tpi/tiles/$filename.tif -o $OUTDIR/tpi/mean/tiles/$filename.tif  -co COMPRESS=LZW -ot Int16
87

  
88
rm -f  $OUTDIR/tpi/tiles/$filename.tif
89

  
90
echo  generate roughness   with file   $INDIR/tif/$filename.tif
91

  
92
gdaldem  roughness  -co COMPRESS=LZW   $INDIR/tif/$filename.tif  $OUTDIR/roughness/tiles/$filename.tif
93

  
94
# roughness median 
95
pkfilter -m -9999 -dx 5 -dy 5 -f median -d 5 -i $OUTDIR/roughness/tiles/$filename.tif -o $OUTDIR/roughness/median/tiles/$filename.tif -co COMPRESS=LZW -ot Int16
96
echo roughness stdev 
97
pkfilter -m -9999 -dx 5 -dy 5 -f var  -d 5 -i $OUTDIR/roughness/tiles/$filename.tif -o $OUTDIR/roughness/stdev/tiles/tmp_$filename.tif -co COMPRESS=LZW 
98
gdal_calc.py -A  $OUTDIR/roughness/stdev/tiles/tmp_$filename.tif --calc="sqrt(A)" --type Int32 --overwrite --outfile $OUTDIR/roughness/stdev/tiles/$filename.tif
99

  
100
rm -f  $OUTDIR/roughness/stdev/tiles/tmp_$filename
101

  
102
# roughness min 
103
pkfilter -m -9999 -dx 5 -dy 5 -f min -d 5 -i $OUTDIR/roughness/tiles/$filename.tif -o $OUTDIR/roughness/min/tiles/$filename.tif    -co COMPRESS=LZW -ot Int16
104
# roughness max
105
pkfilter -m -9999 -dx 5 -dy 5 -f max -d 5 -i $OUTDIR/roughness/tiles/$filename.tif -o $OUTDIR/roughness/max/tiles/$filename.tif    -co COMPRESS=LZW -ot Int16
106
# roughness mean
107
pkfilter -m -9999 -dx 5 -dy 5 -f mean -d 5 -i $OUTDIR/roughness/tiles/$filename.tif -o $OUTDIR/roughness/mean/tiles/$filename.tif  -co COMPRESS=LZW -ot Int16
108

  
109
rm -f   $OUTDIR/roughness/tiles/$filename.tif
110

  
111
) 2>&1 | tee   /mnt/data2/dem_variables/log.txt
terrain/procedures/dem_variables/dem90_res_x5/sc2_dem_merge_x5.sh
1
# calculate different variables for the dem 
2
# for dir1  in altitude  ; do for dir2 in stdev ; do echo $dir1/$dir2 ; done ; done  | xargs -n 1 -P 5 bash /mnt/data2/dem_variables/scripts/sc2_dem_merge.sh
3
# for dir1  in altitude slope tri tpi roughness ; do for dir2 in max mean median min stdev; do echo $dir1/$dir2 ; done ; done  | xargs -n 1 -P 12  bash /mnt/data2/dem_variables/scripts/sc2_dem_merge.sh
4

  
5

  
6
OUTDIR=/mnt/data2/dem_variables/resol_x5
7

  
8
DIR=$1
9
dir1=$(echo ${DIR%/*})   # cancel the part after  /
10
dir2=$(echo ${DIR#*/})   # cancel the part before /
11

  
12

  
13
rm  $OUTDIR/$DIR/$dir1"_"$dir2.tif
14

  
15
echo processing merging tiles in $dir1   
16

  
17
if [ $dir1=altitude ]  ; then type=Int16 ; fi 
18
if [ $dir1=slope ]     ; then type=Byte ; fi  
19
if [ $dir1=tri ]       ; then type=Int16 ; fi 
20
if [ $dir1=tpi ]       ; then type=Int16 ; fi 
21
if [ $dir1=roughness ] ; then type=Int16 ; fi 
22
           
23
rm -f $OUTDIR/$DIR/$dir1"_"${dir2}_NW*.tif 
24
rm -f $OUTDIR/$DIR/$dir1"_"${dir2}_NE*.tif 
25
rm -f $OUTDIR/$DIR/$dir1"_"${dir2}_SW*.tif  
26
rm -f $OUTDIR/$DIR/$dir1"_"${dir2}_SE*.tif  
27

  
28
for tile in 0 1 2 3 4 5 6 7 8 ; do 
29
    gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2"_NW"${tile}.tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/tiles/Smoothed_N${tile}*W*.tif 
30
    gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2"_NE"${tile}.tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/tiles/Smoothed_N${tile}*E*.tif 
31

  
32
    gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2"_SW"${tile}.tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/tiles/Smoothed_S${tile}*W*.tif 
33
    gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2"_SE"${tile}.tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/tiles/Smoothed_S${tile}*E*.tif 
34
done 
35

  
36
rm -f  $OUTDIR/$DIR/$dir1"_"$dir2.tif
37

  
38
gdal_merge.py -o $OUTDIR/$DIR/$dir1"_"$dir2.tif -ot $type -co COMPRESS=LZW  $OUTDIR/$DIR/$dir1"_"${dir2}_NW*.tif $OUTDIR/$DIR/$dir1"_"${dir2}_NE*.tif $OUTDIR/$DIR/$dir1"_"${dir2}_SW*.tif  $OUTDIR/$DIR/$dir1"_"${dir2}_SE*.tif  
39

  
40

  
41
rm -f $OUTDIR/$DIR/$dir1"_"${dir2}_NW*.tif 
42
rm -f $OUTDIR/$DIR/$dir1"_"${dir2}_NE*.tif 
43
rm -f $OUTDIR/$DIR/$dir1"_"${dir2}_SW*.tif  
44
rm -f $OUTDIR/$DIR/$dir1"_"${dir2}_SE*.tif  
45

  
46

  
47

  
48

  
49

  

Also available in: Unified diff