##// END OF EJS Templates
Merge branch 'schain_mp' of http://jro-dev.igp.gob.pe/rhodecode/schain into schain_mp
José Chávez -
r910:bc968be652f0 merge
parent child
Show More
@@ -96,3 +96,7 ENV/
96 96
97 97 # mkdocs documentation
98 98 /site
99
100 # eclipse
101 .project
102 .pydevproject
@@ -4,4 +4,4 Created on Feb 7, 2012
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 __version__ = "2.2.5" No newline at end of file
7 __version__ = "2.3" No newline at end of file
@@ -438,6 +438,7 class OperationConf():
438 438
439 439 def createObject(self, plotter_queue=None):
440 440
441
441 442 if self.type == 'self':
442 443 raise ValueError, "This operation type cannot be created"
443 444
@@ -449,10 +450,10 class OperationConf():
449 450 opObj = Plotter(self.name, plotter_queue)
450 451
451 452 if self.type == 'external' or self.type == 'other':
452 print self.name
453
453 454 className = eval(self.name)
454 455 kwargs = self.getKwargs()
455 print kwargs
456
456 457 opObj = className(**kwargs)
457 458
458 459 return opObj
@@ -673,12 +674,16 class ProcUnitConf():
673 674
674 675 for opConfObj in self.opConfObjList:
675 676
676 if opConfObj.type == 'self':
677 if opConfObj.type=='self' and self.name=='run':
678 continue
679 elif opConfObj.type=='self':
680 procUnitObj.addOperationKwargs(opConfObj.id, **opConfObj.getKwargs())
677 681 continue
678 682
679 683 opObj = opConfObj.createObject(plotter_queue)
680 684
681 685 self.opObjDict[opConfObj.id] = opObj
686
682 687 procUnitObj.addOperation(opObj, opConfObj.id)
683 688
684 689 self.procUnitObj = procUnitObj
@@ -29,8 +29,9 class PlotData(Operation, Process):
29 29
30 30 def __init__(self, **kwargs):
31 31
32 Operation.__init__(self, **kwargs)
32 Operation.__init__(self, plot=True, **kwargs)
33 33 Process.__init__(self)
34 self.kwargs['code'] = self.CODE
34 35 self.mp = False
35 36 self.dataOut = None
36 37 self.isConfig = False
@@ -40,7 +41,7 class PlotData(Operation, Process):
40 41 self.show = kwargs.get('show', True)
41 42 self.save = kwargs.get('save', False)
42 43 self.colormap = kwargs.get('colormap', self.colormap)
43 self.showprofile = kwargs.get('showprofile', False)
44 self.showprofile = kwargs.get('showprofile', True)
44 45 self.title = kwargs.get('wintitle', '')
45 46 self.xaxis = kwargs.get('xaxis', 'time')
46 47 self.zmin = kwargs.get('zmin', None)
@@ -182,7 +183,7 class PlotSpectraData(PlotData):
182 183 self.axes.append(ax)
183 184 n += 1
184 185
185 self.figure.subplots_adjust(wspace=0.9, hspace=0.5)
186 self.figure.subplots_adjust(left=0.1, right=0.95, bottom=0.15, top=0.85, wspace=0.9, hspace=0.5)
186 187 self.figure.show()
187 188
188 189 def plot(self):
@@ -258,6 +259,8 class PlotRTIData(PlotData):
258 259 self.nrows = self.dataOut.nChannels
259 260 self.width = 10
260 261 self.height = 2.2*self.nrows
262 if self.nrows==1:
263 self.height += 1
261 264 self.ylabel = 'Range [Km]'
262 265 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
263 266
@@ -345,6 +348,8 class PlotCOHData(PlotRTIData):
345 348 self.nrows = self.dataOut.nPairs
346 349 self.width = 10
347 350 self.height = 2.2*self.nrows
351 if self.nrows==1:
352 self.height += 1
348 353 self.ylabel = 'Range [Km]'
349 354 self.titles = ['Channels {}'.format(x) for x in self.dataOut.pairsList]
350 355
@@ -354,6 +359,7 class PlotCOHData(PlotRTIData):
354 359 facecolor='w')
355 360 else:
356 361 self.figure.clf()
362 self.axes = []
357 363
358 364 for n in range(self.nrows):
359 365 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
@@ -363,8 +369,54 class PlotCOHData(PlotRTIData):
363 369 self.figure.subplots_adjust(hspace=0.5)
364 370 self.figure.show()
365 371
366 class PlotSNRData(PlotRTIData):
372 class PlotNoiseData(PlotData):
373 CODE = 'noise'
374
375 def setup(self):
376
377 self.ncols = 1
378 self.nrows = 1
379 self.width = 10
380 self.height = 3.2
381 self.ylabel = 'Intensity [dB]'
382 self.titles = ['Noise']
367 383
384 if self.figure is None:
385 self.figure = plt.figure(figsize=(self.width, self.height),
386 edgecolor='k',
387 facecolor='w')
388 else:
389 self.figure.clf()
390 self.axes = []
391
392 self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1)
393 self.ax.firsttime = True
394
395 self.figure.show()
396
397 def plot(self):
398
399 x = self.times
400 xmin = self.min_time
401 xmax = xmin+self.xrange*60*60
402 if self.ax.firsttime:
403 for ch in self.dataOut.channelList:
404 y = [self.data[self.CODE][t][ch] for t in self.times]
405 self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch))
406 self.ax.firsttime = False
407 self.ax.xaxis.set_major_formatter(FuncFormatter(func))
408 self.ax.xaxis.set_major_locator(LinearLocator(6))
409 self.ax.set_ylabel(self.ylabel)
410 plt.legend()
411 else:
412 for ch in self.dataOut.channelList:
413 y = [self.data[self.CODE][t][ch] for t in self.times]
414 self.ax.lines[ch].set_data(x, y)
415
416 self.ax.set_xlim(xmin, xmax)
417 self.ax.set_ylim(min(y)-5, max(y)+5)
418
419 class PlotSNRData(PlotRTIData):
368 420 CODE = 'snr'
369 421
370 422 class PlotDOPData(PlotRTIData):
@@ -372,6 +424,5 class PlotDOPData(PlotRTIData):
372 424 colormap = 'jet'
373 425
374 426 class PlotPHASEData(PlotCOHData):
375
376 427 CODE = 'phase'
377 428 colormap = 'seismic'
@@ -35,12 +35,20 class ProcessingUnit(object):
35 35 self.dataOut = None
36 36
37 37 self.operations2RunDict = {}
38 self.operationKwargs = {}
38 39
39 40 self.isConfig = False
40 41
41 42 self.args = args
42 43 self.kwargs = kwargs
43 44
45 def addOperationKwargs(self, objId, **kwargs):
46 '''
47 '''
48
49 self.operationKwargs[objId] = kwargs
50
51
44 52 def addOperation(self, opObj, objId):
45 53
46 54 """
@@ -80,7 +88,7 class ProcessingUnit(object):
80 88
81 89 raise NotImplementedError
82 90
83 def callMethod(self, name, **kwargs):
91 def callMethod(self, name, opId):
84 92
85 93 """
86 94 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
@@ -100,7 +108,7 class ProcessingUnit(object):
100 108 return False
101 109 else:
102 110 #Si no es un metodo RUN la entrada es la misma dataOut (interna)
103 if self.dataOut.isEmpty():
111 if self.dataOut is not None and self.dataOut.isEmpty():
104 112 return False
105 113
106 114 #Getting the pointer to method
@@ -109,11 +117,17 class ProcessingUnit(object):
109 117 #Executing the self method
110 118
111 119 if hasattr(self, 'mp'):
120 if name=='run':
112 121 if self.mp is False:
113 122 self.mp = True
114 123 self.start()
115 124 else:
116 methodToCall(**kwargs)
125 methodToCall(**self.operationKwargs[opId])
126 else:
127 if name=='run':
128 methodToCall(**self.kwargs)
129 else:
130 methodToCall(**self.operationKwargs[opId])
117 131
118 132 if self.dataOut is None:
119 133 return False
@@ -146,10 +160,12 class ProcessingUnit(object):
146 160
147 161 if hasattr(externalProcObj, 'mp'):
148 162 if externalProcObj.mp is False:
163 self.operationKwargs[objId] = externalProcObj.kwargs
149 164 externalProcObj.mp = True
150 165 externalProcObj.start()
151 166 else:
152 167 externalProcObj.run(self.dataOut, **externalProcObj.kwargs)
168 self.operationKwargs[objId] = externalProcObj.kwargs
153 169
154 170 return True
155 171
@@ -198,7 +214,7 class ProcessingUnit(object):
198 214 if not opName:
199 215 raise ValueError, "opName parameter should be defined"
200 216
201 sts = self.callMethod(opName, **self.kwargs)
217 sts = self.callMethod(opName, opId)
202 218
203 219 elif opType == 'other' or opType == 'external' or opType == 'plotter':
204 220
@@ -518,9 +518,6 class WindProfiler(Operation):
518 518
519 519 n = None
520 520
521 def __init__(self):
522 Operation.__init__(self)
523
524 521 def __calculateCosDir(self, elev, azim):
525 522 zen = (90 - elev)*numpy.pi/180
526 523 azim = azim*numpy.pi/180
@@ -1204,8 +1201,6 class WindProfiler(Operation):
1204 1201
1205 1202 class EWDriftsEstimation(Operation):
1206 1203
1207 def __init__(self):
1208 Operation.__init__(self)
1209 1204
1210 1205 def __correctValues(self, heiRang, phi, velRadial, SNR):
1211 1206 listPhi = phi.tolist()
@@ -262,15 +262,23 class ReceiverData(ProcessingUnit, Process):
262 262 Process.__init__(self)
263 263 self.mp = False
264 264 self.isConfig = False
265 self.isWebConfig = False
265 266 self.plottypes =[]
266 267 self.connections = 0
267 268 server = kwargs.get('server', 'zmq.pipe')
269 plot_server = kwargs.get('plot_server', 'zmq.web')
268 270 if 'tcp://' in server:
269 271 address = server
270 272 else:
271 273 address = 'ipc:///tmp/%s' % server
272 274
275 if 'tcp://' in plot_server:
276 plot_address = plot_server
277 else:
278 plot_address = 'ipc:///tmp/%s' % plot_server
279
273 280 self.address = address
281 self.plot_address = plot_address
274 282 self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')]
275 283 self.realtime = kwargs.get('realtime', False)
276 284 self.throttle_value = kwargs.get('throttle', 10)
@@ -362,8 +370,7 class ReceiverData(ProcessingUnit, Process):
362 370 self.sender = self.context.socket(zmq.PUB)
363 371 if self.realtime:
364 372 self.sender_web = self.context.socket(zmq.PUB)
365 # self.sender_web.setsockopt(zmq.PUBLISH, 'realtime')
366 self.sender_web.bind("ipc:///tmp/zmq.web")
373 self.sender_web.bind(self.plot_address)
367 374 self.sender.bind("ipc:///tmp/zmq.plots")
368 375
369 376 t = Thread(target=self.event_monitor, args=(monitor,))
@@ -393,3 +400,23 class ReceiverData(ProcessingUnit, Process):
393 400 self.started = True
394 401
395 402 return
403
404 def sendToWeb(self):
405
406 if not self.isWebConfig:
407 context = zmq.Context()
408 sender_web_config = context.socket(zmq.PUB)
409 if 'tcp://' in self.plot_address:
410 print self.plot_address
411 dum, address, port = self.plot_address.split(':')
412 conf_address = '{}:{}:{}'.format(dum, address, int(port)+1)
413 else:
414 conf_address = self.plot_address + '.config'
415 sender_web_config.bind(conf_address)
416
417 for kwargs in self.operationKwargs.values():
418 if 'plot' in kwargs:
419 sender_web_config.send_string(json.dumps(kwargs))
420 print kwargs
421 self.isWebConfig = True
422
General Comments 0
You need to be logged in to leave comments. Login now