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