Exemplo n.º 1
0
    def parse_grib_data(self, filepath, lat, lon):
        """Executes wgrib2 and parses its output

        https://aviationweather.gov/turbulence/help?page=plot

        "All graphics display atmospheric turbulence intensity as energy (or eddy) dissipation rate to the
        1/3 power, i.e. EDR =e1/3 where e is the eddy dissipation rate in units of m2/s3). Typically EDR
        varies from close to 0, "smooth", to near 1, "extreme for most aircraft types. The display colors
        of EDR range from white near 0 to violet near 1."
        """

        args = ['-s',
                '-lon',
                '%f' % (lon),
                '%f' % (lat),
                filepath
                ]

        kwargs = {'stdout': subprocess.PIPE}

        if self.conf.spinfo:
            kwargs.update({'startupinfo': self.conf.spinfo, 'shell': True})
        p = subprocess.Popen([self.conf.wgrib2bin] + args, **kwargs)

        it = iter(p.stdout)

        cat = {}
        for line in it:
            print (line)
            sline = line.split(':')
            m = self.RE_PRAM.search(sline[3])

            parmcat, parm = m.groups()
            value = float(sline[7].split(',')[-1:][0][4:-1])

            if parmcat == '19' and parm == '30':
                # Eddy Dissipation Param
                alt = int(c.mb2alt(float(sline[4][:-3])))
                cat[alt] = value
            if parmcat == '19' and parm == '37':
                # Icing severity
                pass
            if parmcat == '6' and parm == '25':
                # Horizontal Extent of Cumulonimbus (CB) %
                pass
            if parmcat == '3' and parm == '3':
                # Cumulonimbus BASE or TOPS
                # ICAO Standard Atmosphere Reference height in METERS
                pass


        turbulence = []
        for key, value in cat.iteritems():
            turbulence.append([key, value])
        turbulence.sort()

        return turbulence
Exemplo n.º 2
0
    def parse_grib_data(self, filepath, lat, lon):
        """Executes wgrib2 and parses its output"""

        args = ['-s',
                '-lon',
                '%f' % (lon),
                '%f' % (lat),
                filepath
                ]

        kwargs = {'stdout': subprocess.PIPE}

        if self.conf.spinfo:
            kwargs.update({'startupinfo': self.conf.spinfo, 'shell': True})

        p = subprocess.Popen([self.conf.wgrib2bin] + args, **kwargs)

        it = iter(p.stdout)

        cat = {}
        for line in it:
            if sys.version_info.major == 2:
                r = line[:-1].split(':')
            else:
                r = line.decode('utf-8')[:-1].split(':')
            # Level, variable, value
            level, variable, value, maxave = [r[4].split(' '), r[3], r[7].split(',')[2].split('=')[1], r[6]]
            if len(level) > 1 and level[1] == 'mb' and maxave == 'spatial max':
                # print level[1], variable, value
                alt = int(c.mb2alt(float(level[0])))
                value = float(value)
                if value < 0:
                    value = 0
                if variable == 'CTP':
                    value *= 100
                if variable in ('CAT', 'CTP'):
                    if alt in cat:
                        # override existing value if bigger
                        if value > cat[alt]:
                            cat[alt] = value
                    else:
                        cat[alt] = value

        turbulence = []
        if sys.version_info.major == 2:
            turb_items = cat.iteritems()
        else:
            turb_items = iter(cat.items())
        for key, value in turb_items:
            turbulence.append([key, value / 6.0])
        turbulence.sort()

        return turbulence
Exemplo n.º 3
0
    def parseGribData(self, filepath, lat, lon):
        '''
        Executes wgrib2 and parses its output
        '''
        args = [
            '-s', '-lon',
            '%f' % (lon),
            '%f' % (lat),
            os.sep.join([self.conf.cachepath, filepath])
        ]

        if self.conf.spinfo:
            p = subprocess.Popen([self.conf.wgrib2bin] + args,
                                 stdout=subprocess.PIPE,
                                 startupinfo=self.conf.spinfo,
                                 shell=True)
        else:
            p = subprocess.Popen([self.conf.wgrib2bin] + args,
                                 stdout=subprocess.PIPE)
        it = iter(p.stdout)

        cat = {}
        for line in it:
            r = line[:-1].split(':')
            # Level, variable, value
            level, variable, value, maxave = [
                r[4].split(' '), r[3], r[7].split(',')[2].split('=')[1], r[6]
            ]
            if len(level) > 1 and level[1] == 'mb' and maxave == 'spatial max':
                #print level[1], variable, value
                alt = int(c.mb2alt(float(level[0])))
                value = float(value)
                if value < 0:
                    value = 0
                if variable == 'CTP':
                    value *= 100
                if variable in ('CAT', 'CTP'):
                    if alt in cat:
                        # override existing value if bigger
                        if value > cat[alt]:
                            cat[alt] = value
                    else:
                        cat[alt] = value

        turbulence = []
        for key, value in cat.iteritems():
            turbulence.append([key, value / 6.0])
        turbulence.sort()

        return turbulence
Exemplo n.º 4
0
 def parseGribData(self, filepath, lat, lon):
     '''
     Executes wgrib2 and parses its output
     '''
     args = ['-s',
             '-lon',
             '%f' % (lon),
             '%f' % (lat),
             os.sep.join([self.conf.cachepath, filepath])
             ]
     
     if self.conf.spinfo:
         p = subprocess.Popen([self.conf.wgrib2bin] + args, stdout=subprocess.PIPE, startupinfo=self.conf.spinfo, shell=True)
     else:
         p = subprocess.Popen([self.conf.wgrib2bin] + args, stdout=subprocess.PIPE)
     it = iter(p.stdout)
     
     cat = {}
     for line in it:
         r = line[:-1].split(':')
         # Level, variable, value
         level, variable, value, maxave = [r[4].split(' '),  r[3],  r[7].split(',')[2].split('=')[1], r[6]]
         if len(level) > 1 and level[1] == 'mb' and maxave == 'spatial max':
             #print level[1], variable, value
             alt = int(c.mb2alt(float(level[0])))
             value = float(value)
             if value < 0:
                 value = 0
             if variable == 'CTP':
                 value *= 100
             if variable in ('CAT', 'CTP'):
                 if alt in cat:
                     # override existing value if bigger
                     if value > cat[alt]:
                         cat[alt] = value
                 else:
                     cat[alt] = value
     
     turbulence = []
     for key, value in cat.iteritems():
         turbulence.append([key, value/6.0])
     turbulence.sort()
     
     return turbulence
Exemplo n.º 5
0
    def parseGribData(self, filepath, lat, lon):
        '''
        Executes wgrib2 and parses its output
        '''
        args = ['-s',
                '-lon',
                '%f' % (lon),
                '%f' % (lat),
                os.sep.join([self.conf.cachepath, filepath])
                ]
        if self.conf.spinfo:
            p = subprocess.Popen([self.conf.wgrib2bin] + args, stdout=subprocess.PIPE, startupinfo=self.conf.spinfo, shell=True)
        else:
            p = subprocess.Popen([self.conf.wgrib2bin] + args, stdout=subprocess.PIPE)
        it = iter(p.stdout)
        data = {}
        clouds = {}
        pressure = False
        for line in it:
            r = line[:-1].split(':')
            # Level, variable, value
            level, variable, value = [r[4].split(' '),  r[3],  r[7].split(',')[2].split('=')[1]]

            if len(level) > 1:
                if level[1] == 'cloud':
                    #cloud layer
                    clouds.setdefault(level[0], {})
                    if len(level) > 3 and variable == 'PRES':
                        clouds[level[0]][level[2]] = value
                    else:
                        #level coverage/temperature
                        clouds[level[0]][variable] = value
                elif level[1] == 'mb':
                    # wind levels
                    data.setdefault(level[0], {})
                    data[level[0]][variable] = value
                elif level[0] == 'mean':
                    if variable == 'PRMSL':
                        pressure = c.pa2inhg(float(value))

        windlevels = []
        cloudlevels = []

        # Let data ready to push on datarefs.

        # Convert wind levels
        for level in data:
            wind = data[level]
            if 'UGRD' in wind and 'VGRD' in wind:
                hdg, vel = c.c2p(float(wind['UGRD']), float(wind['VGRD']))
                #print wind['UGRD'], wind['VGRD'], float(wind['UGRD']), float(wind['VGRD']), hdg, vel
                alt = c.mb2alt(float(level))

                # Optional varialbes
                temp, rh, dew = False, False, False
                # Temperature
                if 'TMP' in wind:
                    temp = float(wind['TMP'])
                # Relative Humidity
                if 'RH' in wind:
                    rh = float(wind['RH'])
                else:
                    temp = False

                if temp and rh:
                    dew = c.dewpoint(temp, rh)

                windlevels.append([alt, hdg, c.ms2knots(vel), {'temp': temp, 'rh': rh, 'dew': dew, 'gust': 0}])
                #print 'alt: %i rh: %i vis: %i' % (alt, float(wind['RH']), vis)

        # Convert cloud level
        for level in clouds:
            level = clouds[level]
            if 'top' in level and 'bottom' in level and 'TCDC' in level:
                top, bottom, cover = float(level['top']), float(level['bottom']), float(level['TCDC'])
                #print "XPGFS: top: %.0fmbar %.0fm, bottom: %.0fmbar %.0fm %d%%" % (top * 0.01, c.mb2alt(top * 0.01), bottom * 0.01, c.mb2alt(bottom * 0.01), cover)

                #if bottom > 1 and alt > 1:
                cloudlevels.append([c.mb2alt(bottom * 0.01) * 0.3048, c.mb2alt(top * 0.01) * 0.3048, cover])
                #XP10
                #cloudlevels.append((c.mb2alt(bottom * 0.01) * 0.3048, c.mb2alt(top * 0.01) * 0.3048, cover/10))

        windlevels.sort()
        cloudlevels.sort()

        data = {
                'winds': windlevels,
                'clouds': cloudlevels,
                'pressure': pressure
                }

        return data
Exemplo n.º 6
0
    def parseGribData(self, filepath, lat, lon):
        '''
        Executes wgrib2 and parses its output
        '''
        args = [
            '-s', '-lon',
            '%f' % (lon),
            '%f' % (lat),
            os.sep.join([self.conf.cachepath, filepath])
        ]
        if self.conf.spinfo:
            p = subprocess.Popen([self.conf.wgrib2bin] + args,
                                 stdout=subprocess.PIPE,
                                 startupinfo=self.conf.spinfo,
                                 shell=True)
        else:
            p = subprocess.Popen([self.conf.wgrib2bin] + args,
                                 stdout=subprocess.PIPE)
        it = iter(p.stdout)
        data = {}
        clouds = {}
        pressure = False
        for line in it:
            r = line[:-1].split(':')
            # Level, variable, value
            level, variable, value = [
                r[4].split(' '), r[3], r[7].split(',')[2].split('=')[1]
            ]

            if len(level) > 1:
                if level[1] == 'cloud':
                    #cloud layer
                    clouds.setdefault(level[0], {})
                    if len(level) > 3 and variable == 'PRES':
                        clouds[level[0]][level[2]] = value
                    else:
                        #level coverage/temperature
                        clouds[level[0]][variable] = value
                elif level[1] == 'mb':
                    # wind levels
                    data.setdefault(level[0], {})
                    data[level[0]][variable] = value
                elif level[0] == 'mean':
                    if variable == 'PRMSL':
                        pressure = c.pa2inhg(float(value))

        windlevels = []
        cloudlevels = []

        # Let data ready to push on datarefs.

        # Convert wind levels
        for level in data:
            wind = data[level]
            if 'UGRD' in wind and 'VGRD' in wind:
                hdg, vel = c.c2p(float(wind['UGRD']), float(wind['VGRD']))
                #print wind['UGRD'], wind['VGRD'], float(wind['UGRD']), float(wind['VGRD']), hdg, vel
                alt = c.mb2alt(float(level))

                # Optional varialbes
                temp, rh, dew = False, False, False
                # Temperature
                if 'TMP' in wind:
                    temp = float(wind['TMP'])
                # Relative Humidity
                if 'RH' in wind:
                    rh = float(wind['RH'])
                else:
                    temp = False

                if temp and rh:
                    dew = c.dewpoint(temp, rh)

                windlevels.append([
                    alt, hdg,
                    c.ms2knots(vel), {
                        'temp': temp,
                        'rh': rh,
                        'dew': dew,
                        'gust': 0
                    }
                ])
                #print 'alt: %i rh: %i vis: %i' % (alt, float(wind['RH']), vis)

        # Convert cloud level
        for level in clouds:
            level = clouds[level]
            if 'top' in level and 'bottom' in level and 'TCDC' in level:
                top, bottom, cover = float(level['top']), float(
                    level['bottom']), float(level['TCDC'])
                #print "XPGFS: top: %.0fmbar %.0fm, bottom: %.0fmbar %.0fm %d%%" % (top * 0.01, c.mb2alt(top * 0.01), bottom * 0.01, c.mb2alt(bottom * 0.01), cover)

                #if bottom > 1 and alt > 1:
                cloudlevels.append([
                    c.mb2alt(bottom * 0.01) * 0.3048,
                    c.mb2alt(top * 0.01) * 0.3048, cover
                ])
                #XP10
                #cloudlevels.append((c.mb2alt(bottom * 0.01) * 0.3048, c.mb2alt(top * 0.01) * 0.3048, cover/10))

        windlevels.sort()
        cloudlevels.sort()

        data = {
            'winds': windlevels,
            'clouds': cloudlevels,
            'pressure': pressure
        }

        return data
Exemplo n.º 7
0
    def parse_grib_data(self, filepath, lat, lon):
        """Executes wgrib2 and parses its output"""
        args = ['-s',
                '-lon',
                '%f' % (lon),
                '%f' % (lat),
                filepath
                ]

        kwargs = {'stdout': subprocess.PIPE}

        if self.conf.spinfo:
            kwargs.update({'startupinfo': self.conf.spinfo, 'shell': True})

        print("Calling subprocess with {}, {}".format([self.conf.wgrib2bin] + args, kwargs))
        p = subprocess.Popen([self.conf.wgrib2bin] + args, **kwargs)
        print("result of grib data subprocess is p={}".format(p))
        it = iter(p.stdout)
        data = {}
        clouds = {}
        pressure = False
        for line in it:
            if sys.version_info.major == 2:
                r = line[:-1].split(':')
            else:
                r = line.decode('utf-8')[:-1].split(':')
            # Level, variable, value
            level, variable, value = [r[4].split(' '), r[3], r[7].split(',')[2].split('=')[1]]

            if len(level) > 1:
                if level[1] == 'cloud':
                    # cloud layer
                    clouds.setdefault(level[0], {})
                    if len(level) > 3 and variable == 'PRES':
                        clouds[level[0]][level[2]] = value
                    else:
                        # level coverage/temperature
                        clouds[level[0]][variable] = value
                elif level[1] == 'mb':
                    # wind levels
                    data.setdefault(level[0], {})
                    data[level[0]][variable] = value
                elif level[0] == 'mean':
                    if variable == 'PRMSL':
                        pressure = c.pa2inhg(float(value))

        windlevels = []
        cloudlevels = []

        # Let data ready to push on datarefs.

        # Convert wind levels
        if sys.version_info.major == 2:
            wind_levels = data.iteritems()
        else:
            wind_levels = iter(data.items())
        for level, wind in wind_levels:
            if 'UGRD' in wind and 'VGRD' in wind:
                hdg, vel = c.c2p(float(wind['UGRD']), float(wind['VGRD']))
                # print wind['UGRD'], wind['VGRD'], float(wind['UGRD']), float(wind['VGRD']), hdg, vel
                alt = int(c.mb2alt(float(level)))

                # Optional varialbes
                temp, rh, dew = False, False, False
                # Temperature
                if 'TMP' in wind:
                    temp = float(wind['TMP'])
                # Relative Humidity
                if 'RH' in wind:
                    rh = float(wind['RH'])

                if temp and rh:
                    dew = c.dewpoint(temp, rh)

                windlevels.append([alt, hdg, c.ms2knots(vel), {'temp': temp, 'rh': rh, 'dew': dew, 'gust': 0}])
                # print 'alt: %i rh: %i vis: %i' % (alt, float(wind['RH']), vis)

        # Convert cloud level
        for level in clouds:
            level = clouds[level]
            if 'top' in level and 'bottom' in level and 'TCDC' in level:
                top, bottom, cover = float(level['top']), float(level['bottom']), float(level['TCDC'])
                # print "XPGFS: top: %.0fmbar %.0fm, bottom: %.0fmbar %.0fm %d%%" % (top * 0.01, c.mb2alt(top * 0.01), bottom * 0.01, c.mb2alt(bottom * 0.01), cover)

                # if bottom > 1 and alt > 1:
                cloudlevels.append([c.mb2alt(bottom * 0.01) * 0.3048, c.mb2alt(top * 0.01) * 0.3048, cover])
                # XP10
                # cloudlevels.append((c.mb2alt(bottom * 0.01) * 0.3048, c.mb2alt(top * 0.01) * 0.3048, cover/10))

        windlevels.sort()
        cloudlevels.sort()

        data = {
            'winds': windlevels,
            'clouds': cloudlevels,
            'pressure': pressure
        }

        return data
Exemplo n.º 8
0
    def parseGribData(self, filepath, lat, lon):
        """
        Executes wgrib2 and parses its output
        """
        args = ["-s", "-lon", "%f" % (lon), "%f" % (lat), os.sep.join([self.conf.cachepath, filepath])]
        if self.conf.spinfo:
            p = subprocess.Popen(
                [self.conf.wgrib2bin] + args, stdout=subprocess.PIPE, startupinfo=self.conf.spinfo, shell=True
            )
        else:
            p = subprocess.Popen([self.conf.wgrib2bin] + args, stdout=subprocess.PIPE)
        it = iter(p.stdout)
        data = {}
        clouds = {}
        pressure = False
        for line in it:
            r = line[:-1].split(":")
            # Level, variable, value
            level, variable, value = [r[4].split(" "), r[3], r[7].split(",")[2].split("=")[1]]

            if len(level) > 1:
                if level[1] == "cloud":
                    # cloud layer
                    clouds.setdefault(level[0], {})
                    if len(level) > 3 and variable == "PRES":
                        clouds[level[0]][level[2]] = value
                    else:
                        # level coverage/temperature
                        clouds[level[0]][variable] = value
                elif level[1] == "mb":
                    # wind levels
                    data.setdefault(level[0], {})
                    data[level[0]][variable] = value
                elif level[0] == "mean":
                    if variable == "PRMSL":
                        pressure = c.pa2inhg(float(value))

        windlevels = []
        cloudlevels = []

        # Let data ready to push on datarefs.

        # Convert wind levels
        for level in data:
            wind = data[level]
            if "UGRD" in wind and "VGRD" in wind:
                hdg, vel = c.c2p(float(wind["UGRD"]), float(wind["VGRD"]))
                # print wind['UGRD'], wind['VGRD'], float(wind['UGRD']), float(wind['VGRD']), hdg, vel
                alt = c.mb2alt(float(level))

                # Optional varialbes
                temp, rh, dew = False, False, False
                # Temperature
                if "TMP" in wind:
                    temp = float(wind["TMP"])
                # Relative Humidity
                if "RH" in wind:
                    rh = float(wind["RH"])
                else:
                    temp = False

                if temp and rh:
                    dew = c.dewpoint(temp, rh)

                windlevels.append([alt, hdg, c.ms2knots(vel), {"temp": temp, "rh": rh, "dew": dew, "gust": 0}])
                # print 'alt: %i rh: %i vis: %i' % (alt, float(wind['RH']), vis)

        # Convert cloud level
        for level in clouds:
            level = clouds[level]
            if "top" in level and "bottom" in level and "TCDC" in level:
                top, bottom, cover = float(level["top"]), float(level["bottom"]), float(level["TCDC"])
                # print "XPGFS: top: %.0fmbar %.0fm, bottom: %.0fmbar %.0fm %d%%" % (top * 0.01, c.mb2alt(top * 0.01), bottom * 0.01, c.mb2alt(bottom * 0.01), cover)

                # if bottom > 1 and alt > 1:
                cloudlevels.append([c.mb2alt(bottom * 0.01) * 0.3048, c.mb2alt(top * 0.01) * 0.3048, cover])
                # XP10
                # cloudlevels.append((c.mb2alt(bottom * 0.01) * 0.3048, c.mb2alt(top * 0.01) * 0.3048, cover/10))

        windlevels.sort()
        cloudlevels.sort()

        data = {"winds": windlevels, "clouds": cloudlevels, "pressure": pressure}

        return data