-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_raw_data.sh
executable file
·83 lines (66 loc) · 2.34 KB
/
prepare_raw_data.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
if [ ! $# -eq 2 ]; then
echo; echo "Usage: prepare_raw_data.sh [input_path] [output_path]"; echo
elif [ ! -d $1 ]; then
echo; echo "$1 is not a directory."; echo
else
input_PATH=$1
output_PATH=$2
if [ ! -d $output_PATH ]; then
mkdir $output_PATH
fi
# Read txt files
cd $input_PATH
input_files=$( ls elev.dat*.txt )
max_filename_length=0
for file in ${input_files[@]}; do
filename_length=${#file}
if [ $filename_length -gt $max_filename_length ]; then
max_filename_length=$filename_length
fi
done
#input_files=$( ls elev.dat*.txt )
for file in ${input_files[@]}; do
filename_length=${#file}
if [ $filename_length -le $max_filename_length ]; then
filename_length_diff=$( echo "$max_filename_length - $filename_length" | bc )
echo "Filename $file is too short ($filename_length chars), adding zeros ..."
time_id=${file:9:-4}
new_filename=${file:0:8}
i=0
while [ "$i" -lt "$filename_length_diff" ]; do
new_filename="${new_filename}0"
((i++))
done
new_filename="${new_filename}${time_id}.txt"
echo "New filename: $new_filename"
mv $file $new_filename
else
echo "Filename is long enough ..."
# cp $input_PATH/GTiff/$tiff $input_PATH/temp/$tiff
fi
done
input_files=$( ls elev.dat*.txt )
mkdir $output_PATH/Diff
for file in ${input_files[@]}; do
gdal_translate -of GTiff $input_PATH/$file $output_PATH/${file::-4}.tif
# gdal_calc.py -A $output_PATH/${file::-4}.tif --outfile=$output_PATH/${file::-4}.tif --calc="A*(A>0)" --NoDataValue=-9999 --overwrite
if [ ! -z $prev_file ]; then
echo "Calculating Diff for ${prev_file} ${file}"
# set -x
gdal_calc.py -A $output_PATH/${file::-4}.tif -B $output_PATH/${prev_file::-4}.tif --outfile=$output_PATH/Diff/${prev_file::-4}--${file::-4}.tif --calc="B-A" --NoDataValue=-9999 --overwrite
fi
prev_file=$file
done
cd $output_PATH
tiffs=$( ls *.tif )
# echo "Tiffs: ${tiffs[@]}"
# if [ -d "$input_PATH/temp" ]; then rm -r $input_PATH/temp; fi
# mkdir $input_PATH/temp
rm -f filelist.txt
new_tiffs=$( ls *.tif )
for tiff in ${new_tiffs[@]}; do
echo "$tiff" >> filelist.txt
done
# gdalbuildvrt -vrtnodata "-9999" -input_file_list filelist.txt -overwrite ${output_PATH}/CAESAR.vrt
fi