##// END OF EJS Templates
jroproc_spectra_lags: decoding data from Tx Pulse (real data)
Miguel Valdez -
r776:12cd779dd5fc
parent child
Show More
@@ -10,15 +10,19 class SpectraLagsProc(ProcessingUnit):
10
10
11 ProcessingUnit.__init__(self)
11 ProcessingUnit.__init__(self)
12
12
13 self.buffer = None
13 self.__input_buffer = None
14 self.firstdatatime = None
14 self.firstdatatime = None
15 self.profIndex = 0
15 self.profIndex = 0
16 self.dataOut = Spectra()
16 self.dataOut = Spectra()
17 self.id_min = None
17 self.id_min = None
18 self.id_max = None
18 self.id_max = None
19 self.__codeIndex = 0
20
21 self.__lags_buffer = None
19
22
20 def __updateSpecFromVoltage(self):
23 def __updateSpecFromVoltage(self):
21
24
25 self.dataOut.plotting = "spectra_lags"
22 self.dataOut.timeZone = self.dataIn.timeZone
26 self.dataOut.timeZone = self.dataIn.timeZone
23 self.dataOut.dstFlag = self.dataIn.dstFlag
27 self.dataOut.dstFlag = self.dataIn.dstFlag
24 self.dataOut.errorCount = self.dataIn.errorCount
28 self.dataOut.errorCount = self.dataIn.errorCount
@@ -57,16 +61,36 class SpectraLagsProc(ProcessingUnit):
57 self.dataOut.beam.codeList = self.dataIn.beam.codeList
61 self.dataOut.beam.codeList = self.dataIn.beam.codeList
58 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
62 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
59 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
63 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
64
65 def __createLagsBlock(self, voltages):
60
66
61 def __decodeData(self, nProfiles, code):
67 if self.__lags_buffer is None:
68 self.__lags_buffer = numpy.zeros((self.dataOut.nChannels, self.dataOut.nProfiles, self.dataOut.nHeights), dtype='complex')
62
69
63 if code is None:
70 nsegments = self.dataOut.nHeights - self.dataOut.nProfiles
64 return
71
72 # codes = numpy.conjugate(self.__input_buffer[:,9:169])/10000
73
74 for i in range(nsegments):
75 self.__lags_buffer[:,:,i] = voltages[:,i:i+self.dataOut.nProfiles]#*codes
76
77 return self.__lags_buffer
65
78
66 for i in range(nProfiles):
79 def __decodeData(self, volt_buffer, pulseIndex=None):
67 self.buffer[:,i,:] = self.buffer[:,i,:]*code[0][i]
68
80
69 def __getFft(self):
81 if pulseIndex is None:
82 return volt_buffer
83
84 codes = numpy.conjugate(self.__input_buffer[:,pulseIndex[0]:pulseIndex[1]])/10000
85
86 nsegments = self.dataOut.nHeights - self.dataOut.nProfiles
87
88 for i in range(nsegments):
89 volt_buffer[:,:,i] = volt_buffer[:,:,i]*codes
90
91 return volt_buffer
92
93 def __getFft(self, datablock):
70 """
94 """
71 Convierte valores de Voltaje a Spectra
95 Convierte valores de Voltaje a Spectra
72
96
@@ -76,25 +100,13 class SpectraLagsProc(ProcessingUnit):
76 self.dataOut.data_dc
100 self.dataOut.data_dc
77 self.dataOut.heightList
101 self.dataOut.heightList
78 self.profIndex
102 self.profIndex
79 self.buffer
103 self.__input_buffer
80 self.dataOut.flagNoData
104 self.dataOut.flagNoData
81 """
105 """
82 nsegments = self.dataOut.nHeights
83
106
84 _fft_buffer = numpy.zeros((self.dataOut.nChannels, self.dataOut.nProfiles, nsegments), dtype='complex')
107 fft_volt = numpy.fft.fft(datablock, n=self.dataOut.nFFTPoints, axis=1)
85
108
86 for i in range(nsegments):
109 # dc = fft_volt[:,0,:]
87 try:
88 _fft_buffer[:,:,i] = self.buffer[:,i:i+self.dataOut.nProfiles]
89
90 if self.code is not None:
91 _fft_buffer[:,:,i] = _fft_buffer[:,:,i]*self.code[0]
92 except:
93 pass
94
95 fft_volt = numpy.fft.fft(_fft_buffer, n=self.dataOut.nFFTPoints, axis=1)
96 fft_volt = fft_volt.astype(numpy.dtype('complex'))
97 dc = fft_volt[:,0,:]
98
110
99 #calculo de self-spectra
111 #calculo de self-spectra
100 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
112 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
@@ -102,7 +114,7 class SpectraLagsProc(ProcessingUnit):
102 spc = spc.real
114 spc = spc.real
103
115
104 blocksize = 0
116 blocksize = 0
105 blocksize += dc.size
117 # blocksize += dc.size
106 blocksize += spc.size
118 blocksize += spc.size
107
119
108 cspc = None
120 cspc = None
@@ -126,19 +138,23 class SpectraLagsProc(ProcessingUnit):
126
138
127 self.dataOut.data_spc = spc
139 self.dataOut.data_spc = spc
128 self.dataOut.data_cspc = cspc
140 self.dataOut.data_cspc = cspc
129 self.dataOut.data_dc = dc
141 # self.dataOut.data_dc = dc
130 self.dataOut.blockSize = blocksize
142 self.dataOut.blockSize = blocksize
131 self.dataOut.flagShiftFFT = True
143 self.dataOut.flagShiftFFT = True
132
144
133 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], code=None, nCode=1, nBaud=1):
145 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], code=None, nCode=None, nBaud=None, codeFromHeader=False, pulseIndex=None):
134
146
135 self.dataOut.flagNoData = True
147 self.dataOut.flagNoData = True
136
148
149 self.code = None
150
151 if codeFromHeader:
152 if self.dataIn.code is not None:
153 self.code = self.dataIn.code
154
137 if code is not None:
155 if code is not None:
138 self.code = numpy.array(code).reshape(nCode,nBaud)
156 self.code = numpy.array(code).reshape(nCode,nBaud)
139 else:
157
140 self.code = None
141
142 if self.dataIn.type == "Voltage":
158 if self.dataIn.type == "Voltage":
143
159
144 if nFFTPoints == None:
160 if nFFTPoints == None:
@@ -146,35 +162,28 class SpectraLagsProc(ProcessingUnit):
146
162
147 if nProfiles == None:
163 if nProfiles == None:
148 nProfiles = nFFTPoints
164 nProfiles = nFFTPoints
149
150 self.dataOut.ippFactor = 1
151
165
166 self.profIndex == nProfiles
167 self.firstdatatime = self.dataIn.utctime
168
169 self.dataOut.ippFactor = 1
152 self.dataOut.nFFTPoints = nFFTPoints
170 self.dataOut.nFFTPoints = nFFTPoints
153 self.dataOut.nProfiles = nProfiles
171 self.dataOut.nProfiles = nProfiles
154 self.dataOut.pairsList = pairsList
172 self.dataOut.pairsList = pairsList
155
156 # if self.buffer is None:
157 # self.buffer = numpy.zeros( (self.dataIn.nChannels, nProfiles, self.dataIn.nHeights),
158 # dtype='complex')
159
160 if not self.dataIn.flagDataAsBlock:
161 self.buffer = self.dataIn.data.copy()
162
163 # for i in range(self.dataIn.nHeights):
164 # self.buffer[:, self.profIndex, self.profIndex:] = voltage_data[:,:self.dataIn.nHeights - self.profIndex]
165 #
166 # self.profIndex += 1
167
173
168 else:
174 self.__updateSpecFromVoltage()
169 raise ValueError, ""
170
175
171 self.firstdatatime = self.dataIn.utctime
176 if not self.dataIn.flagDataAsBlock:
177 self.__input_buffer = self.dataIn.data.copy()
178
179 lags_block = self.__createLagsBlock(self.__input_buffer)
172
180
173 self.profIndex == nProfiles
181 lags_block = self.__decodeData(lags_block, pulseIndex)
174
182
175 self.__updateSpecFromVoltage()
183 else:
184 self.__input_buffer = self.dataIn.data.copy()
176
185
177 self.__getFft()
186 self.__getFft(lags_block)
178
187
179 self.dataOut.flagNoData = False
188 self.dataOut.flagNoData = False
180
189
@@ -727,184 +736,4 class SpectraLagsProc(ProcessingUnit):
727
736
728 self.dataOut.noise_estimation = noise.copy()
737 self.dataOut.noise_estimation = noise.copy()
729
738
730 return 1
739 return 1 No newline at end of file
731
732 class IncohIntLags(Operation):
733
734
735 __profIndex = 0
736 __withOverapping = False
737
738 __byTime = False
739 __initime = None
740 __lastdatatime = None
741 __integrationtime = None
742
743 __buffer_spc = None
744 __buffer_cspc = None
745 __buffer_dc = None
746
747 __dataReady = False
748
749 __timeInterval = None
750
751 n = None
752
753
754
755 def __init__(self):
756
757 Operation.__init__(self)
758 # self.isConfig = False
759
760 def setup(self, n=None, timeInterval=None, overlapping=False):
761 """
762 Set the parameters of the integration class.
763
764 Inputs:
765
766 n : Number of coherent integrations
767 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
768 overlapping :
769
770 """
771
772 self.__initime = None
773 self.__lastdatatime = 0
774
775 self.__buffer_spc = 0
776 self.__buffer_cspc = 0
777 self.__buffer_dc = 0
778
779 self.__profIndex = 0
780 self.__dataReady = False
781 self.__byTime = False
782
783 if n is None and timeInterval is None:
784 raise ValueError, "n or timeInterval should be specified ..."
785
786 if n is not None:
787 self.n = int(n)
788 else:
789 self.__integrationtime = int(timeInterval) #if (type(timeInterval)!=integer) -> change this line
790 self.n = None
791 self.__byTime = True
792
793 def putData(self, data_spc, data_cspc, data_dc):
794
795 """
796 Add a profile to the __buffer_spc and increase in one the __profileIndex
797
798 """
799
800 self.__buffer_spc += data_spc
801
802 if data_cspc is None:
803 self.__buffer_cspc = None
804 else:
805 self.__buffer_cspc += data_cspc
806
807 if data_dc is None:
808 self.__buffer_dc = None
809 else:
810 self.__buffer_dc += data_dc
811
812 self.__profIndex += 1
813
814 return
815
816 def pushData(self):
817 """
818 Return the sum of the last profiles and the profiles used in the sum.
819
820 Affected:
821
822 self.__profileIndex
823
824 """
825
826 data_spc = self.__buffer_spc
827 data_cspc = self.__buffer_cspc
828 data_dc = self.__buffer_dc
829 n = self.__profIndex
830
831 self.__buffer_spc = 0
832 self.__buffer_cspc = 0
833 self.__buffer_dc = 0
834 self.__profIndex = 0
835
836 return data_spc, data_cspc, data_dc, n
837
838 def byProfiles(self, *args):
839
840 self.__dataReady = False
841 avgdata_spc = None
842 avgdata_cspc = None
843 avgdata_dc = None
844
845 self.putData(*args)
846
847 if self.__profIndex == self.n:
848
849 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
850 self.n = n
851 self.__dataReady = True
852
853 return avgdata_spc, avgdata_cspc, avgdata_dc
854
855 def byTime(self, datatime, *args):
856
857 self.__dataReady = False
858 avgdata_spc = None
859 avgdata_cspc = None
860 avgdata_dc = None
861
862 self.putData(*args)
863
864 if (datatime - self.__initime) >= self.__integrationtime:
865 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
866 self.n = n
867 self.__dataReady = True
868
869 return avgdata_spc, avgdata_cspc, avgdata_dc
870
871 def integrate(self, datatime, *args):
872
873 if self.__profIndex == 0:
874 self.__initime = datatime
875
876 if self.__byTime:
877 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
878 else:
879 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
880
881 if not self.__dataReady:
882 return None, None, None, None
883
884 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
885
886 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
887
888 if n==1:
889 return
890
891 dataOut.flagNoData = True
892
893 if not self.isConfig:
894 self.setup(n, timeInterval, overlapping)
895 self.isConfig = True
896
897 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
898 dataOut.data_spc,
899 dataOut.data_cspc,
900 dataOut.data_dc)
901
902 if self.__dataReady:
903
904 dataOut.data_spc = avgdata_spc
905 dataOut.data_cspc = avgdata_cspc
906 dataOut.data_dc = avgdata_dc
907
908 dataOut.nIncohInt *= self.n
909 dataOut.utctime = avgdatatime
910 dataOut.flagNoData = False
General Comments 0
You need to be logged in to leave comments. Login now