예제 #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(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
예제 #3
0
 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)
예제 #4
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
예제 #5
0
def parse_na_line(txt: str, units: Units) -> {str: str}:
    """
    Parser for the North American TAF forcast varient
    """
    retwx = {}
    wxdata = txt.split(' ')
    wxdata, _, retwx['wind_shear'] = core.sanitize_report_list(wxdata)
    wxdata, retwx['type'], retwx['start_time'], retwx['end_time'] = core.get_type_and_times(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['turbulance'] \
        = core.get_taf_alt_ice_turb(wxdata)
    return retwx
예제 #6
0
def parse_na_line(line: str, units: Units) -> {str: str}:
    """
    Parser for the North American TAF forcast varient
    """
    retwx = {}
    wxdata = line.split()
    wxdata, _, retwx['wind_shear'] = core.sanitize_report_list(wxdata)
    wxdata, retwx['type'], retwx['start_time'], retwx['end_time'] = core.get_type_and_times(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['turbulance'] \
        = core.get_taf_alt_ice_turb(wxdata)
    return retwx
예제 #7
0
def parse_na_line(txt: str, units: {str: str}) -> ({str: object}, {str: str}):
    """
    Parser for the North American TAF forcast varient
    """
    retwx = {}
    wxdata = txt.split(' ')
    wxdata, _, retwx['Wind-Shear'] = core.sanitize_report_list(
        wxdata, remove_clr_and_skc=False)
    wxdata, retwx['Type'], retwx['Start-Time'], retwx[
        'End-Time'] = core.get_type_and_times(wxdata)
    wxdata, units, retwx['Wind-Direction'], retwx['Wind-Speed'],\
        retwx['Wind-Gust'], _ = core.get_wind(wxdata, units)
    wxdata, units, retwx['Visibility'] = core.get_visibility(wxdata, units)
    wxdata, retwx['Cloud-List'] = core.get_clouds(wxdata)
    retwx['Other-List'], retwx['Altimeter'], retwx['Icing-List'], retwx['Turb-List'] \
        = core.get_taf_alt_ice_turb(wxdata)
    return retwx, units
예제 #8
0
def parse_in_line(txt: str, units: Units) -> {str: str}:
    """
    Parser for the International TAF forcast varient
    """
    retwx = {}
    wxdata = txt.split(' ')
    wxdata, _, retwx['wind_shear'] = core.sanitize_report_list(wxdata)
    wxdata, retwx['type'], retwx['start_time'], retwx['end_time'] = core.get_type_and_times(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['turbulance'] \
        = core.get_taf_alt_ice_turb(wxdata)
    return retwx
예제 #9
0
def parse_in_line(line: str, units: Units) -> {str: str}:
    """
    Parser for the International TAF forcast varient
    """
    retwx = {}
    wxdata = line.split()
    wxdata, _, retwx['wind_shear'] = core.sanitize_report_list(wxdata)
    wxdata, retwx['type'], retwx['start_time'], retwx['end_time'] = core.get_type_and_times(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['turbulance'] \
        = core.get_taf_alt_ice_turb(wxdata)
    return retwx
예제 #10
0
 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)