GMTB Workflow Documentation
met_point_verf_ua.ksh
Go to the documentation of this file.
1 #!/bin/ksh -l
2 
3 ##########################################################################
4 #
5 # Script Name: met_point_verf_ua.ksh
6 #
7 # Author: J.Wolff & 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_ua.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="048"
47 #export RES_LIST="0p25"
48 #export GRID_VX_LIST="G3 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 FCST_TIME
97 ${ECHO} "MODEL=${MODEL}"
98 ${ECHO} "FCST_TIME=${FCST_TIME}"
99 
100 ########################################################################
101 # Compute VX date - only need to run once
102 ########################################################################
103 
104 # Compute the verification date
105 VDATE=`${UTIL_EXEC}/ndate +${FCST_TIME} ${START_TIME}`
106 VYYYYMMDD=`${ECHO} ${VDATE} | ${CUT} -c1-8`
107 VHH=`${ECHO} ${VDATE} | ${CUT} -c9-10`
108 ${ECHO} 'valid time for ' ${FCST_TIME} 'h forecast = ' ${VDATE}
109 
110 ########################################################################
111 # Run pb2nc on prepbufr obs file - only need to run once
112 ########################################################################
113 
114 # Specify the MET PB2NC configuration file to be used
115 export CONFIG_PB2NC="${MET_CONFIG}/PB2NCConfig_GMTB"
116 
117 # Make sure the MET configuration files exists
118 if [ ! -e ${CONFIG_PB2NC} ]; then
119  echo "ERROR: ${CONFIG_PB2NC} does not exist!"
120  exit 1
121 fi
122 
123 # Handle time -- set beg and end times for pb2nc processing
124 VYYYY=`echo ${VYYYYMMDD} | cut -c1-4`
125 VMM=`echo ${VYYYYMMDD} | cut -c5-6`
126 VDD=`echo ${VYYYYMMDD} | cut -c7-8`
127 REF_UT=`date -ud ''${VYYYY}-${VMM}-${VDD}' UTC '${VHH}:00:00'' +%s`
128 BEG_UT=`expr ${REF_UT} - 2700`
129 END_UT=`expr ${REF_UT} + 2700`
130 BEG_STR=`date -ud '1970-01-01 UTC '${BEG_UT}' seconds' +%Y%m%d_%H%M%S`
131 END_STR=`date -ud '1970-01-01 UTC '${END_UT}' seconds' +%Y%m%d_%H%M%S`
132 
133 # List observation file to be run through pb2nc
134 PB_FILE="${PNT_OBS_DIR}/gdas/prepbufr.gdas.${VYYYYMMDD}${VHH}"
135 if [ ! -e ${PB_FILE} ]; then
136  PB_FILE="${OBS_DIR}/gdas/${VYYYYMMDD}/prepbufr.gdas.${VYYYYMMDD}${VHH}"
137 fi
138 if [ ! -e ${PB_FILE} ]; then
139  echo "ERROR: Could not find observation file."
140  exit 1
141 fi
142 
143 # Go to prepbufr dir
144 pb2nc=${workdir}/pb2nc
145 ${MKDIR} -p ${pb2nc}
146 
147 # Create a PB2NC output file name
148 OBS_FILE="${pb2nc}/prepbufr.gdas.${VYYYYMMDD}.t${VHH}z.nc"
149 
150 # Call PB2NC
151 echo "CALLING: ${MET_EXE_ROOT}/pb2nc ${PB_FILE} ${OBS_FILE} ${CONFIG_PB2NC} -v 2"
152 
153 ${MET_EXE_ROOT}/pb2nc ${PB_FILE} ${OBS_FILE} ${CONFIG_PB2NC} -valid_beg ${BEG_STR} -valid_end ${END_STR} -v 2
154 
155 ########################################################################
156 # Run point stat for each grid resolution and verification grid
157 ########################################################################
158 
159 # Loop through the domain list
160 for RES in ${RES_LIST}; do
161 
162  export RES
163  ${ECHO} "RES=${RES}"
164 
165  for GRID_VX in ${GRID_VX_LIST}; do
166  GRID_VX_NUM=`${ECHO} ${GRID_VX} | cut -c2-`
167  typeset -Z3 GRID_VX_NUM
168  GRID_VX_FORMAT="G${GRID_VX_NUM}"
169 
170  export GRID_VX
171  export GRID_VX_FORMAT
172 
173  # Specify new mask directory structure
174  MASKS=${MET_CONFIG}/masks
175  export MASKS
176 
177  # Specify the MET Point-Stat configuration files to be used
178  CONFIG_ADPUPA="${MET_CONFIG}/PointStatConfig_ADPUPA_REGRID_${GRID_VX}"
179 
180  # Make sure the Point-Stat configuration files exists
181  if [ ! -e ${CONFIG_ADPUPA} ]; then
182  ${ECHO} "ERROR: ${CONFIG_ADPUPA} does not exist!"
183  exit 1
184  fi
185 
186  # Check the GDAS observation file (created from previous command to run pb2nc)
187  ${ECHO} "OBS_FILE: ${OBS_FILE}"
188 
189  if [ ! -e ${OBS_FILE} ]; then
190  ${ECHO} "ERROR: Could not find observation file: ${OBS_FILE}"
191  exit 1
192  fi
193 
194  # Get the forecast to verify
195  FCST_FILE=${ROTDIR}/pgrbq${FCST_TIME}.gfs.${START_TIME}.grib2
196  ${ECHO} "FCST_FILE: ${FCST_FILE}"
197 
198  if [ ! -e ${FCST_FILE} ]; then
199  ${ECHO} "ERROR: Could not find UPP output file: ${FCST_FILE}"
200  exit 1
201  fi
202 
203  #######################################################################
204  # Run Point-Stat
205  #######################################################################
206 
207  # Verify upper air variables only at 00Z and 12Z
208  if [ "${VHH}" == "00" -o "${VHH}" == "12" ]; then
209  CONFIG_FILE=${CONFIG_ADPUPA}
210 
211  ${ECHO} "CALLING: ${MET_EXE_ROOT}/point_stat ${FCST_FILE} ${OBS_FILE} ${CONFIG_FILE} -outdir . -v 2"
212 
213  /usr/bin/time ${MET_EXE_ROOT}/point_stat ${FCST_FILE} ${OBS_FILE} ${CONFIG_FILE} \
214  -outdir . -v 2
215 
216  error=$?
217  if [ ${error} -ne 0 ]; then
218  ${ECHO} "ERROR: For ${MODEL}, ${MET_EXE_ROOT}/point_stat ${CONFIG_FILE} crashed Exit status: ${error}"
219  exit ${error}
220  fi
221  fi
222 
223  done # GRID_VX
224 done # RES
225 
226 ##########################################################################
227 
228 ${ECHO} "${SCRIPT} completed at `${DATE}`"
229 
230 exit 0
231