@@ -1,1060 +1,1060 | |||||
1 | import itertools |
|
1 | import itertools | |
2 |
|
2 | |||
3 | import numpy |
|
3 | import numpy | |
4 |
|
4 | |||
5 | from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation |
|
5 | from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, 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 | from schainpy.utils import log |
|
8 | from schainpy.utils import log | |
9 |
|
9 | |||
10 | @MPDecorator |
|
10 | @MPDecorator | |
11 | class SpectraProc(ProcessingUnit): |
|
11 | class SpectraProc(ProcessingUnit): | |
12 |
|
12 | |||
13 |
|
13 | |||
14 | def __init__(self): |
|
14 | def __init__(self): | |
15 |
|
15 | |||
16 | ProcessingUnit.__init__(self) |
|
16 | ProcessingUnit.__init__(self) | |
17 |
|
17 | |||
18 | self.buffer = None |
|
18 | self.buffer = None | |
19 | self.firstdatatime = None |
|
19 | self.firstdatatime = None | |
20 | self.profIndex = 0 |
|
20 | self.profIndex = 0 | |
21 | self.dataOut = Spectra() |
|
21 | self.dataOut = Spectra() | |
22 | self.id_min = None |
|
22 | self.id_min = None | |
23 | self.id_max = None |
|
23 | self.id_max = None | |
24 | self.setupReq = False #Agregar a todas las unidades de proc |
|
24 | self.setupReq = False #Agregar a todas las unidades de proc | |
25 |
|
25 | |||
26 | def __updateSpecFromVoltage(self): |
|
26 | def __updateSpecFromVoltage(self): | |
27 |
|
27 | |||
28 | self.dataOut.timeZone = self.dataIn.timeZone |
|
28 | self.dataOut.timeZone = self.dataIn.timeZone | |
29 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
29 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
30 | self.dataOut.errorCount = self.dataIn.errorCount |
|
30 | self.dataOut.errorCount = self.dataIn.errorCount | |
31 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
31 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
32 | try: |
|
32 | try: | |
33 | self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy() |
|
33 | self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy() | |
34 | except: |
|
34 | except: | |
35 | pass |
|
35 | pass | |
36 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
36 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
37 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
37 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
38 | self.dataOut.channelList = self.dataIn.channelList |
|
38 | self.dataOut.channelList = self.dataIn.channelList | |
39 | self.dataOut.heightList = self.dataIn.heightList |
|
39 | self.dataOut.heightList = self.dataIn.heightList | |
40 | self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
40 | self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
41 |
|
41 | |||
42 | self.dataOut.nBaud = self.dataIn.nBaud |
|
42 | self.dataOut.nBaud = self.dataIn.nBaud | |
43 | self.dataOut.nCode = self.dataIn.nCode |
|
43 | self.dataOut.nCode = self.dataIn.nCode | |
44 | self.dataOut.code = self.dataIn.code |
|
44 | self.dataOut.code = self.dataIn.code | |
45 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
45 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
46 |
|
46 | |||
47 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock |
|
47 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock | |
48 | self.dataOut.utctime = self.firstdatatime |
|
48 | self.dataOut.utctime = self.firstdatatime | |
49 | # asumo q la data esta decodificada |
|
49 | # asumo q la data esta decodificada | |
50 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData |
|
50 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData | |
51 | # asumo q la data esta sin flip |
|
51 | # asumo q la data esta sin flip | |
52 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData |
|
52 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData | |
53 | self.dataOut.flagShiftFFT = False |
|
53 | self.dataOut.flagShiftFFT = False | |
54 |
|
54 | |||
55 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
55 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
56 | self.dataOut.nIncohInt = 1 |
|
56 | self.dataOut.nIncohInt = 1 | |
57 |
|
57 | |||
58 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
58 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
59 |
|
59 | |||
60 | self.dataOut.frequency = self.dataIn.frequency |
|
60 | self.dataOut.frequency = self.dataIn.frequency | |
61 | self.dataOut.realtime = self.dataIn.realtime |
|
61 | self.dataOut.realtime = self.dataIn.realtime | |
62 |
|
62 | |||
63 | self.dataOut.azimuth = self.dataIn.azimuth |
|
63 | self.dataOut.azimuth = self.dataIn.azimuth | |
64 | self.dataOut.zenith = self.dataIn.zenith |
|
64 | self.dataOut.zenith = self.dataIn.zenith | |
65 |
|
65 | |||
66 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
66 | self.dataOut.beam.codeList = self.dataIn.beam.codeList | |
67 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
67 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList | |
68 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
68 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList | |
69 |
|
69 | |||
70 | def __getFft(self): |
|
70 | def __getFft(self): | |
71 | """ |
|
71 | """ | |
72 | Convierte valores de Voltaje a Spectra |
|
72 | Convierte valores de Voltaje a Spectra | |
73 |
|
73 | |||
74 | Affected: |
|
74 | Affected: | |
75 | self.dataOut.data_spc |
|
75 | self.dataOut.data_spc | |
76 | self.dataOut.data_cspc |
|
76 | self.dataOut.data_cspc | |
77 | self.dataOut.data_dc |
|
77 | self.dataOut.data_dc | |
78 | self.dataOut.heightList |
|
78 | self.dataOut.heightList | |
79 | self.profIndex |
|
79 | self.profIndex | |
80 | self.buffer |
|
80 | self.buffer | |
81 | self.dataOut.flagNoData |
|
81 | self.dataOut.flagNoData | |
82 | """ |
|
82 | """ | |
83 | fft_volt = numpy.fft.fft( |
|
83 | fft_volt = numpy.fft.fft( | |
84 | self.buffer, n=self.dataOut.nFFTPoints, axis=1) |
|
84 | self.buffer, n=self.dataOut.nFFTPoints, axis=1) | |
85 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
85 | fft_volt = fft_volt.astype(numpy.dtype('complex')) | |
86 | dc = fft_volt[:, 0, :] |
|
86 | dc = fft_volt[:, 0, :] | |
87 |
|
87 | |||
88 | # calculo de self-spectra |
|
88 | # calculo de self-spectra | |
89 | fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) |
|
89 | fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,)) | |
90 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
90 | spc = fft_volt * numpy.conjugate(fft_volt) | |
91 | spc = spc.real |
|
91 | spc = spc.real | |
92 |
|
92 | |||
93 | blocksize = 0 |
|
93 | blocksize = 0 | |
94 | blocksize += dc.size |
|
94 | blocksize += dc.size | |
95 | blocksize += spc.size |
|
95 | blocksize += spc.size | |
96 |
|
96 | |||
97 | cspc = None |
|
97 | cspc = None | |
98 | pairIndex = 0 |
|
98 | pairIndex = 0 | |
99 | if self.dataOut.pairsList != None: |
|
99 | if self.dataOut.pairsList != None: | |
100 | # calculo de cross-spectra |
|
100 | # calculo de cross-spectra | |
101 | cspc = numpy.zeros( |
|
101 | cspc = numpy.zeros( | |
102 | (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
102 | (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
103 | for pair in self.dataOut.pairsList: |
|
103 | for pair in self.dataOut.pairsList: | |
104 | if pair[0] not in self.dataOut.channelList: |
|
104 | if pair[0] not in self.dataOut.channelList: | |
105 | raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % ( |
|
105 | raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % ( | |
106 | str(pair), str(self.dataOut.channelList))) |
|
106 | str(pair), str(self.dataOut.channelList))) | |
107 | if pair[1] not in self.dataOut.channelList: |
|
107 | if pair[1] not in self.dataOut.channelList: | |
108 | raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % ( |
|
108 | raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % ( | |
109 | str(pair), str(self.dataOut.channelList))) |
|
109 | str(pair), str(self.dataOut.channelList))) | |
110 |
|
110 | |||
111 | cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \ |
|
111 | cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \ | |
112 | numpy.conjugate(fft_volt[pair[1], :, :]) |
|
112 | numpy.conjugate(fft_volt[pair[1], :, :]) | |
113 | pairIndex += 1 |
|
113 | pairIndex += 1 | |
114 | blocksize += cspc.size |
|
114 | blocksize += cspc.size | |
115 |
|
115 | |||
116 | self.dataOut.data_spc = spc |
|
116 | self.dataOut.data_spc = spc | |
117 | self.dataOut.data_cspc = cspc |
|
117 | self.dataOut.data_cspc = cspc | |
118 | self.dataOut.data_dc = dc |
|
118 | self.dataOut.data_dc = dc | |
119 | self.dataOut.blockSize = blocksize |
|
119 | self.dataOut.blockSize = blocksize | |
120 | self.dataOut.flagShiftFFT = True |
|
120 | self.dataOut.flagShiftFFT = True | |
121 |
|
121 | |||
122 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None, shift_fft=False): |
|
122 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None, shift_fft=False): | |
123 |
|
123 | |||
124 | if self.dataIn.type == "Spectra": |
|
124 | if self.dataIn.type == "Spectra": | |
125 | self.dataOut.copy(self.dataIn) |
|
125 | self.dataOut.copy(self.dataIn) | |
126 | if shift_fft: |
|
126 | if shift_fft: | |
127 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
127 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
128 | shift = int(self.dataOut.nFFTPoints/2) |
|
128 | shift = int(self.dataOut.nFFTPoints/2) | |
129 | self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1) |
|
129 | self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1) | |
130 |
|
130 | |||
131 | if self.dataOut.data_cspc is not None: |
|
131 | if self.dataOut.data_cspc is not None: | |
132 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
132 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
133 | self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1) |
|
133 | self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1) | |
134 |
|
134 | |||
135 | return True |
|
135 | return True | |
136 |
|
136 | |||
137 | if self.dataIn.type == "Voltage": |
|
137 | if self.dataIn.type == "Voltage": | |
138 |
|
138 | |||
139 | self.dataOut.flagNoData = True |
|
139 | self.dataOut.flagNoData = True | |
140 |
|
140 | |||
141 | if nFFTPoints == None: |
|
141 | if nFFTPoints == None: | |
142 | raise ValueError("This SpectraProc.run() need nFFTPoints input variable") |
|
142 | raise ValueError("This SpectraProc.run() need nFFTPoints input variable") | |
143 |
|
143 | |||
144 | if nProfiles == None: |
|
144 | if nProfiles == None: | |
145 | nProfiles = nFFTPoints |
|
145 | nProfiles = nFFTPoints | |
146 |
|
146 | |||
147 | if ippFactor == None: |
|
147 | if ippFactor == None: | |
148 | ippFactor = 1 |
|
148 | ippFactor = 1 | |
149 |
|
149 | |||
150 | self.dataOut.ippFactor = ippFactor |
|
150 | self.dataOut.ippFactor = ippFactor | |
151 |
|
151 | |||
152 | self.dataOut.nFFTPoints = nFFTPoints |
|
152 | self.dataOut.nFFTPoints = nFFTPoints | |
153 | self.dataOut.pairsList = pairsList |
|
153 | self.dataOut.pairsList = pairsList | |
154 |
|
154 | |||
155 | if self.buffer is None: |
|
155 | if self.buffer is None: | |
156 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
156 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
157 | nProfiles, |
|
157 | nProfiles, | |
158 | self.dataIn.nHeights), |
|
158 | self.dataIn.nHeights), | |
159 | dtype='complex') |
|
159 | dtype='complex') | |
160 |
|
160 | |||
161 | if self.dataIn.flagDataAsBlock: |
|
161 | if self.dataIn.flagDataAsBlock: | |
162 | nVoltProfiles = self.dataIn.data.shape[1] |
|
162 | nVoltProfiles = self.dataIn.data.shape[1] | |
163 |
|
163 | |||
164 | if nVoltProfiles == nProfiles: |
|
164 | if nVoltProfiles == nProfiles: | |
165 | self.buffer = self.dataIn.data.copy() |
|
165 | self.buffer = self.dataIn.data.copy() | |
166 | self.profIndex = nVoltProfiles |
|
166 | self.profIndex = nVoltProfiles | |
167 |
|
167 | |||
168 | elif nVoltProfiles < nProfiles: |
|
168 | elif nVoltProfiles < nProfiles: | |
169 |
|
169 | |||
170 | if self.profIndex == 0: |
|
170 | if self.profIndex == 0: | |
171 | self.id_min = 0 |
|
171 | self.id_min = 0 | |
172 | self.id_max = nVoltProfiles |
|
172 | self.id_max = nVoltProfiles | |
173 |
|
173 | |||
174 | self.buffer[:, self.id_min:self.id_max, |
|
174 | self.buffer[:, self.id_min:self.id_max, | |
175 | :] = self.dataIn.data |
|
175 | :] = self.dataIn.data | |
176 | self.profIndex += nVoltProfiles |
|
176 | self.profIndex += nVoltProfiles | |
177 | self.id_min += nVoltProfiles |
|
177 | self.id_min += nVoltProfiles | |
178 | self.id_max += nVoltProfiles |
|
178 | self.id_max += nVoltProfiles | |
179 | else: |
|
179 | else: | |
180 | raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % ( |
|
180 | raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % ( | |
181 | self.dataIn.type, self.dataIn.data.shape[1], nProfiles)) |
|
181 | self.dataIn.type, self.dataIn.data.shape[1], nProfiles)) | |
182 | self.dataOut.flagNoData = True |
|
182 | self.dataOut.flagNoData = True | |
183 | return 0 |
|
183 | return 0 | |
184 | else: |
|
184 | else: | |
185 | self.buffer[:, self.profIndex, :] = self.dataIn.data.copy() |
|
185 | self.buffer[:, self.profIndex, :] = self.dataIn.data.copy() | |
186 | self.profIndex += 1 |
|
186 | self.profIndex += 1 | |
187 |
|
187 | |||
188 | if self.firstdatatime == None: |
|
188 | if self.firstdatatime == None: | |
189 | self.firstdatatime = self.dataIn.utctime |
|
189 | self.firstdatatime = self.dataIn.utctime | |
190 |
|
190 | |||
191 | if self.profIndex == nProfiles: |
|
191 | if self.profIndex == nProfiles: | |
192 | self.__updateSpecFromVoltage() |
|
192 | self.__updateSpecFromVoltage() | |
193 | self.__getFft() |
|
193 | self.__getFft() | |
194 |
|
194 | |||
195 | self.dataOut.flagNoData = False |
|
195 | self.dataOut.flagNoData = False | |
196 | self.firstdatatime = None |
|
196 | self.firstdatatime = None | |
197 | self.profIndex = 0 |
|
197 | self.profIndex = 0 | |
198 |
|
198 | |||
199 | return True |
|
199 | return True | |
200 |
|
200 | |||
201 | raise ValueError("The type of input object '%s' is not valid" % ( |
|
201 | raise ValueError("The type of input object '%s' is not valid" % ( | |
202 | self.dataIn.type)) |
|
202 | self.dataIn.type)) | |
203 |
|
203 | |||
204 | def __selectPairs(self, pairsList): |
|
204 | def __selectPairs(self, pairsList): | |
205 |
|
205 | |||
206 | if not pairsList: |
|
206 | if not pairsList: | |
207 | return |
|
207 | return | |
208 |
|
208 | |||
209 | pairs = [] |
|
209 | pairs = [] | |
210 | pairsIndex = [] |
|
210 | pairsIndex = [] | |
211 |
|
211 | |||
212 | for pair in pairsList: |
|
212 | for pair in pairsList: | |
213 | if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList: |
|
213 | if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList: | |
214 | continue |
|
214 | continue | |
215 | pairs.append(pair) |
|
215 | pairs.append(pair) | |
216 | pairsIndex.append(pairs.index(pair)) |
|
216 | pairsIndex.append(pairs.index(pair)) | |
217 |
|
217 | |||
218 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex] |
|
218 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex] | |
219 | self.dataOut.pairsList = pairs |
|
219 | self.dataOut.pairsList = pairs | |
220 |
|
220 | |||
221 | return |
|
221 | return | |
222 |
|
222 | |||
223 | def __selectPairsByChannel(self, channelList=None): |
|
223 | def __selectPairsByChannel(self, channelList=None): | |
224 |
|
224 | |||
225 | if channelList == None: |
|
225 | if channelList == None: | |
226 | return |
|
226 | return | |
227 |
|
227 | |||
228 | pairsIndexListSelected = [] |
|
228 | pairsIndexListSelected = [] | |
229 | for pairIndex in self.dataOut.pairsIndexList: |
|
229 | for pairIndex in self.dataOut.pairsIndexList: | |
230 | # First pair |
|
230 | # First pair | |
231 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
231 | if self.dataOut.pairsList[pairIndex][0] not in channelList: | |
232 | continue |
|
232 | continue | |
233 | # Second pair |
|
233 | # Second pair | |
234 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
234 | if self.dataOut.pairsList[pairIndex][1] not in channelList: | |
235 | continue |
|
235 | continue | |
236 |
|
236 | |||
237 | pairsIndexListSelected.append(pairIndex) |
|
237 | pairsIndexListSelected.append(pairIndex) | |
238 |
|
238 | |||
239 | if not pairsIndexListSelected: |
|
239 | if not pairsIndexListSelected: | |
240 | self.dataOut.data_cspc = None |
|
240 | self.dataOut.data_cspc = None | |
241 | self.dataOut.pairsList = [] |
|
241 | self.dataOut.pairsList = [] | |
242 | return |
|
242 | return | |
243 |
|
243 | |||
244 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
244 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] | |
245 | self.dataOut.pairsList = [self.dataOut.pairsList[i] |
|
245 | self.dataOut.pairsList = [self.dataOut.pairsList[i] | |
246 | for i in pairsIndexListSelected] |
|
246 | for i in pairsIndexListSelected] | |
247 |
|
247 | |||
248 | return |
|
248 | return | |
249 |
|
249 | |||
250 | def selectChannels(self, channelList): |
|
250 | def selectChannels(self, channelList): | |
251 |
|
251 | |||
252 | channelIndexList = [] |
|
252 | channelIndexList = [] | |
253 |
|
253 | |||
254 | for channel in channelList: |
|
254 | for channel in channelList: | |
255 | if channel not in self.dataOut.channelList: |
|
255 | if channel not in self.dataOut.channelList: | |
256 | raise ValueError("Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" % ( |
|
256 | raise ValueError("Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" % ( | |
257 | channel, str(self.dataOut.channelList))) |
|
257 | channel, str(self.dataOut.channelList))) | |
258 |
|
258 | |||
259 | index = self.dataOut.channelList.index(channel) |
|
259 | index = self.dataOut.channelList.index(channel) | |
260 | channelIndexList.append(index) |
|
260 | channelIndexList.append(index) | |
261 |
|
261 | |||
262 | self.selectChannelsByIndex(channelIndexList) |
|
262 | self.selectChannelsByIndex(channelIndexList) | |
263 |
|
263 | |||
264 | def selectChannelsByIndex(self, channelIndexList): |
|
264 | def selectChannelsByIndex(self, channelIndexList): | |
265 | """ |
|
265 | """ | |
266 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
266 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
267 |
|
267 | |||
268 | Input: |
|
268 | Input: | |
269 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
269 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
270 |
|
270 | |||
271 | Affected: |
|
271 | Affected: | |
272 | self.dataOut.data_spc |
|
272 | self.dataOut.data_spc | |
273 | self.dataOut.channelIndexList |
|
273 | self.dataOut.channelIndexList | |
274 | self.dataOut.nChannels |
|
274 | self.dataOut.nChannels | |
275 |
|
275 | |||
276 | Return: |
|
276 | Return: | |
277 | None |
|
277 | None | |
278 | """ |
|
278 | """ | |
279 |
|
279 | |||
280 | for channelIndex in channelIndexList: |
|
280 | for channelIndex in channelIndexList: | |
281 | if channelIndex not in self.dataOut.channelIndexList: |
|
281 | if channelIndex not in self.dataOut.channelIndexList: | |
282 | raise ValueError("Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " % ( |
|
282 | raise ValueError("Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " % ( | |
283 | channelIndex, self.dataOut.channelIndexList)) |
|
283 | channelIndex, self.dataOut.channelIndexList)) | |
284 |
|
284 | |||
285 | # nChannels = len(channelIndexList) |
|
285 | # nChannels = len(channelIndexList) | |
286 |
|
286 | |||
287 | data_spc = self.dataOut.data_spc[channelIndexList, :] |
|
287 | data_spc = self.dataOut.data_spc[channelIndexList, :] | |
288 | data_dc = self.dataOut.data_dc[channelIndexList, :] |
|
288 | data_dc = self.dataOut.data_dc[channelIndexList, :] | |
289 |
|
289 | |||
290 | self.dataOut.data_spc = data_spc |
|
290 | self.dataOut.data_spc = data_spc | |
291 | self.dataOut.data_dc = data_dc |
|
291 | self.dataOut.data_dc = data_dc | |
292 |
|
292 | |||
293 | self.dataOut.channelList = [ |
|
293 | self.dataOut.channelList = [ | |
294 | self.dataOut.channelList[i] for i in channelIndexList] |
|
294 | self.dataOut.channelList[i] for i in channelIndexList] | |
295 | # self.dataOut.nChannels = nChannels |
|
295 | # self.dataOut.nChannels = nChannels | |
296 |
|
296 | |||
297 | self.__selectPairsByChannel(self.dataOut.channelList) |
|
297 | self.__selectPairsByChannel(self.dataOut.channelList) | |
298 |
|
298 | |||
299 | return 1 |
|
299 | return 1 | |
300 |
|
300 | |||
301 |
|
301 | |||
302 | def selectFFTs(self, minFFT, maxFFT ): |
|
302 | def selectFFTs(self, minFFT, maxFFT ): | |
303 | """ |
|
303 | """ | |
304 | Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango |
|
304 | Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango | |
305 | minFFT<= FFT <= maxFFT |
|
305 | minFFT<= FFT <= maxFFT | |
306 | """ |
|
306 | """ | |
307 |
|
307 | |||
308 | if (minFFT > maxFFT): |
|
308 | if (minFFT > maxFFT): | |
309 | raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT)) |
|
309 | raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT)) | |
310 |
|
310 | |||
311 | if (minFFT < self.dataOut.getFreqRange()[0]): |
|
311 | if (minFFT < self.dataOut.getFreqRange()[0]): | |
312 | minFFT = self.dataOut.getFreqRange()[0] |
|
312 | minFFT = self.dataOut.getFreqRange()[0] | |
313 |
|
313 | |||
314 | if (maxFFT > self.dataOut.getFreqRange()[-1]): |
|
314 | if (maxFFT > self.dataOut.getFreqRange()[-1]): | |
315 | maxFFT = self.dataOut.getFreqRange()[-1] |
|
315 | maxFFT = self.dataOut.getFreqRange()[-1] | |
316 |
|
316 | |||
317 | minIndex = 0 |
|
317 | minIndex = 0 | |
318 | maxIndex = 0 |
|
318 | maxIndex = 0 | |
319 | FFTs = self.dataOut.getFreqRange() |
|
319 | FFTs = self.dataOut.getFreqRange() | |
320 |
|
320 | |||
321 | inda = numpy.where(FFTs >= minFFT) |
|
321 | inda = numpy.where(FFTs >= minFFT) | |
322 | indb = numpy.where(FFTs <= maxFFT) |
|
322 | indb = numpy.where(FFTs <= maxFFT) | |
323 |
|
323 | |||
324 | try: |
|
324 | try: | |
325 | minIndex = inda[0][0] |
|
325 | minIndex = inda[0][0] | |
326 | except: |
|
326 | except: | |
327 | minIndex = 0 |
|
327 | minIndex = 0 | |
328 |
|
328 | |||
329 | try: |
|
329 | try: | |
330 | maxIndex = indb[0][-1] |
|
330 | maxIndex = indb[0][-1] | |
331 | except: |
|
331 | except: | |
332 | maxIndex = len(FFTs) |
|
332 | maxIndex = len(FFTs) | |
333 |
|
333 | |||
334 | self.selectFFTsByIndex(minIndex, maxIndex) |
|
334 | self.selectFFTsByIndex(minIndex, maxIndex) | |
335 |
|
335 | |||
336 | return 1 |
|
336 | return 1 | |
337 |
|
337 | |||
338 |
|
338 | |||
339 | def setH0(self, h0, deltaHeight = None): |
|
339 | def setH0(self, h0, deltaHeight = None): | |
340 |
|
340 | |||
341 | if not deltaHeight: |
|
341 | if not deltaHeight: | |
342 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
342 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
343 |
|
343 | |||
344 | nHeights = self.dataOut.nHeights |
|
344 | nHeights = self.dataOut.nHeights | |
345 |
|
345 | |||
346 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight |
|
346 | newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight | |
347 |
|
347 | |||
348 | self.dataOut.heightList = newHeiRange |
|
348 | self.dataOut.heightList = newHeiRange | |
349 |
|
349 | |||
350 |
|
350 | |||
351 | def selectHeights(self, minHei, maxHei): |
|
351 | def selectHeights(self, minHei, maxHei): | |
352 | """ |
|
352 | """ | |
353 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
353 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
354 | minHei <= height <= maxHei |
|
354 | minHei <= height <= maxHei | |
355 |
|
355 | |||
356 | Input: |
|
356 | Input: | |
357 | minHei : valor minimo de altura a considerar |
|
357 | minHei : valor minimo de altura a considerar | |
358 | maxHei : valor maximo de altura a considerar |
|
358 | maxHei : valor maximo de altura a considerar | |
359 |
|
359 | |||
360 | Affected: |
|
360 | Affected: | |
361 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
361 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
362 |
|
362 | |||
363 | Return: |
|
363 | Return: | |
364 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
364 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
365 | """ |
|
365 | """ | |
366 |
|
366 | |||
367 |
|
367 | |||
368 | if (minHei > maxHei): |
|
368 | if (minHei > maxHei): | |
369 | raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)) |
|
369 | raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)) | |
370 |
|
370 | |||
371 | if (minHei < self.dataOut.heightList[0]): |
|
371 | if (minHei < self.dataOut.heightList[0]): | |
372 | minHei = self.dataOut.heightList[0] |
|
372 | minHei = self.dataOut.heightList[0] | |
373 |
|
373 | |||
374 | if (maxHei > self.dataOut.heightList[-1]): |
|
374 | if (maxHei > self.dataOut.heightList[-1]): | |
375 | maxHei = self.dataOut.heightList[-1] |
|
375 | maxHei = self.dataOut.heightList[-1] | |
376 |
|
376 | |||
377 | minIndex = 0 |
|
377 | minIndex = 0 | |
378 | maxIndex = 0 |
|
378 | maxIndex = 0 | |
379 | heights = self.dataOut.heightList |
|
379 | heights = self.dataOut.heightList | |
380 |
|
380 | |||
381 | inda = numpy.where(heights >= minHei) |
|
381 | inda = numpy.where(heights >= minHei) | |
382 | indb = numpy.where(heights <= maxHei) |
|
382 | indb = numpy.where(heights <= maxHei) | |
383 |
|
383 | |||
384 | try: |
|
384 | try: | |
385 | minIndex = inda[0][0] |
|
385 | minIndex = inda[0][0] | |
386 | except: |
|
386 | except: | |
387 | minIndex = 0 |
|
387 | minIndex = 0 | |
388 |
|
388 | |||
389 | try: |
|
389 | try: | |
390 | maxIndex = indb[0][-1] |
|
390 | maxIndex = indb[0][-1] | |
391 | except: |
|
391 | except: | |
392 | maxIndex = len(heights) |
|
392 | maxIndex = len(heights) | |
393 |
|
393 | |||
394 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
394 | self.selectHeightsByIndex(minIndex, maxIndex) | |
395 |
|
395 | |||
396 |
|
396 | |||
397 | return 1 |
|
397 | return 1 | |
398 |
|
398 | |||
399 | def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None): |
|
399 | def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None): | |
400 | newheis = numpy.where( |
|
400 | newheis = numpy.where( | |
401 | self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
401 | self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
402 |
|
402 | |||
403 | if hei_ref != None: |
|
403 | if hei_ref != None: | |
404 | newheis = numpy.where(self.dataOut.heightList > hei_ref) |
|
404 | newheis = numpy.where(self.dataOut.heightList > hei_ref) | |
405 |
|
405 | |||
406 | minIndex = min(newheis[0]) |
|
406 | minIndex = min(newheis[0]) | |
407 | maxIndex = max(newheis[0]) |
|
407 | maxIndex = max(newheis[0]) | |
408 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
408 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
409 | heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
409 | heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
410 |
|
410 | |||
411 | # determina indices |
|
411 | # determina indices | |
412 | nheis = int(self.dataOut.radarControllerHeaderObj.txB / |
|
412 | nheis = int(self.dataOut.radarControllerHeaderObj.txB / | |
413 | (self.dataOut.heightList[1] - self.dataOut.heightList[0])) |
|
413 | (self.dataOut.heightList[1] - self.dataOut.heightList[0])) | |
414 | avg_dB = 10 * \ |
|
414 | avg_dB = 10 * \ | |
415 | numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0)) |
|
415 | numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0)) | |
416 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
416 | beacon_dB = numpy.sort(avg_dB)[-nheis:] | |
417 | beacon_heiIndexList = [] |
|
417 | beacon_heiIndexList = [] | |
418 | for val in avg_dB.tolist(): |
|
418 | for val in avg_dB.tolist(): | |
419 | if val >= beacon_dB[0]: |
|
419 | if val >= beacon_dB[0]: | |
420 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
420 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) | |
421 |
|
421 | |||
422 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
422 | #data_spc = data_spc[:,:,beacon_heiIndexList] | |
423 | data_cspc = None |
|
423 | data_cspc = None | |
424 | if self.dataOut.data_cspc is not None: |
|
424 | if self.dataOut.data_cspc is not None: | |
425 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
425 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
426 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
426 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] | |
427 |
|
427 | |||
428 | data_dc = None |
|
428 | data_dc = None | |
429 | if self.dataOut.data_dc is not None: |
|
429 | if self.dataOut.data_dc is not None: | |
430 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
430 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
431 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
431 | #data_dc = data_dc[:,beacon_heiIndexList] | |
432 |
|
432 | |||
433 | self.dataOut.data_spc = data_spc |
|
433 | self.dataOut.data_spc = data_spc | |
434 | self.dataOut.data_cspc = data_cspc |
|
434 | self.dataOut.data_cspc = data_cspc | |
435 | self.dataOut.data_dc = data_dc |
|
435 | self.dataOut.data_dc = data_dc | |
436 | self.dataOut.heightList = heightList |
|
436 | self.dataOut.heightList = heightList | |
437 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
437 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList | |
438 |
|
438 | |||
439 | return 1 |
|
439 | return 1 | |
440 |
|
440 | |||
441 | def selectFFTsByIndex(self, minIndex, maxIndex): |
|
441 | def selectFFTsByIndex(self, minIndex, maxIndex): | |
442 | """ |
|
442 | """ | |
443 |
|
443 | |||
444 | """ |
|
444 | """ | |
445 |
|
445 | |||
446 | if (minIndex < 0) or (minIndex > maxIndex): |
|
446 | if (minIndex < 0) or (minIndex > maxIndex): | |
447 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)) |
|
447 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)) | |
448 |
|
448 | |||
449 | if (maxIndex >= self.dataOut.nProfiles): |
|
449 | if (maxIndex >= self.dataOut.nProfiles): | |
450 | maxIndex = self.dataOut.nProfiles-1 |
|
450 | maxIndex = self.dataOut.nProfiles-1 | |
451 |
|
451 | |||
452 | #Spectra |
|
452 | #Spectra | |
453 | data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:] |
|
453 | data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:] | |
454 |
|
454 | |||
455 | data_cspc = None |
|
455 | data_cspc = None | |
456 | if self.dataOut.data_cspc is not None: |
|
456 | if self.dataOut.data_cspc is not None: | |
457 | data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:] |
|
457 | data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:] | |
458 |
|
458 | |||
459 | data_dc = None |
|
459 | data_dc = None | |
460 | if self.dataOut.data_dc is not None: |
|
460 | if self.dataOut.data_dc is not None: | |
461 | data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:] |
|
461 | data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:] | |
462 |
|
462 | |||
463 | self.dataOut.data_spc = data_spc |
|
463 | self.dataOut.data_spc = data_spc | |
464 | self.dataOut.data_cspc = data_cspc |
|
464 | self.dataOut.data_cspc = data_cspc | |
465 | self.dataOut.data_dc = data_dc |
|
465 | self.dataOut.data_dc = data_dc | |
466 |
|
466 | |||
467 | self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1]) |
|
467 | self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1]) | |
468 | self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1] |
|
468 | self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1] | |
469 | self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1] |
|
469 | self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1] | |
470 |
|
470 | |||
471 | return 1 |
|
471 | return 1 | |
472 |
|
472 | |||
473 |
|
473 | |||
474 |
|
474 | |||
475 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
475 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
476 | """ |
|
476 | """ | |
477 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
477 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
478 | minIndex <= index <= maxIndex |
|
478 | minIndex <= index <= maxIndex | |
479 |
|
479 | |||
480 | Input: |
|
480 | Input: | |
481 | minIndex : valor de indice minimo de altura a considerar |
|
481 | minIndex : valor de indice minimo de altura a considerar | |
482 | maxIndex : valor de indice maximo de altura a considerar |
|
482 | maxIndex : valor de indice maximo de altura a considerar | |
483 |
|
483 | |||
484 | Affected: |
|
484 | Affected: | |
485 | self.dataOut.data_spc |
|
485 | self.dataOut.data_spc | |
486 | self.dataOut.data_cspc |
|
486 | self.dataOut.data_cspc | |
487 | self.dataOut.data_dc |
|
487 | self.dataOut.data_dc | |
488 | self.dataOut.heightList |
|
488 | self.dataOut.heightList | |
489 |
|
489 | |||
490 | Return: |
|
490 | Return: | |
491 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
491 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
492 | """ |
|
492 | """ | |
493 |
|
493 | |||
494 | if (minIndex < 0) or (minIndex > maxIndex): |
|
494 | if (minIndex < 0) or (minIndex > maxIndex): | |
495 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( |
|
495 | raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % ( | |
496 | minIndex, maxIndex)) |
|
496 | minIndex, maxIndex)) | |
497 |
|
497 | |||
498 | if (maxIndex >= self.dataOut.nHeights): |
|
498 | if (maxIndex >= self.dataOut.nHeights): | |
499 | maxIndex = self.dataOut.nHeights - 1 |
|
499 | maxIndex = self.dataOut.nHeights - 1 | |
500 |
|
500 | |||
501 | # Spectra |
|
501 | # Spectra | |
502 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] |
|
502 | data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1] | |
503 |
|
503 | |||
504 | data_cspc = None |
|
504 | data_cspc = None | |
505 | if self.dataOut.data_cspc is not None: |
|
505 | if self.dataOut.data_cspc is not None: | |
506 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] |
|
506 | data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1] | |
507 |
|
507 | |||
508 | data_dc = None |
|
508 | data_dc = None | |
509 | if self.dataOut.data_dc is not None: |
|
509 | if self.dataOut.data_dc is not None: | |
510 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] |
|
510 | data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1] | |
511 |
|
511 | |||
512 | self.dataOut.data_spc = data_spc |
|
512 | self.dataOut.data_spc = data_spc | |
513 | self.dataOut.data_cspc = data_cspc |
|
513 | self.dataOut.data_cspc = data_cspc | |
514 | self.dataOut.data_dc = data_dc |
|
514 | self.dataOut.data_dc = data_dc | |
515 |
|
515 | |||
516 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] |
|
516 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1] | |
517 |
|
517 | |||
518 | return 1 |
|
518 | return 1 | |
519 |
|
519 | |||
520 | def removeDC(self, mode=2): |
|
520 | def removeDC(self, mode=2): | |
521 | jspectra = self.dataOut.data_spc |
|
521 | jspectra = self.dataOut.data_spc | |
522 | jcspectra = self.dataOut.data_cspc |
|
522 | jcspectra = self.dataOut.data_cspc | |
523 |
|
523 | |||
524 | num_chan = jspectra.shape[0] |
|
524 | num_chan = jspectra.shape[0] | |
525 | num_hei = jspectra.shape[2] |
|
525 | num_hei = jspectra.shape[2] | |
526 |
|
526 | |||
527 | if jcspectra is not None: |
|
527 | if jcspectra is not None: | |
528 | jcspectraExist = True |
|
528 | jcspectraExist = True | |
529 | num_pairs = jcspectra.shape[0] |
|
529 | num_pairs = jcspectra.shape[0] | |
530 | else: |
|
530 | else: | |
531 | jcspectraExist = False |
|
531 | jcspectraExist = False | |
532 |
|
532 | |||
533 | freq_dc = int(jspectra.shape[1] / 2) |
|
533 | freq_dc = int(jspectra.shape[1] / 2) | |
534 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc |
|
534 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc | |
535 | ind_vel = ind_vel.astype(int) |
|
535 | ind_vel = ind_vel.astype(int) | |
536 |
|
536 | |||
537 | if ind_vel[0] < 0: |
|
537 | if ind_vel[0] < 0: | |
538 | ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof |
|
538 | ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof | |
539 |
|
539 | |||
540 | if mode == 1: |
|
540 | if mode == 1: | |
541 | jspectra[:, freq_dc, :] = ( |
|
541 | jspectra[:, freq_dc, :] = ( | |
542 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION |
|
542 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION | |
543 |
|
543 | |||
544 | if jcspectraExist: |
|
544 | if jcspectraExist: | |
545 | jcspectra[:, freq_dc, :] = ( |
|
545 | jcspectra[:, freq_dc, :] = ( | |
546 | jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2 |
|
546 | jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2 | |
547 |
|
547 | |||
548 | if mode == 2: |
|
548 | if mode == 2: | |
549 |
|
549 | |||
550 | vel = numpy.array([-2, -1, 1, 2]) |
|
550 | vel = numpy.array([-2, -1, 1, 2]) | |
551 | xx = numpy.zeros([4, 4]) |
|
551 | xx = numpy.zeros([4, 4]) | |
552 |
|
552 | |||
553 | for fil in range(4): |
|
553 | for fil in range(4): | |
554 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) |
|
554 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) | |
555 |
|
555 | |||
556 | xx_inv = numpy.linalg.inv(xx) |
|
556 | xx_inv = numpy.linalg.inv(xx) | |
557 | xx_aux = xx_inv[0, :] |
|
557 | xx_aux = xx_inv[0, :] | |
558 |
|
558 | |||
559 | for ich in range(num_chan): |
|
559 | for ich in range(num_chan): | |
560 | yy = jspectra[ich, ind_vel, :] |
|
560 | yy = jspectra[ich, ind_vel, :] | |
561 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
561 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) | |
562 |
|
562 | |||
563 | junkid = jspectra[ich, freq_dc, :] <= 0 |
|
563 | junkid = jspectra[ich, freq_dc, :] <= 0 | |
564 | cjunkid = sum(junkid) |
|
564 | cjunkid = sum(junkid) | |
565 |
|
565 | |||
566 | if cjunkid.any(): |
|
566 | if cjunkid.any(): | |
567 | jspectra[ich, freq_dc, junkid.nonzero()] = ( |
|
567 | jspectra[ich, freq_dc, junkid.nonzero()] = ( | |
568 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 |
|
568 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 | |
569 |
|
569 | |||
570 | if jcspectraExist: |
|
570 | if jcspectraExist: | |
571 | for ip in range(num_pairs): |
|
571 | for ip in range(num_pairs): | |
572 | yy = jcspectra[ip, ind_vel, :] |
|
572 | yy = jcspectra[ip, ind_vel, :] | |
573 | jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
573 | jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy) | |
574 |
|
574 | |||
575 | self.dataOut.data_spc = jspectra |
|
575 | self.dataOut.data_spc = jspectra | |
576 | self.dataOut.data_cspc = jcspectra |
|
576 | self.dataOut.data_cspc = jcspectra | |
577 |
|
577 | |||
578 | return 1 |
|
578 | return 1 | |
579 |
|
579 | |||
580 | def removeInterference2(self): |
|
580 | def removeInterference2(self): | |
581 |
|
581 | |||
582 | cspc = self.dataOut.data_cspc |
|
582 | cspc = self.dataOut.data_cspc | |
583 | spc = self.dataOut.data_spc |
|
583 | spc = self.dataOut.data_spc | |
584 | Heights = numpy.arange(cspc.shape[2]) |
|
584 | Heights = numpy.arange(cspc.shape[2]) | |
585 | realCspc = numpy.abs(cspc) |
|
585 | realCspc = numpy.abs(cspc) | |
586 |
|
586 | |||
587 | for i in range(cspc.shape[0]): |
|
587 | for i in range(cspc.shape[0]): | |
588 | LinePower= numpy.sum(realCspc[i], axis=0) |
|
588 | LinePower= numpy.sum(realCspc[i], axis=0) | |
589 | Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)] |
|
589 | Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)] | |
590 | SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ] |
|
590 | SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ] | |
591 | InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 ) |
|
591 | InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 ) | |
592 | InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)] |
|
592 | InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)] | |
593 | InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)] |
|
593 | InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)] | |
594 |
|
594 | |||
595 |
|
595 | |||
596 | InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) ) |
|
596 | InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) ) | |
597 | #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax])) |
|
597 | #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax])) | |
598 | if len(InterferenceRange)<int(cspc.shape[1]*0.3): |
|
598 | if len(InterferenceRange)<int(cspc.shape[1]*0.3): | |
599 | cspc[i,InterferenceRange,:] = numpy.NaN |
|
599 | cspc[i,InterferenceRange,:] = numpy.NaN | |
600 |
|
600 | |||
601 |
|
601 | |||
602 |
|
602 | |||
603 | self.dataOut.data_cspc = cspc |
|
603 | self.dataOut.data_cspc = cspc | |
604 |
|
604 | |||
605 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
605 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): | |
606 |
|
606 | |||
607 | jspectra = self.dataOut.data_spc |
|
607 | jspectra = self.dataOut.data_spc | |
608 | jcspectra = self.dataOut.data_cspc |
|
608 | jcspectra = self.dataOut.data_cspc | |
609 | jnoise = self.dataOut.getNoise() |
|
609 | jnoise = self.dataOut.getNoise() | |
610 | num_incoh = self.dataOut.nIncohInt |
|
610 | num_incoh = self.dataOut.nIncohInt | |
611 |
|
611 | |||
612 | num_channel = jspectra.shape[0] |
|
612 | num_channel = jspectra.shape[0] | |
613 | num_prof = jspectra.shape[1] |
|
613 | num_prof = jspectra.shape[1] | |
614 | num_hei = jspectra.shape[2] |
|
614 | num_hei = jspectra.shape[2] | |
615 |
|
615 | |||
616 | # hei_interf |
|
616 | # hei_interf | |
617 | if hei_interf is None: |
|
617 | if hei_interf is None: | |
618 | count_hei = int(num_hei / 2) |
|
618 | count_hei = int(num_hei / 2) | |
619 | hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei |
|
619 | hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei | |
620 | hei_interf = numpy.asarray(hei_interf)[0] |
|
620 | hei_interf = numpy.asarray(hei_interf)[0] | |
621 | # nhei_interf |
|
621 | # nhei_interf | |
622 | if (nhei_interf == None): |
|
622 | if (nhei_interf == None): | |
623 | nhei_interf = 5 |
|
623 | nhei_interf = 5 | |
624 | if (nhei_interf < 1): |
|
624 | if (nhei_interf < 1): | |
625 | nhei_interf = 1 |
|
625 | nhei_interf = 1 | |
626 | if (nhei_interf > count_hei): |
|
626 | if (nhei_interf > count_hei): | |
627 | nhei_interf = count_hei |
|
627 | nhei_interf = count_hei | |
628 | if (offhei_interf == None): |
|
628 | if (offhei_interf == None): | |
629 | offhei_interf = 0 |
|
629 | offhei_interf = 0 | |
630 |
|
630 | |||
631 | ind_hei = list(range(num_hei)) |
|
631 | ind_hei = list(range(num_hei)) | |
632 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
632 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 | |
633 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
633 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 | |
634 | mask_prof = numpy.asarray(list(range(num_prof))) |
|
634 | mask_prof = numpy.asarray(list(range(num_prof))) | |
635 | num_mask_prof = mask_prof.size |
|
635 | num_mask_prof = mask_prof.size | |
636 | comp_mask_prof = [0, num_prof / 2] |
|
636 | comp_mask_prof = [0, num_prof / 2] | |
637 |
|
637 | |||
638 | # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
638 | # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal | |
639 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
639 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): | |
640 | jnoise = numpy.nan |
|
640 | jnoise = numpy.nan | |
641 | noise_exist = jnoise[0] < numpy.Inf |
|
641 | noise_exist = jnoise[0] < numpy.Inf | |
642 |
|
642 | |||
643 | # Subrutina de Remocion de la Interferencia |
|
643 | # Subrutina de Remocion de la Interferencia | |
644 | for ich in range(num_channel): |
|
644 | for ich in range(num_channel): | |
645 | # Se ordena los espectros segun su potencia (menor a mayor) |
|
645 | # Se ordena los espectros segun su potencia (menor a mayor) | |
646 | power = jspectra[ich, mask_prof, :] |
|
646 | power = jspectra[ich, mask_prof, :] | |
647 | power = power[:, hei_interf] |
|
647 | power = power[:, hei_interf] | |
648 | power = power.sum(axis=0) |
|
648 | power = power.sum(axis=0) | |
649 | psort = power.ravel().argsort() |
|
649 | psort = power.ravel().argsort() | |
650 |
|
650 | |||
651 | # Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
651 | # Se estima la interferencia promedio en los Espectros de Potencia empleando | |
652 | junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range( |
|
652 | junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range( | |
653 | offhei_interf, nhei_interf + offhei_interf))]]] |
|
653 | offhei_interf, nhei_interf + offhei_interf))]]] | |
654 |
|
654 | |||
655 | if noise_exist: |
|
655 | if noise_exist: | |
656 | # tmp_noise = jnoise[ich] / num_prof |
|
656 | # tmp_noise = jnoise[ich] / num_prof | |
657 | tmp_noise = jnoise[ich] |
|
657 | tmp_noise = jnoise[ich] | |
658 | junkspc_interf = junkspc_interf - tmp_noise |
|
658 | junkspc_interf = junkspc_interf - tmp_noise | |
659 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
659 | #junkspc_interf[:,comp_mask_prof] = 0 | |
660 |
|
660 | |||
661 | jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf |
|
661 | jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf | |
662 | jspc_interf = jspc_interf.transpose() |
|
662 | jspc_interf = jspc_interf.transpose() | |
663 | # Calculando el espectro de interferencia promedio |
|
663 | # Calculando el espectro de interferencia promedio | |
664 | noiseid = numpy.where( |
|
664 | noiseid = numpy.where( | |
665 | jspc_interf <= tmp_noise / numpy.sqrt(num_incoh)) |
|
665 | jspc_interf <= tmp_noise / numpy.sqrt(num_incoh)) | |
666 | noiseid = noiseid[0] |
|
666 | noiseid = noiseid[0] | |
667 | cnoiseid = noiseid.size |
|
667 | cnoiseid = noiseid.size | |
668 | interfid = numpy.where( |
|
668 | interfid = numpy.where( | |
669 | jspc_interf > tmp_noise / numpy.sqrt(num_incoh)) |
|
669 | jspc_interf > tmp_noise / numpy.sqrt(num_incoh)) | |
670 | interfid = interfid[0] |
|
670 | interfid = interfid[0] | |
671 | cinterfid = interfid.size |
|
671 | cinterfid = interfid.size | |
672 |
|
672 | |||
673 | if (cnoiseid > 0): |
|
673 | if (cnoiseid > 0): | |
674 | jspc_interf[noiseid] = 0 |
|
674 | jspc_interf[noiseid] = 0 | |
675 |
|
675 | |||
676 | # Expandiendo los perfiles a limpiar |
|
676 | # Expandiendo los perfiles a limpiar | |
677 | if (cinterfid > 0): |
|
677 | if (cinterfid > 0): | |
678 | new_interfid = ( |
|
678 | new_interfid = ( | |
679 | numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof |
|
679 | numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof | |
680 | new_interfid = numpy.asarray(new_interfid) |
|
680 | new_interfid = numpy.asarray(new_interfid) | |
681 | new_interfid = {x for x in new_interfid} |
|
681 | new_interfid = {x for x in new_interfid} | |
682 | new_interfid = numpy.array(list(new_interfid)) |
|
682 | new_interfid = numpy.array(list(new_interfid)) | |
683 | new_cinterfid = new_interfid.size |
|
683 | new_cinterfid = new_interfid.size | |
684 | else: |
|
684 | else: | |
685 | new_cinterfid = 0 |
|
685 | new_cinterfid = 0 | |
686 |
|
686 | |||
687 | for ip in range(new_cinterfid): |
|
687 | for ip in range(new_cinterfid): | |
688 | ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort() |
|
688 | ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort() | |
689 | jspc_interf[new_interfid[ip] |
|
689 | jspc_interf[new_interfid[ip] | |
690 | ] = junkspc_interf[ind[nhei_interf / 2], new_interfid[ip]] |
|
690 | ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]] | |
691 |
|
691 | |||
692 | jspectra[ich, :, ind_hei] = jspectra[ich, :, |
|
692 | jspectra[ich, :, ind_hei] = jspectra[ich, :, | |
693 | ind_hei] - jspc_interf # Corregir indices |
|
693 | ind_hei] - jspc_interf # Corregir indices | |
694 |
|
694 | |||
695 | # Removiendo la interferencia del punto de mayor interferencia |
|
695 | # Removiendo la interferencia del punto de mayor interferencia | |
696 | ListAux = jspc_interf[mask_prof].tolist() |
|
696 | ListAux = jspc_interf[mask_prof].tolist() | |
697 | maxid = ListAux.index(max(ListAux)) |
|
697 | maxid = ListAux.index(max(ListAux)) | |
698 |
|
698 | |||
699 | if cinterfid > 0: |
|
699 | if cinterfid > 0: | |
700 | for ip in range(cinterfid * (interf == 2) - 1): |
|
700 | for ip in range(cinterfid * (interf == 2) - 1): | |
701 | ind = (jspectra[ich, interfid[ip], :] < tmp_noise * |
|
701 | ind = (jspectra[ich, interfid[ip], :] < tmp_noise * | |
702 | (1 + 1 / numpy.sqrt(num_incoh))).nonzero() |
|
702 | (1 + 1 / numpy.sqrt(num_incoh))).nonzero() | |
703 | cind = len(ind) |
|
703 | cind = len(ind) | |
704 |
|
704 | |||
705 | if (cind > 0): |
|
705 | if (cind > 0): | |
706 | jspectra[ich, interfid[ip], ind] = tmp_noise * \ |
|
706 | jspectra[ich, interfid[ip], ind] = tmp_noise * \ | |
707 | (1 + (numpy.random.uniform(cind) - 0.5) / |
|
707 | (1 + (numpy.random.uniform(cind) - 0.5) / | |
708 | numpy.sqrt(num_incoh)) |
|
708 | numpy.sqrt(num_incoh)) | |
709 |
|
709 | |||
710 | ind = numpy.array([-2, -1, 1, 2]) |
|
710 | ind = numpy.array([-2, -1, 1, 2]) | |
711 | xx = numpy.zeros([4, 4]) |
|
711 | xx = numpy.zeros([4, 4]) | |
712 |
|
712 | |||
713 | for id1 in range(4): |
|
713 | for id1 in range(4): | |
714 | xx[:, id1] = ind[id1]**numpy.asarray(list(range(4))) |
|
714 | xx[:, id1] = ind[id1]**numpy.asarray(list(range(4))) | |
715 |
|
715 | |||
716 | xx_inv = numpy.linalg.inv(xx) |
|
716 | xx_inv = numpy.linalg.inv(xx) | |
717 | xx = xx_inv[:, 0] |
|
717 | xx = xx_inv[:, 0] | |
718 | ind = (ind + maxid + num_mask_prof) % num_mask_prof |
|
718 | ind = (ind + maxid + num_mask_prof) % num_mask_prof | |
719 | yy = jspectra[ich, mask_prof[ind], :] |
|
719 | yy = jspectra[ich, mask_prof[ind], :] | |
720 | jspectra[ich, mask_prof[maxid], :] = numpy.dot( |
|
720 | jspectra[ich, mask_prof[maxid], :] = numpy.dot( | |
721 | yy.transpose(), xx) |
|
721 | yy.transpose(), xx) | |
722 |
|
722 | |||
723 | indAux = (jspectra[ich, :, :] < tmp_noise * |
|
723 | indAux = (jspectra[ich, :, :] < tmp_noise * | |
724 | (1 - 1 / numpy.sqrt(num_incoh))).nonzero() |
|
724 | (1 - 1 / numpy.sqrt(num_incoh))).nonzero() | |
725 | jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \ |
|
725 | jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \ | |
726 | (1 - 1 / numpy.sqrt(num_incoh)) |
|
726 | (1 - 1 / numpy.sqrt(num_incoh)) | |
727 |
|
727 | |||
728 | # Remocion de Interferencia en el Cross Spectra |
|
728 | # Remocion de Interferencia en el Cross Spectra | |
729 | if jcspectra is None: |
|
729 | if jcspectra is None: | |
730 | return jspectra, jcspectra |
|
730 | return jspectra, jcspectra | |
731 | num_pairs = int(jcspectra.size / (num_prof * num_hei)) |
|
731 | num_pairs = int(jcspectra.size / (num_prof * num_hei)) | |
732 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
732 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) | |
733 |
|
733 | |||
734 | for ip in range(num_pairs): |
|
734 | for ip in range(num_pairs): | |
735 |
|
735 | |||
736 | #------------------------------------------- |
|
736 | #------------------------------------------- | |
737 |
|
737 | |||
738 | cspower = numpy.abs(jcspectra[ip, mask_prof, :]) |
|
738 | cspower = numpy.abs(jcspectra[ip, mask_prof, :]) | |
739 | cspower = cspower[:, hei_interf] |
|
739 | cspower = cspower[:, hei_interf] | |
740 | cspower = cspower.sum(axis=0) |
|
740 | cspower = cspower.sum(axis=0) | |
741 |
|
741 | |||
742 | cspsort = cspower.ravel().argsort() |
|
742 | cspsort = cspower.ravel().argsort() | |
743 | junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range( |
|
743 | junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range( | |
744 | offhei_interf, nhei_interf + offhei_interf))]]] |
|
744 | offhei_interf, nhei_interf + offhei_interf))]]] | |
745 | junkcspc_interf = junkcspc_interf.transpose() |
|
745 | junkcspc_interf = junkcspc_interf.transpose() | |
746 | jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf |
|
746 | jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf | |
747 |
|
747 | |||
748 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
748 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() | |
749 |
|
749 | |||
750 | median_real = numpy.median(numpy.real( |
|
750 | median_real = int(numpy.median(numpy.real( | |
751 | junkcspc_interf[mask_prof[ind[list(range(3 * num_prof / 4))]], :])) |
|
751 | junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :]))) | |
752 | median_imag = numpy.median(numpy.imag( |
|
752 | median_imag = int(numpy.median(numpy.imag( | |
753 | junkcspc_interf[mask_prof[ind[list(range(3 * num_prof / 4))]], :])) |
|
753 | junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :]))) | |
|
754 | comp_mask_prof = [int(e) for e in comp_mask_prof] | |||
754 | junkcspc_interf[comp_mask_prof, :] = numpy.complex( |
|
755 | junkcspc_interf[comp_mask_prof, :] = numpy.complex( | |
755 | median_real, median_imag) |
|
756 | median_real, median_imag) | |
756 |
|
757 | |||
757 | for iprof in range(num_prof): |
|
758 | for iprof in range(num_prof): | |
758 | ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort() |
|
759 | ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort() | |
759 | jcspc_interf[iprof] = junkcspc_interf[iprof, |
|
760 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]] | |
760 | ind[nhei_interf / 2]] |
|
|||
761 |
|
761 | |||
762 | # Removiendo la Interferencia |
|
762 | # Removiendo la Interferencia | |
763 | jcspectra[ip, :, ind_hei] = jcspectra[ip, |
|
763 | jcspectra[ip, :, ind_hei] = jcspectra[ip, | |
764 | :, ind_hei] - jcspc_interf |
|
764 | :, ind_hei] - jcspc_interf | |
765 |
|
765 | |||
766 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
766 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() | |
767 | maxid = ListAux.index(max(ListAux)) |
|
767 | maxid = ListAux.index(max(ListAux)) | |
768 |
|
768 | |||
769 | ind = numpy.array([-2, -1, 1, 2]) |
|
769 | ind = numpy.array([-2, -1, 1, 2]) | |
770 | xx = numpy.zeros([4, 4]) |
|
770 | xx = numpy.zeros([4, 4]) | |
771 |
|
771 | |||
772 | for id1 in range(4): |
|
772 | for id1 in range(4): | |
773 | xx[:, id1] = ind[id1]**numpy.asarray(list(range(4))) |
|
773 | xx[:, id1] = ind[id1]**numpy.asarray(list(range(4))) | |
774 |
|
774 | |||
775 | xx_inv = numpy.linalg.inv(xx) |
|
775 | xx_inv = numpy.linalg.inv(xx) | |
776 | xx = xx_inv[:, 0] |
|
776 | xx = xx_inv[:, 0] | |
777 |
|
777 | |||
778 | ind = (ind + maxid + num_mask_prof) % num_mask_prof |
|
778 | ind = (ind + maxid + num_mask_prof) % num_mask_prof | |
779 | yy = jcspectra[ip, mask_prof[ind], :] |
|
779 | yy = jcspectra[ip, mask_prof[ind], :] | |
780 | jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx) |
|
780 | jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx) | |
781 |
|
781 | |||
782 | # Guardar Resultados |
|
782 | # Guardar Resultados | |
783 | self.dataOut.data_spc = jspectra |
|
783 | self.dataOut.data_spc = jspectra | |
784 | self.dataOut.data_cspc = jcspectra |
|
784 | self.dataOut.data_cspc = jcspectra | |
785 |
|
785 | |||
786 | return 1 |
|
786 | return 1 | |
787 |
|
787 | |||
788 | def setRadarFrequency(self, frequency=None): |
|
788 | def setRadarFrequency(self, frequency=None): | |
789 |
|
789 | |||
790 | if frequency != None: |
|
790 | if frequency != None: | |
791 | self.dataOut.frequency = frequency |
|
791 | self.dataOut.frequency = frequency | |
792 |
|
792 | |||
793 | return 1 |
|
793 | return 1 | |
794 |
|
794 | |||
795 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
795 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): | |
796 | # validacion de rango |
|
796 | # validacion de rango | |
797 | if minHei == None: |
|
797 | if minHei == None: | |
798 | minHei = self.dataOut.heightList[0] |
|
798 | minHei = self.dataOut.heightList[0] | |
799 |
|
799 | |||
800 | if maxHei == None: |
|
800 | if maxHei == None: | |
801 | maxHei = self.dataOut.heightList[-1] |
|
801 | maxHei = self.dataOut.heightList[-1] | |
802 |
|
802 | |||
803 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
803 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
804 | print('minHei: %.2f is out of the heights range' % (minHei)) |
|
804 | print('minHei: %.2f is out of the heights range' % (minHei)) | |
805 | print('minHei is setting to %.2f' % (self.dataOut.heightList[0])) |
|
805 | print('minHei is setting to %.2f' % (self.dataOut.heightList[0])) | |
806 | minHei = self.dataOut.heightList[0] |
|
806 | minHei = self.dataOut.heightList[0] | |
807 |
|
807 | |||
808 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
808 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): | |
809 | print('maxHei: %.2f is out of the heights range' % (maxHei)) |
|
809 | print('maxHei: %.2f is out of the heights range' % (maxHei)) | |
810 | print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1])) |
|
810 | print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1])) | |
811 | maxHei = self.dataOut.heightList[-1] |
|
811 | maxHei = self.dataOut.heightList[-1] | |
812 |
|
812 | |||
813 | # validacion de velocidades |
|
813 | # validacion de velocidades | |
814 | velrange = self.dataOut.getVelRange(1) |
|
814 | velrange = self.dataOut.getVelRange(1) | |
815 |
|
815 | |||
816 | if minVel == None: |
|
816 | if minVel == None: | |
817 | minVel = velrange[0] |
|
817 | minVel = velrange[0] | |
818 |
|
818 | |||
819 | if maxVel == None: |
|
819 | if maxVel == None: | |
820 | maxVel = velrange[-1] |
|
820 | maxVel = velrange[-1] | |
821 |
|
821 | |||
822 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
822 | if (minVel < velrange[0]) or (minVel > maxVel): | |
823 | print('minVel: %.2f is out of the velocity range' % (minVel)) |
|
823 | print('minVel: %.2f is out of the velocity range' % (minVel)) | |
824 | print('minVel is setting to %.2f' % (velrange[0])) |
|
824 | print('minVel is setting to %.2f' % (velrange[0])) | |
825 | minVel = velrange[0] |
|
825 | minVel = velrange[0] | |
826 |
|
826 | |||
827 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
827 | if (maxVel > velrange[-1]) or (maxVel < minVel): | |
828 | print('maxVel: %.2f is out of the velocity range' % (maxVel)) |
|
828 | print('maxVel: %.2f is out of the velocity range' % (maxVel)) | |
829 | print('maxVel is setting to %.2f' % (velrange[-1])) |
|
829 | print('maxVel is setting to %.2f' % (velrange[-1])) | |
830 | maxVel = velrange[-1] |
|
830 | maxVel = velrange[-1] | |
831 |
|
831 | |||
832 | # seleccion de indices para rango |
|
832 | # seleccion de indices para rango | |
833 | minIndex = 0 |
|
833 | minIndex = 0 | |
834 | maxIndex = 0 |
|
834 | maxIndex = 0 | |
835 | heights = self.dataOut.heightList |
|
835 | heights = self.dataOut.heightList | |
836 |
|
836 | |||
837 | inda = numpy.where(heights >= minHei) |
|
837 | inda = numpy.where(heights >= minHei) | |
838 | indb = numpy.where(heights <= maxHei) |
|
838 | indb = numpy.where(heights <= maxHei) | |
839 |
|
839 | |||
840 | try: |
|
840 | try: | |
841 | minIndex = inda[0][0] |
|
841 | minIndex = inda[0][0] | |
842 | except: |
|
842 | except: | |
843 | minIndex = 0 |
|
843 | minIndex = 0 | |
844 |
|
844 | |||
845 | try: |
|
845 | try: | |
846 | maxIndex = indb[0][-1] |
|
846 | maxIndex = indb[0][-1] | |
847 | except: |
|
847 | except: | |
848 | maxIndex = len(heights) |
|
848 | maxIndex = len(heights) | |
849 |
|
849 | |||
850 | if (minIndex < 0) or (minIndex > maxIndex): |
|
850 | if (minIndex < 0) or (minIndex > maxIndex): | |
851 | raise ValueError("some value in (%d,%d) is not valid" % ( |
|
851 | raise ValueError("some value in (%d,%d) is not valid" % ( | |
852 | minIndex, maxIndex)) |
|
852 | minIndex, maxIndex)) | |
853 |
|
853 | |||
854 | if (maxIndex >= self.dataOut.nHeights): |
|
854 | if (maxIndex >= self.dataOut.nHeights): | |
855 | maxIndex = self.dataOut.nHeights - 1 |
|
855 | maxIndex = self.dataOut.nHeights - 1 | |
856 |
|
856 | |||
857 | # seleccion de indices para velocidades |
|
857 | # seleccion de indices para velocidades | |
858 | indminvel = numpy.where(velrange >= minVel) |
|
858 | indminvel = numpy.where(velrange >= minVel) | |
859 | indmaxvel = numpy.where(velrange <= maxVel) |
|
859 | indmaxvel = numpy.where(velrange <= maxVel) | |
860 | try: |
|
860 | try: | |
861 | minIndexVel = indminvel[0][0] |
|
861 | minIndexVel = indminvel[0][0] | |
862 | except: |
|
862 | except: | |
863 | minIndexVel = 0 |
|
863 | minIndexVel = 0 | |
864 |
|
864 | |||
865 | try: |
|
865 | try: | |
866 | maxIndexVel = indmaxvel[0][-1] |
|
866 | maxIndexVel = indmaxvel[0][-1] | |
867 | except: |
|
867 | except: | |
868 | maxIndexVel = len(velrange) |
|
868 | maxIndexVel = len(velrange) | |
869 |
|
869 | |||
870 | # seleccion del espectro |
|
870 | # seleccion del espectro | |
871 | data_spc = self.dataOut.data_spc[:, |
|
871 | data_spc = self.dataOut.data_spc[:, | |
872 | minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1] |
|
872 | minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1] | |
873 | # estimacion de ruido |
|
873 | # estimacion de ruido | |
874 | noise = numpy.zeros(self.dataOut.nChannels) |
|
874 | noise = numpy.zeros(self.dataOut.nChannels) | |
875 |
|
875 | |||
876 | for channel in range(self.dataOut.nChannels): |
|
876 | for channel in range(self.dataOut.nChannels): | |
877 | daux = data_spc[channel, :, :] |
|
877 | daux = data_spc[channel, :, :] | |
878 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
878 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) | |
879 |
|
879 | |||
880 | self.dataOut.noise_estimation = noise.copy() |
|
880 | self.dataOut.noise_estimation = noise.copy() | |
881 |
|
881 | |||
882 | return 1 |
|
882 | return 1 | |
883 |
|
883 | |||
884 |
|
884 | |||
885 | class IncohInt(Operation): |
|
885 | class IncohInt(Operation): | |
886 |
|
886 | |||
887 | __profIndex = 0 |
|
887 | __profIndex = 0 | |
888 | __withOverapping = False |
|
888 | __withOverapping = False | |
889 |
|
889 | |||
890 | __byTime = False |
|
890 | __byTime = False | |
891 | __initime = None |
|
891 | __initime = None | |
892 | __lastdatatime = None |
|
892 | __lastdatatime = None | |
893 | __integrationtime = None |
|
893 | __integrationtime = None | |
894 |
|
894 | |||
895 | __buffer_spc = None |
|
895 | __buffer_spc = None | |
896 | __buffer_cspc = None |
|
896 | __buffer_cspc = None | |
897 | __buffer_dc = None |
|
897 | __buffer_dc = None | |
898 |
|
898 | |||
899 | __dataReady = False |
|
899 | __dataReady = False | |
900 |
|
900 | |||
901 | __timeInterval = None |
|
901 | __timeInterval = None | |
902 |
|
902 | |||
903 | n = None |
|
903 | n = None | |
904 |
|
904 | |||
905 | def __init__(self): |
|
905 | def __init__(self): | |
906 |
|
906 | |||
907 | Operation.__init__(self) |
|
907 | Operation.__init__(self) | |
908 |
|
908 | |||
909 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
909 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
910 | """ |
|
910 | """ | |
911 | Set the parameters of the integration class. |
|
911 | Set the parameters of the integration class. | |
912 |
|
912 | |||
913 | Inputs: |
|
913 | Inputs: | |
914 |
|
914 | |||
915 | n : Number of coherent integrations |
|
915 | n : Number of coherent integrations | |
916 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
916 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
917 | overlapping : |
|
917 | overlapping : | |
918 |
|
918 | |||
919 | """ |
|
919 | """ | |
920 |
|
920 | |||
921 | self.__initime = None |
|
921 | self.__initime = None | |
922 | self.__lastdatatime = 0 |
|
922 | self.__lastdatatime = 0 | |
923 |
|
923 | |||
924 | self.__buffer_spc = 0 |
|
924 | self.__buffer_spc = 0 | |
925 | self.__buffer_cspc = 0 |
|
925 | self.__buffer_cspc = 0 | |
926 | self.__buffer_dc = 0 |
|
926 | self.__buffer_dc = 0 | |
927 |
|
927 | |||
928 | self.__profIndex = 0 |
|
928 | self.__profIndex = 0 | |
929 | self.__dataReady = False |
|
929 | self.__dataReady = False | |
930 | self.__byTime = False |
|
930 | self.__byTime = False | |
931 |
|
931 | |||
932 | if n is None and timeInterval is None: |
|
932 | if n is None and timeInterval is None: | |
933 | raise ValueError("n or timeInterval should be specified ...") |
|
933 | raise ValueError("n or timeInterval should be specified ...") | |
934 |
|
934 | |||
935 | if n is not None: |
|
935 | if n is not None: | |
936 | self.n = int(n) |
|
936 | self.n = int(n) | |
937 | else: |
|
937 | else: | |
938 |
|
938 | |||
939 | self.__integrationtime = int(timeInterval) |
|
939 | self.__integrationtime = int(timeInterval) | |
940 | self.n = None |
|
940 | self.n = None | |
941 | self.__byTime = True |
|
941 | self.__byTime = True | |
942 |
|
942 | |||
943 | def putData(self, data_spc, data_cspc, data_dc): |
|
943 | def putData(self, data_spc, data_cspc, data_dc): | |
944 | """ |
|
944 | """ | |
945 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
945 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
946 |
|
946 | |||
947 | """ |
|
947 | """ | |
948 |
|
948 | |||
949 | self.__buffer_spc += data_spc |
|
949 | self.__buffer_spc += data_spc | |
950 |
|
950 | |||
951 | if data_cspc is None: |
|
951 | if data_cspc is None: | |
952 | self.__buffer_cspc = None |
|
952 | self.__buffer_cspc = None | |
953 | else: |
|
953 | else: | |
954 | self.__buffer_cspc += data_cspc |
|
954 | self.__buffer_cspc += data_cspc | |
955 |
|
955 | |||
956 | if data_dc is None: |
|
956 | if data_dc is None: | |
957 | self.__buffer_dc = None |
|
957 | self.__buffer_dc = None | |
958 | else: |
|
958 | else: | |
959 | self.__buffer_dc += data_dc |
|
959 | self.__buffer_dc += data_dc | |
960 |
|
960 | |||
961 | self.__profIndex += 1 |
|
961 | self.__profIndex += 1 | |
962 |
|
962 | |||
963 | return |
|
963 | return | |
964 |
|
964 | |||
965 | def pushData(self): |
|
965 | def pushData(self): | |
966 | """ |
|
966 | """ | |
967 | Return the sum of the last profiles and the profiles used in the sum. |
|
967 | Return the sum of the last profiles and the profiles used in the sum. | |
968 |
|
968 | |||
969 | Affected: |
|
969 | Affected: | |
970 |
|
970 | |||
971 | self.__profileIndex |
|
971 | self.__profileIndex | |
972 |
|
972 | |||
973 | """ |
|
973 | """ | |
974 |
|
974 | |||
975 | data_spc = self.__buffer_spc |
|
975 | data_spc = self.__buffer_spc | |
976 | data_cspc = self.__buffer_cspc |
|
976 | data_cspc = self.__buffer_cspc | |
977 | data_dc = self.__buffer_dc |
|
977 | data_dc = self.__buffer_dc | |
978 | n = self.__profIndex |
|
978 | n = self.__profIndex | |
979 |
|
979 | |||
980 | self.__buffer_spc = 0 |
|
980 | self.__buffer_spc = 0 | |
981 | self.__buffer_cspc = 0 |
|
981 | self.__buffer_cspc = 0 | |
982 | self.__buffer_dc = 0 |
|
982 | self.__buffer_dc = 0 | |
983 | self.__profIndex = 0 |
|
983 | self.__profIndex = 0 | |
984 |
|
984 | |||
985 | return data_spc, data_cspc, data_dc, n |
|
985 | return data_spc, data_cspc, data_dc, n | |
986 |
|
986 | |||
987 | def byProfiles(self, *args): |
|
987 | def byProfiles(self, *args): | |
988 |
|
988 | |||
989 | self.__dataReady = False |
|
989 | self.__dataReady = False | |
990 | avgdata_spc = None |
|
990 | avgdata_spc = None | |
991 | avgdata_cspc = None |
|
991 | avgdata_cspc = None | |
992 | avgdata_dc = None |
|
992 | avgdata_dc = None | |
993 |
|
993 | |||
994 | self.putData(*args) |
|
994 | self.putData(*args) | |
995 |
|
995 | |||
996 | if self.__profIndex == self.n: |
|
996 | if self.__profIndex == self.n: | |
997 |
|
997 | |||
998 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
998 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
999 | self.n = n |
|
999 | self.n = n | |
1000 | self.__dataReady = True |
|
1000 | self.__dataReady = True | |
1001 |
|
1001 | |||
1002 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1002 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1003 |
|
1003 | |||
1004 | def byTime(self, datatime, *args): |
|
1004 | def byTime(self, datatime, *args): | |
1005 |
|
1005 | |||
1006 | self.__dataReady = False |
|
1006 | self.__dataReady = False | |
1007 | avgdata_spc = None |
|
1007 | avgdata_spc = None | |
1008 | avgdata_cspc = None |
|
1008 | avgdata_cspc = None | |
1009 | avgdata_dc = None |
|
1009 | avgdata_dc = None | |
1010 |
|
1010 | |||
1011 | self.putData(*args) |
|
1011 | self.putData(*args) | |
1012 |
|
1012 | |||
1013 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1013 | if (datatime - self.__initime) >= self.__integrationtime: | |
1014 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1014 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
1015 | self.n = n |
|
1015 | self.n = n | |
1016 | self.__dataReady = True |
|
1016 | self.__dataReady = True | |
1017 |
|
1017 | |||
1018 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1018 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1019 |
|
1019 | |||
1020 | def integrate(self, datatime, *args): |
|
1020 | def integrate(self, datatime, *args): | |
1021 |
|
1021 | |||
1022 | if self.__profIndex == 0: |
|
1022 | if self.__profIndex == 0: | |
1023 | self.__initime = datatime |
|
1023 | self.__initime = datatime | |
1024 |
|
1024 | |||
1025 | if self.__byTime: |
|
1025 | if self.__byTime: | |
1026 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime( |
|
1026 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime( | |
1027 | datatime, *args) |
|
1027 | datatime, *args) | |
1028 | else: |
|
1028 | else: | |
1029 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
1029 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
1030 |
|
1030 | |||
1031 | if not self.__dataReady: |
|
1031 | if not self.__dataReady: | |
1032 | return None, None, None, None |
|
1032 | return None, None, None, None | |
1033 |
|
1033 | |||
1034 | return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
1034 | return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc | |
1035 |
|
1035 | |||
1036 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
1036 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
1037 | if n == 1: |
|
1037 | if n == 1: | |
1038 | return |
|
1038 | return | |
1039 |
|
1039 | |||
1040 | dataOut.flagNoData = True |
|
1040 | dataOut.flagNoData = True | |
1041 |
|
1041 | |||
1042 | if not self.isConfig: |
|
1042 | if not self.isConfig: | |
1043 | self.setup(n, timeInterval, overlapping) |
|
1043 | self.setup(n, timeInterval, overlapping) | |
1044 | self.isConfig = True |
|
1044 | self.isConfig = True | |
1045 |
|
1045 | |||
1046 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
1046 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, | |
1047 | dataOut.data_spc, |
|
1047 | dataOut.data_spc, | |
1048 | dataOut.data_cspc, |
|
1048 | dataOut.data_cspc, | |
1049 | dataOut.data_dc) |
|
1049 | dataOut.data_dc) | |
1050 |
|
1050 | |||
1051 | if self.__dataReady: |
|
1051 | if self.__dataReady: | |
1052 |
|
1052 | |||
1053 | dataOut.data_spc = avgdata_spc |
|
1053 | dataOut.data_spc = avgdata_spc | |
1054 | dataOut.data_cspc = avgdata_cspc |
|
1054 | dataOut.data_cspc = avgdata_cspc | |
1055 | dataOut.data_dc = avgdata_dc |
|
1055 | dataOut.data_dc = avgdata_dc | |
1056 | dataOut.nIncohInt *= self.n |
|
1056 | dataOut.nIncohInt *= self.n | |
1057 | dataOut.utctime = avgdatatime |
|
1057 | dataOut.utctime = avgdatatime | |
1058 | dataOut.flagNoData = False |
|
1058 | dataOut.flagNoData = False | |
1059 |
|
1059 | |||
1060 | return dataOut No newline at end of file |
|
1060 | return dataOut |
General Comments 0
You need to be logged in to leave comments.
Login now