From a52f011a763ea445ac4df03f023ab813c29718dc 2017-05-02 20:45:58 From: Juan C. Espinoza Date: 2017-05-02 20:45:58 Subject: [PATCH] Update version, fix kwargs for self operations (methods), Add SendToWeb operation to publish plots arguments --- diff --git a/.gitignore b/.gitignore index fdad5c7..c31424d 100644 --- a/.gitignore +++ b/.gitignore @@ -96,3 +96,7 @@ ENV/ # mkdocs documentation /site + +# eclipse +.project +.pydevproject diff --git a/schainpy/__init__.py b/schainpy/__init__.py index a395f37..3b8fe16 100644 --- a/schainpy/__init__.py +++ b/schainpy/__init__.py @@ -4,4 +4,4 @@ Created on Feb 7, 2012 @author $Author$ @version $Id$ ''' -__version__ = "2.2.5" \ No newline at end of file +__version__ = "2.3" \ No newline at end of file diff --git a/schainpy/controller.py b/schainpy/controller.py index f67c982..1d4530a 100644 --- a/schainpy/controller.py +++ b/schainpy/controller.py @@ -438,7 +438,8 @@ class OperationConf(): def createObject(self, plotter_queue=None): - if self.type == 'self': + + if self.type == 'self': raise ValueError, "This operation type cannot be created" if self.type == 'plotter': @@ -449,10 +450,10 @@ class OperationConf(): opObj = Plotter(self.name, plotter_queue) if self.type == 'external' or self.type == 'other': - print self.name + className = eval(self.name) kwargs = self.getKwargs() - print kwargs + opObj = className(**kwargs) return opObj @@ -671,14 +672,18 @@ class ProcUnitConf(): kwargs = self.getKwargs() procUnitObj = className(**kwargs) - for opConfObj in self.opConfObjList: - - if opConfObj.type == 'self': + for opConfObj in self.opConfObjList: + + if opConfObj.type=='self' and self.name=='run': + continue + elif opConfObj.type=='self': + procUnitObj.addOperationKwargs(opConfObj.id, **opConfObj.getKwargs()) continue opObj = opConfObj.createObject(plotter_queue) self.opObjDict[opConfObj.id] = opObj + procUnitObj.addOperation(opObj, opConfObj.id) self.procUnitObj = procUnitObj diff --git a/schainpy/model/graphics/jroplot_data.py b/schainpy/model/graphics/jroplot_data.py index 42c1655..e8eaf0d 100644 --- a/schainpy/model/graphics/jroplot_data.py +++ b/schainpy/model/graphics/jroplot_data.py @@ -29,8 +29,9 @@ class PlotData(Operation, Process): def __init__(self, **kwargs): - Operation.__init__(self, **kwargs) + Operation.__init__(self, plot=True, **kwargs) Process.__init__(self) + self.kwargs['code'] = self.CODE self.mp = False self.dataOut = None self.isConfig = False diff --git a/schainpy/model/proc/jroproc_base.py b/schainpy/model/proc/jroproc_base.py index 2362475..08e6beb 100644 --- a/schainpy/model/proc/jroproc_base.py +++ b/schainpy/model/proc/jroproc_base.py @@ -35,12 +35,20 @@ class ProcessingUnit(object): self.dataOut = None self.operations2RunDict = {} + self.operationKwargs = {} self.isConfig = False self.args = args self.kwargs = kwargs + def addOperationKwargs(self, objId, **kwargs): + ''' + ''' + + self.operationKwargs[objId] = kwargs + + def addOperation(self, opObj, objId): """ @@ -80,7 +88,7 @@ class ProcessingUnit(object): raise NotImplementedError - def callMethod(self, name, **kwargs): + def callMethod(self, name, opId): """ Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. @@ -100,7 +108,7 @@ class ProcessingUnit(object): return False else: #Si no es un metodo RUN la entrada es la misma dataOut (interna) - if self.dataOut.isEmpty(): + if self.dataOut is not None and self.dataOut.isEmpty(): return False #Getting the pointer to method @@ -109,11 +117,17 @@ class ProcessingUnit(object): #Executing the self method if hasattr(self, 'mp'): - if self.mp is False: - self.mp = True - self.start() + if name=='run': + if self.mp is False: + self.mp = True + self.start() + else: + methodToCall(**self.operationKwargs[opId]) else: - methodToCall(**kwargs) + if name=='run': + methodToCall(**self.kwargs) + else: + methodToCall(**self.operationKwargs[opId]) if self.dataOut is None: return False @@ -146,10 +160,12 @@ class ProcessingUnit(object): if hasattr(externalProcObj, 'mp'): if externalProcObj.mp is False: + self.operationKwargs[objId] = externalProcObj.kwargs externalProcObj.mp = True externalProcObj.start() else: externalProcObj.run(self.dataOut, **externalProcObj.kwargs) + self.operationKwargs[objId] = externalProcObj.kwargs return True @@ -198,7 +214,7 @@ class ProcessingUnit(object): if not opName: raise ValueError, "opName parameter should be defined" - sts = self.callMethod(opName, **self.kwargs) + sts = self.callMethod(opName, opId) elif opType == 'other' or opType == 'external' or opType == 'plotter': diff --git a/schainpy/model/proc/jroproc_parameters.py b/schainpy/model/proc/jroproc_parameters.py index 9ca3b35..c0ed146 100644 --- a/schainpy/model/proc/jroproc_parameters.py +++ b/schainpy/model/proc/jroproc_parameters.py @@ -518,9 +518,6 @@ class WindProfiler(Operation): n = None - def __init__(self): - Operation.__init__(self) - def __calculateCosDir(self, elev, azim): zen = (90 - elev)*numpy.pi/180 azim = azim*numpy.pi/180 @@ -1204,8 +1201,6 @@ class WindProfiler(Operation): class EWDriftsEstimation(Operation): - def __init__(self): - Operation.__init__(self) def __correctValues(self, heiRang, phi, velRadial, SNR): listPhi = phi.tolist() diff --git a/schainpy/model/utils/jroutils_publish.py b/schainpy/model/utils/jroutils_publish.py index 869245e..5984794 100644 --- a/schainpy/model/utils/jroutils_publish.py +++ b/schainpy/model/utils/jroutils_publish.py @@ -262,15 +262,23 @@ class ReceiverData(ProcessingUnit, Process): Process.__init__(self) self.mp = False self.isConfig = False + self.isWebConfig = False self.plottypes =[] self.connections = 0 server = kwargs.get('server', 'zmq.pipe') + plot_server = kwargs.get('plot_server', 'zmq.web') if 'tcp://' in server: address = server else: address = 'ipc:///tmp/%s' % server + if 'tcp://' in plot_server: + plot_address = plot_server + else: + plot_address = 'ipc:///tmp/%s' % plot_server + self.address = address + self.plot_address = plot_address self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] self.realtime = kwargs.get('realtime', False) self.throttle_value = kwargs.get('throttle', 10) @@ -358,10 +366,9 @@ class ReceiverData(ProcessingUnit, Process): self.receiver.bind(self.address) monitor = self.receiver.get_monitor_socket() self.sender = self.context.socket(zmq.PUB) - if self.realtime: - self.sender_web = self.context.socket(zmq.PUB) - # self.sender_web.setsockopt(zmq.PUBLISH, 'realtime') - self.sender_web.bind("ipc:///tmp/zmq.web") + if self.realtime: + self.sender_web = self.context.socket(zmq.PUB) + self.sender_web.bind(self.plot_address) self.sender.bind("ipc:///tmp/zmq.plots") t = Thread(target=self.event_monitor, args=(monitor,)) @@ -391,3 +398,23 @@ class ReceiverData(ProcessingUnit, Process): self.started = True return + + def sendToWeb(self): + + if not self.isWebConfig: + context = zmq.Context() + sender_web_config = context.socket(zmq.PUB) + if 'tcp://' in self.plot_address: + print self.plot_address + dum, address, port = self.plot_address.split(':') + conf_address = '{}:{}:{}'.format(dum, address, int(port)+1) + else: + conf_address = self.plot_address + '.config' + sender_web_config.bind(conf_address) + + for kwargs in self.operationKwargs.values(): + if 'plot' in kwargs: + sender_web_config.send_string(json.dumps(kwargs)) + print kwargs + self.isWebConfig = True +