def parse_in_line(line: str, units: Units) -> {str: str}: """ Parser for the International TAF forcast variant """ wxdata = _core.dedupe(line.split()) wxdata = _core.sanitize_report_list(wxdata) retwx = {"sanitized": " ".join(wxdata)} ( wxdata, retwx["type"], retwx["start_time"], retwx["end_time"], ) = _core.get_type_and_times(wxdata) wxdata, retwx["wind_shear"] = _core.get_wind_shear(wxdata) ( wxdata, retwx["wind_direction"], retwx["wind_speed"], retwx["wind_gust"], _, ) = _core.get_wind(wxdata, units) if "CAVOK" in wxdata: retwx["visibility"] = _core.make_number("CAVOK") retwx["clouds"] = [] wxdata.pop(wxdata.index("CAVOK")) else: wxdata, retwx["visibility"] = _core.get_visibility(wxdata, units) wxdata, retwx["clouds"] = _core.get_clouds(wxdata) ( retwx["other"], retwx["altimeter"], retwx["icing"], retwx["turbulence"], ) = _core.get_taf_alt_ice_turb(wxdata) return retwx
def parse_na_line(line: str, units: Units) -> {str: str}: """ Parser for the North American TAF forcast variant """ wxdata = _core.dedupe(line.split()) wxdata = _core.sanitize_report_list(wxdata) retwx = {"sanitized": " ".join(wxdata)} ( wxdata, retwx["type"], retwx["start_time"], retwx["end_time"], ) = _core.get_type_and_times(wxdata) wxdata, retwx["wind_shear"] = _core.get_wind_shear(wxdata) ( wxdata, retwx["wind_direction"], retwx["wind_speed"], retwx["wind_gust"], _, ) = _core.get_wind(wxdata, units) wxdata, retwx["visibility"] = _core.get_visibility(wxdata, units) wxdata, retwx["clouds"] = _core.get_clouds(wxdata) ( retwx["other"], retwx["altimeter"], retwx["icing"], retwx["turbulence"], ) = _core.get_taf_alt_ice_turb(wxdata) return retwx
def test_get_wind(self): """ Tests that the wind item gets removed and split into its components """ #Both us knots as the default unit, so just test North American default for wx, unit, *wind, varv in ((['1' ], 'kt', (None, ), (None, ), (None, ), []), (['12345(E)', 'G50', '1'], 'kt', ('123', 123), ('45', 45), ('50', 50), []), (['O1234G56', '1'], 'kt', ('012', 12), ('34', 34), ('56', 56), []), (['36010KTS', 'G20', '300V060', '1'], 'kt', ('360', 360), ('10', 10), ('20', 20), [ ('300', 300), ('060', 60) ]), (['VRB10MPS', '1'], 'm/s', ('VRB', ), ('10', 10), (None, ), []), (['VRB20G30KMH', '1'], 'km/h', ('VRB', ), ('20', 20), ('30', 30), [])): units = structs.Units(**static.NA_UNITS) wx, *winds, var = _core.get_wind(wx, units) self.assertEqual(wx, ['1']) for i in range(len(wind)): self.assert_number(winds[i], *wind[i]) if varv: self.assertIsInstance(varv, list) for i in range(2): self.assert_number(var[i], *varv[i]) self.assertEqual(units.wind_speed, unit)
def test_get_wind(self): """ Tests that the wind item gets removed and split into its components """ # Both us knots as the default unit, so just test North American default for wx, unit, *wind, varv in ( (["1"], "kt", (None, ), (None, ), (None, ), []), (["12345(E)", "G50", "1"], "kt", ("123", 123), ("45", 45), ("50", 50), []), (["O1234G56", "1"], "kt", ("012", 12), ("34", 34), ("56", 56), []), ( ["36010KTS", "G20", "300V060", "1"], "kt", ("360", 360), ("10", 10), ("20", 20), [("300", 300), ("060", 60)], ), (["VRB10MPS", "1"], "m/s", ("VRB", ), ("10", 10), (None, ), []), (["VRB20G30KMH", "1"], "km/h", ("VRB", ), ("20", 20), ("30", 30), []), ): units = structs.Units(**static.NA_UNITS) wx, *winds, var = _core.get_wind(wx, units) self.assertEqual(wx, ["1"]) for i in range(len(wind)): self.assert_number(winds[i], *wind[i]) if varv: self.assertIsInstance(varv, list) for i in range(2): self.assert_number(var[i], *varv[i]) self.assertEqual(units.wind_speed, unit)
def parse_in(report: str) -> (MetarData, Units): """ Parser for the International METAR variant """ units = Units(**IN_UNITS) wxresp = {"raw": report} clean = _core.sanitize_report_string(report) wxdata, wxresp["remarks"] = _core.get_remarks(clean) wxdata = _core.dedupe(wxdata) wxdata = _core.sanitize_report_list(wxdata) wxresp["sanitized"] = " ".join(wxdata + [wxresp["remarks"]]) wxdata, wxresp["station"], wxresp["time"] = _core.get_station_and_time(wxdata) wxdata, wxresp["runway_visibility"] = _core.get_runway_visibility(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