##// END OF EJS Templates
-jrodata, parameters class bug fixed...
Julio Valdez -
r550:5ffe99434b98
parent child
Show More
@@ -1,1025 +1,1025
1 1 '''
2 2
3 3 $Author: murco $
4 4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
5 5 '''
6 6
7 7 import copy
8 8 import numpy
9 9 import datetime
10 10
11 11 from jroheaderIO import SystemHeader, RadarControllerHeader
12 12
13 13 def getNumpyDtype(dataTypeCode):
14 14
15 15 if dataTypeCode == 0:
16 16 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
17 17 elif dataTypeCode == 1:
18 18 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
19 19 elif dataTypeCode == 2:
20 20 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
21 21 elif dataTypeCode == 3:
22 22 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
23 23 elif dataTypeCode == 4:
24 24 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
25 25 elif dataTypeCode == 5:
26 26 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
27 27 else:
28 28 raise ValueError, 'dataTypeCode was not defined'
29 29
30 30 return numpyDtype
31 31
32 32 def getDataTypeCode(numpyDtype):
33 33
34 34 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
35 35 datatype = 0
36 36 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
37 37 datatype = 1
38 38 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
39 39 datatype = 2
40 40 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
41 41 datatype = 3
42 42 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
43 43 datatype = 4
44 44 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
45 45 datatype = 5
46 46 else:
47 47 datatype = None
48 48
49 49 return datatype
50 50
51 51 def hildebrand_sekhon(data, navg):
52 52
53 53 data = data.copy()
54 54
55 55 sortdata = numpy.sort(data,axis=None)
56 56 lenOfData = len(sortdata)
57 57 nums_min = lenOfData/10
58 58
59 59 if (lenOfData/10) > 2:
60 60 nums_min = lenOfData/10
61 61 else:
62 62 nums_min = 2
63 63
64 64 sump = 0.
65 65
66 66 sumq = 0.
67 67
68 68 j = 0
69 69
70 70 cont = 1
71 71
72 72 while((cont==1)and(j<lenOfData)):
73 73
74 74 sump += sortdata[j]
75 75
76 76 sumq += sortdata[j]**2
77 77
78 78 j += 1
79 79
80 80 if j > nums_min:
81 81 rtest = float(j)/(j-1) + 1.0/navg
82 82 if ((sumq*j) > (rtest*sump**2)):
83 83 j = j - 1
84 84 sump = sump - sortdata[j]
85 85 sumq = sumq - sortdata[j]**2
86 86 cont = 0
87 87
88 88 lnoise = sump /j
89 89 stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1))
90 90 return lnoise
91 91
92 92 class Beam:
93 93 def __init__(self):
94 94 self.codeList = []
95 95 self.azimuthList = []
96 96 self.zenithList = []
97 97
98 98 class GenericData(object):
99 99
100 100 flagNoData = True
101 101
102 102 def __init__(self):
103 103
104 104 raise ValueError, "This class has not been implemented"
105 105
106 106 def copy(self, inputObj=None):
107 107
108 108 if inputObj == None:
109 109 return copy.deepcopy(self)
110 110
111 111 for key in inputObj.__dict__.keys():
112 112 self.__dict__[key] = inputObj.__dict__[key]
113 113
114 114 def deepcopy(self):
115 115
116 116 return copy.deepcopy(self)
117 117
118 118 def isEmpty(self):
119 119
120 120 return self.flagNoData
121 121
122 122 class JROData(GenericData):
123 123
124 124 # m_BasicHeader = BasicHeader()
125 125 # m_ProcessingHeader = ProcessingHeader()
126 126
127 127 systemHeaderObj = SystemHeader()
128 128
129 129 radarControllerHeaderObj = RadarControllerHeader()
130 130
131 131 # data = None
132 132
133 133 type = None
134 134
135 135 datatype = None #dtype but in string
136 136
137 137 # dtype = None
138 138
139 139 # nChannels = None
140 140
141 141 # nHeights = None
142 142
143 143 nProfiles = None
144 144
145 145 heightList = None
146 146
147 147 channelList = None
148 148
149 149 flagTimeBlock = False
150 150
151 151 useLocalTime = False
152 152
153 153 utctime = None
154 154
155 155 timeZone = None
156 156
157 157 dstFlag = None
158 158
159 159 errorCount = None
160 160
161 161 blocksize = None
162 162
163 163 nCode = None
164 164
165 165 nBaud = None
166 166
167 167 code = None
168 168
169 169 flagDecodeData = False #asumo q la data no esta decodificada
170 170
171 171 flagDeflipData = False #asumo q la data no esta sin flip
172 172
173 173 flagShiftFFT = False
174 174
175 175 # ippSeconds = None
176 176
177 177 # timeInterval = None
178 178
179 179 nCohInt = None
180 180
181 181 noise = None
182 182
183 183 windowOfFilter = 1
184 184
185 185 #Speed of ligth
186 186 C = 3e8
187 187
188 188 frequency = 49.92e6
189 189
190 190 realtime = False
191 191
192 192 beacon_heiIndexList = None
193 193
194 194 last_block = None
195 195
196 196 blocknow = None
197 197
198 198 azimuth = None
199 199
200 200 zenith = None
201 201
202 202 beam = Beam()
203 203
204 204 profileIndex = None
205 205
206 206 def __init__(self):
207 207
208 208 raise ValueError, "This class has not been implemented"
209 209
210 210 def getNoise(self):
211 211
212 212 raise ValueError, "Not implemented"
213 213
214 214 def getNChannels(self):
215 215
216 216 return len(self.channelList)
217 217
218 218 def getChannelIndexList(self):
219 219
220 220 return range(self.nChannels)
221 221
222 222 def getNHeights(self):
223 223
224 224 return len(self.heightList)
225 225
226 226 def getHeiRange(self, extrapoints=0):
227 227
228 228 heis = self.heightList
229 229 # deltah = self.heightList[1] - self.heightList[0]
230 230 #
231 231 # heis.append(self.heightList[-1])
232 232
233 233 return heis
234 234
235 235 def getltctime(self):
236 236
237 237 if self.useLocalTime:
238 238 return self.utctime - self.timeZone*60
239 239
240 240 return self.utctime
241 241
242 242 def getDatatime(self):
243 243
244 244 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
245 245 return datatimeValue
246 246
247 247 def getTimeRange(self):
248 248
249 249 datatime = []
250 250
251 251 datatime.append(self.ltctime)
252 252 datatime.append(self.ltctime + self.timeInterval)
253 253
254 254 datatime = numpy.array(datatime)
255 255
256 256 return datatime
257 257
258 258 def getFmax(self):
259 259
260 260 PRF = 1./(self.ippSeconds * self.nCohInt)
261 261
262 262 fmax = PRF/2.
263 263
264 264 return fmax
265 265
266 266 def getVmax(self):
267 267
268 268 _lambda = self.C/self.frequency
269 269
270 270 vmax = self.getFmax() * _lambda
271 271
272 272 return vmax
273 273
274 274 def get_ippSeconds(self):
275 275 '''
276 276 '''
277 277 return self.radarControllerHeaderObj.ippSeconds
278 278
279 279 def set_ippSeconds(self, ippSeconds):
280 280 '''
281 281 '''
282 282
283 283 self.radarControllerHeaderObj.ippSeconds = ippSeconds
284 284
285 285 return
286 286
287 287 def get_dtype(self):
288 288 '''
289 289 '''
290 290 return getNumpyDtype(self.datatype)
291 291
292 292 def set_dtype(self, numpyDtype):
293 293 '''
294 294 '''
295 295
296 296 self.datatype = getDataTypeCode(numpyDtype)
297 297
298 298 # def getTimeInterval(self):
299 299 #
300 300 # raise IOError, "This method should be implemented inside each Class"
301 301
302 302 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
303 303 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
304 304 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
305 305 #noise = property(getNoise, "I'm the 'nHeights' property.")
306 306 datatime = property(getDatatime, "I'm the 'datatime' property")
307 307 ltctime = property(getltctime, "I'm the 'ltctime' property")
308 308 ippSeconds = property(get_ippSeconds, set_ippSeconds)
309 309 dtype = property(get_dtype, set_dtype)
310 310 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
311 311
312 312 class Voltage(JROData):
313 313
314 314 #data es un numpy array de 2 dmensiones (canales, alturas)
315 315 data = None
316 316
317 317 def __init__(self):
318 318 '''
319 319 Constructor
320 320 '''
321 321
322 322 self.radarControllerHeaderObj = RadarControllerHeader()
323 323
324 324 self.systemHeaderObj = SystemHeader()
325 325
326 326 self.type = "Voltage"
327 327
328 328 self.data = None
329 329
330 330 # self.dtype = None
331 331
332 332 # self.nChannels = 0
333 333
334 334 # self.nHeights = 0
335 335
336 336 self.nProfiles = None
337 337
338 338 self.heightList = None
339 339
340 340 self.channelList = None
341 341
342 342 # self.channelIndexList = None
343 343
344 344 self.flagNoData = True
345 345
346 346 self.flagTimeBlock = False
347 347
348 348 self.utctime = None
349 349
350 350 self.timeZone = None
351 351
352 352 self.dstFlag = None
353 353
354 354 self.errorCount = None
355 355
356 356 self.nCohInt = None
357 357
358 358 self.blocksize = None
359 359
360 360 self.flagDecodeData = False #asumo q la data no esta decodificada
361 361
362 362 self.flagDeflipData = False #asumo q la data no esta sin flip
363 363
364 364 self.flagShiftFFT = False
365 365
366 366 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
367 367
368 368 self.profileIndex = 0
369 369
370 370 def getNoisebyHildebrand(self):
371 371 """
372 372 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
373 373
374 374 Return:
375 375 noiselevel
376 376 """
377 377
378 378 for channel in range(self.nChannels):
379 379 daux = self.data_spc[channel,:,:]
380 380 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
381 381
382 382 return self.noise
383 383
384 384 def getNoise(self, type = 1):
385 385
386 386 self.noise = numpy.zeros(self.nChannels)
387 387
388 388 if type == 1:
389 389 noise = self.getNoisebyHildebrand()
390 390
391 391 return 10*numpy.log10(noise)
392 392
393 393 def getTimeInterval(self):
394 394
395 395 timeInterval = self.ippSeconds * self.nCohInt
396 396
397 397 return timeInterval
398 398
399 399 noise = property(getNoise, "I'm the 'nHeights' property.")
400 400 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
401 401
402 402 class Spectra(JROData):
403 403
404 404 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
405 405 data_spc = None
406 406
407 407 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
408 408 data_cspc = None
409 409
410 410 #data es un numpy array de 2 dmensiones (canales, alturas)
411 411 data_dc = None
412 412
413 413 nFFTPoints = None
414 414
415 415 # nPairs = None
416 416
417 417 pairsList = None
418 418
419 419 nIncohInt = None
420 420
421 421 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
422 422
423 423 nCohInt = None #se requiere para determinar el valor de timeInterval
424 424
425 425 ippFactor = None
426 426
427 427 profileIndex = 0
428 428
429 429 def __init__(self):
430 430 '''
431 431 Constructor
432 432 '''
433 433
434 434 self.radarControllerHeaderObj = RadarControllerHeader()
435 435
436 436 self.systemHeaderObj = SystemHeader()
437 437
438 438 self.type = "Spectra"
439 439
440 440 # self.data = None
441 441
442 442 # self.dtype = None
443 443
444 444 # self.nChannels = 0
445 445
446 446 # self.nHeights = 0
447 447
448 448 self.nProfiles = None
449 449
450 450 self.heightList = None
451 451
452 452 self.channelList = None
453 453
454 454 # self.channelIndexList = None
455 455
456 456 self.pairsList = None
457 457
458 458 self.flagNoData = True
459 459
460 460 self.flagTimeBlock = False
461 461
462 462 self.utctime = None
463 463
464 464 self.nCohInt = None
465 465
466 466 self.nIncohInt = None
467 467
468 468 self.blocksize = None
469 469
470 470 self.nFFTPoints = None
471 471
472 472 self.wavelength = None
473 473
474 474 self.flagDecodeData = False #asumo q la data no esta decodificada
475 475
476 476 self.flagDeflipData = False #asumo q la data no esta sin flip
477 477
478 478 self.flagShiftFFT = False
479 479
480 480 self.ippFactor = 1
481 481
482 482 #self.noise = None
483 483
484 484 self.beacon_heiIndexList = []
485 485
486 486 self.noise_estimation = None
487 487
488 488
489 489 def getNoisebyHildebrand(self):
490 490 """
491 491 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
492 492
493 493 Return:
494 494 noiselevel
495 495 """
496 496
497 497 noise = numpy.zeros(self.nChannels)
498 498 for channel in range(self.nChannels):
499 499 daux = self.data_spc[channel,:,:]
500 500 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
501 501
502 502 return noise
503 503
504 504 def getNoise(self):
505 505 if self.noise_estimation != None:
506 506 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
507 507 else:
508 508 noise = self.getNoisebyHildebrand()
509 509 return noise
510 510
511 511
512 512 def getFreqRange(self, extrapoints=0):
513 513
514 514 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
515 515 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
516 516
517 517 return freqrange
518 518
519 519 def getVelRange(self, extrapoints=0):
520 520
521 521 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
522 522 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
523 523
524 524 return velrange
525 525
526 526 def getNPairs(self):
527 527
528 528 return len(self.pairsList)
529 529
530 530 def getPairsIndexList(self):
531 531
532 532 return range(self.nPairs)
533 533
534 534 def getNormFactor(self):
535 535 pwcode = 1
536 536 if self.flagDecodeData:
537 537 pwcode = numpy.sum(self.code[0]**2)
538 538 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
539 539 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
540 540
541 541 return normFactor
542 542
543 543 def getFlagCspc(self):
544 544
545 545 if self.data_cspc == None:
546 546 return True
547 547
548 548 return False
549 549
550 550 def getFlagDc(self):
551 551
552 552 if self.data_dc == None:
553 553 return True
554 554
555 555 return False
556 556
557 557 def getTimeInterval(self):
558 558
559 559 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
560 560
561 561 return timeInterval
562 562
563 563 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
564 564 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
565 565 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
566 566 flag_cspc = property(getFlagCspc)
567 567 flag_dc = property(getFlagDc)
568 568 noise = property(getNoise, "I'm the 'nHeights' property.")
569 569 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
570 570
571 571 class SpectraHeis(Spectra):
572 572
573 573 data_spc = None
574 574
575 575 data_cspc = None
576 576
577 577 data_dc = None
578 578
579 579 nFFTPoints = None
580 580
581 581 # nPairs = None
582 582
583 583 pairsList = None
584 584
585 585 nIncohInt = None
586 586
587 587 def __init__(self):
588 588
589 589 self.radarControllerHeaderObj = RadarControllerHeader()
590 590
591 591 self.systemHeaderObj = SystemHeader()
592 592
593 593 self.type = "SpectraHeis"
594 594
595 595 # self.dtype = None
596 596
597 597 # self.nChannels = 0
598 598
599 599 # self.nHeights = 0
600 600
601 601 self.nProfiles = None
602 602
603 603 self.heightList = None
604 604
605 605 self.channelList = None
606 606
607 607 # self.channelIndexList = None
608 608
609 609 self.flagNoData = True
610 610
611 611 self.flagTimeBlock = False
612 612
613 613 # self.nPairs = 0
614 614
615 615 self.utctime = None
616 616
617 617 self.blocksize = None
618 618
619 619 self.profileIndex = 0
620 620
621 621 def getNormFactor(self):
622 622 pwcode = 1
623 623 if self.flagDecodeData:
624 624 pwcode = numpy.sum(self.code[0]**2)
625 625
626 626 normFactor = self.nIncohInt*self.nCohInt*pwcode
627 627
628 628 return normFactor
629 629
630 630 def getTimeInterval(self):
631 631
632 632 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
633 633
634 634 return timeInterval
635 635
636 636 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
637 637 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
638 638
639 639 class Fits:
640 640
641 641 heightList = None
642 642
643 643 channelList = None
644 644
645 645 flagNoData = True
646 646
647 647 flagTimeBlock = False
648 648
649 649 useLocalTime = False
650 650
651 651 utctime = None
652 652
653 653 timeZone = None
654 654
655 655 # ippSeconds = None
656 656
657 657 # timeInterval = None
658 658
659 659 nCohInt = None
660 660
661 661 nIncohInt = None
662 662
663 663 noise = None
664 664
665 665 windowOfFilter = 1
666 666
667 667 #Speed of ligth
668 668 C = 3e8
669 669
670 670 frequency = 49.92e6
671 671
672 672 realtime = False
673 673
674 674
675 675 def __init__(self):
676 676
677 677 self.type = "Fits"
678 678
679 679 self.nProfiles = None
680 680
681 681 self.heightList = None
682 682
683 683 self.channelList = None
684 684
685 685 # self.channelIndexList = None
686 686
687 687 self.flagNoData = True
688 688
689 689 self.utctime = None
690 690
691 691 self.nCohInt = None
692 692
693 693 self.nIncohInt = None
694 694
695 695 self.useLocalTime = True
696 696
697 697 self.profileIndex = 0
698 698
699 699 # self.utctime = None
700 700 # self.timeZone = None
701 701 # self.ltctime = None
702 702 # self.timeInterval = None
703 703 # self.header = None
704 704 # self.data_header = None
705 705 # self.data = None
706 706 # self.datatime = None
707 707 # self.flagNoData = False
708 708 # self.expName = ''
709 709 # self.nChannels = None
710 710 # self.nSamples = None
711 711 # self.dataBlocksPerFile = None
712 712 # self.comments = ''
713 713 #
714 714
715 715
716 716 def getltctime(self):
717 717
718 718 if self.useLocalTime:
719 719 return self.utctime - self.timeZone*60
720 720
721 721 return self.utctime
722 722
723 723 def getDatatime(self):
724 724
725 725 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
726 726 return datatime
727 727
728 728 def getTimeRange(self):
729 729
730 730 datatime = []
731 731
732 732 datatime.append(self.ltctime)
733 733 datatime.append(self.ltctime + self.timeInterval)
734 734
735 735 datatime = numpy.array(datatime)
736 736
737 737 return datatime
738 738
739 739 def getHeiRange(self):
740 740
741 741 heis = self.heightList
742 742
743 743 return heis
744 744
745 745 def isEmpty(self):
746 746
747 747 return self.flagNoData
748 748
749 749 def getNHeights(self):
750 750
751 751 return len(self.heightList)
752 752
753 753 def getNChannels(self):
754 754
755 755 return len(self.channelList)
756 756
757 757 def getChannelIndexList(self):
758 758
759 759 return range(self.nChannels)
760 760
761 761 def getNoise(self, type = 1):
762 762
763 763 self.noise = numpy.zeros(self.nChannels)
764 764
765 765 if type == 1:
766 766 noise = self.getNoisebyHildebrand()
767 767
768 768 if type == 2:
769 769 noise = self.getNoisebySort()
770 770
771 771 if type == 3:
772 772 noise = self.getNoisebyWindow()
773 773
774 774 return noise
775 775
776 776 def getTimeInterval(self):
777 777
778 778 raise ValueError, "This method is not implemented yet"
779 779
780 780 datatime = property(getDatatime, "I'm the 'datatime' property")
781 781 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
782 782 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
783 783 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
784 784 noise = property(getNoise, "I'm the 'nHeights' property.")
785 785 datatime = property(getDatatime, "I'm the 'datatime' property")
786 786 ltctime = property(getltctime, "I'm the 'ltctime' property")
787 787 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
788 788
789 789 class Correlation(JROData):
790 790
791 791 noise = None
792 792
793 793 SNR = None
794 794
795 795 pairsAutoCorr = None #Pairs of Autocorrelation
796 796
797 797 #--------------------------------------------------
798 798
799 799 data_corr = None
800 800
801 801 data_volt = None
802 802
803 803 lagT = None # each element value is a profileIndex
804 804
805 805 lagR = None # each element value is in km
806 806
807 807 pairsList = None
808 808
809 809 calculateVelocity = None
810 810
811 811 nPoints = None
812 812
813 813 nAvg = None
814 814
815 815 bufferSize = None
816 816
817 817 def __init__(self):
818 818 '''
819 819 Constructor
820 820 '''
821 821 self.radarControllerHeaderObj = RadarControllerHeader()
822 822
823 823 self.systemHeaderObj = SystemHeader()
824 824
825 825 self.type = "Correlation"
826 826
827 827 self.data = None
828 828
829 829 self.dtype = None
830 830
831 831 self.nProfiles = None
832 832
833 833 self.heightList = None
834 834
835 835 self.channelList = None
836 836
837 837 self.flagNoData = True
838 838
839 839 self.flagTimeBlock = False
840 840
841 841 self.utctime = None
842 842
843 843 self.timeZone = None
844 844
845 845 self.dstFlag = None
846 846
847 847 self.errorCount = None
848 848
849 849 self.blocksize = None
850 850
851 851 self.flagDecodeData = False #asumo q la data no esta decodificada
852 852
853 853 self.flagDeflipData = False #asumo q la data no esta sin flip
854 854
855 855 self.pairsList = None
856 856
857 857 self.nPoints = None
858 858
859 859 def getLagTRange(self, extrapoints=0):
860 860
861 861 lagTRange = self.lagT
862 862 diff = lagTRange[1] - lagTRange[0]
863 863 extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1]
864 864 lagTRange = numpy.hstack((lagTRange, extra))
865 865
866 866 return lagTRange
867 867
868 868 def getLagRRange(self, extrapoints=0):
869 869
870 870 return self.lagR
871 871
872 872 def getPairsList(self):
873 873
874 874 return self.pairsList
875 875
876 876 def getCalculateVelocity(self):
877 877
878 878 return self.calculateVelocity
879 879
880 880 def getNPoints(self):
881 881
882 882 return self.nPoints
883 883
884 884 def getNAvg(self):
885 885
886 886 return self.nAvg
887 887
888 888 def getBufferSize(self):
889 889
890 890 return self.bufferSize
891 891
892 892 def getPairsAutoCorr(self):
893 893 pairsList = self.pairsList
894 894 pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan
895 895
896 896 for l in range(len(pairsList)):
897 897 firstChannel = pairsList[l][0]
898 898 secondChannel = pairsList[l][1]
899 899
900 900 #Obteniendo pares de Autocorrelacion
901 901 if firstChannel == secondChannel:
902 902 pairsAutoCorr[firstChannel] = int(l)
903 903
904 904 pairsAutoCorr = pairsAutoCorr.astype(int)
905 905
906 906 return pairsAutoCorr
907 907
908 908 def getNoise(self, mode = 2):
909 909
910 910 indR = numpy.where(self.lagR == 0)[0][0]
911 911 indT = numpy.where(self.lagT == 0)[0][0]
912 912
913 913 jspectra0 = self.data_corr[:,:,indR,:]
914 914 jspectra = copy.copy(jspectra0)
915 915
916 916 num_chan = jspectra.shape[0]
917 917 num_hei = jspectra.shape[2]
918 918
919 919 freq_dc = jspectra.shape[1]/2
920 920 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
921 921
922 922 if ind_vel[0]<0:
923 923 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
924 924
925 925 if mode == 1:
926 926 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
927 927
928 928 if mode == 2:
929 929
930 930 vel = numpy.array([-2,-1,1,2])
931 931 xx = numpy.zeros([4,4])
932 932
933 933 for fil in range(4):
934 934 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
935 935
936 936 xx_inv = numpy.linalg.inv(xx)
937 937 xx_aux = xx_inv[0,:]
938 938
939 939 for ich in range(num_chan):
940 940 yy = jspectra[ich,ind_vel,:]
941 941 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
942 942
943 943 junkid = jspectra[ich,freq_dc,:]<=0
944 944 cjunkid = sum(junkid)
945 945
946 946 if cjunkid.any():
947 947 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
948 948
949 949 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
950 950
951 951 return noise
952 952
953 953 # pairsList = property(getPairsList, "I'm the 'pairsList' property.")
954 954 # nPoints = property(getNPoints, "I'm the 'nPoints' property.")
955 955 calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.")
956 956 nAvg = property(getNAvg, "I'm the 'nAvg' property.")
957 957 bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.")
958 958
959 959
960 960 class Parameters(JROData):
961 961
962 962 #Information from previous data
963 963
964 964 inputUnit = None #Type of data to be processed
965 965
966 966 operation = None #Type of operation to parametrize
967 967
968 968 normFactor = None #Normalization Factor
969 969
970 970 groupList = None #List of Pairs, Groups, etc
971 971
972 972 #Parameters
973 973
974 974 data_param = None #Parameters obtained
975 975
976 976 data_pre = None #Data Pre Parametrization
977 977
978 978 data_SNR = None #Signal to Noise Ratio
979 979
980 980 heightRange = None #Heights
981 981
982 982 abscissaRange = None #Abscissa, can be velocities, lags or time
983 983
984 984 noise = None #Noise Potency
985 985
986 initUtcTime = None #Initial UTC time
986 utctimeInit = None #Initial UTC time
987 987
988 988 paramInterval = None #Time interval to calculate Parameters in seconds
989 989
990 990 #Fitting
991 991
992 992 data_error = None #Error of the estimation
993 993
994 994 constants = None
995 995
996 996 library = None
997 997
998 998 #Output signal
999 999
1000 1000 outputInterval = None #Time interval to calculate output signal in seconds
1001 1001
1002 1002 data_output = None #Out signal
1003 1003
1004 1004
1005 1005
1006 1006 def __init__(self):
1007 1007 '''
1008 1008 Constructor
1009 1009 '''
1010 1010 self.radarControllerHeaderObj = RadarControllerHeader()
1011 1011
1012 1012 self.systemHeaderObj = SystemHeader()
1013 1013
1014 1014 self.type = "Parameters"
1015 1015
1016 1016 def getTimeRange1(self):
1017 1017
1018 1018 datatime = []
1019 1019
1020 datatime.append(self.initUtcTime)
1021 datatime.append(self.initUtcTime + self.outputInterval - 1)
1020 datatime.append(self.utctimeInit)
1021 datatime.append(self.utctimeInit + self.outputInterval - 1)
1022 1022
1023 1023 datatime = numpy.array(datatime)
1024 1024
1025 1025 return datatime
@@ -1,1195 +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 653 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None,
654 654
655 655 zlabel = "", parameterName = "", parameterObject = "data_param",
656 656 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
657 657 server=None, folder=None, username=None, password=None,
658 658 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
659 659
660 660 """
661 661
662 662 Input:
663 663 dataOut :
664 664 id :
665 665 wintitle :
666 666 channelList :
667 667 showProfile :
668 668 xmin : None,
669 669 xmax : None,
670 670 ymin : None,
671 671 ymax : None,
672 672 zmin : None,
673 673 zmax : None
674 674 """
675 675
676 676 data_param = getattr(dataOut, parameterObject)
677 677
678 678 if channelList == None:
679 679 channelIndexList = numpy.arange(data_param.shape[0])
680 680 else:
681 channelIndexList = numpy.array(channelIndexList)
681 channelIndexList = numpy.array(channelList)
682 682
683 683 nchan = len(channelIndexList) #Number of channels being plotted
684 684
685 685 if timerange != None:
686 686 self.timerange = timerange
687 687
688 688 #tmin = None
689 689 #tmax = None
690 690 if parameterIndex == None:
691 691 parameterIndex = 1
692 692 x = dataOut.getTimeRange1()
693 693 y = dataOut.heightList
694 694 z = data_param[channelIndexList,parameterIndex,:].copy()
695 695
696 696 zRange = dataOut.abscissaList
697 697 nplots = z.shape[0] #Number of wind dimensions estimated
698 698 # thisDatetime = dataOut.datatime
699 699
700 700 if dataOut.data_SNR != None:
701 SNRarray = dataOut.data_SNR
701 SNRarray = dataOut.data_SNR[channelIndexList,:]
702 702 SNRdB = 10*numpy.log10(SNRarray)
703 703 # SNRavgdB = 10*numpy.log10(SNRavg)
704 704 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
705 705 z[ind] = numpy.nan
706 706
707 707 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
708 708 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
709 709 xlabel = ""
710 710 ylabel = "Range (Km)"
711 711
712 712 if SNR: nplots = 2*nplots
713 713
714 714 if onlyPositive:
715 715 colormap = "jet"
716 716 zmin = 0
717 717 else: colormap = "RdBu_r"
718 718
719 719 if not self.__isConfig:
720 720
721 721 self.setup(id=id,
722 722 nplots=nplots,
723 723 wintitle=wintitle,
724 724 showprofile=showprofile,
725 725 show=show)
726 726
727 727 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
728 728
729 729 if ymin == None: ymin = numpy.nanmin(y)
730 730 if ymax == None: ymax = numpy.nanmax(y)
731 731 if zmin == None: zmin = numpy.nanmin(zRange)
732 732 if zmax == None: zmax = numpy.nanmax(zRange)
733 733
734 734 if SNR != None:
735 735 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
736 736 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
737 737
738 738 self.FTP_WEI = ftp_wei
739 739 self.EXP_CODE = exp_code
740 740 self.SUB_EXP_CODE = sub_exp_code
741 741 self.PLOT_POS = plot_pos
742 742
743 743 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
744 744 self.__isConfig = True
745 745 self.figfile = figfile
746 746
747 747 self.setWinTitle(title)
748 748
749 749 if ((self.xmax - x[1]) < (x[1]-x[0])):
750 750 x[1] = self.xmax
751 751
752 752 for i in range(nchan):
753 753 if SNR: j = 2*i
754 754 else: j = i
755 755
756 756 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
757 757
758 758 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
759 759 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
760 760 axes = self.axesList[j*self.__nsubplots]
761 761 z1 = z[i,:].reshape((1,-1))
762 762 axes.pcolorbuffer(x, y, z1,
763 763 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
764 764 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
765 765 ticksize=9, cblabel=zlabel, cbsize="1%")
766 766
767 767 if SNR:
768 768 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
769 769 axes = self.axesList[(j + 1)*self.__nsubplots]
770 770 z1 = SNRdB[i,:].reshape((1,-1))
771 771 axes.pcolorbuffer(x, y, z1,
772 772 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
773 773 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
774 774 ticksize=9, cblabel=zlabel, cbsize="1%")
775 775
776 776
777 777
778 778 self.draw()
779 779
780 780 if self.figfile == None:
781 781 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
782 782 self.figfile = self.getFilename(name = str_datetime)
783 783
784 784 if figpath != '':
785 785
786 786 self.counter_imagwr += 1
787 787 if (self.counter_imagwr>=wr_period):
788 788 # store png plot to local folder
789 789 self.saveFigure(figpath, self.figfile)
790 790 # store png plot to FTP server according to RT-Web format
791 791 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
792 792 ftp_filename = os.path.join(figpath, name)
793 793 self.saveFigure(figpath, ftp_filename)
794 794
795 795 self.counter_imagwr = 0
796 796
797 797 if x[1] >= self.axesList[0].xmax:
798 798 self.counter_imagwr = wr_period
799 799 self.__isConfig = False
800 800 self.figfile = None
801 801
802 802
803 803 class SpectralFittingPlot(Figure):
804 804
805 805 __isConfig = None
806 806 __nsubplots = None
807 807
808 808 WIDTHPROF = None
809 809 HEIGHTPROF = None
810 810 PREFIX = 'prm'
811 811
812 812
813 813 N = None
814 814 ippSeconds = None
815 815
816 816 def __init__(self):
817 817 self.__isConfig = False
818 818 self.__nsubplots = 1
819 819
820 820 self.WIDTH = 450
821 821 self.HEIGHT = 250
822 822 self.WIDTHPROF = 0
823 823 self.HEIGHTPROF = 0
824 824
825 825 def getSubplots(self):
826 826
827 827 ncol = int(numpy.sqrt(self.nplots)+0.9)
828 828 nrow = int(self.nplots*1./ncol + 0.9)
829 829
830 830 return nrow, ncol
831 831
832 832 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
833 833
834 834 showprofile = False
835 835 self.__showprofile = showprofile
836 836 self.nplots = nplots
837 837
838 838 ncolspan = 5
839 839 colspan = 4
840 840 if showprofile:
841 841 ncolspan = 5
842 842 colspan = 4
843 843 self.__nsubplots = 2
844 844
845 845 self.createFigure(id = id,
846 846 wintitle = wintitle,
847 847 widthplot = self.WIDTH + self.WIDTHPROF,
848 848 heightplot = self.HEIGHT + self.HEIGHTPROF,
849 849 show=show)
850 850
851 851 nrow, ncol = self.getSubplots()
852 852
853 853 counter = 0
854 854 for y in range(nrow):
855 855 for x in range(ncol):
856 856
857 857 if counter >= self.nplots:
858 858 break
859 859
860 860 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
861 861
862 862 if showprofile:
863 863 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
864 864
865 865 counter += 1
866 866
867 867 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
868 868 xmin=None, xmax=None, ymin=None, ymax=None,
869 869 save=False, figpath='./', figfile=None, show=True):
870 870
871 871 """
872 872
873 873 Input:
874 874 dataOut :
875 875 id :
876 876 wintitle :
877 877 channelList :
878 878 showProfile :
879 879 xmin : None,
880 880 xmax : None,
881 881 zmin : None,
882 882 zmax : None
883 883 """
884 884
885 885 if cutHeight==None:
886 886 h=270
887 887 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
888 888 cutHeight = dataOut.heightList[heightindex]
889 889
890 890 factor = dataOut.normFactor
891 891 x = dataOut.abscissaList[:-1]
892 892 #y = dataOut.getHeiRange()
893 893
894 894 z = dataOut.data_pre[:,:,heightindex]/factor
895 895 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
896 896 avg = numpy.average(z, axis=1)
897 897 listChannels = z.shape[0]
898 898
899 899 #Reconstruct Function
900 900 if fit==True:
901 901 groupArray = dataOut.groupList
902 902 listChannels = groupArray.reshape((groupArray.size))
903 903 listChannels.sort()
904 904 spcFitLine = numpy.zeros(z.shape)
905 905 constants = dataOut.constants
906 906
907 907 nGroups = groupArray.shape[0]
908 908 nChannels = groupArray.shape[1]
909 909 nProfiles = z.shape[1]
910 910
911 911 for f in range(nGroups):
912 912 groupChann = groupArray[f,:]
913 913 p = dataOut.data_param[f,:,heightindex]
914 914 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
915 915 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
916 916 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
917 917 spcFitLine[groupChann,:] = fitLineAux
918 918 # spcFitLine = spcFitLine/factor
919 919
920 920 z = z[listChannels,:]
921 921 spcFitLine = spcFitLine[listChannels,:]
922 922 spcFitLinedB = 10*numpy.log10(spcFitLine)
923 923
924 924 zdB = 10*numpy.log10(z)
925 925 #thisDatetime = dataOut.datatime
926 926 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
927 927 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
928 928 xlabel = "Velocity (m/s)"
929 929 ylabel = "Spectrum"
930 930
931 931 if not self.__isConfig:
932 932
933 933 nplots = listChannels.size
934 934
935 935 self.setup(id=id,
936 936 nplots=nplots,
937 937 wintitle=wintitle,
938 938 showprofile=showprofile,
939 939 show=show)
940 940
941 941 if xmin == None: xmin = numpy.nanmin(x)
942 942 if xmax == None: xmax = numpy.nanmax(x)
943 943 if ymin == None: ymin = numpy.nanmin(zdB)
944 944 if ymax == None: ymax = numpy.nanmax(zdB)+2
945 945
946 946 self.__isConfig = True
947 947
948 948 self.setWinTitle(title)
949 949 for i in range(self.nplots):
950 950 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
951 951 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]+1)
952 952 axes = self.axesList[i*self.__nsubplots]
953 953 if fit == False:
954 954 axes.pline(x, zdB[i,:],
955 955 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
956 956 xlabel=xlabel, ylabel=ylabel, title=title
957 957 )
958 958 if fit == True:
959 959 fitline=spcFitLinedB[i,:]
960 960 y=numpy.vstack([zdB[i,:],fitline] )
961 961 legendlabels=['Data','Fitting']
962 962 axes.pmultilineyaxis(x, y,
963 963 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
964 964 xlabel=xlabel, ylabel=ylabel, title=title,
965 965 legendlabels=legendlabels, marker=None,
966 966 linestyle='solid', grid='both')
967 967
968 968 self.draw()
969 969
970 970 if save:
971 971 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
972 972 if figfile == None:
973 973 figfile = self.getFilename(name = date)
974 974
975 975 self.saveFigure(figpath, figfile)
976 976
977 977
978 978 class EWDriftsPlot(Figure):
979 979
980 980 __isConfig = None
981 981 __nsubplots = None
982 982
983 983 WIDTHPROF = None
984 984 HEIGHTPROF = None
985 985 PREFIX = 'drift'
986 986
987 987 def __init__(self):
988 988
989 989 self.timerange = 2*60*60
990 990 self.isConfig = False
991 991 self.__nsubplots = 1
992 992
993 993 self.WIDTH = 800
994 994 self.HEIGHT = 150
995 995 self.WIDTHPROF = 120
996 996 self.HEIGHTPROF = 0
997 997 self.counter_imagwr = 0
998 998
999 999 self.PLOT_CODE = 0
1000 1000 self.FTP_WEI = None
1001 1001 self.EXP_CODE = None
1002 1002 self.SUB_EXP_CODE = None
1003 1003 self.PLOT_POS = None
1004 1004 self.tmin = None
1005 1005 self.tmax = None
1006 1006
1007 1007 self.xmin = None
1008 1008 self.xmax = None
1009 1009
1010 1010 self.figfile = None
1011 1011
1012 1012 def getSubplots(self):
1013 1013
1014 1014 ncol = 1
1015 1015 nrow = self.nplots
1016 1016
1017 1017 return nrow, ncol
1018 1018
1019 1019 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1020 1020
1021 1021 self.__showprofile = showprofile
1022 1022 self.nplots = nplots
1023 1023
1024 1024 ncolspan = 1
1025 1025 colspan = 1
1026 1026
1027 1027 self.createFigure(id = id,
1028 1028 wintitle = wintitle,
1029 1029 widthplot = self.WIDTH + self.WIDTHPROF,
1030 1030 heightplot = self.HEIGHT + self.HEIGHTPROF,
1031 1031 show=show)
1032 1032
1033 1033 nrow, ncol = self.getSubplots()
1034 1034
1035 1035 counter = 0
1036 1036 for y in range(nrow):
1037 1037 if counter >= self.nplots:
1038 1038 break
1039 1039
1040 1040 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1041 1041 counter += 1
1042 1042
1043 1043 def run(self, dataOut, id, wintitle="", channelList=None,
1044 1044 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1045 1045 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1046 1046 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1047 1047 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1048 1048 server=None, folder=None, username=None, password=None,
1049 1049 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1050 1050 """
1051 1051
1052 1052 Input:
1053 1053 dataOut :
1054 1054 id :
1055 1055 wintitle :
1056 1056 channelList :
1057 1057 showProfile :
1058 1058 xmin : None,
1059 1059 xmax : None,
1060 1060 ymin : None,
1061 1061 ymax : None,
1062 1062 zmin : None,
1063 1063 zmax : None
1064 1064 """
1065 1065
1066 1066 if timerange != None:
1067 1067 self.timerange = timerange
1068 1068
1069 1069 tmin = None
1070 1070 tmax = None
1071 1071
1072 1072 x = dataOut.getTimeRange1()
1073 1073 # y = dataOut.heightList
1074 1074 y = dataOut.heightList
1075 1075
1076 1076 z = dataOut.data_output
1077 1077 nplots = z.shape[0] #Number of wind dimensions estimated
1078 1078 nplotsw = nplots
1079 1079
1080 1080 #If there is a SNR function defined
1081 1081 if dataOut.data_SNR != None:
1082 1082 nplots += 1
1083 1083 SNR = dataOut.data_SNR
1084 1084
1085 1085 if SNR_1:
1086 1086 SNR += 1
1087 1087
1088 1088 SNRavg = numpy.average(SNR, axis=0)
1089 1089
1090 1090 SNRdB = 10*numpy.log10(SNR)
1091 1091 SNRavgdB = 10*numpy.log10(SNRavg)
1092 1092
1093 1093 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1094 1094
1095 1095 for i in range(nplotsw):
1096 1096 z[i,ind] = numpy.nan
1097 1097
1098 1098
1099 1099 showprofile = False
1100 1100 # thisDatetime = dataOut.datatime
1101 1101 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1102 1102 title = wintitle + " EW Drifts"
1103 1103 xlabel = ""
1104 1104 ylabel = "Height (Km)"
1105 1105
1106 1106 if not self.__isConfig:
1107 1107
1108 1108 self.setup(id=id,
1109 1109 nplots=nplots,
1110 1110 wintitle=wintitle,
1111 1111 showprofile=showprofile,
1112 1112 show=show)
1113 1113
1114 1114 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1115 1115
1116 1116 if ymin == None: ymin = numpy.nanmin(y)
1117 1117 if ymax == None: ymax = numpy.nanmax(y)
1118 1118
1119 1119 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1120 1120 if zminZonal == None: zminZonal = -zmaxZonal
1121 1121 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1122 1122 if zminVertical == None: zminVertical = -zmaxVertical
1123 1123
1124 1124 if dataOut.data_SNR != None:
1125 1125 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1126 1126 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1127 1127
1128 1128 self.FTP_WEI = ftp_wei
1129 1129 self.EXP_CODE = exp_code
1130 1130 self.SUB_EXP_CODE = sub_exp_code
1131 1131 self.PLOT_POS = plot_pos
1132 1132
1133 1133 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1134 1134 self.__isConfig = True
1135 1135
1136 1136
1137 1137 self.setWinTitle(title)
1138 1138
1139 1139 if ((self.xmax - x[1]) < (x[1]-x[0])):
1140 1140 x[1] = self.xmax
1141 1141
1142 1142 strWind = ['Zonal','Vertical']
1143 1143 strCb = 'Velocity (m/s)'
1144 1144 zmaxVector = [zmaxZonal, zmaxVertical]
1145 1145 zminVector = [zminZonal, zminVertical]
1146 1146
1147 1147 for i in range(nplotsw):
1148 1148
1149 1149 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1150 1150 axes = self.axesList[i*self.__nsubplots]
1151 1151
1152 1152 z1 = z[i,:].reshape((1,-1))
1153 1153
1154 1154 axes.pcolorbuffer(x, y, z1,
1155 1155 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1156 1156 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1157 1157 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1158 1158
1159 1159 if dataOut.data_SNR != None:
1160 1160 i += 1
1161 1161 if SNR_1:
1162 1162 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1163 1163 else:
1164 1164 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1165 1165 axes = self.axesList[i*self.__nsubplots]
1166 1166 SNRavgdB = SNRavgdB.reshape((1,-1))
1167 1167
1168 1168 axes.pcolorbuffer(x, y, SNRavgdB,
1169 1169 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1170 1170 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1171 1171 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1172 1172
1173 1173 self.draw()
1174 1174
1175 1175 if self.figfile == None:
1176 1176 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1177 1177 self.figfile = self.getFilename(name = str_datetime)
1178 1178
1179 1179 if figpath != '':
1180 1180
1181 1181 self.counter_imagwr += 1
1182 1182 if (self.counter_imagwr>=wr_period):
1183 1183 # store png plot to local folder
1184 1184 self.saveFigure(figpath, self.figfile)
1185 1185 # store png plot to FTP server according to RT-Web format
1186 1186 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1187 1187 ftp_filename = os.path.join(figpath, name)
1188 1188 self.saveFigure(figpath, ftp_filename)
1189 1189
1190 1190 self.counter_imagwr = 0
1191 1191
1192 1192 if x[1] >= self.axesList[0].xmax:
1193 1193 self.counter_imagwr = wr_period
1194 1194 self.__isConfig = False
1195 1195 self.figfile = None No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now