-
Notifications
You must be signed in to change notification settings - Fork 5
/
submit_cycle.sh
executable file
·390 lines (302 loc) · 11.8 KB
/
submit_cycle.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#!/bin/bash -le
#SBATCH --job-name=offline_noahmp
#SBATCH --account=gsienkf
#SBATCH --qos=debug
#SBATCH --nodes=1
#SBATCH --tasks-per-node=6
#SBATCH --cpus-per-task=1
#SBATCH -t 00:10:00
#SBATCH -o log_noahmp.%j.log
#SBATCH -e err_noahmp.%j.err
############################
# to do:
# -specify resolution in this script (currently fixed at 96)
# -update ICS directory to include forcing / res info.
# -decide how to manage soil moisture DA. Separate DA script to snow?
############################
# load config file
if [[ $# -gt 0 ]]; then
config_file=${CURDIR}/$1
else
config_file=./config.sh
fi
source $config_file
# load modules
source cycle_mods_bash
# set out directory
export EXPDIR=${EXPDIR:-$(pwd)} # directory that output will be save to. default to current directory if not set in config
export CYCLEDIR=${CYCLEDIR:-$(pwd)} # directory weith cycleDA scripts. default to current directory if not set in config
export OUTDIR=${EXPDIR}/exp_out/${exp_name}/output/ # directory where output will be saved
# set executables
vec2tileexec=${CYCLEDIR}/vector2tile/vector2tile_converter.exe
LSMexec=${CYCLEDIR}/ufs-land-driver/run/ufsLand.exe
DAscript=${CYCLEDIR}/landDA_workflow/do_snowDA.sh
export DADIR=${CYCLEDIR}/landDA_workflow/
analdate=${CYCLEDIR}/analdates.sh
incdate=${CYCLEDIR}/incdate.sh
# create clean workdir
if [[ -e ${WORKDIR} ]]; then
rm -rf ${WORKDIR}
fi
mkdir ${WORKDIR}
############################
# create the jedi yaml name
if [[ $do_DA == "YES" || $do_hofx == "YES" ]]; then # do DA
do_jedi=YES
# construct yaml name
if [ $do_DA == "YES" ]; then
JEDI_YAML=${DAtype}"_offline_DA"
elif [ $do_hofx == "YES" ]; then
JEDI_YAML=${DAtype}"_offline_hofx"
fi
if [ $ASSIM_IMS == "YES" ]; then JEDI_YAML=${JEDI_YAML}"_IMS" ; fi
if [ $ASSIM_GHCN == "YES" ]; then JEDI_YAML=${JEDI_YAML}"_GHCN" ; fi
if [ $ASSIM_SYNTH == "YES" ]; then JEDI_YAML=${JEDI_YAML}"_SYNTH"; fi
if [ $ASSIM_GTS == "YES" ]; then JEDI_YAML=${JEDI_YAML}"_GTS" ; fi
JEDI_YAML=${JEDI_YAML}"_C96.yaml"
echo "JEDI YAML is: "$JEDI_YAML
if [[ ! -e ./landDA_workflow/jedi/fv3-jedi/yaml_files/$JEDI_YAML ]]; then
echo "YAML does not exist, exiting"
exit
fi
export JEDI_YAML
else
do_jedi=NO
fi
############################
# create output directories if they do not already exist.
if [[ ! -e ${OUTDIR} ]]; then
mkdir -p ${OUTDIR}/DA
mkdir ${OUTDIR}/DA/IMSproc
mkdir ${OUTDIR}/DA/jedi_incr
mkdir ${OUTDIR}/DA/logs
mkdir ${OUTDIR}/DA/hofx
mkdir ${OUTDIR}/modl
n_ens=1
while [ $n_ens -le $ensemble_size ]; do
if [ $ensemble_size == 1 ]; then
mem_ens=""
else
mem_ens="mem`printf %03i $n_ens`"
fi
mkdir -p ${OUTDIR}/modl/${mem_ens}/restarts/vector/
mkdir ${OUTDIR}/modl/${mem_ens}/restarts/tile/
mkdir -p ${OUTDIR}/modl/${mem_ens}/noahmp/
n_ens=$((n_ens+1))
done # n_ens < ensemble_size
fi
############################
# fetch initial conditions, if not already in place
# read in dates
source ${analdate}
logfile=${CYCLEDIR}/cycle.log
touch $logfile
echo "***************************************" >> $logfile
echo "cycling from $STARTDATE to $ENDDATE" >> $logfile
sYYYY=`echo $STARTDATE | cut -c1-4`
sMM=`echo $STARTDATE | cut -c5-6`
sDD=`echo $STARTDATE | cut -c7-8`
sHH=`echo $STARTDATE | cut -c9-10`
# copy initial conditions
n_ens=1
while [ $n_ens -le $ensemble_size ]; do
if [ $ensemble_size == 1 ]; then
mem_ens=""
else
mem_ens="mem`printf %03i $n_ens`"
fi
MEM_OUTDIR=${OUTDIR}/modl/${mem_ens}/
MEM_ICSDIR=${ICSDIR}/modl/${mem_ens}/
source_restart=${MEM_ICSDIR}/restarts/vector/ufs_land_restart.${sYYYY}-${sMM}-${sDD}_${sHH}-00-00.nc
target_restart=${MEM_OUTDIR}/restarts/vector/ufs_land_restart_back.${sYYYY}-${sMM}-${sDD}_${sHH}-00-00.nc
# if restart not in experiment out directory, copy the restarts from the ICSDIR
if [[ ! -e ${target_restart} ]]; then
echo $source_restart
# if ensemble of restarts exists in ICSDIR, use these. Otherwise, use single restart.
if [[ -e ${source_restart} ]]; then
cp ${source_restart} ${target_restart}
else # use non-ensemble restart
echo 'using single restart for every ensemble member'
cp ${ICSDIR}/modl/restarts/vector/ufs_land_restart.${sYYYY}-${sMM}-${sDD}_${sHH}-00-00.nc ${target_restart}
fi
fi
n_ens=$((n_ens+1))
done # n_ens < ensemble_size
############################
# loop over time steps
THISDATE=$STARTDATE
date_count=0
while [ $date_count -lt $dates_per_job ]; do
if [ $THISDATE -ge $ENDDATE ]; then
echo "All done, at date ${THISDATE}" >> $logfile
cd $CYCLEDIR
rm -rf $WORKDIR
exit
fi
echo "starting $THISDATE"
# substringing to get yr, mon, day, hr info
export YYYY=`echo $THISDATE | cut -c1-4`
export MM=`echo $THISDATE | cut -c5-6`
export DD=`echo $THISDATE | cut -c7-8`
export HH=`echo $THISDATE | cut -c9-10`
# substringing to get yr, mon, day, hr info for previous cycle
PREVDATE=`${incdate} $THISDATE -6`
export YYYP=`echo $PREVDATE | cut -c1-4`
export MP=`echo $PREVDATE | cut -c5-6`
export DP=`echo $PREVDATE | cut -c7-8`
export HP=`echo $PREVDATE | cut -c9-10`
# compute the restart frequency, run_days and run_hours
export FREQ=`expr 3600 \* $CYCHR`
export RDD=`expr $CYCHR / 24`
export RHH=`expr $CYCHR % 24`
############################
# create work directory and copy in restarts
n_ens=1
while [ $n_ens -le $ensemble_size ]; do
if [ $ensemble_size == 1 ]; then
mem_ens=""
else
mem_ens="mem`printf %03i $n_ens`"
fi
MEM_WORKDIR=${WORKDIR}/${mem_ens}/
MEM_OUTDIR=${OUTDIR}/modl/${mem_ens}/ # for model only
# create temporary workdir
if [[ -d $MEM_WORKDIR ]]; then
rm -rf $MEM_WORKDIR
fi
# move to work directory, and copy in templates and restarts
mkdir -p $MEM_WORKDIR
cd $MEM_WORKDIR
ln -s ${MEM_OUTDIR}/noahmp/ ${MEM_WORKDIR}/noahmp_output
mkdir ${MEM_WORKDIR}/restarts
mkdir ${MEM_WORKDIR}/restarts/tile
mkdir ${MEM_WORKDIR}/restarts/vector
# copy restarts into work directory
source_restart=${MEM_OUTDIR}/restarts/vector/ufs_land_restart_back.${YYYY}-${MM}-${DD}_${HH}-00-00.nc
target_restart=${MEM_WORKDIR}/restarts/vector/ufs_land_restart.${YYYY}-${MM}-${DD}_${HH}-00-00.nc
cp $source_restart $target_restart
n_ens=$((n_ens+1))
done # n_ens < ensemble_size
############################
# call JEDI
if [ $do_jedi == "YES" ]; then # do DA
cd ${WORKDIR}
# CSDtodo - do for every ensemble member
# update vec2tile and tile2vec namelists
cp ${CYCLEDIR}/template.vector2tile vector2tile.namelist
sed -i -e "s/XXYYYY/${YYYY}/g" vector2tile.namelist
sed -i -e "s/XXMM/${MM}/g" vector2tile.namelist
sed -i -e "s/XXDD/${DD}/g" vector2tile.namelist
sed -i -e "s/XXHH/${HH}/g" vector2tile.namelist
cp ${CYCLEDIR}/template.tile2vector tile2vector.namelist
sed -i -e "s/XXYYYY/${YYYY}/g" tile2vector.namelist
sed -i -e "s/XXMM/${MM}/g" tile2vector.namelist
sed -i -e "s/XXDD/${DD}/g" tile2vector.namelist
sed -i -e "s/XXHH/${HH}/g" tile2vector.namelist
# submit vec2tile
echo '************************************************'
echo 'calling vector2tile'
$vec2tileexec vector2tile.namelist
if [[ $? != 0 ]]; then
echo "vec2tile failed"
exit
fi
# add coupler.res file
cres_file=${WORKDIR}/restarts/tile/${YYYY}${MM}${DD}.${HH}0000.coupler.res
cp ${CYCLEDIR}/template.coupler.res $cres_file
sed -i -e "s/XXYYYY/${YYYY}/g" $cres_file
sed -i -e "s/XXMM/${MM}/g" $cres_file
sed -i -e "s/XXDD/${DD}/g" $cres_file
sed -i -e "s/XXHH/${HH}/g" $cres_file
sed -i -e "s/XXYYYP/${YYYP}/g" $cres_file
sed -i -e "s/XXMP/${MP}/g" $cres_file
sed -i -e "s/XXDP/${DP}/g" $cres_file
sed -i -e "s/XXHP/${HP}/g" $cres_file
# CSDtodo - call once
# submit snow DA
echo '************************************************'
echo 'calling snow DA'
export THISDATE
$DAscript
if [[ $? != 0 ]]; then
echo "land DA script failed"
exit
fi
# CSDtodo - every ensemble member
echo '************************************************'
echo 'calling tile2vector'
$vec2tileexec tile2vector.namelist
if [[ $? != 0 ]]; then
echo "tile2vector failed"
exit
fi
# CSDtodo - every ensemble member
# save analysis restart
cp ${WORKDIR}/restarts/vector/ufs_land_restart.${YYYY}-${MM}-${DD}_${HH}-00-00.nc ${OUTDIR}/modl/restarts/vector/ufs_land_restart_anal.${YYYY}-${MM}-${DD}_${HH}-00-00.nc
fi # DA step
############################
# run the forecast model
NEXTDATE=`${incdate} $THISDATE $CYCHR`
export nYYYY=`echo $NEXTDATE | cut -c1-4`
export nMM=`echo $NEXTDATE | cut -c5-6`
export nDD=`echo $NEXTDATE | cut -c7-8`
export nHH=`echo $NEXTDATE | cut -c9-10`
# loop over ensemble members
n_ens=1
while [ $n_ens -le $ensemble_size ]; do
if [ $ensemble_size == 1 ]; then
mem_ens=""
else
mem_ens="mem`printf %03i $n_ens`"
fi
MEM_WORKDIR=${WORKDIR}/${mem_ens}/
MEM_OUTDIR=${OUTDIR}/modl/${mem_ens}/ # for model only
cd $MEM_WORKDIR
# update model namelist
if [ $ensemble_size == 1 ]; then
cp ${CYCLEDIR}/template.ufs-noahMP.namelist.${atmos_forc} ufs-land.namelist
else
#cp ${CYCLEDIR}/template.ens.ufs-noahMP.namelist.${atmos_forc} ufs-land.namelist
echo 'CSD - temporarily using non-ensemble namelist'
cp ${CYCLEDIR}/template.ufs-noahMP.namelist.${atmos_forc} ufs-land.namelist
fi
sed -i -e "s/XXYYYY/${YYYY}/g" ufs-land.namelist
sed -i -e "s/XXMM/${MM}/g" ufs-land.namelist
sed -i -e "s/XXDD/${DD}/g" ufs-land.namelist
sed -i -e "s/XXHH/${HH}/g" ufs-land.namelist
sed -i -e "s/XXFREQ/${FREQ}/g" ufs-land.namelist
sed -i -e "s/XXRDD/${RDD}/g" ufs-land.namelist
sed -i -e "s/XXRHH/${RHH}/g" ufs-land.namelist
NN="`printf %02i $n_ens`" # ensemble number
sed -i -e "s/XXMEM/${NN}/g" ufs-land.namelist
# submit model
echo '************************************************'
echo 'calling model'
echo $MEM_WORKDIR
$LSMexec
# no error codes on exit from model, check for restart below instead
# if [[ $? != 0 ]]; then
# echo "model failed"
# exit
# fi
if [[ -e ${MEM_WORKDIR}/restarts/vector/ufs_land_restart.${nYYYY}-${nMM}-${nDD}_${nHH}-00-00.nc ]]; then
cp ${MEM_WORKDIR}/restarts/vector/ufs_land_restart.${nYYYY}-${nMM}-${nDD}_${nHH}-00-00.nc ${MEM_OUTDIR}/restarts/vector/ufs_land_restart_back.${nYYYY}-${nMM}-${nDD}_${nHH}-00-00.nc
else
echo "Something is wrong, probably the model, exiting"
exit
fi
n_ens=$((n_ens+1))
done # n_ens < ensemble_size
echo "Finished job number, ${date_count},for date: ${THISDATE}" >> $logfile
#THISDATE=`${incdate} $THISDATE 24`
THISDATE=$NEXTDATE
date_count=$((date_count+1))
done # date_count -lt dates_per_job
############################
# resubmit script
if [ $THISDATE -lt $ENDDATE ]; then
echo "export STARTDATE=${THISDATE}" > ${analdate}
echo "export ENDDATE=${ENDDATE}" >> ${analdate}
cd ${CYCLEDIR}
sbatch ${CYCLEDIR}/submit_cycle.sh
fi