@@ -52,7 +52,8 RADAR_STRUCTURE = numpy.dtype([ | |||||
52 | ('sRangeTxB','<a20'), |
|
52 | ('sRangeTxB', '<a20'), | |
53 | ]) |
|
53 | ]) | |
54 |
|
54 | |||
55 |
SAMPLING_STRUCTURE = numpy.dtype( |
|
55 | SAMPLING_STRUCTURE = numpy.dtype( | |
|
56 | [('h0', '<f4'), ('dh', '<f4'), ('nsa', '<u4')]) | |||
56 |
|
57 | |||
57 |
|
58 | |||
58 | PROCESSING_STRUCTURE = numpy.dtype([ |
|
59 | PROCESSING_STRUCTURE = numpy.dtype([ | |
@@ -68,6 +69,7 PROCESSING_STRUCTURE = numpy.dtype([ | |||||
68 |
|
|
69 | ('nTotalSpectra', '<u4') | |
69 | ]) |
|
70 | ]) | |
70 |
|
71 | |||
|
72 | ||||
71 | class Header(object): |
|
73 | class Header(object): | |
72 |
|
74 | |||
73 | def __init__(self): |
|
75 | def __init__(self): | |
@@ -122,6 +124,7 class Header(object): | |||||
122 |
|
124 | |||
123 | print message |
|
125 | print message | |
124 |
|
126 | |||
|
127 | ||||
125 | class BasicHeader(Header): |
|
128 | class BasicHeader(Header): | |
126 |
|
129 | |||
127 | size = None |
|
130 | size = None | |
@@ -180,7 +183,8 class BasicHeader(Header): | |||||
180 |
|
183 | |||
181 | def write(self, fp): |
|
184 | def write(self, fp): | |
182 |
|
185 | |||
183 |
headerTuple = (self.size,self.version,self.dataBlock,self.utc, |
|
186 | headerTuple = (self.size, self.version, self.dataBlock, self.utc, | |
|
187 | self.miliSecond, self.timeZone, self.dstFlag, self.errorCount) | |||
184 |
header = numpy.array(headerTuple, BASIC_STRUCTURE) |
|
188 | header = numpy.array(headerTuple, BASIC_STRUCTURE) | |
185 | header.tofile(fp) |
|
189 | header.tofile(fp) | |
186 |
|
190 | |||
@@ -201,6 +205,7 class BasicHeader(Header): | |||||
201 | ltc = property(get_ltc, set_ltc) |
|
205 | ltc = property(get_ltc, set_ltc) | |
202 | datatime = property(get_datatime) |
|
206 | datatime = property(get_datatime) | |
203 |
|
207 | |||
|
208 | ||||
204 | class SystemHeader(Header): |
|
209 | class SystemHeader(Header): | |
205 |
|
210 | |||
206 | size = None |
|
211 | size = None | |
@@ -244,16 +249,17 class SystemHeader(Header): | |||||
244 | self.adcResolution = header['nADCResolution'][0] |
|
249 | self.adcResolution = header['nADCResolution'][0] | |
245 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
250 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] | |
246 |
|
251 | |||
247 |
|
||||
248 | if startFp is not None: |
|
252 | if startFp is not None: | |
249 | endFp = self.size + startFp |
|
253 | endFp = self.size + startFp | |
250 |
|
254 | |||
251 | if fp.tell() > endFp: |
|
255 | if fp.tell() > endFp: | |
252 | sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name) |
|
256 | sys.stderr.write( | |
|
257 | "Warning %s: Size value read from System Header is lower than it has to be\n" % fp.name) | |||
253 | return 0 |
|
258 | return 0 | |
254 |
|
259 | |||
255 | if fp.tell() < endFp: |
|
260 | if fp.tell() < endFp: | |
256 | sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name) |
|
261 | sys.stderr.write( | |
|
262 | "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp.name) | |||
257 | return 0 |
|
263 | return 0 | |
258 |
|
264 | |||
259 | self.length = header.nbytes |
|
265 | self.length = header.nbytes | |
@@ -261,12 +267,14 class SystemHeader(Header): | |||||
261 |
|
267 | |||
262 | def write(self, fp): |
|
268 | def write(self, fp): | |
263 |
|
269 | |||
264 |
headerTuple = (self.size,self.nSamples,self.nProfiles, |
|
270 | headerTuple = (self.size, self.nSamples, self.nProfiles, | |
|
271 | self.nChannels, self.adcResolution, self.pciDioBusWidth) | |||
265 | header = numpy.array(headerTuple,SYSTEM_STRUCTURE) |
|
272 | header = numpy.array(headerTuple, SYSTEM_STRUCTURE) | |
266 | header.tofile(fp) |
|
273 | header.tofile(fp) | |
267 |
|
274 | |||
268 | return 1 |
|
275 | return 1 | |
269 |
|
276 | |||
|
277 | ||||
270 | class RadarControllerHeader(Header): |
|
278 | class RadarControllerHeader(Header): | |
271 |
|
279 | |||
272 | expType = None |
|
280 | expType = None | |
@@ -370,9 +378,11 class RadarControllerHeader(Header): | |||||
370 |
|
378 | |||
371 | try: |
|
379 | try: | |
372 | if hasattr(fp, 'read'): |
|
380 | if hasattr(fp, 'read'): | |
373 |
samplingWindow = numpy.fromfile( |
|
381 | samplingWindow = numpy.fromfile( | |
|
382 | fp, SAMPLING_STRUCTURE, self.nWindows) | |||
374 | else: |
|
383 | else: | |
375 |
samplingWindow = numpy.fromstring( |
|
384 | samplingWindow = numpy.fromstring( | |
|
385 | fp[self.length:], SAMPLING_STRUCTURE, self.nWindows) | |||
376 | self.length += samplingWindow.nbytes |
|
386 | self.length += samplingWindow.nbytes | |
377 | except Exception, e: |
|
387 | except Exception, e: | |
378 | print "RadarControllerHeader: " + str(e) |
|
388 | print "RadarControllerHeader: " + str(e) | |
@@ -382,20 +392,17 class RadarControllerHeader(Header): | |||||
382 | self.deltaHeight = samplingWindow['dh'] |
|
392 | self.deltaHeight = samplingWindow['dh'] | |
383 | self.samplesWin = samplingWindow['nsa'] |
|
393 | self.samplesWin = samplingWindow['nsa'] | |
384 |
|
394 | |||
385 |
|
||||
386 |
|
||||
387 | try: |
|
395 | try: | |
388 | if hasattr(fp, 'read'): |
|
396 | if hasattr(fp, 'read'): | |
389 | self.Taus = numpy.fromfile(fp, '<f4', self.numTaus) |
|
397 | self.Taus = numpy.fromfile(fp, '<f4', self.numTaus) | |
390 | else: |
|
398 | else: | |
391 |
self.Taus = numpy.fromstring( |
|
399 | self.Taus = numpy.fromstring( | |
|
400 | fp[self.length:], '<f4', self.numTaus) | |||
392 | self.length += self.Taus.nbytes |
|
401 | self.length += self.Taus.nbytes | |
393 | except Exception, e: |
|
402 | except Exception, e: | |
394 | print "RadarControllerHeader: " + str(e) |
|
403 | print "RadarControllerHeader: " + str(e) | |
395 | return 0 |
|
404 | return 0 | |
396 |
|
405 | |||
397 |
|
||||
398 |
|
||||
399 | self.code_size = 0 |
|
406 | self.code_size = 0 | |
400 | if self.codeType != 0: |
|
407 | if self.codeType != 0: | |
401 |
|
408 | |||
@@ -406,9 +413,11 class RadarControllerHeader(Header): | |||||
406 | self.nBaud = numpy.fromfile(fp, '<u4', 1)[0] |
|
413 | self.nBaud = numpy.fromfile(fp, '<u4', 1)[0] | |
407 | self.length += self.nBaud.nbytes |
|
414 | self.length += self.nBaud.nbytes | |
408 | else: |
|
415 | else: | |
409 |
self.nCode = numpy.fromstring( |
|
416 | self.nCode = numpy.fromstring( | |
|
417 | fp[self.length:], '<u4', 1)[0] | |||
410 | self.length += self.nCode.nbytes |
|
418 | self.length += self.nCode.nbytes | |
411 |
self.nBaud = numpy.fromstring( |
|
419 | self.nBaud = numpy.fromstring( | |
|
420 | fp[self.length:], '<u4', 1)[0] | |||
412 | self.length += self.nBaud.nbytes |
|
421 | self.length += self.nBaud.nbytes | |
413 | except Exception, e: |
|
422 | except Exception, e: | |
414 | print "RadarControllerHeader: " + str(e) |
|
423 | print "RadarControllerHeader: " + str(e) | |
@@ -418,9 +427,11 class RadarControllerHeader(Header): | |||||
418 | for ic in range(self.nCode): |
|
427 | for ic in range(self.nCode): | |
419 | try: |
|
428 | try: | |
420 | if hasattr(fp, 'read'): |
|
429 | if hasattr(fp, 'read'): | |
421 |
temp = numpy.fromfile(fp,'u4', int( |
|
430 | temp = numpy.fromfile(fp, 'u4', int( | |
|
431 | numpy.ceil(self.nBaud / 32.))) | |||
422 | else: |
|
432 | else: | |
423 |
temp = numpy.fromstring( |
|
433 | temp = numpy.fromstring( | |
|
434 | fp, 'u4', int(numpy.ceil(self.nBaud / 32.))) | |||
424 | self.length += temp.nbytes |
|
435 | self.length += temp.nbytes | |
425 | except Exception, e: |
|
436 | except Exception, e: | |
426 | print "RadarControllerHeader: " + str(e) |
|
437 | print "RadarControllerHeader: " + str(e) | |
@@ -447,12 +458,13 class RadarControllerHeader(Header): | |||||
447 | # return 0 |
|
458 | # return 0 | |
448 |
|
459 | |||
449 | if fp.tell() > endFp: |
|
460 | if fp.tell() > endFp: | |
450 | sys.stderr.write("Warning %s: Size value read from Radar Controller header is lower than it has to be\n" %fp.name) |
|
461 | sys.stderr.write( | |
|
462 | "Warning %s: Size value read from Radar Controller header is lower than it has to be\n" % fp.name) | |||
451 | # return 0 |
|
463 | # return 0 | |
452 |
|
464 | |||
453 | if fp.tell() < endFp: |
|
465 | if fp.tell() < endFp: | |
454 | sys.stderr.write("Warning %s: Size value read from Radar Controller header is greater than it has to be\n" %fp.name) |
|
466 | sys.stderr.write( | |
455 |
|
467 | "Warning %s: Size value read from Radar Controller header is greater than it has to be\n" % fp.name) | ||
456 |
|
468 | |||
457 | return 1 |
|
469 | return 1 | |
458 |
|
470 | |||
@@ -479,7 +491,8 class RadarControllerHeader(Header): | |||||
479 | header = numpy.array(headerTuple,RADAR_STRUCTURE) |
|
491 | header = numpy.array(headerTuple, RADAR_STRUCTURE) | |
480 | header.tofile(fp) |
|
492 | header.tofile(fp) | |
481 |
|
493 | |||
482 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
494 | sampleWindowTuple = ( | |
|
495 | self.firstHeight, self.deltaHeight, self.samplesWin) | |||
483 | samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) |
|
496 | samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE) | |
484 | samplingWindow.tofile(fp) |
|
497 | samplingWindow.tofile(fp) | |
485 |
|
498 | |||
@@ -501,7 +514,8 class RadarControllerHeader(Header): | |||||
501 | code_selected = code1[ic,start:end] |
|
514 | code_selected = code1[ic, start:end] | |
502 |
for j in range(len(code_selected)-1, |
|
515 | for j in range(len(code_selected) - 1, -1, -1): | |
503 | if code_selected[j] == 1: |
|
516 | if code_selected[j] == 1: | |
504 |
tempx[i] = tempx[i] + |
|
517 | tempx[i] = tempx[i] + \ | |
|
518 | 2**(len(code_selected) - 1 - j) | |||
505 | start = start + 32 |
|
519 | start = start + 32 | |
506 | end = end + 32 |
|
520 | end = end + 32 | |
507 |
|
521 | |||
@@ -536,7 +550,8 class RadarControllerHeader(Header): | |||||
536 | self.__size = 116 + 12*self.nWindows + 4*self.numTaus |
|
550 | self.__size = 116 + 12 * self.nWindows + 4 * self.numTaus | |
537 |
|
551 | |||
538 | if self.codeType != 0: |
|
552 | if self.codeType != 0: | |
539 |
self.__size += 4 + 4 + 4*self.nCode* |
|
553 | self.__size += 4 + 4 + 4 * self.nCode * \ | |
|
554 | numpy.ceil(self.nBaud / 32.) | |||
540 |
|
555 | |||
541 | return self.__size |
|
556 | return self.__size | |
542 |
|
557 | |||
@@ -549,6 +564,7 class RadarControllerHeader(Header): | |||||
549 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
564 | ippSeconds = property(get_ippSeconds, set_ippSeconds) | |
550 | size = property(get_size, set_size) |
|
565 | size = property(get_size, set_size) | |
551 |
|
566 | |||
|
567 | ||||
552 | class ProcessingHeader(Header): |
|
568 | class ProcessingHeader(Header): | |
553 |
|
569 | |||
554 | # size = None |
|
570 | # size = None | |
@@ -628,9 +644,11 class ProcessingHeader(Header): | |||||
628 |
|
644 | |||
629 | try: |
|
645 | try: | |
630 | if hasattr(fp, 'read'): |
|
646 | if hasattr(fp, 'read'): | |
631 |
samplingWindow = numpy.fromfile( |
|
647 | samplingWindow = numpy.fromfile( | |
|
648 | fp, SAMPLING_STRUCTURE, self.nWindows) | |||
632 | else: |
|
649 | else: | |
633 |
samplingWindow = numpy.fromstring( |
|
650 | samplingWindow = numpy.fromstring( | |
|
651 | fp[self.length:], SAMPLING_STRUCTURE, self.nWindows) | |||
634 | self.length += samplingWindow.nbytes |
|
652 | self.length += samplingWindow.nbytes | |
635 | except Exception, e: |
|
653 | except Exception, e: | |
636 | print "ProcessingHeader: " + str(e) |
|
654 | print "ProcessingHeader: " + str(e) | |
@@ -641,12 +659,13 class ProcessingHeader(Header): | |||||
641 | self.deltaHeight = float(samplingWindow['dh'][0]) |
|
659 | self.deltaHeight = float(samplingWindow['dh'][0]) | |
642 | self.samplesWin = samplingWindow['nsa'][0] |
|
660 | self.samplesWin = samplingWindow['nsa'][0] | |
643 |
|
661 | |||
644 |
|
||||
645 | try: |
|
662 | try: | |
646 | if hasattr(fp, 'read'): |
|
663 | if hasattr(fp, 'read'): | |
647 |
self.spectraComb = numpy.fromfile( |
|
664 | self.spectraComb = numpy.fromfile( | |
|
665 | fp, 'u1', 2 * self.totalSpectra) | |||
648 | else: |
|
666 | else: | |
649 |
self.spectraComb = numpy.fromstring( |
|
667 | self.spectraComb = numpy.fromstring( | |
|
668 | fp[self.length:], 'u1', 2 * self.totalSpectra) | |||
650 | self.length += self.spectraComb.nbytes |
|
669 | self.length += self.spectraComb.nbytes | |
651 | except Exception, e: |
|
670 | except Exception, e: | |
652 | print "ProcessingHeader: " + str(e) |
|
671 | print "ProcessingHeader: " + str(e) | |
@@ -655,7 +674,8 class ProcessingHeader(Header): | |||||
655 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): |
|
674 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): | |
656 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
675 | self.nCode = int(numpy.fromfile(fp, '<u4', 1)) | |
657 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
676 | self.nBaud = int(numpy.fromfile(fp, '<u4', 1)) | |
658 | self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud) |
|
677 | self.code = numpy.fromfile( | |
|
678 | fp, '<f4', self.nCode * self.nBaud).reshape(self.nCode, self.nBaud) | |||
659 |
|
679 | |||
660 | if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP): |
|
680 | if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP): | |
661 | exp_name_len = int(numpy.fromfile(fp,'<u4',1)) |
|
681 | exp_name_len = int(numpy.fromfile(fp, '<u4', 1)) | |
@@ -696,16 +716,16 class ProcessingHeader(Header): | |||||
696 | if nPairs > 0: |
|
716 | if nPairs > 0: | |
697 | self.flag_cspc = True |
|
717 | self.flag_cspc = True | |
698 |
|
718 | |||
699 |
|
||||
700 |
|
||||
701 | if startFp is not None: |
|
719 | if startFp is not None: | |
702 | endFp = size + startFp |
|
720 | endFp = size + startFp | |
703 | if fp.tell() > endFp: |
|
721 | if fp.tell() > endFp: | |
704 | sys.stderr.write("Warning: Processing header size is lower than it has to be") |
|
722 | sys.stderr.write( | |
|
723 | "Warning: Processing header size is lower than it has to be") | |||
705 | return 0 |
|
724 | return 0 | |
706 |
|
725 | |||
707 | if fp.tell() < endFp: |
|
726 | if fp.tell() < endFp: | |
708 | sys.stderr.write("Warning: Processing header size is greater than it is considered") |
|
727 | sys.stderr.write( | |
|
728 | "Warning: Processing header size is greater than it is considered") | |||
709 |
|
729 | |||
710 | return 1 |
|
730 | return 1 | |
711 |
|
731 | |||
@@ -728,7 +748,8 class ProcessingHeader(Header): | |||||
728 | header.tofile(fp) |
|
748 | header.tofile(fp) | |
729 |
|
749 | |||
730 | if self.nWindows != 0: |
|
750 | if self.nWindows != 0: | |
731 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
751 | sampleWindowTuple = ( | |
|
752 | self.firstHeight, self.deltaHeight, self.samplesWin) | |||
732 | samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) |
|
753 | samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE) | |
733 | samplingWindow.tofile(fp) |
|
754 | samplingWindow.tofile(fp) | |
734 |
|
755 | |||
@@ -768,6 +789,7 class ProcessingHeader(Header): | |||||
768 |
|
789 | |||
769 | size = property(get_size, set_size) |
|
790 | size = property(get_size, set_size) | |
770 |
|
791 | |||
|
792 | ||||
771 | class RCfunction: |
|
793 | class RCfunction: | |
772 | NONE=0 |
|
794 | NONE = 0 | |
773 | FLIP=1 |
|
795 | FLIP = 1 | |
@@ -776,6 +798,7 class RCfunction: | |||||
776 | LIN6DIV256=4 |
|
798 | LIN6DIV256 = 4 | |
777 | SYNCHRO=5 |
|
799 | SYNCHRO = 5 | |
778 |
|
800 | |||
|
801 | ||||
779 | class nCodeType: |
|
802 | class nCodeType: | |
780 | NONE=0 |
|
803 | NONE = 0 | |
781 | USERDEFINE=1 |
|
804 | USERDEFINE = 1 | |
@@ -796,6 +819,7 class nCodeType: | |||||
796 | COMPLEMENTARYCODE128=16 |
|
819 | COMPLEMENTARYCODE128 = 16 | |
797 | CODE_BINARY28=17 |
|
820 | CODE_BINARY28 = 17 | |
798 |
|
821 | |||
|
822 | ||||
799 |
class PROCFLAG: |
|
823 | class PROCFLAG: | |
800 |
|
824 | |||
801 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
825 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) | |
@@ -834,6 +858,7 class PROCFLAG: | |||||
834 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
858 | DATAARRANGE_MASK = numpy.uint32(0x00007000) | |
835 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) |
|
859 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) | |
836 |
|
860 | |||
|
861 | ||||
837 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
862 | dtype0 = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) | |
838 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
863 | dtype1 = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) | |
839 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
864 | dtype2 = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) | |
@@ -852,6 +877,7 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR, | |||||
852 |
|
877 | |||
853 | DTYPE_WIDTH = [1, 2, 4, 8, 4, 8] |
|
878 | DTYPE_WIDTH = [1, 2, 4, 8, 4, 8] | |
854 |
|
879 | |||
|
880 | ||||
855 | def get_dtype_index(numpy_dtype): |
|
881 | def get_dtype_index(numpy_dtype): | |
856 |
|
882 | |||
857 | index = None |
|
883 | index = None | |
@@ -863,14 +889,17 def get_dtype_index(numpy_dtype): | |||||
863 |
|
889 | |||
864 | return index |
|
890 | return index | |
865 |
|
891 | |||
|
892 | ||||
866 | def get_numpy_dtype(index): |
|
893 | def get_numpy_dtype(index): | |
867 |
|
894 | |||
868 | return NUMPY_DTYPE_LIST[index] |
|
895 | return NUMPY_DTYPE_LIST[index] | |
869 |
|
896 | |||
|
897 | ||||
870 | def get_procflag_dtype(index): |
|
898 | def get_procflag_dtype(index): | |
871 |
|
899 | |||
872 | return PROCFLAG_DTYPE_LIST[index] |
|
900 | return PROCFLAG_DTYPE_LIST[index] | |
873 |
|
901 | |||
|
902 | ||||
874 | def get_dtype_width(index): |
|
903 | def get_dtype_width(index): | |
875 |
|
904 | |||
876 | return DTYPE_WIDTH[index] |
|
905 | return DTYPE_WIDTH[index] |
@@ -657,11 +657,11 class DigitalRFWriter(Operation): | |||||
657 | self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData |
|
657 | self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData | |
658 | self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData |
|
658 | self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData | |
659 | self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT |
|
659 | self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT | |
660 | self.metadata_dict['flagDataAsBlock'] = self.dataOut.flagDataAsBlock |
|
|||
661 | self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime |
|
660 | self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime | |
662 | self.metadata_dict['nCohInt'] = self.dataOut.nCohInt |
|
661 | self.metadata_dict['nCohInt'] = self.dataOut.nCohInt | |
663 |
|
662 | self.metadata_dict['type'] = self.dataOut.type | ||
664 | return |
|
663 | self.metadata_dict['flagDataAsBlock'] = getattr( | |
|
664 | self.dataOut, 'flagDataAsBlock', None) # chequear | |||
665 |
|
665 | |||
666 | def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'): |
|
666 | def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'): | |
667 | ''' |
|
667 | ''' | |
@@ -678,9 +678,13 class DigitalRFWriter(Operation): | |||||
678 | self.__dtype = dataOut.dtype[0] |
|
678 | self.__dtype = dataOut.dtype[0] | |
679 | self.__nSamples = dataOut.systemHeaderObj.nSamples |
|
679 | self.__nSamples = dataOut.systemHeaderObj.nSamples | |
680 | self.__nProfiles = dataOut.nProfiles |
|
680 | self.__nProfiles = dataOut.nProfiles | |
681 | self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile |
|
|||
682 |
|
681 | |||
683 | self.arr_data = arr_data = numpy.ones((self.__nSamples, len( |
|
682 | if self.dataOut.type != 'Voltage': | |
|
683 | raise 'Digital RF cannot be used with this data type' | |||
|
684 | self.arr_data = numpy.ones((1, dataOut.nFFTPoints * len( | |||
|
685 | self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) | |||
|
686 | else: | |||
|
687 | self.arr_data = numpy.ones((self.__nSamples, len( | |||
684 | self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) |
|
688 | self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) | |
685 |
|
689 | |||
686 | file_cadence_millisecs = 1000 |
|
690 | file_cadence_millisecs = 1000 | |
@@ -702,14 +706,11 class DigitalRFWriter(Operation): | |||||
702 | fileCadence, start_global_index, |
|
706 | fileCadence, start_global_index, | |
703 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, |
|
707 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, | |
704 | is_complex, num_subchannels, is_continuous, marching_periods) |
|
708 | is_complex, num_subchannels, is_continuous, marching_periods) | |
705 |
|
||||
706 | metadata_dir = os.path.join(path, 'metadata') |
|
709 | metadata_dir = os.path.join(path, 'metadata') | |
707 | os.system('mkdir %s' % (metadata_dir)) |
|
710 | os.system('mkdir %s' % (metadata_dir)) | |
708 |
|
||||
709 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000 |
|
711 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000 | |
710 | sample_rate_numerator, sample_rate_denominator, |
|
712 | sample_rate_numerator, sample_rate_denominator, | |
711 | metadataFile) |
|
713 | metadataFile) | |
712 |
|
||||
713 | self.isConfig = True |
|
714 | self.isConfig = True | |
714 | self.currentSample = 0 |
|
715 | self.currentSample = 0 | |
715 | self.oldAverage = 0 |
|
716 | self.oldAverage = 0 | |
@@ -717,7 +718,6 class DigitalRFWriter(Operation): | |||||
717 | return |
|
718 | return | |
718 |
|
719 | |||
719 | def writeMetadata(self): |
|
720 | def writeMetadata(self): | |
720 | print '[Writing] - Writing metadata' |
|
|||
721 | start_idx = self.__sample_rate * self.dataOut.utctime |
|
721 | start_idx = self.__sample_rate * self.dataOut.utctime | |
722 |
|
722 | |||
723 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict( |
|
723 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict( | |
@@ -741,6 +741,15 class DigitalRFWriter(Operation): | |||||
741 | return |
|
741 | return | |
742 |
|
742 | |||
743 | def writeData(self): |
|
743 | def writeData(self): | |
|
744 | if self.dataOut.type != 'Voltage': | |||
|
745 | raise 'Digital RF cannot be used with this data type' | |||
|
746 | for channel in self.dataOut.channelList: | |||
|
747 | for i in range(self.dataOut.nFFTPoints): | |||
|
748 | self.arr_data[1][channel * self.dataOut.nFFTPoints + | |||
|
749 | i]['r'] = self.dataOut.data[channel][i].real | |||
|
750 | self.arr_data[1][channel * self.dataOut.nFFTPoints + | |||
|
751 | i]['i'] = self.dataOut.data[channel][i].imag | |||
|
752 | else: | |||
744 | for i in range(self.dataOut.systemHeaderObj.nSamples): |
|
753 | for i in range(self.dataOut.systemHeaderObj.nSamples): | |
745 | for channel in self.dataOut.channelList: |
|
754 | for channel in self.dataOut.channelList: | |
746 | self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real |
|
755 | self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real |
@@ -6,6 +6,7 from jroproc_base import ProcessingUnit, Operation | |||||
6 | from schainpy.model.data.jrodata import Spectra |
|
6 | from schainpy.model.data.jrodata import Spectra | |
7 | from schainpy.model.data.jrodata import hildebrand_sekhon |
|
7 | from schainpy.model.data.jrodata import hildebrand_sekhon | |
8 |
|
8 | |||
|
9 | ||||
9 | class SpectraProc(ProcessingUnit): |
|
10 | class SpectraProc(ProcessingUnit): | |
10 |
|
11 | |||
11 | def __init__(self, **kwargs): |
|
12 | def __init__(self, **kwargs): | |
@@ -25,7 +26,10 class SpectraProc(ProcessingUnit): | |||||
25 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
26 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
26 | self.dataOut.errorCount = self.dataIn.errorCount |
|
27 | self.dataOut.errorCount = self.dataIn.errorCount | |
27 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
28 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
28 |
|
29 | try: | ||
|
30 | self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy() | |||
|
31 | except: | |||
|
32 | pass | |||
29 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
33 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
30 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
34 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
31 | self.dataOut.channelList = self.dataIn.channelList |
|
35 | self.dataOut.channelList = self.dataIn.channelList | |
@@ -39,8 +43,10 class SpectraProc(ProcessingUnit): | |||||
39 |
|
43 | |||
40 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock |
|
44 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock | |
41 | self.dataOut.utctime = self.firstdatatime |
|
45 | self.dataOut.utctime = self.firstdatatime | |
42 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
46 | # asumo q la data esta decodificada | |
43 |
self.dataOut.flagDe |
|
47 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData | |
|
48 | # asumo q la data esta sin flip | |||
|
49 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData | |||
44 | self.dataOut.flagShiftFFT = False |
|
50 | self.dataOut.flagShiftFFT = False | |
45 |
|
51 | |||
46 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
52 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
@@ -71,7 +77,8 class SpectraProc(ProcessingUnit): | |||||
71 | self.buffer |
|
77 | self.buffer | |
72 | self.dataOut.flagNoData |
|
78 | self.dataOut.flagNoData | |
73 | """ |
|
79 | """ | |
74 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) |
|
80 | fft_volt = numpy.fft.fft( | |
|
81 | self.buffer, n=self.dataOut.nFFTPoints, axis=1) | |||
75 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
82 | fft_volt = fft_volt.astype(numpy.dtype('complex')) | |
76 | dc = fft_volt[:,0,:] |
|
83 | dc = fft_volt[:, 0, :] | |
77 |
|
84 | |||
@@ -88,14 +95,18 class SpectraProc(ProcessingUnit): | |||||
88 | pairIndex = 0 |
|
95 | pairIndex = 0 | |
89 | if self.dataOut.pairsList != None: |
|
96 | if self.dataOut.pairsList != None: | |
90 | #calculo de cross-spectra |
|
97 | # calculo de cross-spectra | |
91 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
98 | cspc = numpy.zeros( | |
|
99 | (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |||
92 | for pair in self.dataOut.pairsList: |
|
100 | for pair in self.dataOut.pairsList: | |
93 | if pair[0] not in self.dataOut.channelList: |
|
101 | if pair[0] not in self.dataOut.channelList: | |
94 |
raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %( |
|
102 | raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % ( | |
|
103 | str(pair), str(self.dataOut.channelList)) | |||
95 | if pair[1] not in self.dataOut.channelList: |
|
104 | if pair[1] not in self.dataOut.channelList: | |
96 |
raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %( |
|
105 | raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % ( | |
|
106 | str(pair), str(self.dataOut.channelList)) | |||
97 |
|
107 | |||
98 |
cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * |
|
108 | cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \ | |
|
109 | numpy.conjugate(fft_volt[pair[1], :, :]) | |||
99 | pairIndex += 1 |
|
110 | pairIndex += 1 | |
100 | blocksize += cspc.size |
|
111 | blocksize += cspc.size | |
101 |
|
112 | |||
@@ -154,12 +165,14 class SpectraProc(ProcessingUnit): | |||||
154 | self.id_min = 0 |
|
165 | self.id_min = 0 | |
155 | self.id_max = nVoltProfiles |
|
166 | self.id_max = nVoltProfiles | |
156 |
|
167 | |||
157 |
self.buffer[:,self.id_min:self.id_max, |
|
168 | self.buffer[:, self.id_min:self.id_max, | |
|
169 | :] = self.dataIn.data | |||
158 | self.profIndex += nVoltProfiles |
|
170 | self.profIndex += nVoltProfiles | |
159 | self.id_min += nVoltProfiles |
|
171 | self.id_min += nVoltProfiles | |
160 | self.id_max += nVoltProfiles |
|
172 | self.id_max += nVoltProfiles | |
161 | else: |
|
173 | else: | |
162 |
raise ValueError, "The type object %s has %d profiles, it should just has %d profiles"%( |
|
174 | raise ValueError, "The type object %s has %d profiles, it should just has %d profiles" % ( | |
|
175 | self.dataIn.type, self.dataIn.data.shape[1], nProfiles) | |||
163 | self.dataOut.flagNoData = True |
|
176 | self.dataOut.flagNoData = True | |
164 | return 0 |
|
177 | return 0 | |
165 | else: |
|
178 | else: | |
@@ -179,7 +192,8 class SpectraProc(ProcessingUnit): | |||||
179 |
|
192 | |||
180 | return True |
|
193 | return True | |
181 |
|
194 | |||
182 |
raise ValueError, "The type of input object '%s' is not valid"%( |
|
195 | raise ValueError, "The type of input object '%s' is not valid" % ( | |
|
196 | self.dataIn.type) | |||
183 |
|
197 | |||
184 | def __selectPairs(self, pairsList): |
|
198 | def __selectPairs(self, pairsList): | |
185 |
|
199 | |||
@@ -222,7 +236,8 class SpectraProc(ProcessingUnit): | |||||
222 | return |
|
236 | return | |
223 |
|
237 | |||
224 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
238 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
225 |
self.dataOut.pairsList = [self.dataOut.pairsList[i] |
|
239 | self.dataOut.pairsList = [self.dataOut.pairsList[i] | |
|
240 | for i in pairsIndexListSelected] | |||
226 |
|
241 | |||
227 | return |
|
242 | return | |
228 |
|
243 | |||
@@ -232,7 +247,8 class SpectraProc(ProcessingUnit): | |||||
232 |
|
247 | |||
233 | for channel in channelList: |
|
248 | for channel in channelList: | |
234 | if channel not in self.dataOut.channelList: |
|
249 | if channel not in self.dataOut.channelList: | |
235 |
raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %( |
|
250 | raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" % ( | |
|
251 | channel, str(self.dataOut.channelList)) | |||
236 |
|
252 | |||
237 | index = self.dataOut.channelList.index(channel) |
|
253 | index = self.dataOut.channelList.index(channel) | |
238 | channelIndexList.append(index) |
|
254 | channelIndexList.append(index) | |
@@ -257,7 +273,8 class SpectraProc(ProcessingUnit): | |||||
257 |
|
273 | |||
258 | for channelIndex in channelIndexList: |
|
274 | for channelIndex in channelIndexList: | |
259 | if channelIndex not in self.dataOut.channelIndexList: |
|
275 | if channelIndex not in self.dataOut.channelIndexList: | |
260 |
raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %( |
|
276 | raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " % ( | |
|
277 | channelIndex, self.dataOut.channelIndexList) | |||
261 |
|
278 | |||
262 | # nChannels = len(channelIndexList) |
|
279 | # nChannels = len(channelIndexList) | |
263 |
|
280 | |||
@@ -267,7 +284,8 class SpectraProc(ProcessingUnit): | |||||
267 | self.dataOut.data_spc = data_spc |
|
284 | self.dataOut.data_spc = data_spc | |
268 | self.dataOut.data_dc = data_dc |
|
285 | self.dataOut.data_dc = data_dc | |
269 |
|
286 | |||
270 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
287 | self.dataOut.channelList = [ | |
|
288 | self.dataOut.channelList[i] for i in channelIndexList] | |||
271 | # self.dataOut.nChannels = nChannels |
|
289 | # self.dataOut.nChannels = nChannels | |
272 |
|
290 | |||
273 | self.__selectPairsByChannel(self.dataOut.channelList) |
|
291 | self.__selectPairsByChannel(self.dataOut.channelList) | |
@@ -291,7 +309,8 class SpectraProc(ProcessingUnit): | |||||
291 | """ |
|
309 | """ | |
292 |
|
310 | |||
293 | if (minHei > maxHei): |
|
311 | if (minHei > maxHei): | |
294 |
raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % ( |
|
312 | raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % ( | |
|
313 | minHei, maxHei) | |||
295 |
|
314 | |||
296 | if (minHei < self.dataOut.heightList[0]): |
|
315 | if (minHei < self.dataOut.heightList[0]): | |
297 | minHei = self.dataOut.heightList[0] |
|
316 | minHei = self.dataOut.heightList[0] | |
@@ -321,7 +340,8 class SpectraProc(ProcessingUnit): | |||||
321 | return 1 |
|
340 | return 1 | |
322 |
|
341 | |||
323 |
def getBeaconSignal(self, tauindex |
|
342 | def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None): | |
324 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
343 | newheis = numpy.where( | |
|
344 | self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |||
325 |
|
345 | |||
326 | if hei_ref != None: |
|
346 | if hei_ref != None: | |
327 | newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
347 | newheis = numpy.where(self.dataOut.heightList > hei_ref) | |
@@ -332,8 +352,10 class SpectraProc(ProcessingUnit): | |||||
332 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
352 | heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
333 |
|
353 | |||
334 | # determina indices |
|
354 | # determina indices | |
335 |
nheis = int(self.dataOut.radarControllerHeaderObj.txB/ |
|
355 | nheis = int(self.dataOut.radarControllerHeaderObj.txB / | |
336 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) |
|
356 | (self.dataOut.heightList[1] - self.dataOut.heightList[0])) | |
|
357 | avg_dB = 10 * \ | |||
|
358 | numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0)) | |||
337 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
359 | beacon_dB = numpy.sort(avg_dB)[-nheis:] | |
338 | beacon_heiIndexList = [] |
|
360 | beacon_heiIndexList = [] | |
339 | for val in avg_dB.tolist(): |
|
361 | for val in avg_dB.tolist(): | |
@@ -359,7 +381,6 class SpectraProc(ProcessingUnit): | |||||
359 |
|
381 | |||
360 | return 1 |
|
382 | return 1 | |
361 |
|
383 | |||
362 |
|
||||
363 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
384 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
364 | """ |
|
385 | """ | |
365 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
386 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
@@ -380,7 +401,8 class SpectraProc(ProcessingUnit): | |||||
380 | """ |
|
401 | """ | |
381 |
|
402 | |||
382 | if (minIndex < 0) or (minIndex > maxIndex): |
|
403 | if (minIndex < 0) or (minIndex > maxIndex): | |
383 |
raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
404 | raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % ( | |
|
405 | minIndex, maxIndex) | |||
384 |
|
406 | |||
385 | if (maxIndex >= self.dataOut.nHeights): |
|
407 | if (maxIndex >= self.dataOut.nHeights): | |
386 | maxIndex = self.dataOut.nHeights-1 |
|
408 | maxIndex = self.dataOut.nHeights - 1 | |
@@ -408,14 +430,14 class SpectraProc(ProcessingUnit): | |||||
408 | jspectra = self.dataOut.data_spc |
|
430 | jspectra = self.dataOut.data_spc | |
409 | jcspectra = self.dataOut.data_cspc |
|
431 | jcspectra = self.dataOut.data_cspc | |
410 |
|
432 | |||
411 |
|
||||
412 | num_chan = jspectra.shape[0] |
|
433 | num_chan = jspectra.shape[0] | |
413 | num_hei = jspectra.shape[2] |
|
434 | num_hei = jspectra.shape[2] | |
414 |
|
435 | |||
415 | if jcspectra is not None: |
|
436 | if jcspectra is not None: | |
416 | jcspectraExist = True |
|
437 | jcspectraExist = True | |
417 | num_pairs = jcspectra.shape[0] |
|
438 | num_pairs = jcspectra.shape[0] | |
418 | else: jcspectraExist = False |
|
439 | else: | |
|
440 | jcspectraExist = False | |||
419 |
|
441 | |||
420 | freq_dc = jspectra.shape[1]/2 |
|
442 | freq_dc = jspectra.shape[1] / 2 | |
421 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
443 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc | |
@@ -424,10 +446,12 class SpectraProc(ProcessingUnit): | |||||
424 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
446 | ind_vel[range(0, 1)] = ind_vel[range(0, 1)] + self.num_prof | |
425 |
|
447 | |||
426 | if mode == 1: |
|
448 | if mode == 1: | |
427 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
449 | jspectra[:, freq_dc, :] = ( | |
|
450 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION | |||
428 |
|
451 | |||
429 | if jcspectraExist: |
|
452 | if jcspectraExist: | |
430 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 |
|
453 | jcspectra[:, freq_dc, :] = ( | |
|
454 | jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2 | |||
431 |
|
455 | |||
432 | if mode == 2: |
|
456 | if mode == 2: | |
433 |
|
457 | |||
@@ -448,14 +472,14 class SpectraProc(ProcessingUnit): | |||||
448 | cjunkid = sum(junkid) |
|
472 | cjunkid = sum(junkid) | |
449 |
|
473 | |||
450 | if cjunkid.any(): |
|
474 | if cjunkid.any(): | |
451 |
jspectra[ich,freq_dc,junkid.nonzero()] = ( |
|
475 | jspectra[ich, freq_dc, junkid.nonzero()] = ( | |
|
476 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 | |||
452 |
|
477 | |||
453 | if jcspectraExist: |
|
478 | if jcspectraExist: | |
454 | for ip in range(num_pairs): |
|
479 | for ip in range(num_pairs): | |
455 | yy = jcspectra[ip,ind_vel,:] |
|
480 | yy = jcspectra[ip, ind_vel, :] | |
456 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
481 | jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy) | |
457 |
|
482 | |||
458 |
|
||||
459 | self.dataOut.data_spc = jspectra |
|
483 | self.dataOut.data_spc = jspectra | |
460 | self.dataOut.data_cspc = jcspectra |
|
484 | self.dataOut.data_cspc = jcspectra | |
461 |
|
485 | |||
@@ -494,7 +518,6 class SpectraProc(ProcessingUnit): | |||||
494 | num_mask_prof = mask_prof.size |
|
518 | num_mask_prof = mask_prof.size | |
495 | comp_mask_prof = [0, num_prof/2] |
|
519 | comp_mask_prof = [0, num_prof / 2] | |
496 |
|
520 | |||
497 |
|
||||
498 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
521 | # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal | |
499 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
522 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): | |
500 | jnoise = numpy.nan |
|
523 | jnoise = numpy.nan | |
@@ -509,7 +532,8 class SpectraProc(ProcessingUnit): | |||||
509 | psort = power.ravel().argsort() |
|
532 | psort = power.ravel().argsort() | |
510 |
|
533 | |||
511 | #Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
534 | # Se estima la interferencia promedio en los Espectros de Potencia empleando | |
512 |
junkspc_interf = jspectra[ich,:,hei_interf[psort[range( |
|
535 | junkspc_interf = jspectra[ich, :, hei_interf[psort[range( | |
|
536 | offhei_interf, nhei_interf + offhei_interf)]]] | |||
513 |
|
537 | |||
514 | if noise_exist: |
|
538 | if noise_exist: | |
515 | # tmp_noise = jnoise[ich] / num_prof |
|
539 | # tmp_noise = jnoise[ich] / num_prof | |
@@ -520,43 +544,51 class SpectraProc(ProcessingUnit): | |||||
520 |
jspc_interf = junkspc_interf.sum(axis |
|
544 | jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf | |
521 | jspc_interf = jspc_interf.transpose() |
|
545 | jspc_interf = jspc_interf.transpose() | |
522 | #Calculando el espectro de interferencia promedio |
|
546 | # Calculando el espectro de interferencia promedio | |
523 | noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh)) |
|
547 | noiseid = numpy.where( | |
|
548 | jspc_interf <= tmp_noise / numpy.sqrt(num_incoh)) | |||
524 | noiseid = noiseid[0] |
|
549 | noiseid = noiseid[0] | |
525 | cnoiseid = noiseid.size |
|
550 | cnoiseid = noiseid.size | |
526 | interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh)) |
|
551 | interfid = numpy.where( | |
|
552 | jspc_interf > tmp_noise / numpy.sqrt(num_incoh)) | |||
527 | interfid = interfid[0] |
|
553 | interfid = interfid[0] | |
528 | cinterfid = interfid.size |
|
554 | cinterfid = interfid.size | |
529 |
|
555 | |||
530 |
if (cnoiseid > 0): |
|
556 | if (cnoiseid > 0): | |
|
557 | jspc_interf[noiseid] = 0 | |||
531 |
|
558 | |||
532 | #Expandiendo los perfiles a limpiar |
|
559 | # Expandiendo los perfiles a limpiar | |
533 | if (cinterfid > 0): |
|
560 | if (cinterfid > 0): | |
534 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof |
|
561 | new_interfid = ( | |
|
562 | numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof | |||
535 | new_interfid = numpy.asarray(new_interfid) |
|
563 | new_interfid = numpy.asarray(new_interfid) | |
536 | new_interfid = {x for x in new_interfid} |
|
564 | new_interfid = {x for x in new_interfid} | |
537 | new_interfid = numpy.array(list(new_interfid)) |
|
565 | new_interfid = numpy.array(list(new_interfid)) | |
538 | new_cinterfid = new_interfid.size |
|
566 | new_cinterfid = new_interfid.size | |
539 |
else: |
|
567 | else: | |
|
568 | new_cinterfid = 0 | |||
540 |
|
569 | |||
541 | for ip in range(new_cinterfid): |
|
570 | for ip in range(new_cinterfid): | |
542 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() |
|
571 | ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort() | |
543 |
jspc_interf[new_interfid[ip] |
|
572 | jspc_interf[new_interfid[ip] | |
544 |
|
573 | ] = junkspc_interf[ind[nhei_interf / 2], new_interfid[ip]] | ||
545 |
|
574 | |||
546 |
jspectra[ich,:,ind_hei] = jspectra[ich,:, |
|
575 | jspectra[ich, :, ind_hei] = jspectra[ich, :, | |
|
576 | ind_hei] - jspc_interf # Corregir indices | |||
547 |
|
577 | |||
548 | #Removiendo la interferencia del punto de mayor interferencia |
|
578 | # Removiendo la interferencia del punto de mayor interferencia | |
549 | ListAux = jspc_interf[mask_prof].tolist() |
|
579 | ListAux = jspc_interf[mask_prof].tolist() | |
550 | maxid = ListAux.index(max(ListAux)) |
|
580 | maxid = ListAux.index(max(ListAux)) | |
551 |
|
581 | |||
552 |
|
||||
553 | if cinterfid > 0: |
|
582 | if cinterfid > 0: | |
554 | for ip in range(cinterfid*(interf == 2) - 1): |
|
583 | for ip in range(cinterfid * (interf == 2) - 1): | |
555 |
ind = (jspectra[ich,interfid[ip],:] < tmp_noise* |
|
584 | ind = (jspectra[ich, interfid[ip], :] < tmp_noise * | |
|
585 | (1 + 1 / numpy.sqrt(num_incoh))).nonzero() | |||
556 | cind = len(ind) |
|
586 | cind = len(ind) | |
557 |
|
587 | |||
558 | if (cind > 0): |
|
588 | if (cind > 0): | |
559 |
jspectra[ich,interfid[ip],ind] = tmp_noise* |
|
589 | jspectra[ich, interfid[ip], ind] = tmp_noise * \ | |
|
590 | (1 + (numpy.random.uniform(cind) - 0.5) / | |||
|
591 | numpy.sqrt(num_incoh)) | |||
560 |
|
592 | |||
561 | ind = numpy.array([-2,-1,1,2]) |
|
593 | ind = numpy.array([-2, -1, 1, 2]) | |
562 | xx = numpy.zeros([4,4]) |
|
594 | xx = numpy.zeros([4, 4]) | |
@@ -568,14 +600,17 class SpectraProc(ProcessingUnit): | |||||
568 | xx = xx_inv[:,0] |
|
600 | xx = xx_inv[:, 0] | |
569 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
601 | ind = (ind + maxid + num_mask_prof) % num_mask_prof | |
570 | yy = jspectra[ich,mask_prof[ind],:] |
|
602 | yy = jspectra[ich, mask_prof[ind], :] | |
571 |
jspectra[ich,mask_prof[maxid],:] = numpy.dot( |
|
603 | jspectra[ich, mask_prof[maxid], :] = numpy.dot( | |
|
604 | yy.transpose(), xx) | |||
572 |
|
605 | |||
573 |
|
606 | indAux = (jspectra[ich, :, :] < tmp_noise * | ||
574 |
|
|
607 | (1 - 1 / numpy.sqrt(num_incoh))).nonzero() | |
575 |
jspectra[ich,indAux[0],indAux[1]] = tmp_noise * |
|
608 | jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \ | |
|
609 | (1 - 1 / numpy.sqrt(num_incoh)) | |||
576 |
|
610 | |||
577 | #Remocion de Interferencia en el Cross Spectra |
|
611 | # Remocion de Interferencia en el Cross Spectra | |
578 |
if jcspectra is None: |
|
612 | if jcspectra is None: | |
|
613 | return jspectra, jcspectra | |||
579 | num_pairs = jcspectra.size/(num_prof*num_hei) |
|
614 | num_pairs = jcspectra.size / (num_prof * num_hei) | |
580 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
615 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) | |
581 |
|
616 | |||
@@ -588,22 +623,28 class SpectraProc(ProcessingUnit): | |||||
588 |
cspower = cspower.sum(axis |
|
623 | cspower = cspower.sum(axis=0) | |
589 |
|
624 | |||
590 | cspsort = cspower.ravel().argsort() |
|
625 | cspsort = cspower.ravel().argsort() | |
591 |
junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range( |
|
626 | junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[range( | |
|
627 | offhei_interf, nhei_interf + offhei_interf)]]] | |||
592 | junkcspc_interf = junkcspc_interf.transpose() |
|
628 | junkcspc_interf = junkcspc_interf.transpose() | |
593 |
jcspc_interf = junkcspc_interf.sum(axis |
|
629 | jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf | |
594 |
|
630 | |||
595 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
631 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() | |
596 |
|
632 | |||
597 |
median_real = numpy.median(numpy.real( |
|
633 | median_real = numpy.median(numpy.real( | |
598 |
|
|
634 | junkcspc_interf[mask_prof[ind[range(3 * num_prof / 4)]], :])) | |
599 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) |
|
635 | median_imag = numpy.median(numpy.imag( | |
|
636 | junkcspc_interf[mask_prof[ind[range(3 * num_prof / 4)]], :])) | |||
|
637 | junkcspc_interf[comp_mask_prof, :] = numpy.complex( | |||
|
638 | median_real, median_imag) | |||
600 |
|
639 | |||
601 | for iprof in range(num_prof): |
|
640 | for iprof in range(num_prof): | |
602 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() |
|
641 | ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort() | |
603 |
jcspc_interf[iprof] = junkcspc_interf[iprof, |
|
642 | jcspc_interf[iprof] = junkcspc_interf[iprof, | |
|
643 | ind[nhei_interf / 2]] | |||
604 |
|
644 | |||
605 | #Removiendo la Interferencia |
|
645 | # Removiendo la Interferencia | |
606 |
jcspectra[ip,:,ind_hei] = jcspectra[ip, |
|
646 | jcspectra[ip, :, ind_hei] = jcspectra[ip, | |
|
647 | :, ind_hei] - jcspc_interf | |||
607 |
|
648 | |||
608 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
649 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() | |
609 | maxid = ListAux.index(max(ListAux)) |
|
650 | maxid = ListAux.index(max(ListAux)) | |
@@ -690,7 +731,8 class SpectraProc(ProcessingUnit): | |||||
690 | maxIndex = len(heights) |
|
731 | maxIndex = len(heights) | |
691 |
|
732 | |||
692 | if (minIndex < 0) or (minIndex > maxIndex): |
|
733 | if (minIndex < 0) or (minIndex > maxIndex): | |
693 |
raise ValueError, "some value in (%d,%d) is not valid" % ( |
|
734 | raise ValueError, "some value in (%d,%d) is not valid" % ( | |
|
735 | minIndex, maxIndex) | |||
694 |
|
736 | |||
695 | if (maxIndex >= self.dataOut.nHeights): |
|
737 | if (maxIndex >= self.dataOut.nHeights): | |
696 | maxIndex = self.dataOut.nHeights-1 |
|
738 | maxIndex = self.dataOut.nHeights - 1 | |
@@ -709,7 +751,8 class SpectraProc(ProcessingUnit): | |||||
709 | maxIndexVel = len(velrange) |
|
751 | maxIndexVel = len(velrange) | |
710 |
|
752 | |||
711 | #seleccion del espectro |
|
753 | # seleccion del espectro | |
712 |
data_spc = self.dataOut.data_spc[:, |
|
754 | data_spc = self.dataOut.data_spc[:, | |
|
755 | minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1] | |||
713 | #estimacion de ruido |
|
756 | # estimacion de ruido | |
714 | noise = numpy.zeros(self.dataOut.nChannels) |
|
757 | noise = numpy.zeros(self.dataOut.nChannels) | |
715 |
|
758 | |||
@@ -721,8 +764,8 class SpectraProc(ProcessingUnit): | |||||
721 |
|
764 | |||
722 | return 1 |
|
765 | return 1 | |
723 |
|
766 | |||
724 | class IncohInt(Operation): |
|
|||
725 |
|
767 | |||
|
768 | class IncohInt(Operation): | |||
726 |
|
769 | |||
727 | __profIndex = 0 |
|
770 | __profIndex = 0 | |
728 |
__withOverapping |
|
771 | __withOverapping = False | |
@@ -742,8 +785,6 class IncohInt(Operation): | |||||
742 |
|
785 | |||
743 | n = None |
|
786 | n = None | |
744 |
|
787 | |||
745 |
|
||||
746 |
|
||||
747 | def __init__(self, **kwargs): |
|
788 | def __init__(self, **kwargs): | |
748 |
|
789 | |||
749 | Operation.__init__(self, **kwargs) |
|
790 | Operation.__init__(self, **kwargs) | |
@@ -778,12 +819,12 class IncohInt(Operation): | |||||
778 | if n is not None: |
|
819 | if n is not None: | |
779 | self.n = int(n) |
|
820 | self.n = int(n) | |
780 | else: |
|
821 | else: | |
781 |
|
|
822 | # if (type(timeInterval)!=integer) -> change this line | |
|
823 | self.__integrationtime = int(timeInterval) | |||
782 | self.n = None |
|
824 | self.n = None | |
783 | self.__byTime = True |
|
825 | self.__byTime = True | |
784 |
|
826 | |||
785 | def putData(self, data_spc, data_cspc, data_dc): |
|
827 | def putData(self, data_spc, data_cspc, data_dc): | |
786 |
|
||||
787 | """ |
|
828 | """ | |
788 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
829 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
789 |
|
830 | |||
@@ -866,7 +907,8 class IncohInt(Operation): | |||||
866 | self.__initime = datatime |
|
907 | self.__initime = datatime | |
867 |
|
908 | |||
868 | if self.__byTime: |
|
909 | if self.__byTime: | |
869 |
avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime( |
|
910 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime( | |
|
911 | datatime, *args) | |||
870 | else: |
|
912 | else: | |
871 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
913 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
872 |
|
914 |
General Comments 0
You need to be logged in to leave comments.
Login now