##// END OF EJS Templates
Add SkyMapPlotData, operation can access parent kwargs, fix server plot for multiple ReceiverData
Add SkyMapPlotData, operation can access parent kwargs, fix server plot for multiple ReceiverData

File last commit:

r927:8a8ce128f618
r937:6cdcc42f2694
Show More
jroplotter.py
240 lines | 5.7 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
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):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
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
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
José Chávez
ningun cambio
r927 def __init__(self, plotter_name, plotter_queue=None, **kwargs):
Operation.__init__(self, **kwargs)
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
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
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 def getSubplots(self):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 nrow = self.nplots
ncol = 1
return nrow, ncol
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 def setup(self, **kwargs):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 print "Initializing ..."
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 def run(self, dataOut, id=None, **kwargs):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 """
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
A new Plotter Class was added for plotting using queues
r691 Input:
dataOut :
id :
"""
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 packDict = {}
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 packDict['id'] = id
packDict['name'] = self.name
packDict['kwargs'] = kwargs
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
jroplotter: data object is not serialized. (it was a waste of time)
r824 # packDict['data'] = obj2Dict(dataOut)
packDict['data'] = dataOut
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 self.__queue.put(packDict)
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 # class PlotManager(Thread):
class PlotManager():
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
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
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
External plotter simplified.
r716 controllerThreadObj = None
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
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',
José Chávez
ningun cambio
r927 'SpectraHeisScope', 'RTIfromSpectraHeis']
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 def __init__(self, plotter_queue):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 # Thread.__init__(self)
# self.setDaemon(True)
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
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()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 self.plotInstanceDict = {}
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
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
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 def __handleError(self, name="", send_email=False):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 err = traceback.format_exception(sys.exc_info()[0],
sys.exc_info()[1],
sys.exc_info()[2])
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 print "***** Error occurred in PlotManager *****"
print "***** [%s]: %s" %(name, err[-1])
message = "\nError ocurred in %s:\n" %name
message += "".join(err)
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 sys.stderr.write(message)
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 if not send_email:
return
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 import socket
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 subject = "SChain v%s: Error running %s\n" %(schainpy.__version__, name)
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 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())
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 adminObj = schainpy.admin.SchainNotify()
adminObj.sendAlert(message=message,
subject=subject,
subtitle=subtitle)
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 def run(self):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 if self.__queue.empty():
return
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 if self.__err:
serial_data = self.__queue.get()
self.__queue.task_done()
return
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 self.__lock.acquire()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 # if self.__queue.full():
# for i in range(int(self.__queue.qsize()/2)):
# serial_data = self.__queue.get()
# self.__queue.task_done()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 n = int(self.__queue.qsize()/3 + 1)
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 for i in range(n):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
External plotter simplified.
r716 if self.__queue.empty():
break
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 serial_data = self.__queue.get()
self.__queue.task_done()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
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']
Miguel Valdez
jroplotter: data object is not serialized. (it was a waste of time)
r824 # dataDict = serial_data['data']
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897 #
Miguel Valdez
jroplotter: data object is not serialized. (it was a waste of time)
r824 # dataPlot = dict2Obj(dataDict)
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
jroplotter: data object is not serialized. (it was a waste of time)
r824 dataPlot = serial_data['data']
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 if plot_id not in self.plotInstanceDict.keys():
className = eval(plot_name)
José Chávez
ningun cambio
r927 self.plotInstanceDict[plot_id] = className(**kwargs)
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 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
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 self.__lock.release()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
GUI - External plotter: Read items while queue is not empty
r710 def isEmpty(self):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
GUI - External plotter: Read items while queue is not empty
r710 return self.__queue.empty()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
SChain v2.1.5: jroplotter.py and testPlotter.py were added to Signal Chain
r698 def stop(self):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 self.__lock.acquire()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 self.__stop = True
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 self.__lock.release()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 def close(self):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 self.__lock.acquire()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 for plot_id in self.plotInstanceDict.keys():
plotter = self.plotInstanceDict[plot_id]
plotter.close()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
Using threading.Lock in jroplotter.py
r707 self.__lock.release()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
External plotter simplified.
r716 def setController(self, controllerThreadObj):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
External plotter simplified.
r716 self.controllerThreadObj = controllerThreadObj
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
External plotter simplified.
r716 def start(self):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
External plotter simplified.
r716 if not self.controllerThreadObj.isRunning():
raise RuntimeError, "controllerThreadObj has not been initialized. Use controllerThreadObj.start() before call this method"
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
External plotter simplified.
r716 self.join()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
External plotter simplified.
r716 def join(self):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
External plotter simplified.
r716 #Execute plotter while controller is running
while self.controllerThreadObj.isRunning():
self.run()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
External plotter simplified.
r716 self.controllerThreadObj.stop()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
External plotter simplified.
r716 #Wait until plotter queue is empty
while not self.isEmpty():
self.run()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 self.close()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 def isErrorDetected(self):
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 self.__lock.acquire()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 err = self.__err
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
Miguel Valdez
handleError added to jroplotter
r732 self.__lock.release()
José Chávez
cambiados los kwargs para cada operacion/unidad de procesamiento
r897
return err