diff --git a/internal/tests/pytests/wrappers/command_builder/test_command_builder.py b/internal/tests/pytests/wrappers/command_builder/test_command_builder.py index 89fd7fef36..396c0006d4 100644 --- a/internal/tests/pytests/wrappers/command_builder/test_command_builder.py +++ b/internal/tests/pytests/wrappers/command_builder/test_command_builder.py @@ -1199,16 +1199,14 @@ def test_errors_and_defaults(metplus_config): assert actual == False assert _in_last_err('Could not generate command', cb.logger) - # test python embedding error + # test python embedding check with mock.patch.object(cb_wrapper, 'is_python_script', return_value=True): actual = cb.check_for_python_embedding('FCST',{'fcst_name':'pyEmbed'}) - assert actual == None - assert _in_last_err('must be set to a valid Python Embedding type', cb.logger) + assert actual == 'python_embedding' - cb.c_dict['FCST_INPUT_DATATYPE'] = 'PYTHON_XARRAY' - with mock.patch.object(cb_wrapper, 'is_python_script', return_value=True): + with mock.patch.object(cb_wrapper, 'is_python_script', return_value=False): actual = cb.check_for_python_embedding('FCST',{'fcst_name':'pyEmbed'}) - assert actual == 'python_embedding' + assert actual == 'pyEmbed' # test field_info not set cb.c_dict['CURRENT_VAR_INFO'] = None diff --git a/internal/tests/pytests/wrappers/series_analysis/test_series_analysis.py b/internal/tests/pytests/wrappers/series_analysis/test_series_analysis.py index 594fc6d2c4..0535ffc531 100644 --- a/internal/tests/pytests/wrappers/series_analysis/test_series_analysis.py +++ b/internal/tests/pytests/wrappers/series_analysis/test_series_analysis.py @@ -1027,16 +1027,6 @@ def test_run_once_per_lead(metplus_config): assert actual is False -@pytest.mark.wrapper_a -def test_get_fcst_obs_not_embedding(metplus_config): - config = metplus_config - set_minimum_config_settings(config) - wrapper = SeriesAnalysisWrapper(config) - with mock.patch.object(wrapper, "_check_python_embedding", return_value=False): - actual = wrapper._get_fcst_and_obs_path({}, '*', None) - assert actual == (None, None) - - @pytest.mark.parametrize( 'lead_group, use_both, mock_exists, expected', [ (('Group1', [0, 21600]), True, True, ('both_path', 'both_path')), diff --git a/metplus/wrappers/command_builder.py b/metplus/wrappers/command_builder.py index 995d62259b..d9371bd571 100755 --- a/metplus/wrappers/command_builder.py +++ b/metplus/wrappers/command_builder.py @@ -1105,38 +1105,25 @@ def set_current_field_config(self, field_info=None): self.config.set('config', current_var, field_info[name] if name in field_info else '') - def check_for_python_embedding(self, input_type, var_info): - """!Check if field name of given input type is a python script. If it is not, return the field name. - If it is, check if the input datatype is a valid Python Embedding string, set the c_dict item - that sets the file_type in the MET config file accordingly, and set the output string to 'python_embedding. - Used to set up Python Embedding input for MET tools that support multiple input files, such as MTD, EnsembleStat, - and SeriesAnalysis. - Args: - @param input_type type of field input, i.e. FCST, OBS, ENS, POINT_OBS, GRID_OBS, or BOTH - @param var_info dictionary item containing field information for the current *_VAR_* configs being handled - @returns field name if not a python script, 'python_embedding' if it is, and None if configuration is invalid""" + @staticmethod + def check_for_python_embedding(input_type, var_info): + """!Check if field name of given input type is a python script. + If it is not, return the field name. + If it is, return 'python_embedding. + + @param input_type type of field input, e.g. FCST, OBS, ENS, POINT_OBS, + GRID_OBS, or BOTH + @param var_info dictionary item containing field information for the + current *_VAR_* configs being handled + @returns field name if not a python script, 'python_embedding' if it is + """ var_input_type = input_type.lower() if input_type != 'BOTH' else 'fcst' - # reset file type to empty string to handle if python embedding is used for one field but not for the next - self.c_dict[f'{input_type}_FILE_TYPE'] = '' - if not is_python_script(var_info[f"{var_input_type}_name"]): # if not a python script, return var name return var_info[f"{var_input_type}_name"] - # if it is a python script, set file extension to show that and make sure *_INPUT_DATATYPE is a valid PYTHON_* string - file_ext = 'python_embedding' - data_type = self.c_dict.get(f'{input_type}_INPUT_DATATYPE', '') - if data_type not in PYTHON_EMBEDDING_TYPES: - self.log_error(f"{input_type}_{self.app_name.upper()}_INPUT_DATATYPE ({data_type}) must be set to a valid Python Embedding type " - f"if supplying a Python script as the {input_type}_VAR_NAME. Valid options: " - f"{','.join(PYTHON_EMBEDDING_TYPES)}") - return None - - # set file type string to be set in MET config file to specify Python Embedding is being used for this dataset - file_type = f"file_type = {data_type};" - self.c_dict[f'{input_type}_FILE_TYPE'] = file_type - self.env_var_dict[f'METPLUS_{input_type}_FILE_TYPE'] = file_type - return file_ext + # if it is a python script, return string used for file list file name + return 'python_embedding' def get_field_info(self, d_type='', v_name='', v_level='', v_thresh=None, v_extra='', add_curly_braces=True): diff --git a/metplus/wrappers/compare_gridded_wrapper.py b/metplus/wrappers/compare_gridded_wrapper.py index 41adf3ddc7..a379181bef 100755 --- a/metplus/wrappers/compare_gridded_wrapper.py +++ b/metplus/wrappers/compare_gridded_wrapper.py @@ -217,12 +217,6 @@ def get_all_field_info(self, var_list, data_type): name = var_info[f'{type_lower}_name'] extra = var_info[f'{type_lower}_extra'] - # check if python embedding is used and set up correctly - # set env var for file type if it is used - py_embed_ok = self.check_for_python_embedding(data_type, var_info) - if not py_embed_ok: - return '' - next_field = self.get_field_info(v_level=level, v_thresh=thresh, v_name=name, diff --git a/metplus/wrappers/ensemble_stat_wrapper.py b/metplus/wrappers/ensemble_stat_wrapper.py index be9fac1f0b..2fc6c4299f 100755 --- a/metplus/wrappers/ensemble_stat_wrapper.py +++ b/metplus/wrappers/ensemble_stat_wrapper.py @@ -132,13 +132,11 @@ def create_c_dict(self): ) c_dict['OBS_POINT_INPUT_DATATYPE'] = ( - self.config.getraw('config', - 'OBS_ENSEMBLE_STAT_INPUT_POINT_DATATYPE') + self.config.getraw('config', 'OBS_ENSEMBLE_STAT_INPUT_POINT_DATATYPE') ) c_dict['OBS_GRID_INPUT_DATATYPE'] = ( - self.config.getraw('config', - 'OBS_ENSEMBLE_STAT_INPUT_GRID_DATATYPE') + self.config.getraw('config', 'OBS_ENSEMBLE_STAT_INPUT_GRID_DATATYPE') ) # check if more than 1 obs datatype is set to python embedding, diff --git a/metplus/wrappers/series_analysis_wrapper.py b/metplus/wrappers/series_analysis_wrapper.py index 3341244e1b..d656efc829 100755 --- a/metplus/wrappers/series_analysis_wrapper.py +++ b/metplus/wrappers/series_analysis_wrapper.py @@ -640,9 +640,6 @@ def _get_fcst_and_obs_path(self, time_info, storm_id, lead_group): key will match the format "NoLabel_" and if no lead groups are defined, the dictionary should be replaced with None """ - if not self._check_python_embedding(): - return None, None - time_info['storm_id'] = storm_id # get label and lead list if grouping by forecast leads @@ -699,24 +696,6 @@ def _get_fcst_and_obs_path(self, time_info, storm_id, lead_group): obs_path = list_file_dict[obs_key] return fcst_path, obs_path - def _check_python_embedding(self): - """! Check if any of the field names contain a Python embedding script. - See CommandBuilder.check_for_python_embedding for more info. - - @returns False if something is not configured correctly or True - """ - for var_info in self.c_dict['VAR_LIST']: - if self.c_dict['USING_BOTH']: - if not self.check_for_python_embedding('BOTH', var_info): - return False - else: - if not self.check_for_python_embedding('FCST', var_info): - return False - if not self.check_for_python_embedding('OBS', var_info): - return False - - return True - def get_output_dir(self, time_info, storm_id, label): """! Determine directory that will contain output data from the OUTPUT_DIR and OUTPUT_TEMPLATE. This will include any