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