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