def test_parse_var_list_wrapper_specific(): conf = metplus_config() conf.set('config', 'FCST_VAR1_NAME', "ENAME1") conf.set('config', 'FCST_VAR1_LEVELS', "ELEVELS11, ELEVELS12") conf.set('config', 'FCST_VAR2_NAME', "ENAME2") conf.set('config', 'FCST_VAR2_LEVELS', "ELEVELS21, ELEVELS22") conf.set('config', 'FCST_GRID_STAT_VAR1_NAME', "GNAME1") conf.set('config', 'FCST_GRID_STAT_VAR1_LEVELS', "GLEVELS11, GLEVELS12") e_var_list = util.parse_var_list(conf, time_info=None, data_type='FCST', met_tool='ensemble_stat') g_var_list = util.parse_var_list(conf, time_info=None, data_type='FCST', met_tool='grid_stat') assert (len(e_var_list) == 4 and len(g_var_list) == 2 and e_var_list[0]['fcst_name'] == "ENAME1" and e_var_list[1]['fcst_name'] == "ENAME1" and e_var_list[2]['fcst_name'] == "ENAME2" and e_var_list[3]['fcst_name'] == "ENAME2" and e_var_list[0]['fcst_level'] == "ELEVELS11" and e_var_list[1]['fcst_level'] == "ELEVELS12" and e_var_list[2]['fcst_level'] == "ELEVELS21" and e_var_list[3]['fcst_level'] == "ELEVELS22" and g_var_list[0]['fcst_name'] == "GNAME1" and g_var_list[1]['fcst_name'] == "GNAME1" and g_var_list[0]['fcst_level'] == "GLEVELS11" and g_var_list[1]['fcst_level'] == "GLEVELS12")
def test_get_field_info_list(conf_dict, expected_field_info_list): config = metplus_config() logger = logging.getLogger("dummy") data_type = 'OBS' for key, value in conf_dict.items(): config.set('config', key, value) input_dict = { 'valid': datetime.datetime.strptime("201802010000", '%Y%m%d%H%M'), 'lead': 0 } time_info = time_util.ti_calculate(input_dict) var_list = util.parse_var_list(config, time_info, data_type=data_type) rdp = RegridDataPlaneWrapper(config, logger) field_info_list = rdp.get_field_info_list(var_list, data_type, time_info) print(f"FIELD INFO LIST: {field_info_list}") print(f"EXPECTED FIELD INFO LIST: {expected_field_info_list}") is_good = True if len(field_info_list) != len(expected_field_info_list): assert (False) for actual_field, expected_field in zip(field_info_list, expected_field_info_list): for key, value in expected_field.items(): if actual_field[key] != value: print(f"{actual_field[key]} not equal to {value}") is_good = False
def test_parse_var_list_fcst_and_obs(): conf = metplus_config() conf.set('config', 'FCST_VAR1_NAME', "FNAME1") conf.set('config', 'FCST_VAR1_LEVELS', "FLEVELS11, FLEVELS12") conf.set('config', 'FCST_VAR2_NAME', "FNAME2") conf.set('config', 'FCST_VAR2_LEVELS', "FLEVELS21, FLEVELS22") conf.set('config', 'OBS_VAR1_NAME', "ONAME1") conf.set('config', 'OBS_VAR1_LEVELS', "OLEVELS11, OLEVELS12") conf.set('config', 'OBS_VAR2_NAME', "ONAME2") conf.set('config', 'OBS_VAR2_LEVELS', "OLEVELS21, OLEVELS22") # this should not occur because FCST and OBS variables are found if not util.validate_configuration_variables(conf, force_check=True)[1]: assert (False) var_list = util.parse_var_list(conf) assert(var_list[0]['fcst_name'] == "FNAME1" and \ var_list[0]['obs_name'] == "ONAME1" and \ var_list[1]['fcst_name'] == "FNAME1" and \ var_list[1]['obs_name'] == "ONAME1" and \ var_list[2]['fcst_name'] == "FNAME2" and \ var_list[2]['obs_name'] == "ONAME2" and \ var_list[3]['fcst_name'] == "FNAME2" and \ var_list[3]['obs_name'] == "ONAME2" and \ var_list[0]['fcst_level'] == "FLEVELS11" and \ var_list[0]['obs_level'] == "OLEVELS11" and \ var_list[1]['fcst_level'] == "FLEVELS12" and \ var_list[1]['obs_level'] == "OLEVELS12" and \ var_list[2]['fcst_level'] == "FLEVELS21" and \ var_list[2]['obs_level'] == "OLEVELS21" and \ var_list[3]['fcst_level'] == "FLEVELS22" and \ var_list[3]['obs_level'] == "OLEVELS22")
def test_parse_var_list_obs(data_type, list_created): conf = metplus_config() conf.set('config', 'OBS_VAR1_NAME', "NAME1") conf.set('config', 'OBS_VAR1_LEVELS', "LEVELS11, LEVELS12") conf.set('config', 'OBS_VAR2_NAME', "NAME2") conf.set('config', 'OBS_VAR2_LEVELS', "LEVELS21, LEVELS22") # this should not occur because FCST variables are missing if util.validate_configuration_variables(conf, force_check=True)[1]: assert (False) var_list = util.parse_var_list(conf, time_info=None, data_type=data_type) # list will be created if requesting just OBS, but it should not be created if # nothing was requested because FCST values are missing if list_created: assert(var_list[0]['obs_name'] == "NAME1" and \ var_list[1]['obs_name'] == "NAME1" and \ var_list[2]['obs_name'] == "NAME2" and \ var_list[3]['obs_name'] == "NAME2" and \ var_list[0]['obs_level'] == "LEVELS11" and \ var_list[1]['obs_level'] == "LEVELS12" and \ var_list[2]['obs_level'] == "LEVELS21" and \ var_list[3]['obs_level'] == "LEVELS22") else: assert (not var_list)
def test_parse_var_list_fcst_and_obs_alternate(): conf = metplus_config() conf.set('config', 'FCST_VAR1_NAME', "FNAME1") conf.set('config', 'FCST_VAR1_LEVELS', "FLEVELS11, FLEVELS12") conf.set('config', 'OBS_VAR2_NAME', "ONAME2") conf.set('config', 'OBS_VAR2_LEVELS', "OLEVELS21, OLEVELS22") # configuration is invalid and parse var list should not give any results assert ( not util.validate_configuration_variables(conf, force_check=True)[1] and not util.parse_var_list(conf))
def test_parse_var_list_fcst_only_options(data_type, list_len): conf = metplus_config() conf.set('config', 'FCST_VAR1_NAME', "NAME1") conf.set('config', 'FCST_VAR1_LEVELS', "LEVELS11, LEVELS12") conf.set('config', 'FCST_VAR1_THRESH', ">1, >2") conf.set('config', 'OBS_VAR1_OPTIONS', "OOPTIONS11") # this should not occur because OBS variables are missing if util.validate_configuration_variables(conf, force_check=True)[1]: assert (False) var_list = util.parse_var_list(conf, time_info=None, data_type=data_type) assert (len(var_list) == list_len)
def test_parse_var_list_fcst_and_obs_and_both(data_type, list_len, name_levels): conf = metplus_config() conf.set('config', 'OBS_VAR1_NAME', "ONAME1") conf.set('config', 'OBS_VAR1_LEVELS', "OLEVELS11, OLEVELS12") conf.set('config', 'FCST_VAR2_NAME', "FNAME2") conf.set('config', 'FCST_VAR2_LEVELS', "FLEVELS21, FLEVELS22") conf.set('config', 'FCST_VAR3_NAME', "FNAME3") conf.set('config', 'FCST_VAR3_LEVELS', "FLEVELS31, FLEVELS32") conf.set('config', 'OBS_VAR3_NAME', "ONAME3") conf.set('config', 'OBS_VAR3_LEVELS', "OLEVELS31, OLEVELS32") # configuration is invalid and parse var list should not give any results if util.validate_configuration_variables(conf, force_check=True)[1]: assert (False) var_list = util.parse_var_list(conf, time_info=None, data_type=data_type) if len(var_list) != list_len: assert (False) if data_type is None: assert (len(var_list) == 0) if name_levels is not None: dt_lower = data_type.lower() expected = [] for name_level in name_levels: name, level = name_level.split(':') expected.append({ f'{dt_lower}_name': name, f'{dt_lower}_level': level }) for expect, reality in zip(expected, var_list): if expect[f'{dt_lower}_name'] != reality[f'{dt_lower}_name']: assert (False) if expect[f'{dt_lower}_level'] != reality[f'{dt_lower}_level']: assert (False) assert (True)
def test_parse_var_list_both(data_type, list_created): conf = metplus_config() conf.set('config', 'BOTH_VAR1_NAME', "NAME1") conf.set('config', 'BOTH_VAR1_LEVELS', "LEVELS11, LEVELS12") conf.set('config', 'BOTH_VAR2_NAME', "NAME2") conf.set('config', 'BOTH_VAR2_LEVELS', "LEVELS21, LEVELS22") # this should not occur because BOTH variables are used if not util.validate_configuration_variables(conf, force_check=True)[1]: assert (False) var_list = util.parse_var_list(conf, time_info=None, data_type=data_type) for list_to_check in list_created.split(':'): if not var_list[0][f'{list_to_check}_name'] == "NAME1" or \ not var_list[1][f'{list_to_check}_name'] == "NAME1" or \ not var_list[2][f'{list_to_check}_name'] == "NAME2" or \ not var_list[3][f'{list_to_check}_name'] == "NAME2" or \ not var_list[0][f'{list_to_check}_level'] == "LEVELS11" or \ not var_list[1][f'{list_to_check}_level'] == "LEVELS12" or \ not var_list[2][f'{list_to_check}_level'] == "LEVELS21" or \ not var_list[3][f'{list_to_check}_level'] == "LEVELS22": assert (False)