1
- #! /bin/bash -e
1
+ #! /usr/ bin/env bash
2
2
# srv_downsampler_image.sh - Filter the highest resolution image to lower resolution versions
3
3
#
4
4
# usage: srv_downsampler_image.sh recipe [-f] [-n] [-x]
19
19
20
20
source scripts/filter_width_from_output_spacing.sh
21
21
22
+ # Hardwired settings for images
23
+ DST_OFFSET=0
24
+ DST_SCALE=1
25
+ DST_TILE_SIZE=0
26
+ DST_CPT=-
27
+ MARK=" "
28
+
22
29
if [ $# -eq 0 ]; then
23
30
cat << - EOF >&2
24
31
usage: srv_downsampler_image.sh <recipefile> [-f] [-n] [-x]"
@@ -64,13 +71,15 @@ mkdir -p ${TMP}
64
71
grep SRC_FILE $RECIPE | awk ' {print $2}' > ${TMP} /par.sh
65
72
grep SRC_RADIUS $RECIPE | awk ' {print $2}' >> ${TMP} /par.sh
66
73
grep SRC_TITLE $RECIPE | awk ' {print $2}' >> ${TMP} /par.sh
74
+ grep SRC_REF $RECIPE | awk ' {print $2}' >> ${TMP} /par.sh
67
75
grep SRC_REG $RECIPE | awk ' {print $2}' >> ${TMP} /par.sh
68
76
grep DST_MODE $RECIPE | awk ' {print $2}' >> ${TMP} /par.sh
69
77
grep DST_PLANET $RECIPE | awk ' {print $2}' >> ${TMP} /par.sh
70
78
grep DST_PREFIX $RECIPE | awk ' {print $2}' >> ${TMP} /par.sh
71
79
grep DST_FORMAT $RECIPE | awk ' {print $2}' >> ${TMP} /par.sh
72
80
source ${TMP} /par.sh
73
-
81
+ CITE=$( echo ${SRC_REF} | tr ' _' ' ' )
82
+ TITLE=$( echo ${SRC_TITLE} | tr ' _' ' ' )
74
83
# 4. Get the file name of the source file and output modifiers
75
84
SRC_BASENAME=$( basename ${SRC_FILE} )
76
85
SRC_ORIG=${SRC_BASENAME}
@@ -120,31 +129,41 @@ while [ ! "X$1" == "X" ]; do
120
129
shift # So that $2 now is next arg or blank
121
130
done
122
131
132
+ # 9.0 Set info file here since no image tiling yet
133
+ INFOFILE=${DST_PLANET} /${DST_PREFIX} /${DST_PREFIX} _server.txt
134
+
123
135
# 9.1 Check if just reporting
124
136
125
- if [ ${DST_BUILD} -eq 0 ]; then # Report variables
137
+ if [ ${DST_BUILD} -eq 1 ]; then # Start building info file
138
+ if [ -d ${DST_PLANET} /${DST_PREFIX} ]; then
139
+ if [ ${DST_FORCE} -eq 1 ]; then
140
+ rm -rf ${DST_PLANET} /${DST_PREFIX}
141
+ else
142
+ echo " Data set directory ${DST_PLANET} /${DST_PREFIX} already exists - aborting. Use -f to force removal instead."
143
+ exit -1
144
+ fi
145
+ fi
146
+ mkdir -p ${DST_PLANET} /${DST_PREFIX}
147
+ cat << - EOF > ${INFOFILE}
148
+ #
149
+ # ${TITLE}
150
+ #
151
+ EOF
152
+ else # Just report parameters and tasks
126
153
cat << - EOF
127
154
# Final parameters after processing ${RECIPE} :
128
155
129
156
SRC_ORIG ${SRC_ORIG}
130
157
SRC_FILE ${SRC_FILE}
131
158
SRC_REG ${SRC_REG}
132
159
DST_SPLIT ${DST_SPLIT}
133
- TITLE ${SRC_TITLE}
160
+ INFOFILE ${INFOFILE}
161
+ TITLE ${TITLE}
162
+ CITE ${CITE}
134
163
135
164
# Processing steps to be taken if -n was not given:
136
165
137
166
EOF
138
- else # Make files in given directory unless it exists and no -f
139
- if [ -d ${DST_PLANET} /${DST_PREFIX} ]; then
140
- if [ ${DST_FORCE} -eq 1 ]; then
141
- rm -rf ${DST_PLANET} /${DST_PREFIX}
142
- else
143
- echo " Data set directory ${DST_PLANET} /${DST_PREFIX} already exists - aborting. Use -f to force removal instead."
144
- exit -1
145
- fi
146
- fi
147
- mkdir -p ${DST_PLANET} /${DST_PREFIX}
148
167
fi
149
168
150
169
# 9.2 Get the right projection ellipsoid/spheroid for this planetary body
154
173
DST_SPHERE=${DST_PLANET}
155
174
fi
156
175
176
+ # 9.4 Get creation date
177
+ creation_date=$( date +%Y-%m-%d)
178
+
157
179
# 10. Loop over all the resolutions found
158
180
159
181
while read RES UNIT TILE MASTER; do
@@ -183,13 +205,19 @@ while read RES UNIT TILE MASTER; do
183
205
echo " ${DST_FILE} exist - skipping"
184
206
elif [ " X${MASTER} " = " Xmaster" ]; then # Just make a copy of the master to a new output file
185
207
echo " Convert ${SRC_FILE} to ${DST_FILE} "
208
+ SIZE=$( ls -lh ${SRC_FILE} | awk ' {print $5}' )
209
+ MSG=" ${TITLE} original at ${RES} x${RES} arc ${UNIT_NAME} "
186
210
if [ ${DST_BUILD} -eq 1 ]; then
187
211
cp ${SRC_FILE} ${DST_FILE}
212
+ printf " %s/server/%s/%s/\t%s_%s_%s\t%s\t%s\t%s\t%s\t%4s\t%s\t%s\t-\t-\t\t%s [%s]\n" \
213
+ " ${MARK} " ${DST_PLANET} ${DST_PREFIX} ${DST_PREFIX} ${FTAG} ${SRC_REG} ${TAG} ${SRC_REG} ${DST_SCALE} ${DST_OFFSET} ${SIZE} ${DST_TILE_SIZE} ${creation_date} " ${MSG} " " ${CITE} " >> ${INFOFILE}
188
214
fi
189
215
else # Must down-sample to a lower resolution via spherical Gaussian filtering
190
216
# Get suitable Gaussian full-width filter rounded to nearest 0.1 km after adding 50 meters for noise
191
217
FILTER_WIDTH=$( filter_width_from_output_spacing ${INC} )
192
218
FWR_SEC=$( gmt math -Q 2 2 SQRT MUL ${INC} MUL 3600 MUL RINT =)
219
+ FTAG=" ${IRES}${UNIT} "
220
+ MSG=" ${TITLE} at ${RES} x${RES} arc ${UNIT_NAME} reduced by Gaussian ${DST_MODE} r/g/b filtering (${FILTER_WIDTH} km fullwidth)"
193
221
if [ ${DST_BUILD} -eq 1 ]; then
194
222
printf " Down-filter ${SRC_FILE} to ${DST_FILE} FW = ${FILTER_WIDTH} km [${FWR_SEC} s] via layers "
195
223
gmt grdmix ${SRC_FILE} -D -G/tmp/tmp_%c.nc=ns
@@ -199,6 +227,9 @@ while read RES UNIT TILE MASTER; do
199
227
done
200
228
printf " > ${DST_FORMAT} \n"
201
229
gmt grdmix -C /tmp/tmp_filt_r.nc /tmp/tmp_filt_g.nc /tmp/tmp_filt_b.nc -G${DST_FILE} -Ni
230
+ SIZE=$( ls -lh ${DST_FILE} | awk ' {print $5}' )
231
+ printf " %s/server/%s/%s/\t%s_%s_%s\t%s\t%s\t%s\t%s\t%4s\t%s\t%s\t-\t-\t\t%s [%s]\n" \
232
+ " ${MARK} " ${DST_PLANET} ${DST_PREFIX} ${DST_PREFIX} ${FTAG} ${SRC_REG} ${TAG} ${SRC_REG} ${DST_SCALE} ${DST_OFFSET} ${SIZE} ${DST_TILE_SIZE} ${creation_date} $" ${MSG} " " ${CITE} " >> ${INFOFILE}
202
233
else
203
234
echo " Down-filter ${SRC_FILE} to ${DST_FILE} via R, G, and B layers. FW = ${FILTER_WIDTH} km [${FWR_SEC} s]"
204
235
fi
0 commit comments