def parse_in(txt: str) -> (MetarData, Units): """ Parser for the International METAR variant """ units = Units(**IN_UNITS) clean = core.sanitize_report_string(txt) wxresp = {'raw': txt, 'sanitized': clean} wxdata, wxresp['remarks'] = core.get_remarks(clean) wxdata, wxresp['runway_visibility'], _ = core.sanitize_report_list(wxdata) wxdata, wxresp['station'], wxresp['time'] = core.get_station_and_time( wxdata) if 'CAVOK' not in wxdata: wxdata, wxresp['clouds'] = core.get_clouds(wxdata) wxdata, wxresp['wind_direction'], wxresp['wind_speed'], \ wxresp['wind_gust'], wxresp['wind_variable_direction'] = core.get_wind(wxdata, units) wxdata, wxresp['altimeter'] = core.get_altimeter(wxdata, units, 'IN') if 'CAVOK' in wxdata: wxresp['visibility'] = core.make_number('CAVOK') wxresp['clouds'] = [] wxdata.remove('CAVOK') else: wxdata, wxresp['visibility'] = core.get_visibility(wxdata, units) wxresp['other'], wxresp['temperature'], wxresp[ 'dewpoint'] = core.get_temp_and_dew(wxdata) condition = core.get_flight_rules(wxresp['visibility'], core.get_ceiling(wxresp['clouds'])) wxresp['flight_rules'] = FLIGHT_RULES[condition] wxresp['remarks_info'] = remarks.parse(wxresp['remarks']) wxresp['time'] = core.make_timestamp(wxresp['time']) return MetarData(**wxresp), units
def parse_in(txt: str) -> {str: object}: """ Parser for the International METAR variant """ units = copy(IN_UNITS) wxresp = {} txt = core.sanitize_report_string(txt) wxdata, wxresp['Remarks'] = core.get_remarks(txt) wxdata, wxresp['Runway-Vis-List'], _ = core.sanitize_report_list(wxdata) wxdata, wxresp['Station'], wxresp['Time'] = core.get_station_and_time( wxdata) if 'CAVOK' not in wxdata: wxdata, wxresp['Cloud-List'] = core.get_clouds(wxdata) wxdata, units, wxresp['Wind-Direction'], wxresp['Wind-Speed'], \ wxresp['Wind-Gust'], wxresp['Wind-Variable-Dir'] = core.get_wind(wxdata, units) wxdata, units, wxresp['Altimeter'] = core.get_altimeter( wxdata, units, 'IN') if 'CAVOK' in wxdata: wxresp['Visibility'] = '9999' wxresp['Cloud-List'] = [] wxdata.remove('CAVOK') else: wxdata, units, wxresp['Visibility'] = core.get_visibility( wxdata, units) wxresp['Other-List'], wxresp['Temperature'], wxresp[ 'Dewpoint'] = core.get_temp_and_dew(wxdata) wxresp['Units'] = units condition = core.get_flight_rules(wxresp['Visibility'], core.get_ceiling(wxresp['Cloud-List'])) wxresp['Flight-Rules'] = FLIGHT_RULES[condition] wxresp['Remarks-Info'] = core.parse_remarks(wxresp['Remarks']) return wxresp
def parse_na(report: str) -> (MetarData, Units): """ Parser for the North American METAR variant """ units = Units(**NA_UNITS) clean = core.sanitize_report_string(report) wxresp = {'raw': report, 'sanitized': clean} wxdata, wxresp['remarks'] = core.get_remarks(clean) wxdata = core.dedupe(wxdata) wxdata, wxresp['runway_visibility'], _ = core.sanitize_report_list(wxdata) wxdata, wxresp['station'], wxresp['time'] = core.get_station_and_time( wxdata) wxdata, wxresp['clouds'] = core.get_clouds(wxdata) wxdata, wxresp['wind_direction'], wxresp['wind_speed'], \ wxresp['wind_gust'], wxresp['wind_variable_direction'] = core.get_wind(wxdata, units) wxdata, wxresp['altimeter'] = core.get_altimeter(wxdata, units, 'NA') wxdata, wxresp['visibility'] = core.get_visibility(wxdata, units) wxresp['other'], wxresp['temperature'], wxresp[ 'dewpoint'] = core.get_temp_and_dew(wxdata) condition = core.get_flight_rules(wxresp['visibility'], core.get_ceiling(wxresp['clouds'])) wxresp['flight_rules'] = FLIGHT_RULES[condition] wxresp['remarks_info'] = remarks.parse(wxresp['remarks']) wxresp['time'] = core.make_timestamp(wxresp['time']) return MetarData(**wxresp), units
def test_get_flight_rules(self): """ Tests that the proper flight rule is calculated for a set visibility and ceiling Note: Only 'Broken', 'Overcast', and 'Vertical Visibility' are considdered ceilings """ for vis, ceiling, rule in ( (None, None, 'IFR'), ('10', None, 'VFR'), ('P6SM', ['OCV',50], 'VFR'), ('6', ['OVC',20], 'MVFR'), ('6', ['OVC',7], 'IFR'), ('2', ['OVC',20], 'IFR'), ('6', ['OVC',4], 'LIFR'), ('1/2', ['OVC',30], 'LIFR'), ('M1/4', ['OVC',30], 'LIFR'), ): vis = core.make_number(vis) if ceiling: ceiling = structs.Cloud(None, *ceiling) self.assertEqual(static.FLIGHT_RULES[core.get_flight_rules(vis, ceiling)], rule)