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