Beispiel #1
0
 def __parse_metar_string(self, metar_string):
     self.metar = Metar(metar_string)
     self.wind_speed = int(self.metar.wind_speed.value("MPS"))
     self.wind_dir = int(self.metar.wind_dir.value())
     self.visibility = int(self.metar.vis.value())
     # cloud base: 300-5000
     # cloud thickness: 200-2000
     if self.metar.sky:
         cloud_coverage = self.metar.sky[0][0]
         if self.metar.sky[0][1]:
             self.cloud_alti = int(self.metar.sky[0][1].value("M"))
         else:
             self.cloud_alti = 300
         if cloud_coverage == "FEW":
             self.clouds = 2
             self.cloud_thickness = 500
         elif cloud_coverage == "SCT":
             self.clouds = 4
             self.cloud_thickness = 1000
         elif cloud_coverage == "BKN":
             self.clouds = 6
             self.cloud_thickness = 1500
         elif cloud_coverage == "OCT":
             self.clouds = 8
             self.cloud_thickness = 2000
     else:
         self.clouds = 0
         self.cloud_alti = 300
     self.pres_hg = int(self.metar.press.value('MMHG'))
     self.pres_mb = int(self.metar.press.value('MB'))
     self.temp = int(self.metar.temp.value('C'))
     self.dew_point = int(self.metar.dewpt.value('C'))
     self.update_time = self.metar.time
     self._parsed = True
Beispiel #2
0
def process_metar(mstr, now):
    """ Do the METAR Processing """
    mtr = None
    while mtr is None:
        try:
            mtr = Metar(mstr, now.month, now.year, allexceptions=True)
        except MetarParserError, exp:
            msg = str(exp)
            if msg.startswith("Unparsed groups:"):
                badpart = msg.strip().split()[2]
                mstr = mstr.replace(badpart.replace("'", ''), "")
            else:
                print("MetarParserError:"+msg)
                return None
        except Exception, exp:
            print("Double Fail: %s %s" % (mstr, exp))
            return None
Beispiel #3
0
def dumpRawMetar(raw_metar):
    print "raw_metar=", raw_metar
    obs = Metar(raw_metar)
    dumpMetar(obs)
Beispiel #4
0
def getMetar(metar_string):
    m = Metar(metar_string)
    return m
Beispiel #5
0
icursor2 = IEM.cursor()

sts = mx.DateTime.DateTime(2011, 1, 1)
ets = mx.DateTime.DateTime(2012, 1, 1)
interval = mx.DateTime.RelativeDateTime(days=1)
now = sts
while now < ets:
    icursor.execute("""
  select valid, station, metar from t%s
  where metar is not null and valid >= '%s' and valid < '%s'
    """ % (now.year, now.strftime("%Y-%m-%d"),
           (now + interval).strftime("%Y-%m-%d")))
    total = 0
    for row in icursor:
        try:
            mtr = Metar(row[2], row[0].month, row[0].year)
        except:
            continue
        sql = 'update t%s SET ' % (now.year, )
        if mtr.max_temp_6hr:
            sql += "max_tmpf_6hr = %s," % (mtr.max_temp_6hr.value("F"), )
        if mtr.min_temp_6hr:
            sql += "min_tmpf_6hr = %s," % (mtr.min_temp_6hr.value("F"), )
        if mtr.max_temp_24hr:
            sql += "max_tmpf_24hr = %s," % (mtr.max_temp_24hr.value("F"), )
        if mtr.min_temp_24hr:
            sql += "min_tmpf_24hr = %s," % (mtr.min_temp_24hr.value("F"), )
        if mtr.precip_3hr:
            sql += "p03i = %s," % (mtr.precip_3hr.value("IN"), )
        if mtr.precip_6hr:
            sql += "p06i = %s," % (mtr.precip_6hr.value("IN"), )
Beispiel #6
0
            "Temp: {}".format(self.temp),
            "Dew point: {}".format(self.dew_point),
            "wind_speed: {}".format(self.wind_speed),
            "wind_dir: {}".format(self.wind_dir),
            "visibility: {}".format(self.visibility),
            "clouds: {}".format(self.clouds),
            "cloud_alti: {}".format(self.cloud_alti),
            "pres_hg: {}".format(self.pres_hg),
            "pres_mb: {}".format(self.pres_mb),
        ]
        return "\n".join(s)


if __name__ == '__main__':
    metar_str = get_metar_of('UGKO')
    metar = Metar(metar_str)
    print(metar.wind_dir)
    print(metar.wind_dir_from)
    print(metar.wind_dir_to)
    print(metar.wind_speed)
    print(metar.wind_gust)
    print(metar.max_vis)
    print(metar.temp)
    print(metar.mod)
    print(metar.press.value('IN'))
    print(metar.press.value('HPA'))
    print(metar.press.value('MMHG'))
    print(metar.runway)
    print(metar.type)
    print(metar.time)
    print(metar.weather)
Beispiel #7
0
from lxml import objectify

current_METAR_url = 'https://aviationweather.gov/adds/dataserver_current/current/'

#xml_METAR_url = 'https://aviationweather.gov/adds/dataserver_current/httpparam?datasource=metars&requesttype=retrieve&format=xml&hoursBeforeNow=1.25&stationString=KORD'

weather_etl = weather.WeatherETL(debug=True)

# An example code:
# - In this example, we have "few clouds at 1500 feet, broken clouds at 4,000 feet w/ cumulonimbus,
#   broken at 6,500 feet, overcast at 20,000 feet"
# - Visibility is 2 statute miles
#code = "METAR KEWR 111851Z VRB03G19KT 2SM R04R/3000VP6000FT TSRA BR FEW015 BKN040CB BKN065 OVC200 22/22 A2987 RMK AO2 PK WND 29028/1817 WSHFT 1812 TSB05RAB22 SLP114 FRQ LTGICCCCG TS OHD AND NW-N-E MOV NE P0013 T02270215"
code = "METAR KEWR 111851Z VRB03G19KT 2SM R04R/3000VP6000FT TSRA BR FEW015 BKN040CB BKN065 OVC200 22/22 A2987 RMK AO2 PK WND 29028/1817 WSHFT 1812 TSB05RAB22 SLP114 FRQ LTGICCCCG TS OHD AND NW-N-E MOV NE P0013 T02270215"
# using the python-metar library
obs = Metar(code)

def all_callSigns():
    sql = "SELECT call_sign FROM weather_stations ORDER by call_sign"
    result=engine.execute(sql)
    #x = result.first()
    return [x[0] for x in result.fetchall()]


def callSign2Wban(call_sign):
    sql = "SELECT wban_code FROM weather_stations where call_sign='%s'" % call_sign
    result = engine.execute(sql)
    #print "result=", result
    x = result.first()
    wban = None
    if x: