forked from NOAA-EMC/global-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexgdas_enkf_post.sh
More file actions
executable file
·168 lines (143 loc) · 6.18 KB
/
exgdas_enkf_post.sh
File metadata and controls
executable file
·168 lines (143 loc) · 6.18 KB
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
#! /usr/bin/env bash
################################################################################
#### UNIX Script Documentation Block
# . .
# Script name: exgdas_enkf_post.sh
# Script description: Global ensemble forecast post processing
#
# Author: Rahul Mahajan Org: NCEP/EMC Date: 2017-03-02
#
# Abstract: This script post-processes global ensemble forecast output
#
# $Id$
#
# Attributes:
# Language: POSIX shell
#
################################################################################
# Directories.
pwd=$(pwd)
APRUN_EPOS=${APRUN_EPOS:-${APRUN:-""}}
NTHREADS_EPOS=${NTHREADS_EPOS:-1}
# Fix files
LEVS=${LEVS:-64}
HYBENSMOOTH=${HYBENSMOOTH:-${FIXgfs}/gsi/global_hybens_smoothinfo.l${LEVS}.txt}
# Executables.
GETATMENSMEANEXEC=${GETATMENSMEANEXEC:-${EXECgfs}/getsigensmeanp_smooth.x}
GETSFCENSMEANEXEC=${GETSFCENSMEANEXEC:-${EXECgfs}/getsfcensmeanp.x}
# Other variables.
PREFIX=${PREFIX:-""}
FHMIN=${FHMIN_EPOS:-3}
FHMAX=${FHMAX_EPOS:-9}
FHOUT=${FHOUT_EPOS:-3}
if [[ "${RUN}" == "enkfgfs" ]]; then
NMEM_ENS=${NMEM_ENS_GFS:-${NMEM_ENS:-30}}
else
NMEM_ENS=${NMEM_ENS:-80}
fi
SMOOTH_ENKF=${SMOOTH_ENKF:-"NO"}
ENKF_SPREAD=${ENKF_SPREAD:-"NO"}
################################################################################
# Preprocessing
ENKF_SUFFIX="s"
if [[ "${SMOOTH_ENKF}" == "NO" ]]; then
ENKF_SUFFIX=""
fi
################################################################################
# Copy executables to working directory
cpreq "${GETSFCENSMEANEXEC}" "${DATA}"
cpreq "${GETATMENSMEANEXEC}" "${DATA}"
export OMP_NUM_THREADS=${NTHREADS_EPOS}
################################################################################
# Forecast ensemble member files
for imem in $(seq 1 "${NMEM_ENS}"); do
memchar="mem"$(printf %03i "${imem}")
declare -x COMIN_ATMOS_HISTORY=${ROTDIR}/${RUN}.${PDY}/${cyc}/${memchar}/model/atmos/history
# TODO: remove deadlinks and refer https://github.com/NOAA-EMC/global-workflow/issues/4405
for fhr in $(seq "${FHMIN}" "${FHOUT}" "${FHMAX}"); do
fhrchar=$(printf %03i "${fhr}")
${NLN} "${COMIN_ATMOS_HISTORY}/${PREFIX}sfc.f${fhrchar}.nc" "sfcf${fhrchar}_${memchar}"
${NLN} "${COMIN_ATMOS_HISTORY}/${PREFIX}atm.f${fhrchar}.nc" "atmf${fhrchar}_${memchar}"
done
done
# Forecast ensemble mean and smoothed files
declare -rx COMOUT_ATMOS_HISTORY_STAT="${ROTDIR}/${RUN}.${PDY}/${cyc}/ensstat/model/atmos/history"
if [[ ! -d "${COMOUT_ATMOS_HISTORY_STAT}" ]]; then
mkdir -p "${COMOUT_ATMOS_HISTORY_STAT}"
fi
for fhr in $(seq "${FHMIN}" "${FHOUT}" "${FHMAX}"); do
fhrchar=$(printf %03i "${fhr}")
# TODO: remove deadlinks and refer https://github.com/NOAA-EMC/global-workflow/issues/4405
${NLN} "${COMOUT_ATMOS_HISTORY_STAT}/${PREFIX}ensmean.sfc.f${fhrchar}.nc" "sfcf${fhrchar}.ensmean"
${NLN} "${COMOUT_ATMOS_HISTORY_STAT}/${PREFIX}ensmean.atm.f${fhrchar}.nc" "atmf${fhrchar}.ensmean"
if [[ "${SMOOTH_ENKF}" == "YES" ]]; then
for imem in $(seq 1 "${NMEM_ENS}"); do
memchar="mem"$(printf %03i "${imem}")
declare -x COMIN_ATMOS_HISTORY=${ROTDIR}/${RUN}.${PDY}/${cyc}/${memchar}/model/atmos/history
${NLN} "${COMIN_ATMOS_HISTORY}/${PREFIX}atm.f${fhrchar}${ENKF_SUFFIX}.nc" "atmf${fhrchar}${ENKF_SUFFIX}_${memchar}"
done
fi
if [[ "${ENKF_SPREAD}" == "YES" ]]; then
${NLN} "${COMOUT_ATMOS_HISTORY_STAT}/${PREFIX}ensspread.atm.f${fhrchar}.nc" "atmf${fhrchar}.ensspread"
fi
done
################################################################################
# Generate ensemble mean surface and atmospheric files
if [[ "${SMOOTH_ENKF}" == "YES" ]]; then
cpreq "${HYBENSMOOTH}" ./hybens_smoothinfo
fi
for fhr in $(seq "${FHMIN}" "${FHOUT}" "${FHMAX}"); do
fhrchar=$(printf %03i "${fhr}")
export pgm=${GETSFCENSMEANEXEC}
source prep_step
${APRUN_EPOS} "${DATA}/$(basename "${GETSFCENSMEANEXEC}")" ./ "sfcf${fhrchar}.ensmean" "sfcf${fhrchar}" "${NMEM_ENS}" && true
export err=$?
if [[ ${err} -ne 0 ]]; then
err_exit "Failed to calculate ensemble surface mean for forecast hour ${fhr}"
fi
export pgm=${GETATMENSMEANEXEC}
source prep_step
if [[ "${ENKF_SPREAD}" == "YES" ]]; then
${APRUN_EPOS} "${DATA}/$(basename "${GETATMENSMEANEXEC}")" ./ "atmf${fhrchar}.ensmean" "atmf${fhrchar}" "${NMEM_ENS}" "atmf${fhrchar}.ensspread" && true
export err=$?
if [[ ${err} -ne 0 ]]; then
err_exit "Failed to calculate ensemble atmospheric mean and spread for forecast hour ${fhr}"
fi
else
${APRUN_EPOS} "${DATA}/$(basename "${GETATMENSMEANEXEC}")" ./ "atmf${fhrchar}.ensmean" "atmf${fhrchar}" "${NMEM_ENS}" && true
export err=$?
if [[ ${err} -ne 0 ]]; then
err_exit "Failed to calculate ensemble atmospheric mean for forecast hour ${fhr}"
fi
fi
done
################################################################################
# If smoothing on but no smoothing output, copy smoothed ensemble atmospheric files
if [[ "${SMOOTH_ENKF}" == "YES" ]]; then
for fhr in $(seq "${FHMIN}" "${FHOUT}" "${FHMAX}"); do
fhrchar=$(printf "%03i" "${fhr}")
if [[ ! -s "atmf${fhrchar}${ENKF_SUFFIX}_mem001" ]]; then
echo "WARNING! no smoothed ensemble member for fhour = ${fhrchar}" >&2
for imem in $(seq 1 "${NMEM_ENS}"); do
memchar="mem"$(printf "%03i" "${imem}")
cpreq "atmf${fhrchar}_${memchar}" "atmf${fhrchar}${ENKF_SUFFIX}_${memchar}"
done
fi
done
fi
################################################################################
# Send DBN alerts
if [[ "${SENDDBN}" == "YES" ]]; then
for fhr in $(seq "${FHMIN}" "${FHOUT}" "${FHMAX}"); do
fhrchar=$(printf "%03i" "${fhr}")
if ((fhr % 3 == 0)); then
if [[ -s "./sfcf${fhrchar}.ensmean" ]]; then
"${DBNROOT}/bin/dbn_alert" "MODEL" "GFS_ENKF" "${job}" "${COMOUT_ATMOS_HISTORY_STAT}/${PREFIX}ensmean.sfc.f${fhrchar}.nc"
fi
fi
done
fi
################################################################################
# Postprocessing
cd "${pwd}" || exit 1
exit "${err}"