##// END OF EJS Templates
Ajuste de los graficos Spectra y RTI para el caso en que no se grafiquen los perfiles de potencia
Daniel Valdez -
r271:0b4cc89b3407
parent child
Show More
@@ -1,1052 +1,1060
1 1 import numpy
2 2 import time, datetime
3 3 from graphics.figure import *
4 4
5 5 class CrossSpectraPlot(Figure):
6 6
7 7 __isConfig = None
8 8 __nsubplots = None
9 9
10 10 WIDTH = None
11 11 HEIGHT = None
12 12 WIDTHPROF = None
13 13 HEIGHTPROF = None
14 14 PREFIX = 'cspc'
15 15
16 16 def __init__(self):
17 17
18 18 self.__isConfig = False
19 19 self.__nsubplots = 4
20 20
21 21 self.WIDTH = 250
22 22 self.HEIGHT = 250
23 23 self.WIDTHPROF = 0
24 24 self.HEIGHTPROF = 0
25 25
26 26 def getSubplots(self):
27 27
28 28 ncol = 4
29 29 nrow = self.nplots
30 30
31 31 return nrow, ncol
32 32
33 33 def setup(self, idfigure, nplots, wintitle, showprofile=True):
34 34
35 35 self.__showprofile = showprofile
36 36 self.nplots = nplots
37 37
38 38 ncolspan = 1
39 39 colspan = 1
40 40
41 41 self.createFigure(idfigure = idfigure,
42 42 wintitle = wintitle,
43 43 widthplot = self.WIDTH + self.WIDTHPROF,
44 44 heightplot = self.HEIGHT + self.HEIGHTPROF)
45 45
46 46 nrow, ncol = self.getSubplots()
47 47
48 48 counter = 0
49 49 for y in range(nrow):
50 50 for x in range(ncol):
51 51 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
52 52
53 53 counter += 1
54 54
55 55 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
56 56 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, normalize=True,
57 57 save=False, figpath='./', figfile=None,
58 58 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r'):
59 59
60 60 """
61 61
62 62 Input:
63 63 dataOut :
64 64 idfigure :
65 65 wintitle :
66 66 channelList :
67 67 showProfile :
68 68 xmin : None,
69 69 xmax : None,
70 70 ymin : None,
71 71 ymax : None,
72 72 zmin : None,
73 73 zmax : None
74 74 """
75 75
76 76 if pairsList == None:
77 77 pairsIndexList = dataOut.pairsIndexList
78 78 else:
79 79 pairsIndexList = []
80 80 for pair in pairsList:
81 81 if pair not in dataOut.pairsList:
82 82 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
83 83 pairsIndexList.append(dataOut.pairsList.index(pair))
84 84
85 85 if pairsIndexList == []:
86 86 return
87 87
88 88 if len(pairsIndexList) > 4:
89 89 pairsIndexList = pairsIndexList[0:4]
90 90
91 91 factor = 1
92 92 if normalize:
93 93 factor = dataOut.normFactor
94 94 x = dataOut.getVelRange(1)
95 95 y = dataOut.getHeiRange()
96 96 z = dataOut.data_spc[:,:,:]/factor
97 97
98 98 avg = numpy.average(z, axis=1)
99 99 noise = dataOut.getNoise()/factor
100 100
101 101 zdB = 10*numpy.log10(z)
102 102 avgdB = 10*numpy.log10(avg)
103 103 noisedB = 10*numpy.log10(noise)
104 104
105 105
106 106 thisDatetime = dataOut.datatime
107 107 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
108 108 xlabel = "Velocity (m/s)"
109 109 ylabel = "Range (Km)"
110 110
111 111 if not self.__isConfig:
112 112
113 113 nplots = len(pairsIndexList)
114 114
115 115 self.setup(idfigure=idfigure,
116 116 nplots=nplots,
117 117 wintitle=wintitle,
118 118 showprofile=showprofile)
119 119
120 120 if xmin == None: xmin = numpy.nanmin(x)
121 121 if xmax == None: xmax = numpy.nanmax(x)
122 122 if ymin == None: ymin = numpy.nanmin(y)
123 123 if ymax == None: ymax = numpy.nanmax(y)
124 124 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
125 125 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
126 126
127 127 self.__isConfig = True
128 128
129 129 self.setWinTitle(title)
130 130
131 131 for i in range(self.nplots):
132 132 pair = dataOut.pairsList[pairsIndexList[i]]
133 133
134 134 title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]])
135 135 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
136 136 axes0 = self.axesList[i*self.__nsubplots]
137 137 axes0.pcolor(x, y, zdB,
138 138 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
139 139 xlabel=xlabel, ylabel=ylabel, title=title,
140 140 ticksize=9, colormap=power_cmap, cblabel='')
141 141
142 142 title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]])
143 143 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
144 144 axes0 = self.axesList[i*self.__nsubplots+1]
145 145 axes0.pcolor(x, y, zdB,
146 146 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
147 147 xlabel=xlabel, ylabel=ylabel, title=title,
148 148 ticksize=9, colormap=power_cmap, cblabel='')
149 149
150 150 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
151 151 coherence = numpy.abs(coherenceComplex)
152 152 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
153 153 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
154 154
155 155 title = "Coherence %d%d" %(pair[0], pair[1])
156 156 axes0 = self.axesList[i*self.__nsubplots+2]
157 157 axes0.pcolor(x, y, coherence,
158 158 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
159 159 xlabel=xlabel, ylabel=ylabel, title=title,
160 160 ticksize=9, colormap=coherence_cmap, cblabel='')
161 161
162 162 title = "Phase %d%d" %(pair[0], pair[1])
163 163 axes0 = self.axesList[i*self.__nsubplots+3]
164 164 axes0.pcolor(x, y, phase,
165 165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
166 166 xlabel=xlabel, ylabel=ylabel, title=title,
167 167 ticksize=9, colormap=phase_cmap, cblabel='')
168 168
169 169
170 170
171 171 self.draw()
172 172
173 173 if save:
174 174 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
175 175 if figfile == None:
176 176 figfile = self.getFilename(name = date)
177 177
178 178 self.saveFigure(figpath, figfile)
179 179
180 180
181 181 class RTIPlot(Figure):
182 182
183 183 __isConfig = None
184 184 __nsubplots = None
185 185 __missing = 1E30
186 186 WIDTHPROF = None
187 187 HEIGHTPROF = None
188 188 PREFIX = 'rti'
189 189
190 190 def __init__(self):
191 191
192 192 self.timerange = 2*60*60
193 193 self.__isConfig = False
194 194 self.__nsubplots = 1
195 195
196 196 self.WIDTH = 800
197 197 self.HEIGHT = 200
198 198 self.WIDTHPROF = 120
199 199 self.HEIGHTPROF = 0
200 200 self.x_buffer = None
201 201 self.avgdB_buffer = None
202 202
203 203 def getSubplots(self):
204 204
205 205 ncol = 1
206 206 nrow = self.nplots
207 207
208 208 return nrow, ncol
209 209
210 210 def setup(self, idfigure, nplots, wintitle, showprofile=True):
211 211
212 212 self.__showprofile = showprofile
213 213 self.nplots = nplots
214 214
215 215 ncolspan = 1
216 216 colspan = 1
217 widthplot = self.WIDTH
218 heightplot = self.HEIGHT
217 219 if showprofile:
218 220 ncolspan = 7
219 221 colspan = 6
220 222 self.__nsubplots = 2
223 widthplot += self.WIDTHPROF
224 heightplot += self.HEIGHTPROF
221 225
222 226 self.createFigure(idfigure = idfigure,
223 227 wintitle = wintitle,
224 widthplot = self.WIDTH + self.WIDTHPROF,
225 heightplot = self.HEIGHT + self.HEIGHTPROF)
228 widthplot = widthplot,
229 heightplot = heightplot)
226 230
227 231 nrow, ncol = self.getSubplots()
228 232
229 233 counter = 0
230 234 for y in range(nrow):
231 235 for x in range(ncol):
232 236
233 237 if counter >= self.nplots:
234 238 break
235 239
236 240 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
237 241
238 242 if showprofile:
239 243 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
240 244
241 245 counter += 1
242 246
243 247 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
244 248 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, normalize=True,
245 249 timerange=None,
246 250 save=False, figpath='./', figfile=None):
247 251
248 252 """
249 253
250 254 Input:
251 255 dataOut :
252 256 idfigure :
253 257 wintitle :
254 258 channelList :
255 259 showProfile :
256 260 xmin : None,
257 261 xmax : None,
258 262 ymin : None,
259 263 ymax : None,
260 264 zmin : None,
261 265 zmax : None
262 266 """
263 267
264 268 if channelList == None:
265 269 channelIndexList = dataOut.channelIndexList
266 270 else:
267 271 channelIndexList = []
268 272 for channel in channelList:
269 273 if channel not in dataOut.channelList:
270 274 raise ValueError, "Channel %d is not in dataOut.channelList"
271 275 channelIndexList.append(dataOut.channelList.index(channel))
272 276
273 277 if timerange != None:
274 278 self.timerange = timerange
275 279
276 280 tmin = None
277 281 tmax = None
278 282 factor = 1
279 283 if normalize:
280 284 factor = dataOut.normFactor
281 285 x = dataOut.getTimeRange()
282 286 y = dataOut.getHeiRange()
283 287
284 288 z = dataOut.data_spc[channelIndexList,:,:]/factor
285 289 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
286 290 avg = numpy.average(z, axis=1)
287 291
288 292 avgdB = 10.*numpy.log10(avg)
289 293
290 294
291 295 thisDatetime = dataOut.datatime
292 296 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
293 297 xlabel = "Velocity (m/s)"
294 298 ylabel = "Range (Km)"
295 299
296 300 if not self.__isConfig:
297 301
298 302 nplots = len(channelIndexList)
299 303
300 304 self.setup(idfigure=idfigure,
301 305 nplots=nplots,
302 306 wintitle=wintitle,
303 307 showprofile=showprofile)
304 308
305 309 tmin, tmax = self.getTimeLim(x, xmin, xmax)
306 310 if ymin == None: ymin = numpy.nanmin(y)
307 311 if ymax == None: ymax = numpy.nanmax(y)
308 312 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
309 313 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
310 314
311 315 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
312 316 self.x_buffer = numpy.array([])
313 317 self.avgdB_buffer = numpy.array([])
314 318 self.__isConfig = True
315 319
316 320
317 321 self.setWinTitle(title)
318 322
319 323 if len(self.avgdB_buffer)==0:
320 324 self.avgdB_buffer = avgdB
321 325 newxdim = 1
322 326 newydim = -1
323 327 else:
324 328 if x[0]>self.x_buffer[-1]:
325 329 gap = avgdB.copy()
326 330 gap[:] = self.__missing
327 331 self.avgdB_buffer = numpy.hstack((self.avgdB_buffer, gap))
328 332
329 333 self.avgdB_buffer = numpy.hstack((self.avgdB_buffer, avgdB))
330 334 newxdim = -1
331 335 newydim = len(y)
332 336
333 337 self.x_buffer = numpy.hstack((self.x_buffer, x))
334 338
335 339 self.avgdB_buffer = numpy.ma.masked_inside(self.avgdB_buffer,0.99*self.__missing,1.01*self.__missing)
336 340
337 341 for i in range(self.nplots):
338 342 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
339 343 axes = self.axesList[i*self.__nsubplots]
340 344 zdB = self.avgdB_buffer[i].reshape(newxdim,newydim)
341 345 axes.pcolor(self.x_buffer, y, zdB,
342 346 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
343 347 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
344 348 ticksize=9, cblabel='', cbsize="1%")
345 349
346 350 if self.__showprofile:
347 351 axes = self.axesList[i*self.__nsubplots +1]
348 352 axes.pline(avgdB[i], y,
349 353 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
350 354 xlabel='dB', ylabel='', title='',
351 355 ytick_visible=False,
352 356 grid='x')
353 357
354 358 self.draw()
355 359
356 360 if save:
357 361
358 362 if figfile == None:
359 363 figfile = self.getFilename(name = self.name)
360 364
361 365 self.saveFigure(figpath, figfile)
362 366
363 367 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
364 368 self.__isConfig = False
365 369
366 370 class SpectraPlot(Figure):
367 371
368 372 __isConfig = None
369 373 __nsubplots = None
370 374
371 375 WIDTHPROF = None
372 376 HEIGHTPROF = None
373 377 PREFIX = 'spc'
374 378
375 379 def __init__(self):
376 380
377 381 self.__isConfig = False
378 382 self.__nsubplots = 1
379 383
380 384 self.WIDTH = 230
381 385 self.HEIGHT = 250
382 386 self.WIDTHPROF = 120
383 387 self.HEIGHTPROF = 0
384 388
385 389 def getSubplots(self):
386 390
387 391 ncol = int(numpy.sqrt(self.nplots)+0.9)
388 392 nrow = int(self.nplots*1./ncol + 0.9)
389 393
390 394 return nrow, ncol
391 395
392 396 def setup(self, idfigure, nplots, wintitle, showprofile=True):
393 397
394 398 self.__showprofile = showprofile
395 399 self.nplots = nplots
396 400
397 401 ncolspan = 1
398 402 colspan = 1
403 widthplot = self.WIDTH
404 heightplot = self.HEIGHT
399 405 if showprofile:
400 406 ncolspan = 3
401 407 colspan = 2
402 408 self.__nsubplots = 2
403
409 widthplot += self.WIDTHPROF
410 heightplot += self.HEIGHTPROF
411
404 412 self.createFigure(idfigure = idfigure,
405 413 wintitle = wintitle,
406 widthplot = self.WIDTH + self.WIDTHPROF,
407 heightplot = self.HEIGHT + self.HEIGHTPROF)
414 widthplot = widthplot,
415 heightplot = heightplot)
408 416
409 417 nrow, ncol = self.getSubplots()
410 418
411 419 counter = 0
412 420 for y in range(nrow):
413 421 for x in range(ncol):
414 422
415 423 if counter >= self.nplots:
416 424 break
417 425
418 426 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
419 427
420 428 if showprofile:
421 429 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
422 430
423 431 counter += 1
424 432
425 433 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
426 434 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, normalize=True,
427 435 save=False, figpath='./', figfile=None):
428 436
429 437 """
430 438
431 439 Input:
432 440 dataOut :
433 441 idfigure :
434 442 wintitle :
435 443 channelList :
436 444 showProfile :
437 445 xmin : None,
438 446 xmax : None,
439 447 ymin : None,
440 448 ymax : None,
441 449 zmin : None,
442 450 zmax : None
443 451 """
444 452
445 453 if channelList == None:
446 454 channelIndexList = dataOut.channelIndexList
447 455 else:
448 456 channelIndexList = []
449 457 for channel in channelList:
450 458 if channel not in dataOut.channelList:
451 459 raise ValueError, "Channel %d is not in dataOut.channelList"
452 460 channelIndexList.append(dataOut.channelList.index(channel))
453 461 factor = 1
454 462 if normalize:
455 463 factor = dataOut.normFactor
456 464 x = dataOut.getVelRange(1)
457 465 y = dataOut.getHeiRange()
458 466
459 467 z = dataOut.data_spc[channelIndexList,:,:]/factor
460 468 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
461 469 avg = numpy.average(z, axis=1)
462 470 noise = dataOut.getNoise()/factor
463 471
464 472 zdB = 10*numpy.log10(z)
465 473 avgdB = 10*numpy.log10(avg)
466 474 noisedB = 10*numpy.log10(noise)
467 475
468 476 thisDatetime = dataOut.datatime
469 477 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
470 478 xlabel = "Velocity (m/s)"
471 479 ylabel = "Range (Km)"
472 480
473 481 if not self.__isConfig:
474 482
475 483 nplots = len(channelIndexList)
476 484
477 485 self.setup(idfigure=idfigure,
478 486 nplots=nplots,
479 487 wintitle=wintitle,
480 488 showprofile=showprofile)
481 489
482 490 if xmin == None: xmin = numpy.nanmin(x)
483 491 if xmax == None: xmax = numpy.nanmax(x)
484 492 if ymin == None: ymin = numpy.nanmin(y)
485 493 if ymax == None: ymax = numpy.nanmax(y)
486 494 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
487 495 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
488 496
489 497 self.__isConfig = True
490 498
491 499 self.setWinTitle(title)
492 500
493 501 for i in range(self.nplots):
494 502 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i])
495 503 axes = self.axesList[i*self.__nsubplots]
496 504 axes.pcolor(x, y, zdB[i,:,:],
497 505 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
498 506 xlabel=xlabel, ylabel=ylabel, title=title,
499 507 ticksize=9, cblabel='')
500 508
501 509 if self.__showprofile:
502 510 axes = self.axesList[i*self.__nsubplots +1]
503 511 axes.pline(avgdB[i], y,
504 512 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
505 513 xlabel='dB', ylabel='', title='',
506 514 ytick_visible=False,
507 515 grid='x')
508 516
509 517 noiseline = numpy.repeat(noisedB[i], len(y))
510 518 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
511 519
512 520 self.draw()
513 521
514 522 if save:
515 523 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
516 524 if figfile == None:
517 525 figfile = self.getFilename(name = date)
518 526
519 527 self.saveFigure(figpath, figfile)
520 528
521 529 class Scope(Figure):
522 530
523 531 __isConfig = None
524 532
525 533 def __init__(self):
526 534
527 535 self.__isConfig = False
528 536 self.WIDTH = 600
529 537 self.HEIGHT = 200
530 538
531 539 def getSubplots(self):
532 540
533 541 nrow = self.nplots
534 542 ncol = 3
535 543 return nrow, ncol
536 544
537 545 def setup(self, idfigure, nplots, wintitle):
538 546
539 547 self.nplots = nplots
540 548
541 549 self.createFigure(idfigure, wintitle)
542 550
543 551 nrow,ncol = self.getSubplots()
544 552 colspan = 3
545 553 rowspan = 1
546 554
547 555 for i in range(nplots):
548 556 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
549 557
550 558
551 559
552 560 def run(self, dataOut, idfigure, wintitle="", channelList=None,
553 561 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
554 562 figpath='./', figfile=None):
555 563
556 564 """
557 565
558 566 Input:
559 567 dataOut :
560 568 idfigure :
561 569 wintitle :
562 570 channelList :
563 571 xmin : None,
564 572 xmax : None,
565 573 ymin : None,
566 574 ymax : None,
567 575 """
568 576
569 577 if channelList == None:
570 578 channelIndexList = dataOut.channelIndexList
571 579 else:
572 580 channelIndexList = []
573 581 for channel in channelList:
574 582 if channel not in dataOut.channelList:
575 583 raise ValueError, "Channel %d is not in dataOut.channelList"
576 584 channelIndexList.append(dataOut.channelList.index(channel))
577 585
578 586 x = dataOut.heightList
579 587 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
580 588 y = y.real
581 589
582 590 thisDatetime = dataOut.datatime
583 591 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
584 592 xlabel = "Range (Km)"
585 593 ylabel = "Intensity"
586 594
587 595 if not self.__isConfig:
588 596 nplots = len(channelIndexList)
589 597
590 598 self.setup(idfigure=idfigure,
591 599 nplots=nplots,
592 600 wintitle=wintitle)
593 601
594 602 if xmin == None: xmin = numpy.nanmin(x)
595 603 if xmax == None: xmax = numpy.nanmax(x)
596 604 if ymin == None: ymin = numpy.nanmin(y)
597 605 if ymax == None: ymax = numpy.nanmax(y)
598 606
599 607 self.__isConfig = True
600 608
601 609 self.setWinTitle(title)
602 610
603 611 for i in range(len(self.axesList)):
604 612 title = "Channel %d" %(i)
605 613 axes = self.axesList[i]
606 614 ychannel = y[i,:]
607 615 axes.pline(x, ychannel,
608 616 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
609 617 xlabel=xlabel, ylabel=ylabel, title=title)
610 618
611 619 self.draw()
612 620
613 621 if save:
614 622 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
615 623 if figfile == None:
616 624 figfile = self.getFilename(name = date)
617 625
618 626 self.saveFigure(figpath, figfile)
619 627
620 628 class ProfilePlot(Figure):
621 629 __isConfig = None
622 630 __nsubplots = None
623 631
624 632 WIDTHPROF = None
625 633 HEIGHTPROF = None
626 634 PREFIX = 'spcprofile'
627 635
628 636 def __init__(self):
629 637 self.__isConfig = False
630 638 self.__nsubplots = 1
631 639
632 640 self.WIDTH = 300
633 641 self.HEIGHT = 500
634 642
635 643 def getSubplots(self):
636 644 ncol = 1
637 645 nrow = 1
638 646
639 647 return nrow, ncol
640 648
641 649 def setup(self, idfigure, nplots, wintitle):
642 650
643 651 self.nplots = nplots
644 652
645 653 ncolspan = 1
646 654 colspan = 1
647 655
648 656 self.createFigure(idfigure = idfigure,
649 657 wintitle = wintitle,
650 658 widthplot = self.WIDTH,
651 659 heightplot = self.HEIGHT)
652 660
653 661 nrow, ncol = self.getSubplots()
654 662
655 663 counter = 0
656 664 for y in range(nrow):
657 665 for x in range(ncol):
658 666 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
659 667
660 668 def run(self, dataOut, idfigure, wintitle="", channelList=None,
661 669 xmin=None, xmax=None, ymin=None, ymax=None, normalize=True,
662 670 save=False, figpath='./', figfile=None):
663 671
664 672 if channelList == None:
665 673 channelIndexList = dataOut.channelIndexList
666 674 channelList = dataOut.channelList
667 675 else:
668 676 channelIndexList = []
669 677 for channel in channelList:
670 678 if channel not in dataOut.channelList:
671 679 raise ValueError, "Channel %d is not in dataOut.channelList"
672 680 channelIndexList.append(dataOut.channelList.index(channel))
673 681
674 682 factor = 1
675 683 if normalize:
676 684 factor = dataOut.normFactor
677 685 y = dataOut.getHeiRange()
678 686 x = dataOut.data_spc[channelIndexList,:,:]/factor
679 687 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
680 688 avg = numpy.average(x, axis=1)
681 689
682 690 avgdB = 10*numpy.log10(avg)
683 691
684 692 thisDatetime = dataOut.datatime
685 693 title = "Power Profile"
686 694 xlabel = "dB"
687 695 ylabel = "Range (Km)"
688 696
689 697 if not self.__isConfig:
690 698
691 699 nplots = 1
692 700
693 701 self.setup(idfigure=idfigure,
694 702 nplots=nplots,
695 703 wintitle=wintitle)
696 704
697 705 if ymin == None: ymin = numpy.nanmin(y)
698 706 if ymax == None: ymax = numpy.nanmax(y)
699 707 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
700 708 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
701 709
702 710 self.__isConfig = True
703 711
704 712 self.setWinTitle(title)
705 713
706 714
707 715 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
708 716 axes = self.axesList[0]
709 717
710 718 legendlabels = ["channel %d"%x for x in channelList]
711 719 axes.pmultiline(avgdB, y,
712 720 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
713 721 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
714 722 ytick_visible=True, nxticks=5,
715 723 grid='x')
716 724
717 725 self.draw()
718 726
719 727 if save:
720 728 date = thisDatetime.strftime("%Y%m%d")
721 729 if figfile == None:
722 730 figfile = self.getFilename(name = date)
723 731
724 732 self.saveFigure(figpath, figfile)
725 733
726 734 class CoherenceMap(Figure):
727 735 __isConfig = None
728 736 __nsubplots = None
729 737
730 738 WIDTHPROF = None
731 739 HEIGHTPROF = None
732 740 PREFIX = 'cmap'
733 741 __missing = 1E30
734 742
735 743 def __init__(self):
736 744 self.timerange = 2*60*60
737 745 self.__isConfig = False
738 746 self.__nsubplots = 1
739 747
740 748 self.WIDTH = 800
741 749 self.HEIGHT = 200
742 750 self.WIDTHPROF = 120
743 751 self.HEIGHTPROF = 0
744 752 self.x_buffer = None
745 753 self.coherence_buffer = None
746 754 self.phase_buffer = None
747 755
748 756 def getSubplots(self):
749 757 ncol = 1
750 758 nrow = self.nplots*2
751 759
752 760 return nrow, ncol
753 761
754 762 def setup(self, idfigure, nplots, wintitle, showprofile=True):
755 763 self.__showprofile = showprofile
756 764 self.nplots = nplots
757 765
758 766 ncolspan = 1
759 767 colspan = 1
760 768 if showprofile:
761 769 ncolspan = 7
762 770 colspan = 6
763 771 self.__nsubplots = 2
764 772
765 773 self.createFigure(idfigure = idfigure,
766 774 wintitle = wintitle,
767 775 widthplot = self.WIDTH + self.WIDTHPROF,
768 776 heightplot = self.HEIGHT + self.HEIGHTPROF)
769 777
770 778 nrow, ncol = self.getSubplots()
771 779
772 780 for y in range(nrow):
773 781 for x in range(ncol):
774 782
775 783 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
776 784
777 785 if showprofile:
778 786 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
779 787
780 788 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
781 789 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
782 790 timerange=None,
783 791 save=False, figpath='./', figfile=None,
784 792 coherence_cmap='jet', phase_cmap='RdBu_r'):
785 793
786 794 if pairsList == None:
787 795 pairsIndexList = dataOut.pairsIndexList
788 796 else:
789 797 pairsIndexList = []
790 798 for pair in pairsList:
791 799 if pair not in dataOut.pairsList:
792 800 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
793 801 pairsIndexList.append(dataOut.pairsList.index(pair))
794 802
795 803 if timerange != None:
796 804 self.timerange = timerange
797 805
798 806 if pairsIndexList == []:
799 807 return
800 808
801 809 if len(pairsIndexList) > 4:
802 810 pairsIndexList = pairsIndexList[0:4]
803 811
804 812 tmin = None
805 813 tmax = None
806 814 x = dataOut.getTimeRange()
807 815 y = dataOut.getHeiRange()
808 816
809 817 thisDatetime = dataOut.datatime
810 818 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
811 819 xlabel = ""
812 820 ylabel = "Range (Km)"
813 821
814 822 if not self.__isConfig:
815 823 nplots = len(pairsIndexList)
816 824 self.setup(idfigure=idfigure,
817 825 nplots=nplots,
818 826 wintitle=wintitle,
819 827 showprofile=showprofile)
820 828
821 829 tmin, tmax = self.getTimeLim(x, xmin, xmax)
822 830 if ymin == None: ymin = numpy.nanmin(y)
823 831 if ymax == None: ymax = numpy.nanmax(y)
824 832
825 833 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
826 834 self.x_buffer = numpy.array([])
827 835 self.coherence_buffer = numpy.array([])
828 836 self.phase_buffer = numpy.array([])
829 837 self.__isConfig = True
830 838
831 839 self.setWinTitle(title)
832 840
833 841
834 842 pairArray = numpy.array(dataOut.pairsList)
835 843 pairArray = pairArray[pairsIndexList]
836 844 pair0ids = pairArray[:,0]
837 845 pair1ids = pairArray[:,1]
838 846
839 847 coherenceComplex = dataOut.data_cspc[pairsIndexList,:,:]/numpy.sqrt(dataOut.data_spc[pair0ids,:,:]*dataOut.data_spc[pair1ids,:,:])
840 848 avgcoherenceComplex = numpy.average(coherenceComplex, axis=1)
841 849 coherence = numpy.abs(avgcoherenceComplex)
842 850
843 851 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
844 852
845 853 if len(self.coherence_buffer)==0:
846 854 self.coherence_buffer = coherence
847 855 self.phase_buffer = phase
848 856 newxdim = 1
849 857 newydim = -1
850 858 else:
851 859 if x[0]>self.x_buffer[-1]:
852 860 gap = coherence.copy()
853 861 gap[:] = self.__missing
854 862 self.coherence_buffer = numpy.hstack((self.coherence_buffer, gap))
855 863 self.phase_buffer = numpy.hstack((self.phase_buffer, gap))
856 864
857 865 self.coherence_buffer = numpy.hstack((self.coherence_buffer, coherence))
858 866 self.phase_buffer = numpy.hstack((self.phase_buffer, phase))
859 867 newxdim = -1
860 868 newydim = len(y)
861 869
862 870 self.x_buffer = numpy.hstack((self.x_buffer, x))
863 871
864 872 self.coherence_buffer = numpy.ma.masked_inside(self.coherence_buffer,0.99*self.__missing,1.01*self.__missing)
865 873 self.phase_buffer = numpy.ma.masked_inside(self.phase_buffer,0.99*self.__missing,1.01*self.__missing)
866 874
867 875
868 876 for i in range(self.nplots):
869 877 counter = 0
870 878 z = self.coherence_buffer[i,:].reshape((newxdim,newydim))
871 879 title = "Coherence %d%d: %s" %(pair0ids[i], pair1ids[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
872 880 axes = self.axesList[i*self.__nsubplots*2]
873 881 axes.pcolor(self.x_buffer, y, z,
874 882 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
875 883 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
876 884 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
877 885
878 886 if self.__showprofile:
879 887 counter += 1
880 888 axes = self.axesList[i*self.__nsubplots*2 + counter]
881 889 axes.pline(coherence[i,:], y,
882 890 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
883 891 xlabel='', ylabel='', title='', ticksize=7,
884 892 ytick_visible=False, nxticks=5,
885 893 grid='x')
886 894
887 895 counter += 1
888 896
889 897 z = self.phase_buffer[i,:].reshape((newxdim,newydim))
890 898
891 899 title = "Phase %d%d: %s" %(pair0ids[i], pair1ids[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
892 900 axes = self.axesList[i*self.__nsubplots*2 + counter]
893 901 axes.pcolor(self.x_buffer, y, z,
894 902 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
895 903 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
896 904 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
897 905
898 906 if self.__showprofile:
899 907 counter += 1
900 908 axes = self.axesList[i*self.__nsubplots*2 + counter]
901 909 axes.pline(phase[i,:], y,
902 910 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
903 911 xlabel='', ylabel='', title='', ticksize=7,
904 912 ytick_visible=False, nxticks=4,
905 913 grid='x')
906 914
907 915 self.draw()
908 916
909 917 if save:
910 918
911 919 if figfile == None:
912 920 figfile = self.getFilename(name = self.name)
913 921
914 922 self.saveFigure(figpath, figfile)
915 923
916 924 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
917 925 self.__isConfig = False
918 926
919 927 class RTIfromNoise(Figure):
920 928
921 929 __isConfig = None
922 930 __nsubplots = None
923 931
924 932 PREFIX = 'rtinoise'
925 933
926 934 def __init__(self):
927 935
928 936 self.timerange = 24*60*60
929 937 self.__isConfig = False
930 938 self.__nsubplots = 1
931 939
932 940 self.WIDTH = 820
933 941 self.HEIGHT = 200
934 942 self.WIDTHPROF = 120
935 943 self.HEIGHTPROF = 0
936 944 self.xdata = None
937 945 self.ydata = None
938 946
939 947 def getSubplots(self):
940 948
941 949 ncol = 1
942 950 nrow = 1
943 951
944 952 return nrow, ncol
945 953
946 954 def setup(self, idfigure, nplots, wintitle, showprofile=True):
947 955
948 956 self.__showprofile = showprofile
949 957 self.nplots = nplots
950 958
951 959 ncolspan = 7
952 960 colspan = 6
953 961 self.__nsubplots = 2
954 962
955 963 self.createFigure(idfigure = idfigure,
956 964 wintitle = wintitle,
957 965 widthplot = self.WIDTH+self.WIDTHPROF,
958 966 heightplot = self.HEIGHT+self.HEIGHTPROF)
959 967
960 968 nrow, ncol = self.getSubplots()
961 969
962 970 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
963 971
964 972
965 973 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
966 974 xmin=None, xmax=None, ymin=None, ymax=None, normalize=True,
967 975 timerange=None,
968 976 save=False, figpath='./', figfile=None):
969 977
970 978 if channelList == None:
971 979 channelIndexList = dataOut.channelIndexList
972 980 channelList = dataOut.channelList
973 981 else:
974 982 channelIndexList = []
975 983 for channel in channelList:
976 984 if channel not in dataOut.channelList:
977 985 raise ValueError, "Channel %d is not in dataOut.channelList"
978 986 channelIndexList.append(dataOut.channelList.index(channel))
979 987
980 988 if timerange != None:
981 989 self.timerange = timerange
982 990
983 991 tmin = None
984 992 tmax = None
985 993 x = dataOut.getTimeRange()
986 994 y = dataOut.getHeiRange()
987 995 factor = 1
988 996 if normalize:
989 997 factor = dataOut.normFactor
990 998 noise = dataOut.getNoise()/factor
991 999 noisedB = 10*numpy.log10(noise)
992 1000
993 1001 thisDatetime = dataOut.datatime
994 1002 title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y"))
995 1003 xlabel = ""
996 1004 ylabel = "Range (Km)"
997 1005
998 1006 if not self.__isConfig:
999 1007
1000 1008 nplots = 1
1001 1009
1002 1010 self.setup(idfigure=idfigure,
1003 1011 nplots=nplots,
1004 1012 wintitle=wintitle,
1005 1013 showprofile=showprofile)
1006 1014
1007 1015 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1008 1016 if ymin == None: ymin = numpy.nanmin(noisedB)
1009 1017 if ymax == None: ymax = numpy.nanmax(noisedB)
1010 1018
1011 1019 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1012 1020 self.__isConfig = True
1013 1021
1014 1022 self.xdata = numpy.array([])
1015 1023 self.ydata = numpy.array([])
1016 1024
1017 1025 self.setWinTitle(title)
1018 1026
1019 1027
1020 1028 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
1021 1029
1022 1030 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1023 1031 axes = self.axesList[0]
1024 1032
1025 1033 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1026 1034
1027 1035 if len(self.ydata)==0:
1028 1036 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1029 1037 else:
1030 1038 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1031 1039
1032 1040
1033 1041 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1034 1042 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1035 1043 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1036 1044 XAxisAsTime=True
1037 1045 )
1038 1046
1039 1047 self.draw()
1040 1048
1041 1049 if save:
1042 1050
1043 1051 if figfile == None:
1044 1052 figfile = self.getFilename(name = self.name)
1045 1053
1046 1054 self.saveFigure(figpath, figfile)
1047 1055
1048 1056 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1049 1057 self.__isConfig = False
1050 1058 del self.xdata
1051 1059 del self.ydata
1052 1060 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now