##// END OF EJS Templates
Changes to meteor detection and phase correction because of relocation of antenna
Changes to meteor detection and phase correction because of relocation of antenna

File last commit:

r775:e4a69634f7a2
r819:c63b6bff3798
Show More
jroplotter.py
237 lines | 6.1 KiB | text/x-python | PythonLexer
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 '''
Created on Jul 9, 2014
@author: roj-idl71
'''
Miguel Valdez
handleError added to jroplotter
r732 import os, sys
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 import datetime
import numpy
Miguel Valdez
handleError added to jroplotter
r732 import traceback
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 from time import sleep
from Queue import Queue
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 from threading import Lock
# from threading import Thread
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691
Miguel Valdez
handleError added to jroplotter
r732 import schainpy
import schainpy.admin
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 from schainpy.model.proc.jroproc_base import Operation
from schainpy.model.serializer.data import obj2Dict, dict2Obj
Miguel Valdez
ImportError when msgpack is not installed
r701 from jroplot_correlation import *
from jroplot_heispectra import *
from jroplot_parameters import *
from jroplot_spectra import *
from jroplot_voltage import *
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698
class Plotter(Operation):
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691
isConfig = None
name = None
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 __queue = None
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691
def __init__(self, plotter_name, plotter_queue=None):
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 Operation.__init__(self)
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 self.isConfig = False
self.name = plotter_name
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 self.__queue = plotter_queue
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691
def getSubplots(self):
nrow = self.nplots
ncol = 1
return nrow, ncol
def setup(self, **kwargs):
print "Initializing ..."
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 def run(self, dataOut, id=None, **kwargs):
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691
"""
Input:
dataOut :
id :
"""
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 packDict = {}
packDict['id'] = id
packDict['name'] = self.name
packDict['kwargs'] = kwargs
packDict['data'] = obj2Dict(dataOut)
self.__queue.put(packDict)
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 # class PlotManager(Thread):
class PlotManager():
Miguel Valdez
handleError added to jroplotter
r732
__err = False
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 __stop = False
Miguel Valdez
handleError added to jroplotter
r732 __realtime = False
Miguel Valdez
External plotter simplified.
r716 controllerThreadObj = None
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698
Miguel Valdez
handleError added to jroplotter
r732 plotterList = ['Scope',
'SpectraPlot', 'RTIPlot',
Miguel Valdez
SpectraCutPlot added to PlotManager
r775 'SpectraCutPlot',
Miguel Valdez
handleError added to jroplotter
r732 'CrossSpectraPlot', 'CoherenceMap',
'PowerProfilePlot', 'Noise', 'BeaconPhase',
'CorrelationPlot',
'SpectraHeisScope','RTIfromSpectraHeis']
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 def __init__(self, plotter_queue):
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 # Thread.__init__(self)
# self.setDaemon(True)
Miguel Valdez
jroplotter.py updated
r703
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 self.__queue = plotter_queue
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 self.__lock = Lock()
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698
self.plotInstanceDict = {}
Miguel Valdez
handleError added to jroplotter
r732
self.__err = False
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 self.__stop = False
Miguel Valdez
handleError added to jroplotter
r732 self.__realtime = False
def __handleError(self, name="", send_email=False):
err = traceback.format_exception(sys.exc_info()[0],
sys.exc_info()[1],
sys.exc_info()[2])
print "***** Error occurred in PlotManager *****"
print "***** [%s]: %s" %(name, err[-1])
message = "\nError ocurred in %s:\n" %name
message += "".join(err)
sys.stderr.write(message)
if not send_email:
return
import socket
subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, name)
subtitle = "%s:\n" %(name)
subtitle += "Hostname: %s\n" %socket.gethostbyname(socket.gethostname())
subtitle += "Working directory: %s\n" %os.path.abspath("./")
# subtitle += "Configuration file: %s\n" %self.filename
subtitle += "Time: %s\n" %str(datetime.datetime.now())
adminObj = schainpy.admin.SchainNotify()
adminObj.sendAlert(message=message,
subject=subject,
subtitle=subtitle)
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698
def run(self):
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 if self.__queue.empty():
return
Miguel Valdez
handleError added to jroplotter
r732 if self.__err:
serial_data = self.__queue.get()
self.__queue.task_done()
return
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 self.__lock.acquire()
# if self.__queue.full():
# for i in range(int(self.__queue.qsize()/2)):
# serial_data = self.__queue.get()
# self.__queue.task_done()
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 n = int(self.__queue.qsize()/3 + 1)
for i in range(n):
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698
Miguel Valdez
External plotter simplified.
r716 if self.__queue.empty():
break
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 serial_data = self.__queue.get()
self.__queue.task_done()
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698
plot_id = serial_data['id']
plot_name = serial_data['name']
kwargs = serial_data['kwargs']
dataDict = serial_data['data']
dataPlot = dict2Obj(dataDict)
if plot_id not in self.plotInstanceDict.keys():
className = eval(plot_name)
self.plotInstanceDict[plot_id] = className()
plotter = self.plotInstanceDict[plot_id]
Miguel Valdez
handleError added to jroplotter
r732 try:
plotter.run(dataPlot, plot_id, **kwargs)
except:
self.__err = True
self.__handleError(plot_name, send_email=True)
break
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 self.__lock.release()
Miguel Valdez
GUI - External plotter: Read items while queue is not empty
r710
def isEmpty(self):
return self.__queue.empty()
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 def stop(self):
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 self.__lock.acquire()
self.__stop = True
self.__lock.release()
def close(self):
self.__lock.acquire()
for plot_id in self.plotInstanceDict.keys():
plotter = self.plotInstanceDict[plot_id]
plotter.close()
self.__lock.release()
Miguel Valdez
External plotter simplified.
r716
def setController(self, controllerThreadObj):
self.controllerThreadObj = controllerThreadObj
def start(self):
if not self.controllerThreadObj.isRunning():
raise RuntimeError, "controllerThreadObj has not been initialized. Use controllerThreadObj.start() before call this method"
self.join()
def join(self):
#Execute plotter while controller is running
while self.controllerThreadObj.isRunning():
self.run()
self.controllerThreadObj.stop()
#Wait until plotter queue is empty
while not self.isEmpty():
self.run()
Miguel Valdez
handleError added to jroplotter
r732 self.close()
def isErrorDetected(self):
self.__lock.acquire()
err = self.__err
self.__lock.release()
return err