Skip to content

Commit

Permalink
Bugfix #2567 PointStat multiple point observation files (#2582)
Browse files Browse the repository at this point in the history
* per #2567, properly pass multiple point observation files to point_stat using the -point_obs argument

* per #2567, fix bug that caused file window logic to fail

* Revert "per #2567, fix bug that caused file window logic to fail"

This reverts commit 27fe822.

* per #2567, fix bug that caused file window logic to fail
  • Loading branch information
georgemccabe authored May 16, 2024
1 parent 9aa27cb commit a3ce98f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,8 @@ def test_met_dictionary_in_var_options(metplus_config):
({'POINT_STAT_OBS_PERC_VALUE': '50', },
{'METPLUS_OBS_PERC_VALUE': 'obs_perc_value = 50;'}),
({'POINT_STAT_UGRID_CONFIG_FILE': ugrid_config_file, }, {}),
({'OBS_POINT_STAT_INPUT_TEMPLATE': '{valid?fmt=%Y%m%d%H}/obs_file,{valid?fmt=%Y%m%d%H}/obs_file2', }, {}),
({'OBS_POINT_STAT_INPUT_TEMPLATE': '{valid?fmt=%Y%m%d%H}/obs_file,{valid?fmt=%Y%m%d%H}/obs_file2,{valid?fmt=%Y%m%d%H}/obs_file3', }, {}),
({'POINT_STAT_TIME_OFFSET_WARNING': 3},
{'METPLUS_TIME_OFFSET_WARNING': 'time_offset_warning = 3;'}),
Expand Down Expand Up @@ -751,6 +753,13 @@ def test_point_stat_all_fields(metplus_config, config_overrides,
# add extra command line arguments
extra_args = [' '] * len(inits)

if 'OBS_POINT_STAT_INPUT_TEMPLATE' in config_overrides:
for index in range(0, len(inits)):
extra_args[index] += f'-point_obs {obs_dir}/{valids[index]}/obs_file2 '
# if obs_file3 is set, an additional point observation file is added
if 'obs_file3' in config_overrides['OBS_POINT_STAT_INPUT_TEMPLATE']:
extra_args[index] += f'-point_obs {obs_dir}/{valids[index]}/obs_file3 '

if 'POINT_STAT_UGRID_CONFIG_FILE' in config_overrides:
for index in range(0, len(inits)):
extra_args[index] += f'-ugrid_config {ugrid_config_file} '
Expand Down
71 changes: 56 additions & 15 deletions metplus/wrappers/point_stat_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,10 @@ def create_c_dict(self):
c_dict['OFFSETS'] = getlistint(
self.config.getstr('config', 'POINT_STAT_OFFSETS', '0')
)
c_dict['FCST_INPUT_TEMPLATE'] = (
self.config.getraw('config', 'FCST_POINT_STAT_INPUT_TEMPLATE', '')
)

c_dict['OBS_INPUT_TEMPLATE'] = (
self.config.getraw('config', 'OBS_POINT_STAT_INPUT_TEMPLATE', '')
)
self.get_input_templates(c_dict, {
'FCST': {'prefix': 'FCST_POINT_STAT', 'required': True},
'OBS': {'prefix': 'OBS_POINT_STAT', 'required': True},
})

c_dict['FCST_INPUT_DATATYPE'] = (
self.config.getstr('config', 'FCST_POINT_STAT_INPUT_DATATYPE', '')
Expand All @@ -141,14 +138,6 @@ def create_c_dict(self):
self.config.getstr('config', 'OBS_POINT_STAT_INPUT_DATATYPE', '')
)

c_dict['FCST_INPUT_DIR'] = (
self.config.getdir('FCST_POINT_STAT_INPUT_DIR', '')
)

c_dict['OBS_INPUT_DIR'] = (
self.config.getdir('OBS_POINT_STAT_INPUT_DIR', '')
)

c_dict['OUTPUT_DIR'] = (
self.config.getdir('POINT_STAT_OUTPUT_DIR', '')
)
Expand Down Expand Up @@ -322,3 +311,55 @@ def set_command_line_arguments(self, time_info):
obs_valid = do_string_sub(self.c_dict[f'OBS_VALID_{ext}'],
**time_info)
self.args.append(f"-obs_valid_{ext.lower()} {obs_valid}")

def find_input_files(self, time_info):
# get model from first var to compare
model_path = self.find_model(time_info,
mandatory=True,
return_list=True)
if not model_path:
return False

# if there is more than 1 file, create file list file
if len(model_path) > 1:
self.logger.warning('Multiple forecast files found.'
'Using the first one')

self.infiles.append(model_path[0])

# get observation to from first var compare
obs_path, time_info = self.find_obs_offset(time_info,
mandatory=True,
return_list=True)
if obs_path is None:
return False

# add observation files found individually to use -point_obs argument
self.infiles.extend(obs_path)

return True

def get_command(self):
"""! Builds the command to run point_stat
@rtype string
@return Returns a point_stat command with arguments that you can run
"""
fcst_file, *obs_files = self.infiles
if fcst_file.startswith('PYTHON'):
fcst_file = f"'{fcst_file}'"

obs_file = obs_files[0]
if obs_file.startswith('PYTHON'):
obs_file = f"'{obs_file}'"

cmd = (f"{self.app_path} -v {self.c_dict['VERBOSITY']} "
f"{fcst_file} {obs_file} {self.param}")

if len(obs_files) > 1:
cmd += ' -point_obs ' + ' -point_obs '.join(obs_files[1:])

for arg in self.args:
cmd += f' {arg}'

cmd += f' -outdir {self.outdir}'
return cmd
4 changes: 1 addition & 3 deletions metplus/wrappers/runtime_freq_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ def get_input_templates(self, c_dict, input_info=None):
templates = getlist(
self.config.getraw('config', f'{prefix}_INPUT_TEMPLATE')
)
template_list = [os.path.join(input_dir, template)
for template in templates]
template = ','.join(template_list)
template = ','.join(templates)
c_dict[f'{label}_INPUT_TEMPLATE'] = template
if not c_dict[f'{label}_INPUT_TEMPLATE']:
if required:
Expand Down

0 comments on commit a3ce98f

Please sign in to comment.