def __validate(self): if not self.site.valid(): msg = 'Invalid site id' self.messagebar().message('usererror', msg) return for name, label in [('wmo', 'TAF WMO'), ('afos', 'TAF AFOS'), \ ('vsby', 'Visibility'), ('cig', 'Ceiling'), \ ('radar_hgt', 'Radar Cutoff'), \ ('profiler_hgt', 'Profiler Cutoff'), \ ('lat', 'Latitude'), ('lon', 'Longitude'), \ ('elev', 'Elevation'), ('runway', 'Runway(s)')]: if not getattr(self, name).valid(): msg = 'Invalid %s entry' % label self.messagebar().message('usererror', msg) return False for tag in self.AltSites: if not self.ident[tag].valid(): msg = 'Invalid %s entry' % tag self.messagebar().message('usererror', msg) return False # check for number of radar and profiler heights num_radars = len(AvnParser.split(self.ident['Radars'].getvalue())) num_heights = len(AvnParser.split(self.radar_hgt.getvalue())) if num_radars != num_heights: msg = 'Invalid number of Radar Cutoff heights' self.messagebar().message('usererror', msg) return False num_profilers = len(AvnParser.split(self.ident['Profilers'].getvalue())) num_heights = len(AvnParser.split(self.profiler_hgt.getvalue())) if num_profilers != num_heights: msg = 'Invalid number of Profiler Cutoff heights' self.messagebar().message('usererror', msg) return False return True
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)
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
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 []
def getResources(self): # Reads application resources file def _setResource(line): # returns true if line defines resource and is not in menu if line[0] == '!': return 0 name, value = line.split(None, 1) for m in self.menu: if m.id == name[:-1]: # skip ':' m.set(value[:-1]) # skip '\n' return 0 return 1 filename = 'etc/app-resources/X' id = AvnParser.getForecasters().get(Globals.Forecaster, '')['id'] ffilename = '%s.%s' % (filename, id) if not os.path.isfile(ffilename): Busy.showwarning('Cannot access resources file\n' + \ 'starting with defaults', self.parent) ffilename = filename try: self.fresources = filter(_setResource, file(ffilename)) except IOError: msg = 'Cannot access resources file' _Logger.exception(msg) Busy.showerror(msg, self.parent) self.fresources = [] return
def __init__(self, **kw): guicfg = AvnParser.getGuiCfg() if not guicfg: raise SystemExit Globals.Colors = guicfg['colors'] AppShell.AppShell.__init__(self, **kw) ErrorRedirect.fixlogging(_Logger, self.interior())
def _climate(ident, periods, dataDir): result = {} try: month = time.gmtime(periods[0][1]['time']['from']).tm_mon path = os.path.join(dataDir, '%s.%02d.nc' % (ident, month)) if not os.path.isfile(path): raise Avn.AvnError('File %s does not exist' % path) ncfh = pupynere.NetCDFFile(path) cfg = AvnParser.getClimQCConfig(ident) except IndexError: return result except IOError: raise IOError, 'Cannot access %s' % path for ix, p in periods: off = _getOffset(cfg, p) a0, text, off = _analyze(ncfh, off, cfg['showdetails']) level = _getLevel(a0, cfg['alpha']) if a0 < cfg['alpha']: suggestions = [_analyze(ncfh, toff, cfg['showdetails']) \ for toff in _neighbors(ncfh, off)] suggestions.sort() suggestions.reverse() best = filter(None, [_suggest(off, x[2]) for x in suggestions \ if x[0] >= cfg['alpha']]) if best: text.extend(best) else: text.append('Cannot figure it out') result[ix] = {'level': level, 'text': '\n'.join(text)} ncfh.close() return result
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
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]
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
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
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
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))
def _getCriteria(ident): fname = Avn.getTafPath(ident, 'impact.cfg') cp = ConfigParser.SafeConfigParser() cp.read(fname) clist = AvnParser.split(cp.get('conditions', 'items')) criteria = [dict(cp.items(c)) for c in clist] for d in criteria: d['level'] = int(d['level']) return criteria
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]
def __loadSites(self, event=None): lbox = self.sitelist.component('listbox') lbox.delete(0, 'end') try: for p in self.productlist.getcurselection(): lbox.insert('end', *AvnParser.getTwbProductCfg(p)['sites']) lbox.selection_set(0, 'end') except Exception, e: Busy.showerror(e, self.interior())
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
def setProductList(self): if self.radiobuttons.getcurselection() == 'Delayed': self.radiobuttons.invoke('Routine') self.productlist.setlist(AvnParser.getTafProducts()) try: self.productlist.setvalue(Globals.Products) except IndexError: return self.__loadSites()
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
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()
def listProducts(self): self.messagebar().resetmessages('systemerror') products = AvnParser.getTwbProducts() if products: self.products.setlist(products) self.products.selectitem(0) self.products.invoke() else: self.products.clear() self.messagebar().message('usererror', 'Empty product list')
def setProductList(self): if self.radiobuttons.getcurselection() == 'Delayed': self.radiobuttons.invoke('Routine') items = AvnParser.getTwbProducts() self.productlist.setlist(items) try: self.productlist.setvalue(items[0]) except IndexError: return self.__loadSites()
def __init__(self, inqueue, outqueue, info): self.inqueue = inqueue self.outqueue = outqueue self.name = info['name'] self.nhours = int(info['nhours']) self.info = info.copy() del self.info['name'] del self.info['nhours'] del self.info['module'] self.siteinfo = AvnParser.getAllSiteIds()
def verify(self): self.messagebar().resetmessages('systemerror') try: product = self.products.getcurselection()[0] cfg = AvnParser.getTwbProductCfg(product) if not cfg: raise Avn.AvnError('Cannot parse product definition') idents = cfg.get('sites', []) for i in idents: if not AvnParser.getTwbSiteCfg(i): raise Avn.AvnError('Cannot parse %s info file' % i) try: AvnParser.getTwbTemplate(i) except IOError: raise Avn.AvnError('Cannot read %s template' % i) 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))
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]
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])
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)
def __init__(self, **kw): self.root = Tk() self.root.withdraw() self.get_option_db() Pmw.initialise(self.root, useTkOptionDb=1) self.root.title(self.AppName) Pmw.MegaWidget.__init__(self, parent=self.root) self.root.resizable(0, 0) ErrorRedirect.fixlogging(_Logger, self.interior()) interior = self.interior() Busy.instantiate(interior) self._img1 = PhotoImage(file=Image1) self.slist = Pmw.ScrolledListBox(interior, labelpos='n', label_image=self._img1, listbox_exportselection=0, ) self.slist.pack(side='top', expand='yes', fill='x') f = Frame(interior) self._img2 = PhotoImage(file=Image2) cfg = AvnParser.getGuiCfg() self.servers = Pmw.ScrolledListBox(f, labelpos='n', label_image=self._img2, items=cfg['ns'], listbox_height=max(4, len(cfg['ns'])), listbox_exportselection=0, ) self.servers.pack(side='left', expand='yes', fill='x') self.servers.selection_set(0) self.bbox = Pmw.ButtonBox(f, orient='vertical', labelpos='w', frame_borderwidth=2, frame_relief='groove', ) self.bbox.pack(side='left', expand='yes', fill='x') self.bbox.add('TAFs', command=Avn.curry(self.ok, 'TAFs')) self.bbox.add('Climate', command=Avn.curry(self.ok, 'Climate')) self.bbox.add('Cancel', command=self.cancel) self.bbox.setdefault('TAFs') self.bbox.alignbuttons() f.pack(side='top') self.loadForecasters() self.prods = 0 self.pid = 0 signal.signal(signal.SIGUSR1, self.handler) signal.signal(signal.SIGCHLD, self.handler)
def __restore(self): if not Busy.askokcancel("""This will delete your configuration. Really want to continue?""", self.interior()): return id = AvnParser.getForecasters().get(Globals.Forecaster, '')['id'] filename = 'etc/app-resources/X.%s' % id try: os.unlink(filename) self.getResources() except OSError: msg = 'Cannot remove %s' % filename _Logger.exception(msg) Busy.showerror(msg, self.interior())
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)
def listIdents(self, product): self.messagebar().resetmessages('systemerror') cfg = AvnParser.getTwbProductCfg(product) if cfg: idents = cfg.get('sites', []) pil = cfg.get('workpil') self.idents.setlist(idents) if pil is None: pil = Avn.TWBWorkPIL self.pil.setvalue(pil) else: self.idents.clear() self.pil.clear() msg = 'Cannot read product %s' % product self.messagebar().message('usererror', msg)
def main(): os.chdir(TopDir) sys.path = sys.path[1:] sys.path.extend([os.path.join(TopDir, 'py')]) import AvnParser fdict = AvnParser.getForecasters() fcstrs = dict([(str(fdict[k]['id']),k) for k in fdict]) okx='0' if os.uname()[1].find('-okx') > -1: okx='1' print 'Processing files in etc' rmvOldExtensions(os.path.join('etc')) # for _file in [x for x in os.listdir(os.path.join('etc','app-resources')) if re.match('X\.\d+$',x)]: cvtFcstResourceFile(_file,okx,fcstrs.get(_file.split('.')[1], 'Unknown Forecaster')) updateGUICfg(os.path.join('etc','gui.cfg')) updateWxPlotCfg(os.path.join('etc','wxplot.cfg')) updateServerCfg(os.path.join('etc','server.cfg')) updateXmitCfg(os.path.join('etc','xmit.cfg')) # sites = [x for x in os.listdir(os.path.join('etc','tafs')) if re.match('[PNKT][A-Z0-9]{3}$',x)] for site in sites: cvtInfoCfg(site) # sites.insert(0,'XXXX') for site in sites: cvtMtrsCfg(site) for product in [x for x in os.listdir(os.path.join('etc','tafs')) if x.endswith('.cfg')]: cvtTAFPrdct(product) if okx == '1': print """Attention OKX ITO! Attention OKX AFP! Attention OKX ITO! Attention OKX AFP! You no longer have to alter TafEditDialog.__saveWorkFile() function to store the TAF workfile in the text database. It is now implemented as a forecaster resource setting '*alwaySaveToDB'. For all OKX forecasters, this new resource has been turned on as a convenience. """ print """Attention OKX ITO! Attention OKX AFP! Attention OKX ITO! Attention OKX AFP!"""
def loadForecasters(self): try: fcstnames = AvnParser.getForecasters().keys() if not fcstnames: raise ValueError, 'Empty file' fcstnames.sort() self.slist.setlist(fcstnames) except IOError: msg = 'Cannot open forecaster file' _Logger.exception(msg) Busy.showerror(msg, self.interior()) raise SystemExit except (ValueError, IndexError): msg = 'Invalid entry in forecaster file' _Logger.exception(msg) Busy.showerror(msg, self.interior()) raise SystemExit
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()
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)
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)
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)
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 []
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]
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)