From bc968be652f0e8a8d791acdb4679273a75c5e6d4 2017-05-03 13:39:26 From: José Chávez Date: 2017-05-03 13:39:26 Subject: [PATCH] Merge branch 'schain_mp' of http://jro-dev.igp.gob.pe/rhodecode/schain into schain_mp --- 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..6d3d898 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 @@ -40,7 +41,7 @@ class PlotData(Operation, Process): self.show = kwargs.get('show', True) self.save = kwargs.get('save', False) self.colormap = kwargs.get('colormap', self.colormap) - self.showprofile = kwargs.get('showprofile', False) + self.showprofile = kwargs.get('showprofile', True) self.title = kwargs.get('wintitle', '') self.xaxis = kwargs.get('xaxis', 'time') self.zmin = kwargs.get('zmin', None) @@ -182,7 +183,7 @@ class PlotSpectraData(PlotData): self.axes.append(ax) n += 1 - self.figure.subplots_adjust(wspace=0.9, hspace=0.5) + self.figure.subplots_adjust(left=0.1, right=0.95, bottom=0.15, top=0.85, wspace=0.9, hspace=0.5) self.figure.show() def plot(self): @@ -258,6 +259,8 @@ class PlotRTIData(PlotData): self.nrows = self.dataOut.nChannels self.width = 10 self.height = 2.2*self.nrows + if self.nrows==1: + self.height += 1 self.ylabel = 'Range [Km]' self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] @@ -345,6 +348,8 @@ class PlotCOHData(PlotRTIData): self.nrows = self.dataOut.nPairs self.width = 10 self.height = 2.2*self.nrows + if self.nrows==1: + self.height += 1 self.ylabel = 'Range [Km]' self.titles = ['Channels {}'.format(x) for x in self.dataOut.pairsList] @@ -354,6 +359,7 @@ class PlotCOHData(PlotRTIData): facecolor='w') else: self.figure.clf() + self.axes = [] for n in range(self.nrows): ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) @@ -363,8 +369,54 @@ class PlotCOHData(PlotRTIData): self.figure.subplots_adjust(hspace=0.5) self.figure.show() -class PlotSNRData(PlotRTIData): +class PlotNoiseData(PlotData): + CODE = 'noise' + + def setup(self): + + self.ncols = 1 + self.nrows = 1 + self.width = 10 + self.height = 3.2 + self.ylabel = 'Intensity [dB]' + self.titles = ['Noise'] + if self.figure is None: + self.figure = plt.figure(figsize=(self.width, self.height), + edgecolor='k', + facecolor='w') + else: + self.figure.clf() + self.axes = [] + + self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1) + self.ax.firsttime = True + + self.figure.show() + + def plot(self): + + x = self.times + xmin = self.min_time + xmax = xmin+self.xrange*60*60 + if self.ax.firsttime: + for ch in self.dataOut.channelList: + y = [self.data[self.CODE][t][ch] for t in self.times] + self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch)) + self.ax.firsttime = False + self.ax.xaxis.set_major_formatter(FuncFormatter(func)) + self.ax.xaxis.set_major_locator(LinearLocator(6)) + self.ax.set_ylabel(self.ylabel) + plt.legend() + else: + for ch in self.dataOut.channelList: + y = [self.data[self.CODE][t][ch] for t in self.times] + self.ax.lines[ch].set_data(x, y) + + self.ax.set_xlim(xmin, xmax) + self.ax.set_ylim(min(y)-5, max(y)+5) + +class PlotSNRData(PlotRTIData): CODE = 'snr' class PlotDOPData(PlotRTIData): @@ -372,6 +424,5 @@ class PlotDOPData(PlotRTIData): colormap = 'jet' class PlotPHASEData(PlotCOHData): - CODE = 'phase' colormap = 'seismic' 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 8f927e4..ef72bbc 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) @@ -360,10 +368,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,)) @@ -393,3 +400,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 +