From 4042108b4f6b4f210106bd47c87468708b523165 2015-12-02 22:42:49 From: Miguel Valdez Date: 2015-12-02 22:42:49 Subject: [PATCH] A new Plotter Class was added for plotting using queues --- diff --git a/schainpy/__init__.py b/schainpy/__init__.py index ab8d7d9..26b6d8f 100644 --- a/schainpy/__init__.py +++ b/schainpy/__init__.py @@ -4,4 +4,4 @@ Created on Feb 7, 2012 @author $Author$ @version $Id$ ''' -__version__ = "2.1.4.1" \ No newline at end of file +__version__ = "2.1.4.2" \ No newline at end of file diff --git a/schainpy/controller.py b/schainpy/controller.py index 1f16b04..8c83ac4 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -377,11 +377,15 @@ class OperationConf(): for parmConfObj in self.parmConfObjList: parmConfObj.printattr() - def createObject(self): + def createObject(self, plotter_queue=None): if self.type == 'self': raise ValueError, "This operation type cannot be created" + if self.type == 'plotter': + #Plotter(plotter_name) + opObj = Plotter(self.name, plotter_queue) + if self.type == 'external' or self.type == 'other': className = eval(self.name) opObj = className() @@ -587,7 +591,7 @@ class ProcUnitConf(): for opConfObj in self.opConfObjList: opConfObj.printattr() - def createObjects(self): + def createObjects(self, plotter_queue=None): className = eval(self.name) procUnitObj = className() @@ -597,7 +601,7 @@ class ProcUnitConf(): if opConfObj.type == 'self': continue - opObj = opConfObj.createObject() + opObj = opConfObj.createObject(plotter_queue) self.opObjDict[opConfObj.id] = opObj procUnitObj.addOperation(opObj, opConfObj.id) @@ -816,12 +820,17 @@ class Project(): ELEMENTNAME = 'Project' - def __init__(self): + __plotterQueue = None + + def __init__(self, filename="./schain.xml", plotter_queue=None): self.id = None self.name = None self.description = None + self.filename = filename + self.__plotterQueue = plotter_queue + self.procUnitConfObjDict = {} def __getNewId(self): @@ -1023,7 +1032,7 @@ class Project(): def createObjects(self): for procUnitConfObj in self.procUnitConfObjDict.values(): - procUnitConfObj.createObjects() + procUnitConfObj.createObjects(self.__plotterQueue) def __connect(self, objIN, thisObj): @@ -1113,7 +1122,19 @@ class Project(): return 0 return 1 + + def setFilename(self, filename): + + self.filename = filename + + def setPlotterQueue(self, plotter_queue): + + self.__plotterQueue = plotter_queue + def getPlotterQueue(self): + + return self.__plotterQueue + def run(self): print @@ -1164,15 +1185,12 @@ class Project(): procUnitConfObj.close() print "Process finished" - - def start(self, filename): - if not self.writeXml(filename): - return + def start(self): - if not self.readXml(filename): + if not self.writeXml(self.filename): return - + self.createObjects() self.connectObjects() self.run() diff --git a/schainpy/controller_api.py b/schainpy/controller_api.py index d44d9e6..cb97963 100644 --- a/schainpy/controller_api.py +++ b/schainpy/controller_api.py @@ -4,15 +4,13 @@ from schainpy.controller import Project class ControllerThread(threading.Thread, Project): - def __init__(self, filename): + def __init__(self, filename=None, plotter_queue=None): threading.Thread.__init__(self) - Project.__init__(self) + Project.__init__(self, filename, plotter_queue) self.setDaemon(True) - self.filename = filename - self.lock = threading.Lock() self.control = {'stop':False, 'pause':False} diff --git a/schainpy/model/graphics/__init__.py b/schainpy/model/graphics/__init__.py index b298167..72dcc5d 100644 --- a/schainpy/model/graphics/__init__.py +++ b/schainpy/model/graphics/__init__.py @@ -2,4 +2,5 @@ from jroplot_voltage import * from jroplot_spectra import * from jroplot_heispectra import * from jroplot_correlation import * -from jroplot_parameters import * \ No newline at end of file +from jroplot_parameters import * +from jroplotter import * \ No newline at end of file diff --git a/schainpy/model/graphics/jroplotter.py b/schainpy/model/graphics/jroplotter.py new file mode 100644 index 0000000..485d169 --- /dev/null +++ b/schainpy/model/graphics/jroplotter.py @@ -0,0 +1,68 @@ +''' +Created on Jul 9, 2014 + +@author: roj-idl71 +''' +import os +import datetime +import numpy + +from figure import Figure + +class Plotter(Figure): + + isConfig = None + name = None + plotterQueue = None + + def __init__(self, plotter_name, plotter_queue=None): + + self.isConfig = False + self.name = plotter_name + self.plotterQueue = plotter_queue + + def getSubplots(self): + + nrow = self.nplots + ncol = 1 + return nrow, ncol + + def setup(self, **kwargs): + +# self.nplots = nplots +# +# self.createFigure(id=id, +# wintitle=wintitle, +# show=show) +# +# nrow,ncol = self.getSubplots() +# colspan = 3 +# rowspan = 1 +# +# for i in range(nplots): +# self.addAxes(nrow, ncol, i, 0, colspan, rowspan) + + + + print "Initializing ..." + + + def run(self, dataOut, **kwargs): + + """ + + Input: + dataOut : + id : + wintitle : + channelList : + show : + """ + + if not self.isConfig: + self.setup(**kwargs) + self.isConfig=True + + print "Putting data on %s queue:" %self.name + print kwargs + diff --git a/schainpy/model/proc/jroproc_base.py b/schainpy/model/proc/jroproc_base.py index 4b4d774..4aba04e 100644 --- a/schainpy/model/proc/jroproc_base.py +++ b/schainpy/model/proc/jroproc_base.py @@ -161,26 +161,31 @@ class ProcessingUnit(object): opType : Puede ser "self" o "external" - La operacion puede ser de dos tipos (callMethod or callObject): + Depende del tipo de operacion para llamar a:callMethod or callObject: - 1. Un metodo propio de esta clase: + 1. If opType = "self": Llama a un metodo propio de esta clase: + + name_method = getattr(self, name) + name_method(**kwargs) - opType = "self" - 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: + 2. If opType = "other" o"external": Llama al metodo "run()" de una instancia de la + clase "Operation" o de un derivado de ella: - opType = "other" or "external". + instanceName = self.operationList[opId] + instanceName.run(**kwargs) opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera usada para llamar a un metodo interno de la clase Processing - opId : Si la operacion es externa (opType = 'other'), entonces el "opId" sera - usada para llamar al metodo "run" de la clase Operation registrada con ese Id + opId : Si la operacion es externa (opType = 'other' o 'external), entonces el + "opId" sera usada para llamar al metodo "run" de la clase Operation + registrada anteriormente con ese Id Exception: Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: "addOperation" e identificado con el valor "opId" = el id de la operacion. - De lo contrario retornara un error del tipo IOError + De lo contrario retornara un error del tipo ValueError """ @@ -191,16 +196,19 @@ class ProcessingUnit(object): sts = self.callMethod(opName, **kwargs) - if opType == 'other' or opType == 'external': + elif opType == 'other' or opType == 'external' or opType == 'plotter': if not opId: raise ValueError, "opId parameter should be defined" if opId not in self.operations2RunDict.keys(): - raise ValueError, "Id operation has not been registered" + raise ValueError, "Any operation with id=%s has been added" %str(opId) sts = self.callObject(opId, **kwargs) + else: + raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType + return sts def setInput(self, dataIn):