-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.sh
More file actions
executable file
·105 lines (80 loc) · 3.9 KB
/
main.sh
File metadata and controls
executable file
·105 lines (80 loc) · 3.9 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
set -euo pipefail
# For run local machine
source .venv/bin/activate
baseURL="https://weather.tmd.go.th"
# See more URL: https://weather.tmd.go.th/xxx_HQ_edit2.php
filenames=(
"skm/skm240_HQ_latest.gif"
"cri/cri240_HQ_latest.png"
"phs/phs240_HQ_latest.png"
"kkn/kkn240_HQ_latest.png"
"hyi/hyi240_HQ_latest.gif"
"cmp/cmp240_HQ_latest.png"
)
echo "==============================================="
echo "... Starting radar image download... "
echo "==============================================="
for filename in "${filenames[@]}"; do
printf "Downloading: %s/%s\n" "$baseURL" "$filename"
outputFile="./$(basename "$filename")"
curl -o "$outputFile" "$baseURL/$filename"
done
# หากสีแต่ละเรดาร์ไม่เหมือนกัน ปรับจูนได้จากค่า -zmin, -zmax, -s_min, -v_min ต้องทดลองเอาภาพไปลองปรับ HSV เอาเองว่าใช้เท่าไหร่
echo "==============================================="
echo "...... Starting radar image processing........ "
echo "==============================================="
python3 radar_process.py --template_tif ./geotif/skm240.tif --input_png skm240_HQ_latest.gif \
--workdir out/skm --zmin 5 --zmax 11 --h_low=5 --h_high=109 --s_min=196 --v_min=180 --skip_tiles
python3 radar_process.py --template_tif ./geotif/cri240.tif --input_png cri240_HQ_latest.png \
--workdir out/cri --zmin 5 --zmax 11 --h_low=5 --h_high=109 --s_min=196 --v_min=180 --skip_tiles
python3 radar_process.py --template_tif ./geotif/phs240.tif --input_png phs240_HQ_latest.png \
--workdir out/phs --zmin 5 --zmax 11 --h_low=5 --h_high=109 --s_min=196 --v_min=180 --skip_tiles
python3 radar_process.py --template_tif ./geotif/kkn240.tif --input_png kkn240_HQ_latest.png \
--workdir out/kkn --zmin 5 --zmax 11 --h_low=5 --h_high=109 --s_min=196 --v_min=180 --skip_tiles
python3 radar_process.py --template_tif ./geotif/hyi240.tif --input_png hyi240_HQ_latest.gif \
--workdir out/hyi --zmin 5 --zmax 11 --h_low=0 --h_high=120 --s_min=120 --v_min=180 --skip_tiles
python3 radar_process.py --template_tif ./geotif/cmp240.tif --input_png cmp240_HQ_latest.png \
--workdir out/cmp --zmin 5 --zmax 11 --h_low=5 --h_high=109 --s_min=196 --v_min=150 --skip_tiles
echo "==============================================="
echo "..... Starting radar image to tile XYZ...... "
echo "==============================================="
# Clean previous output files
rm -f out/source_mosaic.vrt out/mosaic_3857.tif out/mosaic_3857_rgba.tif
rm -rf out/tiles
gdalbuildvrt -resolution highest \
-srcnodata "0 0 0 0" -vrtnodata "0 0 0 0" \
out/source_mosaic.vrt \
out/skm/rain_only_georef.tif \
out/cri/rain_only_georef.tif \
out/phs/rain_only_georef.tif \
out/kkn/rain_only_georef.tif \
out/cmp/rain_only_georef.tif \
out/hyi/rain_only_georef.tif
gdal_edit -colorinterp_1 red -colorinterp_2 green -colorinterp_3 blue -colorinterp_4 alpha \
out/source_mosaic.vrt || true
gdalwarp -multi -wo NUM_THREADS=ALL_CPUS \
-t_srs EPSG:3857 -r near \
-srcalpha -dstalpha \
-of GTiff -co PHOTOMETRIC=RGB -co ALPHA=YES \
out/source_mosaic.vrt out/mosaic_3857.tif
gdal_translate -b 1 -b 2 -b 3 -b 4 \
out/mosaic_3857.tif out/mosaic_3857_rgba.tif
mkdir -p out/tiles
gdal2tiles.py -z 5-11 -r near out/mosaic_3857_rgba.tif out/tiles
echo "[DONE] Tiles at: out/tiles"
echo "==============================================="
echo "....Create tile with timestamp............."
echo "==============================================="
currentTime=$(date +%s)
roundedTime=$(( (currentTime / 600) * 600 ))
echo "Creating tiles for timestamp: $(date -d @$roundedTime +'%Y-%m-%d %H:%M:%S')"
if [ ! -d "./radar/$roundedTime" ]; then
mkdir -p "./radar/$roundedTime"
fi
for dir in out/tiles/*; do
if [ -d "$dir" ]; then
mv "$dir" "./radar/$roundedTime/"
fi
done
# rm -rf out