예제 #1
0
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
예제 #2
0
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
예제 #3
0
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
예제 #4
0
 def test_parse(self):
     """
     Tests generating RemarksData from a remarks string
     """
     for rmk, data in (
         ("", (None, None)),
         ("T09870123", ("12.3", "98.7")),
         ("RMK AO2 SLP141 T02670189 $", ("18.9", "26.7")),
     ):
         data = [_core.make_number(d) for d in data]
         self.assertEqual(remarks.parse(rmk), structs.RemarksData(*data))
예제 #5
0
 def test_parse(self):
     """
     Tests generating RemarksData from a remarks string
     """
     for rmk, data in (
         ('', (None, None)),
         ('T09870123', ('12.3', '98.7')),
         ('RMK AO2 SLP141 T02670189 $', ('18.9', '26.7')),
     ):
         data = [core.make_number(d) for d in data]
         self.assertEqual(remarks.parse(rmk), structs.RemarksData(*data))
 def test_parse(self):
     """
     Tests generating RemarksData from a remarks string
     """
     for rmk, data in (
         ('', (None, None)),
         ('T09870123', ('12.3', '98.7')),
         ('RMK AO2 SLP141 T02670189 $', ('18.9', '26.7')),
     ):
         data = [core.make_number(d) for d in data]
         self.assertEqual(remarks.parse(rmk), structs.RemarksData(*data))