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