GMTB Workflow Documentation
met_point_verf_sfc.ksh
Go to the documentation of this file.
1 #!/bin/ksh -l
2 
3 ##########################################################################
4 #
5 # Script Name: met_point_verf_sfc.ksh
6 #
7 # Authors: J.Wolff and M.Harrold
8 # NCAR/RAL & DTC
9 #
10 # Released: 6/7/2016
11 #
12 # Description:
13 # This script runs the MET/Point-Stat tool to verify gridded output
14 # from the WRF PostProcessor using point observations. The MET/PB2NC
15 # tool is run on the PREPBUFR observation files within this script.
16 #
17 # START_TIME = The cycle time to use for the initial time.
18 # FCST_TIME = The three-digit forecast that is to be verified.
19 # DOMAIN_LIST = A list of domains to be verified.
20 # MET_EXE_ROOT = The full path of the MET executables.
21 # MET_CONFIG = The full path of the MET configuration files.
22 # UTIL_EXEC = The full path of the ndate executable.
23 # MOAD_DATAROOT = Top-level data directory of WRF output.
24 # RAW_OBS = Directory containing observations to be used.
25 # MODEL = The model being evaluated.
26 #
27 ##########################################################################
28 
29 # Name of this script
30 SCRIPT=met_point_verf_sfc.ksh
31 
32 # Set path for manual testing of script
33 #export CONSTANT=/scratch4/BMC/gmtb/harrold/gmtb-tierIII/bin/constants.ksh
34 
35 # Make sure ${CONSTANT} exists
36 if [ ! -x "${CONSTANT}" ]; then
37  ${ECHO} "ERROR: ${CONSTANT} does not exist or is not executable"
38  exit 1
39 fi
40 
41 # Read constants into the current shell
42 . ${CONSTANT}
43 
44 # Vars used for manual testing of the script
45 #export START_TIME=2016012200
46 #export FCST_TIME="006"
47 #export RES_LIST="0p25"
48 #export GRID_VX_LIST="G218"
49 #export MET_EXE_ROOT=/scratch4/BMC/dtc/MET/met-5.1/bin
50 #export MET_CONFIG=/scratch4/BMC/gmtb/harrold/gmtb-tierIII/parm/met_config
51 #export UTIL_EXEC=/scratch4/BMC/gmtb/gmtb-tierIII/util
52 #export MOAD_DATAROOT=/scratch4/BMC/gmtb/mid_tier/OUTPUT/prtutornems_0p25/DOMAINS/2016012200
53 #export PNT_OBS_DIR=/scratch4/NCEPDEV/global/noscrub/stat/prepbufr
54 #export MODEL=GFSnems
55 
56 # Print run parameters/masks
57 ${ECHO}
58 ${ECHO} "${SCRIPT} started at `${DATE}`"
59 ${ECHO}
60 ${ECHO} " START_TIME = ${START_TIME}"
61 ${ECHO} " FCST_TIME = ${FCST_TIME}"
62 ${ECHO} " RES_LIST = ${RES_LIST}"
63 ${ECHO} " GRID_VX_LIST = ${GRID_VX_LIST}"
64 ${ECHO} " MET_EXE_ROOT = ${MET_EXE_ROOT}"
65 ${ECHO} " MET_CONFIG = ${MET_CONFIG}"
66 ${ECHO} " UTIL_EXEC = ${UTIL_EXEC}"
67 ${ECHO} " MOAD_DATAROOT = ${MOAD_DATAROOT}"
68 ${ECHO} " ROTDIR = ${ROTDIR}"
69 ${ECHO} " PNT_OBS_DIR = ${PNT_OBS_DIR}"
70 ${ECHO} " MODEL = ${MODEL}"
71 
72 # Make sure $MOAD_DATAROOT exists
73 if [ ! -d "${MOAD_DATAROOT}" ]; then
74  ${ECHO} "MOAD_DATAROOT, ${MOAD_DATAROOT} does not exist; will create it now!"
75  ${MKDIR} -p ${MOAD_DATAROOT}
76 fi
77 
78 # Make sure ROTDIR exists
79 if [ ! -d "${ROTDIR}" ]; then
80  ${ECHO} "ERROR: ROTDIR, ${ROTDIR} does not exist"
81  exit 1
82 fi
83 
84 # Make sure PNT_OBS_DIR directory exists
85 if [ ! -d ${PNT_OBS_DIR} ]; then
86  ${ECHO} "ERROR: PNT_OBS_DIR, ${PNT_OBS_DIR}, does not exist!"
87  exit 1
88 fi
89 
90 # Go to working directory
91 workdir=${MOAD_DATAROOT}/metprd
92 ${MKDIR} -p ${workdir}
93 cd ${workdir}
94 
95 export MODEL
96 export VERSION
97 export FCST_TIME
98 ${ECHO} "MODEL=${MODEL}"
99 ${ECHO} "VERSION=${VERSION}"
100 ${ECHO} "FCST_TIME=${FCST_TIME}"
101 
102 ########################################################################
103 # Compute VX date - only need to run once
104 ########################################################################
105 
106 # Compute the verification date
107 VDATE=`${UTIL_EXEC}/ndate +${FCST_TIME} ${START_TIME}`
108 VYYYYMMDD=`${ECHO} ${VDATE} | ${CUT} -c1-8`
109 VHH=`${ECHO} ${VDATE} | ${CUT} -c9-10`
110 ${ECHO} 'valid time for ' ${FCST_TIME} 'h forecast = ' ${VDATE}
111 
112 ########################################################################
113 # Run pb2nc on prepbufr obs file - only need to run once
114 ########################################################################
115 
116 # Specify the MET PB2NC configuration file to be used
117 export CONFIG_PB2NC="${MET_CONFIG}/PB2NCConfig_GMTB"
118 
119 # Make sure the MET configuration files exists
120 if [ ! -e ${CONFIG_PB2NC} ]; then
121  echo "ERROR: ${CONFIG_PB2NC} does not exist!"
122  exit 1
123 fi
124 
125 # Process time information -- NDAS specific
126 # For retro NDAS vx, use "late" files, which are tm09 and tm12.
127 if [[ ${VHH} == "00" || ${VHH} == "06" || ${VHH} == "12" || ${VHH} == "18" ]]; then
128  TMMARK="tm12"
129 elif [[ ${VHH} == "03" || ${VHH} == "09" || ${VHH} == "15" || ${VHH} == "21" ]]; then
130  TMMARK="tm09"
131 else
132  echo "ERROR: Valid hour is not compatible with using NDAS data."
133  exit 1
134 fi
135 
136 # For finding NDAS files in traditional naming convention and placements, uncomment.
137 # For GMTB, we organized the data by valid time.
138 #TM_HR=`echo ${TMMARK} | cut -c3-4`
139 
140 #VYYYY=`echo ${VYYYYMMDD} | cut -c1-4`
141 #VMM=`echo ${VYYYYMMDD} | cut -c5-6`
142 #VDD=`echo ${VYYYYMMDD} | cut -c7-8`
143 #SEC_OFF=`expr ${TM_HR} \* 3600`
144 #REF_UT=`date -ud ''${VYYYY}-${VMM}-${VDD}' UTC '${VHH}:00:00'' +%s`
145 #NDAS_UT=`expr ${REF_UT} + ${SEC_OFF}`
146 #NDAS_YMD=`date -ud '1970-01-01 UTC '${NDAS_UT}' seconds' +%Y%m%d`
147 #NDAS_HR=`date -ud '1970-01-01 UTC '${NDAS_UT}' seconds' +%H`
148 #BEG_UT=`expr ${REF_UT} - 2700`
149 #END_UT=`expr ${REF_UT} + 2700`
150 #BEG_STR=`date -ud '1970-01-01 UTC '${BEG_UT}' seconds' +%Y%m%d_%H%M%S`
151 #END_STR=`date -ud '1970-01-01 UTC '${END_UT}' seconds' +%Y%m%d_%H%M%S`
152 
153 TM_HR=`echo ${TMMARK} | cut -c3-4`
154 
155 VYYYY=`echo ${VYYYYMMDD} | cut -c1-4`
156 VMM=`echo ${VYYYYMMDD} | cut -c5-6`
157 VDD=`echo ${VYYYYMMDD} | cut -c7-8`
158 REF_UT=`date -ud ''${VYYYY}-${VMM}-${VDD}' UTC '${VHH}:00:00'' +%s`
159 BEG_UT=`expr ${REF_UT} - 2700`
160 END_UT=`expr ${REF_UT} + 2700`
161 BEG_STR=`date -ud '1970-01-01 UTC '${BEG_UT}' seconds' +%Y%m%d_%H%M%S`
162 END_STR=`date -ud '1970-01-01 UTC '${END_UT}' seconds' +%Y%m%d_%H%M%S`
163 
164 
165 # List observation file to be run through pb2nc
166 #PB_FILE=`${LS} ${PNT_OBS_DIR}/ndas/ndas.${NDAS_YMD}/ndas.t${NDAS_HR}z.prepbufr.${TMMARK} | head -1`
167 PB_FILE=`${LS} ${PNT_OBS_DIR}/${VYYYYMMDD}/prepbufr.ndas.${VYYYYMMDD}.t${VHH}z.${TMMARK} | head -1`
168 if [ ! -e ${PB_FILE} ]; then
169  echo "ERROR: Could not find observation file: ${PB_FILE}"
170  exit 1
171 fi
172 
173 # Go to prepbufr dir
174 pb2nc=${workdir}/pb2nc
175 ${MKDIR} -p ${pb2nc}
176 
177 # Create a PB2NC output file name
178 OBS_FILE="${pb2nc}/prepbufr.ndas.${VYYYYMMDD}.t${VHH}z.nc"
179 
180 # Call PB2NC
181 echo "CALLING: ${MET_EXE_ROOT}/pb2nc ${PB_FILE} ${OBS_FILE} ${CONFIG_PB2NC} -v 2"
182 
183 ${MET_EXE_ROOT}/pb2nc ${PB_FILE} ${OBS_FILE} ${CONFIG_PB2NC} -valid_beg ${BEG_STR} -valid_end ${END_STR} -v 2
184 
185 ########################################################################
186 # Run point stat for each grid resolution and verification grid
187 ########################################################################
188 
189 # Loop through the domain list
190 for RES in ${RES_LIST}; do
191 
192  export RES
193  ${ECHO} "RES=${RES}"
194 
195  for GRID_VX in ${GRID_VX_LIST}; do
196  GRID_VX_NUM=`${ECHO} ${GRID_VX} | cut -c2-`
197  typeset -Z3 GRID_VX_NUM
198  GRID_VX_FORMAT="G${GRID_VX_NUM}"
199 
200  export GRID_VX
201  export GRID_VX_FORMAT
202 
203  ${ECHO} "FCST_TIME=${FCST_TIME}"
204 
205  # Specify new mask directory structure
206  MASKS=${MET_CONFIG}/masks
207  export MASKS
208 
209  # Specify the MET Point-Stat configuration files to be used
210  CONFIG_ADPSFC="${MET_CONFIG}/PointStatConfig_ADPSFC_NDAS_REGRID"
211  CONFIG_ADPSFC_MPR="${MET_CONFIG}/PointStatConfig_ADPSFC_MPR_NDAS_REGRID"
212 
213  # Make sure the Point-Stat configuration files exists
214  if [ ! -e ${CONFIG_ADPSFC} ]; then
215  ${ECHO} "ERROR: ${CONFIG_ADPSFC} does not exist!"
216  exit 1
217  fi
218  if [ ! -e ${CONFIG_ADPSFC_MPR} ]; then
219  ${ECHO} "ERROR: ${CONFIG_ADPSFC_MPR} does not exist!"
220  exit 1
221  fi
222 
223  # Check the NDAS observation file (created from previous command to run pb2nc)
224  ${ECHO} "OBS_FILE: ${OBS_FILE}"
225 
226  if [ ! -e ${OBS_FILE} ]; then
227  ${ECHO} "ERROR: Could not find observation file: ${OBS_FILE}"
228  exit 1
229  fi
230 
231  # Get the forecast to verify
232  FCST_FILE=${ROTDIR}/pgrbq${FCST_TIME}.gfs.${START_TIME}.grib2
233  ${ECHO} "FCST_FILE: ${FCST_FILE}"
234 
235  if [ ! -e ${FCST_FILE} ]; then
236  ${ECHO} "ERROR: Could not find UPP output file: ${FCST_FILE}"
237  exit 1
238  fi
239 
240  #######################################################################
241  # Run Point-Stat
242  #######################################################################
243 
244  # Verify surface variables for each forecast hour
245  CONFIG_FILE=${CONFIG_ADPSFC}
246 
247  ${ECHO} "CALLING: ${MET_EXE_ROOT}/point_stat ${FCST_FILE} ${OBS_FILE} ${CONFIG_FILE} -outdir . -v 2"
248 
249  /usr/bin/time ${MET_EXE_ROOT}/point_stat ${FCST_FILE} ${OBS_FILE} ${CONFIG_FILE} \
250  -outdir . -v 2
251 
252  error=$?
253  if [ ${error} -ne 0 ]; then
254  ${ECHO} "ERROR: For ${MODEL}, ${MET_EXE_ROOT}/point_stat ${CONFIG_FILE} crashed Exit status: ${error}"
255  exit ${error}
256  fi
257 
258  # Verify surface variables for each forecast hour - MPR output
259  CONFIG_FILE=${CONFIG_ADPSFC_MPR}
260 
261  ${ECHO} "CALLING: ${MET_EXE_ROOT}/point_stat ${FCST_FILE} ${OBS_FILE} ${CONFIG_FILE} -outdir . -v 2"
262 
263  /usr/bin/time ${MET_EXE_ROOT}/point_stat ${FCST_FILE} ${OBS_FILE} ${CONFIG_FILE} \
264  -outdir . -v 2
265 
266  error=$?
267  if [ ${error} -ne 0 ]; then
268  ${ECHO} "ERROR: For ${MODEL}, ${MET_EXE_ROOT}/point_stat ${CONFIG_FILE} crashed Exit status: ${error}"
269  exit ${error}
270  fi
271 
272  done # GRID_VX
273 done # RES
274 
275 ##########################################################################
276 
277 ${ECHO} "${SCRIPT} completed at `${DATE}`"
278 
279 exit 0
280