-
Notifications
You must be signed in to change notification settings - Fork 22
/
test_get_nam.sh
executable file
·264 lines (264 loc) · 10.3 KB
/
test_get_nam.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/bash
#
# This script should be run within the asgs shell environment
# (needed so that the values of SCRIPTDIR etc are available)
#
# set variables to be used in json template
RUNDIR=$PWD
BACKSITE=ftp.ncep.noaa.gov
BACKDIR=/pub/data/nccf/com/nam/prod
instanceNamDir=$PWD/nam
FORECASTCYCLE="00,18"
DATETIME=$(date +'%Y-%h-%d-T%H:%M:%S%z')
THIS=cmd_line_test
lastCycle=$(date -d yesterday +%Y%m%d00)
namTemplateName="get_nam_template.json"
filledNamTemplateName="asgs_main.sh_get_nam_status.json"
# keep sed from getting confused by escaping slashes
escBACKDIR=${BACKDIR////'\/'}
escRUNDIR=${RUNDIR////'\/'}
escSCRIPTDIR=${SCRIPTDIR////'\/'}
escInstanceNamDir=${instanceNamDir////'\/'}
arrFORECASTCYCLE=${FORECASTCYCLE//,/\",\"}
# n o w c a s t
stage=NOWCAST
#
# fill in template with data needed to get NAM status
#
# asgs_main.sh->downloadBackgroundMet :
sed \
-e "s/%NULLGETNAMTEMPLATEFILE%/$namTemplateName/" \
-e "s/%NULLGETNAMTEMPLATEFILLEDFILE%/$filledNamTemplateName/" \
-e "s/%NULLBACKSITE%/$BACKSITE/" \
-e "s/%NULLBACKDIR%/$escBACKDIR/" \
-e "s/%NULLCYCLE%/$lastCycle/" \
-e "s/%NULLFORECASTCYCLE%/$arrFORECASTCYCLE/" \
-e "s/%NULLSTAGE%/$stage/" \
-e "s/%NULLSCRIPTDIR%/$escSCRIPTDIR/" \
-e "s/%NULLNAMDATAPATH%/$escInstanceNamDir/" \
-e "s/\"%NULLNAMNOWCASTDOWNLOADED%\"/null/" \
-e "s/\"%NULLNAMNOWCASTFOUND%\"/null/" \
-e "s/\"%NULLNAMFORECASTDOWNLOADED%\"/null/" \
-e "s/\"%NULLNAMFORECASTFOUND%\"/null/" \
-e "s/\"%NULLNAMSTATUSFILE%\"/null/" \
-e "s/\"%NULLNAMSELECTFILE%\"/null/" \
-e "s/\"%NULLGETNAMFILE%\"/null/" \
-e "s/%NULLLASTUPDATER%/$THIS/" \
-e "s/%NULLLASTUPDATETIME%/$DATETIME/" \
< $SCRIPTDIR/$namTemplateName \
> $filledNamTemplateName \
# getting nam status
get_nam_status.pl < $filledNamTemplateName > get_nam_status.pl.json
err=$?
if [[ $err != 0 ]]; then
echo "ERROR: Failed to get status of NAM cycles with get_nam_status.pl."
exit $err
fi
latest.pl < get_nam_status.pl.json > latestCycle
err=$?
if [[ $err != 0 ]]; then
echo "ERROR: Failed to extract the latest NAM cycle from get_nam_status.pl.json with latest.pl"
exit $err
fi
latestCycle=$(<"latestCycle")
# refine the list of NAM cycles to end the nowcast on the correct cycle
select_nam_nowcast.pl < get_nam_status.pl.json > select_nam_nowcast.pl.json
err=$?
if [[ $err != 0 ]]; then
echo "ERROR: Failed to select the proper NAM cycle to end the nowcast with select_nam_nowcast.pl."
exit $err
fi
# then download the actual nowcast data for the time range of interest
get_nam_data.pl < select_nam_nowcast.pl.json > get_nam_data.pl.json
err=$?
if [[ $err != 0 ]]; then
echo "ERROR: Failed to download NAM nowcast data with get_nam_data.pl.json."
exit $err
fi
thisCycle=$(latest.pl < select_nam_nowcast.pl.json)
err=$?
if [[ $err != 0 ]]; then
echo "ERROR: Failed to get the latest cycle from select_nam_nowcast.pl.json."
exit $err
fi
echo $thisCycle
# for extracting the grib2 and converting to ascii win/pre (owi) format
SCENARIO=nowcast
SCENARIODIR=$RUNDIR/nowcast
if [[ ! -d $SCENARIODIR ]]; then mkdir $SCENARIODIR ; fi
escSCENARIODIR=${SCENARIODIR////'\/'}
SPATIALEXTRAPOLATIONRAMPDISTANCE=1.0
VELOCITYMULTIPLIER=1.0
boolApplyRamp=true
ptFilePath=${SCRIPTDIR}/input/ptFile_oneEighth.txt
escPtFilePath=${ptFilePath////'\/'}
# NAMtoOWIRamp.pl writes the ascii OWI WIN/PRE files to
# the scenario directories
sed -e "s/%NULLNAMWINPREDATAPATH%/$escSCENARIODIR/" \
-e "s/%NULLNAMWINPREGRID%/$escPtFilePath/" \
-e "s/\"%NULLNAMAWIPGRID%\"/218/" \
-e "s/%NULLNAMRAWFORMAT%/grib2/" \
-e "s/\"%NULLVELMULT%\"/$VELOCITYMULTIPLIER/" \
-e "s/\"%NULLPRESSMULT%\"/0.01/" \
-e "s/\"%NULLAPPLYRAMP%\"/$boolApplyRamp/" \
-e "s/\"%NULLRAMPDIST%\"/$SPATIALEXTRAPOLATIONRAMPDISTANCE/" \
< get_nam_data.pl.json \
| $SCRIPTDIR/NAMtoOWIRamp.pl > NAMtoOWIRamp.pl.json
preFile=$($SCRIPTDIR/bin/bashJSON.pl --key winPrePressureFile < NAMtoOWIRamp.pl.json)
winFile=$($SCRIPTDIR/bin/bashJSON.pl --key winPreVelocityFile < NAMtoOWIRamp.pl.json)
mv fort.22 $SCENARIODIR
mv NAMtoOWIRamp.pl.* get_nam_status.pl.* asgs_main.sh_get_nam_status.json rotatedNAM.txt select_nam_nowcast.pl.json reproject.log lambert_diag.out $SCENARIODIR
cp get_nam_data.pl.* $SCENARIODIR # needed for forecast
# f o r e c a s t
stage=FORECAST
SCENARIO=namforecast
SCENARIODIR=$RUNDIR/namforecast
if [[ ! -d $SCENARIODIR ]]; then mkdir $SCENARIODIR ; fi
escSCENARIODIR=${SCENARIODIR////'\/'}
sed "s/NOWCAST/FORECAST/" < get_nam_data.pl.json > get_nam_forecast.json
err=$?
if [[ $err != 0 ]]; then
echo "ERROR: Failed to replace NOWCAST with FORECAST in select_nam_nowcast.pl.json with sed."
exit $err
fi
# download the forecast data
get_nam_data.pl < get_nam_forecast.json > get_nam_data.pl.json
err=$?
if [[ $err != 0 ]]; then
echo "ERROR: Failed to download NAM forecast data with get_nam_data.pl."
exit $err
fi
# NAMtoOWIRamp.pl writes the ascii OWI WIN/PRE files to
# the scenario directories
sed -e "s/%NULLNAMWINPREDATAPATH%/$escSCENARIODIR/" \
-e "s/%NULLNAMWINPREGRID%/$escPtFilePath/" \
-e "s/\"%NULLNAMAWIPGRID%\"/218/" \
-e "s/%NULLNAMRAWFORMAT%/grib2/" \
-e "s/\"%NULLVELMULT%\"/$VELOCITYMULTIPLIER/" \
-e "s/\"%NULLPRESSMULT%\"/0.01/" \
-e "s/\"%NULLAPPLYRAMP%\"/$boolApplyRamp/" \
-e "s/\"%NULLRAMPDIST%\"/$SPATIALEXTRAPOLATIONRAMPDISTANCE/" \
< get_nam_data.pl.json \
| $SCRIPTDIR/NAMtoOWIRamp.pl > NAMtoOWIRamp.pl.json
preFile=$($SCRIPTDIR/bin/bashJSON.pl --key winPrePressureFile < NAMtoOWIRamp.pl.json)
winFile=$($SCRIPTDIR/bin/bashJSON.pl --key winPreVelocityFile < NAMtoOWIRamp.pl.json)
mv fort.22 $SCENARIODIR
mv get_nam_forecast.json get_nam_data.pl.* NAMtoOWIRamp.pl.* rotatedNAM.txt reproject.log lambert_diag.out forecast.properties $SCENARIODIR
#
# N O W C A S T F R O M F I L E S Y S T E M
#
# test the construction of a nowcast from grib2 files already
# on the filesystem
# set variables to be used in json template
RUNDIR=$PWD
namArchiveDir=$RUNDIR/nam-filesystem
if [[ -d $namArchiveDir ]]; then
rm -rf $namArchiveDir
fi
# use the files already downloaded to construct a nowcast
# from the filesystem
mv $instanceNamDir $namArchiveDir
BACKSITE=filesystem # <--
BACKDIR=$namArchiveDir # <--
FORECASTCYCLE="00,18"
DATETIME=$(date +'%Y-%h-%d-T%H:%M:%S%z')
THIS=cmd_line_test
lastCycle=$(date -d yesterday +%Y%m%d00)
namTemplateName="get_nam_template.json"
filledNamTemplateName="asgs_main.sh_get_nam_status.json"
# keep sed from getting confused by escaping slashes
escBACKDIR=${BACKDIR////'\/'}
escRUNDIR=${RUNDIR////'\/'}
escSCRIPTDIR=${SCRIPTDIR////'\/'}
escInstanceNamDir=${instanceNamDir////'\/'}
arrFORECASTCYCLE=${FORECASTCYCLE//,/\",\"}
stage=NOWCAST
#
# fill in template with data needed to get NAM status
#
# asgs_main.sh->downloadBackgroundMet :
sed \
-e "s/%NULLGETNAMTEMPLATEFILE%/$namTemplateName/" \
-e "s/%NULLGETNAMTEMPLATEFILLEDFILE%/$filledNamTemplateName/" \
-e "s/%NULLBACKSITE%/$BACKSITE/" \
-e "s/%NULLBACKDIR%/$escBACKDIR/" \
-e "s/%NULLCYCLE%/$lastCycle/" \
-e "s/%NULLFORECASTCYCLE%/$arrFORECASTCYCLE/" \
-e "s/%NULLSTAGE%/$stage/" \
-e "s/%NULLSCRIPTDIR%/$escSCRIPTDIR/" \
-e "s/%NULLNAMDATAPATH%/$escInstanceNamDir/" \
-e "s/\"%NULLNAMNOWCASTDOWNLOADED%\"/null/" \
-e "s/\"%NULLNAMNOWCASTFOUND%\"/null/" \
-e "s/\"%NULLNAMFORECASTDOWNLOADED%\"/null/" \
-e "s/\"%NULLNAMFORECASTFOUND%\"/null/" \
-e "s/\"%NULLNAMSTATUSFILE%\"/null/" \
-e "s/\"%NULLNAMSELECTFILE%\"/null/" \
-e "s/\"%NULLGETNAMFILE%\"/null/" \
-e "s/%NULLLASTUPDATER%/$THIS/" \
-e "s/%NULLLASTUPDATETIME%/$DATETIME/" \
< $SCRIPTDIR/$namTemplateName \
> $filledNamTemplateName \
# getting nam status
get_nam_status.pl < $filledNamTemplateName > get_nam_status.pl.json
err=$?
if [[ $err != 0 ]]; then
echo "ERROR: Failed to get status of NAM cycles with get_nam_status.pl."
exit $err
fi
latest.pl < get_nam_status.pl.json > latestCycle
err=$?
if [[ $err != 0 ]]; then
echo "ERROR: Failed to extract the latest NAM cycle from get_nam_status.pl.json with latest.pl"
exit $err
fi
latestCycle=$(<"latestCycle")
# refine the list of NAM cycles to end the nowcast on the correct cycle
select_nam_nowcast.pl < get_nam_status.pl.json > select_nam_nowcast.pl.json
err=$?
if [[ $err != 0 ]]; then
echo "ERROR: Failed to select the proper NAM cycle to end the nowcast with select_nam_nowcast.pl."
exit $err
fi
# then download the actual nowcast data for the time range of interest
get_nam_data.pl < select_nam_nowcast.pl.json > get_nam_data.pl.json
err=$?
if [[ $err != 0 ]]; then
echo "ERROR: Failed to download NAM nowcast data with get_nam_data.pl.json."
exit $err
fi
thisCycle=$(latest.pl < select_nam_nowcast.pl.json)
err=$?
if [[ $err != 0 ]]; then
echo "ERROR: Failed to get the latest cycle from select_nam_nowcast.pl.json."
exit $err
fi
# for extracting the grib2 and converting to ascii win/pre (owi) format
SCENARIO=nowcast-filesystem
SCENARIODIR=$RUNDIR/$SCENARIO
if [[ ! -d $SCENARIODIR ]]; then mkdir $SCENARIODIR ; fi
escSCENARIODIR=${SCENARIODIR////'\/'}
SPATIALEXTRAPOLATIONRAMPDISTANCE=1.0
VELOCITYMULTIPLIER=1.0
boolApplyRamp=true
ptFilePath=${SCRIPTDIR}/input/ptFile_oneEighth.txt
escPtFilePath=${ptFilePath////'\/'}
# NAMtoOWIRamp.pl writes the ascii OWI WIN/PRE files to
# the scenario directories
sed -e "s/%NULLNAMWINPREDATAPATH%/$escSCENARIODIR/" \
-e "s/%NULLNAMWINPREGRID%/$escPtFilePath/" \
-e "s/\"%NULLNAMAWIPGRID%\"/218/" \
-e "s/%NULLNAMRAWFORMAT%/grib2/" \
-e "s/\"%NULLVELMULT%\"/$VELOCITYMULTIPLIER/" \
-e "s/\"%NULLPRESSMULT%\"/0.01/" \
-e "s/\"%NULLAPPLYRAMP%\"/$boolApplyRamp/" \
-e "s/\"%NULLRAMPDIST%\"/$SPATIALEXTRAPOLATIONRAMPDISTANCE/" \
< get_nam_data.pl.json \
| $SCRIPTDIR/NAMtoOWIRamp.pl > NAMtoOWIRamp.pl.json
preFile=$($SCRIPTDIR/bin/bashJSON.pl --key winPrePressureFile < NAMtoOWIRamp.pl.json)
winFile=$($SCRIPTDIR/bin/bashJSON.pl --key winPreVelocityFile < NAMtoOWIRamp.pl.json)
mv fort.22 $SCENARIODIR
mv get_nam_data.pl.* NAMtoOWIRamp.pl.* get_nam_status.pl.* asgs_main.sh_get_nam_status.json rotatedNAM.txt select_nam_nowcast.pl.json reproject.log lambert_diag.out $SCENARIODIR
# move the files already downloaded back to where they
# can be used to run this test again (for use as a cache to
# avoid having to download them again)
mv $namArchiveDir $instanceNamDir