##// END OF EJS Templates
The Spectra-1d Plot shows the normalized power.
Daniel Valdez -
r496:c1e2ee842644
parent child
Show More
@@ -1,725 +1,736
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 GenericData(object):
93 93
94 94 flagNoData = True
95 95
96 96 def __init__(self):
97 97
98 98 raise ValueError, "This class has not been implemented"
99 99
100 100 def copy(self, inputObj=None):
101 101
102 102 if inputObj == None:
103 103 return copy.deepcopy(self)
104 104
105 105 for key in inputObj.__dict__.keys():
106 106 self.__dict__[key] = inputObj.__dict__[key]
107 107
108 108 def deepcopy(self):
109 109
110 110 return copy.deepcopy(self)
111 111
112 112 def isEmpty(self):
113 113
114 114 return self.flagNoData
115 115
116 116 class JROData(GenericData):
117 117
118 118 # m_BasicHeader = BasicHeader()
119 119 # m_ProcessingHeader = ProcessingHeader()
120 120
121 121 systemHeaderObj = SystemHeader()
122 122
123 123 radarControllerHeaderObj = RadarControllerHeader()
124 124
125 125 # data = None
126 126
127 127 type = None
128 128
129 129 datatype = None #dtype but in string
130 130
131 131 # dtype = None
132 132
133 133 # nChannels = None
134 134
135 135 # nHeights = None
136 136
137 137 nProfiles = None
138 138
139 139 heightList = None
140 140
141 141 channelList = None
142 142
143 143 flagTimeBlock = False
144 144
145 145 useLocalTime = False
146 146
147 147 utctime = None
148 148
149 149 timeZone = None
150 150
151 151 dstFlag = None
152 152
153 153 errorCount = None
154 154
155 155 blocksize = None
156 156
157 157 nCode = None
158 158
159 159 nBaud = None
160 160
161 161 code = None
162 162
163 163 flagDecodeData = False #asumo q la data no esta decodificada
164 164
165 165 flagDeflipData = False #asumo q la data no esta sin flip
166 166
167 167 flagShiftFFT = False
168 168
169 169 # ippSeconds = None
170 170
171 171 timeInterval = None
172 172
173 173 nCohInt = None
174 174
175 175 noise = None
176 176
177 177 windowOfFilter = 1
178 178
179 179 #Speed of ligth
180 180 C = 3e8
181 181
182 182 frequency = 49.92e6
183 183
184 184 realtime = False
185 185
186 186 beacon_heiIndexList = None
187 187
188 188 last_block = None
189 189
190 190 blocknow = None
191 191
192 192 def __init__(self):
193 193
194 194 raise ValueError, "This class has not been implemented"
195 195
196 196 def getNoise(self):
197 197
198 198 raise ValueError, "Not implemented"
199 199
200 200 def getNChannels(self):
201 201
202 202 return len(self.channelList)
203 203
204 204 def getChannelIndexList(self):
205 205
206 206 return range(self.nChannels)
207 207
208 208 def getNHeights(self):
209 209
210 210 return len(self.heightList)
211 211
212 212 def getHeiRange(self, extrapoints=0):
213 213
214 214 heis = self.heightList
215 215 # deltah = self.heightList[1] - self.heightList[0]
216 216 #
217 217 # heis.append(self.heightList[-1])
218 218
219 219 return heis
220 220
221 221 def getltctime(self):
222 222
223 223 if self.useLocalTime:
224 224 return self.utctime - self.timeZone*60
225 225
226 226 return self.utctime
227 227
228 228 def getDatatime(self):
229 229
230 230 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
231 231 return datatimeValue
232 232
233 233 def getTimeRange(self):
234 234
235 235 datatime = []
236 236
237 237 datatime.append(self.ltctime)
238 238 datatime.append(self.ltctime + self.timeInterval)
239 239
240 240 datatime = numpy.array(datatime)
241 241
242 242 return datatime
243 243
244 244 def getFmax(self):
245 245
246 246 PRF = 1./(self.ippSeconds * self.nCohInt)
247 247
248 248 fmax = PRF/2.
249 249
250 250 return fmax
251 251
252 252 def getVmax(self):
253 253
254 254 _lambda = self.C/self.frequency
255 255
256 256 vmax = self.getFmax() * _lambda
257 257
258 258 return vmax
259 259
260 260 def get_ippSeconds(self):
261 261 '''
262 262 '''
263 263 return self.radarControllerHeaderObj.ippSeconds
264 264
265 265 def set_ippSeconds(self, ippSeconds):
266 266 '''
267 267 '''
268 268
269 269 self.radarControllerHeaderObj.ippSeconds = ippSeconds
270 270
271 271 return
272 272
273 273 def get_dtype(self):
274 274 '''
275 275 '''
276 276 return getNumpyDtype(self.datatype)
277 277
278 278 def set_dtype(self, numpyDtype):
279 279 '''
280 280 '''
281 281
282 282 self.datatype = getDataTypeCode(numpyDtype)
283 283
284 284 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
285 285 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
286 286 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
287 287 #noise = property(getNoise, "I'm the 'nHeights' property.")
288 288 datatime = property(getDatatime, "I'm the 'datatime' property")
289 289 ltctime = property(getltctime, "I'm the 'ltctime' property")
290 290 ippSeconds = property(get_ippSeconds, set_ippSeconds)
291 291 dtype = property(get_dtype, set_dtype)
292 292
293 293 class Voltage(JROData):
294 294
295 295 #data es un numpy array de 2 dmensiones (canales, alturas)
296 296 data = None
297 297
298 298 def __init__(self):
299 299 '''
300 300 Constructor
301 301 '''
302 302
303 303 self.radarControllerHeaderObj = RadarControllerHeader()
304 304
305 305 self.systemHeaderObj = SystemHeader()
306 306
307 307 self.type = "Voltage"
308 308
309 309 self.data = None
310 310
311 311 # self.dtype = None
312 312
313 313 # self.nChannels = 0
314 314
315 315 # self.nHeights = 0
316 316
317 317 self.nProfiles = None
318 318
319 319 self.heightList = None
320 320
321 321 self.channelList = None
322 322
323 323 # self.channelIndexList = None
324 324
325 325 self.flagNoData = True
326 326
327 327 self.flagTimeBlock = False
328 328
329 329 self.utctime = None
330 330
331 331 self.timeZone = None
332 332
333 333 self.dstFlag = None
334 334
335 335 self.errorCount = None
336 336
337 337 self.nCohInt = None
338 338
339 339 self.blocksize = None
340 340
341 341 self.flagDecodeData = False #asumo q la data no esta decodificada
342 342
343 343 self.flagDeflipData = False #asumo q la data no esta sin flip
344 344
345 345 self.flagShiftFFT = False
346 346
347 347
348 348 def getNoisebyHildebrand(self):
349 349 """
350 350 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
351 351
352 352 Return:
353 353 noiselevel
354 354 """
355 355
356 356 for channel in range(self.nChannels):
357 357 daux = self.data_spc[channel,:,:]
358 358 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
359 359
360 360 return self.noise
361 361
362 362 def getNoise(self, type = 1):
363 363
364 364 self.noise = numpy.zeros(self.nChannels)
365 365
366 366 if type == 1:
367 367 noise = self.getNoisebyHildebrand()
368 368
369 369 return 10*numpy.log10(noise)
370 370
371 371 noise = property(getNoise, "I'm the 'nHeights' property.")
372 372
373 373 class Spectra(JROData):
374 374
375 375 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
376 376 data_spc = None
377 377
378 378 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
379 379 data_cspc = None
380 380
381 381 #data es un numpy array de 2 dmensiones (canales, alturas)
382 382 data_dc = None
383 383
384 384 nFFTPoints = None
385 385
386 386 # nPairs = None
387 387
388 388 pairsList = None
389 389
390 390 nIncohInt = None
391 391
392 392 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
393 393
394 394 nCohInt = None #se requiere para determinar el valor de timeInterval
395 395
396 396 ippFactor = None
397 397
398 398 def __init__(self):
399 399 '''
400 400 Constructor
401 401 '''
402 402
403 403 self.radarControllerHeaderObj = RadarControllerHeader()
404 404
405 405 self.systemHeaderObj = SystemHeader()
406 406
407 407 self.type = "Spectra"
408 408
409 409 # self.data = None
410 410
411 411 # self.dtype = None
412 412
413 413 # self.nChannels = 0
414 414
415 415 # self.nHeights = 0
416 416
417 417 self.nProfiles = None
418 418
419 419 self.heightList = None
420 420
421 421 self.channelList = None
422 422
423 423 # self.channelIndexList = None
424 424
425 425 self.pairsList = None
426 426
427 427 self.flagNoData = True
428 428
429 429 self.flagTimeBlock = False
430 430
431 431 self.utctime = None
432 432
433 433 self.nCohInt = None
434 434
435 435 self.nIncohInt = None
436 436
437 437 self.blocksize = None
438 438
439 439 self.nFFTPoints = None
440 440
441 441 self.wavelength = None
442 442
443 443 self.flagDecodeData = False #asumo q la data no esta decodificada
444 444
445 445 self.flagDeflipData = False #asumo q la data no esta sin flip
446 446
447 447 self.flagShiftFFT = False
448 448
449 449 self.ippFactor = 1
450 450
451 451 #self.noise = None
452 452
453 453 self.beacon_heiIndexList = []
454 454
455 455 self.noise_estimation = None
456 456
457 457
458 458 def getNoisebyHildebrand(self):
459 459 """
460 460 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
461 461
462 462 Return:
463 463 noiselevel
464 464 """
465 465
466 466 noise = numpy.zeros(self.nChannels)
467 467 for channel in range(self.nChannels):
468 468 daux = self.data_spc[channel,:,:]
469 469 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
470 470
471 471 return noise
472 472
473 473 def getNoise(self):
474 474 if self.noise_estimation != None:
475 475 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
476 476 else:
477 477 noise = self.getNoisebyHildebrand()
478 478 return noise
479 479
480 480
481 481 def getFreqRange(self, extrapoints=0):
482 482
483 483 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
484 484 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
485 485
486 486 return freqrange
487 487
488 488 def getVelRange(self, extrapoints=0):
489 489
490 490 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
491 491 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
492 492
493 493 return velrange
494 494
495 495 def getNPairs(self):
496 496
497 497 return len(self.pairsList)
498 498
499 499 def getPairsIndexList(self):
500 500
501 501 return range(self.nPairs)
502 502
503 503 def getNormFactor(self):
504 504 pwcode = 1
505 505 if self.flagDecodeData:
506 506 pwcode = numpy.sum(self.code[0]**2)
507 507 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
508 508 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
509 509
510 510 return normFactor
511 511
512 512 def getFlagCspc(self):
513 513
514 514 if self.data_cspc == None:
515 515 return True
516 516
517 517 return False
518 518
519 519 def getFlagDc(self):
520 520
521 521 if self.data_dc == None:
522 522 return True
523 523
524 524 return False
525 525
526 526 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
527 527 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
528 528 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
529 529 flag_cspc = property(getFlagCspc)
530 530 flag_dc = property(getFlagDc)
531 531 noise = property(getNoise, "I'm the 'nHeights' property.")
532 532
533 533 class SpectraHeis(Spectra):
534 534
535 535 data_spc = None
536 536
537 537 data_cspc = None
538 538
539 539 data_dc = None
540 540
541 541 nFFTPoints = None
542 542
543 543 # nPairs = None
544 544
545 545 pairsList = None
546 546
547 547 nIncohInt = None
548 548
549 549 def __init__(self):
550 550
551 551 self.radarControllerHeaderObj = RadarControllerHeader()
552 552
553 553 self.systemHeaderObj = SystemHeader()
554 554
555 555 self.type = "SpectraHeis"
556 556
557 557 # self.dtype = None
558 558
559 559 # self.nChannels = 0
560 560
561 561 # self.nHeights = 0
562 562
563 563 self.nProfiles = None
564 564
565 565 self.heightList = None
566 566
567 567 self.channelList = None
568 568
569 569 # self.channelIndexList = None
570 570
571 571 self.flagNoData = True
572 572
573 573 self.flagTimeBlock = False
574 574
575 575 # self.nPairs = 0
576 576
577 577 self.utctime = None
578 578
579 579 self.blocksize = None
580
581 def getNormFactor(self):
582 pwcode = 1
583 if self.flagDecodeData:
584 pwcode = numpy.sum(self.code[0]**2)
585
586 normFactor = self.nIncohInt*self.nCohInt*pwcode
587
588 return normFactor
589
590 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
580 591
581 592 class Fits:
582 593
583 594 heightList = None
584 595
585 596 channelList = None
586 597
587 598 flagNoData = True
588 599
589 600 flagTimeBlock = False
590 601
591 602 useLocalTime = False
592 603
593 604 utctime = None
594 605
595 606 timeZone = None
596 607
597 608 # ippSeconds = None
598 609
599 610 timeInterval = None
600 611
601 612 nCohInt = None
602 613
603 614 nIncohInt = None
604 615
605 616 noise = None
606 617
607 618 windowOfFilter = 1
608 619
609 620 #Speed of ligth
610 621 C = 3e8
611 622
612 623 frequency = 49.92e6
613 624
614 625 realtime = False
615 626
616 627
617 628 def __init__(self):
618 629
619 630 self.type = "Fits"
620 631
621 632 self.nProfiles = None
622 633
623 634 self.heightList = None
624 635
625 636 self.channelList = None
626 637
627 638 # self.channelIndexList = None
628 639
629 640 self.flagNoData = True
630 641
631 642 self.utctime = None
632 643
633 644 self.nCohInt = None
634 645
635 646 self.nIncohInt = None
636 647
637 648 self.useLocalTime = True
638 649
639 650 # self.utctime = None
640 651 # self.timeZone = None
641 652 # self.ltctime = None
642 653 # self.timeInterval = None
643 654 # self.header = None
644 655 # self.data_header = None
645 656 # self.data = None
646 657 # self.datatime = None
647 658 # self.flagNoData = False
648 659 # self.expName = ''
649 660 # self.nChannels = None
650 661 # self.nSamples = None
651 662 # self.dataBlocksPerFile = None
652 663 # self.comments = ''
653 664 #
654 665
655 666
656 667 def getltctime(self):
657 668
658 669 if self.useLocalTime:
659 670 return self.utctime - self.timeZone*60
660 671
661 672 return self.utctime
662 673
663 674 def getDatatime(self):
664 675
665 676 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
666 677 return datatime
667 678
668 679 def getTimeRange(self):
669 680
670 681 datatime = []
671 682
672 683 datatime.append(self.ltctime)
673 684 datatime.append(self.ltctime + self.timeInterval)
674 685
675 686 datatime = numpy.array(datatime)
676 687
677 688 return datatime
678 689
679 690 def getHeiRange(self):
680 691
681 692 heis = self.heightList
682 693
683 694 return heis
684 695
685 696 def isEmpty(self):
686 697
687 698 return self.flagNoData
688 699
689 700 def getNHeights(self):
690 701
691 702 return len(self.heightList)
692 703
693 704 def getNChannels(self):
694 705
695 706 return len(self.channelList)
696 707
697 708 def getChannelIndexList(self):
698 709
699 710 return range(self.nChannels)
700 711
701 712 def getNoise(self, type = 1):
702 713
703 714 self.noise = numpy.zeros(self.nChannels)
704 715
705 716 if type == 1:
706 717 noise = self.getNoisebyHildebrand()
707 718
708 719 if type == 2:
709 720 noise = self.getNoisebySort()
710 721
711 722 if type == 3:
712 723 noise = self.getNoisebyWindow()
713 724
714 725 return noise
715 726
716 727 datatime = property(getDatatime, "I'm the 'datatime' property")
717 728 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
718 729 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
719 730 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
720 731 noise = property(getNoise, "I'm the 'nHeights' property.")
721 732 datatime = property(getDatatime, "I'm the 'datatime' property")
722 733 ltctime = property(getltctime, "I'm the 'ltctime' property")
723 734
724 735 ltctime = property(getltctime, "I'm the 'ltctime' property")
725 736
@@ -1,324 +1,326
1 1 '''
2 2
3 3 @author: Daniel Suarez
4 4 '''
5 5
6 6 import os
7 7 import datetime
8 8 import numpy
9 9
10 10 from figure import Figure, isRealtime
11 11
12 12 class SpectraHeisScope(Figure):
13 13
14 14
15 15 isConfig = None
16 16 __nsubplots = None
17 17
18 18 WIDTHPROF = None
19 19 HEIGHTPROF = None
20 20 PREFIX = 'spc'
21 21
22 22 def __init__(self):
23 23
24 24 self.isConfig = False
25 25 self.__nsubplots = 1
26 26
27 27 self.WIDTH = 230
28 28 self.HEIGHT = 250
29 29 self.WIDTHPROF = 120
30 30 self.HEIGHTPROF = 0
31 31 self.counter_imagwr = 0
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, show):
41 41
42 42 showprofile = False
43 43 self.__showprofile = showprofile
44 44 self.nplots = nplots
45 45
46 46 ncolspan = 1
47 47 colspan = 1
48 48 if showprofile:
49 49 ncolspan = 3
50 50 colspan = 2
51 51 self.__nsubplots = 2
52 52
53 53 self.createFigure(id = id,
54 54 wintitle = wintitle,
55 55 widthplot = self.WIDTH + self.WIDTHPROF,
56 56 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 57 show = show)
58 58
59 59 nrow, ncol = self.getSubplots()
60 60
61 61 counter = 0
62 62 for y in range(nrow):
63 63 for x in range(ncol):
64 64
65 65 if counter >= self.nplots:
66 66 break
67 67
68 68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
69 69
70 70 if showprofile:
71 71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
72 72
73 73 counter += 1
74 74
75 75
76 76 def run(self, dataOut, id, wintitle="", channelList=None,
77 77 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
78 78 figpath='', figfile=None, ftp=False, wr_period=1, show=True,
79 79 server=None, folder=None, username=None, password=None):
80 80
81 81 """
82 82
83 83 Input:
84 84 dataOut :
85 85 id :
86 86 wintitle :
87 87 channelList :
88 88 xmin : None,
89 89 xmax : None,
90 90 ymin : None,
91 91 ymax : None,
92 92 """
93 93
94 94 if dataOut.realtime:
95 95 if not(isRealtime(utcdatatime = dataOut.utctime)):
96 96 print 'Skipping this plot function'
97 97 return
98 98
99 99 if channelList == None:
100 100 channelIndexList = dataOut.channelIndexList
101 101 else:
102 102 channelIndexList = []
103 103 for channel in channelList:
104 104 if channel not in dataOut.channelList:
105 105 raise ValueError, "Channel %d is not in dataOut.channelList"
106 106 channelIndexList.append(dataOut.channelList.index(channel))
107 107
108 108 # x = dataOut.heightList
109 109 c = 3E8
110 110 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
111 111 #deberia cambiar para el caso de 1Mhz y 100KHz
112 112 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
113 113 #para 1Mhz descomentar la siguiente linea
114 114 #x= x/(10000.0)
115 115 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
116 116 # y = y.real
117 datadB = 10.*numpy.log10(dataOut.data_spc)
117 factor = dataOut.normFactor
118 data = dataOut.data_spc / factor
119 datadB = 10.*numpy.log10(data)
118 120 y = datadB
119 121
120 122 #thisDatetime = dataOut.datatime
121 123 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
122 124 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
123 125 xlabel = ""
124 126 #para 1Mhz descomentar la siguiente linea
125 127 #xlabel = "Frequency x 10000"
126 128 ylabel = "Intensity (dB)"
127 129
128 130 if not self.isConfig:
129 131 nplots = len(channelIndexList)
130 132
131 133 self.setup(id=id,
132 134 nplots=nplots,
133 135 wintitle=wintitle,
134 136 show=show)
135 137
136 138 if xmin == None: xmin = numpy.nanmin(x)
137 139 if xmax == None: xmax = numpy.nanmax(x)
138 140 if ymin == None: ymin = numpy.nanmin(y)
139 141 if ymax == None: ymax = numpy.nanmax(y)
140 142
141 143 self.isConfig = True
142 144
143 145 self.setWinTitle(title)
144 146
145 147 for i in range(len(self.axesList)):
146 148 ychannel = y[i,:]
147 149 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
148 150 title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime)
149 151 axes = self.axesList[i]
150 152 axes.pline(x, ychannel,
151 153 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
152 154 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
153 155
154 156
155 157 self.draw()
156 158
157 159 if figfile == None:
158 160 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
159 161 figfile = self.getFilename(name = str_datetime)
160 162
161 163 if figpath != '':
162 164 self.counter_imagwr += 1
163 165 if (self.counter_imagwr>=wr_period):
164 166 # store png plot to local folder
165 167 self.saveFigure(figpath, figfile)
166 168 # store png plot to FTP server according to RT-Web format
167 169 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
168 170 #ftp_filename = os.path.join(figpath, name)
169 171 #self.saveFigure(figpath, ftp_filename)
170 172 self.counter_imagwr = 0
171 173
172 174 class RTIfromSpectraHeis(Figure):
173 175
174 176 isConfig = None
175 177 __nsubplots = None
176 178
177 179 PREFIX = 'rtinoise'
178 180
179 181 def __init__(self):
180 182
181 183 self.timerange = 24*60*60
182 184 self.isConfig = False
183 185 self.__nsubplots = 1
184 186
185 187 self.WIDTH = 820
186 188 self.HEIGHT = 200
187 189 self.WIDTHPROF = 120
188 190 self.HEIGHTPROF = 0
189 191 self.counter_imagwr = 0
190 192 self.xdata = None
191 193 self.ydata = None
192 194 self.figfile = None
193 195
194 196 def getSubplots(self):
195 197
196 198 ncol = 1
197 199 nrow = 1
198 200
199 201 return nrow, ncol
200 202
201 203 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
202 204
203 205 self.__showprofile = showprofile
204 206 self.nplots = nplots
205 207
206 208 ncolspan = 7
207 209 colspan = 6
208 210 self.__nsubplots = 2
209 211
210 212 self.createFigure(id = id,
211 213 wintitle = wintitle,
212 214 widthplot = self.WIDTH+self.WIDTHPROF,
213 215 heightplot = self.HEIGHT+self.HEIGHTPROF,
214 216 show = show)
215 217
216 218 nrow, ncol = self.getSubplots()
217 219
218 220 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
219 221
220 222
221 223 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
222 224 xmin=None, xmax=None, ymin=None, ymax=None,
223 225 timerange=None,
224 226 save=False, figpath='', figfile=None, ftp=False, wr_period=1, show=True,
225 227 server=None, folder=None, username=None, password=None):
226 228
227 229 if channelList == None:
228 230 channelIndexList = dataOut.channelIndexList
229 231 channelList = dataOut.channelList
230 232 else:
231 233 channelIndexList = []
232 234 for channel in channelList:
233 235 if channel not in dataOut.channelList:
234 236 raise ValueError, "Channel %d is not in dataOut.channelList"
235 237 channelIndexList.append(dataOut.channelList.index(channel))
236 238
237 239 if timerange != None:
238 240 self.timerange = timerange
239 241
240 242 tmin = None
241 243 tmax = None
242 244 x = dataOut.getTimeRange()
243 245 y = dataOut.getHeiRange()
244 246
245 247
246 248 data = dataOut.data_spc
247 249 data = numpy.average(data,axis=1)
248 250 datadB = 10*numpy.log10(data)
249 251
250 252 # factor = dataOut.normFactor
251 253 # noise = dataOut.getNoise()/factor
252 254 # noisedB = 10*numpy.log10(noise)
253 255
254 256 #thisDatetime = dataOut.datatime
255 257 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
256 258 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
257 259 xlabel = "Local Time"
258 260 ylabel = "Intensity (dB)"
259 261
260 262 if not self.isConfig:
261 263
262 264 nplots = 1
263 265
264 266 self.setup(id=id,
265 267 nplots=nplots,
266 268 wintitle=wintitle,
267 269 showprofile=showprofile,
268 270 show=show)
269 271
270 272 tmin, tmax = self.getTimeLim(x, xmin, xmax)
271 273 if ymin == None: ymin = numpy.nanmin(datadB)
272 274 if ymax == None: ymax = numpy.nanmax(datadB)
273 275
274 276 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
275 277 self.isConfig = True
276 278 self.figfile = figfile
277 279 self.xdata = numpy.array([])
278 280 self.ydata = numpy.array([])
279 281
280 282 self.setWinTitle(title)
281 283
282 284
283 285 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
284 286 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
285 287
286 288 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
287 289 axes = self.axesList[0]
288 290
289 291 self.xdata = numpy.hstack((self.xdata, x[0:1]))
290 292
291 293 if len(self.ydata)==0:
292 294 self.ydata = datadB[channelIndexList].reshape(-1,1)
293 295 else:
294 296 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
295 297
296 298
297 299 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
298 300 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
299 301 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
300 302 XAxisAsTime=True
301 303 )
302 304
303 305 self.draw()
304 306
305 307 if x[1] >= self.axesList[0].xmax:
306 308 self.counter_imagwr = wr_period
307 309 del self.xdata
308 310 del self.ydata
309 311 self.__isConfig = False
310 312
311 313 if self.figfile == None:
312 314 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
313 315 self.figfile = self.getFilename(name = str_datetime)
314 316
315 317 if figpath != '':
316 318 self.counter_imagwr += 1
317 319 if (self.counter_imagwr>=wr_period):
318 320 # store png plot to local folder
319 321 self.saveFigure(figpath, self.figfile)
320 322 # store png plot to FTP server according to RT-Web format
321 323 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
322 324 #ftp_filename = os.path.join(figpath, name)
323 325 #self.saveFigure(figpath, ftp_filename)
324 326 self.counter_imagwr = 0
General Comments 0
You need to be logged in to leave comments. Login now