def test_taf_line(self): """ Tests converting TAF line data into into a single spoken string """ units = structs.Units(**static.NA_UNITS) line = { 'altimeter': core.make_number('2992'), 'clouds': [core.make_cloud('BKN015CB')], 'end_time': core.make_timestamp('1206'), 'icing': ['611005'], 'other': ['+RA'], 'start_time': core.make_timestamp('1202'), 'turbulance': ['540553'], 'type': 'FROM', 'visibility': core.make_number('3'), 'wind_direction': core.make_number('360'), 'wind_gust': core.make_number('20'), 'wind_shear': 'WS020/07040KT', 'wind_speed': core.make_number('12'), } line.update({k: None for k in ('flight_rules', 'probability', 'raw', 'sanitized')}) line = structs.TafLineData(**line) spoken = ('From 2 to 6 zulu, Winds three six zero at 12kt gusting to 20kt. ' 'Wind shear 2000inHg from zero seven zero at 40kt. Visibility three miles. ' 'Altimeter two nine point nine two. Heavy Rain. ' 'Broken layer at 1500ft (Cumulonimbus). ' 'Occasional moderate turbulence in clouds from 5500ft to 8500ft. ' 'Light icing from 10000ft to 15000ft') ret = speech.taf_line(line, units) self.assertIsInstance(ret, str) self.assertEqual(ret, spoken)
def test_metar(self): """ Tests converting METAR data into into a single spoken string """ units = structs.Units(**static.NA_UNITS) data = { 'altimeter': core.make_number('2992'), 'clouds': [core.make_cloud('BKN015CB')], 'dewpoint': core.make_number('M01'), 'other': ['+RA'], 'temperature': core.make_number('03'), 'visibility': core.make_number('3'), 'wind_direction': core.make_number('360'), 'wind_gust': core.make_number('20'), 'wind_speed': core.make_number('12'), 'wind_variable_direction': [ core.make_number('340'), core.make_number('020', speak='020') ] } data.update({k: None for k in ( 'raw', 'remarks', 'station', 'time', 'flight_rules', 'remarks_info', 'runway_visibility', 'sanitized' )}) data = structs.MetarData(**data) spoken = ('Winds three six zero (variable three four zero to zero two zero) ' 'at 12kt gusting to 20kt. Visibility three miles. ' 'Temperature three degrees Celsius. Dew point minus one degree Celsius. ' 'Altimeter two nine point nine two. Heavy Rain. ' 'Broken layer at 1500ft (Cumulonimbus)') ret = speech.metar(data, units) self.assertIsInstance(ret, str) self.assertEqual(ret, spoken)
def test_clouds(self): """ Tests translating each cloud into a single string """ self.assertEqual(translate.clouds(None), '') self.assertEqual(translate.clouds([]), 'Sky clear') for clouds, translation in ( (['BKN','FEW020'], 'Few clouds at 2000ft'), (['OVC030','SCT100'], 'Overcast layer at 3000ft, Scattered clouds at 10000ft'), (['BKN015CB'], 'Broken layer at 1500ft (Cumulonimbus)'), ): clouds = [core.make_cloud(cloud) for cloud in clouds] self.assertEqual(translate.clouds(clouds), translation + ' - Reported AGL')
def test_taf(self): """ Tests end-to-end TAF translation """ units = structs.Units(**static.NA_UNITS) line_data = { 'altimeter': core.make_number('2992'), 'clouds': [core.make_cloud('BKN015CB')], 'icing': ['611005'], 'other': ['+RA'], 'turbulance': ['540553'], 'visibility': core.make_number('3'), 'wind_direction': core.make_number('360'), 'wind_gust': core.make_number('20'), 'wind_shear': 'WS020/07040KT', 'wind_speed': core.make_number('12') } line_data.update({ k: '' for k in ('raw', 'end_time', 'start_time', 'probability', 'type', 'flight_rules', 'sanitized') }) data = {'max_temp': 'TX20/1518Z', 'min_temp': 'TN00/00', 'remarks': ''} data.update({ k: '' for k in ('raw', 'station', 'time', 'start_time', 'end_time') }) data = structs.TafData(forecast=[structs.TafLineData(**line_data)], **data) line_trans = structs.TafLineTrans( altimeter='29.92 inHg (1013 hPa)', clouds='Broken layer at 1500ft (Cumulonimbus) - Reported AGL', icing='Light icing from 10000ft to 15000ft', other='Heavy Rain', turbulance= 'Occasional moderate turbulence in clouds from 5500ft to 8500ft', visibility='3sm (4.8km)', wind_shear='Wind shear 2000ft from 070 at 40kt', wind='N-360 at 12kt gusting to 20kt') trans = structs.TafTrans( forecast=[line_trans], max_temp='Maximum temperature of 20°C (68°F) at 15-18:00Z', min_temp='Minimum temperature of 0°C (32°F) at 00:00Z', remarks={}) translated = translate.taf(data, units) self.assertIsInstance(translated, structs.TafTrans) for line in translated.forecast: self.assertIsInstance(line, structs.TafLineTrans) self.assertEqual(translated, trans)
def test_taf(self): """ Tests end-to-end TAF translation """ units = structs.Units(**static.NA_UNITS) line_data = { 'altimeter': core.make_number('2992'), 'clouds': [core.make_cloud('BKN015CB')], 'icing': ['611005'], 'other': ['+RA'], 'turbulance': ['540553'], 'visibility': core.make_number('3'), 'wind_direction': core.make_number('360'), 'wind_gust': core.make_number('20'), 'wind_shear': 'WS020/07040KT', 'wind_speed': core.make_number('12') } line_data.update({k: '' for k in ( 'raw', 'end_time', 'start_time', 'probability', 'type', 'flight_rules', 'sanitized' )}) data = { 'max_temp': 'TX20/1518Z', 'min_temp': 'TN00/00', 'remarks': '' } data.update({k: '' for k in ('raw', 'station', 'time', 'start_time', 'end_time')}) data = structs.TafData(forecast=[structs.TafLineData(**line_data)], **data) line_trans = structs.TafLineTrans( altimeter='29.92 inHg (1013 hPa)', clouds='Broken layer at 1500ft (Cumulonimbus) - Reported AGL', icing='Light icing from 10000ft to 15000ft', other='Heavy Rain', turbulance='Occasional moderate turbulence in clouds from 5500ft to 8500ft', visibility='3sm (4.8km)', wind_shear='Wind shear 2000ft from 070 at 40kt', wind='N-360 at 12kt gusting to 20kt' ) trans = structs.TafTrans( forecast=[line_trans], max_temp='Maximum temperature of 20°C (68°F) at 15-18:00Z', min_temp='Minimum temperature of 0°C (32°F) at 00:00Z', remarks={} ) translated = translate.taf(data, units) self.assertIsInstance(translated, structs.TafTrans) for line in translated.forecast: self.assertIsInstance(line, structs.TafLineTrans) self.assertEqual(translated, trans)
def test_clouds(self): """ Tests translating each cloud into a single string """ self.assertEqual(translate.clouds(None), '') self.assertEqual(translate.clouds([]), 'Sky clear') for clouds, translation in ( (['BKN', 'FEW020'], 'Few clouds at 2000ft'), (['OVC030', 'SCT100'], 'Overcast layer at 3000ft, Scattered clouds at 10000ft'), (['BKN015CB'], 'Broken layer at 1500ft (Cumulonimbus)'), ): clouds = [core.make_cloud(cloud) for cloud in clouds] self.assertEqual(translate.clouds(clouds), translation + ' - Reported AGL')
def test_metar(self): """ Tests end-to-end METAR translation """ units = structs.Units(**static.NA_UNITS) data = { 'altimeter': core.make_number('2992'), 'clouds': [core.make_cloud('BKN015CB')], 'dewpoint': core.make_number('M01'), 'other': ['+RA'], 'temperature': core.make_number('03'), 'visibility': core.make_number('3'), 'wind_direction': core.make_number('360'), 'wind_gust': core.make_number('20'), 'wind_speed': core.make_number('12'), 'wind_variable_direction': [core.make_number('340'), core.make_number('020')] } data.update({ k: '' for k in ('raw', 'remarks', 'station', 'time', 'flight_rules', 'remarks_info', 'runway_visibility', 'sanitized') }) data = structs.MetarData(**data) trans = structs.MetarTrans( altimeter='29.92 inHg (1013 hPa)', clouds='Broken layer at 1500ft (Cumulonimbus) - Reported AGL', dewpoint='-1°C (30°F)', other='Heavy Rain', remarks={}, temperature='3°C (37°F)', visibility='3sm (4.8km)', wind='N-360 (variable 340 to 020) at 12kt gusting to 20kt') translated = translate.metar(data, units) self.assertIsInstance(translated, structs.MetarTrans) self.assertEqual(translated, trans)
def test_make_cloud(self): """ Tests helper function which returns a Cloud dataclass """ for cloud, out in ( ('SCT060', ['SCT', 60, None]), ('FEWO03', ['FEW', 3, None]), ('BKNC015', ['BKN', 15, 'C']), ('OVC120TS', ['OVC', 120, 'TS']), ('VV002', ['VV', 2, None]), ('SCT', ['SCT', None, None]), ('FEW027///', ['FEW', 27, None]), ('FEW//////', ['FEW', None, None]), ('FEW///TS', ['FEW', None, 'TS']), ): ret_cloud = core.make_cloud(cloud) self.assertIsInstance(ret_cloud, structs.Cloud) self.assertEqual(ret_cloud.repr, cloud) for i, key in enumerate(('type', 'altitude', 'modifier')): self.assertEqual(getattr(ret_cloud, key), out[i])
def test_make_cloud(self): """ Tests helper function which returns a Cloud dataclass """ for cloud, out in ( ('SCT060', ['SCT', 60, None]), ('FEWO03', ['FEW', 3, None]), ('BKNC015', ['BKN', 15, 'C']), ('OVC120TS', ['OVC', 120, 'TS']), ('VV002', ['VV', 2, None]), ('SCT', ['SCT', None, None]), ('FEW027///', ['FEW', 27, None]), ('FEW//////', ['FEW', None, None]), ('FEW///TS', ['FEW', None, 'TS']), ): ret_cloud = core.make_cloud(cloud) self.assertIsInstance(ret_cloud, structs.Cloud) self.assertEqual(ret_cloud.repr, cloud) for i, key in enumerate(('type', 'altitude', 'modifier')): self.assertEqual(getattr(ret_cloud, key), out[i])
def test_shared(self): """ Tests availibility of shared values between the METAR and TAF translations """ units = structs.Units(**static.NA_UNITS) data = structs.SharedData( altimeter=core.make_number('2992'), clouds=[core.make_cloud('OVC060')], flight_rules='', other=['RA'], sanitized='', visibility=core.make_number('10'), wind_direction=core.make_number('0'), wind_gust=core.make_number('0'), wind_speed=core.make_number('0') ) trans = translate.shared(data, units) self.assertIsInstance(trans, dict) for key in ('altimeter', 'clouds', 'other', 'visibility'): self.assertIn(key, trans) self.assertTrue(bool(trans[key]))
def test_metar(self): """ Tests end-to-end METAR translation """ units = structs.Units(**static.NA_UNITS) data = { 'altimeter': core.make_number('2992'), 'clouds': [core.make_cloud('BKN015CB')], 'dewpoint': core.make_number('M01'), 'other': ['+RA'], 'temperature': core.make_number('03'), 'visibility': core.make_number('3'), 'wind_direction': core.make_number('360'), 'wind_gust': core.make_number('20'), 'wind_speed': core.make_number('12'), 'wind_variable_direction': [ core.make_number('340'), core.make_number('020') ] } data.update({k: '' for k in ( 'raw', 'remarks', 'station', 'time', 'flight_rules', 'remarks_info', 'runway_visibility', 'sanitized' )}) data = structs.MetarData(**data) trans = structs.MetarTrans( altimeter='29.92 inHg (1013 hPa)', clouds='Broken layer at 1500ft (Cumulonimbus) - Reported AGL', dewpoint='-1°C (30°F)', other='Heavy Rain', remarks={}, temperature='3°C (37°F)', visibility='3sm (4.8km)', wind='N-360 (variable 340 to 020) at 12kt gusting to 20kt' ) translated = translate.metar(data, units) self.assertIsInstance(translated, structs.MetarTrans) self.assertEqual(translated, trans)
def _clouds(item: str) -> [Cloud]: """ Convert cloud element to a list of Clouds """ return [core.make_cloud(cloud) for cloud in item.split()]
def _clouds(item: str) -> [Cloud]: """ Convert cloud element to a list of Clouds """ return [core.make_cloud(cloud) for cloud in item.split()]