forked from bellemae/dea_bits
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_netcdf_vrt_ovr.sh
161 lines (128 loc) · 3.67 KB
/
create_netcdf_vrt_ovr.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
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# example
#OVR_FIELDS="frequency count_wet count_clear"
OVR_FIELDS="edev"
#OVR_GLOB='*FYsummary.nc'
OVR_OUTPUT='.'
SENSORS="ls7"
# overview-build-all-vrt
# overview-resample-all
# overview-collate
# create yearly vrts
ncdf-yearly-vrt () {
local field=$1
local sensor=$2
for y in {2013..2017}; do
#y=2013
# wet season summary vrts
## vrt_name=wofs_${y}-11_$((y + 1))-03_summary.vrt;
# dry season summary vrts
#vrt_name=wofs_${y}-04_${y}-10_summary.vrt;
vrt_name=${sensor}_tmad-${y}-${field}.vrt
if [ ! -e vrt_name ]; then
# set this to gather together appropriate netcdfs
OVR_GLOB=*${y}0101*;
echo Creating vrt: "${vrt_name}"
ncdf-list-fields ${field} ${sensor} | xargs -x --max-args 2000 gdalbuildvrt ${vrt_name}
fi
done
}
ncdf-yearly-overviews () {
for y in {1987..2017}; do
local sensor=$1
local field=$2
# wet season summary vrtss
#vrt_name=wofs_${y}-11_$((y + 1))-03_summary.vrt;
# dry season summary vrts
#vrt_name=wofs_${y}-04_${y}-10_summary.vrt;
vrt_name=${sensor}_tmad-${y}-${field}.vrt;
echo "Creating overviews for ${vrt_name}"
gdaladdo -r nearest ${vrt_name} 16 64 256 1024 2048
done
}
# list the netcdf files in the manner needed for gdalbuildvrt NETCDF:filename:band
ncdf-list-fields () {
local field=$1
local folder=$2
for file in $(find ${folder} -iname "${OVR_GLOB}"); do
echo "NETCDF:${file}:${field}"
done
}
ncdf-list-fields-thisdir() {
local field=$1
for file in $(find ls5 -iname "${OVR_GLOB}" -maxdepth 1); do
echo "NETCDF:${file}:${field}"
done
}
# build vrt with list of files returned from overview-list-netcdf-field
ncdf-build-vrt () {
local field=$1
local folder=$2
echo building vrt for "$field" with glob "${OVR_GLOB}"
ncdf-list-fields ${field} ${folder} | xargs -x --max-args 2000 gdalbuildvrt "${OVR_OUTPUT}/${field}.vrt"
echo done building vrt for "$field"
}
# create overviews of vrt created
ncdf-create-overviews () {
local field=$1
echo resampling "$field"
gdaladdo "${OVR_OUTPUT}/${field}.vrt" 16 64 256 1024 2048
echo done resampling "$field"
}
# create vrts for each field listed
ncdf-build-all-vrt () {
if [[ -z "${OVR_FIELDS}" ]]; then
echo "no OVR_FIELDS set"
return
fi
if [[ -z "${OVR_GLOB}" ]]; then
echo "no OVR_GLOB set"
return
fi
if [[ -z "${OVR_OUTPUT}" ]]; then
echo "no OVR_OUTPUT set"
return
fi
for field in ${OVR_FIELDS}; do
#ncdf-build-vrt "$field" "${OVR_GLOB}"
ncdf-yearly-vrt "$field"
done
}
# create overviews for each field listed
ncdf-create-all-overviews () {
if [[ -z "${OVR_FIELDS}" ]]; then
echo "no OVR_FIELDS set"
return
fi
if [[ -z "${OVR_GLOB}" ]]; then
echo "no OVR_GLOB set"
return
fi
if [[ -z "${OVR_OUTPUT}" ]]; then
echo "no OVR_OUTPUT set"
return
fi
#for field in ${OVR_FIELDS}; do
# ncdf-create-overviews "$field"
#done
for sensor in ${SENSORS}; do
ncdf-yearly-overviews "$sensor"
done
}
# Create an overview of overviews
ncdf-overview-collate () {
if [[ -z "${OVR_FIELDS}" ]]; then
echo "no OVR_FIELDS set"
return
fi
if [[ -z "${OVR_OUTPUT}" ]]; then
echo "no OVR_OUTPUT set"
return
fi
local OVR_ARRAY=($OVR_FIELDS)
local OVR_PATH="${OVR_OUTPUT}/"
OVR_ARRAY=("${OVR_ARRAY[@]/#/${OVR_PATH}}")
OVR_ARRAY=("${OVR_ARRAY[@]/%/.vrt}")
echo "${OVR_ARRAY[@]}"
gdalbuildvrt "${OVR_OUTPUT}/full.vrt" -separate "${OVR_ARRAY[@]}"
}