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