-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsrtm_proc.sh
executable file
·149 lines (125 loc) · 4.42 KB
/
srtm_proc.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#! /bin/bash
#Wrapper to fetch and process NASADEM SRTM products for regional mosaics
#SRTM collection dates: February 11-22, 2000
#hgt_srtmOnly_R4 (non void-filled) tiles are float relative to ellipsoid
#hgt_merge tiles are Int16 relative to EGM96
topdir=/nobackup/deshean/data/nasadem
if [ ! -d $topdir ] ; then
mkdir $topdir
fi
#lfs setstripe -c 64 $topdir
cd $topdir
#For provisional NASADEM products, need NASA Earthdata account
uname=''
#Need to hardcode password if using GNU parallel to fetch (recommended)
#Make sure to use hard quotes if pw contains special characters
#pw=\''pw'\'
pw=''
#Scripts in repo must be in PATH, or specify here
srcdir=~/src/nasadem
gdal_opt="-co COMPRESS=LZW -co TILED=YES -co BIGTIFF=IF_SAFER"
#CONUS
site='conus'
proj='+proj=aea +lat_1=36 +lat_2=49 +lat_0=43 +lon_0=-115 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs '
#HMA
#site='hma'
#proj='+proj=aea +lat_1=25 +lat_2=47 +lat_0=36 +lon_0=85 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs '
#Fuego
#site='fuego'
#proj='+proj=utm +zone=15 +ellps=WGS84 +units=m +no_defs'
#Chad
#site='chad'
#proj='+proj=utm +zone=33 +ellps=WGS84 +units=m +no_defs'
if [ ! -d $site ] ; then
mkdir $site
fi
cd $site
#This defines the products to download and process
productdir_list='hgt_merge hgt_srtmOnly_R4 hgt_srtmOnly err_I2 img_comb'
#productdir_list='hgt_merge'
for productdir in $productdir_list
do
echo
if [ "$productdir" == 'hgt_merge' ] ; then
#ext_list='hgt num'
ext_list='hgt'
elif [ "$productdir" == 'hgt_srtmOnly_R4' ] ; then
ext_list='srtmOnly.hgt'
elif [ "$productdir" == 'hgt_srtmOnly' ] ; then
ext_list='hgts'
elif [ "$productdir" == 'img_comb' ] ; then
#ext_list='img img.num'
ext_list='img'
elif [ "$productdir" == 'err_I2' ] ; then
ext_list='err'
else
echo "Invalid product directory"
exit
fi
if [ ! -d $productdir ] ; then
mkdir $productdir
fi
cd $productdir
for ext in $ext_list
do
#Create a subdir, so we avoid overwriting .hdr files for products with multiple file extensions
if [ ! -d $ext ] ; then
mkdir $ext
fi
cd $ext
#Generate a text file containing url for all tiles
#Edit srtm_tilelist.py, modify lat/lon bounds
urllist=${site}_nasadem_tilelist_${productdir}_${ext}.txt
echo -n > $urllist
$srcdir/srtm_tilelist.py $site $productdir $ext >> $urllist
nf=$(wc -l $urllist)
echo "Total tile count: $nf"
url_zip_list=$(cat $urllist | awk -F'/' '{print $NF}')
fn_list=$(ls *${ext}.zip)
echo -n > ${urllist%.*}_missing.txt
for i in $url_zip_list
do
if ! echo $fn_list | grep -q $i ; then
grep $i $urllist >> ${urllist%.*}_missing.txt
fi
done
nf=$(wc -l ${urllist%.*}_missing.txt)
echo "Missing tile count: $nf"
if [ ! -z "$pw" ] ; then
#Parallel wget
cat ${urllist%.*}_missing.txt | parallel --verbose --delay 1 -j 16 --progress "wget --user $uname --password $pw -nc -q {}"
else
#Serial wget
wget --user $uname --ask-password -nc -i $urllist
fi
#Unzip tiles
fn_list_to_unzip=''
for i in *${ext}.zip
do
if [ ! -e ${i%.*} ] ; then
fn_list_to_unzip+=" $i"
fi
done
if [ ! -z "$fn_list_to_unzip" ] ; then
nf=$(echo $fn_list_to_unzip | wc -w)
echo "Unzipped tile count: $nf"
parallel --progress 'unzip {} {.}' ::: $fn_list_to_unzip
fi
#Generate hdr and prj sidecar files
echo "Creating hdr and prj files"
fn_list=$(ls *.${ext})
parallel "$srcdir/srtm_hdr.sh {}" ::: $fn_list
#Build mosaic in original WGS84 coordinates
if [ ! -e ${site}_nasadem_${productdir}_${ext}.vrt ] ; then
echo "Building vrt"
gdalbuildvrt ${site}_nasadem_${productdir}_${ext}.vrt $fn_list
#gdaladdo_ro.sh ${site}_nasadem_${ext}.vrt
#gdal_translate $gdal_opt ${site}_nasadem_${ext}.vrt ${site}_nasadem_${ext}.tif
#gdalwarp -overwrite $gdal_opt -r cubic -t_srs "$proj" -tr 30 30 nasadem_${ext}.vrt nasadem_${ext}_30m.tif
fi
cd ..
done
cd ..
done
#Filter, adjust vertical datum and reproject
$srcdir/srtm_post.sh $site "$proj"