##// END OF EJS Templates
se actualiza el titulo de cada grafico por canal empezando desde 1
Daniel Valdez -
r394:e89c72bcdad6
parent child
Show More
@@ -1,1363 +1,1363
1 1 import numpy
2 2 import time, datetime, os
3 3 from graphics.figure import *
4 4 def isRealtime(utcdatatime):
5 5 utcnow = time.mktime(datetime.datetime.utcnow().timetuple())
6 6 delta = utcnow - utcdatatime # abs
7 7 if delta >= 5*60.:
8 8 return False
9 9 return True
10 10
11 11 class CrossSpectraPlot(Figure):
12 12
13 13 __isConfig = None
14 14 __nsubplots = None
15 15
16 16 WIDTH = None
17 17 HEIGHT = None
18 18 WIDTHPROF = None
19 19 HEIGHTPROF = None
20 20 PREFIX = 'cspc'
21 21
22 22 def __init__(self):
23 23
24 24 self.__isConfig = False
25 25 self.__nsubplots = 4
26 26
27 27 self.WIDTH = 250
28 28 self.HEIGHT = 250
29 29 self.WIDTHPROF = 0
30 30 self.HEIGHTPROF = 0
31 31
32 32 def getSubplots(self):
33 33
34 34 ncol = 4
35 35 nrow = self.nplots
36 36
37 37 return nrow, ncol
38 38
39 39 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
40 40
41 41 self.__showprofile = showprofile
42 42 self.nplots = nplots
43 43
44 44 ncolspan = 1
45 45 colspan = 1
46 46
47 47 self.createFigure(idfigure = idfigure,
48 48 wintitle = wintitle,
49 49 widthplot = self.WIDTH + self.WIDTHPROF,
50 50 heightplot = self.HEIGHT + self.HEIGHTPROF,
51 51 show=True)
52 52
53 53 nrow, ncol = self.getSubplots()
54 54
55 55 counter = 0
56 56 for y in range(nrow):
57 57 for x in range(ncol):
58 58 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
59 59
60 60 counter += 1
61 61
62 62 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
63 63 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
64 64 save=False, figpath='./', figfile=None,
65 65 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
66 66
67 67 """
68 68
69 69 Input:
70 70 dataOut :
71 71 idfigure :
72 72 wintitle :
73 73 channelList :
74 74 showProfile :
75 75 xmin : None,
76 76 xmax : None,
77 77 ymin : None,
78 78 ymax : None,
79 79 zmin : None,
80 80 zmax : None
81 81 """
82 82
83 83 if pairsList == None:
84 84 pairsIndexList = dataOut.pairsIndexList
85 85 else:
86 86 pairsIndexList = []
87 87 for pair in pairsList:
88 88 if pair not in dataOut.pairsList:
89 89 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
90 90 pairsIndexList.append(dataOut.pairsList.index(pair))
91 91
92 92 if pairsIndexList == []:
93 93 return
94 94
95 95 if len(pairsIndexList) > 4:
96 96 pairsIndexList = pairsIndexList[0:4]
97 97 factor = dataOut.normFactor
98 98 x = dataOut.getVelRange(1)
99 99 y = dataOut.getHeiRange()
100 100 z = dataOut.data_spc[:,:,:]/factor
101 101 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
102 102 avg = numpy.abs(numpy.average(z, axis=1))
103 103 noise = dataOut.getNoise()/factor
104 104
105 105 zdB = 10*numpy.log10(z)
106 106 avgdB = 10*numpy.log10(avg)
107 107 noisedB = 10*numpy.log10(noise)
108 108
109 109
110 110 #thisDatetime = dataOut.datatime
111 111 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
112 112 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
113 113 xlabel = "Velocity (m/s)"
114 114 ylabel = "Range (Km)"
115 115
116 116 if not self.__isConfig:
117 117
118 118 nplots = len(pairsIndexList)
119 119
120 120 self.setup(idfigure=idfigure,
121 121 nplots=nplots,
122 122 wintitle=wintitle,
123 123 showprofile=showprofile,
124 124 show=show)
125 125
126 126 if xmin == None: xmin = numpy.nanmin(x)
127 127 if xmax == None: xmax = numpy.nanmax(x)
128 128 if ymin == None: ymin = numpy.nanmin(y)
129 129 if ymax == None: ymax = numpy.nanmax(y)
130 130 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
131 131 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
132 132
133 133 self.__isConfig = True
134 134
135 135 self.setWinTitle(title)
136 136
137 137 for i in range(self.nplots):
138 138 pair = dataOut.pairsList[pairsIndexList[i]]
139 139
140 140 title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]])
141 141 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
142 142 axes0 = self.axesList[i*self.__nsubplots]
143 143 axes0.pcolor(x, y, zdB,
144 144 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
145 145 xlabel=xlabel, ylabel=ylabel, title=title,
146 146 ticksize=9, colormap=power_cmap, cblabel='')
147 147
148 148 title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]])
149 149 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
150 150 axes0 = self.axesList[i*self.__nsubplots+1]
151 151 axes0.pcolor(x, y, zdB,
152 152 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
153 153 xlabel=xlabel, ylabel=ylabel, title=title,
154 154 ticksize=9, colormap=power_cmap, cblabel='')
155 155
156 156 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
157 157 coherence = numpy.abs(coherenceComplex)
158 158 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
159 159 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
160 160
161 161 title = "Coherence %d%d" %(pair[0], pair[1])
162 162 axes0 = self.axesList[i*self.__nsubplots+2]
163 163 axes0.pcolor(x, y, coherence,
164 164 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
165 165 xlabel=xlabel, ylabel=ylabel, title=title,
166 166 ticksize=9, colormap=coherence_cmap, cblabel='')
167 167
168 168 title = "Phase %d%d" %(pair[0], pair[1])
169 169 axes0 = self.axesList[i*self.__nsubplots+3]
170 170 axes0.pcolor(x, y, phase,
171 171 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
172 172 xlabel=xlabel, ylabel=ylabel, title=title,
173 173 ticksize=9, colormap=phase_cmap, cblabel='')
174 174
175 175
176 176
177 177 self.draw()
178 178
179 179 if save:
180 180 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
181 181 if figfile == None:
182 182 figfile = self.getFilename(name = date)
183 183
184 184 self.saveFigure(figpath, figfile)
185 185
186 186
187 187 class RTIPlot(Figure):
188 188
189 189 __isConfig = None
190 190 __nsubplots = None
191 191
192 192 WIDTHPROF = None
193 193 HEIGHTPROF = None
194 194 PREFIX = 'rti'
195 195
196 196 def __init__(self):
197 197
198 198 self.timerange = 2*60*60
199 199 self.__isConfig = False
200 200 self.__nsubplots = 1
201 201
202 202 self.WIDTH = 800
203 203 self.HEIGHT = 150
204 204 self.WIDTHPROF = 120
205 205 self.HEIGHTPROF = 0
206 206 self.counterftp = 0
207 207
208 208 def getSubplots(self):
209 209
210 210 ncol = 1
211 211 nrow = self.nplots
212 212
213 213 return nrow, ncol
214 214
215 215 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
216 216
217 217 self.__showprofile = showprofile
218 218 self.nplots = nplots
219 219
220 220 ncolspan = 1
221 221 colspan = 1
222 222 if showprofile:
223 223 ncolspan = 7
224 224 colspan = 6
225 225 self.__nsubplots = 2
226 226
227 227 self.createFigure(idfigure = idfigure,
228 228 wintitle = wintitle,
229 229 widthplot = self.WIDTH + self.WIDTHPROF,
230 230 heightplot = self.HEIGHT + self.HEIGHTPROF,
231 231 show=show)
232 232
233 233 nrow, ncol = self.getSubplots()
234 234
235 235 counter = 0
236 236 for y in range(nrow):
237 237 for x in range(ncol):
238 238
239 239 if counter >= self.nplots:
240 240 break
241 241
242 242 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
243 243
244 244 if showprofile:
245 245 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
246 246
247 247 counter += 1
248 248
249 249 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
250 250 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
251 251 timerange=None,
252 252 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
253 253
254 254 """
255 255
256 256 Input:
257 257 dataOut :
258 258 idfigure :
259 259 wintitle :
260 260 channelList :
261 261 showProfile :
262 262 xmin : None,
263 263 xmax : None,
264 264 ymin : None,
265 265 ymax : None,
266 266 zmin : None,
267 267 zmax : None
268 268 """
269 269
270 270 if channelList == None:
271 271 channelIndexList = dataOut.channelIndexList
272 272 else:
273 273 channelIndexList = []
274 274 for channel in channelList:
275 275 if channel not in dataOut.channelList:
276 276 raise ValueError, "Channel %d is not in dataOut.channelList"
277 277 channelIndexList.append(dataOut.channelList.index(channel))
278 278
279 279 if timerange != None:
280 280 self.timerange = timerange
281 281
282 282 tmin = None
283 283 tmax = None
284 284 factor = dataOut.normFactor
285 285 x = dataOut.getTimeRange()
286 286 y = dataOut.getHeiRange()
287 287
288 288 z = dataOut.data_spc[channelIndexList,:,:]/factor
289 289 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
290 290 avg = numpy.average(z, axis=1)
291 291
292 292 avgdB = 10.*numpy.log10(avg)
293 293
294 294
295 295 # thisDatetime = dataOut.datatime
296 296 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
297 297 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
298 298 xlabel = ""
299 299 ylabel = "Range (Km)"
300 300
301 301 if not self.__isConfig:
302 302
303 303 nplots = len(channelIndexList)
304 304
305 305 self.setup(idfigure=idfigure,
306 306 nplots=nplots,
307 307 wintitle=wintitle,
308 308 showprofile=showprofile,
309 309 show=show)
310 310
311 311 tmin, tmax = self.getTimeLim(x, xmin, xmax)
312 312 if ymin == None: ymin = numpy.nanmin(y)
313 313 if ymax == None: ymax = numpy.nanmax(y)
314 314 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
315 315 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
316 316
317 317 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
318 318 self.__isConfig = True
319 319
320 320
321 321 self.setWinTitle(title)
322 322
323 323 for i in range(self.nplots):
324 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
324 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
325 325 axes = self.axesList[i*self.__nsubplots]
326 326 zdB = avgdB[i].reshape((1,-1))
327 327 axes.pcolorbuffer(x, y, zdB,
328 328 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
329 329 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
330 330 ticksize=9, cblabel='', cbsize="1%")
331 331
332 332 if self.__showprofile:
333 333 axes = self.axesList[i*self.__nsubplots +1]
334 334 axes.pline(avgdB[i], y,
335 335 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
336 336 xlabel='dB', ylabel='', title='',
337 337 ytick_visible=False,
338 338 grid='x')
339 339
340 340 self.draw()
341 341
342 342 if save:
343 343
344 344 if figfile == None:
345 345 figfile = self.getFilename(name = self.name)
346 346
347 347 self.saveFigure(figpath, figfile)
348 348
349 349 self.counterftp += 1
350 350 if (ftp and (self.counterftp==ftpratio)):
351 351 figfilename = os.path.join(figpath,figfile)
352 352 self.sendByFTP(figfilename)
353 353 self.counterftp = 0
354 354
355 355 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
356 356 self.__isConfig = False
357 357
358 358 class SpectraPlot(Figure):
359 359
360 360 __isConfig = None
361 361 __nsubplots = None
362 362
363 363 WIDTHPROF = None
364 364 HEIGHTPROF = None
365 365 PREFIX = 'spc'
366 366
367 367 def __init__(self):
368 368
369 369 self.__isConfig = False
370 370 self.__nsubplots = 1
371 371
372 372 self.WIDTH = 230
373 373 self.HEIGHT = 250
374 374 self.WIDTHPROF = 120
375 375 self.HEIGHTPROF = 0
376 376
377 377 def getSubplots(self):
378 378
379 379 ncol = int(numpy.sqrt(self.nplots)+0.9)
380 380 nrow = int(self.nplots*1./ncol + 0.9)
381 381
382 382 return nrow, ncol
383 383
384 384 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
385 385
386 386 self.__showprofile = showprofile
387 387 self.nplots = nplots
388 388
389 389 ncolspan = 1
390 390 colspan = 1
391 391 if showprofile:
392 392 ncolspan = 3
393 393 colspan = 2
394 394 self.__nsubplots = 2
395 395
396 396 self.createFigure(idfigure = idfigure,
397 397 wintitle = wintitle,
398 398 widthplot = self.WIDTH + self.WIDTHPROF,
399 399 heightplot = self.HEIGHT + self.HEIGHTPROF,
400 400 show=show)
401 401
402 402 nrow, ncol = self.getSubplots()
403 403
404 404 counter = 0
405 405 for y in range(nrow):
406 406 for x in range(ncol):
407 407
408 408 if counter >= self.nplots:
409 409 break
410 410
411 411 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
412 412
413 413 if showprofile:
414 414 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
415 415
416 416 counter += 1
417 417
418 418 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
419 419 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
420 420 save=False, figpath='./', figfile=None, show=True):
421 421
422 422 """
423 423
424 424 Input:
425 425 dataOut :
426 426 idfigure :
427 427 wintitle :
428 428 channelList :
429 429 showProfile :
430 430 xmin : None,
431 431 xmax : None,
432 432 ymin : None,
433 433 ymax : None,
434 434 zmin : None,
435 435 zmax : None
436 436 """
437 437
438 438 if channelList == None:
439 439 channelIndexList = dataOut.channelIndexList
440 440 else:
441 441 channelIndexList = []
442 442 for channel in channelList:
443 443 if channel not in dataOut.channelList:
444 444 raise ValueError, "Channel %d is not in dataOut.channelList"
445 445 channelIndexList.append(dataOut.channelList.index(channel))
446 446 factor = dataOut.normFactor
447 447 x = dataOut.getVelRange(1)
448 448 y = dataOut.getHeiRange()
449 449
450 450 z = dataOut.data_spc[channelIndexList,:,:]/factor
451 451 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
452 452 avg = numpy.average(z, axis=1)
453 453 noise = dataOut.getNoise()/factor
454 454
455 455 zdB = 10*numpy.log10(z)
456 456 avgdB = 10*numpy.log10(avg)
457 457 noisedB = 10*numpy.log10(noise)
458 458
459 459 #thisDatetime = dataOut.datatime
460 460 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
461 461 title = wintitle + " Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
462 462 xlabel = "Velocity (m/s)"
463 463 ylabel = "Range (Km)"
464 464
465 465 if not self.__isConfig:
466 466
467 467 nplots = len(channelIndexList)
468 468
469 469 self.setup(idfigure=idfigure,
470 470 nplots=nplots,
471 471 wintitle=wintitle,
472 472 showprofile=showprofile,
473 473 show=show)
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 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i])
487 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, 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, show):
531 531
532 532 self.nplots = nplots
533 533
534 534 self.createFigure(idfigure=idfigure,
535 535 wintitle=wintitle,
536 536 show=show)
537 537
538 538 nrow,ncol = self.getSubplots()
539 539 colspan = 3
540 540 rowspan = 1
541 541
542 542 for i in range(nplots):
543 543 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
544 544
545 545
546 546
547 547 def run(self, dataOut, idfigure, wintitle="", channelList=None,
548 548 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
549 549 figpath='./', figfile=None, show=True):
550 550
551 551 """
552 552
553 553 Input:
554 554 dataOut :
555 555 idfigure :
556 556 wintitle :
557 557 channelList :
558 558 xmin : None,
559 559 xmax : None,
560 560 ymin : None,
561 561 ymax : None,
562 562 """
563 563
564 564 if channelList == None:
565 565 channelIndexList = dataOut.channelIndexList
566 566 else:
567 567 channelIndexList = []
568 568 for channel in channelList:
569 569 if channel not in dataOut.channelList:
570 570 raise ValueError, "Channel %d is not in dataOut.channelList"
571 571 channelIndexList.append(dataOut.channelList.index(channel))
572 572
573 573 x = dataOut.heightList
574 574 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
575 575 y = y.real
576 576
577 577 #thisDatetime = dataOut.datatime
578 578 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
579 579 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
580 580 xlabel = "Range (Km)"
581 581 ylabel = "Intensity"
582 582
583 583 if not self.__isConfig:
584 584 nplots = len(channelIndexList)
585 585
586 586 self.setup(idfigure=idfigure,
587 587 nplots=nplots,
588 588 wintitle=wintitle,
589 589 show=show)
590 590
591 591 if xmin == None: xmin = numpy.nanmin(x)
592 592 if xmax == None: xmax = numpy.nanmax(x)
593 593 if ymin == None: ymin = numpy.nanmin(y)
594 594 if ymax == None: ymax = numpy.nanmax(y)
595 595
596 596 self.__isConfig = True
597 597
598 598 self.setWinTitle(title)
599 599
600 600 for i in range(len(self.axesList)):
601 601 title = "Channel %d" %(i)
602 602 axes = self.axesList[i]
603 603 ychannel = y[i,:]
604 604 axes.pline(x, ychannel,
605 605 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
606 606 xlabel=xlabel, ylabel=ylabel, title=title)
607 607
608 608 self.draw()
609 609
610 610 if save:
611 611 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
612 612 if figfile == None:
613 613 figfile = self.getFilename(name = date)
614 614
615 615 self.saveFigure(figpath, figfile)
616 616
617 617 class PowerProfilePlot(Figure):
618 618 __isConfig = None
619 619 __nsubplots = None
620 620
621 621 WIDTHPROF = None
622 622 HEIGHTPROF = None
623 623 PREFIX = 'spcprofile'
624 624
625 625 def __init__(self):
626 626 self.__isConfig = False
627 627 self.__nsubplots = 1
628 628
629 629 self.WIDTH = 300
630 630 self.HEIGHT = 500
631 631
632 632 def getSubplots(self):
633 633 ncol = 1
634 634 nrow = 1
635 635
636 636 return nrow, ncol
637 637
638 638 def setup(self, idfigure, nplots, wintitle, show):
639 639
640 640 self.nplots = nplots
641 641
642 642 ncolspan = 1
643 643 colspan = 1
644 644
645 645 self.createFigure(idfigure = idfigure,
646 646 wintitle = wintitle,
647 647 widthplot = self.WIDTH,
648 648 heightplot = self.HEIGHT,
649 649 show=show)
650 650
651 651 nrow, ncol = self.getSubplots()
652 652
653 653 counter = 0
654 654 for y in range(nrow):
655 655 for x in range(ncol):
656 656 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
657 657
658 658 def run(self, dataOut, idfigure, wintitle="", channelList=None,
659 659 xmin=None, xmax=None, ymin=None, ymax=None,
660 660 save=False, figpath='./', figfile=None, show=True):
661 661
662 662 if channelList == None:
663 663 channelIndexList = dataOut.channelIndexList
664 664 channelList = dataOut.channelList
665 665 else:
666 666 channelIndexList = []
667 667 for channel in channelList:
668 668 if channel not in dataOut.channelList:
669 669 raise ValueError, "Channel %d is not in dataOut.channelList"
670 670 channelIndexList.append(dataOut.channelList.index(channel))
671 671
672 672 factor = dataOut.normFactor
673 673 y = dataOut.getHeiRange()
674 674 x = dataOut.data_spc[channelIndexList,:,:]/factor
675 675 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
676 676 avg = numpy.average(x, axis=1)
677 677
678 678 avgdB = 10*numpy.log10(avg)
679 679
680 680 #thisDatetime = dataOut.datatime
681 681 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
682 682 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
683 683 xlabel = "dB"
684 684 ylabel = "Range (Km)"
685 685
686 686 if not self.__isConfig:
687 687
688 688 nplots = 1
689 689
690 690 self.setup(idfigure=idfigure,
691 691 nplots=nplots,
692 692 wintitle=wintitle,
693 693 show=show)
694 694
695 695 if ymin == None: ymin = numpy.nanmin(y)
696 696 if ymax == None: ymax = numpy.nanmax(y)
697 697 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
698 698 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
699 699
700 700 self.__isConfig = True
701 701
702 702 self.setWinTitle(title)
703 703
704 704
705 705 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
706 706 axes = self.axesList[0]
707 707
708 708 legendlabels = ["channel %d"%x for x in channelList]
709 709 axes.pmultiline(avgdB, y,
710 710 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
711 711 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
712 712 ytick_visible=True, nxticks=5,
713 713 grid='x')
714 714
715 715 self.draw()
716 716
717 717 if save:
718 718 date = thisDatetime.strftime("%Y%m%d")
719 719 if figfile == None:
720 720 figfile = self.getFilename(name = date)
721 721
722 722 self.saveFigure(figpath, figfile)
723 723
724 724 class CoherenceMap(Figure):
725 725 __isConfig = None
726 726 __nsubplots = None
727 727
728 728 WIDTHPROF = None
729 729 HEIGHTPROF = None
730 730 PREFIX = 'cmap'
731 731
732 732 def __init__(self):
733 733 self.timerange = 2*60*60
734 734 self.__isConfig = False
735 735 self.__nsubplots = 1
736 736
737 737 self.WIDTH = 800
738 738 self.HEIGHT = 150
739 739 self.WIDTHPROF = 120
740 740 self.HEIGHTPROF = 0
741 741 self.counterftp = 0
742 742
743 743 def getSubplots(self):
744 744 ncol = 1
745 745 nrow = self.nplots*2
746 746
747 747 return nrow, ncol
748 748
749 749 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
750 750 self.__showprofile = showprofile
751 751 self.nplots = nplots
752 752
753 753 ncolspan = 1
754 754 colspan = 1
755 755 if showprofile:
756 756 ncolspan = 7
757 757 colspan = 6
758 758 self.__nsubplots = 2
759 759
760 760 self.createFigure(idfigure = idfigure,
761 761 wintitle = wintitle,
762 762 widthplot = self.WIDTH + self.WIDTHPROF,
763 763 heightplot = self.HEIGHT + self.HEIGHTPROF,
764 764 show=True)
765 765
766 766 nrow, ncol = self.getSubplots()
767 767
768 768 for y in range(nrow):
769 769 for x in range(ncol):
770 770
771 771 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
772 772
773 773 if showprofile:
774 774 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
775 775
776 776 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
777 777 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
778 778 timerange=None,
779 779 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1,
780 780 coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
781 781
782 782 if pairsList == None:
783 783 pairsIndexList = dataOut.pairsIndexList
784 784 else:
785 785 pairsIndexList = []
786 786 for pair in pairsList:
787 787 if pair not in dataOut.pairsList:
788 788 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
789 789 pairsIndexList.append(dataOut.pairsList.index(pair))
790 790
791 791 if timerange != None:
792 792 self.timerange = timerange
793 793
794 794 if pairsIndexList == []:
795 795 return
796 796
797 797 if len(pairsIndexList) > 4:
798 798 pairsIndexList = pairsIndexList[0:4]
799 799
800 800 tmin = None
801 801 tmax = None
802 802 x = dataOut.getTimeRange()
803 803 y = dataOut.getHeiRange()
804 804
805 805 #thisDatetime = dataOut.datatime
806 806 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
807 807 title = wintitle + " CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
808 808 xlabel = ""
809 809 ylabel = "Range (Km)"
810 810
811 811 if not self.__isConfig:
812 812 nplots = len(pairsIndexList)
813 813 self.setup(idfigure=idfigure,
814 814 nplots=nplots,
815 815 wintitle=wintitle,
816 816 showprofile=showprofile,
817 817 show=show)
818 818
819 819 tmin, tmax = self.getTimeLim(x, xmin, xmax)
820 820 if ymin == None: ymin = numpy.nanmin(y)
821 821 if ymax == None: ymax = numpy.nanmax(y)
822 822
823 823 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
824 824
825 825 self.__isConfig = True
826 826
827 827 self.setWinTitle(title)
828 828
829 829 for i in range(self.nplots):
830 830
831 831 pair = dataOut.pairsList[pairsIndexList[i]]
832 832 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
833 833 avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
834 834 coherence = numpy.abs(avgcoherenceComplex)
835 835 # coherence = numpy.abs(coherenceComplex)
836 836 # avg = numpy.average(coherence, axis=0)
837 837
838 838 z = coherence.reshape((1,-1))
839 839
840 840 counter = 0
841 841
842 842 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
843 843 axes = self.axesList[i*self.__nsubplots*2]
844 844 axes.pcolorbuffer(x, y, z,
845 845 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
846 846 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
847 847 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
848 848
849 849 if self.__showprofile:
850 850 counter += 1
851 851 axes = self.axesList[i*self.__nsubplots*2 + counter]
852 852 axes.pline(coherence, y,
853 853 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
854 854 xlabel='', ylabel='', title='', ticksize=7,
855 855 ytick_visible=False, nxticks=5,
856 856 grid='x')
857 857
858 858 counter += 1
859 859 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
860 860 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
861 861 # avg = numpy.average(phase, axis=0)
862 862 z = phase.reshape((1,-1))
863 863
864 864 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
865 865 axes = self.axesList[i*self.__nsubplots*2 + counter]
866 866 axes.pcolorbuffer(x, y, z,
867 867 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
868 868 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
869 869 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
870 870
871 871 if self.__showprofile:
872 872 counter += 1
873 873 axes = self.axesList[i*self.__nsubplots*2 + counter]
874 874 axes.pline(phase, y,
875 875 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
876 876 xlabel='', ylabel='', title='', ticksize=7,
877 877 ytick_visible=False, nxticks=4,
878 878 grid='x')
879 879
880 880 self.draw()
881 881
882 882 if save:
883 883
884 884 if figfile == None:
885 885 figfile = self.getFilename(name = self.name)
886 886
887 887 self.saveFigure(figpath, figfile)
888 888
889 889 self.counterftp += 1
890 890 if (ftp and (self.counterftp==ftpratio)):
891 891 figfilename = os.path.join(figpath,figfile)
892 892 self.sendByFTP(figfilename)
893 893 self.counterftp = 0
894 894
895 895 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
896 896 self.__isConfig = False
897 897
898 898 class RTIfromNoise(Figure):
899 899
900 900 __isConfig = None
901 901 __nsubplots = None
902 902
903 903 PREFIX = 'rtinoise'
904 904
905 905 def __init__(self):
906 906
907 907 self.timerange = 24*60*60
908 908 self.__isConfig = False
909 909 self.__nsubplots = 1
910 910
911 911 self.WIDTH = 820
912 912 self.HEIGHT = 200
913 913 self.WIDTHPROF = 120
914 914 self.HEIGHTPROF = 0
915 915 self.xdata = None
916 916 self.ydata = None
917 917
918 918 def getSubplots(self):
919 919
920 920 ncol = 1
921 921 nrow = 1
922 922
923 923 return nrow, ncol
924 924
925 925 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
926 926
927 927 self.__showprofile = showprofile
928 928 self.nplots = nplots
929 929
930 930 ncolspan = 7
931 931 colspan = 6
932 932 self.__nsubplots = 2
933 933
934 934 self.createFigure(idfigure = idfigure,
935 935 wintitle = wintitle,
936 936 widthplot = self.WIDTH+self.WIDTHPROF,
937 937 heightplot = self.HEIGHT+self.HEIGHTPROF,
938 938 show=show)
939 939
940 940 nrow, ncol = self.getSubplots()
941 941
942 942 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
943 943
944 944
945 945 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
946 946 xmin=None, xmax=None, ymin=None, ymax=None,
947 947 timerange=None,
948 948 save=False, figpath='./', figfile=None, show=True):
949 949
950 950 if channelList == None:
951 951 channelIndexList = dataOut.channelIndexList
952 952 channelList = dataOut.channelList
953 953 else:
954 954 channelIndexList = []
955 955 for channel in channelList:
956 956 if channel not in dataOut.channelList:
957 957 raise ValueError, "Channel %d is not in dataOut.channelList"
958 958 channelIndexList.append(dataOut.channelList.index(channel))
959 959
960 960 if timerange != None:
961 961 self.timerange = timerange
962 962
963 963 tmin = None
964 964 tmax = None
965 965 x = dataOut.getTimeRange()
966 966 y = dataOut.getHeiRange()
967 967 factor = dataOut.normFactor
968 968 noise = dataOut.getNoise()/factor
969 969 noisedB = 10*numpy.log10(noise)
970 970
971 971 #thisDatetime = dataOut.datatime
972 972 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
973 973 title = wintitle + " RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y"))
974 974 xlabel = ""
975 975 ylabel = "Range (Km)"
976 976
977 977 if not self.__isConfig:
978 978
979 979 nplots = 1
980 980
981 981 self.setup(idfigure=idfigure,
982 982 nplots=nplots,
983 983 wintitle=wintitle,
984 984 showprofile=showprofile,
985 985 show=show)
986 986
987 987 tmin, tmax = self.getTimeLim(x, xmin, xmax)
988 988 if ymin == None: ymin = numpy.nanmin(noisedB)
989 989 if ymax == None: ymax = numpy.nanmax(noisedB)
990 990
991 991 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
992 992 self.__isConfig = True
993 993
994 994 self.xdata = numpy.array([])
995 995 self.ydata = numpy.array([])
996 996
997 997 self.setWinTitle(title)
998 998
999 999
1000 1000 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
1001 1001
1002 1002 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1003 1003 axes = self.axesList[0]
1004 1004
1005 1005 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1006 1006
1007 1007 if len(self.ydata)==0:
1008 1008 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1009 1009 else:
1010 1010 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1011 1011
1012 1012
1013 1013 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1014 1014 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1015 1015 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1016 1016 XAxisAsTime=True
1017 1017 )
1018 1018
1019 1019 self.draw()
1020 1020
1021 1021 if save:
1022 1022
1023 1023 if figfile == None:
1024 1024 figfile = self.getFilename(name = self.name)
1025 1025
1026 1026 self.saveFigure(figpath, figfile)
1027 1027
1028 1028 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1029 1029 self.__isConfig = False
1030 1030 del self.xdata
1031 1031 del self.ydata
1032 1032
1033 1033
1034 1034 class SpectraHeisScope(Figure):
1035 1035
1036 1036
1037 1037 __isConfig = None
1038 1038 __nsubplots = None
1039 1039
1040 1040 WIDTHPROF = None
1041 1041 HEIGHTPROF = None
1042 1042 PREFIX = 'spc'
1043 1043
1044 1044 def __init__(self):
1045 1045
1046 1046 self.__isConfig = False
1047 1047 self.__nsubplots = 1
1048 1048
1049 1049 self.WIDTH = 230
1050 1050 self.HEIGHT = 250
1051 1051 self.WIDTHPROF = 120
1052 1052 self.HEIGHTPROF = 0
1053 1053 self.counterftp = 0
1054 1054
1055 1055 def getSubplots(self):
1056 1056
1057 1057 ncol = int(numpy.sqrt(self.nplots)+0.9)
1058 1058 nrow = int(self.nplots*1./ncol + 0.9)
1059 1059
1060 1060 return nrow, ncol
1061 1061
1062 1062 def setup(self, idfigure, nplots, wintitle, show):
1063 1063
1064 1064 showprofile = False
1065 1065 self.__showprofile = showprofile
1066 1066 self.nplots = nplots
1067 1067
1068 1068 ncolspan = 1
1069 1069 colspan = 1
1070 1070 if showprofile:
1071 1071 ncolspan = 3
1072 1072 colspan = 2
1073 1073 self.__nsubplots = 2
1074 1074
1075 1075 self.createFigure(idfigure = idfigure,
1076 1076 wintitle = wintitle,
1077 1077 widthplot = self.WIDTH + self.WIDTHPROF,
1078 1078 heightplot = self.HEIGHT + self.HEIGHTPROF,
1079 1079 show = show)
1080 1080
1081 1081 nrow, ncol = self.getSubplots()
1082 1082
1083 1083 counter = 0
1084 1084 for y in range(nrow):
1085 1085 for x in range(ncol):
1086 1086
1087 1087 if counter >= self.nplots:
1088 1088 break
1089 1089
1090 1090 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1091 1091
1092 1092 if showprofile:
1093 1093 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1094 1094
1095 1095 counter += 1
1096 1096
1097 1097 # __isConfig = None
1098 1098 # def __init__(self):
1099 1099 #
1100 1100 # self.__isConfig = False
1101 1101 # self.WIDTH = 600
1102 1102 # self.HEIGHT = 200
1103 1103 #
1104 1104 # def getSubplots(self):
1105 1105 #
1106 1106 # nrow = self.nplots
1107 1107 # ncol = 3
1108 1108 # return nrow, ncol
1109 1109 #
1110 1110 # def setup(self, idfigure, nplots, wintitle):
1111 1111 #
1112 1112 # self.nplots = nplots
1113 1113 #
1114 1114 # self.createFigure(idfigure, wintitle)
1115 1115 #
1116 1116 # nrow,ncol = self.getSubplots()
1117 1117 # colspan = 3
1118 1118 # rowspan = 1
1119 1119 #
1120 1120 # for i in range(nplots):
1121 1121 # self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
1122 1122
1123 1123 def run(self, dataOut, idfigure, wintitle="", channelList=None,
1124 1124 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1125 1125 figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1126 1126
1127 1127 """
1128 1128
1129 1129 Input:
1130 1130 dataOut :
1131 1131 idfigure :
1132 1132 wintitle :
1133 1133 channelList :
1134 1134 xmin : None,
1135 1135 xmax : None,
1136 1136 ymin : None,
1137 1137 ymax : None,
1138 1138 """
1139 1139
1140 1140 if dataOut.realtime:
1141 1141 if not(isRealtime(utcdatatime = dataOut.utctime)):
1142 1142 print 'Skipping this plot function'
1143 1143 return
1144 1144
1145 1145 if channelList == None:
1146 1146 channelIndexList = dataOut.channelIndexList
1147 1147 else:
1148 1148 channelIndexList = []
1149 1149 for channel in channelList:
1150 1150 if channel not in dataOut.channelList:
1151 1151 raise ValueError, "Channel %d is not in dataOut.channelList"
1152 1152 channelIndexList.append(dataOut.channelList.index(channel))
1153 1153
1154 1154 # x = dataOut.heightList
1155 1155 c = 3E8
1156 1156 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1157 1157 #deberia cambiar para el caso de 1Mhz y 100KHz
1158 1158 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1159 1159 x= x/(10000.0)
1160 1160 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1161 1161 # y = y.real
1162 1162 datadB = 10.*numpy.log10(dataOut.data_spc)
1163 1163 y = datadB
1164 1164
1165 1165 #thisDatetime = dataOut.datatime
1166 1166 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1167 1167 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1168 1168 xlabel = "Frequency x 10000"
1169 1169 ylabel = "Intensity (dB)"
1170 1170
1171 1171 if not self.__isConfig:
1172 1172 nplots = len(channelIndexList)
1173 1173
1174 1174 self.setup(idfigure=idfigure,
1175 1175 nplots=nplots,
1176 1176 wintitle=wintitle,
1177 1177 show=show)
1178 1178
1179 1179 if xmin == None: xmin = numpy.nanmin(x)
1180 1180 if xmax == None: xmax = numpy.nanmax(x)
1181 1181 if ymin == None: ymin = numpy.nanmin(y)
1182 1182 if ymax == None: ymax = numpy.nanmax(y)
1183 1183
1184 1184 self.__isConfig = True
1185 1185
1186 1186 self.setWinTitle(title)
1187 1187
1188 1188 for i in range(len(self.axesList)):
1189 1189 ychannel = y[i,:]
1190 1190 title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel))
1191 1191 axes = self.axesList[i]
1192 1192 axes.pline(x, ychannel,
1193 1193 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1194 1194 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1195 1195
1196 1196
1197 1197 self.draw()
1198 1198
1199 1199 if save:
1200 1200 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1201 1201 if figfile == None:
1202 1202 figfile = self.getFilename(name = date)
1203 1203
1204 1204 self.saveFigure(figpath, figfile)
1205 1205
1206 1206 self.counterftp += 1
1207 1207 if (ftp and (self.counterftp==ftpratio)):
1208 1208 figfilename = os.path.join(figpath,figfile)
1209 1209 self.sendByFTP(figfilename)
1210 1210 self.counterftp = 0
1211 1211
1212 1212
1213 1213 class RTIfromSpectraHeis(Figure):
1214 1214
1215 1215 __isConfig = None
1216 1216 __nsubplots = None
1217 1217
1218 1218 PREFIX = 'rtinoise'
1219 1219
1220 1220 def __init__(self):
1221 1221
1222 1222 self.timerange = 24*60*60
1223 1223 self.__isConfig = False
1224 1224 self.__nsubplots = 1
1225 1225
1226 1226 self.WIDTH = 820
1227 1227 self.HEIGHT = 200
1228 1228 self.WIDTHPROF = 120
1229 1229 self.HEIGHTPROF = 0
1230 1230 self.counterftp = 0
1231 1231 self.xdata = None
1232 1232 self.ydata = None
1233 1233
1234 1234 def getSubplots(self):
1235 1235
1236 1236 ncol = 1
1237 1237 nrow = 1
1238 1238
1239 1239 return nrow, ncol
1240 1240
1241 1241 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
1242 1242
1243 1243 self.__showprofile = showprofile
1244 1244 self.nplots = nplots
1245 1245
1246 1246 ncolspan = 7
1247 1247 colspan = 6
1248 1248 self.__nsubplots = 2
1249 1249
1250 1250 self.createFigure(idfigure = idfigure,
1251 1251 wintitle = wintitle,
1252 1252 widthplot = self.WIDTH+self.WIDTHPROF,
1253 1253 heightplot = self.HEIGHT+self.HEIGHTPROF,
1254 1254 show = show)
1255 1255
1256 1256 nrow, ncol = self.getSubplots()
1257 1257
1258 1258 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1259 1259
1260 1260
1261 1261 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
1262 1262 xmin=None, xmax=None, ymin=None, ymax=None,
1263 1263 timerange=None,
1264 1264 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1265 1265
1266 1266 if channelList == None:
1267 1267 channelIndexList = dataOut.channelIndexList
1268 1268 channelList = dataOut.channelList
1269 1269 else:
1270 1270 channelIndexList = []
1271 1271 for channel in channelList:
1272 1272 if channel not in dataOut.channelList:
1273 1273 raise ValueError, "Channel %d is not in dataOut.channelList"
1274 1274 channelIndexList.append(dataOut.channelList.index(channel))
1275 1275
1276 1276 if timerange != None:
1277 1277 self.timerange = timerange
1278 1278
1279 1279 tmin = None
1280 1280 tmax = None
1281 1281 x = dataOut.getTimeRange()
1282 1282 y = dataOut.getHeiRange()
1283 1283
1284 1284 factor = 1
1285 1285 data = dataOut.data_spc/factor
1286 1286 data = numpy.average(data,axis=1)
1287 1287 datadB = 10*numpy.log10(data)
1288 1288
1289 1289 # factor = dataOut.normFactor
1290 1290 # noise = dataOut.getNoise()/factor
1291 1291 # noisedB = 10*numpy.log10(noise)
1292 1292
1293 1293 #thisDatetime = dataOut.datatime
1294 1294 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1295 1295 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1296 1296 xlabel = "Local Time"
1297 1297 ylabel = "Intensity (dB)"
1298 1298
1299 1299 if not self.__isConfig:
1300 1300
1301 1301 nplots = 1
1302 1302
1303 1303 self.setup(idfigure=idfigure,
1304 1304 nplots=nplots,
1305 1305 wintitle=wintitle,
1306 1306 showprofile=showprofile,
1307 1307 show=show)
1308 1308
1309 1309 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1310 1310 if ymin == None: ymin = numpy.nanmin(datadB)
1311 1311 if ymax == None: ymax = numpy.nanmax(datadB)
1312 1312
1313 1313 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1314 1314 self.__isConfig = True
1315 1315
1316 1316 self.xdata = numpy.array([])
1317 1317 self.ydata = numpy.array([])
1318 1318
1319 1319 self.setWinTitle(title)
1320 1320
1321 1321
1322 1322 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1323 1323 title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1324 1324
1325 1325 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1326 1326 axes = self.axesList[0]
1327 1327
1328 1328 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1329 1329
1330 1330 if len(self.ydata)==0:
1331 1331 self.ydata = datadB[channelIndexList].reshape(-1,1)
1332 1332 else:
1333 1333 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1334 1334
1335 1335
1336 1336 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1337 1337 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1338 1338 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1339 1339 XAxisAsTime=True
1340 1340 )
1341 1341
1342 1342 self.draw()
1343 1343
1344 1344 if save:
1345 1345
1346 1346 if figfile == None:
1347 1347 figfile = self.getFilename(name = self.name)
1348 1348
1349 1349 self.saveFigure(figpath, figfile)
1350 1350
1351 1351 self.counterftp += 1
1352 1352 if (ftp and (self.counterftp==ftpratio)):
1353 1353 figfilename = os.path.join(figpath,figfile)
1354 1354 self.sendByFTP(figfilename)
1355 1355 self.counterftp = 0
1356 1356
1357 1357 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1358 1358 self.__isConfig = False
1359 1359 del self.xdata
1360 1360 del self.ydata
1361 1361
1362 1362
1363 1363 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now