Exemple #1
0
    def _getSiteConfig(self, ident):
        self.ident = ident
        siteinfo = AvnParser.getTafSiteCfg(ident)
        if not siteinfo:
            msg = 'Missing configuration file for %s' % ident
            _Logger.error(msg)
            Busy.showerror(msg, self.interior())
            return False
        self.sites = siteinfo['sites']
        thresholds = siteinfo['thresholds']
        self.tafduration = int(thresholds.get('tafduration','24'))
        self.vsby = thresholds['vsby']
        self.cig = thresholds['cig']
        if self.cfg['vsby']['bot'] < thresholds['vsby'][0]:
            self.vsby.insert(0, self.cfg['vsby']['bot'])
        if self.cfg['vsby']['top'] > thresholds['vsby'][-1]:
            self.vsby.append(self.cfg['vsby']['top'])
        if self.cfg['cig']['bot'] < thresholds['cig'][0]:
            self.cig.insert(0, self.cfg['cig']['bot'])
        if self.cfg['cig']['top'] > thresholds['cig'][-1]:
            self.cig.append(self.cfg['cig']['top'])

        self.yaxis = { \
            'cig': tuple([(math.log(h), _formatCig(h)) for h in self.cig]),\
            'vsby': tuple([(math.log(v), _formatVsby(v)) for v in self.vsby]), \
            'wind': ((-1, ' '*4), (1, ' '*4)), \
            }
        return True
Exemple #2
0
    def __init__(self, modelId, allFcst, tafType='   ', tafTime=None):
        self.model = modelId
        self.ident = allFcst['ident']['str']
        self.fcst = allFcst['group']
        self.startTimes = [t['time']['from'] for t in self.fcst]
        self.endTimes = [t['time']['to'] for t in self.fcst]
        self.grpTaf = Config(self.ident, modelId).grpTaf()
        self.fltCat = Config(self.ident, modelId).fltCat()
        self.tafType = tafType
        self.formatTafTime = tafTime
        if tafTime:
            self.tafTime = tafTime
        else:
            self.tafTime = AvnLib.getValidTime('taf', tafType)
        #get TAF's start and end projections

        try:
            self.tafDuration = int(
                AvnParser.getTafSiteCfg(
                    self.ident)['thresholds']['tafduration'])
        except:
            self.tafDuration = 24

        nBeg, nEnd = self.getTafPrd(self.tafDuration)
        if self.model == 'gfslamp':
            self.projData = [LampProjection(self.ident,self.grpTaf,self.fltCat, \
                dat,self.tafTime).getData() for dat in self.fcst[nBeg:nEnd]]
        else:
            self.projData = [Projection(self.ident,self.grpTaf,self.fltCat,dat,\
                self.tafTime).getData() for dat in self.fcst[nBeg:nEnd]]
        #create a subset time series
        self.subStartTimes = self.startTimes[nBeg:nEnd]
        self.subEndTimes = self.endTimes[nBeg:nEnd]
Exemple #3
0
 def processProfilerData(self,ident):
    """
    Process the newly arrived profiler data
    """      
    import RefTimePointDataRetrieve, NoDataException
    PARAMETERS = ["profilerId", "validTime", "numProfLvls", "height",
                  "uComponent", "vComponent", "uvQualityCode"]
    site = AvnParser.getTafSiteCfg(ident)
    profilerList = site['sites']['profilers']
    if len(profilerList) > 0:
       for profilerName in profilerList:
          try :
              pdc = RefTimePointDataRetrieve.retrieve('profiler', None, PARAMETERS,
                                               keyId='validTime', constraint={'profilerId':profilerName},
                                               maxSize=1)
          except NoDataException.NoDataException:
              _Logger.info("Error reading profiler " + profilerName)
              profilerList.remove(profilerName)
              continue
          validTimes = pdc.keys()
          validTimes.sort(reverse=True)
          data = pdc[validTimes[0]]
          try:
             self.vwpObsDict[profilerName] = self.__readProfilerData(data,profilerName)        
          except InValid:
             _Logger.info("Error reading profiler data")
       return profilerList
    else:
       return []
Exemple #4
0
def curWx(tafs, items):
    result = {}
    for taf in tafs:
        
        if items[taf['ident']['str']]['currentwx'] == 0:
            continue            
        if not taf['group']:
            continue
        
        try:
            _Logger.debug('curWx QC invoked for %s' % taf['ident']['str'])
            hourly = AvnLib.TafData(taf['group'])
            info = AvnParser.getTafSiteCfg(taf['ident']['str'])
            metar_monitor = MetarMonitor.Monitor(info, _MetarMonitorDict)
            r = metar_monitor.compare(Avn.Bunch(hourly=hourly, dcd=taf))
            msg = [r['status'][i].msg for i in _MetarMonitorDict['items'][1:] \
                if r['status'][i].severity > 1]
            index = AvnLib.getGroupIndex(taf['group'][0]['prev'])
            if msg:
                result[index] = {'level': 1, 'text': '\n'.join(msg)}
            else:
                result[index] = {'level': 0, 'text': 'OK'}
        except:
            _Logger.error('curWx() failed for %s',taf['ident']['str'])
            pass
        
    return result
Exemple #5
0
def _retrieveMapData(siteIDs, timeSeconds, parameters=Parameters):
    import JUtil
    from com.raytheon.uf.common.dataplugin.gfe.request import GetPointDataRequest
    from com.vividsolutions.jts.geom import Coordinate
    from com.raytheon.viz.aviation.guidance import GuidanceUtil
    from com.raytheon.uf.viz.core.localization import LocalizationManager
    gfeSiteId = LocalizationManager.getInstance().getCurrentSite()
    task = GetPointDataRequest()
    task.setSiteID(gfeSiteId);
    db = gfeSiteId + '_GRID__Official_00000000_0000'
    task.setDatabaseID(db)
    for siteID in siteIDs:
        config = AvnParser.getTafSiteCfg(siteID)
        lat = config['geography']['lat']
        lon = config['geography']['lon']
        c = Coordinate(float(lon), float(lat))
        task.addCoordinate(c)
    task.setNumberHours(_NumHours)
    task.setStartTime(long(timeSeconds * 1000))
    for p in parameters:
        task.addParameter(p)
    pdcs = GuidanceUtil.getGFEPointsData(task)
    i = 0
    results = {}
    for siteID in siteIDs:
        pdc = pdcs.getContainer(i)
        if i < pdcs.getSize() :
            ++i
        data = _getData(pdc, timeSeconds * 1000)
        if data is None:
            _Logger.info('Data not available for %s', siteID)
        results[siteID] = data
    return results
Exemple #6
0
def curWx(tafs, items):
    result = {}
    for taf in tafs:

        if items[taf['ident']['str']]['currentwx'] == 0:
            continue
        if not taf['group']:
            continue

        try:
            _Logger.debug('curWx QC invoked for %s' % taf['ident']['str'])
            hourly = AvnLib.TafData(taf['group'])
            info = AvnParser.getTafSiteCfg(taf['ident']['str'])
            metar_monitor = MetarMonitor.Monitor(info, _MetarMonitorDict)
            r = metar_monitor.compare(Avn.Bunch(hourly=hourly, dcd=taf))
            msg = [r['status'][i].msg for i in _MetarMonitorDict['items'][1:] \
                if r['status'][i].severity > 1]
            index = AvnLib.getGroupIndex(taf['group'][0]['prev'])
            if msg:
                result[index] = {'level': 1, 'text': '\n'.join(msg)}
            else:
                result[index] = {'level': 0, 'text': 'OK'}
        except:
            _Logger.error('curWx() failed for %s', taf['ident']['str'])
            pass

    return result
Exemple #7
0
    def __showAll(self):
        """Show all TAFs being actively monitored."""
        bbb = self._tkBBB.get()
        cvOnly = self._tkCigVisToggle.get()
        offset = 0
        LAMPs = Globals.DRC.getMosData(self._ids,self._model)
        if LAMPs is None:
            raise Avn.AvnError('No guidance available' )
        
        TAFs = []
        for  _id in self._ids:
            try:
                TAFs.append(Globals.DRC.getTafs(_id,True,time.time()-25200,1)[0])
            except IndexError:
                msg = 'No recent TAF for %s' % _id
                self.messagebar().message('usererror', msg)
                
        if TAFs is None:
            msg = 'No issued TAFs available'
            self.messagebar().message('usererror', msg)
        
        Thresholds = []
        for LAMP in LAMPs:
            tmtuple = time.gmtime(LAMP.data['itime']['value'])
            Thresholds.append(Globals.DRC.getProbs(LAMP.data['ident']['str'],
                                                  [tmtuple[7],('%02d'%tmtuple[3])]))

        if not (len(LAMPs) == len(TAFs) == len(Thresholds)):
            msg = 'Unable to show all TAFs due to missing data'
            self.messagebar().message('usererror', msg)
            
        for LAMP,TAF,thresholds in zip(LAMPs,TAFs,Thresholds):
            try:
                siteinfo = AvnParser.getTafSiteCfg(LAMP.data['ident']['str'])
                tafDuration = int(siteinfo['thresholds'].get('tafduration','24'))
                newTaf = TAMPGenerator.TAMPGenerator(LAMP,TAF.dcd['group'],thresholds,
                                                     bbb,cvOnly,(self._format == 'long'),
                                                     tafDuration)
                
                offset = int(self.text.index('end').split('.')[0])-2
                self.text.insert('end', '\n'.join(newTaf))
                self.text.insert('end', '\n\n')
                
                if self._tkHighlightFlightCat.get():
                    dcd = self._decoder(newTaf, bbb, offset)
                    if 'fatal' in dcd:
                        continue
                    
                    for ix, g in AvnLib.getTafPeriods(dcd):
                        fc = AvnLib.flightCategory(g)
                        self.text.tag_add(fc, *ix)
                        
            except (KeyError,TypeError,AttributeError):
                msg = 'Unable to format %s' % LAMP.data['ident']['str']
                self.messagebar().message('usererror', msg)
                
        if offset:
            self.text.component('columnheader').insert('end', 
                self.__makeHeader(LAMP.data))
Exemple #8
0
def tampgen(selSite, siteObjs, model, format, taf, tafHeader, cvOnly, routine = False, highlightFlightCat=True):
    siteObjs = JUtil.javaStringListToPylist(siteObjs)
    #print 'GuidanceEntry:tampgen  model, format, taf, tafHeader, cvOnly, highlightFlightCat:', model, format, taf, tafHeader, cvOnly, highlightFlightCat
    if routine :
        bbb = '   '
    else:
        bbb = 'AAX'
        
    LAMPs = []
    siteIDs = []
    for siteObj in siteObjs:
        o = pickle.loads(siteObj)
        siteID = o['siteID']
        LAMP = o['data']
#        print 'tampgen siteID, LAMP:', siteID, LAMP
        if LAMP is not None:
            LAMPs.append(LAMP)
            siteIDs.append(siteID)
        if selSite == siteID:
            selLAMP = LAMP
    if len(LAMPs) == 0 or selLAMP is None:
        if len(siteObjs) == 1 or selLAMP is None:
            msg = 'No data available for site %s' % selSite
        else:
            msg = 'No data available for the sites'
        return [msg]

    tafWithHeader = [__makeHeader('%s TAF/%s' % (selSite,model), selLAMP.data)]
    import TafDecoder, AvnParser, TAMPGenerator, ProbReader
    decoder = TafDecoder.Decoder()
    for siteID, LAMP in zip(siteIDs, LAMPs):
        tmtuple = time.gmtime(LAMP.data['itime']['value'])
        thresholds = ProbReader.prob_reader(siteID,[tmtuple[7],('%02d'%tmtuple[3])])
        if thresholds is None:
            msg = 'Missing LAMP thresholds at this hour for %s' % siteID
            return [msg]
        header = tafHeader
        text = taf
        
        dcd = decoder(text, bbb)
        TAF = Avn.Bunch(header=header, text=text, dcd=dcd)

        try:
            siteinfo = AvnParser.getTafSiteCfg(LAMP.data['ident']['str'])
            tafDuration = int(siteinfo['thresholds'].get('tafduration','24'))
            newTaf = TAMPGenerator.TAMPGenerator(LAMP,TAF.dcd['group'],thresholds,
                                                 bbb,cvOnly, (format == 'long'),
                                                 tafDuration)
            if highlightFlightCat:
                newTaf = __highlightFlightCat(newTaf)           
            tafWithHeader.append('')        
            tafWithHeader += newTaf
        except (KeyError,TypeError,AttributeError, Avn.AvnError), e:
            msg = "%s - %s" % (siteID, e)
            _Logger.exception('Error with TAMPGenerator: %s', msg)
            if len(siteObjs) == 1:
                return [msg]
Exemple #9
0
 def getSites(self):
     self._ids = AvnParser.getAllSiteIds()
     for ident in self._ids['taf']:
         info = AvnParser.getTafSiteCfg(ident)
         if info is None:
             continue
         lat = float(info['geography']['lat'])
         lon = float(info['geography']['lon'])
         d = {'id': ident, 'lat': lat, 'lon': lon}
         self._tafinfo.append(d)
Exemple #10
0
 def setSite(self, id_, ids):
     if self._id == id_:
         return
     self._id = id_
     self._etaid = None
     self._ids = []
     for i in ids:
         siteinfo = AvnParser.getTafSiteCfg(i)
         if siteinfo and siteinfo['sites'].get('eta'):
             self._ids.extend(siteinfo['sites']['eta'])
             if i == self._id:
                 self._etaid = self._ids[-1]
Exemple #11
0
    def __load(self):
        self.messagebar().resetmessages('systemerror')
        if not self.site.valid():
            msg = 'Invalid site id'
            self.messagebar().message('usererror', msg)
            return
        ident = self.site.getvalue().upper()
        cfg = AvnParser.getTafSiteCfg(ident)
        if cfg is None:
            self.__clear()
            msg = 'Failed to retrieve configuration for %s' % ident
            self.messagebar().message('systemerror', msg)
            return
        
        self.wmo.setvalue(cfg['headers']['wmo'])
        self.afos.setvalue(cfg['headers']['afos'])
        
        self.vsby.setvalue(','.join([str(x) for x in \
                                     cfg['thresholds']['vsby']]))
        self.cig.setvalue(','.join([str(x) for x in \
                                    cfg['thresholds']['cig']]))
        self.radar_hgt.setvalue(','.join([str(x) for x in \
                                          cfg['thresholds']['radar_cutoff']]))
        self.profiler_hgt.setvalue(','.join([str(x) for x in \
                                             cfg['thresholds']['profiler_cutoff']]))
        self.tafDuration.setvalue(cfg['thresholds']['tafduration'])

        self.lat.setvalue(cfg['geography']['lat']) 
        self.lon.setvalue(cfg['geography']['lon']) 
        self.elev.setvalue(cfg['geography']['elev']) 
        self.runway.setvalue(','.join([str(x) for x in \
                                       cfg['geography']['runway']+['']]))
	
        for tag in self.AltSites:
            try:
                self.ident[tag].setvalue(','.join(cfg['sites'][tag.lower()]))
            except KeyError:
                if tag not in ['Radars', 'Profilers', 'ACARS']:
                    msg = 'Missing entry %s for %s' % (tag, ident)
                    self.messagebar().message('systemerror', msg)
                    _Logger.error(msg) 

	for btn, label in [('Impact','impact'),('Climate','climate'),('Current Wx','currentwx')]:
	    try:
                self.qcCheck.button(btn).select()
		if cfg['qc'][label] == 0:
                    self.qcCheck.button(btn).deselect()
                    
	    except KeyError:
                self.qcCheck.button(btn).select()
		continue
            
	    self.__setQC(label, cfg['qc'][label])
Exemple #12
0
    def qcFromJava(self, text, sites, items, bbb, dataDir):
        import JUtil
        import TafDecoder
        
        # tafs
        # convert the ArrayList of tafs into a python list
        fcsts = []
        size = text.size()
        for i in range(size):
            fcsts.append(str(text.get(i)))
        
        # decode the tafs for use in the QC check
        taf_decoder = TafDecoder.Decoder()
        pytafs = []
        offset = 0
        for fcst in fcsts:
            taf = taf_decoder(fcst, bbb, offset, strict=True)
            offset += fcst.count('\n')+1
            if 'fatal' in taf:
                continue
            pytafs.append(taf)
            
            
        # convert the siteinfo Hashmap into python dictionary
        pysiteinfo = {}
        itr = sites.iterator()
        while itr.hasNext():  
            key = itr.next()
            ident = str(key)
            pysite = AvnParser.getTafSiteCfg(ident)
            pysiteinfo[ident] = pysite
            
        
        # convert the items HashMap into a python dictionary
        pyitems = {}
        keys = items.keySet()
        itr = keys.iterator()
        while itr.hasNext():
            key = itr.next()
            val = items.get(key)
            wx = eval(str(val.get('currentwx')))
            climate = eval(str(val.get('climate')))
            impact = eval(str(val.get('impact')))
            pyitem = {}
            pyitem['currentwx'] = wx
            pyitem['climate'] = climate
            pyitem['impact'] = impact
            pyitems[str(key)] = pyitem
        
        result = self(pytafs, pysiteinfo, pyitems, dataDir)

        return JUtil.pyValToJavaObj(result)
Exemple #13
0
 def __getSites(self):
     ids = AvnParser.getAllSiteIds()
     self.sitelist = []
     for ident in ids['taf']:
         info = AvnParser.getTafSiteCfg(ident)
         if info is None:
             continue
         d = {'id': ident, \
             'lat': float(info['geography']['lat']), \
             'lon': float(info['geography']['lon'])}
         self.sitelist.append(d)
     if not self.sitelist:
         _Logger.debug('Cannot get site list')
         raise SystemExit
Exemple #14
0
    def qcFromJava(self, text, sites, items, bbb, dataDir):
        import JUtil
        import TafDecoder

        # tafs
        # convert the ArrayList of tafs into a python list
        fcsts = []
        size = text.size()
        for i in range(size):
            fcsts.append(str(text.get(i)))

        # decode the tafs for use in the QC check
        taf_decoder = TafDecoder.Decoder()
        pytafs = []
        offset = 0
        for fcst in fcsts:
            taf = taf_decoder(fcst, bbb, offset, strict=True)
            offset += fcst.count('\n') + 1
            if 'fatal' in taf:
                continue
            pytafs.append(taf)

        # convert the siteinfo Hashmap into python dictionary
        pysiteinfo = {}
        itr = sites.iterator()
        while itr.hasNext():
            key = itr.next()
            ident = str(key)
            pysite = AvnParser.getTafSiteCfg(ident)
            pysiteinfo[ident] = pysite

        # convert the items HashMap into a python dictionary
        pyitems = {}
        keys = items.keySet()
        itr = keys.iterator()
        while itr.hasNext():
            key = itr.next()
            val = items.get(key)
            wx = eval(str(val.get('currentwx')))
            climate = eval(str(val.get('climate')))
            impact = eval(str(val.get('impact')))
            pyitem = {}
            pyitem['currentwx'] = wx
            pyitem['climate'] = climate
            pyitem['impact'] = impact
            pyitems[str(key)] = pyitem

        result = self(pytafs, pysiteinfo, pyitems, dataDir)

        return JUtil.pyValToJavaObj(result)
Exemple #15
0
    def __initializeLLWSDictsLists(self, info):
        """
      Examine configuration file and setup dictionaries and lists
      """
        pList = []
        rList = []
        aList = []

        m = info['ident']
        if m is not None:
            siteDict = AvnParser.getTafSiteCfg(m)
            try:
                radars = siteDict['sites']['radars']
                radar_cutoff = siteDict['thresholds']['radar_cutoff']
            except KeyError:
                radars, radar_cutoff = [], []

            try:
                profilers = siteDict['sites']['profilers']
                profiler_cutoff = siteDict['thresholds']['profiler_cutoff']
            except KeyError:
                profilers, profiler_cutoff = [], []

            try:
                acars = siteDict['sites']['acars']
            except KeyError:
                acars = []

            if len(profilers) > 0 or len(radars) > 0 or len(acars) > 0:
                #
                # This TAF site needs to be monitored
                self.metarList.append(m)
                self.siteVWPsDict[m] = [
                    radars, profilers, radar_cutoff, profiler_cutoff
                ]
                self.acarsDict[m] = [acars]
                #
                pList.extend(profilers)
                rList.extend(radars)
                aList.extend(acars)
        #
        # Find all unique radars and profilers to monitor
        self.profilerList = dict.fromkeys(pList).keys()
        self.radarList = dict.fromkeys(rList).keys()
        self.acarsList = dict.fromkeys(aList).keys()
Exemple #16
0
 def __getSites(self):
     ids = AvnParser.getAllSiteIds()
     dlat = math.degrees(self.distance/3959.0)
     self.sitelist = []
     self.sitedata = {}
     for ident in ids['taf']:
         info = AvnParser.getTafSiteCfg(ident)
         if info is None:
             continue
         lat = float(info['geography']['lat'])
         lon = float(info['geography']['lon'])
         dlon = dlat/math.cos(math.radians(lat))
         d = {'id': ident, 'lat': (lat-dlat, lat+dlat) , \
             'lon': (lon-dlon, lon+dlon)}
         self.sitelist.append(d)
         self.sitedata[ident] = []   # list of lightnings
     if not self.sitelist:
         raise SystemExit
Exemple #17
0
 def __getSites(self):
     ids = AvnParser.getAllSiteIds()
     dlat = math.degrees(self.distance / 3959.0)
     self.sitelist = []
     self.sitedata = {}
     for ident in ids['taf']:
         info = AvnParser.getTafSiteCfg(ident)
         if info is None:
             continue
         lat = float(info['geography']['lat'])
         lon = float(info['geography']['lon'])
         dlon = dlat / math.cos(math.radians(lat))
         d = {'id': ident, 'lat': (lat-dlat, lat+dlat) , \
             'lon': (lon-dlon, lon+dlon)}
         self.sitelist.append(d)
         self.sitedata[ident] = []  # list of lightnings
     if not self.sitelist:
         raise SystemExit
Exemple #18
0
    def __showFormatted(self):
        
        newTaf = None
        bbb=self._tkBBB.get()
        cvOnly = self._tkCigVisToggle.get()
        LAMP = Globals.DRC.getMosData(self._mosid, self._model)
        if LAMP is None:
            msg = 'Cannot retrieve LAMP data for %s' % self._mosid
            self.messagebar().message('usererror', msg)
        
        tmtuple = time.gmtime(LAMP.data['itime']['value'])
        thresholds = Globals.DRC.getProbs(self._mosid,[tmtuple[7],('%02d'%tmtuple[3])])
        if thresholds is None:
            msg = 'Missing LAMP thresholds at this hour for %s' % self._mosid
            self.messagebar().message('usererror', msg)

        self.text.component('columnheader').insert('end',self.__makeHeader(LAMP.data))
        
        try:
            TAF = Globals.DRC.getTafs(self._id,True,time.time()-25200,1)[0]
        except:
            msg = 'Cannot retrieve TAF for %s' % self._id
            self.messagebar().message('usererror', msg)

        try:
            siteinfo = AvnParser.getTafSiteCfg(LAMP.data['ident']['str'])
            tafDuration = int(siteinfo['thresholds'].get('tafduration','24'))
            newTaf = TAMPGenerator.TAMPGenerator(LAMP,TAF.dcd['group'],thresholds,
                                                 bbb,cvOnly,(self._format == 'long'),
                                                 tafDuration)
            
        except (KeyError,TypeError,AttributeError):
            msg = 'Unable to format %s' % self._id
            self.messagebar().message('usererror', msg)
        
        if newTaf:
            self.text.insert('end','\n'.join(newTaf))
            if self._tkHighlightFlightCat.get():
                dcd = self._decoder(newTaf)
                if 'fatal' in dcd:
                    return
                for ix, g in AvnLib.getTafPeriods(dcd):
                    fc = AvnLib.flightCategory(g)
                    self.text.tag_add(fc, *ix)
Exemple #19
0
   def __initializeLLWSDictsLists(self,info):
      """
      Examine configuration file and setup dictionaries and lists
      """
      pList = []
      rList = []
      aList = []

      for m in AvnParser.getTafHeaders():
         siteDict = AvnParser.getTafSiteCfg(m)
         try:
            radars = siteDict['sites']['radars']
            radar_cutoff = siteDict['thresholds']['radar_cutoff']
         except KeyError:
            radars, radar_cutoff = [], []

         try:    
            profilers = siteDict['sites']['profilers']
            profiler_cutoff = siteDict['thresholds']['profiler_cutoff']
         except KeyError:
            profilers, profiler_cutoff = [], []

         try:
            acars = siteDict['sites']['acars']
         except KeyError:
            acars = []

         if profilers == [] and radars == [] and acars == []:
            continue
         #
         # This TAF site needs to be monitored
         self.metarList.append(m)
         self.siteVWPsDict[m] = [radars,profilers,radar_cutoff,profiler_cutoff]
         self.acarsDict[m] = [acars]
         #
         pList.extend(profilers)
         rList.extend(radars)
         aList.extend(acars)
      #
      # Find all unique radars and profilers to monitor
      self.profilerList = dict.fromkeys(pList).keys()
      self.radarList = dict.fromkeys(rList).keys()
      self.acarsList = dict.fromkeys(aList).keys()
Exemple #20
0
def monitor(request):
    taf = decodeTaf(request.getTaf(), request.getWmoHeader())
    if taf.dcd.has_key('fatal'):
        _Logger.error(taf.dcd['fatal'])
        return JUtil.pyValToJavaObj({'fatal': taf.dcd['fatal']})
        
    monitorModuleName = request.getCfg().getClassName()
    monitorModule = __import__(monitorModuleName)
    info = AvnParser.getTafSiteCfg(request.getSiteID())
    m = transformCfg(monitorModule, request)
    monitor = monitorModule.Monitor(info, m)
    result = {'ident': info['ident'], 'taf': taf, \
            'newtaf': False, 'status': {}}
    result['taf'].hourly = AvnLib.TafData( \
                        result['taf'].dcd['group'])
    result['status'] = monitor.compare(result['taf'])
    result = bunchToDict(result)
    if result['taf'].has_key('hourly'):
        hourly = result['taf']['hourly']        
        result['taf']['hourly'] = None
    return JUtil.pyValToJavaObj(result)
Exemple #21
0
def monitor(request):
    taf = decodeTaf(request.getTaf(), request.getWmoHeader())
    if taf.dcd.has_key('fatal'):
        _Logger.error(taf.dcd['fatal'])
        return JUtil.pyValToJavaObj({'fatal': taf.dcd['fatal']})

    monitorModuleName = request.getCfg().getClassName()
    monitorModule = __import__(monitorModuleName)
    info = AvnParser.getTafSiteCfg(request.getSiteID())
    m = transformCfg(monitorModule, request)
    monitor = monitorModule.Monitor(info, m)
    result = {'ident': info['ident'], 'taf': taf, \
            'newtaf': False, 'status': {}}
    result['taf'].hourly = AvnLib.TafData( \
                        result['taf'].dcd['group'])
    result['status'] = monitor.compare(result['taf'])
    result = bunchToDict(result)
    if result['taf'].has_key('hourly'):
        hourly = result['taf']['hourly']
        result['taf']['hourly'] = None
    return JUtil.pyValToJavaObj(result)
Exemple #22
0
 def verify(self):
     self.messagebar().resetmessages('systemerror')
     try:
         product = self.products.getcurselection()[0]
         cfg = AvnParser.getTafProductCfg(product)
         if not cfg:
             raise Avn.AvnError('Cannot parse product definition file')
         idents = cfg.get('sites', [])
         for i in idents:
             if not AvnParser.getTafSiteCfg(i):
                 raise Avn.AvnError('Cannot parse %s info file' % i)
             for h in [0, 6, 12, 18]:
                 try:
                     AvnParser.getTafTemplate(i, h)
                 except IOError:
                     raise Avn.AvnError('Cannot read %s %02dZ template' % \
                         (i, h))
         self.messagebar().message('userevent', 'Verify succeeded')
     except IndexError:  
         self.messagebar().message('usererror', 'Select product to verify')
     except Avn.AvnError, e: 
         self.messagebar().message('usererror', str(e))
Exemple #23
0
def _retrieveMapData(siteIDs, timeSeconds, parameters=Parameters):
    import JUtil
    from com.raytheon.uf.common.dataplugin.gfe.request import GetPointDataRequest
    from com.vividsolutions.jts.geom import Coordinate
    from com.raytheon.viz.aviation.guidance import GuidanceUtil
    from com.raytheon.uf.viz.core.localization import LocalizationManager
    gfeSiteId = LocalizationManager.getInstance().getCurrentSite()
    task = GetPointDataRequest()
    task.setSiteID(gfeSiteId)
    db = gfeSiteId + '_GRID__Official_00000000_0000'
    task.setDatabaseID(db)
    for siteID in siteIDs:
        config = AvnParser.getTafSiteCfg(siteID)
        lat = config['geography']['lat']
        lon = config['geography']['lon']
        c = Coordinate(float(lon), float(lat))
        task.addCoordinate(c)
    task.setNumberHours(_NumHours)
    task.setStartTime(long(timeSeconds * 1000))
    for p in parameters:
        task.addParameter(p)
    pdcs = GuidanceUtil.getGFEPointsData(task)
    results = {}
    if pdcs is None:
        for siteId in siteIDs:
            _Logger.info('Data not available for %s', siteID)
            results[siteID] = None
        return results

    for i, siteID in enumerate(siteIDs):
        data = None
        if i < pdcs.getSize():
            pdc = pdcs.getContainer(i)
            data = _getData(pdc, timeSeconds * 1000)

        if data is None:
            _Logger.info('Data not available for %s', siteID)
        results[siteID] = data
    return results
def updateTafs(bbb, fcsts):
    # master is the parent widget, not used here
    # fcsts is a dictionary of forecasts displayed in the editor window
    # the function returns dictionary of modified forecasts
    # may raise AvnError
    badidents = []
    decoder = TafDecoder.Decoder()

    for ident in fcsts:
        try:
            tafDuration = int(
                AvnParser.getTafSiteCfg(ident)['thresholds']['tafduration'])
            taf = decoder(fcsts[ident], bbb)

            if not 'group' in taf or not taf['group']:
                _Logger.error('NIL TAF for %s', ident)
                continue

            AvnLib.adjustTimes(bbb, taf)
            evtime = taf['vtime']['str'][5:]
            # For DR15476: use 'maxSize=0' to indicate that the latest record is to be retrieved
            metar = MetarData.retrieve(ident, 0)[0]
            AvnLib.updateTafWithMetar(taf['group'][0]['prev'], metar.dcd)
            lines = AvnLib.makeTafFromPeriods(ident,
                                              bbb,
                                              taf['group'],
                                              tafDuration=tafDuration,
                                              evtime=evtime)

            if 'amd' in taf:
                lines.append(taf['amd']['str'])

            fcsts[ident] = '\n'.join(AvnLib.indentTaf(lines) + [''])

        except Exception, e:
            _Logger.exception(ident)
            badidents.append(ident)
Exemple #25
0
 def processProfilerData(self, ident):
     """
   Process the newly arrived profiler data
   """
     import RefTimePointDataRetrieve, NoDataException
     PARAMETERS = [
         "profilerId", "validTime", "numProfLvls", "height", "uComponent",
         "vComponent", "uvQualityCode"
     ]
     site = AvnParser.getTafSiteCfg(ident)
     profilerList = site['sites']['profilers']
     if len(profilerList) > 0:
         for profilerName in profilerList:
             try:
                 pdc = RefTimePointDataRetrieve.retrieve(
                     'profiler',
                     None,
                     PARAMETERS,
                     keyId='validTime',
                     constraint={'profilerId': profilerName},
                     maxSize=1)
             except NoDataException.NoDataException:
                 _Logger.info("Error reading profiler " + profilerName)
                 profilerList.remove(profilerName)
                 continue
             validTimes = pdc.keys()
             validTimes.sort(reverse=True)
             data = pdc[validTimes[0]]
             try:
                 self.vwpObsDict[profilerName] = self.__readProfilerData(
                     data, profilerName)
             except InValid:
                 _Logger.info("Error reading profiler data")
         return profilerList
     else:
         return []
Exemple #26
0
def tampgen(selSite,
            siteObjs,
            model,
            format,
            taf,
            tafHeader,
            cvOnly,
            routine=False,
            highlightFlightCat=True):
    siteObjs = JUtil.javaStringListToPylist(siteObjs)
    #print 'GuidanceEntry:tampgen  model, format, taf, tafHeader, cvOnly, highlightFlightCat:', model, format, taf, tafHeader, cvOnly, highlightFlightCat
    if routine:
        bbb = '   '
    else:
        bbb = 'AAX'

    LAMPs = []
    siteIDs = []
    for siteObj in siteObjs:
        o = pickle.loads(siteObj)
        siteID = o['siteID']
        LAMP = o['data']
        #        print 'tampgen siteID, LAMP:', siteID, LAMP
        if LAMP is not None:
            LAMPs.append(LAMP)
            siteIDs.append(siteID)
        if selSite == siteID:
            selLAMP = LAMP
    if len(LAMPs) == 0 or selLAMP is None:
        if len(siteObjs) == 1 or selLAMP is None:
            msg = 'No data available for site %s' % selSite
        else:
            msg = 'No data available for the sites'
        return [msg]

    tafWithHeader = [
        __makeHeader('%s TAF/%s' % (selSite, model), selLAMP.data)
    ]
    if str(tafWithHeader).find('Unable to determine data/time') > 0:
        tafWithHeader.append('')
        return tafWithHeader

    import TafDecoder, AvnParser, TAMPGenerator, ProbReader
    decoder = TafDecoder.Decoder()
    for siteID, LAMP in zip(siteIDs, LAMPs):
        tmtuple = time.gmtime(LAMP.data['itime']['value'])
        thresholds = ProbReader.prob_reader(
            siteID, [tmtuple[7], ('%02d' % tmtuple[3])])
        if thresholds is None:
            msg = 'Missing LAMP thresholds at this hour for %s' % siteID
            return [msg]
        header = tafHeader
        text = taf

        dcd = decoder(text, bbb)
        TAF = Avn.Bunch(header=header, text=text, dcd=dcd)

        try:
            siteinfo = AvnParser.getTafSiteCfg(LAMP.data['ident']['str'])
            tafDuration = int(siteinfo['thresholds'].get('tafduration', '24'))
            newTaf = TAMPGenerator.TAMPGenerator(LAMP, TAF.dcd['group'],
                                                 thresholds, bbb, cvOnly,
                                                 (format == 'long'),
                                                 tafDuration)
            if highlightFlightCat:
                newTaf = __highlightFlightCat(newTaf)
            tafWithHeader.append('')
            tafWithHeader += newTaf
        except (KeyError, TypeError, AttributeError, Avn.AvnError), e:
            msg = "%s - %s" % (siteID, e)
            _Logger.exception('Error with TAMPGenerator: %s', msg)
            if len(siteObjs) == 1:
                return [msg]
Exemple #27
0
def updateTafs(bbb, fcsts):
    badidents = []
    decoder = TafDecoder.Decoder()

    for ident in fcsts:
        try:
            try:
                tafDuration=int(AvnParser.getTafSiteCfg(ident)['thresholds']['tafduration'])
            except:
                tafDuration=24
                
            taf = decoder(fcsts[ident], bbb) 
            if not 'group' in taf or not taf['group']:
#                _Logger.error('NIL TAF for %s', ident)
                _Logger.info('NIL TAF for %s', ident)
                continue
            
            AvnLib.adjustTimes(bbb, taf)
            evtime=taf['vtime']['str'][5:]
            lines = AvnLib.makeTafFromPeriods(ident, bbb, taf['group'],
                                              tafDuration=tafDuration,
                                              evtime=evtime)
            if 'amd' in taf:
                m = _AmdPat.search(taf['amd']['str'])
                if m:
                    vtime = taf['vtime']['from']
                    tms = list(time.gmtime(vtime))
                    #
                    # Get new valid time made by adjustTimes routine
                    vpttrn = _AmdPat.search(' '.join(lines[:2]))
                    if vpttrn:
                        s = vpttrn.group(3)
                        tms[2:4] = (int(s[:2]), int(s[2:4]))
                        TafDecoder.fix_date(tms)
                        vtime = time.mktime(tms) - time.timezone
                        #
                        # If a TIL or AFT expression
                        if m.group(1):
	                        
                            s = m.group(2)
                            tms[2:5] = (int(s[:2]), int(s[2:4]), int(s[4:6]))
                            TafDecoder.fix_date(tms)
                            amdtime = time.mktime(tms) - time.timezone
	                        
                            if m.group(1) == 'AFT' and vtime >= amdtime :
                                lines.append(taf['amd']['str'][:m.start(1)])
                            elif m.group(1) == 'TIL' and vtime < amdtime:
                                lines.append(taf['amd']['str'])
                        #
                        # Range
                        elif m.group(3):
	                        
                            s = m.group(3)
                            tms[2:4] = (int(s[5:7]), int(s[7:]))
                            TafDecoder.fix_date(tms)
                            amdtime = time.mktime(tms) - time.timezone
                            if vtime < amdtime:                        
                                tms[2:4] = (int(s[:2]), int(s[2:4]))
                                TafDecoder.fix_date(tms)
                                amdtime = time.mktime(tms) - time.timezone
                                if vtime >= amdtime:
                                    lines.append('%sTIL %s00' % (taf['amd']['str'][:m.start(3)],s[5:]))
                                else:
                                    lines.append(taf['amd']['str'])
                    else:
                        lines.append(taf['amd']['str'])
                else:
                    lines.append(taf['amd']['str'])
                
            fcsts[ident] = '\n'.join(AvnLib.indentTaf(lines)+[''])
            
        except Avn.AvnError, e:
            badidents.append(ident)