##// END OF EJS Templates
parametrs plotting: SNR and DOP arguments have been added
Miguel Valdez -
r588:c1c257c97d52
parent child
Show More
@@ -1,1148 +1,1164
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 134 if not self.isConfig:
135 135
136 136 nplots = len(channelIndexList)
137 137
138 138 self.setup(id=id,
139 139 nplots=nplots,
140 140 wintitle=wintitle,
141 141 showprofile=showprofile,
142 142 show=show)
143 143
144 144 if xmin == None: xmin = numpy.nanmin(x)
145 145 if xmax == None: xmax = numpy.nanmax(x)
146 146 if ymin == None: ymin = numpy.nanmin(y)
147 147 if ymax == None: ymax = numpy.nanmax(y)
148 148 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
149 149 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
150 150
151 151 self.FTP_WEI = ftp_wei
152 152 self.EXP_CODE = exp_code
153 153 self.SUB_EXP_CODE = sub_exp_code
154 154 self.PLOT_POS = plot_pos
155 155
156 156 self.isConfig = True
157 157
158 158 self.setWinTitle(title)
159 159
160 160 for i in range(self.nplots):
161 161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
162 162 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
163 163 axes = self.axesList[i*self.__nsubplots]
164 164 axes.pcolor(x, y, zdB[i,:,:],
165 165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
166 166 xlabel=xlabel, ylabel=ylabel, title=title,
167 167 ticksize=9, cblabel='')
168 168 #Mean Line
169 169 mean = dataOut.data_param[i, 1, :]
170 170 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
171 171
172 172 if self.__showprofile:
173 173 axes = self.axesList[i*self.__nsubplots +1]
174 174 axes.pline(avgdB[i], y,
175 175 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
176 176 xlabel='dB', ylabel='', title='',
177 177 ytick_visible=False,
178 178 grid='x')
179 179
180 180 noiseline = numpy.repeat(noisedB[i], len(y))
181 181 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
182 182
183 183 self.draw()
184 184
185 185 self.save(figpath=figpath,
186 186 figfile=figfile,
187 187 save=save,
188 188 ftp=ftp,
189 189 wr_period=wr_period,
190 190 thisDatetime=thisDatetime)
191 191
192 192
193 193
194 194 class SkyMapPlot(Figure):
195 195
196 196 __isConfig = None
197 197 __nsubplots = None
198 198
199 199 WIDTHPROF = None
200 200 HEIGHTPROF = None
201 201 PREFIX = 'prm'
202 202
203 203 def __init__(self):
204 204
205 205 self.__isConfig = False
206 206 self.__nsubplots = 1
207 207
208 208 # self.WIDTH = 280
209 209 # self.HEIGHT = 250
210 210 self.WIDTH = 600
211 211 self.HEIGHT = 600
212 212 self.WIDTHPROF = 120
213 213 self.HEIGHTPROF = 0
214 214 self.counter_imagwr = 0
215 215
216 216 self.PLOT_CODE = SKYMAP_CODE
217 217
218 218 self.FTP_WEI = None
219 219 self.EXP_CODE = None
220 220 self.SUB_EXP_CODE = None
221 221 self.PLOT_POS = None
222 222
223 223 def getSubplots(self):
224 224
225 225 ncol = int(numpy.sqrt(self.nplots)+0.9)
226 226 nrow = int(self.nplots*1./ncol + 0.9)
227 227
228 228 return nrow, ncol
229 229
230 230 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
231 231
232 232 self.__showprofile = showprofile
233 233 self.nplots = nplots
234 234
235 235 ncolspan = 1
236 236 colspan = 1
237 237
238 238 self.createFigure(id = id,
239 239 wintitle = wintitle,
240 240 widthplot = self.WIDTH, #+ self.WIDTHPROF,
241 241 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
242 242 show=show)
243 243
244 244 nrow, ncol = 1,1
245 245 counter = 0
246 246 x = 0
247 247 y = 0
248 248 self.addAxes(1, 1, 0, 0, 1, 1, True)
249 249
250 250 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
251 251 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
252 252 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
253 253 server=None, folder=None, username=None, password=None,
254 254 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
255 255
256 256 """
257 257
258 258 Input:
259 259 dataOut :
260 260 id :
261 261 wintitle :
262 262 channelList :
263 263 showProfile :
264 264 xmin : None,
265 265 xmax : None,
266 266 ymin : None,
267 267 ymax : None,
268 268 zmin : None,
269 269 zmax : None
270 270 """
271 271
272 272 arrayParameters = dataOut.data_param
273 273 error = arrayParameters[:,-1]
274 274 indValid = numpy.where(error == 0)[0]
275 275 finalMeteor = arrayParameters[indValid,:]
276 276 finalAzimuth = finalMeteor[:,4]
277 277 finalZenith = finalMeteor[:,5]
278 278
279 279 x = finalAzimuth*numpy.pi/180
280 280 y = finalZenith
281 281
282 282
283 283 #thisDatetime = dataOut.datatime
284 284 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
285 285 title = wintitle + " Parameters"
286 286 xlabel = "Zonal Zenith Angle (deg) "
287 287 ylabel = "Meridional Zenith Angle (deg)"
288 288
289 289 if not self.__isConfig:
290 290
291 291 nplots = 1
292 292
293 293 self.setup(id=id,
294 294 nplots=nplots,
295 295 wintitle=wintitle,
296 296 showprofile=showprofile,
297 297 show=show)
298 298
299 299 self.FTP_WEI = ftp_wei
300 300 self.EXP_CODE = exp_code
301 301 self.SUB_EXP_CODE = sub_exp_code
302 302 self.PLOT_POS = plot_pos
303 303 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
304 304 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
305 305 self.__isConfig = True
306 306
307 307 self.setWinTitle(title)
308 308
309 309 i = 0
310 310 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
311 311
312 312 axes = self.axesList[i*self.__nsubplots]
313 313 nevents = axes.x_buffer.shape[0] + x.shape[0]
314 314 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
315 315 axes.polar(x, y,
316 316 title=title, xlabel=xlabel, ylabel=ylabel,
317 317 ticksize=9, cblabel='')
318 318
319 319 self.draw()
320 320
321 321 self.save(figpath=figpath,
322 322 figfile=figfile,
323 323 save=save,
324 324 ftp=ftp,
325 325 wr_period=wr_period,
326 326 thisDatetime=thisDatetime)
327 327
328 328 class WindProfilerPlot(Figure):
329 329
330 330 __isConfig = None
331 331 __nsubplots = None
332 332
333 333 WIDTHPROF = None
334 334 HEIGHTPROF = None
335 335 PREFIX = 'wind'
336 336
337 337 def __init__(self):
338 338
339 339 self.timerange = 2*60*60
340 340 self.__isConfig = False
341 341 self.__nsubplots = 1
342 342
343 343 self.WIDTH = 800
344 344 self.HEIGHT = 150
345 345 self.WIDTHPROF = 120
346 346 self.HEIGHTPROF = 0
347 347 self.counter_imagwr = 0
348 348
349 349 self.PLOT_CODE = WIND_CODE
350 350
351 351 self.FTP_WEI = None
352 352 self.EXP_CODE = None
353 353 self.SUB_EXP_CODE = None
354 354 self.PLOT_POS = None
355 355 self.tmin = None
356 356 self.tmax = None
357 357
358 358 self.xmin = None
359 359 self.xmax = None
360 360
361 361 self.figfile = None
362 362
363 363 def getSubplots(self):
364 364
365 365 ncol = 1
366 366 nrow = self.nplots
367 367
368 368 return nrow, ncol
369 369
370 370 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
371 371
372 372 self.__showprofile = showprofile
373 373 self.nplots = nplots
374 374
375 375 ncolspan = 1
376 376 colspan = 1
377 377
378 378 self.createFigure(id = id,
379 379 wintitle = wintitle,
380 380 widthplot = self.WIDTH + self.WIDTHPROF,
381 381 heightplot = self.HEIGHT + self.HEIGHTPROF,
382 382 show=show)
383 383
384 384 nrow, ncol = self.getSubplots()
385 385
386 386 counter = 0
387 387 for y in range(nrow):
388 388 if counter >= self.nplots:
389 389 break
390 390
391 391 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
392 392 counter += 1
393 393
394 394 def run(self, dataOut, id, wintitle="", channelList=None,
395 395 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
396 396 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
397 397 timerange=None, SNRthresh = None,
398 398 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
399 399 server=None, folder=None, username=None, password=None,
400 400 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
401 401 """
402 402
403 403 Input:
404 404 dataOut :
405 405 id :
406 406 wintitle :
407 407 channelList :
408 408 showProfile :
409 409 xmin : None,
410 410 xmax : None,
411 411 ymin : None,
412 412 ymax : None,
413 413 zmin : None,
414 414 zmax : None
415 415 """
416 416
417 417 if channelList == None:
418 418 channelIndexList = dataOut.channelIndexList
419 419 else:
420 420 channelIndexList = []
421 421 for channel in channelList:
422 422 if channel not in dataOut.channelList:
423 423 raise ValueError, "Channel %d is not in dataOut.channelList"
424 424 channelIndexList.append(dataOut.channelList.index(channel))
425 425
426 426 if timerange != None:
427 427 self.timerange = timerange
428 428
429 429 tmin = None
430 430 tmax = None
431 431
432 432 x = dataOut.getTimeRange1()
433 433 # y = dataOut.heightList
434 434 y = dataOut.heightList
435 435
436 436 z = dataOut.data_output.copy()
437 437 nplots = z.shape[0] #Number of wind dimensions estimated
438 438 nplotsw = nplots
439 439
440 440 #If there is a SNR function defined
441 441 if dataOut.data_SNR != None:
442 442 nplots += 1
443 443 SNR = dataOut.data_SNR
444 444 SNRavg = numpy.average(SNR, axis=0)
445 445
446 446 SNRdB = 10*numpy.log10(SNR)
447 447 SNRavgdB = 10*numpy.log10(SNRavg)
448 448
449 449 if SNRthresh == None: SNRthresh = -5.0
450 450 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
451 451
452 452 for i in range(nplotsw):
453 453 z[i,ind] = numpy.nan
454 454
455 455
456 456 showprofile = False
457 457 # thisDatetime = dataOut.datatime
458 458 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
459 459 title = wintitle + "Wind"
460 460 xlabel = ""
461 461 ylabel = "Range (Km)"
462 462
463 463 if not self.__isConfig:
464 464
465 465 self.setup(id=id,
466 466 nplots=nplots,
467 467 wintitle=wintitle,
468 468 showprofile=showprofile,
469 469 show=show)
470 470
471 471 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
472 472
473 473 if ymin == None: ymin = numpy.nanmin(y)
474 474 if ymax == None: ymax = numpy.nanmax(y)
475 475
476 476 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
477 477 #if numpy.isnan(zmax): zmax = 50
478 478 if zmin == None: zmin = -zmax
479 479
480 480 if nplotsw == 3:
481 481 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
482 482 if zmin_ver == None: zmin_ver = -zmax_ver
483 483
484 484 if dataOut.data_SNR != None:
485 485 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
486 486 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
487 487
488 488 self.FTP_WEI = ftp_wei
489 489 self.EXP_CODE = exp_code
490 490 self.SUB_EXP_CODE = sub_exp_code
491 491 self.PLOT_POS = plot_pos
492 492
493 493 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
494 494 self.__isConfig = True
495 495
496 496
497 497 self.setWinTitle(title)
498 498
499 499 if ((self.xmax - x[1]) < (x[1]-x[0])):
500 500 x[1] = self.xmax
501 501
502 502 strWind = ['Zonal', 'Meridional', 'Vertical']
503 503 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
504 504 zmaxVector = [zmax, zmax, zmax_ver]
505 505 zminVector = [zmin, zmin, zmin_ver]
506 506 windFactor = [1,1,100]
507 507
508 508 for i in range(nplotsw):
509 509
510 510 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
511 511 axes = self.axesList[i*self.__nsubplots]
512 512
513 513 z1 = z[i,:].reshape((1,-1))*windFactor[i]
514 514
515 515 axes.pcolorbuffer(x, y, z1,
516 516 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
517 517 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
518 518 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
519 519
520 520 if dataOut.data_SNR != None:
521 521 i += 1
522 522 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
523 523 axes = self.axesList[i*self.__nsubplots]
524 524
525 525 SNRavgdB = SNRavgdB.reshape((1,-1))
526 526
527 527 axes.pcolorbuffer(x, y, SNRavgdB,
528 528 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
529 529 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
530 530 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
531 531
532 532 self.draw()
533 533
534 534 if x[1] >= self.axesList[0].xmax:
535 535 self.counter_imagwr = wr_period
536 536 self.__isConfig = False
537 537 self.figfile = None
538 538
539 539 self.save(figpath=figpath,
540 540 figfile=figfile,
541 541 save=save,
542 542 ftp=ftp,
543 543 wr_period=wr_period,
544 544 thisDatetime=thisDatetime,
545 545 update_figfile=False)
546 546
547 547
548 548 class ParametersPlot(Figure):
549 549
550 550 __isConfig = None
551 551 __nsubplots = None
552 552
553 553 WIDTHPROF = None
554 554 HEIGHTPROF = None
555 555 PREFIX = 'prm'
556 556
557 557 def __init__(self):
558 558
559 559 self.timerange = 2*60*60
560 560 self.__isConfig = False
561 561 self.__nsubplots = 1
562 562
563 563 self.WIDTH = 800
564 564 self.HEIGHT = 150
565 565 self.WIDTHPROF = 120
566 566 self.HEIGHTPROF = 0
567 567 self.counter_imagwr = 0
568 568
569 569 self.PLOT_CODE = PARMS_CODE
570 570
571 571 self.FTP_WEI = None
572 572 self.EXP_CODE = None
573 573 self.SUB_EXP_CODE = None
574 574 self.PLOT_POS = None
575 575 self.tmin = None
576 576 self.tmax = None
577 577
578 578 self.xmin = None
579 579 self.xmax = None
580 580
581 581 self.figfile = None
582 582
583 583 def getSubplots(self):
584 584
585 585 ncol = 1
586 586 nrow = self.nplots
587 587
588 588 return nrow, ncol
589 589
590 590 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
591 591
592 592 self.__showprofile = showprofile
593 593 self.nplots = nplots
594 594
595 595 ncolspan = 1
596 596 colspan = 1
597 597
598 598 self.createFigure(id = id,
599 599 wintitle = wintitle,
600 600 widthplot = self.WIDTH + self.WIDTHPROF,
601 601 heightplot = self.HEIGHT + self.HEIGHTPROF,
602 602 show=show)
603 603
604 604 nrow, ncol = self.getSubplots()
605 605
606 606 counter = 0
607 607 for y in range(nrow):
608 608 for x in range(ncol):
609 609
610 610 if counter >= self.nplots:
611 611 break
612 612
613 613 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
614 614
615 615 if showprofile:
616 616 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
617 617
618 618 counter += 1
619 619
620 620 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
621 621 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
622 622 parameterIndex = None, onlyPositive = False,
623 623 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None,
624 DOP = True,
624 625 zlabel = "", parameterName = "", parameterObject = "data_param",
625 626 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
626 627 server=None, folder=None, username=None, password=None,
627 628 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
628 629
629 630 """
630 631
631 632 Input:
632 633 dataOut :
633 634 id :
634 635 wintitle :
635 636 channelList :
636 637 showProfile :
637 638 xmin : None,
638 639 xmax : None,
639 640 ymin : None,
640 641 ymax : None,
641 642 zmin : None,
642 643 zmax : None
643 644 """
644 645
645 646 data_param = getattr(dataOut, parameterObject)
646 647
647 648 if channelList == None:
648 649 channelIndexList = numpy.arange(data_param.shape[0])
649 650 else:
650 651 channelIndexList = numpy.array(channelList)
651 652
652 653 nchan = len(channelIndexList) #Number of channels being plotted
653 654
655 if nchan < 1:
656 return
657
658 nGraphsByChannel = 0
659
660 if SNR:
661 nGraphsByChannel += 1
662 if DOP:
663 nGraphsByChannel += 1
664
665 if nGraphsByChannel < 1:
666 return
667
668 nplots = nGraphsByChannel*nchan
669
654 670 if timerange != None:
655 671 self.timerange = timerange
656 672
657 673 #tmin = None
658 674 #tmax = None
659 675 if parameterIndex == None:
660 676 parameterIndex = 1
677
661 678 x = dataOut.getTimeRange1()
662 679 y = dataOut.heightList
663 680 z = data_param[channelIndexList,parameterIndex,:].copy()
664 681
665 682 zRange = dataOut.abscissaList
666 nplots = z.shape[0] #Number of wind dimensions estimated
683 # nChannels = z.shape[0] #Number of wind dimensions estimated
667 684 # thisDatetime = dataOut.datatime
668 685
669 686 if dataOut.data_SNR != None:
670 687 SNRarray = dataOut.data_SNR[channelIndexList,:]
671 688 SNRdB = 10*numpy.log10(SNRarray)
672 689 # SNRavgdB = 10*numpy.log10(SNRavg)
673 690 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
674 691 z[ind] = numpy.nan
675 692
676 693 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
677 694 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
678 695 xlabel = ""
679 696 ylabel = "Range (Km)"
680 697
681 if SNR: nplots = 2*nplots
682
683 698 if onlyPositive:
684 699 colormap = "jet"
685 700 zmin = 0
686 701 else: colormap = "RdBu_r"
687 702
688 703 if not self.__isConfig:
689 704
690 705 self.setup(id=id,
691 706 nplots=nplots,
692 707 wintitle=wintitle,
693 708 showprofile=showprofile,
694 709 show=show)
695 710
696 711 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
697 712
698 713 if ymin == None: ymin = numpy.nanmin(y)
699 714 if ymax == None: ymax = numpy.nanmax(y)
700 715 if zmin == None: zmin = numpy.nanmin(zRange)
701 716 if zmax == None: zmax = numpy.nanmax(zRange)
702 717
703 if SNR != None:
718 if SNR:
704 719 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
705 720 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
706 721
707 722 self.FTP_WEI = ftp_wei
708 723 self.EXP_CODE = exp_code
709 724 self.SUB_EXP_CODE = sub_exp_code
710 725 self.PLOT_POS = plot_pos
711 726
712 727 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
713 728 self.__isConfig = True
714 729 self.figfile = figfile
715 730
716 731 self.setWinTitle(title)
717 732
718 733 if ((self.xmax - x[1]) < (x[1]-x[0])):
719 734 x[1] = self.xmax
720 735
721 736 for i in range(nchan):
722 if SNR: j = 2*i
723 else: j = i
724 737
725 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
738 j = nGraphsByChannel*i
726 739
727 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
728 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
729 axes = self.axesList[j*self.__nsubplots]
730 z1 = z[i,:].reshape((1,-1))
731 axes.pcolorbuffer(x, y, z1,
732 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
733 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
734 ticksize=9, cblabel=zlabel, cbsize="1%")
740 if DOP:
741 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
742
743 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
744 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
745 axes = self.axesList[j]
746 z1 = z[i,:].reshape((1,-1))
747 axes.pcolorbuffer(x, y, z1,
748 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
749 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
750 ticksize=9, cblabel=zlabel, cbsize="1%")
735 751
736 752 if SNR:
737 753 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
738 axes = self.axesList[(j + 1)*self.__nsubplots]
754 axes = self.axesList[(j + nGraphsByChannel-1)]
739 755 z1 = SNRdB[i,:].reshape((1,-1))
740 756 axes.pcolorbuffer(x, y, z1,
741 757 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
742 758 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
743 759 ticksize=9, cblabel=zlabel, cbsize="1%")
744 760
745 761
746 762
747 763 self.draw()
748 764
749 765 if x[1] >= self.axesList[0].xmax:
750 766 self.counter_imagwr = wr_period
751 767 self.__isConfig = False
752 768 self.figfile = None
753 769
754 770 self.save(figpath=figpath,
755 771 figfile=figfile,
756 772 save=save,
757 773 ftp=ftp,
758 774 wr_period=wr_period,
759 775 thisDatetime=thisDatetime,
760 776 update_figfile=False)
761 777
762 778 class SpectralFittingPlot(Figure):
763 779
764 780 __isConfig = None
765 781 __nsubplots = None
766 782
767 783 WIDTHPROF = None
768 784 HEIGHTPROF = None
769 785 PREFIX = 'prm'
770 786
771 787
772 788 N = None
773 789 ippSeconds = None
774 790
775 791 def __init__(self):
776 792 self.__isConfig = False
777 793 self.__nsubplots = 1
778 794
779 795 self.PLOT_CODE = SPECFIT_CODE
780 796
781 797 self.WIDTH = 450
782 798 self.HEIGHT = 250
783 799 self.WIDTHPROF = 0
784 800 self.HEIGHTPROF = 0
785 801
786 802 def getSubplots(self):
787 803
788 804 ncol = int(numpy.sqrt(self.nplots)+0.9)
789 805 nrow = int(self.nplots*1./ncol + 0.9)
790 806
791 807 return nrow, ncol
792 808
793 809 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
794 810
795 811 showprofile = False
796 812 self.__showprofile = showprofile
797 813 self.nplots = nplots
798 814
799 815 ncolspan = 5
800 816 colspan = 4
801 817 if showprofile:
802 818 ncolspan = 5
803 819 colspan = 4
804 820 self.__nsubplots = 2
805 821
806 822 self.createFigure(id = id,
807 823 wintitle = wintitle,
808 824 widthplot = self.WIDTH + self.WIDTHPROF,
809 825 heightplot = self.HEIGHT + self.HEIGHTPROF,
810 826 show=show)
811 827
812 828 nrow, ncol = self.getSubplots()
813 829
814 830 counter = 0
815 831 for y in range(nrow):
816 832 for x in range(ncol):
817 833
818 834 if counter >= self.nplots:
819 835 break
820 836
821 837 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
822 838
823 839 if showprofile:
824 840 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
825 841
826 842 counter += 1
827 843
828 844 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
829 845 xmin=None, xmax=None, ymin=None, ymax=None,
830 846 save=False, figpath='./', figfile=None, show=True):
831 847
832 848 """
833 849
834 850 Input:
835 851 dataOut :
836 852 id :
837 853 wintitle :
838 854 channelList :
839 855 showProfile :
840 856 xmin : None,
841 857 xmax : None,
842 858 zmin : None,
843 859 zmax : None
844 860 """
845 861
846 862 if cutHeight==None:
847 863 h=270
848 864 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
849 865 cutHeight = dataOut.heightList[heightindex]
850 866
851 867 factor = dataOut.normFactor
852 868 x = dataOut.abscissaList[:-1]
853 869 #y = dataOut.getHeiRange()
854 870
855 871 z = dataOut.data_pre[:,:,heightindex]/factor
856 872 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
857 873 avg = numpy.average(z, axis=1)
858 874 listChannels = z.shape[0]
859 875
860 876 #Reconstruct Function
861 877 if fit==True:
862 878 groupArray = dataOut.groupList
863 879 listChannels = groupArray.reshape((groupArray.size))
864 880 listChannels.sort()
865 881 spcFitLine = numpy.zeros(z.shape)
866 882 constants = dataOut.constants
867 883
868 884 nGroups = groupArray.shape[0]
869 885 nChannels = groupArray.shape[1]
870 886 nProfiles = z.shape[1]
871 887
872 888 for f in range(nGroups):
873 889 groupChann = groupArray[f,:]
874 890 p = dataOut.data_param[f,:,heightindex]
875 891 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
876 892 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
877 893 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
878 894 spcFitLine[groupChann,:] = fitLineAux
879 895 # spcFitLine = spcFitLine/factor
880 896
881 897 z = z[listChannels,:]
882 898 spcFitLine = spcFitLine[listChannels,:]
883 899 spcFitLinedB = 10*numpy.log10(spcFitLine)
884 900
885 901 zdB = 10*numpy.log10(z)
886 902 #thisDatetime = dataOut.datatime
887 903 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
888 904 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
889 905 xlabel = "Velocity (m/s)"
890 906 ylabel = "Spectrum"
891 907
892 908 if not self.__isConfig:
893 909
894 910 nplots = listChannels.size
895 911
896 912 self.setup(id=id,
897 913 nplots=nplots,
898 914 wintitle=wintitle,
899 915 showprofile=showprofile,
900 916 show=show)
901 917
902 918 if xmin == None: xmin = numpy.nanmin(x)
903 919 if xmax == None: xmax = numpy.nanmax(x)
904 920 if ymin == None: ymin = numpy.nanmin(zdB)
905 921 if ymax == None: ymax = numpy.nanmax(zdB)+2
906 922
907 923 self.__isConfig = True
908 924
909 925 self.setWinTitle(title)
910 926 for i in range(self.nplots):
911 927 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
912 928 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]+1)
913 929 axes = self.axesList[i*self.__nsubplots]
914 930 if fit == False:
915 931 axes.pline(x, zdB[i,:],
916 932 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
917 933 xlabel=xlabel, ylabel=ylabel, title=title
918 934 )
919 935 if fit == True:
920 936 fitline=spcFitLinedB[i,:]
921 937 y=numpy.vstack([zdB[i,:],fitline] )
922 938 legendlabels=['Data','Fitting']
923 939 axes.pmultilineyaxis(x, y,
924 940 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
925 941 xlabel=xlabel, ylabel=ylabel, title=title,
926 942 legendlabels=legendlabels, marker=None,
927 943 linestyle='solid', grid='both')
928 944
929 945 self.draw()
930 946
931 947 self.save(figpath=figpath,
932 948 figfile=figfile,
933 949 save=save,
934 950 ftp=ftp,
935 951 wr_period=wr_period,
936 952 thisDatetime=thisDatetime)
937 953
938 954
939 955 class EWDriftsPlot(Figure):
940 956
941 957 __isConfig = None
942 958 __nsubplots = None
943 959
944 960 WIDTHPROF = None
945 961 HEIGHTPROF = None
946 962 PREFIX = 'drift'
947 963
948 964 def __init__(self):
949 965
950 966 self.timerange = 2*60*60
951 967 self.isConfig = False
952 968 self.__nsubplots = 1
953 969
954 970 self.WIDTH = 800
955 971 self.HEIGHT = 150
956 972 self.WIDTHPROF = 120
957 973 self.HEIGHTPROF = 0
958 974 self.counter_imagwr = 0
959 975
960 976 self.PLOT_CODE = EWDRIFT_CODE
961 977
962 978 self.FTP_WEI = None
963 979 self.EXP_CODE = None
964 980 self.SUB_EXP_CODE = None
965 981 self.PLOT_POS = None
966 982 self.tmin = None
967 983 self.tmax = None
968 984
969 985 self.xmin = None
970 986 self.xmax = None
971 987
972 988 self.figfile = None
973 989
974 990 def getSubplots(self):
975 991
976 992 ncol = 1
977 993 nrow = self.nplots
978 994
979 995 return nrow, ncol
980 996
981 997 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
982 998
983 999 self.__showprofile = showprofile
984 1000 self.nplots = nplots
985 1001
986 1002 ncolspan = 1
987 1003 colspan = 1
988 1004
989 1005 self.createFigure(id = id,
990 1006 wintitle = wintitle,
991 1007 widthplot = self.WIDTH + self.WIDTHPROF,
992 1008 heightplot = self.HEIGHT + self.HEIGHTPROF,
993 1009 show=show)
994 1010
995 1011 nrow, ncol = self.getSubplots()
996 1012
997 1013 counter = 0
998 1014 for y in range(nrow):
999 1015 if counter >= self.nplots:
1000 1016 break
1001 1017
1002 1018 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1003 1019 counter += 1
1004 1020
1005 1021 def run(self, dataOut, id, wintitle="", channelList=None,
1006 1022 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1007 1023 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1008 1024 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1009 1025 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1010 1026 server=None, folder=None, username=None, password=None,
1011 1027 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1012 1028 """
1013 1029
1014 1030 Input:
1015 1031 dataOut :
1016 1032 id :
1017 1033 wintitle :
1018 1034 channelList :
1019 1035 showProfile :
1020 1036 xmin : None,
1021 1037 xmax : None,
1022 1038 ymin : None,
1023 1039 ymax : None,
1024 1040 zmin : None,
1025 1041 zmax : None
1026 1042 """
1027 1043
1028 1044 if timerange != None:
1029 1045 self.timerange = timerange
1030 1046
1031 1047 tmin = None
1032 1048 tmax = None
1033 1049
1034 1050 x = dataOut.getTimeRange1()
1035 1051 # y = dataOut.heightList
1036 1052 y = dataOut.heightList
1037 1053
1038 1054 z = dataOut.data_output
1039 1055 nplots = z.shape[0] #Number of wind dimensions estimated
1040 1056 nplotsw = nplots
1041 1057
1042 1058 #If there is a SNR function defined
1043 1059 if dataOut.data_SNR != None:
1044 1060 nplots += 1
1045 1061 SNR = dataOut.data_SNR
1046 1062
1047 1063 if SNR_1:
1048 1064 SNR += 1
1049 1065
1050 1066 SNRavg = numpy.average(SNR, axis=0)
1051 1067
1052 1068 SNRdB = 10*numpy.log10(SNR)
1053 1069 SNRavgdB = 10*numpy.log10(SNRavg)
1054 1070
1055 1071 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1056 1072
1057 1073 for i in range(nplotsw):
1058 1074 z[i,ind] = numpy.nan
1059 1075
1060 1076
1061 1077 showprofile = False
1062 1078 # thisDatetime = dataOut.datatime
1063 1079 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1064 1080 title = wintitle + " EW Drifts"
1065 1081 xlabel = ""
1066 1082 ylabel = "Height (Km)"
1067 1083
1068 1084 if not self.__isConfig:
1069 1085
1070 1086 self.setup(id=id,
1071 1087 nplots=nplots,
1072 1088 wintitle=wintitle,
1073 1089 showprofile=showprofile,
1074 1090 show=show)
1075 1091
1076 1092 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1077 1093
1078 1094 if ymin == None: ymin = numpy.nanmin(y)
1079 1095 if ymax == None: ymax = numpy.nanmax(y)
1080 1096
1081 1097 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1082 1098 if zminZonal == None: zminZonal = -zmaxZonal
1083 1099 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1084 1100 if zminVertical == None: zminVertical = -zmaxVertical
1085 1101
1086 1102 if dataOut.data_SNR != None:
1087 1103 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1088 1104 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1089 1105
1090 1106 self.FTP_WEI = ftp_wei
1091 1107 self.EXP_CODE = exp_code
1092 1108 self.SUB_EXP_CODE = sub_exp_code
1093 1109 self.PLOT_POS = plot_pos
1094 1110
1095 1111 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1096 1112 self.__isConfig = True
1097 1113
1098 1114
1099 1115 self.setWinTitle(title)
1100 1116
1101 1117 if ((self.xmax - x[1]) < (x[1]-x[0])):
1102 1118 x[1] = self.xmax
1103 1119
1104 1120 strWind = ['Zonal','Vertical']
1105 1121 strCb = 'Velocity (m/s)'
1106 1122 zmaxVector = [zmaxZonal, zmaxVertical]
1107 1123 zminVector = [zminZonal, zminVertical]
1108 1124
1109 1125 for i in range(nplotsw):
1110 1126
1111 1127 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1112 1128 axes = self.axesList[i*self.__nsubplots]
1113 1129
1114 1130 z1 = z[i,:].reshape((1,-1))
1115 1131
1116 1132 axes.pcolorbuffer(x, y, z1,
1117 1133 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1118 1134 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1119 1135 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1120 1136
1121 1137 if dataOut.data_SNR != None:
1122 1138 i += 1
1123 1139 if SNR_1:
1124 1140 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1125 1141 else:
1126 1142 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1127 1143 axes = self.axesList[i*self.__nsubplots]
1128 1144 SNRavgdB = SNRavgdB.reshape((1,-1))
1129 1145
1130 1146 axes.pcolorbuffer(x, y, SNRavgdB,
1131 1147 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1132 1148 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1133 1149 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1134 1150
1135 1151 self.draw()
1136 1152
1137 1153 if x[1] >= self.axesList[0].xmax:
1138 1154 self.counter_imagwr = wr_period
1139 1155 self.__isConfig = False
1140 1156 self.figfile = None
1141 1157
1142 1158 self.save(figpath=figpath,
1143 1159 figfile=figfile,
1144 1160 save=save,
1145 1161 ftp=ftp,
1146 1162 wr_period=wr_period,
1147 1163 thisDatetime=thisDatetime,
1148 1164 update_figfile=False) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now