Skip to content

Commit

Permalink
Minor modifications to Mike's PR changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gsketefian committed Oct 28, 2024
1 parent b84a902 commit f3d21bd
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 30 deletions.
6 changes: 2 additions & 4 deletions scripts/exregional_run_met_genensprod_or_ensemblestat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,13 @@ case "$OBTYPE" in
esac
vx_hr_end="${FCST_LEN_HRS}"

set -x
if [ "${MetplusToolName}" = "GenEnsProd" ]; then
VX_LEADHR_LIST=$( python3 $USHdir/set_leadhrs.py \
--lhr_min="${vx_hr_start}" \
--lhr_max="${vx_hr_end}" \
--lhr_intvl="${vx_intvl}" \
--skip_check_files ) || \
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"

elif [ "${MetplusToolName}" = "EnsembleStat" ]; then
VX_LEADHR_LIST=$( python3 $USHdir/set_leadhrs.py \
Expand All @@ -250,9 +249,8 @@ elif [ "${MetplusToolName}" = "EnsembleStat" ]; then
--fn_template="${OBS_INPUT_FN_TEMPLATE}" \
--num_missing_files_max="${NUM_MISSING_OBS_FILES_MAX}" \
--time_lag="${time_lag%.*}" ) || \
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"
fi
echo "VX_LEADHR_LIST=$VX_LEADHR_LIST"
#
#-----------------------------------------------------------------------
#
Expand Down
3 changes: 1 addition & 2 deletions scripts/exregional_run_met_gridstat_or_pointstat_vx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ case "$OBTYPE" in
esac
vx_hr_end="${FCST_LEN_HRS}"

set -x
VX_LEADHR_LIST=$( python3 $USHdir/set_leadhrs.py \
--date_init="${CDATE}" \
--lhr_min="${vx_hr_start}" \
Expand All @@ -242,7 +241,7 @@ VX_LEADHR_LIST=$( python3 $USHdir/set_leadhrs.py \
--fn_template="${OBS_INPUT_FN_TEMPLATE}" \
--num_missing_files_max="${NUM_MISSING_OBS_FILES_MAX}" \
--time_lag="${time_lag%.*}") || \
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"
#
#-----------------------------------------------------------------------
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ case "$OBTYPE" in
esac
vx_hr_end="${FCST_LEN_HRS}"

set -x
VX_LEADHR_LIST=$( python3 $USHdir/set_leadhrs.py \
--date_init="${CDATE}" \
--lhr_min="${vx_hr_start}" \
Expand All @@ -184,7 +183,7 @@ VX_LEADHR_LIST=$( python3 $USHdir/set_leadhrs.py \
--base_dir="${OBS_INPUT_DIR}" \
--fn_template="${OBS_INPUT_FN_TEMPLATE}" \
--num_missing_files_max="${NUM_MISSING_OBS_FILES_MAX}" ) || \
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"

#
#-----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ case "$OBTYPE" in
esac
vx_hr_end="${FCST_LEN_HRS}"

set -x
VX_LEADHR_LIST=$( python3 $USHdir/set_leadhrs.py \
--date_init="${CDATE}" \
--lhr_min="${vx_hr_start}" \
Expand All @@ -183,7 +182,7 @@ VX_LEADHR_LIST=$( python3 $USHdir/set_leadhrs.py \
--base_dir="${OBS_INPUT_DIR}" \
--fn_template="${OBS_INPUT_FN_TEMPLATE}" \
--num_missing_files_max="${NUM_MISSING_OBS_FILES_MAX}" ) || \
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"

#
#-----------------------------------------------------------------------
Expand Down
13 changes: 4 additions & 9 deletions scripts/exregional_run_met_pb2nc_obs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,12 @@ for yyyymmddhh in ${obs_retrieve_times_crnt_day[@]}; do
# create.
sec_since_ref=$(${DATE_UTIL} --date "${yyyymmdd} ${hh} hours" +%s)
lhr=$(( (sec_since_ref - sec_since_ref_task)/3600 ))
eval_METplus_timestr_tmpl \
init_time="${yyyymmdd_task}00" \
fhr="${lhr}" \
METplus_timestr_tmpl="${OBS_DIR}/${OBS_NDAS_ADPSFCandADPUPA_FN_TEMPLATE}" \
outvarname_evaluated_timestr="fp"

fp=$( python3 $USHdir/run_eval_metplus_timestr_tmpl.py \
fp=$( python3 $USHdir/eval_metplus_timestr_tmpl.py \
--init_time="${yyyymmdd_task}00" \
--fhr="${lhr}" \
--fn_template="${OBS_DIR}/${OBS_NDAS_ADPSFCandADPUPA_FN_TEMPLATE}") || \
print_err_msg_exit "Call to run_eval_metplus_timestr_tmpl.py failed with return code: $?"
--lhr="${lhr}" \
--fn_template="${OBS_DIR}/${OBS_NDAS_FN_TEMPLATES[1]}") || \
print_err_msg_exit "Call to eval_metplus_timestr_tmpl.py failed with return code: $?"

if [[ -f "${fp}" ]]; then
print_info_msg "
Expand Down
5 changes: 2 additions & 3 deletions scripts/exregional_run_met_pcpcombine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,13 @@ fi
#
#-----------------------------------------------------------------------
#
set -x
vx_intvl="$((10#${ACCUM_HH}))"
VX_LEADHR_LIST=$( python3 $USHdir/set_leadhrs.py \
--lhr_min="${vx_intvl}" \
--lhr_max="${FCST_LEN_HRS}" \
--lhr_intvl="${vx_intvl}" \
--skip_check_files ) || \
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"
#
#-----------------------------------------------------------------------
#
Expand Down Expand Up @@ -260,7 +259,7 @@ accumulation ending at lead hour ${hr_end} (relative to ${CDATE})...
--fn_template="${fn_template}" \
--num_missing_files_max="${num_missing_files_max}" \
--time_lag="${time_lag%.*}" || \
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"
print_err_msg_exit "Call to set_leadhrs.py failed with return code: $?"
done

print_info_msg "
Expand Down
12 changes: 6 additions & 6 deletions ush/eval_metplus_timestr_tmpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
raise
from metplus.util import string_template_substitution as sts

def eval_tmpl(init_time, fhr, time_lag, fn_template, verbose=False):
def eval_metplus_timestr_tmpl(init_time, lhr, time_lag, fn_template, verbose=False):
"""
Calls native METplus routine for evaluating filename templates
Args:
init_time (str): Date string for initial time in YYYYMMDD[mmss] format, where minutes and
seconds are optional.
fhr (int): Forecast hour (number of hours since init_time)
lhr (int): Lead hour (number of hours since init_time)
time_lag (int): Hours of time lag for a time-lagged ensemble member
fn_template (str): The METplus filename template for finding the files
verbose (bool): By default this script only outputs the list of forecast hours
Expand All @@ -35,8 +35,8 @@ def eval_tmpl(init_time, fhr, time_lag, fn_template, verbose=False):
else:
raise ValueError(f"Invalid {init_time=}; must be 10, 12, or 14 characters in length")

validdate=initdate + timedelta(hours=fhr)
leadsec=fhr*3600
validdate=initdate + timedelta(hours=lhr)
leadsec=lhr*3600
# Evaluate the METplus timestring template for the current lead hour
if verbose:
print("Resolving METplus template for:")
Expand All @@ -52,12 +52,12 @@ def eval_tmpl(init_time, fhr, time_lag, fn_template, verbose=False):
)
parser.add_argument("-v", "--verbose", help="Verbose output", action="store_true")
parser.add_argument("-i", "--init_time", help="Initial date in YYYYMMDDHH[mmss] format", type=str, default='')
parser.add_argument("-f", "--fhr", help="Forecast hour", type=int, required=True)
parser.add_argument("-f", "--lhr", help="Forecast hour", type=int, required=True)
parser.add_argument("-tl", "--time_lag", help="Hours of time lag for a time-lagged ensemble member", type=int, default=0)
parser.add_argument("-ft", "--fn_template", help="Template for file names to search; see ??? for details on template settings", type=str, default='')

args = parser.parse_args()

filename = eval_tmpl(**vars(args))
filename = eval_metplus_timestr_tmpl(**vars(args))
# If called from command line, we want to print the resolved filename
print(filename)
4 changes: 2 additions & 2 deletions ush/set_leadhrs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
import argparse
import os
from run_eval_metplus_timestr_tmpl import eval_tmpl
from eval_metplus_timestr_tmpl import eval_metplus_timestr_tmpl

def set_leadhrs(date_init, lhr_min, lhr_max, lhr_intvl, base_dir, time_lag, fn_template, num_missing_files_max,
skip_check_files=False, verbose=False):
Expand Down Expand Up @@ -42,7 +42,7 @@ def set_leadhrs(date_init, lhr_min, lhr_max, lhr_intvl, base_dir, time_lag, fn_t
for lhr in lhrs_list:

# Evaluate the METplus timestring template for the current lead hour
fn = eval_tmpl(date_init, lhr, time_lag, fn_template, verbose=False)
fn = eval_metplus_timestr_tmpl(date_init, lhr, time_lag, fn_template, verbose=False)

# Get the full path and check if the file exists
fp = os.path.join(base_dir, fn)
Expand Down

0 comments on commit f3d21bd

Please sign in to comment.