##// END OF EJS Templates
Pulleado con master 15/08/17
J Gomez -
r1002:641b26f17149
parent child
Show More
@@ -1,958 +1,955
1 1
2 2 import os
3 3 import zmq
4 4 import time
5 5 import numpy
6 6 import datetime
7 7 import numpy as np
8 8 import matplotlib
9 9 import glob
10 10 matplotlib.use('TkAgg')
11 11 import matplotlib.pyplot as plt
12 12 from mpl_toolkits.axes_grid1 import make_axes_locatable
13 13 from matplotlib.ticker import FuncFormatter, LinearLocator
14 14 from multiprocessing import Process
15 15
16 16 from schainpy.model.proc.jroproc_base import Operation
17 17
18 18 plt.ion()
19 19
20 20 func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M'))
21 21
22 22 d1970 = datetime.datetime(1970,1,1)
23 23
24 24 class PlotData(Operation, Process):
25 25
26 26 CODE = 'Figure'
27 27 colormap = 'jro'
28 28 CONFLATE = False
29 29 __MAXNUMX = 80
30 30 __missing = 1E30
31 31
32 32 def __init__(self, **kwargs):
33 33
34 34 Operation.__init__(self, plot=True, **kwargs)
35 35 Process.__init__(self)
36 36 self.kwargs['code'] = self.CODE
37 37 self.mp = False
38 38 self.dataOut = None
39 39 self.isConfig = False
40 40 self.figure = None
41 41 self.axes = []
42 42 self.localtime = kwargs.pop('localtime', True)
43 43 self.show = kwargs.get('show', True)
44 44 self.save = kwargs.get('save', False)
45 45 self.colormap = kwargs.get('colormap', self.colormap)
46 46 self.colormap_coh = kwargs.get('colormap_coh', 'jet')
47 47 self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r')
48 48 self.showprofile = kwargs.get('showprofile', True)
49 49 self.title = kwargs.get('wintitle', '')
50 50 self.xaxis = kwargs.get('xaxis', 'frequency')
51 51 self.zmin = kwargs.get('zmin', None)
52 52 self.zmax = kwargs.get('zmax', None)
53 53 self.xmin = kwargs.get('xmin', None)
54 54 self.xmax = kwargs.get('xmax', None)
55 55 self.xrange = kwargs.get('xrange', 24)
56 56 self.ymin = kwargs.get('ymin', None)
57 57 self.ymax = kwargs.get('ymax', None)
58 58 self.__MAXNUMY = kwargs.get('decimation', 80)
59 59 self.throttle_value = 5
60 60 self.times = []
61 61 #self.interactive = self.kwargs['parent']
62 62
63 63 '''
64 64 this new parameter is created to plot data from varius channels at different figures
65 65 1. crear una lista de figuras donde se puedan plotear las figuras,
66 66 2. dar las opciones de configuracion a cada figura, estas opciones son iguales para ambas figuras
67 67 3. probar?
68 68 '''
69 69 self.ind_plt_ch = kwargs.get('ind_plt_ch', False)
70 70 self.figurelist = None
71 71
72 72
73 73 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
74 74
75 75 if x_buffer.shape[0] < 2:
76 76 return x_buffer, y_buffer, z_buffer
77 77
78 78 deltas = x_buffer[1:] - x_buffer[0:-1]
79 79 x_median = np.median(deltas)
80 80
81 81 index = np.where(deltas > 5*x_median)
82 82
83 83 if len(index[0]) != 0:
84 84 z_buffer[::, index[0], ::] = self.__missing
85 85 z_buffer = np.ma.masked_inside(z_buffer,
86 86 0.99*self.__missing,
87 87 1.01*self.__missing)
88 88
89 89 return x_buffer, y_buffer, z_buffer
90 90
91 91 def decimate(self):
92 92
93 93 # dx = int(len(self.x)/self.__MAXNUMX) + 1
94 94 dy = int(len(self.y)/self.__MAXNUMY) + 1
95 95
96 96 # x = self.x[::dx]
97 97 x = self.x
98 98 y = self.y[::dy]
99 99 z = self.z[::, ::, ::dy]
100 100
101 101 return x, y, z
102 102
103 103 '''
104 104 JM:
105 105 elimana las otras imagenes generadas debido a que lso workers no llegan en orden y le pueden
106 106 poner otro tiempo a la figura q no necesariamente es el ultimo.
107 107 Solo se realiza cuando termina la imagen.
108 108 Problemas:
109 109
110 110 File "/home/ci-81/workspace/schainv2.3/schainpy/model/graphics/jroplot_data.py", line 145, in __plot
111 111 for n, eachfigure in enumerate(self.figurelist):
112 112 TypeError: 'NoneType' object is not iterable
113 113
114 114 '''
115 115 def deleteanotherfiles(self):
116 116 figurenames=[]
117 117 if self.figurelist != None:
118 118 for n, eachfigure in enumerate(self.figurelist):
119 119 #add specific name for each channel in channelList
120 120 ghostfigname = os.path.join(self.save, '{}_{}_{}'.format(self.titles[n].replace(' ',''),self.CODE,
121 121 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d')))
122 122 figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE,
123 123 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
124 124
125 125 for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures
126 126 if ghostfigure != figname:
127 127 os.remove(ghostfigure)
128 128 print 'Removing GhostFigures:' , figname
129 129 else :
130 130 '''Erasing ghost images for just on******************'''
131 131 ghostfigname = os.path.join(self.save, '{}_{}'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d')))
132 132 figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
133 133 for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures
134 134 if ghostfigure != figname:
135 135 os.remove(ghostfigure)
136 136 print 'Removing GhostFigures:' , figname
137 137
138 138 def __plot(self):
139 139
140 140 print 'plotting...{}'.format(self.CODE)
141 141 if self.ind_plt_ch is False : #standard
142 142 if self.show:
143 143 self.figure.show()
144 144 self.plot()
145 145 plt.tight_layout()
146 146 self.figure.canvas.manager.set_window_title('{} {} - {}'.format(self.title, self.CODE.upper(),
147 147 datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d')))
148 148 else :
149 149 print 'len(self.figurelist): ',len(self.figurelist)
150 150 for n, eachfigure in enumerate(self.figurelist):
151 151 if self.show:
152 152 eachfigure.show()
153 153
154 self.plot() # ok? como elijo que figura?
155 #eachfigure.subplots_adjust(left=0.2)
156 #eachfigure.subplots_adjuccst(right=0.2)
154 self.plot()
157 155 eachfigure.tight_layout() # ajuste de cada subplot
158 156 eachfigure.canvas.manager.set_window_title('{} {} - {}'.format(self.title[n], self.CODE.upper(),
159 157 datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d')))
160 158
161 159 # if self.save:
162 160 # if self.ind_plt_ch is False : #standard
163 161 # figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,
164 162 # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
165 163 # print 'Saving figure: {}'.format(figname)
166 164 # self.figure.savefig(figname)
167 165 # else :
168 166 # for n, eachfigure in enumerate(self.figurelist):
169 167 # #add specific name for each channel in channelList
170 168 # figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n],self.CODE,
171 169 # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
172 170 #
173 171 # print 'Saving figure: {}'.format(figname)
174 172 # eachfigure.savefig(figname)
175 173
176 174 if self.ind_plt_ch is False :
177 175 self.figure.canvas.draw()
178 176 else :
179 177 for eachfigure in self.figurelist:
180 178 eachfigure.canvas.draw()
181 179
182 180 if self.save:
183 181 if self.ind_plt_ch is False : #standard
184 182 figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,
185 183 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
186 184 print 'Saving figure: {}'.format(figname)
187 185 self.figure.savefig(figname)
188 186 else :
189 187 for n, eachfigure in enumerate(self.figurelist):
190 188 #add specific name for each channel in channelList
191 189 figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE,
192 190 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
193 191
194 192 print 'Saving figure: {}'.format(figname)
195 193 eachfigure.savefig(figname)
196 194
197 195
198 196 def plot(self):
199 197
200 198 print 'plotting...{}'.format(self.CODE.upper())
201 199 return
202 200
203 201 def run(self):
204 202
205 203 print '[Starting] {}'.format(self.name)
206 204
207 205 context = zmq.Context()
208 206 receiver = context.socket(zmq.SUB)
209 207 receiver.setsockopt(zmq.SUBSCRIBE, '')
210 208 receiver.setsockopt(zmq.CONFLATE, self.CONFLATE)
211 209
212 210 if 'server' in self.kwargs['parent']:
213 211 receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server']))
214 212 else:
215 213 receiver.connect("ipc:///tmp/zmq.plots")
216 214
217 215 seconds_passed = 0
218 216
219 217 while True:
220 218 try:
221 219 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)#flags=zmq.NOBLOCK
222 220 self.started = self.data['STARTED']
223 221 self.dataOut = self.data['dataOut']
224 222
225 223 if (len(self.times) < len(self.data['times']) and not self.started and self.data['ENDED']):
226 224 continue
227 225
228 226 self.times = self.data['times']
229 227 self.times.sort()
230 228 self.throttle_value = self.data['throttle']
231 229 self.min_time = self.times[0]
232 230 self.max_time = self.times[-1]
233 231
234 232 if self.isConfig is False:
235 233 print 'setting up'
236 234 self.setup()
237 235 self.isConfig = True
238 236 self.__plot()
239 237
240 238 if self.data['ENDED'] is True:
241 239 print '********GRAPHIC ENDED********'
242 240 self.ended = True
243 241 self.isConfig = False
244 242 self.__plot()
245 #TODO : AUN NO FUNCIONA PARA COHERENCIA.
246 243 self.deleteanotherfiles() #CLPDG
247 244 elif seconds_passed >= self.data['throttle']:
248 245 print 'passed', seconds_passed
249 246 self.__plot()
250 247 seconds_passed = 0
251 248
252 249 except zmq.Again as e:
253 250 print 'Waiting for data...'
254 251 plt.pause(2)
255 252 seconds_passed += 2
256 253
257 254 def close(self):
258 255 if self.dataOut:
259 256 self.__plot()
260 257
261 258
262 259 class PlotSpectraData(PlotData):
263 260
264 261 CODE = 'spc'
265 262 colormap = 'jro'
266 263 CONFLATE = False
267 264
268 265 def setup(self):
269 266
270 267 ncolspan = 1
271 268 colspan = 1
272 269 self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9)
273 270 self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9)
274 271 self.width = 3.6*self.ncols
275 272 self.height = 3.2*self.nrows
276 273 if self.showprofile:
277 274 ncolspan = 3
278 275 colspan = 2
279 276 self.width += 1.2*self.ncols
280 277
281 278 self.ylabel = 'Range [Km]'
282 279 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
283 280
284 281 if self.figure is None:
285 282 self.figure = plt.figure(figsize=(self.width, self.height),
286 283 edgecolor='k',
287 284 facecolor='w')
288 285 else:
289 286 self.figure.clf()
290 287
291 288 n = 0
292 289 for y in range(self.nrows):
293 290 for x in range(self.ncols):
294 291 if n >= self.dataOut.nChannels:
295 292 break
296 293 ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan)
297 294 if self.showprofile:
298 295 ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1)
299 296
300 297 ax.firsttime = True
301 298 self.axes.append(ax)
302 299 n += 1
303 300
304 301 def plot(self):
305 302
306 303 if self.xaxis == "frequency":
307 304 x = self.dataOut.getFreqRange(1)/1000.
308 305 xlabel = "Frequency (kHz)"
309 306 elif self.xaxis == "time":
310 307 x = self.dataOut.getAcfRange(1)
311 308 xlabel = "Time (ms)"
312 309 else:
313 310 x = self.dataOut.getVelRange(1)
314 311 xlabel = "Velocity (m/s)"
315 312
316 313 y = self.dataOut.getHeiRange()
317 314 z = self.data[self.CODE]
318 315
319 316 for n, ax in enumerate(self.axes):
320 317 if ax.firsttime:
321 318 self.xmax = self.xmax if self.xmax else np.nanmax(x)
322 319 self.xmin = self.xmin if self.xmin else -self.xmax
323 320 self.ymin = self.ymin if self.ymin else np.nanmin(y)
324 321 self.ymax = self.ymax if self.ymax else np.nanmax(y)
325 322 self.zmin = self.zmin if self.zmin else np.nanmin(z)
326 323 self.zmax = self.zmax if self.zmax else np.nanmax(z)
327 324 ax.plot = ax.pcolormesh(x, y, z[n].T,
328 325 vmin=self.zmin,
329 326 vmax=self.zmax,
330 327 cmap=plt.get_cmap(self.colormap)
331 328 )
332 329 divider = make_axes_locatable(ax)
333 330 cax = divider.new_horizontal(size='3%', pad=0.05)
334 331 self.figure.add_axes(cax)
335 332 plt.colorbar(ax.plot, cax)
336 333
337 334 ax.set_xlim(self.xmin, self.xmax)
338 335 ax.set_ylim(self.ymin, self.ymax)
339 336
340 337 ax.set_ylabel(self.ylabel)
341 338 ax.set_xlabel(xlabel)
342 339
343 340 ax.firsttime = False
344 341
345 342 if self.showprofile:
346 343 ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0]
347 344 ax.ax_profile.set_xlim(self.zmin, self.zmax)
348 345 ax.ax_profile.set_ylim(self.ymin, self.ymax)
349 346 ax.ax_profile.set_xlabel('dB')
350 347 ax.ax_profile.grid(b=True, axis='x')
351 348 ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y,
352 349 color="k", linestyle="dashed", lw=2)[0]
353 350 [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()]
354 351 else:
355 352 ax.plot.set_array(z[n].T.ravel())
356 353 if self.showprofile:
357 354 ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y)
358 355 ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y)
359 356
360 357 ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]),
361 358 size=8)
362 359 self.saveTime = self.max_time
363 360
364 361
365 362 class PlotCrossSpectraData(PlotData):
366 363
367 364 CODE = 'cspc'
368 365 zmin_coh = None
369 366 zmax_coh = None
370 367 zmin_phase = None
371 368 zmax_phase = None
372 369 CONFLATE = False
373 370
374 371 def setup(self):
375 372
376 373 ncolspan = 1
377 374 colspan = 1
378 375 self.ncols = 2
379 376 self.nrows = self.dataOut.nPairs
380 377 self.width = 3.6*self.ncols
381 378 self.height = 3.2*self.nrows
382 379
383 380 self.ylabel = 'Range [Km]'
384 381 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
385 382
386 383 if self.figure is None:
387 384 self.figure = plt.figure(figsize=(self.width, self.height),
388 385 edgecolor='k',
389 386 facecolor='w')
390 387 else:
391 388 self.figure.clf()
392 389
393 390 for y in range(self.nrows):
394 391 for x in range(self.ncols):
395 392 ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1)
396 393 ax.firsttime = True
397 394 self.axes.append(ax)
398 395
399 396 def plot(self):
400 397
401 398 if self.xaxis == "frequency":
402 399 x = self.dataOut.getFreqRange(1)/1000.
403 400 xlabel = "Frequency (kHz)"
404 401 elif self.xaxis == "time":
405 402 x = self.dataOut.getAcfRange(1)
406 403 xlabel = "Time (ms)"
407 404 else:
408 405 x = self.dataOut.getVelRange(1)
409 406 xlabel = "Velocity (m/s)"
410 407
411 408 y = self.dataOut.getHeiRange()
412 409 z_coh = self.data['cspc_coh']
413 410 z_phase = self.data['cspc_phase']
414 411
415 412 for n in range(self.nrows):
416 413 ax = self.axes[2*n]
417 414 ax1 = self.axes[2*n+1]
418 415 if ax.firsttime:
419 416 self.xmax = self.xmax if self.xmax else np.nanmax(x)
420 417 self.xmin = self.xmin if self.xmin else -self.xmax
421 418 self.ymin = self.ymin if self.ymin else np.nanmin(y)
422 419 self.ymax = self.ymax if self.ymax else np.nanmax(y)
423 420 self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0
424 421 self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0
425 422 self.zmin_phase = self.zmin_phase if self.zmin_phase else -180
426 423 self.zmax_phase = self.zmax_phase if self.zmax_phase else 180
427 424
428 425 ax.plot = ax.pcolormesh(x, y, z_coh[n].T,
429 426 vmin=self.zmin_coh,
430 427 vmax=self.zmax_coh,
431 428 cmap=plt.get_cmap(self.colormap_coh)
432 429 )
433 430 divider = make_axes_locatable(ax)
434 431 cax = divider.new_horizontal(size='3%', pad=0.05)
435 432 self.figure.add_axes(cax)
436 433 plt.colorbar(ax.plot, cax)
437 434
438 435 ax.set_xlim(self.xmin, self.xmax)
439 436 ax.set_ylim(self.ymin, self.ymax)
440 437
441 438 ax.set_ylabel(self.ylabel)
442 439 ax.set_xlabel(xlabel)
443 440 ax.firsttime = False
444 441
445 442 ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T,
446 443 vmin=self.zmin_phase,
447 444 vmax=self.zmax_phase,
448 445 cmap=plt.get_cmap(self.colormap_phase)
449 446 )
450 447 divider = make_axes_locatable(ax1)
451 448 cax = divider.new_horizontal(size='3%', pad=0.05)
452 449 self.figure.add_axes(cax)
453 450 plt.colorbar(ax1.plot, cax)
454 451
455 452 ax1.set_xlim(self.xmin, self.xmax)
456 453 ax1.set_ylim(self.ymin, self.ymax)
457 454
458 455 ax1.set_ylabel(self.ylabel)
459 456 ax1.set_xlabel(xlabel)
460 457 ax1.firsttime = False
461 458 else:
462 459 ax.plot.set_array(z_coh[n].T.ravel())
463 460 ax1.plot.set_array(z_phase[n].T.ravel())
464 461
465 462 ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8)
466 463 ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8)
467 464 self.saveTime = self.max_time
468 465
469 466
470 467 class PlotSpectraMeanData(PlotSpectraData):
471 468
472 469 CODE = 'spc_mean'
473 470 colormap = 'jet'
474 471
475 472 def plot(self):
476 473
477 474 if self.xaxis == "frequency":
478 475 x = self.dataOut.getFreqRange(1)/1000.
479 476 xlabel = "Frequency (kHz)"
480 477 elif self.xaxis == "time":
481 478 x = self.dataOut.getAcfRange(1)
482 479 xlabel = "Time (ms)"
483 480 else:
484 481 x = self.dataOut.getVelRange(1)
485 482 xlabel = "Velocity (m/s)"
486 483
487 484 y = self.dataOut.getHeiRange()
488 485 z = self.data['spc']
489 486 mean = self.data['mean'][self.max_time]
490 487
491 488 for n, ax in enumerate(self.axes):
492 489
493 490 if ax.firsttime:
494 491 self.xmax = self.xmax if self.xmax else np.nanmax(x)
495 492 self.xmin = self.xmin if self.xmin else -self.xmax
496 493 self.ymin = self.ymin if self.ymin else np.nanmin(y)
497 494 self.ymax = self.ymax if self.ymax else np.nanmax(y)
498 495 self.zmin = self.zmin if self.zmin else np.nanmin(z)
499 496 self.zmax = self.zmax if self.zmax else np.nanmax(z)
500 497 ax.plt = ax.pcolormesh(x, y, z[n].T,
501 498 vmin=self.zmin,
502 499 vmax=self.zmax,
503 500 cmap=plt.get_cmap(self.colormap)
504 501 )
505 502 ax.plt_dop = ax.plot(mean[n], y,
506 503 color='k')[0]
507 504
508 505 divider = make_axes_locatable(ax)
509 506 cax = divider.new_horizontal(size='3%', pad=0.05)
510 507 self.figure.add_axes(cax)
511 508 plt.colorbar(ax.plt, cax)
512 509
513 510 ax.set_xlim(self.xmin, self.xmax)
514 511 ax.set_ylim(self.ymin, self.ymax)
515 512
516 513 ax.set_ylabel(self.ylabel)
517 514 ax.set_xlabel(xlabel)
518 515
519 516 ax.firsttime = False
520 517
521 518 if self.showprofile:
522 519 ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0]
523 520 ax.ax_profile.set_xlim(self.zmin, self.zmax)
524 521 ax.ax_profile.set_ylim(self.ymin, self.ymax)
525 522 ax.ax_profile.set_xlabel('dB')
526 523 ax.ax_profile.grid(b=True, axis='x')
527 524 ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y,
528 525 color="k", linestyle="dashed", lw=2)[0]
529 526 [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()]
530 527 else:
531 528 ax.plt.set_array(z[n].T.ravel())
532 529 ax.plt_dop.set_data(mean[n], y)
533 530 if self.showprofile:
534 531 ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y)
535 532 ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y)
536 533
537 534 ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]),
538 535 size=8)
539 536 self.saveTime = self.max_time
540 537
541 538
542 539 class PlotRTIData(PlotData):
543 540
544 541 CODE = 'rti'
545 542 colormap = 'jro'
546 543
547 544 def setup(self):
548 545 self.ncols = 1
549 546 self.nrows = self.dataOut.nChannels
550 547 self.width = 10
551 548 #TODO : arreglar la altura de la figura, esta hardcodeada.
552 549 #Se arreglo, testear!
553 550 if self.ind_plt_ch:
554 551 self.height = 3.2#*self.nrows if self.nrows<6 else 12
555 552 else:
556 553 self.height = 2.2*self.nrows if self.nrows<6 else 12
557 554
558 555 '''
559 556 if self.nrows==1:
560 557 self.height += 1
561 558 '''
562 559 self.ylabel = 'Range [Km]'
563 560 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
564 561
565 562 '''
566 563 Logica:
567 564 1) Si la variable ind_plt_ch es True, va a crear mas de 1 figura
568 565 2) guardamos "Figures" en una lista y "axes" en otra, quizas se deberia guardar el
569 566 axis dentro de "Figures" como un diccionario.
570 567 '''
571 568 if self.ind_plt_ch is False: #standard mode
572 569
573 570 if self.figure is None: #solo para la priemra vez
574 571 self.figure = plt.figure(figsize=(self.width, self.height),
575 572 edgecolor='k',
576 573 facecolor='w')
577 574 else:
578 575 self.figure.clf()
579 576 self.axes = []
580 577
581 578
582 579 for n in range(self.nrows):
583 580 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
584 581 #ax = self.figure(n+1)
585 582 ax.firsttime = True
586 583 self.axes.append(ax)
587 584
588 585 else : #append one figure foreach channel in channelList
589 586 if self.figurelist == None:
590 587 self.figurelist = []
591 588 for n in range(self.nrows):
592 589 self.figure = plt.figure(figsize=(self.width, self.height),
593 590 edgecolor='k',
594 591 facecolor='w')
595 592 #add always one subplot
596 593 self.figurelist.append(self.figure)
597 594
598 595 else : # cada dia nuevo limpia el axes, pero mantiene el figure
599 596 for eachfigure in self.figurelist:
600 597 eachfigure.clf() # eliminaria todas las figuras de la lista?
601 598 self.axes = []
602 599
603 600 for eachfigure in self.figurelist:
604 601 ax = eachfigure.add_subplot(1,1,1) #solo 1 axis por figura
605 602 #ax = self.figure(n+1)
606 603 ax.firsttime = True
607 604 #Cada figura tiene un distinto puntero
608 605 self.axes.append(ax)
609 606 #plt.close(eachfigure)
610 607
611 608
612 609 def plot(self):
613 610
614 611 if self.ind_plt_ch is False: #standard mode
615 612 self.x = np.array(self.times)
616 613 self.y = self.dataOut.getHeiRange()
617 614 self.z = []
618 615
619 616 for ch in range(self.nrows):
620 617 self.z.append([self.data[self.CODE][t][ch] for t in self.times])
621 618
622 619 self.z = np.array(self.z)
623 620 for n, ax in enumerate(self.axes):
624 621 x, y, z = self.fill_gaps(*self.decimate())
625 622 xmin = self.min_time
626 623 xmax = xmin+self.xrange*60*60
627 624 self.zmin = self.zmin if self.zmin else np.min(self.z)
628 625 self.zmax = self.zmax if self.zmax else np.max(self.z)
629 626 if ax.firsttime:
630 627 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
631 628 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
632 629 plot = ax.pcolormesh(x, y, z[n].T,
633 630 vmin=self.zmin,
634 631 vmax=self.zmax,
635 632 cmap=plt.get_cmap(self.colormap)
636 633 )
637 634 divider = make_axes_locatable(ax)
638 635 cax = divider.new_horizontal(size='2%', pad=0.05)
639 636 self.figure.add_axes(cax)
640 637 plt.colorbar(plot, cax)
641 638 ax.set_ylim(self.ymin, self.ymax)
642 639 ax.xaxis.set_major_formatter(FuncFormatter(func))
643 640 ax.xaxis.set_major_locator(LinearLocator(6))
644 641 ax.set_ylabel(self.ylabel)
645 642 if self.xmin is None:
646 643 xmin = self.min_time
647 644 else:
648 645 xmin = (datetime.datetime.combine(self.dataOut.datatime.date(),
649 646 datetime.time(self.xmin, 0, 0))-d1970).total_seconds()
650 647 ax.set_xlim(xmin, xmax)
651 648 ax.firsttime = False
652 649 else:
653 650 ax.collections.remove(ax.collections[0])
654 651 ax.set_xlim(xmin, xmax)
655 652 plot = ax.pcolormesh(x, y, z[n].T,
656 653 vmin=self.zmin,
657 654 vmax=self.zmax,
658 655 cmap=plt.get_cmap(self.colormap)
659 656 )
660 657 ax.set_title('{} {}'.format(self.titles[n],
661 658 datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
662 659 size=8)
663 660
664 661 self.saveTime = self.min_time
665 662 else :
666 663 self.x = np.array(self.times)
667 664 self.y = self.dataOut.getHeiRange()
668 665 self.z = []
669 666
670 667 for ch in range(self.nrows):
671 668 self.z.append([self.data[self.CODE][t][ch] for t in self.times])
672 669
673 670 self.z = np.array(self.z)
674 671 for n, eachfigure in enumerate(self.figurelist): #estaba ax in axes
675 672
676 673 x, y, z = self.fill_gaps(*self.decimate())
677 674 xmin = self.min_time
678 675 xmax = xmin+self.xrange*60*60
679 676 self.zmin = self.zmin if self.zmin else np.min(self.z)
680 677 self.zmax = self.zmax if self.zmax else np.max(self.z)
681 678 if self.axes[n].firsttime:
682 679 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
683 680 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
684 681 plot = self.axes[n].pcolormesh(x, y, z[n].T,
685 682 vmin=self.zmin,
686 683 vmax=self.zmax,
687 684 cmap=plt.get_cmap(self.colormap)
688 685 )
689 686 divider = make_axes_locatable(self.axes[n])
690 687 cax = divider.new_horizontal(size='2%', pad=0.05)
691 688 eachfigure.add_axes(cax)
692 689 #self.figure2.add_axes(cax)
693 690 plt.colorbar(plot, cax)
694 691 self.axes[n].set_ylim(self.ymin, self.ymax)
695 692
696 693 self.axes[n].xaxis.set_major_formatter(FuncFormatter(func))
697 694 self.axes[n].xaxis.set_major_locator(LinearLocator(6))
698 695
699 696 self.axes[n].set_ylabel(self.ylabel)
700 697
701 698 if self.xmin is None:
702 699 xmin = self.min_time
703 700 else:
704 701 xmin = (datetime.datetime.combine(self.dataOut.datatime.date(),
705 702 datetime.time(self.xmin, 0, 0))-d1970).total_seconds()
706 703
707 704 self.axes[n].set_xlim(xmin, xmax)
708 705 self.axes[n].firsttime = False
709 706 else:
710 707 self.axes[n].collections.remove(self.axes[n].collections[0])
711 708 self.axes[n].set_xlim(xmin, xmax)
712 709 plot = self.axes[n].pcolormesh(x, y, z[n].T,
713 710 vmin=self.zmin,
714 711 vmax=self.zmax,
715 712 cmap=plt.get_cmap(self.colormap)
716 713 )
717 714 self.axes[n].set_title('{} {}'.format(self.titles[n],
718 715 datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
719 716 size=8)
720 717
721 718 self.saveTime = self.min_time
722 719
723 720
724 721 class PlotCOHData(PlotRTIData):
725 722
726 723 CODE = 'coh'
727 724
728 725 def setup(self):
729 726
730 727 self.ncols = 1
731 728 self.nrows = self.dataOut.nPairs
732 729 self.width = 10
733 730 self.height = 2.2*self.nrows if self.nrows<6 else 12
734 731 self.ind_plt_ch = False #just for coherence and phase
735 732 if self.nrows==1:
736 733 self.height += 1
737 734 self.ylabel = 'Range [Km]'
738 735 self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList]
739 736
740 737 if self.figure is None:
741 738 self.figure = plt.figure(figsize=(self.width, self.height),
742 739 edgecolor='k',
743 740 facecolor='w')
744 741 else:
745 742 self.figure.clf()
746 743 self.axes = []
747 744
748 745 for n in range(self.nrows):
749 746 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
750 747 ax.firsttime = True
751 748 self.axes.append(ax)
752 749
753 750
754 751 class PlotNoiseData(PlotData):
755 752 CODE = 'noise'
756 753
757 754 def setup(self):
758 755
759 756 self.ncols = 1
760 757 self.nrows = 1
761 758 self.width = 10
762 759 self.height = 3.2
763 760 self.ylabel = 'Intensity [dB]'
764 761 self.titles = ['Noise']
765 762
766 763 if self.figure is None:
767 764 self.figure = plt.figure(figsize=(self.width, self.height),
768 765 edgecolor='k',
769 766 facecolor='w')
770 767 else:
771 768 self.figure.clf()
772 769 self.axes = []
773 770
774 771 self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1)
775 772 self.ax.firsttime = True
776 773
777 774 def plot(self):
778 775
779 776 x = self.times
780 777 xmin = self.min_time
781 778 xmax = xmin+self.xrange*60*60
782 779 if self.ax.firsttime:
783 780 for ch in self.dataOut.channelList:
784 781 y = [self.data[self.CODE][t][ch] for t in self.times]
785 782 self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch))
786 783 self.ax.firsttime = False
787 784 self.ax.xaxis.set_major_formatter(FuncFormatter(func))
788 785 self.ax.xaxis.set_major_locator(LinearLocator(6))
789 786 self.ax.set_ylabel(self.ylabel)
790 787 plt.legend()
791 788 else:
792 789 for ch in self.dataOut.channelList:
793 790 y = [self.data[self.CODE][t][ch] for t in self.times]
794 791 self.ax.lines[ch].set_data(x, y)
795 792
796 793 self.ax.set_xlim(xmin, xmax)
797 794 self.ax.set_ylim(min(y)-5, max(y)+5)
798 795 self.saveTime = self.min_time
799 796
800 797
801 798 class PlotWindProfilerData(PlotRTIData):
802 799
803 800 CODE = 'wind'
804 801 colormap = 'seismic'
805 802
806 803 def setup(self):
807 804 self.ncols = 1
808 805 self.nrows = self.dataOut.data_output.shape[0]
809 806 self.width = 10
810 807 self.height = 2.2*self.nrows
811 808 self.ylabel = 'Height [Km]'
812 809 self.titles = ['Zonal Wind' ,'Meridional Wind', 'Vertical Wind']
813 810 self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
814 811 self.windFactor = [1, 1, 100]
815 812
816 813 if self.figure is None:
817 814 self.figure = plt.figure(figsize=(self.width, self.height),
818 815 edgecolor='k',
819 816 facecolor='w')
820 817 else:
821 818 self.figure.clf()
822 819 self.axes = []
823 820
824 821 for n in range(self.nrows):
825 822 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
826 823 ax.firsttime = True
827 824 self.axes.append(ax)
828 825
829 826 def plot(self):
830 827
831 828 self.x = np.array(self.times)
832 829 self.y = self.dataOut.heightList
833 830 self.z = []
834 831
835 832 for ch in range(self.nrows):
836 833 self.z.append([self.data['output'][t][ch] for t in self.times])
837 834
838 835 self.z = np.array(self.z)
839 836 self.z = numpy.ma.masked_invalid(self.z)
840 837
841 838 cmap=plt.get_cmap(self.colormap)
842 839 cmap.set_bad('black', 1.)
843 840
844 841 for n, ax in enumerate(self.axes):
845 842 x, y, z = self.fill_gaps(*self.decimate())
846 843 xmin = self.min_time
847 844 xmax = xmin+self.xrange*60*60
848 845 if ax.firsttime:
849 846 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
850 847 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
851 848 self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :]))
852 849 self.zmin = self.zmin if self.zmin else -self.zmax
853 850
854 851 plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n],
855 852 vmin=self.zmin,
856 853 vmax=self.zmax,
857 854 cmap=cmap
858 855 )
859 856 divider = make_axes_locatable(ax)
860 857 cax = divider.new_horizontal(size='2%', pad=0.05)
861 858 self.figure.add_axes(cax)
862 859 cb = plt.colorbar(plot, cax)
863 860 cb.set_label(self.clabels[n])
864 861 ax.set_ylim(self.ymin, self.ymax)
865 862
866 863 ax.xaxis.set_major_formatter(FuncFormatter(func))
867 864 ax.xaxis.set_major_locator(LinearLocator(6))
868 865
869 866 ax.set_ylabel(self.ylabel)
870 867
871 868 ax.set_xlim(xmin, xmax)
872 869 ax.firsttime = False
873 870 else:
874 871 ax.collections.remove(ax.collections[0])
875 872 ax.set_xlim(xmin, xmax)
876 873 plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n],
877 874 vmin=self.zmin,
878 875 vmax=self.zmax,
879 876 cmap=plt.get_cmap(self.colormap)
880 877 )
881 878 ax.set_title('{} {}'.format(self.titles[n],
882 879 datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
883 880 size=8)
884 881
885 882 self.saveTime = self.min_time
886 883
887 884
888 885 class PlotSNRData(PlotRTIData):
889 886 CODE = 'snr'
890 887 colormap = 'jet'
891 888
892 889 class PlotDOPData(PlotRTIData):
893 890 CODE = 'dop'
894 891 colormap = 'jet'
895 892
896 893
897 894 class PlotPHASEData(PlotCOHData):
898 895 CODE = 'phase'
899 896 colormap = 'seismic'
900 897
901 898
902 899 class PlotSkyMapData(PlotData):
903 900
904 901 CODE = 'met'
905 902
906 903 def setup(self):
907 904
908 905 self.ncols = 1
909 906 self.nrows = 1
910 907 self.width = 7.2
911 908 self.height = 7.2
912 909
913 910 self.xlabel = 'Zonal Zenith Angle (deg)'
914 911 self.ylabel = 'Meridional Zenith Angle (deg)'
915 912
916 913 if self.figure is None:
917 914 self.figure = plt.figure(figsize=(self.width, self.height),
918 915 edgecolor='k',
919 916 facecolor='w')
920 917 else:
921 918 self.figure.clf()
922 919
923 920 self.ax = plt.subplot2grid((self.nrows, self.ncols), (0, 0), 1, 1, polar=True)
924 921 self.ax.firsttime = True
925 922
926 923
927 924 def plot(self):
928 925
929 926 arrayParameters = np.concatenate([self.data['param'][t] for t in self.times])
930 927 error = arrayParameters[:,-1]
931 928 indValid = numpy.where(error == 0)[0]
932 929 finalMeteor = arrayParameters[indValid,:]
933 930 finalAzimuth = finalMeteor[:,3]
934 931 finalZenith = finalMeteor[:,4]
935 932
936 933 x = finalAzimuth*numpy.pi/180
937 934 y = finalZenith
938 935
939 936 if self.ax.firsttime:
940 937 self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0]
941 938 self.ax.set_ylim(0,90)
942 939 self.ax.set_yticks(numpy.arange(0,90,20))
943 940 self.ax.set_xlabel(self.xlabel)
944 941 self.ax.set_ylabel(self.ylabel)
945 942 self.ax.yaxis.labelpad = 40
946 943 self.ax.firsttime = False
947 944 else:
948 945 self.ax.plot.set_data(x, y)
949 946
950 947
951 948 dt1 = datetime.datetime.fromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S')
952 949 dt2 = datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')
953 950 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
954 951 dt2,
955 952 len(x))
956 953 self.ax.set_title(title, size=8)
957 954
958 955 self.saveTime = self.max_time
General Comments 0
You need to be logged in to leave comments. Login now