예제 #1
0
    def visibility_group_function():
        """
        Function built for extracting taf._weather_groups[X]["visibility"]
        Attribute "winds" has 2 outputs
        'visibility': None 
        or
        'visibility':{'more': P, 'range': '3', 'unit': 'SM'}
        'visibility':{'range': '10 000', 'more': True, 'unit': 'M'}
        """
        visibility_array = []
        for values in content01:
            taf = pytaf.TAF(values)
            weather_groups = taf._weather_groups
            visibilitytf = weather_groups[0]["visibility"]    
            if not visibilitytf:
                res2 = 10
                visibility_array.append(res2)
            else:
                if weather_groups[0]["visibility"]["unit"] == 'M':

                    if weather_groups[0]["visibility"]["range"] == '10 000':
                        res2 = 10 
                        visibility_array.append(res2)
                    else:    
                        if int(weather_groups[0]["visibility"]["range"])<900:
                            res2 = 0.125 
                        elif 900<=int(weather_groups[0]["visibility"]["range"])<1200:
                            res2 = 0.5 
                        elif 1200<=int(weather_groups[0]["visibility"]["range"])<1600:
                            res2 = 0.75
                        elif 1600<=int(weather_groups[0]["visibility"]["range"])<3200:
                            res2 = 1 
                        elif 3200<=int(weather_groups[0]["visibility"]["range"])<4800:
                            res2 = 2 
                        elif 4800<=int(weather_groups[0]["visibility"]["range"])<6000:
                            res2 = 3 
                        elif 6000<=int(weather_groups[0]["visibility"]["range"])<8000:
                            res2 = 4 
                        elif 8000<=int(weather_groups[0]["visibility"]["range"])<9000:
                            res2 = 5 
                        elif 9000>=int(weather_groups[0]["visibility"]["range"]):
                            res2 = 10
                        visibility_array.append(res2)
                else:
                    res2 = weather_groups[0]["visibility"]["range"]    
                    if (' ' in res2) == True:
                        res2=res2.split()
                        res3=Fraction(res2[1])
                        res2=int(res2[0])+float(res3)
                    else:
                        if ('/' in res2) == True:
                           res2=Fraction(res2)
                           res2=float(res2)
                        else: 
                            res2=float(res2)
                    visibility_array.append(res2)
                visibilitytf = []
      
        return(visibility_array)
예제 #2
0
def parse_taf(taf):
    try:
        msg = pytaf.TAF(taf)
        decoder = pytaf.Decoder(msg)
        return decoder.decode_taf()
    except:
        pass

    return None
예제 #3
0
 def wind_group_function():
     """
     Function built for extracting taf._weather_groups[X]["winds"]
     Attribute "Clouds" has 2 outputs
     'wind': None 
     or 
     wind': {'direction': '210', 'speed': '06', 'gust': None, 'unit': 'KT'}
     """
     direction_val =[]
     speed_val =[]
     gust_val =[]
     unit_val = []
     wind_array = [direction_val,speed_val,gust_val,unit_val]
     for values in content01:
         #print(values)
         taf = pytaf.TAF(values)
         weather_groups = taf._weather_groups  
         windtf = weather_groups[0]["wind"]
         #print(windtf)
         if not windtf:
             res1 = -9999
             res2 = -9999
             res3 = -9999
             res4 = -9999
             direction_val.append(res1)
             speed_val.append(res2)
             gust_val.append(res3)
             unit_val.append(res4)
         else:
             if weather_groups[0]["wind"]["direction"] == 'VRB':
                 res1 = 777
                 res2 = int(weather_groups[0]["wind"]["speed"])
                 res4 = weather_groups[0]["wind"]["unit"]
                 direction_val.append(res1)
                 speed_val.append(res2)
                 unit_val.append(res4)
             else: 
                 res1 = int(weather_groups[0]["wind"]["direction"])
                 res2 = int(weather_groups[0]["wind"]["speed"])
                 res4 = weather_groups[0]["wind"]["unit"]
                 direction_val.append(res1)
                 speed_val.append(res2)
                 unit_val.append(res4)
         if not weather_groups[0]["wind"]["gust"]:
             res3 = -9999 
             gust_val.append(res3)
         else:
             res3 = weather_groups[0]["wind"]["gust"]
             gust_val.append(res3)
         windtf = []
     
     return(wind_array)
예제 #4
0
    def present_wx_group_function():
        """
        Function built for extracting taf._weather_groups[X]["weather"]
        Attribute "Weather" has 3 outputs
        'weather': None 
        or 
        'weather': [{'intensity': XXX, 'modifier': XXX, 'phenomenon': XXX}] 
        """
        present_wx=[]
        for values in content01:
            res1 = []
            res2 = []
            #print(values)
            taf = pytaf.TAF(values)
            weather_groups = taf._weather_groups  
            weathertf = weather_groups[0]["weather"]
            res1 = []
            res2 = []
            res3 = []
            res4 = []
            results1=[]

            if not weathertf:

                res1 = "None"              
                present_wx.append(res1)

            elif weathertf: 
                if len(weather_groups[0]["weather"]) == 1:
                    res1 = weather_groups[0]["weather"][0]["intensity"]
                    res2 = weather_groups[0]["weather"][0]["modifier"]
                    res3 = weather_groups[0]["weather"][0]["phenomenon"]
                    res4=res1+res2+res3
                    res4="".join(res4)
                    res4 = "".join(OrderedDict.fromkeys(res4))
                    present_wx.append(res4)
                else:
                    for k in range(0,len(weather_groups[0]["weather"])): 
                        res1 = weather_groups[0]["weather"][k]["intensity"]
                        res2 = weather_groups[0]["weather"][k]["modifier"]
                        res3 = weather_groups[0]["weather"][k]["phenomenon"]
                        res4=res1+res2+res3
                        res4="".join(res4)
                        results1.append(res4)
                    results1=" ".join(results1)
                    print(results1)
                    results1 = "".join(OrderedDict.fromkeys(results1))
                    present_wx.append(results1)
            weathertf = []

        return(present_wx)
예제 #5
0
    def clouds_group_function():
        """
        Function built for extracting taf._weather_groups[X]["clouds"]
        Attribute "Clouds" has 2 outputs
        'clouds': None 
        or 
        'clouds': [{'layer': 'XXX', 'ceiling': 'XXX', 'type': XXX}] 
        """
        layer_val = []
        ceiling_val =[]
        clouds_array = [layer_val, ceiling_val]
        for values in content01:
            #print(values)
            res1 = []
            res2 = []
            taf = pytaf.TAF(values)
            weather_groups = taf._weather_groups  
            cloudstf = weather_groups[0]["clouds"]
            vvtf = weather_groups[0]["vertical_visibility"]
            results3 =[]
            results4 =[] 
            if not cloudstf and not vvtf:
                res1 = ["-9999"]
                res2 = ["-9999"]
                layer_val.append(res1)
                ceiling_val.append(res2)
            elif vvtf:
                res1 = ["VV"]
                res2 = [weather_groups[0]["vertical_visibility"]]
                layer_val.append(res1)
                ceiling_val.append(res2)
            elif cloudstf and not vvtf: 
                if weather_groups[0]["clouds"][0]["layer"] == 'CLR' or weather_groups[0]["clouds"][0]["layer"] == 'CAVOK' or weather_groups[0]["clouds"][0]["layer"] == 'NSC' or weather_groups[0]["clouds"][0]["layer"] == 'SKC'or weather_groups[0]["clouds"][0]["layer"] == 'NCD':
                    res1 = ["CLR"]
                    res2 = ["9999"]
                    layer_val.append(res1)
                    ceiling_val.append(res2)
                else:
                    for k in range(0,len(weather_groups[0]["clouds"])): 
                        #print(weather_groups[0]["clouds"])
                        res1 = weather_groups[0]["clouds"][k]["layer"]
                        res2 = weather_groups[0]["clouds"][k]["ceiling"]
                        results3.append(res1)
                        results4.append(res2)
                    layer_val.append(results3)
                    ceiling_val.append(results4)
            cloudstf = []

        return(clouds_array)
예제 #6
0
#!/usr/bin/env python

import pytaf

taf_str = """
TAF AMD KDEN 291134Z 2912/3018 32006KT 1/4SM FG OVC001 
     TEMPO 2914/2915 1SM -BR CLR
     FM291500 04006KT P6SM SKC
     TEMPO 2915/2917 2SM BR OVC008 
     FM291900 05007KT P6SM SCT050 BKN090 WS010/13040KT
     PROB30 2921/3001 VRB20G30KT -TSRA BKN050CB 
     FM300100 31007KT P6SM SCT070 BKN120 +FC
     FM300500 23006KT P6SM SCT120 $
"""

t = pytaf.TAF(taf_str)

d = pytaf.Decoder(t)

print(taf_str)
dec = d.decode_taf()

print(dec)

 def read_taf_function(values):
     taf = pytaf.TAF(values)
     return (taf)
예제 #8
0
def parse_data(code):
    code = code.split('\n')[1]
    return pytaf.Decoder(pytaf.TAF(code)).decode_taf()
예제 #9
0
 def parse_taf(self):
     t = pytaf.TAF(self.raw_taf)
     self.taf = pytaf.Decoder(t, self.timestamp)
예제 #10
0
 def icao_get_function():
     icao = []
     for values in content01:
         taf = pytaf.TAF(values)
         icao.append(taf._taf_header["icao_code"])
     return(icao)
예제 #11
0
 def decode_taf(self, s):
     taf = pytaf.TAF(s)
     decoder = pytaf.Decoder(taf)
     return decoder
예제 #12
0
    'KIAH', 'KDEN', 'KMBS', 'KRST', 'KJAX', 'KPBI', 'KSNA', 'KFAR', 'KELP', 'KCHS', 'KCWA',
    'KFWA', 'KSBN', 'KSAT', 'KCMH', 'KIND', 'KCID', 'KBMI', 'KMIA', 'KBWI', 'KPIT', 'KCMX',
    'KLAN', 'KGSP', 'KLSE', 'KSGF', 'KTOL', 'KOMA', 'KTPA', 'KPWM', 'KTVC', 'KHPN', 'KDLH',
    'KSAN', 'KSRQ', 'KEWR', 'KROC', 'KPDX', 'KORF', 'KMKG', 'KSPI', 'KMSN', 'KATL', 'KCOU',
    'KDSM', 'KILM', 'KROA', 'KMEM', 'KHSV', 'KSLC', 'KLEX', 'KSDF', 'KEVV', 'KFSD', 'KDTW',
    'KBOS', 'KSYR', 'KASE', 'KPHX', 'KMCI', 'KLIT'
  ]

  for airport in airports:

    try:

      cxn = mysql.connector.connect(host='146.148.73.209', user='******', db='TAF')

      raw_taf = fetch(airport)
      parsed_taf = pytaf.TAF(raw_taf)

      taf = {
        'type': parsed_taf._taf_header.get('type'),
        'icao_code': parsed_taf._taf_header.get('icao_code'),
        'origin_date_time': construct_date_time(parsed_taf._taf_header.get('origin_date'), parsed_taf._taf_header.get('origin_hours'), parsed_taf._taf_header.get('origin_minutes')),
        'valid_from_date_time': construct_date_time(parsed_taf._taf_header.get('valid_from_date'), parsed_taf._taf_header.get('valid_from_hours')),
        'valid_till_date_time': construct_date_time(parsed_taf._taf_header.get('valid_till_date'), parsed_taf._taf_header.get('valid_till_hours')),
        'form': parsed_taf._taf_header.get('form'),
        'code': parsed_taf._raw_taf
      }

      taf_id = insert_taf(cxn, taf)

      for (parsed_group, raw_group) in zip(parsed_taf._weather_groups, parsed_taf._raw_weather_groups):