-
Notifications
You must be signed in to change notification settings - Fork 2
/
do_landDA.sh
executable file
·395 lines (312 loc) · 11.7 KB
/
do_landDA.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
#!/bin/bash
# script to run the land DA. Currently only option is the snow LETKFOI.
#
# 1. stage the restarts.
# 2. stage and process obs.
# 3. create the JEDI yamls.
# 4. create pseudo ensemble (LETKF-OI).
# 5. run JEDI.
# 6. add increment file to restarts (and adjust any necessary dependent variables).
# 7. clean up.
# Clara Draper, Oct 2021.
# Aug 2020, generalized for all DA types.
#########################################
# source namelist and setup directories
#########################################
set -x
if [[ $# -gt 0 ]]; then
config_file=$1
else
echo "do_landDA.sh: no config file specified, exting"
exit 1
fi
echo "reading DA settings from $config_file"
GFSv17=${GFSv17:-"NO"}
fv3bundle_vn=${fv3bundle_vn:-"psl_develop"}
#fv3bundle_vn=${fv3bundle_vn:-"release-v1.0"}
source $config_file
LOGDIR=${OUTDIR}/DA/logs/
# executables
if [[ -e ${BUILDDIR}/bin/apply_incr.exe ]]; then #prefer cmake-built executables
apply_incr_EXEC=${BUILDDIR}/bin/apply_incr.exe
elif [[ -e ${EXECdir}/apply_incr.exe ]]; then # vertical dir structure in nco standards
apply_incr_EXEC=${EXECdir}/apply_incr.exe
else
apply_incr_EXEC=${CYCLEDIR}/DA_update/add_jedi_incr/exec/apply_incr
fi
# storage settings
SAVE_INCR="YES" # "YES" to save increment (add others?) JEDI output
SAVE_TILE=${SAVE_TILE:-"NO"} # "YES" to save background in tile space
KEEPJEDIDIR=${KEEPJEDIDIR:-"YES"} # delete DA workdir
echo 'THISDATE in land DA, '$THISDATE
############################################################################################
# create output directories.
if [[ ! -e ${OUTDIR}/DA ]]; then
mkdir -p ${OUTDIR}/DA
mkdir ${OUTDIR}/DA/jedi_incr
mkdir ${OUTDIR}/DA/logs
mkdir ${OUTDIR}/DA/hofx
fi
export JEDIWORKDIR=${WORKDIR}/mem000/jedi
OROG_PATH="TPATH"
if [[ ! -e $JEDIWORKDIR ]]; then
mkdir -p $JEDIWORKDIR
fi
cd $JEDIWORKDIR
################################################
# 1. FORMAT DATE STRINGS AND STAGE RESTARTS
################################################
INCDATE=${LANDDADIR}/incdate.sh
YYYY=`echo $THISDATE | cut -c1-4`
MM=`echo $THISDATE | cut -c5-6`
DD=`echo $THISDATE | cut -c7-8`
HH=`echo $THISDATE | cut -c9-10`
PREVDATE=`${INCDATE} $THISDATE -$WINLEN`
YYYP=`echo $PREVDATE | cut -c1-4`
MP=`echo $PREVDATE | cut -c5-6`
DP=`echo $PREVDATE | cut -c7-8`
HP=`echo $PREVDATE | cut -c9-10`
FILEDATE=${YYYY}${MM}${DD}.${HH}0000
if [[ ! -e ${JEDIWORKDIR}/output ]]; then
ln -s ${OUTDIR} ${JEDIWORKDIR}/output
fi
if [[ $SAVE_TILE == "YES" ]]; then
for tile in 1 2 3 4 5 6
do
cp ${RSTRDIR}/${FILEDATE}.sfc_data.tile${tile}.nc ${RSTRDIR}/${FILEDATE}.sfc_data_back.tile${tile}.nc
done
fi
#stage restarts for applying JEDI update (files will get directly updated)
for tile in 1 2 3 4 5 6
do
ln -fs ${RSTRDIR}/${FILEDATE}.sfc_data.tile${tile}.nc ${JEDIWORKDIR}/${FILEDATE}.sfc_data.tile${tile}.nc
done
cres_file=${JEDIWORKDIR}/${FILEDATE}.coupler.res
if [[ -e ${RSTRDIR}/${FILEDATE}.coupler.res ]]; then
ln -sf ${RSTRDIR}/${FILEDATE}.coupler.res $cres_file
else # if not present, need to create coupler.res for JEDI
cp ${LANDDADIR}/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
fi
################################################
# 2. PREPARE OBS FILES
################################################
for ii in "${!OBS_TYPES[@]}"; # loop through requested obs
do
# get the obs file name
if [ ${OBS_TYPES[$ii]} == "GTS" ]; then
obsfile=$OBSDIR/snow_depth/GTS/data_proc/${YYYY}${MM}/adpsfc_snow_${YYYY}${MM}${DD}${HH}.nc4
# GHCN are time-stamped at 18. If assimilating at 00, need to use previous day's obs, so that
# obs are within DA window.
elif [ $atmos_forc == "era5" ] && [ ${OBS_TYPES[$ii]} == "GHCN" ]; then
obsfile=$OBSDIR/snow_depth/GHCN/data_proc/v3/${YYYY}/ghcn_snwd_ioda_${YYYP}${MP}${DP}.nc
elif [ $atmos_forc == "gswp3" ] && [ ${OBS_TYPES[$ii]} == "GHCN" ]; then
obsfile=$OBSDIR/snow_depth/GHCN/data_proc/v3/${YYYY}/fake_ghcn_snwd_ioda_${YYYP}${MP}${DP}.nc
elif [ ${OBS_TYPES[$ii]} == "SYNTH" ]; then
obsfile=$OBSDIR/synthetic_noahmp/IODA.synthetic_gswp_obs.${YYYY}${MM}${DD}${HH}.nc
else
echo "do_landDA: Unknown obs type requested ${OBS_TYPES[$ii]}, exiting"
exit 1
fi
# check obs are available
if [[ -e $obsfile ]]; then
echo "do_landDA: ${OBS_TYPES[$ii]} observations found: $obsfile"
ln -fs $obsfile ${OBS_TYPES[$ii]}_${YYYY}${MM}${DD}${HH}.nc
else
echo "${OBS_TYPES[$ii]} observations not found: $obsfile"
JEDI_TYPES[$ii]="SKIP"
fi
done # OBS_TYPES
################################################
# 3. DETERMINE REQUESTED JEDI TYPE, CONSTRUCT YAMLS
################################################
do_DA="NO"
do_HOFX="NO"
for ii in "${!OBS_TYPES[@]}"; # loop through requested obs
do
if [ ${JEDI_TYPES[$ii]} == "DA" ]; then
do_DA="YES"
elif [ ${JEDI_TYPES[$ii]} == "HOFX" ]; then
do_HOFX="YES"
elif [ ${JEDI_TYPES[$ii]} != "SKIP" ]; then
echo "do_landDA:Unknown obs action ${JEDI_TYPES[$ii]}, exiting"
exit 1
fi
done
if [[ $do_DA == "NO" && $do_HOFX == "NO" ]]; then
echo "do_landDA:No obs found, not calling JEDI"
exit 0
fi
# if yaml is specified by user, use that. Otherwise, build the yaml
if [[ $do_DA == "YES" ]]; then
if [[ $YAML_DA == "construct" ]];then # construct the yaml
cp ${LANDDADIR}/jedi/fv3-jedi/yaml_files/${fv3bundle_vn}/${DAtype}.yaml ${JEDIWORKDIR}/letkf_land.yaml
for ii in "${!OBS_TYPES[@]}";
do
if [ ${JEDI_TYPES[$ii]} == "DA" ]; then
cat ${LANDDADIR}/jedi/fv3-jedi/yaml_files/${fv3bundle_vn}/${OBS_TYPES[$ii]}.yaml >> letkf_land.yaml
fi
done
else # use specified yaml
echo "Using user specified YAML: ${YAML_DA}"
cp ${LANDDADIR}/jedi/fv3-jedi/yaml_files/${fv3bundle_vn}/${YAML_DA} ${JEDIWORKDIR}/letkf_land.yaml
fi
sed -i -e "s/XXYYYY/${YYYY}/g" letkf_land.yaml
sed -i -e "s/XXMM/${MM}/g" letkf_land.yaml
sed -i -e "s/XXDD/${DD}/g" letkf_land.yaml
sed -i -e "s/XXHH/${HH}/g" letkf_land.yaml
sed -i -e "s/XXYYYP/${YYYP}/g" letkf_land.yaml
sed -i -e "s/XXMP/${MP}/g" letkf_land.yaml
sed -i -e "s/XXDP/${DP}/g" letkf_land.yaml
sed -i -e "s/XXHP/${HP}/g" letkf_land.yaml
sed -i -e "s/XXTSTUB/${TSTUB}/g" letkf_land.yaml
sed -i -e "s#XXTPATH#${TPATH}#g" letkf_land.yaml
sed -i -e "s/XXRES/${RES}/g" letkf_land.yaml
RESP1=$((RES+1))
sed -i -e "s/XXREP/${RESP1}/g" letkf_land.yaml
sed -i -e "s/XXHOFX/false/g" letkf_land.yaml # do DA
fi
if [[ $do_HOFX == "YES" ]]; then
if [[ $YAML_HOFX == "construct" ]];then # construct the yaml
cp ${LANDDADIR}/jedi/fv3-jedi/yaml_files/${fv3bundle_vn}/${DAtype}.yaml ${JEDIWORKDIR}/hofx_land.yaml
for ii in "${!OBS_TYPES[@]}";
do
if [ ${JEDI_TYPES[$ii]} == "HOFX" ]; then
cat ${LANDDADIR}/jedi/fv3-jedi/yaml_files/${fv3bundle_vn}/${OBS_TYPES[$ii]}.yaml >> hofx_land.yaml
fi
done
else # use specified yaml
echo "Using user specified YAML: ${YAML_HOFX}"
cp ${LANDDADIR}/jedi/fv3-jedi/yaml_files/${fv3bundle_vn}/${YAML_HOFX} ${JEDIWORKDIR}/hofx_land.yaml
fi
sed -i -e "s/XXYYYY/${YYYY}/g" hofx_land.yaml
sed -i -e "s/XXMM/${MM}/g" hofx_land.yaml
sed -i -e "s/XXDD/${DD}/g" hofx_land.yaml
sed -i -e "s/XXHH/${HH}/g" hofx_land.yaml
sed -i -e "s/XXYYYP/${YYYP}/g" hofx_land.yaml
sed -i -e "s/XXMP/${MP}/g" hofx_land.yaml
sed -i -e "s/XXDP/${DP}/g" hofx_land.yaml
sed -i -e "s/XXHP/${HP}/g" hofx_land.yaml
sed -i -e "s#XXTPATH#${TPATH}#g" hofx_land.yaml
sed -i -e "s/XXTSTUB/${TSTUB}/g" hofx_land.yaml
sed -i -e "s/XXRES/${RES}/g" hofx_land.yaml
RESP1=$((RES+1))
sed -i -e "s/XXREP/${RESP1}/g" hofx_land.yaml
sed -i -e "s/XXHOFX/true/g" hofx_land.yaml # do HOFX
fi
################################################
# 4. CREATE BACKGROUND ENSEMBLE (LETKFOI)
################################################
if [[ ${DAtype} == 'letkfoi_snow' ]]; then
JEDI_EXEC="fv3jedi_letkf.x"
if [ $GFSv17 == "YES" ]; then
SNOWDEPTHVAR="snodl"
# field overwrite file with GFSv17 variables.
cp ${LANDDADIR}/jedi/fv3-jedi/yaml_files/${fv3bundle_vn}/gfs-land-v17.yaml ${JEDIWORKDIR}/gfs-land-v17.yaml
else
SNOWDEPTHVAR="snwdph"
fi
B=30 # back ground error std for LETKFOI
# FOR LETKFOI, CREATE THE PSEUDO-ENSEMBLE
for ens in pos neg
do
if [ -e $JEDIWORKDIR/mem_${ens} ]; then
rm -r $JEDIWORKDIR/mem_${ens}
fi
mkdir -p $JEDIWORKDIR/mem_${ens}
for tile in 1 2 3 4 5 6
do
cp ${JEDIWORKDIR}/${FILEDATE}.sfc_data.tile${tile}.nc ${JEDIWORKDIR}/mem_${ens}/${FILEDATE}.sfc_data.tile${tile}.nc
done
cp ${JEDIWORKDIR}/${FILEDATE}.coupler.res ${JEDIWORKDIR}/mem_${ens}/${FILEDATE}.coupler.res
done
echo 'do_landDA: calling create ensemble'
# using ioda mods to get a python version with netCDF4
if [[ ${BASELINE} =~ 'hera.internal' ]]; then
source ${LANDDADIR}/ioda_mods_hera
python ${LANDDADIR}/letkf_create_ens.py $FILEDATE $SNOWDEPTHVAR $B
else
${PYTHON} ${LANDDADIR}/letkf_create_ens.py $FILEDATE $SNOWDEPTHVAR $B
fi
if [[ $? != 0 ]]; then
echo "letkf create failed"
exit 10
fi
fi
################################################
# 5. RUN JEDI
################################################
NPROC_JEDI=6
if [[ ! -e Data ]]; then
ln -s $JEDI_STATICDIR Data
fi
echo 'do_landDA: calling fv3-jedi'
if [[ $do_DA == "YES" ]]; then
if [[ ${BASELINE} =~ 'hera.internal' ]]; then
source /scratch2/NCEPDEV/land/data/jedi/fv3_mods_hera
srun -n $NPROC_JEDI ${JEDI_EXECDIR}/${JEDI_EXEC} letkf_land.yaml ${LOGDIR}/jedi_letkf.log
else
${MPIEXEC} -n $NPROC_JEDI ${JEDI_EXECDIR}/${JEDI_EXEC} letkf_land.yaml ${LOGDIR}/jedi_letkf.log
fi
if [[ $? != 0 ]]; then
echo "JEDI DA failed"
exit 10
fi
fi
if [[ $do_HOFX == "YES" ]]; then
if [[ ${BASELINE} =~ 'hera.internal' ]]; then
source ${JEDI_EXECDIR}/../../../fv3_mods_hera
srun -n $NPROC_JEDI ${JEDI_EXECDIR}/${JEDI_EXEC} hofx_land.yaml ${LOGDIR}/jedi_hofx.log
else
${MPIEXEC} -n $NPROC_JEDI ${JEDI_EXECDIR}/${JEDI_EXEC} hofx_land.yaml ${LOGDIR}/jedi_hofx.log
fi
if [[ $? != 0 ]]; then
echo "JEDI hofx failed"
exit 10
fi
fi
################################################
# 6. APPLY INCREMENT TO UFS RESTARTS
################################################
if [[ $do_DA == "YES" ]]; then
if [[ $DAtype == "letkfoi_snow" ]]; then
cat << EOF > apply_incr_nml
&noahmp_snow
date_str=${YYYY}${MM}${DD}
hour_str=$HH
res=$RES
frac_grid=$GFSv17
orog_path="$TPATH"
otype="$TSTUB"
/
EOF
echo 'do_landDA: calling apply snow increment'
if [[ ${BASELINE} =~ 'hera.internal' ]]; then
source ${LANDDADIR}/land_mods_hera
fi
# (n=6) -> this is fixed, at one task per tile (with minor code change, could run on a single proc).
${MPIEXEC} -n 6 ${apply_incr_EXEC} ${LOGDIR}/apply_incr.log
if [[ $? != 0 ]]; then
echo "apply snow increment failed"
exit 10
fi
fi
fi
################################################
# 7. CLEAN UP
################################################
# keep increments
if [ $SAVE_INCR == "YES" ] && [ $do_DA == "YES" ]; then
cp ${JEDIWORKDIR}/${FILEDATE}.xainc.sfc_data.tile*.nc ${OUTDIR}/DA/jedi_incr/
fi
# clean up
if [[ $KEEPJEDIDIR == "NO" ]]; then
rm -rf ${JEDIWORKDIR}
fi