forked from ufs-community/land-DA_workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit_cycle.sh
executable file
·417 lines (322 loc) · 13.7 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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
#!/bin/bash
#SBATCH --job-name=ufs_land_da
#SBATCH --account=da-cpu
#SBATCH --qos=debug
#SBATCH --nodes=1
#SBATCH --tasks-per-node=6
#SBATCH --cpus-per-task=1
#SBATCH -t 00:06:00
#SBATCH -o log_noahmp.%j.log
#SBATCH -e err_noahmp.%j.err
############################
# loop over time steps
source $analdate
THISDATE=$STARTDATE
date_count=0
while [ $date_count -lt $cycles_per_job ]; do
if [ $THISDATE -ge $ENDDATE ]; then
echo "All done, at date ${THISDATE}" >> $logfile
cd $CYCLEDIR
if [ $KEEPWORKDIR == "NO" ]; then
rm -rf $WORKDIR
fi
exit
fi
echo "starting $THISDATE"
# get DA settings
this_config=DA_config$HH
DA_config=${!this_config}
if [ $DA_config == "openloop" ]; then do_jedi="NO" ; else do_jedi="YES" ; fi
# substringing to get yr, mon, day, hr info
YYYY=`echo $THISDATE | cut -c1-4`
MM=`echo $THISDATE | cut -c5-6`
DD=`echo $THISDATE | cut -c7-8`
HH=`echo $THISDATE | cut -c9-10`
# substringing to get yr, mon, day, hr info for previous cycle
PREVDATE=`${incdate} $THISDATE -6`
YYYP=`echo $PREVDATE | cut -c1-4`
MP=`echo $PREVDATE | cut -c5-6`
DP=`echo $PREVDATE | cut -c7-8`
HP=`echo $PREVDATE | cut -c9-10`
# substring for next cycle
NEXTDATE=`${incdate} $THISDATE $FCSTHR`
nYYYY=`echo $NEXTDATE | cut -c1-4`
nMM=`echo $NEXTDATE | cut -c5-6`
nDD=`echo $NEXTDATE | cut -c7-8`
nHH=`echo $NEXTDATE | cut -c9-10`
############################
# copy restarts to workdir, convert to UFS tile for DA (all members)
mem_ens="mem000"
MEM_WORKDIR=${WORKDIR}/${mem_ens}
MEM_MODL_OUTDIR=${OUTDIR}/${mem_ens}
cd $MEM_WORKDIR
if [[ $do_jedi == "YES" && $atmos_forc == "era5" ]]; then
# copy restarts into work directory
rst_in=${MEM_MODL_OUTDIR}/restarts/vector/ufs_land_restart_back.${YYYY}-${MM}-${DD}_${HH}-00-00.nc
if [[ ! -e ${rst_in} ]]; then
rst_in=${LANDDA_INPUTS}/restarts/${atmos_forc}/ufs_land_restart.${YYYY}-${MM}-${DD}_${HH}-00-00.nc
fi
rst_out=${MEM_WORKDIR}/ufs_land_restart.${YYYY}-${MM}-${DD}_${HH}-00-00.nc
cp ${rst_in} ${rst_out}
echo '************************************************'
echo 'calling vector2tile'
export MEM_WORKDIR
# update vec2tile and tile2vec namelists
cp ${CYCLEDIR}/template.vector2tile vector2tile.namelist
sed -i "s|LANDDA_INPUTS|${LANDDA_INPUTS}|g" 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
sed -i -e "s/XXHH/${HH}/g" vector2tile.namelist
sed -i -e "s/MODEL_FORCING/${atmos_forc}/g" vector2tile.namelist
sed -i -e "s/XXRES/${RES}/g" vector2tile.namelist
sed -i -e "s/XXTSTUB/${TSTUB}/g" vector2tile.namelist
sed -i -e "s#XXTPATH#${TPATH}#g" vector2tile.namelist
# submit vec2tile
echo '************************************************'
echo 'calling vector2tile'
if [[ $BASELINE =~ 'hera.internal' ]]; then
source ${CYCLEDIR}/land_mods
fi
$vec2tileexec vector2tile.namelist
if [[ $? != 0 ]]; then
echo "vec2tile failed"
exit
fi
fi # vector2tile for DA
if [[ $do_jedi == "YES" && $atmos_forc == "gswp3" ]]; then
echo '************************************************'
echo 'calling tile2tile'
export MEM_WORKDIR
# copy restarts into work directory
for tile in 1 2 3 4 5 6
do
rst_in=${MEM_MODL_OUTDIR}/restarts/tile/ufs_land_restart_back.${YYYY}-${MM}-${DD}_${HH}-00-00.nc
if [[ ! -e ${rst_in} ]]; then
rst_in=${LANDDA_INPUTS}/restarts/${atmos_forc}/ufs.cpld.lnd.out.${YYYY}-${MM}-${DD}-00000.tile${tile}.nc
fi
rst_out=${MEM_WORKDIR}/ufs_land_restart.${YYYY}-${MM}-${DD}_${HH}-00-00.tile${tile}.nc
cp ${rst_in} ${rst_out}
done
# update tile2tile namelist
cp ${CYCLEDIR}/template.ufs2jedi ufs2jedi.namelist
sed -i "s|LANDDA_INPUTS|${LANDDA_INPUTS}|g" ufs2jedi.namelist
sed -i -e "s/XXYYYY/${YYYY}/g" ufs2jedi.namelist
sed -i -e "s/XXMM/${MM}/g" ufs2jedi.namelist
sed -i -e "s/XXDD/${DD}/g" ufs2jedi.namelist
sed -i -e "s/XXHH/${HH}/g" ufs2jedi.namelist
sed -i -e "s/XXHH/${HH}/g" ufs2jedi.namelist
sed -i -e "s/MODEL_FORCING/${atmos_forc}/g" ufs2jedi.namelist
sed -i -e "s/XXRES/${RES}/g" ufs2jedi.namelist
sed -i -e "s/XXTSTUB/${TSTUB}/g" ufs2jedi.namelist
sed -i -e "s#XXTPATH#${TPATH}#g" ufs2jedi.namelist
# submit tile2tile
if [[ $BASELINE =~ 'hera.internal' ]]; then
source ${CYCLEDIR}/land_mods
fi
$tile2tileexec ufs2jedi.namelist
if [[ $? != 0 ]]; then
echo "tile2tile failed"
exit
fi
fi # tile2tile for DA
############################
# do DA update
if [[ $do_jedi == "YES" ]]; then
# submit snow DA
echo '************************************************'
echo 'calling snow DA'
cd $WORKDIR
export THISDATE
$DAscript ${CYCLEDIR}/$DA_config
if [[ $? != 0 ]]; then
echo "land DA script failed"
exit
fi
fi
############################
# convert back to vector/tile
mem_ens="mem000"
MEM_WORKDIR=${WORKDIR}/${mem_ens}
MEM_MODL_OUTDIR=${OUTDIR}/${mem_ens}
cd $MEM_WORKDIR
# convert back to vector, run model (all members) convert back to vector, run model (all members)
if [[ $do_jedi == "YES" && $atmos_forc == "era5" ]]; then
echo '************************************************'
echo 'calling tile2vector'
if [[ $BASELINE =~ 'hera.internal' ]]; then
source ${CYCLEDIR}/land_mods
fi
cp ${CYCLEDIR}/template.tile2vector tile2vector.namelist
sed -i "s|LANDDA_INPUTS|${LANDDA_INPUTS}|g" 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
sed -i -e "s/MODEL_FORCING/${atmos_forc}/g" vector2tile.namelist
sed -i -e "s/XXRES/${RES}/g" tile2vector.namelist
sed -i -e "s/XXTSTUB/${TSTUB}/g" tile2vector.namelist
sed -i -e "s#XXTPATH#${TPATH}#g" tile2vector.namelist
$vec2tileexec tile2vector.namelist
if [[ $? != 0 ]]; then
echo "tile2vector failed"
exit
fi
# save analysis restart
cp ${MEM_WORKDIR}/ufs_land_restart.${YYYY}-${MM}-${DD}_${HH}-00-00.nc ${MEM_MODL_OUTDIR}/restarts/vector/ufs_land_restart_anal.${YYYY}-${MM}-${DD}_${HH}-00-00.nc
fi
# convert back to UFS tile, run model (all members)
if [[ $do_jedi == "YES" && $atmos_forc == "gswp3" ]]; then
echo '************************************************'
echo 'calling tile2tile'
if [[ $BASELINE =~ 'hera.internal' ]]; then
source ${CYCLEDIR}/land_mods
fi
cp ${CYCLEDIR}/template.jedi2ufs jedi2ufs.namelist
sed -i "s|LANDDA_INPUTS|${LANDDA_INPUTS}|g" jedi2ufs.namelist
sed -i -e "s/XXYYYY/${YYYY}/g" jedi2ufs.namelist
sed -i -e "s/XXMM/${MM}/g" jedi2ufs.namelist
sed -i -e "s/XXDD/${DD}/g" jedi2ufs.namelist
sed -i -e "s/XXHH/${HH}/g" jedi2ufs.namelist
sed -i -e "s/MODEL_FORCING/${atmos_forc}/g" jedi2ufs.namelist
sed -i -e "s/XXRES/${RES}/g" jedi2ufs.namelist
sed -i -e "s/XXTSTUB/${TSTUB}/g" jedi2ufs.namelist
sed -i -e "s#XXTPATH#${TPATH}#g" jedi2ufs.namelist
$tile2tileexec jedi2ufs.namelist
if [[ $? != 0 ]]; then
echo "tile2tile failed"
exit
fi
# save analysis restart
for tile in 1 2 3 4 5 6
do
cp ${MEM_WORKDIR}/ufs_land_restart.${YYYY}-${MM}-${DD}_${HH}-00-00.tile${tile}.nc ${MEM_MODL_OUTDIR}/restarts/tile/ufs_land_restart_anal.${YYYY}-${MM}-${DD}_${HH}-00-00.tile${tile}.nc
cp ${MEM_WORKDIR}/ufs_land_restart.${YYYY}-${MM}-${DD}_${HH}-00-00.tile${tile}.nc ${MEM_MODL_OUTDIR}/restarts/tile/ufs.cpld.lnd.out.${YYYY}-${MM}-${DD}-00000.tile${tile}.nc
done
fi
############################
# run the forecast model
if [[ $do_jedi == "YES" && $atmos_forc == "era5" ]]; then
echo '************************************************'
echo 'running the forecast model'
set -x
# update model namelist
cp ${CYCLEDIR}/template.ufs-noahMP.namelist.${atmos_forc} ufs-land.namelist
sed -i "s|LANDDA_INPUTS|${LANDDA_INPUTS}|g" ufs-land.namelist
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
# submit model
echo $MEM_WORKDIR
nt=$SLURM_NTASKS
if [[ $BASELINE =~ 'hera.internal' ]]; then
source ${CYCLEDIR}/land_mods
fi
if [[ $BASELINE =~ 'hera.internal' ]]; then
srun '--export=ALL' --label -K -n $nt $LSMexec
else
${MPIEXEC} -n 1 $LSMexec
fi
fi
# no error codes on exit from model, check for restart below instead
if [[ $do_jedi == "YES" && $atmos_forc == "gswp3" ]]; then
set -e
echo '************************************************'
echo 'running the forecast model'
TEST_NAME=datm_cdeps_lnd_gswp3
TEST_NAME_RST=datm_cdeps_lnd_gswp3_rst
PATHRT=${CYCLEDIR}/ufs-weather-model/tests
RT_COMPILER=${RT_COMPILER:-intel}
ATOL="1e-7"
cp $CYCLEDIR/$TEST_NAME_RST ${PATHRT}/tests/$TEST_NAME_RST
source ${PATHRT}/detect_machine.sh
source ${PATHRT}/rt_utils.sh
source ${PATHRT}/default_vars.sh
source ${PATHRT}/tests/$TEST_NAME_RST
source ${PATHRT}/atparse.bash
BL_DATE=20230816
RTPWD=${RTPWD:-${LANDDA_INPUTS}/NEMSfv3gfs/develop-${BL_DATE}/INTEL/${TEST_NAME}}
INPUTDATA_ROOT=${INPUTDATA_ROOT:-${LANDDA_INPUTS}/NEMSfv3gfs/input-data-20221101}
echo "RTPWD= $RTPWD"
echo "INPUTDATA_ROOT= $INPUTDATA_ROOT"
if [[ ! -d ${INPUTDATA_ROOT} ]] || [[ ! -d ${RTPWD} ]]; then
echo "Error: cannot find either folder for INPUTDATA_ROOT or RTPWD, please check!"
exit 1
fi
# create run folder
RUNDIR=${MEM_MODL_OUTDIR}/noahmp/${TEST_NAME_RST}
[[ -d ${RUNDIR} ]] && echo "Warning: remove old run folder!" && rm -rf ${RUNDIR}
mkdir -p ${RUNDIR}
cd ${RUNDIR}
echo "NoahMP run dir= $RUNDIR"
# modify some env variables - reduce core usage
export ATM_compute_tasks=0
export ATM_io_tasks=1
export LND_tasks=6
export layout_x=1
export layout_y=1
# FV3 executable:
cp ${CYCLEDIR}/build/ufs-weather-model/src/ufs-weather-model-build/ufs_model ./ufs_model
cp ${CYCLEDIR}/fv3_run ./fv3_run
if [[ $DATM_CDEPS = 'true' ]] || [[ $FV3 = 'true' ]] || [[ $S2S = 'true' ]]; then
if [[ $HAFS = 'false' ]] || [[ $FV3 = 'true' && $HAFS = 'true' ]]; then
atparse < ${PATHRT}/parm/${INPUT_NML:-input.nml.IN} > input.nml
fi
fi
atparse < ${PATHRT}/parm/${MODEL_CONFIGURE:-model_configure.IN} > model_configure
compute_petbounds_and_tasks
atparse < ${PATHRT}/parm/${UFS_CONFIGURE:-ufs.configure} > ufs.configure
# diag table
if [[ "Q${DIAG_TABLE:-}" != Q ]] ; then
atparse < ${PATHRT}/parm/diag_table/${DIAG_TABLE} > diag_table
fi
# Field table
if [[ "Q${FIELD_TABLE:-}" != Q ]] ; then
cp ${PATHRT}/parm/field_table/${FIELD_TABLE} field_table
fi
# Field Dictionary
cp ${PATHRT}/parm/fd_ufs.yaml fd_ufs.yaml
# Set up the run directory
source ./fv3_run
if [[ $DATM_CDEPS = 'true' ]]; then
atparse < ${PATHRT}/parm/${DATM_IN_CONFIGURE:-datm_in.IN} > datm_in
atparse < ${PATHRT}/parm/${DATM_STREAM_CONFIGURE:-datm.streams.IN} > datm.streams
fi
# NoahMP table file
cp ${PATHRT}/parm/noahmptable.tbl noahmptable.tbl
# start runs
echo "Start ufs-cdeps-land model run with TASKS: ${TASKS}"
export MPIRUN=${MPIRUN:-`which mpiexec`}
${MPIRUN} -n ${TASKS} ./ufs_model
fi
# no error codes on exit from model, check for restart below instead
############################
# check model ouput (all members)
mem_ens="mem000"
MEM_WORKDIR=${WORKDIR}/${mem_ens}
MEM_MODL_OUTDIR=${OUTDIR}/${mem_ens}
if [[ $atmos_forc == "era5" ]]; then
# if [[ -e ${MEM_WORKDIR}/ufs_land_restart.${nYYYY}-${nMM}-${nDD}_${nHH}-00-00.nc ]]; then
cp ${MEM_WORKDIR}/ufs_land_restart.${nYYYY}-${nMM}-${nDD}_${nHH}-00-00.nc ${MEM_MODL_OUTDIR}/restarts/vector/ufs_land_restart_back.${nYYYY}-${nMM}-${nDD}_${nHH}-00-00.nc
else
for tile in 1 2 3 4 5 6
do
cp ${MEM_WORKDIR}/noahmp_output/${TEST_NAME_RST}/ufs.cpld.lnd.out.${nYYYY}-${nMM}-${nDD}-00000.tile${tile}.nc ${MEM_MODL_OUTDIR}/restarts/tile/ufs_land_restart_back.${nYYYY}-${nMM}-${nDD}_${nHH}-00-00.tile${tile}.nc
done
fi
THISDATE=$NEXTDATE
date_count=$((date_count+1))
done # date_count -lt cycles_per_job
############################
# resubmit script
if [ $THISDATE -lt $ENDDATE ]; then
echo "STARTDATE=${THISDATE}" > ${analdate}
echo "ENDDATE=${ENDDATE}" >> ${analdate}
cd ${CYCLEDIR}
sbatch ${CYCLEDIR}/submit_cycle.sh
fi