GMTB Workflow Documentation
met_grid_anl_verf.ksh
Go to the documentation of this file.
1 #!/bin/ksh -l
2 
3 ##########################################################################
4 #
5 # Script Name: met_grid_anl_verf.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/Grid-Stat to verify gridded model output
14 # against gridded precipitation analyses.
15 #
16 # START_TIME = The cycle time to use for the initial time.
17 # FCST_TIME_LIST = The three-digit forecasts that is to be verified.
18 # ACCUM_TIME = The two-digit accumulation time: 03 or 24.
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 UPP executables.
23 # MOAD_DATAROOT = Top-level data directory of WRF output.
24 # ANL_OBS_DIR = Directory containing observations to be used.
25 # CLIMO_FILE_DIR = Directory containing climo files to be used.
26 # MODEL = The model being evaluated.
27 #
28 ##########################################################################
29 
30 # Name of this script
31 SCRIPT=met_grid_anl_verf.ksh
32 
33 # Set path for manual testing of script
34 #export CONSTANT=/scratch4/BMC/gmtb/harrold/gmtb-tierIII/bin/constants.ksh
35 
36 # Make sure ${CONSTANT} exists
37 if [ ! -x "${CONSTANT}" ]; then
38  ${ECHO} "ERROR: ${CONSTANT} does not exist or is not executable"
39  exit 1
40 fi
41 
42 # Read constants into the current shell
43 . ${CONSTANT}
44 
45 # Vars used for manual testing of the script
46 #export START_TIME=2016012200
47 #export FCST_TIME="000"
48 #export RES_LIST="0p25"
49 #export GRID_VX_LIST="G3"
50 #export MET_EXE_ROOT=/scratch4/BMC/dtc/MET/met-5.1/bin
51 #export MET_CONFIG=/scratch4/BMC/gmtb/harrold/gmtb-tierIII/parm/met_config
52 #export UTIL_EXEC=/scratch4/BMC/gmtb/gmtb-tierIII/util
53 #export MOAD_DATAROOT=/scratch4/BMC/gmtb/gmtb-tierIII/OUTPUT/prtutornems_0p25/DOMAINS/2016012200
54 #export ROTDIR=/scratch4/BMC/gmtb/gmtb-tierIII/prtutornems_0p25/DOMAINS/2016012200
55 #export ANL_OBS_DIR=/scratch4/BMC/gmtb/gmtb-tierIII/vx_data/analyses/gfs_0p25
56 #export CLIMO_FILE_DIR=/scratch4/NCEPDEV/global/save/Fanglin.Yang/VRFY/vsdb/nwprod/fix
57 #export MODEL=GFSnems
58 
59 # Print run parameters
60 ${ECHO}
61 ${ECHO} "${SCRIPT} started at `${DATE}`"
62 ${ECHO}
63 ${ECHO} " START_TIME = ${START_TIME}"
64 ${ECHO} " FCST_TIME = ${FCST_TIME}"
65 ${ECHO} " RES_LIST = ${RES_LIST}"
66 ${ECHO} " GRID_VX_LIST = ${GRID_VX_LIST}"
67 ${ECHO} " MET_EXE_ROOT = ${MET_EXE_ROOT}"
68 ${ECHO} " MET_CONFIG = ${MET_CONFIG}"
69 ${ECHO} " UTIL_EXEC = ${UTIL_EXEC}"
70 ${ECHO} " MOAD_DATAROOT = ${MOAD_DATAROOT}"
71 ${ECHO} " ROTDIR = ${ROTDIR}"
72 ${ECHO} " ANL_OBS_DIR = ${ANL_OBS_DIR}"
73 ${ECHO} " MODEL = ${MODEL}"
74 
75 # Make sure $MOAD_DATAROOT exists
76 if [ ! -d "${MOAD_DATAROOT}" ]; then
77  ${ECHO} "MOAD_DATAROOT, ${MOAD_DATAROOT} does not exist; will create it now!"
78  ${MKDIR} -p ${MOAD_DATAROOT}
79 fi
80 
81 # Make sure ROTDIR exists
82 if [ ! -d "${ROTDIR}" ]; then
83  ${ECHO} "ERROR: ROTDIR, ${ROTDIR} does not exist"
84  exit 1
85 fi
86 
87 # Make sure RAW_OBS directory exists
88 if [ ! -d ${ANL_OBS_DIR} ]; then
89  ${ECHO} "ERROR: ANL_OBS_DIR, ${ANL_OBS_DIR}, does not exist!"
90  exit 1
91 fi
92 
93 # Go to working directory
94 workdir=${MOAD_DATAROOT}/metprd
95 ${MKDIR} -p ${workdir}
96 cd ${workdir}
97 
98 export MODEL
99 export VERSION
100 export FCST_TIME
101 ${ECHO} "MODEL=${MODEL}"
102 ${ECHO} "VERSION=${VERSION}"
103 ${ECHO} "FCST_TIME=${FCST_TIME}"
104 
105 # Loop through the domain list
106 for RES in ${RES_LIST}; do
107 
108  export RES
109  ${ECHO} "RES=${RES}"
110 
111  for GRID_VX in ${GRID_VX_LIST}; do
112  GRID_VX_NUM=`${ECHO} ${GRID_VX} | cut -c2-`
113  typeset -Z3 GRID_VX_NUM
114  GRID_VX_FORMAT="G${GRID_VX_NUM}"
115 
116  export GRID_VX
117  export GRID_VX_FORMAT
118 
119  # Specify mask directory structure
120  MASKS=${MET_CONFIG}/masks
121  export MASKS
122 
123  # Specify the MET Grid-Stat configuration file(s) to be used
124  GS_CONFIG_LIST="${MET_CONFIG}/GridStatConfig_AC_REGRID"
125 
126  # Compute the verification date
127  VDATE=`${UTIL_EXEC}/ndate +${FCST_TIME} ${START_TIME}`
128  VYYYYMMDD=`${ECHO} ${VDATE} | ${CUT} -c1-8`
129  VMMDD=`${ECHO} ${VDATE} | ${CUT} -c5-8`
130  VHH=`${ECHO} ${VDATE} | ${CUT} -c9-10`
131  ${ECHO} 'valid time for ' ${FCST_TIME} 'h forecast = ' ${VDATE}
132 
133  # Get the forecast to verify
134  FCST_FILE=${ROTDIR}/pgrbq${FCST_TIME}.gfs.${START_TIME}.grib2
135  ${ECHO} "FCST_FILE: ${FCST_FILE}"
136 
137  if [ ! -e ${FCST_FILE} ]; then
138  ${ECHO} "ERROR: Could not find UPP output file: ${FCST_FILE}"
139  exit 1
140  fi
141 
142  # Get obs/analysis file to verify with
143  ANL_OBS_FILE=`${LS} ${ANL_OBS_DIR}/${VYYYYMMDD}${VHH}/gfs.t${VHH}z.pgrb2.0p25.anl | head -1`
144  ${ECHO} "ANL_OBS_FILE: ${ANL_OBS_FILE}"
145 
146  if [ ! -e ${ANL_OBS_FILE} ]; then
147  ${ECHO} "ERROR: Could not find observation file: ${ANL_OBS_FILE}"
148  exit 1
149  fi
150 
151  # Get climo mean file
152  CLIMO_MEAN_FILE=`${LS} ${CLIMO_FILE_DIR}/cmean_1d.1959${VMMDD} | head -1`
153  ${ECHO} "CLIMO_MEAN_FILE: ${CLIMO_MEAN_FILE}"
154 
155  if [ ! -e ${CLIMO_MEAN_FILE} ]; then
156  ${ECHO} "ERROR: Could not find observation file: ${CLIMO_MEAN_FILE}"
157  exit 1
158  fi
159 
160  export CLIMO_MEAN_FILE
161 
162  #######################################################################
163  # Run Grid-Stat
164  #######################################################################
165 
166  for CONFIG_FILE in ${GS_CONFIG_LIST}; do
167 
168  # Make sure the Grid-Stat configuration file exists
169  if [ ! -e ${CONFIG_FILE} ]; then
170  ${ECHO} "ERROR: ${CONFIG_FILE} does not exist!"
171  exit 1
172  fi
173 
174  ${ECHO} "CALLING: ${MET_EXE_ROOT}/grid_stat ${FCST_FILE} ${ANL_OBS_FILE} ${CONFIG_FILE} -outdir . -v 2"
175 
176  ${MET_EXE_ROOT}/grid_stat \
177  ${FCST_FILE} \
178  ${ANL_OBS_FILE} \
179  ${CONFIG_FILE} \
180  -outdir . \
181  -v 2
182 
183  error=$?
184  if [ ${error} -ne 0 ]; then
185  ${ECHO} "ERROR: For ${MODEL}, ${MET_EXE_ROOT}/grid_stat crashed Exit status: ${error}"
186  exit ${error}
187  fi
188 
189  done
190 
191  done # GRID_VX
192 done # RES
193 
194 ##########################################################################
195 
196 ${ECHO} "${SCRIPT} completed at `${DATE}`"
197 
198 exit 0