Project

General

Profile

« Previous | Next » 

Revision e5db2cbc

Added by selv over 11 years ago

first push for all the script used to create topographic variable

View differences:

.gitignore
1
*.sh~
terrain/procedures/dem_variables/gmted2010_res_x10/sc1_wget_gmted2010.sh
1
# download  unzip and tif conversion of the Global Multi-resolution Terrain Elevation Data 2010 (GMTED2010)
2
# setting working directory 
3

  
4
INDIR=/mnt/data2/dem_variables/GMTED2010
5
cd $INDIR
6

  
7
# download all the zip file from http://topotools.cr.usgs.gov/gmted_viewer/gmted2010_global_grids.php
8
# using multiprocess approch 
9
url=http://gmted.cr.usgs.gov/gmted/Grid_ZipFiles/
10
echo $url"be75_grd.zip" $url"ds75_grd.zip" $url"md75_grd.zip" $url"mi75_grd.zip" $url"mn75_grd.zip" $url"mx75_grd.zip"  $url"sd75_grd.zip" | xargs -n 1 -P 7  wget  -d /mnt/data2/dem_variables/GMTED2010/zip/ $1   
11

  
12
# unzip the file using multiprocess approch  
13

  
14
ls  /mnt/data2/dem_variables/GMTED2010/zip/*.zip | xargs -n 1 -P 7 bash -c $'
15

  
16
dir=`basename $1 .zip`
17
unzip  -d  /mnt/data2/dem_variables/GMTED2010/tiles/$dir $1
18

  
19
' _ 
20

  
21
# transform to tif and tiling them using multiprocess approch   
22
# be75_grd.zip	Breakline Emphasis     , 7.5 arc-seconds
23
# ds75_grd.zip	Systematic Subsample   , 7.5 arc-seconds
24
# md75_grd.zip	Median Statistic       , 7.5 arc-seconds
25
# mi75_grd.zip	Minimum Statistic      , 7.5 arc-seconds
26
# mn75_grd.zip	Mean Statistic         , 7.5 arc-seconds
27
# mx75_grd.zip	Maximum Statistic      , 7.5 arc-seconds
28
# sd75_grd.zip	Standard Dev. Statistic, 7.5 arc-seconds
29

  
30
echo  be75_grd ds75_grd md75_grd mi75_grd mn75_grd mx75_grd sd75_grd  | xargs -n 1 -P 7 bash -c $'
31
dir=$1
32
INDIR=/mnt/data2/dem_variables/GMTED2010/tiles/$dir
33
for nx in `seq 0 9` ; do 
34
    for ny in `seq 0 4` ; do 
35
        xoff=$(echo 17280 \* $nx | bc)
36
        yoff=$(echo 13440 \* $ny | bc)
37
        xsize=17280
38
        ysize=13440
39
        gdal_translate -srcwin  $xoff $yoff $xsize $ysize  -co COMPRESS=LZW $INDIR/$dir  $INDIR"_tif"/$nx"_"$ny.tif
40
    done
41
done
42
' _ 
43

  
44
# at the end fo this process the 50 tiles tiff has been created for each of the defined component 
terrain/procedures/dem_variables/gmted2010_res_x10/sc1b_pixel_correction.sh
1
# correct immage with  anomalus pixel valus. 
2
# the file
3
# giuseppea@turaco:/mnt/data2/dem_variables/GMTED2010/altitude/class_mi$ pkinfo -hist -i   ../../tiles/mi75_grd_tif/5_1.tif  | more 
4
# -931 1  anomalus 
5
# -898 1  anomalus
6
# -498 1
7
# -461 1
8

  
9
# therefore the -931 -898 will be fill in withe the nearby pixel.
10

  
11
cd /mnt/data2/dem_variables/GMTED2010/tiles/mi75_grd_tif
12
cp  5_1.tif 5_1_orig.tiff
13
pkgetmask -co COMPRESS=LZW -i 5_1.tif  -min  -890 -max 10000 -t 1 -f 0 -o 5_1_mask.tif
14
pkfillnodata -i 5_1.tif  -m 5_1_mask.tif     -o 5_1_fill.tif
15
mv 5_1_fill.tif 5_1.tif
16
rm 5_1_mask.tif 
17

  
18
# the values becom -93 and -80 
19

  
20
#  -93 2830
21
#  -93 2831
22
# 
23
#  -80 19449
24
#  -80 19450
25

  
26
# correction of a square box of 500 500 pixel. Set the value = to 179 as the near by pixel.
27
cd /mnt/data2/dem_variables/GMTED2010/tiles/mi75_grd_tif
28
gdal_translate  -srcwin  10070 3830 500 500   2_1.tif  2_1_clip.tif
29

  
30
pksetmask -co COMPRESS=LZW -t 0  -f 179   -i 2_1.tif   -m 2_1_clip.tif   -o 2_1_correct.tif 
31
mv 2_1.tif 2_1_orig.tiff
32
mv 2_1_correct.tif 2_1.tif 
33
rm 2_1_clip.tif
34

  
35
# correction of a square in the caspian sea set value to -27 
36
cd /mnt/data2/dem_variables/GMTED2010/tiles/mi75_grd_tif
37
gdal_translate  -srcwin  5719 5249 1050 1050   6_1.tif  6_1_clip1.tif
38
gdal_translate  -srcwin  6200 6200 1050 550    6_1.tif  6_1_clip2.tif
39
gdal_translate  -srcwin  6700 6700 1050 550    6_1.tif  6_1_clip3.tif
40
gdal_translate  -srcwin  7150 7000 550  700    6_1.tif  6_1_clip4.tif
41
gdal_translate  -srcwin  6700 7550 1050 1100   6_1.tif  6_1_clip5.tif
42
gdal_translate  -srcwin  7150 8000 1050 1150   6_1.tif  6_1_clip6.tif
43

  
44
pksetmask -co COMPRESS=LZW -t 0 -f -27 -t 0 -f -27 -t 0 -f -27 -t 0 -f -27 -t 0 -f -27 -t 0 -f -27   -m 6_1_clip1.tif  -m 6_1_clip2.tif  -m 6_1_clip3.tif  -m 6_1_clip4.tif  -m 6_1_clip5.tif  -m 6_1_clip6.tif   -i 6_1.tif -o 6_1_correct.tif
45
mv  6_1.tif  6_1_orig.tiff
46
mv 6_1_correct.tif 6_1.tif
47
rm 6_1_clip*.tif
48

  
49
# correction of a square box of 500 500 pixel. Set the value = to 179 as the near by pixel.
50
cd /mnt/data2/dem_variables/GMTED2010/tiles/mx75_grd_tif
51
gdal_translate  -srcwin  10070 3830 500 500   2_1.tif  2_1_clip.tif
52

  
53
pksetmask -co COMPRESS=LZW -t 0  -f 179   -i 2_1.tif   -m 2_1_clip.tif   -o 2_1_correct.tif 
54
mv 2_1.tif 2_1_orig.tiff
55
mv 2_1_correct.tif 2_1.tif 
56
rm 2_1_clip.tif
57

  
58
# correction of a square in the caspian sea set value to -27 
59
cd /mnt/data2/dem_variables/GMTED2010/tiles/mx75_grd_tif
60
gdal_translate  -srcwin  5719 5249 1050 1050   6_1.tif  6_1_clip1.tif
61
gdal_translate  -srcwin  6200 6200 1050 550    6_1.tif  6_1_clip2.tif
62
gdal_translate  -srcwin  6700 6700 1050 550    6_1.tif  6_1_clip3.tif
63
gdal_translate  -srcwin  7150 7000 550  700    6_1.tif  6_1_clip4.tif
64
gdal_translate  -srcwin  6700 7550 1050 1100   6_1.tif  6_1_clip5.tif
65
gdal_translate  -srcwin  7150 8000 1050 1150   6_1.tif  6_1_clip6.tif
66

  
67
pksetmask -co COMPRESS=LZW -t 0 -f -27 -t 0 -f -27 -t 0 -f -27 -t 0 -f -27 -t 0 -f -27 -t 0 -f -27   -m 6_1_clip1.tif  -m 6_1_clip2.tif  -m 6_1_clip3.tif  -m 6_1_clip4.tif  -m 6_1_clip5.tif  -m 6_1_clip6.tif   -i 6_1.tif -o 6_1_correct.tif
68
mv  6_1.tif  6_1_orig.tiff
69
mv 6_1_correct.tif 6_1.tif
70
rm 6_1_clip*.tif
71

  
terrain/procedures/dem_variables/gmted2010_res_x10/sc2_class_treshold_percent.sh
1
# calculate altitude area percent above a specific treshold
2
# e.g  75% of class200 means that 75% of the pixels is >= 200 
3
# for this case the treshold is set every 100 meter
4
# geting the integer of the altitued / 100
5

  
6
#  for file in /mnt/data2/dem_variables/GMTED2010/tiles/mi75_grd_tif/*.tif ; do echo $file mi ; done  | xargs -n 2 -P 25  bash /mnt/data2/dem_variables/GMTED2010/scripts/sc2_class_treshold_percent.sh 
7
# rm  /tmp/ramdisk/* ; for file in /mnt/data2/dem_variables/GMTED2010/tiles/mx75_grd_tif/*.tif ; do echo $file mx ; done  | xargs -n 2 -P 25  bash /mnt/data2/dem_variables/GMTED2010/scripts/sc2_class_treshold_percent.sh 
8
# to check 
9
# ny=45 ; for n in `seq 1 9` ;do echo `gdallocationinfo -valonly altitude/class/5_1_class_tmp3.tif 2$n $ny` `gdallocationinfo  -valonly  tiles/mn75_grd_tif/5_1.tif 2$n $ny` ; done 
10

  
11
export file=$1
12
export mm=$2
13
export filename=`basename $file .tif`
14
(
15

  
16
INDIR=/mnt/data2/dem_variables/GMTED2010/tiles/$mm"75_grd_tif"
17
OUTDIR=/mnt/data2/dem_variables/GMTED2010/altitude/class_$mm/class
18

  
19
echo  calcualte altitude  every 100 meter  using the the Int16 factors for $file 
20

  
21
oft-calc  -X -ot Int16 $INDIR/$filename.tif $OUTDIR/../tmp/$filename"_class_tmp1.tif"  &> /dev/null   <<EOF
22
1
23
#1 49 - 100 /
24
EOF
25

  
26
oft-calc  -X -ot Int16  $OUTDIR/../tmp/$filename"_class_tmp1.tif"  $OUTDIR/../tmp/$filename"_class_tmp2.tif"    &> /dev/null   <<EOF
27
1
28
#1 100 *
29
EOF
30

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

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

  
37
echo min and max for $OUTDIR/../tmp/$filename"_min_max_"$mm.txt
38

  
39
 
40
for class in $(seq `awk '{ print $1}'  $OUTDIR/../tmp/${filename}_min_max_${mm}.txt` 100  `awk '{ print $2}' $OUTDIR/../tmp/${filename}_min_max_${mm}.txt`) ; do 
41

  
42
    class_start=$class
43
    class_end=$(awk '{ print $2}'  $OUTDIR/../tmp/${filename}_min_max_${mm}.txt)
44
    class_string=$(for class_unique in $(seq $class_start 100  $class_end  ) ; do echo -n "-class $class_unique "  ; done) 
45

  
46
    echo applaid the filter for the classes  $class_string
47

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

  
50
done 
51

  
52

  
53
) 2>&1 | tee  /mnt/data2/dem_variables/GMTED2010/log/log_of_class_$mm"_"$filename".txt"
terrain/procedures/dem_variables/gmted2010_res_x10/sc3_class_treshold_density_merge.sh
1

  
2

  
3
# for dir in `seq -500 100 8600` ; do echo $dir mi ; done |  xargs -n 2 -P 1 bash /mnt/data2/dem_variables/GMTED2010/scripts/sc3_class_treshold_density_merge.sh
4

  
5
DIR=$1
6
mm=$2
7
INDIR=/mnt/data2/dem_variables/GMTED2010/altitude/class_mi/class${DIR}
8
INDIR_C=/mnt/data2/dem_variables/GMTED2010/altitude/class_mi/class
9
OUTDIR=/mnt/data2/dem_variables/GMTED2010/altitude/percent_class_${mm}
10

  
11
rm  $OUTDIR/file_processed_sc3.txt  # the file has ben processed by the script sc1_dem_treshold_percent.sh
12

  
13
for file  in `ls $INDIR_C/*.tif`  ; do 
14
    tile=`basename $file _class.tif`
15

  
16
    if [ -f $INDIR/$tile"_C"$DIR"Perc.tif" ] ; then 
17
	echo the file  $INDIR/$tile"_C"$DIR"Perc.tif"   exist and will be merged as it is
18
	echo $tile"_C"$DIR"Perc.tif" >>  $OUTDIR/file_processed_sc3.txt # usefull to list file processed by script sc1, in case of delatio use this.
19
    else
20

  
21
gdalinfo -mm /mnt/data2/dem_variables/GMTED2010/altitude/class_mi/class/$tile"_class.tif"  | grep Computed | awk '{ gsub ("[=,]"," "); print int($(NF-1)), int($(NF))}' > /tmp/ramdisk/$filename"_min_max_"$mm.txt
22

  
23
min=`awk '{ print $1}'  /tmp/ramdisk/${filename}_min_max_${mm}.txt`  
24
max=`awk '{ print $2}'  /tmp/ramdisk/${filename}_min_max_${mm}.txt`
25
rm -f /tmp/ramdisk/${filename}_min_max_${mm}.txt
26

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

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

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

  
43
fi  
44

  
45
done
46

  
47
exit 
48

  
49

  
50
gdal_merge.py   -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" 
51

  
terrain/procedures/dem_variables/gmted2010_res_x10/wget.sh
1

  
2
# seq 2001 2012 | xargs -n 1 -P 10  bash /mnt/data/jetzlab/Data/environ/global/MODIS/wget.sh
3
# echo 2012  | xargs -n 1 -P 10  bash /mnt/data/jetzlab/Data/environ/global/MODIS/wget.sh
4

  
5
YEAR=$1
6
OUTDIR=/mnt/data/jetzlab/Data/environ/global/MODIS/MCD12Q1/051/$YEAR
7

  
8
# get the file list from the ftp 
9
wget -O  -   http://e4ftl01.cr.usgs.gov/MOTA/MCD12Q1.051/$YEAR.01.01/  > $OUTDIR/list_$YEAR.txt 
10

  
11
# manipulate to get just the file name 
12

  
13
grep hdf  $OUTDIR/list_$YEAR.txt   | grep -v xml | awk '{ gsub("[\"]", " ") ;  print $10 }' > $OUTDIR/list_hdf_$YEAR.txt 
14

  
15
# starting the downloding procedure and tif conversion. 
16
for file in `cat $OUTDIR/list_hdf_$YEAR.txt` ; do 
17
    filename=`basename $file .hdf`
18
    LD_PRELOAD=/usr/local/lib/vsipreload.so gdal_translate  -co COMPRESS=LZW   HDF4_EOS:EOS_GRID:"\"""/vsicurl/http://e4ftl01.cr.usgs.gov/MOTA/MCD12Q1.051/$YEAR.01.01/${file}""\"":MOD12Q1:Land_Cover_Type_1 $OUTDIR/$filename.tif 
19
    rm $OUTDIR/$filename.tif.aux.xml
20
done 
21

  
22
# merge all the data 
23

  
24
gdal_merge.py  -o $OUTDIR/../MCD12Q1_051_$YEAR"_tmp".tif  $(ls  $OUTDIR/*.tif) 
25

  
26
oft-calc -inv $OUTDIR/../MCD12Q1_051_$YEAR"_tmp".tif $OUTDIR/../MCD12Q1_051_$YEAR"_tmp2".tif  <<EOF
27
1
28
#1 254 > 0 #1 ?
29
EOF
30

  
31
gdal_translate -co COMPRESS=LZW  $OUTDIR/../MCD12Q1_051_$YEAR"_tmp2".tif   $OUTDIR/../MCD12Q1_051_$YEAR.tif 
32

  
33
$OUTDIR/../MCD12Q1_051_$YEAR"_wgs84_tmp.tif"
34
gdalwarp -rn -multi  -co COMPRESS=LZW  -t_srs   EPSG:4326  $OUTDIR/../MCD12Q1_051_$YEAR.tif   $OUTDIR/../MCD12Q1_051_$YEAR"_wgs84_tmp.tif"
35
gdal_translate -co COMPRESS=LZW    $OUTDIR/../MCD12Q1_051_$YEAR"_wgs84_tmp.tif"   $OUTDIR/../MCD12Q1_051_$YEAR"_wgs84.tif"
36
rm $OUTDIR/../M*tm*.tif
37

  
38

  
39

  
40

  
41

  
terrain/procedures/dem_variables/panoram90_res_x10/sc1_wget_panoramas.sh
1
# get the file list from the ftp 
2

  
3
INDIR=/mnt/data2/dem_variables/dem_panoramas/tiles
4
cd $INDIR
5

  
6
# wget http://www.viewfinderpanoramas.org/Coverage%20map%20viewfinderpanoramas_org3.htm  
7

  
8
# mv Coverage\ map\ viewfinderpanoramas_org3.htm  $INDIR/../geo_file/list_zip.txt 
9

  
10
# grep "zip"   $INDIR/../geo_file/list_zip.txt  |  awk '{  print $NF }' | awk '{ gsub("href=\"","") ; gsub("\"","")   ; print  }' |  sort -k 1,1 | uniq   >  $INDIR/../geo_file/list_zip_clean.txt 
11

  
12
# cd zip_files
13

  
14
# # the list_zip_clean.txt   contain ANTDEM3 antartich dem so 
15
# # wget only dem3 lines 
16

  
17
# for file in `grep dem3  $INDIR/../geo_file/list_zip_clean.txt ` ; do echo $file ; done | xargs -n 1 -P 20   wget -m  $1 
18
# unzip and trasform to tif 
19

  
20
# ls  $INDIR/zip_files/*.zip |   xargs -n 1 -P 14 bash -c  $' 
21

  
22
# file=$1
23

  
24
# # save the standard error and in a file for later use in the loop
25

  
26
# unzip -o  -d /mnt/data2/dem_variables/dem_panoramas/tiles/  $file  &> /mnt/data2/dem_variables/dem_panoramas/tiles/zip_files/listzip$$.txt  
27

  
28
# for f_hgt in $(grep inflating /mnt/data2/dem_variables/dem_panoramas/tiles/zip_files/listzip$$.txt | awk \'{print $2  }\') ; do 
29

  
30
#     f_name_hgt=`basename $f_hgt .hgt`
31
#     d_name=`dirname $f_hgt`
32

  
33
#     gdal_translate  -co COMPRESS=LZW    $f_hgt   $d_name/$f_name_hgt.tif   
34
#     rm -f  $f_hgt
35
# done
36
 
37
# rm /mnt/data2/dem_variables/dem_panoramas/tiles/zip_files/listzip$$.txt
38
# ' _
39

  
40

  
41
# in order to restrict the searching path 
42
# mkdir $INDIR/tilesNE
43
# mkdir $INDIR/tilesNW
44
# mkdir $INDIR/tilesSE
45
# mkdir $INDIR/tilesSW
46

  
47
# mv  $INDIR/*/N*E*.tif $INDIR/tilesNE
48
# mv  $INDIR/*/N*W*.tif $INDIR/tilesNW
49
# mv  $INDIR/*/S*E*.tif $INDIR/tilesSE
50
# mv  $INDIR/*/S*W*.tif $INDIR/tilesSW
51

  
52

  
53
# create a vrt filie 
54

  
55
# gdalbuildvrt -overwrite $INDIR/tilesNE/tilesNE.vrt $INDIR/tilesNE/*.tif 
56
# gdalbuildvrt -overwrite $INDIR/tilesNW/tilesNW.vrt $INDIR/tilesNW/*.tif
57

  
58
# gdalbuildvrt -overwrite $INDIR/tilesSE/tilesSE.vrt $INDIR/tilesSE/*.tif
59
# gdalbuildvrt -overwrite $INDIR/tilesSW/tilesSW.vrt $INDIR/tilesSW/*.tif
60

  
61
# mkdir /tmp/ramdisk; chmod 777 /tmp/ramdisk
62
# mount -t tmpfs -o size=10000M tmpfs /tmp/ramdisk
63

  
64
ls /mnt/data2/dem_variables/resol_x10/tif/Smoothed_N*E*.tif |  xargs -n 1 -P 30  bash -c  $'  
65

  
66
file=$1
67
filename=`basename $file .tif`
68
gdal_translate  -projwin  $(getCorners4Gtranslate $file) -co COMPRESS=LZW  /mnt/data2/dem_variables/dem_panoramas/tiles/tilesNE/tilesNE.vrt  /tmp/ramdisk/$filename"_tmp.tif"
69
if [ -f   /tmp/ramdisk/$filename"_tmp.tif"  ]  ; then 
70
pkreclass -co COMPRESS=LZW -c -32768 -r 0 -i  /tmp/ramdisk/$filename"_tmp.tif"   -o /mnt/data2/dem_variables/dem_panoramas/tiles_merged/$filename.tif
71
rm -f  /tmp/ramdisk/$filename"_tmp.tif"
72
fi 
73

  
74
' _
75

  
76

  
77

  
78
ls /mnt/data2/dem_variables/resol_x10/tif/Smoothed_N*W*.tif |  xargs -n 1 -P 30  bash -c  $'  
79

  
80
file=$1
81
filename=`basename $file .tif`
82
gdal_translate  -projwin  $(getCorners4Gtranslate $file) -co COMPRESS=LZW  /mnt/data2/dem_variables/dem_panoramas/tiles/tilesNW/tilesNW.vrt  /tmp/ramdisk/$filename"_tmp.tif"
83
if [ -f    /tmp/ramdisk/$filename"_tmp.tif"  ]  ; then 
84
pkreclass -co COMPRESS=LZW -c -32768 -r 0 -i  /tmp/ramdisk/$filename"_tmp.tif"   -o /mnt/data2/dem_variables/dem_panoramas/tiles_merged/$filename.tif
85
rm -f  /tmp/ramdisk/$filename"_tmp.tif"
86
fi 
87

  
88
' _
89

  
90
ls /mnt/data2/dem_variables/resol_x10/tif/Smoothed_S*E*.tif |  xargs -n 1 -P 30  bash -c  $'  
91

  
92
file=$1
93
filename=`basename $file .tif`
94
gdal_translate  -projwin  $(getCorners4Gtranslate $file) -co COMPRESS=LZW  /mnt/data2/dem_variables/dem_panoramas/tiles/tilesSE/tilesSE.vrt  /tmp/ramdisk/$filename"_tmp.tif"
95
if [ -f /tmp/ramdisk/$filename"_tmp.tif"  ]  ; then 
96
pkreclass -co COMPRESS=LZW -c -32768 -r 0 -i  /tmp/ramdisk/$filename"_tmp.tif"   -o /mnt/data2/dem_variables/dem_panoramas/tiles_merged/$filename.tif
97
rm -f  /tmp/ramdisk/$filename"_tmp.tif"
98
fi 
99

  
100
' _
101

  
102
ls /mnt/data2/dem_variables/resol_x10/tif/Smoothed_S*W*.tif |  xargs -n 1 -P 30  bash -c  $'  
103

  
104
file=$1
105
filename=`basename $file .tif`
106
gdal_translate  -projwin  $(getCorners4Gtranslate $file) -co COMPRESS=LZW  /mnt/data2/dem_variables/dem_panoramas/tiles/tilesSW/tilesSW.vrt  /tmp/ramdisk/$filename"_tmp.tif"
107
if [ -f   /tmp/ramdisk/$filename"_tmp.tif"  ]  ; then 
108
pkreclass -co COMPRESS=LZW -c -32768 -r 0 -i  /tmp/ramdisk/$filename"_tmp.tif"   -o /mnt/data2/dem_variables/dem_panoramas/tiles_merged/$filename.tif
109
rm -f  /tmp/ramdisk/$filename"_tmp.tif"
110
fi 
111

  
112
' _
113

  
terrain/procedures/dem_variables/panoram90_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
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
rm -f  $OUTDIR/$DIR/$dir1"_"$dir2.tif
36

  
37
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 
38

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

  
44
else  # just applaied to the aspect variables 
45

  
46
echo processing merging tiles for the different aspect variables in $dir1   
47

  
48
for aspect_var in "_sin_t10k" "_cos_t10k" "_Ew_t10k" "_Nw_t10k" ; do 
49

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

  
55
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
56
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 
57
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
58
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
59

  
60
rm -f  $OUTDIR/$DIR/$dir1"_"$dir2$aspect_var.tif
61

  
62
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
63

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

  
69
done
70

  
71
fi 
72

  
73

  
74

  
terrain/procedures/dem_variables/panoram90_res_x10/sc2_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/dem_panoramas/{altitude,aspect,roughness,slope,tpi,tri}  -name *.tif | xargs -n 1 -P 10 rm ; 
6

  
7
# ls /mnt/data2/dem_variables/dem_panoramas/tiles_merged/Smoothed_*.tif | head  | xargs -n 1 -P 30 bash  /mnt/data2/dem_variables/dem_panoramas/scripts2/sc2_dem_variables.sh
8

  
9

  
10
export OUTDIR=/mnt/data2/dem_variables/dem_panoramas
11
export file=$1
12
export filename=`basename $file .tif` 
13

  
14
( 
15

  
16
echo altitude variables with file    $OUTDIR/tiles_merged/$filename.tif 
17

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

  
31
# starting to use gdaldem to compute variables. Gdaldem use -9999 as no data. 
32

  
33
echo  slope with file   $OUTDIR/tiles_merged/$filename.tif
34
gdaldem slope  -s 111120 -co COMPRESS=LZW   $OUTDIR/tiles_merged/$filename.tif  $OUTDIR/slope/tiles/$filename.tif  # -s to consider xy in degree and z in meters
35
# slope median 
36
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
37
# slope stdev 
38
pkfilter -m -9999 -dx 10 -dy 10 -f var -d 10 -i $OUTDIR/slope/tiles/$filename.tif -o   /tmp/ramdisk/tmp_$filename.tif  -ot Int32
39
gdal_calc.py -A  /tmp/ramdisk/tmp_$filename.tif --calc="sqrt(A)" --type Int16 --overwrite --outfile $OUTDIR/slope/stdev/tiles/$filename.tif
40
rm -f /tmp/ramdisk/tmp_$filename.tif
41
# slope min 
42
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 
43
# slope max
44
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 
45
# slope mean
46
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 
47

  
48
# rm -f  $OUTDIR/slope/tiles/$filename.tif
49

  
50
echo  generate a Terrain Ruggedness Index TRI  with file   $file
51
gdaldem TRI  -co COMPRESS=LZW   $OUTDIR/tiles_merged/$filename.tif  $OUTDIR/tri/tiles/$filename.tif
52
# tri median 
53
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  
54
# tri stdev 
55
pkfilter -m -9999 -dx 10 -dy 10 -f var -d 10 -i $OUTDIR/tri/tiles/$filename.tif -o  /tmp/ramdisk/tmp_$filename.tif 
56
gdal_calc.py -A  /tmp/ramdisk/tmp_$filename.tif --calc="sqrt(A)" --type Int16 --overwrite --outfile $OUTDIR/tri/stdev/tiles/$filename.tif
57
rm -f  /tmp/ramdisk/tmp_$filename.tif
58
# tri min 
59
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  
60
# tri max
61
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
62
# tri mean
63
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
64

  
65
# rm -f  $OUTDIR/tri/tiles/$filename.tif
66

  
67

  
68
echo  generate a Topographic Position Index TPI  with file   $OUTDIR/tiles_merged/$filename.tif
69

  
70
gdaldem TPI  -co COMPRESS=LZW   $OUTDIR/tiles_merged/$filename.tif  $OUTDIR/tpi/tiles/$filename.tif       # tpi has negative number 
71

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

  
77
# tpi median 
78
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
79
echo tpi stdev 
80
pkfilter -m -9999 -dx 10 -dy 10 -f var -d 10 -i $OUTDIR/tpi/tiles/$filename"_t10.tif"  -o /tmp/ramdisk/tmp_$filename.tif 
81
gdal_calc.py -A  /tmp/ramdisk/tmp_$filename.tif  --calc="sqrt(A)" --type Int32 --overwrite --outfile $OUTDIR/tpi/stdev/tiles/$filename.tif
82
rm -f  /tmp/ramdisk/tmp_$filename.tif
83
# tpi min 
84
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
85
# tpi max
86
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
87
# tpi mean
88
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
89

  
90

  
91
echo  generate roughness   with file   $OUTDIR/tiles_merged/$filename.tif
92

  
93
gdaldem  roughness  -co COMPRESS=LZW   $OUTDIR/tiles_merged/$filename.tif  $OUTDIR/roughness/tiles/$filename.tif
94

  
95
# roughness median 
96
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
97
echo roughness stdev 
98
pkfilter -m -9999 -dx 10 -dy 10 -f var  -d 10 -i $OUTDIR/roughness/tiles/$filename.tif -o /tmp/ramdisk/tmp_$filename.tif  
99
gdal_calc.py -A  /tmp/ramdisk/tmp_$filename.tif --calc="sqrt(A)" --type Int32 --overwrite --outfile $OUTDIR/roughness/stdev/tiles/$filename.tif
100
rm -f  /tmp/ramdisk/tmp_$filename.tif
101
# roughness min 
102
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
103
# roughness max
104
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
105
# roughness mean
106
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
107

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

  
110

  
111

  
112
echo  aspect  with file   $OUTDIR/tiles_merged/$filename.tif
113

  
114
gdaldem aspect  -zero_for_flat -co COMPRESS=LZW   $OUTDIR/tiles_merged/$filename.tif  $OUTDIR/aspect/tiles/$filename.tif
115

  
116
# r1 aspect , r2 slope 
117

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

  
121
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
122
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
123

  
124
echo  aspect sin   cos  Ew  Nw   median 
125
# sin
126
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
127
oft-calc -ot Int16   $OUTDIR/aspect/median/tiles/$filename"_sin_f.tif"  /tmp/ramdisk/$filename"_sin_t10k_tmp.tif"  &> /dev/null    <<EOF
128
1
129
#1 10000 *
130
EOF
131
gdal_translate  -co COMPRESS=LZW  -ot Int16  /tmp/ramdisk/$filename"_sin_t10k_tmp.tif" $OUTDIR/aspect/median/tiles/$filename"_sin_t10k.tif"  
132
rm  /tmp/ramdisk/$filename"_sin_t10k_tmp.tif" 
133
# cos
134
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
135
oft-calc  -ot Int16   $OUTDIR/aspect/median/tiles/$filename"_cos_f.tif"  /tmp/ramdisk/$filename"_cos_t10k_tmp.tif"  &> /dev/null   <<EOF
136
1
137
#1 10000 *
138
EOF
139
gdal_translate  -co COMPRESS=LZW  -ot Int16  /tmp/ramdisk/$filename"_cos_t10k_tmp.tif" $OUTDIR/aspect/median/tiles/$filename"_cos_t10k.tif" 
140
rm  /tmp/ramdisk/$filename"_cos_t10k_tmp.tif" 
141
# Ew
142
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
143
oft-calc -ot Int16   $OUTDIR/aspect/median/tiles/$filename"_Ew_f.tif"  /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif"  &> /dev/null   <<EOF
144
1
145
#1 10000 *
146
EOF
147
gdal_translate  -co COMPRESS=LZW  -ot Int16  /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif" $OUTDIR/aspect/median/tiles/$filename"_Ew_t10k.tif" 
148
rm  /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif" 
149
# Nw
150
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
151
oft-calc  -ot Int16  $OUTDIR/aspect/median/tiles/$filename"_Nw_f.tif"  /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif"  &> /dev/null   <<EOF
152
1
153
#1 10000 *
154
EOF
155
gdal_translate  -co COMPRESS=LZW  -ot Int16  /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif" $OUTDIR/aspect/median/tiles/$filename"_Nw_t10k.tif" 
156
rm  /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif" 
157

  
158

  
159
echo aspect sin   cos  Ew  Nw   mean
160
# sin
161
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
162
oft-calc -ot Int16   $OUTDIR/aspect/mean/tiles/$filename"_sin_f.tif"  /tmp/ramdisk/$filename"_sin_t10k_tmp.tif" &> /dev/null  <<EOF
163
1
164
#1 10000 *
165
EOF
166
gdal_translate  -co COMPRESS=LZW  -ot Int16  /tmp/ramdisk/$filename"_sin_t10k_tmp.tif" $OUTDIR/aspect/mean/tiles/$filename"_sin_t10k.tif"  
167
rm  /tmp/ramdisk/$filename"_sin_t10k_tmp.tif" 
168
# cos
169
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
170
oft-calc -ot Int16   $OUTDIR/aspect/mean/tiles/$filename"_cos_f.tif"  /tmp/ramdisk/$filename"_cos_t10k_tmp.tif"  &> /dev/null   <<EOF
171
1
172
#1 10000 *
173
EOF
174
gdal_translate  -co COMPRESS=LZW  -ot Int16  /tmp/ramdisk/$filename"_cos_t10k_tmp.tif" $OUTDIR/aspect/mean/tiles/$filename"_cos_t10k.tif" 
175
rm  /tmp/ramdisk/$filename"_cos_t10k_tmp.tif" 
176
# Ew
177
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
178
oft-calc -ot Int16   $OUTDIR/aspect/mean/tiles/$filename"_Ew_f.tif"  /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif"  &> /dev/null  <<EOF
179
1
180
#1 10000 *
181
EOF
182
gdal_translate  -co COMPRESS=LZW  -ot Int16  /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif" $OUTDIR/aspect/mean/tiles/$filename"_Ew_t10k.tif" 
183
rm  /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif" 
184
# Nw
185
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
186
oft-calc  -ot Int16  $OUTDIR/aspect/mean/tiles/$filename"_Nw_f.tif"  /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif"  &> /dev/null   <<EOF
187
1
188
#1 10000 *
189
EOF
190
gdal_translate  -co COMPRESS=LZW  -ot Int16  /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif"  &> /dev/null   <<EOF
191
1
192
#1 10000 *
193
EOF
194
gdal_translate  -co COMPRESS=LZW  -ot Int16  /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif" $OUTDIR/aspect/mean/tiles/$filename"_Nw_t10k.tif" 
195
rm  /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif" 
196

  
197
echo aspect sin   cos  Ew  Nw   max
198
# sin
199
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
200
oft-calc -ot Int16  $OUTDIR/aspect/max/tiles/$filename"_sin_f.tif"  /tmp/ramdisk/$filename"_sin_t10k_tmp.tif"   &> /dev/null  <<EOF
201
1
202
#1 10000 *
203
EOF
204
gdal_translate  -co COMPRESS=LZW  -ot Int16 /tmp/ramdisk/$filename"_sin_t10k_tmp.tif" $OUTDIR/aspect/max/tiles/$filename"_sin_t10k.tif"  
205
rm  /tmp/ramdisk/$filename"_sin_t10k_tmp.tif" 
206
# cos
207
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
208
oft-calc  -ot Int16  $OUTDIR/aspect/max/tiles/$filename"_cos_f.tif"   /tmp/ramdisk/$filename"_cos_t10k_tmp.tif"  &> /dev/null  <<EOF
209
1
210
#1 10000 *
211
EOF
212
gdal_translate  -co COMPRESS=LZW  -ot Int16   /tmp/ramdisk/$filename"_cos_t10k_tmp.tif" $OUTDIR/aspect/max/tiles/$filename"_cos_t10k.tif" 
213
rm   /tmp/ramdisk/$filename"_cos_t10k_tmp.tif" 
214
# Ew
215
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
216
oft-calc  -ot Int16   $OUTDIR/aspect/max/tiles/$filename"_Ew_f.tif"   /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif" &> /dev/null   <<EOF
217
1
218
#1 10000 *
219
EOF
220
gdal_translate  -co COMPRESS=LZW  -ot Int16   /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif" $OUTDIR/aspect/max/tiles/$filename"_Ew_t10k.tif" 
221
rm   /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif" 
222
# Nw
223
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
224
oft-calc  -ot Int16   $OUTDIR/aspect/max/tiles/$filename"_Nw_f.tif"   /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif"  &> /dev/null   <<EOF
225
1
226
#1 10000 *
227
EOF
228
gdal_translate  -co COMPRESS=LZW  -ot Int16   /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif" $OUTDIR/aspect/max/tiles/$filename"_Nw_t10k.tif" 
229
rm   /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif" 
230

  
231
echo aspect sin   cos  Ew  Nw   min 
232
# sin
233
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
234
oft-calc  -ot Int16   $OUTDIR/aspect/min/tiles/$filename"_sin_f.tif"   /tmp/ramdisk/$filename"_sin_t10k_tmp.tif"  &> /dev/null   <<EOF
235
1
236
#1 10000 *
237
EOF
238
gdal_translate  -co COMPRESS=LZW  -ot Int16   /tmp/ramdisk/$filename"_sin_t10k_tmp.tif" $OUTDIR/aspect/min/tiles/$filename"_sin_t10k.tif"  
239
rm   /tmp/ramdisk/$filename"_sin_t10k_tmp.tif" 
240
# cos
241
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
242
oft-calc  -ot Int16   $OUTDIR/aspect/min/tiles/$filename"_cos_f.tif"   /tmp/ramdisk/$filename"_cos_t10k_tmp.tif"  &> /dev/null  <<EOF
243
1
244
#1 10000 *
245
EOF
246
gdal_translate  -co COMPRESS=LZW  -ot Int16   /tmp/ramdisk/$filename"_cos_t10k_tmp.tif" $OUTDIR/aspect/min/tiles/$filename"_cos_t10k.tif" 
247
rm   /tmp/ramdisk/$filename"_cos_t10k_tmp.tif" 
248
# Ew
249
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
250
oft-calc -ot Int16   $OUTDIR/aspect/min/tiles/$filename"_Ew_f.tif"   /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif" &> /dev/null   <<EOF
251
1
252
#1 10000 *
253
EOF
254
gdal_translate  -co COMPRESS=LZW  -ot Int16   /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif" $OUTDIR/aspect/min/tiles/$filename"_Ew_t10k.tif" 
255
rm   /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif" 
256
# Nw
257
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
258
oft-calc -ot Int16   $OUTDIR/aspect/min/tiles/$filename"_Nw_f.tif"   /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif"  &> /dev/null   <<EOF
259
1
260
#1 10000 *
261
EOF
262
gdal_translate  -co COMPRESS=LZW  -ot Int16   /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif" $OUTDIR/aspect/min/tiles/$filename"_Nw_t10k.tif" 
263
rm   /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif" 
264

  
265
echo aspect sin   cos  Ew  Nw   stdev
266
# stdev   
267
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
268
gdal_calc.py -A  $OUTDIR/aspect/stdev/tiles/$filename"_sin_f.tif"  --calc="(sqrt(A))*10000" --type Int16 --overwrite --outfile   /tmp/ramdisk/$filename"_sin_t10k_tmp.tif"
269
gdal_translate  -co COMPRESS=LZW  -ot Int16  /tmp/ramdisk/$filename"_sin_t10k_tmp.tif" $OUTDIR/aspect/stdev/tiles/$filename"_sin_t10k.tif"  
270
rm   /tmp/ramdisk/$filename"_sin_t10k_tmp.tif" 
271
# cos
272
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
273
gdal_calc.py -A  $OUTDIR/aspect/stdev/tiles/$filename"_cos_f.tif"  --calc="(sqrt(A))*10000" --type Int16 --overwrite --outfile   /tmp/ramdisk/$filename"_cos_t10k_tmp.tif"
274
gdal_translate  -co COMPRESS=LZW  -ot Int16   /tmp/ramdisk/$filename"_cos_t10k_tmp.tif" $OUTDIR/aspect/stdev/tiles/$filename"_cos_t10k.tif" 
275
rm   /tmp/ramdisk/$filename"_cos_t10k_tmp.tif" 
276
# Ew
277
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
278
gdal_calc.py -A  $OUTDIR/aspect/stdev/tiles/$filename"_Ew_f.tif"  --calc="(sqrt(A))*10000" --type Int16 --overwrite --outfile   /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif"
279
gdal_translate  -co COMPRESS=LZW  -ot Int16   /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif" $OUTDIR/aspect/stdev/tiles/$filename"_Ew_t10k.tif" 
280
rm   /tmp/ramdisk/$filename"_Ew_t10k_tmp.tif" 
281
# Nw
282
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
283
gdal_calc.py -A  $OUTDIR/aspect/stdev/tiles/$filename"_Nw_f.tif"  --calc="(sqrt(A))*10000" --type Int16 --overwrite --outfile   /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif"
284
gdal_translate  -co COMPRESS=LZW  -ot Int16   /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif" $OUTDIR/aspect/stdev/tiles/$filename"_Nw_t10k.tif" 
285
rm   /tmp/ramdisk/$filename"_Nw_t10k_tmp.tif" 
286

  
287
) 2>&1 | tee  /mnt/data2/dem_variables/dem_panoramas/log.txt
terrain/procedures/dem_variables/panoram90_res_x10/sc3_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 aspect 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/dem_panoramas/scripts2/sc3_dem_merge.sh
4

  
5
OUTDIR=/mnt/data2/dem_variables/dem_panoramas
6

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

  
11

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

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

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

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

  
34

  
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
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_NW".tif  
41
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_NE".tif  
42
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_SW".tif  
43
rm -f $OUTDIR/$DIR/$dir1"_"$dir2"_SE".tif
44

  
45
else  # just applaied to the aspect variables 
46

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

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

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

  
56
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
57
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 
58
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
59
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
60

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

  
63
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
64

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

  
70
done
71

  
72
fi 
73

  
74

  
75

  

Also available in: Unified diff