Example #1
0
def processMsg(self):
    try:
        dic = json.loads(self.data)
    except ValueError:
        # errors out if we got multiple packets (race condition)
        # If we get more than one dictionary, just skip the whole thing
        # this shouldn't happen very often
        logging.info("Error decoding dictionary, skipping packet")
        return

    #prm data update
    self.parent.myBeam = beamData()
    self.parent.myBeam.updateValsFromDict(dic)
    self.parent.myBeam.prm.updateValsFromDict(dic)

    self.endP = False

    #fit data update and param noisesky
    self.parent.myBeam.fit.updateValsFromDict(dic)
    self.parent.myBeam.prm.noisesky = dic['noise.sky']

    #updates time to a datetime string
    self.parent.myBeam.time = datetime.datetime(dic['time.yr'],dic['time.mo'],\
     dic['time.dy'],dic['time.hr'],dic['time.mt'],dic['time.sc'])

    #inserts removes and inserts new beam data
    self.gque.put(self.parent.myBeam)
    if self.parent.myBeam.bmnum == int(self.parent.beams[0]):
        self.tque.put(self.parent.myBeam)
    logging.info("Proccessing packet: %s" % (str(self.parent.i)))
    self.parent.i = self.parent.i + 1
    self.endP = True
Example #2
0
def processMsg(self):
    try:
        dic = json.loads(self.data)
    except ValueError:
        # errors out if we got multiple packets (race condition)
        # If we get more than one dictionary, just skip the whole thing
        # this shouldn't happen very often
        logging.info("Error decoding dictionary, skipping packet")
        return
    
    #prm data update
    self.parent.myBeam = beamData()
    self.parent.myBeam.updateValsFromDict(dic)
    self.parent.myBeam.prm.updateValsFromDict(dic)

    self.endP = False

    #fit data update and param noisesky
    self.parent.myBeam.fit.updateValsFromDict(dic)
    self.parent.myBeam.prm.noisesky = dic['noise.sky']



    #updates time to a datetime string
    self.parent.myBeam.time = datetime.datetime(dic['time.yr'],dic['time.mo'],\
    	dic['time.dy'],dic['time.hr'],dic['time.mt'],dic['time.sc']) 
    
    #inserts removes and inserts new beam data
    self.gque.put(self.parent.myBeam)
    if self.parent.myBeam.bmnum == int(self.parent.beams[0]):
        self.tque.put(self.parent.myBeam)
    logging.info("Proccessing packet: %s" % (str(self.parent.i)))
    self.parent.i = self.parent.i+1
    self.endP = True
Example #3
0
    def run(self):
        myBeamList = scanData()
        while not self.data.empty():
            myBeamList = self.data.get(True, 0.01)
        while not self.stoprequest.isSet():
            time.sleep(20)
            timeNow = datetime.datetime.utcnow()
            while not self.data.empty():
                tmpB = self.data.get(True, 0.01)
                if tmpB == 0:
                    try:
                        reactor.stop()
                    except:
                        logging.error('Reactor already stopped')
                    logging.error('Time thread stopped')
                    self.stoprequest.set()

                    sys.exit()
                    break
                else:
                    myBeam = beamData()
                    myBeam = tmpB
                #writes to a file so the beam data can be later uploaded
                dFilenm = 'data/' + ` timeNow.month ` + ` timeNow.day ` + ` timeNow.year ` + '_' + self.parent.rad + self.parent.channels[
                    0]

                with open(dFilenm, 'a+') as f:
                    fLine = `myBeam.stid`+';'+`myBeam.time`+';'+`myBeam.cp`+';'+`myBeam.prm.nave`+\
                     ';'+`myBeam.prm.noisesky`+';'+`myBeam.prm.rsep`+';'+`myBeam.prm.nrang`+\
                     ';'+`myBeam.prm.frang`+';'+`myBeam.prm.noisesearch`+';'+`myBeam.prm.tfreq`+\
                     ';'+`myBeam.fit.slist`+';'+`myBeam.prm.ifmode`+';'+`myBeam.fit.v`+';'+\
                     `myBeam.fit.p_l`+';'+`myBeam.fit.w_l`+';'+`myBeam.fit.gflg`+'\n'
                    f.write(fLine)
                f.close()
                myBeamList.append(myBeam)
            if len(myBeamList) > 2:
                try:
                    self.parent.time['figure'].clf()
                    self.parent.time['figure'] = plotRti(
                        myBeamList,
                        self.parent.rad,
                        params=self.parent.time['param'],
                        scales=self.parent.time['sc'],
                        gsct=self.parent.time['gsct'],
                        bmnum=int(self.parent.beams[0]),
                        figure=self.parent.time['figure'],
                        rTime=timeNow,
                        title=self.parent.names[0],
                        myFov=self.parent.fovs)
                    self.parent.time['figure'].savefig(
                        "%stime" % (self.parent.filepath[0]))
                except:
                    logging.error('time plot missing info')
                    logging.error('Time Figure: %s' % (sys.exc_info()[0]))
            else:
                lowData(self, 'time.png')
Example #4
0
	def run(self):
		myBeamList = scanData()
		while not self.data.empty():
			myBeamList = self.data.get(True, 0.01)
		while not self.stoprequest.isSet():
			time.sleep(20)
			timeNow = datetime.datetime.utcnow()
			while not self.data.empty():
				tmpB = self.data.get(True, 0.01)
				if tmpB == 0:
					try:
						reactor.stop()
					except:
						logging.error('Reactor already stopped')
					logging.error('Time thread stopped')
					self.stoprequest.set()
					
					sys.exit()
					break
				else:
					myBeam = beamData()
					myBeam = tmpB
				#writes to a file so the beam data can be later uploaded
				dFilenm = 'data/'+`timeNow.month`+`timeNow.day`+`timeNow.year`+'_'+self.parent.rad+self.parent.channels[0]
				
				with open(dFilenm,'a+') as f:
					fLine = `myBeam.stid`+';'+`myBeam.time`+';'+`myBeam.cp`+';'+`myBeam.prm.nave`+\
						';'+`myBeam.prm.noisesky`+';'+`myBeam.prm.rsep`+';'+`myBeam.prm.nrang`+\
						';'+`myBeam.prm.frang`+';'+`myBeam.prm.noisesearch`+';'+`myBeam.prm.tfreq`+\
						';'+`myBeam.fit.slist`+';'+`myBeam.prm.ifmode`+';'+`myBeam.fit.v`+';'+\
						`myBeam.fit.p_l`+';'+`myBeam.fit.w_l`+';'+`myBeam.fit.gflg`+'\n'
					f.write(fLine)
				f.close()
				myBeamList.append(myBeam)
			if len(myBeamList)>2:
				try:
					self.parent.time['figure'].clf()
					self.parent.time['figure']=plotRti(myBeamList,
							self.parent.rad,
							params=self.parent.time['param'],
							scales=self.parent.time['sc'],
							gsct=self.parent.time['gsct'],
							bmnum = int(self.parent.beams[0]),
							figure = self.parent.time['figure'],
							rTime = timeNow,
							title = self.parent.names[0],
							myFov = self.parent.fovs)
					self.parent.time['figure'].savefig("%stime" % (self.parent.filepath[0]))
				except:
					logging.error('time plot missing info')
					logging.error('Time Figure: %s' %(sys.exc_info()[0]))
			else:
				lowData(self,'time.png')
Example #5
0
    def run(self):
        while not self.data.empty():
            myScan = self.data.get(True, 0.1)
            for mb in myScan:
                myBeam = beamData()
                myBeam = mb
                break
        while not self.stoprequest.isSet():
            time.sleep(1)
            timeNow = datetime.datetime.utcnow()
            myBeam.time = myBeam.time.replace(tzinfo=None)
            tdif = timeNow - myBeam.time
            if tdif.seconds > 360:
                try:
                    reactor.stop()
                except:
                    logging.error('Reactor already stopped')
                self.tq.put(0)
                logging.error('Geo thread stopped')
                for pr in self.parent.fan['param']:
                    silentRemove(self, "fan_%s.png" % (pr))
                    silentRemove(self, "geo_%s.png" % (pr))
                self.stoprequest.set()
                break
            while not self.data.empty():
                myBeam = beamData()
                myBeam = self.data.get()
                if myBeam.cp != self.oldCpid:
                    self.oldCpid = myBeam.cp
                    self.parent.maxbm = self.parent.maxbeam[0]
                #updates if maxgates is changing
                if myBeam.prm.nrang != self.maxgates:
                    logging.info('Changing Gates')
                    self.maxgates = myBeam.prm.nrang
                    self.parent.lon_0,self.parent.lat_0, self.parent.fovs,\
                    self.parent.dist, self.parent.height,self.parent.width = geoLoc(self.parent.site,\
                     self.maxgates,myBeam.prm.rsep,int(self.parent.maxbm))
                    self.parent.myMap = mapObj(coords='geo', projection='stere',\
                     lat_0=self.parent.lat_0, lon_0=self.parent.lon_0,\
                     width= self.parent.width*1.3,height = self.parent.height*1.3,\
                     grid =True)
                #updates myScan size if the beam number is greater then the current myScan size
                elif myBeam.bmnum >= len(myScan):
                    bmnum = len(myScan)
                    while myBeam.bmnum > len(myScan):
                        time.sleep(0.1)
                        tmp_myBeam = beamData()
                        tmp_myBeam.bmnum = bmnum
                        tmp_myBeam.time = timeNow.replace(tzinfo=None)
                        myScan.append(tmp_myBeam)
                        bmnum += 1
                    myScan.append(myBeam)
                    logging.info('Changing Beam number %s' % (myBeam))
                    self.parent.maxbm = myBeam.bmnum + 1
                    self.parent.lon_0,self.parent.lat_0, self.parent.fovs,\
                    self.parent.dist, self.parent.height,self.parent.width = geoLoc(self.parent.site,\
                     self.maxgates,myBeam.prm.rsep,\
                     int(self.parent.maxbm))
                    self.parent.myMap = mapObj(coords='geo', projection='stere',\
                     lat_0=self.parent.lat_0, lon_0=self.parent.lon_0,\
                     width= self.parent.width*1.3,height = self.parent.height*1.3,\
                     anchor = 'N',grid =True,draw=True)
                else:
                    myScan.pop(myBeam.bmnum)
                    myScan.insert(myBeam.bmnum, myBeam)
            #Plot and save geographic figure for each parameter
            try:
                self.parent.geo['figure'] = plotFan(
                    myScan, [self.parent.rad],
                    fovs=self.parent.fovs,
                    params=self.parent.geo['param'],
                    gsct=self.parent.geo['gsct'],
                    maxbeams=int(self.parent.maxbm),
                    maxgates=self.maxgates,
                    scales=self.parent.geo['sc'],
                    drawEdge=self.parent.geo['drawEdge'],
                    myFigs=self.parent.geo['figure'],
                    bmnum=myBeam.bmnum,
                    site=self.parent.site,
                    tfreq=myBeam.prm.tfreq,
                    noise=myBeam.prm.noisesearch,
                    nave=myBeam.prm.nave,
                    inttime=myBeam.prm.inttsc,
                    rTime=myBeam.time,
                    radN=self.parent.names[0],
                    dist=self.parent.dist,
                    merGrid=self.parent.geo['merGrid'],
                    merColor=self.parent.geo['merColor'],
                    continentBorder=self.parent.geo['continentBorder'],
                    waterColor=self.parent.geo['waterColor'],
                    continentColor=self.parent.geo['continentColor'],
                    backgColor=self.parent.geo['backgColor'],
                    gridColor=self.parent.geo['gridColor'],
                    filepath=self.parent.filepath[0],
                    myMap=self.parent.myMap)
            except:
                logging.error('geographic plot missing info')
                logging.error('Geo Figure: %s' % (sys.exc_info()[0]))

            #Plot and save beam number vs gates figure for each parameter
            for i in range(len(self.parent.fan['figure'])):
                time.sleep(1)
                if self.parent.fan['param'][i] == 'velocity':
                    self.parent.fan['gsct'] = True
                else:
                    self.parent.fan['gsct'] = False
                try:
                    self.parent.fan['figure'][i].clf()
                    self.parent.fan['figure'][i] = plotFgpJson(
                        myScan,
                        self.parent.rad,
                        params=[self.parent.fan['param'][i]],
                        gsct=self.parent.fan['gsct'],
                        scales=[self.parent.fan['sc'][i]],
                        bmnum=myBeam.bmnum,
                        figure=self.parent.fan['figure'][i],
                        tfreq=myBeam.prm.tfreq,
                        noise=myBeam.prm.noisesearch,
                        rTime=myBeam.time,
                        radN=self.parent.names[0])
                    self.parent.fan['figure'][i].savefig(
                        "%sfan_%s" %
                        (self.parent.filepath[0], self.parent.fan['param'][i]))
                except:
                    logging.error('fan plot missing info')
                    logging.error('Fan Figure: %s' % (sys.exc_info()[0]))
Example #6
0
	def run(self):
		while not self.data.empty():
			myScan = self.data.get(True, 0.1)
			for mb in myScan:
				myBeam = beamData()
				myBeam = mb
				break
		while not self.stoprequest.isSet():
			time.sleep(1)
			timeNow = datetime.datetime.utcnow()
			myBeam.time = myBeam.time.replace(tzinfo=None)	
			tdif = timeNow - myBeam.time
			if tdif.seconds > 360:
				try:
					reactor.stop()
				except:
					logging.error('Reactor already stopped')
				self.tq.put(0)
				logging.error('Geo thread stopped')
				for pr in self.parent.fan['param']:
					silentRemove(self,"fan_%s.png" % (pr))
					silentRemove(self,"geo_%s.png" % (pr))
				self.stoprequest.set()
				break
			while not self.data.empty():
				myBeam = beamData()
				myBeam = self.data.get()
				if myBeam.cp != self.oldCpid:
					self.oldCpid = myBeam.cp
					self.parent.maxbm = self.parent.maxbeam[0]
				#updates if maxgates is changing
				if myBeam.prm.nrang != self.maxgates:
					logging.info('Changing Gates')
					self.maxgates = myBeam.prm.nrang
					self.parent.lon_0,self.parent.lat_0, self.parent.fovs,\
					self.parent.dist, self.parent.height,self.parent.width = geoLoc(self.parent.site,\
						self.maxgates,myBeam.prm.rsep,int(self.parent.maxbm))
					self.parent.myMap = mapObj(coords='geo', projection='stere',\
						lat_0=self.parent.lat_0, lon_0=self.parent.lon_0,\
						width= self.parent.width*1.3,height = self.parent.height*1.3,\
						grid =True)
				#updates myScan size if the beam number is greater then the current myScan size
				elif myBeam.bmnum >= len(myScan):
					bmnum = len(myScan)
					while myBeam.bmnum > len(myScan):
						time.sleep(0.1)
						tmp_myBeam = beamData()
						tmp_myBeam.bmnum = bmnum
						tmp_myBeam.time = timeNow.replace(tzinfo=None)
						myScan.append(tmp_myBeam)
						bmnum += 1
					myScan.append(myBeam)
					logging.info('Changing Beam number %s'%(myBeam))
					self.parent.maxbm = myBeam.bmnum+1
					self.parent.lon_0,self.parent.lat_0, self.parent.fovs,\
					self.parent.dist, self.parent.height,self.parent.width = geoLoc(self.parent.site,\
						self.maxgates,myBeam.prm.rsep,\
						int(self.parent.maxbm))
					self.parent.myMap = mapObj(coords='geo', projection='stere',\
						lat_0=self.parent.lat_0, lon_0=self.parent.lon_0,\
						width= self.parent.width*1.3,height = self.parent.height*1.3,\
						anchor = 'N',grid =True,draw=True)
				else:
					myScan.pop(myBeam.bmnum)
					myScan.insert(myBeam.bmnum,myBeam)
			#Plot and save geographic figure for each parameter
			try:
				self.parent.geo['figure'] = plotFan(myScan,[self.parent.rad],
					fovs = self.parent.fovs,
					params=self.parent.geo['param'],
					gsct=self.parent.geo['gsct'], 
					maxbeams = int(self.parent.maxbm),
					maxgates=self.maxgates,	
					scales=self.parent.geo['sc'],
					drawEdge = self.parent.geo['drawEdge'], 
					myFigs = self.parent.geo['figure'],
					bmnum = myBeam.bmnum,
					site = self.parent.site,
					tfreq = myBeam.prm.tfreq,
					noise = myBeam.prm.noisesearch,
					nave = myBeam.prm.nave,
					inttime = myBeam.prm.inttsc,
					rTime=myBeam.time,
					radN = self.parent.names[0],
					dist = self.parent.dist,
					merGrid = self.parent.geo['merGrid'],
					merColor = self.parent.geo['merColor'],
					continentBorder = self.parent.geo['continentBorder'],
					waterColor = self.parent.geo['waterColor'],
					continentColor = self.parent.geo['continentColor'],
					backgColor = self.parent.geo['backgColor'],
					gridColor = self.parent.geo['gridColor'],
					filepath = self.parent.filepath[0],
					myMap = self.parent.myMap)
			except:
				logging.error('geographic plot missing info')
				logging.error('Geo Figure: %s'%(sys.exc_info()[0]))
				
			
			#Plot and save beam number vs gates figure for each parameter
			for i in range(len(self.parent.fan['figure'])):
				time.sleep(1)
				if self.parent.fan['param'][i] == 'velocity':
					self.parent.fan['gsct'] = True
				else:
					self.parent.fan['gsct'] = False
				try:
					self.parent.fan['figure'][i].clf()
					self.parent.fan['figure'][i]=plotFgpJson(myScan,self.parent.rad,
						params=[self.parent.fan['param'][i]],
						gsct=self.parent.fan['gsct'],
						scales=[self.parent.fan['sc'][i]],
						bmnum = myBeam.bmnum,
						figure = self.parent.fan['figure'][i],
						tfreq = myBeam.prm.tfreq,
						noise = myBeam.prm.noisesearch,
						rTime=myBeam.time,
						radN = self.parent.names[0])
					self.parent.fan['figure'][i].savefig("%sfan_%s" % (self.parent.filepath[0],self.parent.fan['param'][i]))
				except:
					logging.error('fan plot missing info')
					logging.error('Fan Figure: %s'%(sys.exc_info()[0]))