diff --git a/internal/tests/pytests/wrappers/point_stat/test_point_stat_wrapper.py b/internal/tests/pytests/wrappers/point_stat/test_point_stat_wrapper.py index 9589448f2..e1aa52c6a 100755 --- a/internal/tests/pytests/wrappers/point_stat/test_point_stat_wrapper.py +++ b/internal/tests/pytests/wrappers/point_stat/test_point_stat_wrapper.py @@ -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;'}), @@ -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} ' diff --git a/metplus/wrappers/point_stat_wrapper.py b/metplus/wrappers/point_stat_wrapper.py index cac553cfd..2ff73c601 100755 --- a/metplus/wrappers/point_stat_wrapper.py +++ b/metplus/wrappers/point_stat_wrapper.py @@ -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', '') @@ -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', '') ) @@ -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 diff --git a/metplus/wrappers/runtime_freq_wrapper.py b/metplus/wrappers/runtime_freq_wrapper.py index 03a6f1a31..67f5f3763 100755 --- a/metplus/wrappers/runtime_freq_wrapper.py +++ b/metplus/wrappers/runtime_freq_wrapper.py @@ -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: