Skip to content

Commit

Permalink
per #1569, added support for setting optional -ens_mean path, refacto…
Browse files Browse the repository at this point in the history
…red logic to be consistent with other wrappers and remove unnecessary extra class variables
  • Loading branch information
georgemccabe committed Nov 16, 2022
1 parent 90d7c35 commit fb28694
Showing 1 changed file with 29 additions and 43 deletions.
72 changes: 29 additions & 43 deletions metplus/wrappers/ensemble_stat_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ def create_c_dict(self):
self.log_error("Must set FCST_ENSEMBLE_STAT_INPUT_TEMPLATE or "
"FCST_ENSEMBLE_STAT_INPUT_FILE_LIST")

# optional -ens_mean argument path
c_dict['ENS_MEAN_INPUT_DIR'] = (
self.config.getdir('ENSEMBLE_STAT_ENS_MEAN_INPUT_DIR', ''))

c_dict['ENS_MEAN_INPUT_TEMPLATE'] = (
self.config.getraw('config',
'ENSEMBLE_STAT_ENS_MEAN_INPUT_TEMPLATE'))

c_dict['OUTPUT_DIR'] = (
self.config.getdir('ENSEMBLE_STAT_OUTPUT_DIR', '')
)
Expand Down Expand Up @@ -380,35 +388,9 @@ def get_command(self):
@rtype string
@return Returns a MET command with arguments that you can run
"""
cmd = '{} -v {} '.format(self.app_path, self.c_dict['VERBOSITY'])

for args in self.args:
cmd += args + " "

if not self.infiles:
self.log_error(self.app_name+": No input filenames specified")
return None

for infile in self.infiles:
cmd += infile + " "

if self.param != "":
cmd += self.param + " "

for obs_file in self.point_obs_files:
if obs_file.startswith('PYTHON'):
obs_file = f"'{obs_file}'"
cmd += "-point_obs " + obs_file + " "

for obs_file in self.grid_obs_files:
cmd += "-grid_obs " + obs_file + " "

if not self.outdir:
self.log_error(self.app_name+": No output directory specified")
return None

cmd += '-outdir {}'.format(self.outdir)
return cmd
return (f"{self.app_path} -v {self.c_dict['VERBOSITY']}"
f" {' '.join(self.infiles)} {self.param}"
f" {' '.join(self.args)} -outdir {self.outdir}")

def run_at_time_all_fields(self, time_info):
"""! Runs the MET application for a given time and forecast lead combination
Expand All @@ -424,21 +406,32 @@ def run_at_time_all_fields(self, time_info):

# get point observation file if requested
if self.c_dict['OBS_POINT_INPUT_TEMPLATE']:
point_obs_path = self.find_data(time_info, data_type='OBS_POINT',
return_list=True)
if point_obs_path is None:
point_obs_files = self.find_data(time_info, data_type='OBS_POINT',
return_list=True)
if point_obs_files is None:
return

self.point_obs_files.extend(point_obs_path)
for point_obs_path in point_obs_files:
self.args.append(f'-point_obs "{point_obs_path}"')

# get grid observation file if requested
if self.c_dict['OBS_GRID_INPUT_TEMPLATE']:
grid_obs_path = self.find_data(time_info, data_type='OBS_GRID',
grid_obs_files = self.find_data(time_info, data_type='OBS_GRID',
return_list=True)
if grid_obs_files is None:
return

for grid_obs_path in grid_obs_files:
self.args.append(f'-grid_obs "{grid_obs_path}"')

# get ens_mean file if requested
if self.c_dict['ENS_MEAN_INPUT_TEMPLATE']:
ens_mean_path = self.find_data(time_info, data_type='ENS_MEAN',
return_list=True)
if grid_obs_path is None:
if ens_mean_path is None:
return

self.grid_obs_files.extend(grid_obs_path)
self.args.append(f'-ens_mean {ens_mean_path[0]}')

# parse optional var list for FCST and/or OBS fields
var_list = sub_var_list(self.c_dict['VAR_LIST_TEMP'], time_info)
Expand Down Expand Up @@ -511,10 +504,3 @@ def process_fields(self, time_info):

# run the MET command
self.build()

def clear(self):
"""!Unset class variables to prepare for next run time
"""
super().clear()
self.point_obs_files = []
self.grid_obs_files = []

0 comments on commit fb28694

Please sign in to comment.