##// END OF EJS Templates
update testing EWDrifts_19Jun2023
Alexander Valdez -
r1677:dbcdef2bc4fb
parent child
Show More
@@ -1,937 +1,939
1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
2 # All rights reserved.
2 # All rights reserved.
3 #
3 #
4 # Distributed under the terms of the BSD 3-clause license.
4 # Distributed under the terms of the BSD 3-clause license.
5 """Spectra processing Unit and operations
5 """Spectra processing Unit and operations
6
6
7 Here you will find the processing unit `SpectraProc` and several operations
7 Here you will find the processing unit `SpectraProc` and several operations
8 to work with Spectra data type
8 to work with Spectra data type
9 """
9 """
10
10
11 import time
11 import time
12 import itertools
12 import itertools
13 import numpy
13 import numpy
14 # repositorio
14 # repositorio
15 from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation
15 from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation
16 from schainpy.model.data.jrodata import Spectra
16 from schainpy.model.data.jrodata import Spectra
17 from schainpy.model.data.jrodata import hildebrand_sekhon
17 from schainpy.model.data.jrodata import hildebrand_sekhon
18 from schainpy.utils import log
18 from schainpy.utils import log
19
19
20
20
21 class SpectraProc(ProcessingUnit):
21 class SpectraProc(ProcessingUnit):
22
22
23 def __init__(self):
23 def __init__(self):
24
24
25 ProcessingUnit.__init__(self)
25 ProcessingUnit.__init__(self)
26
26
27 self.buffer = None
27 self.buffer = None
28 self.firstdatatime = None
28 self.firstdatatime = None
29 self.profIndex = 0
29 self.profIndex = 0
30 self.dataOut = Spectra()
30 self.dataOut = Spectra()
31 self.id_min = None
31 self.id_min = None
32 self.id_max = None
32 self.id_max = None
33 self.setupReq = False #Agregar a todas las unidades de proc
33 self.setupReq = False #Agregar a todas las unidades de proc
34
34
35 def __updateSpecFromVoltage(self):
35 def __updateSpecFromVoltage(self):
36
36
37 self.dataOut.timeZone = self.dataIn.timeZone
37 self.dataOut.timeZone = self.dataIn.timeZone
38 self.dataOut.dstFlag = self.dataIn.dstFlag
38 self.dataOut.dstFlag = self.dataIn.dstFlag
39 self.dataOut.errorCount = self.dataIn.errorCount
39 self.dataOut.errorCount = self.dataIn.errorCount
40 self.dataOut.useLocalTime = self.dataIn.useLocalTime
40 self.dataOut.useLocalTime = self.dataIn.useLocalTime
41 try:
41 try:
42 self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy()
42 self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy()
43 except:
43 except:
44 pass
44 pass
45 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
45 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
46 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
46 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
47 self.dataOut.channelList = self.dataIn.channelList
47 self.dataOut.channelList = self.dataIn.channelList
48 self.dataOut.heightList = self.dataIn.heightList
48 self.dataOut.heightList = self.dataIn.heightList
49 self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
49 self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
50 self.dataOut.nProfiles = self.dataOut.nFFTPoints
50 self.dataOut.nProfiles = self.dataOut.nFFTPoints
51 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
51 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
52 self.dataOut.utctime = self.firstdatatime
52 self.dataOut.utctime = self.firstdatatime
53 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData
53 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData
54 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData
54 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData
55 self.dataOut.flagShiftFFT = False
55 self.dataOut.flagShiftFFT = False
56 self.dataOut.nCohInt = self.dataIn.nCohInt
56 self.dataOut.nCohInt = self.dataIn.nCohInt
57 self.dataOut.nIncohInt = 1
57 self.dataOut.nIncohInt = 1
58 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
58 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
59 self.dataOut.frequency = self.dataIn.frequency
59 self.dataOut.frequency = self.dataIn.frequency
60 self.dataOut.realtime = self.dataIn.realtime
60 self.dataOut.realtime = self.dataIn.realtime
61 self.dataOut.azimuth = self.dataIn.azimuth
61 self.dataOut.azimuth = self.dataIn.azimuth
62 self.dataOut.zenith = self.dataIn.zenith
62 self.dataOut.zenith = self.dataIn.zenith
63 self.dataOut.beam.codeList = self.dataIn.beam.codeList
63 self.dataOut.beam.codeList = self.dataIn.beam.codeList
64 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
64 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
65 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
65 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
66 self.dataOut.runNextUnit = self.dataIn.runNextUnit
66 self.dataOut.runNextUnit = self.dataIn.runNextUnit
67 try:
67 try:
68 self.dataOut.step = self.dataIn.step
68 self.dataOut.step = self.dataIn.step
69 except:
69 except:
70 pass
70 pass
71
71
72 def __getFft(self):
72 def __getFft(self):
73 """
73 """
74 Convierte valores de Voltaje a Spectra
74 Convierte valores de Voltaje a Spectra
75
75
76 Affected:
76 Affected:
77 self.dataOut.data_spc
77 self.dataOut.data_spc
78 self.dataOut.data_cspc
78 self.dataOut.data_cspc
79 self.dataOut.data_dc
79 self.dataOut.data_dc
80 self.dataOut.heightList
80 self.dataOut.heightList
81 self.profIndex
81 self.profIndex
82 self.buffer
82 self.buffer
83 self.dataOut.flagNoData
83 self.dataOut.flagNoData
84 """
84 """
85 fft_volt = numpy.fft.fft(
85 fft_volt = numpy.fft.fft(
86 self.buffer, n=self.dataOut.nFFTPoints, axis=1)
86 self.buffer, n=self.dataOut.nFFTPoints, axis=1)
87 fft_volt = fft_volt.astype(numpy.dtype('complex'))
87 fft_volt = fft_volt.astype(numpy.dtype('complex'))
88 dc = fft_volt[:, 0, :]
88 dc = fft_volt[:, 0, :]
89
89
90 # calculo de self-spectra
90 # calculo de self-spectra
91 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
91 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
92 spc = fft_volt * numpy.conjugate(fft_volt)
92 spc = fft_volt * numpy.conjugate(fft_volt)
93 spc = spc.real
93 spc = spc.real
94
94
95 blocksize = 0
95 blocksize = 0
96 blocksize += dc.size
96 blocksize += dc.size
97 blocksize += spc.size
97 blocksize += spc.size
98
98
99 cspc = None
99 cspc = None
100 pairIndex = 0
100 pairIndex = 0
101 if self.dataOut.pairsList != None:
101 if self.dataOut.pairsList != None:
102 # calculo de cross-spectra
102 # calculo de cross-spectra
103 cspc = numpy.zeros(
103 cspc = numpy.zeros(
104 (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
104 (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
105 for pair in self.dataOut.pairsList:
105 for pair in self.dataOut.pairsList:
106 if pair[0] not in self.dataOut.channelList:
106 if pair[0] not in self.dataOut.channelList:
107 raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % (
107 raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % (
108 str(pair), str(self.dataOut.channelList)))
108 str(pair), str(self.dataOut.channelList)))
109 if pair[1] not in self.dataOut.channelList:
109 if pair[1] not in self.dataOut.channelList:
110 raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % (
110 raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % (
111 str(pair), str(self.dataOut.channelList)))
111 str(pair), str(self.dataOut.channelList)))
112
112
113 cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \
113 cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \
114 numpy.conjugate(fft_volt[pair[1], :, :])
114 numpy.conjugate(fft_volt[pair[1], :, :])
115 pairIndex += 1
115 pairIndex += 1
116 blocksize += cspc.size
116 blocksize += cspc.size
117
117
118 self.dataOut.data_spc = spc
118 self.dataOut.data_spc = spc
119 self.dataOut.data_cspc = cspc
119 self.dataOut.data_cspc = cspc
120 self.dataOut.data_dc = dc
120 self.dataOut.data_dc = dc
121 self.dataOut.blockSize = blocksize
121 self.dataOut.blockSize = blocksize
122 self.dataOut.flagShiftFFT = False
122 self.dataOut.flagShiftFFT = False
123
123
124 def run(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None, shift_fft=False, runNextUnit = 0):
124 def run(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None, shift_fft=False, runNextUnit = 0):
125
125
126 self.dataIn.runNextUnit = runNextUnit
126 self.dataIn.runNextUnit = runNextUnit
127 if self.dataIn.type == "Spectra":
127 if self.dataIn.type == "Spectra":
128 self.dataOut.copy(self.dataIn)
128 self.dataOut.copy(self.dataIn)
129 if shift_fft:
129 if shift_fft:
130 #desplaza a la derecha en el eje 2 determinadas posiciones
130 #desplaza a la derecha en el eje 2 determinadas posiciones
131 shift = int(self.dataOut.nFFTPoints/2)
131 shift = int(self.dataOut.nFFTPoints/2)
132 self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1)
132 self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1)
133
133
134 if self.dataOut.data_cspc is not None:
134 if self.dataOut.data_cspc is not None:
135 #desplaza a la derecha en el eje 2 determinadas posiciones
135 #desplaza a la derecha en el eje 2 determinadas posiciones
136 self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1)
136 self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1)
137 if pairsList:
137 if pairsList:
138 self.__selectPairs(pairsList)
138 self.__selectPairs(pairsList)
139
139
140 elif self.dataIn.type == "Voltage":
140 elif self.dataIn.type == "Voltage":
141
141
142 self.dataOut.flagNoData = True
142 self.dataOut.flagNoData = True
143
143
144 if nFFTPoints == None:
144 if nFFTPoints == None:
145 raise ValueError("This SpectraProc.run() need nFFTPoints input variable")
145 raise ValueError("This SpectraProc.run() need nFFTPoints input variable")
146
146
147 if nProfiles == None:
147 if nProfiles == None:
148 nProfiles = nFFTPoints
148 nProfiles = nFFTPoints
149
149
150 if ippFactor == None:
150 if ippFactor == None:
151 self.dataOut.ippFactor = 1
151 self.dataOut.ippFactor = 1
152
152
153 self.dataOut.nFFTPoints = nFFTPoints
153 self.dataOut.nFFTPoints = nFFTPoints
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 print("W",self.buffer.shape)
160
161
161 if self.dataIn.flagDataAsBlock:
162 if self.dataIn.flagDataAsBlock:
162 nVoltProfiles = self.dataIn.data.shape[1]
163 nVoltProfiles = self.dataIn.data.shape[1]
163 if nVoltProfiles == nProfiles:
164 if nVoltProfiles == nProfiles:
164 self.buffer = self.dataIn.data.copy()
165 self.buffer = self.dataIn.data.copy()
165 self.profIndex = nVoltProfiles
166 self.profIndex = nVoltProfiles
166
167
167 elif nVoltProfiles < nProfiles:
168 elif nVoltProfiles < nProfiles:
168
169
169 if self.profIndex == 0:
170 if self.profIndex == 0:
170 self.id_min = 0
171 self.id_min = 0
171 self.id_max = nVoltProfiles
172 self.id_max = nVoltProfiles
172
173
173 self.buffer[:, self.id_min:self.id_max,
174 self.buffer[:, self.id_min:self.id_max,
174 :] = self.dataIn.data
175 :] = self.dataIn.data
175 self.profIndex += nVoltProfiles
176 self.profIndex += nVoltProfiles
176 self.id_min += nVoltProfiles
177 self.id_min += nVoltProfiles
177 self.id_max += nVoltProfiles
178 self.id_max += nVoltProfiles
178 elif nVoltProfiles > nProfiles:
179 elif nVoltProfiles > nProfiles:
179 self.reader.bypass = True
180 self.reader.bypass = True
180 if self.profIndex == 0:
181 if self.profIndex == 0:
181 self.id_min = 0
182 self.id_min = 0
182 self.id_max = nProfiles
183 self.id_max = nProfiles
183
184
184 self.buffer = self.dataIn.data[:, self.id_min:self.id_max,:]
185 self.buffer = self.dataIn.data[:, self.id_min:self.id_max,:]
185 self.profIndex += nProfiles
186 self.profIndex += nProfiles
186 self.id_min += nProfiles
187 self.id_min += nProfiles
187 self.id_max += nProfiles
188 self.id_max += nProfiles
188 if self.id_max == nVoltProfiles:
189 if self.id_max == nVoltProfiles:
189 self.reader.bypass = False
190 self.reader.bypass = False
190
191
191 else:
192 else:
192 raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % (
193 raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % (
193 self.dataIn.type, self.dataIn.data.shape[1], nProfiles))
194 self.dataIn.type, self.dataIn.data.shape[1], nProfiles))
194 self.dataOut.flagNoData = True
195 self.dataOut.flagNoData = True
195 else:
196 else:
197 print(self.profIndex,self.dataIn.data.copy().shape)
196 self.buffer[:, self.profIndex, :] = self.dataIn.data.copy()
198 self.buffer[:, self.profIndex, :] = self.dataIn.data.copy()
197 self.profIndex += 1
199 self.profIndex += 1
198
200
199 if self.firstdatatime == None:
201 if self.firstdatatime == None:
200 self.firstdatatime = self.dataIn.utctime
202 self.firstdatatime = self.dataIn.utctime
201
203
202 if self.profIndex == nProfiles:
204 if self.profIndex == nProfiles:
203 self.__updateSpecFromVoltage()
205 self.__updateSpecFromVoltage()
204 if pairsList == None:
206 if pairsList == None:
205 self.dataOut.pairsList = [pair for pair in itertools.combinations(self.dataOut.channelList, 2)]
207 self.dataOut.pairsList = [pair for pair in itertools.combinations(self.dataOut.channelList, 2)]
206 else:
208 else:
207 self.dataOut.pairsList = pairsList
209 self.dataOut.pairsList = pairsList
208 self.__getFft()
210 self.__getFft()
209 self.dataOut.flagNoData = False
211 self.dataOut.flagNoData = False
210 self.firstdatatime = None
212 self.firstdatatime = None
211 if not self.reader.bypass:
213 #if not self.reader.bypass:
212 self.profIndex = 0
214 self.profIndex = 0
213 else:
215 else:
214 raise ValueError("The type of input object '%s' is not valid".format(
216 raise ValueError("The type of input object '%s' is not valid".format(
215 self.dataIn.type))
217 self.dataIn.type))
216
218
217 def __selectPairs(self, pairsList):
219 def __selectPairs(self, pairsList):
218
220
219 if not pairsList:
221 if not pairsList:
220 return
222 return
221
223
222 pairs = []
224 pairs = []
223 pairsIndex = []
225 pairsIndex = []
224
226
225 for pair in pairsList:
227 for pair in pairsList:
226 if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList:
228 if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList:
227 continue
229 continue
228 pairs.append(pair)
230 pairs.append(pair)
229 pairsIndex.append(pairs.index(pair))
231 pairsIndex.append(pairs.index(pair))
230
232
231 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
233 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
232 self.dataOut.pairsList = pairs
234 self.dataOut.pairsList = pairs
233
235
234 return
236 return
235
237
236 def selectFFTs(self, minFFT, maxFFT ):
238 def selectFFTs(self, minFFT, maxFFT ):
237 """
239 """
238 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
240 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
239 minFFT<= FFT <= maxFFT
241 minFFT<= FFT <= maxFFT
240 """
242 """
241
243
242 if (minFFT > maxFFT):
244 if (minFFT > maxFFT):
243 raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT))
245 raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT))
244
246
245 if (minFFT < self.dataOut.getFreqRange()[0]):
247 if (minFFT < self.dataOut.getFreqRange()[0]):
246 minFFT = self.dataOut.getFreqRange()[0]
248 minFFT = self.dataOut.getFreqRange()[0]
247
249
248 if (maxFFT > self.dataOut.getFreqRange()[-1]):
250 if (maxFFT > self.dataOut.getFreqRange()[-1]):
249 maxFFT = self.dataOut.getFreqRange()[-1]
251 maxFFT = self.dataOut.getFreqRange()[-1]
250
252
251 minIndex = 0
253 minIndex = 0
252 maxIndex = 0
254 maxIndex = 0
253 FFTs = self.dataOut.getFreqRange()
255 FFTs = self.dataOut.getFreqRange()
254
256
255 inda = numpy.where(FFTs >= minFFT)
257 inda = numpy.where(FFTs >= minFFT)
256 indb = numpy.where(FFTs <= maxFFT)
258 indb = numpy.where(FFTs <= maxFFT)
257
259
258 try:
260 try:
259 minIndex = inda[0][0]
261 minIndex = inda[0][0]
260 except:
262 except:
261 minIndex = 0
263 minIndex = 0
262
264
263 try:
265 try:
264 maxIndex = indb[0][-1]
266 maxIndex = indb[0][-1]
265 except:
267 except:
266 maxIndex = len(FFTs)
268 maxIndex = len(FFTs)
267
269
268 self.selectFFTsByIndex(minIndex, maxIndex)
270 self.selectFFTsByIndex(minIndex, maxIndex)
269
271
270 return 1
272 return 1
271
273
272 def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None):
274 def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None):
273 newheis = numpy.where(
275 newheis = numpy.where(
274 self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex])
276 self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex])
275
277
276 if hei_ref != None:
278 if hei_ref != None:
277 newheis = numpy.where(self.dataOut.heightList > hei_ref)
279 newheis = numpy.where(self.dataOut.heightList > hei_ref)
278
280
279 minIndex = min(newheis[0])
281 minIndex = min(newheis[0])
280 maxIndex = max(newheis[0])
282 maxIndex = max(newheis[0])
281 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
283 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
282 heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
284 heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
283
285
284 # determina indices
286 # determina indices
285 nheis = int(self.dataOut.radarControllerHeaderObj.txB /
287 nheis = int(self.dataOut.radarControllerHeaderObj.txB /
286 (self.dataOut.heightList[1] - self.dataOut.heightList[0]))
288 (self.dataOut.heightList[1] - self.dataOut.heightList[0]))
287 avg_dB = 10 * \
289 avg_dB = 10 * \
288 numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0))
290 numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0))
289 beacon_dB = numpy.sort(avg_dB)[-nheis:]
291 beacon_dB = numpy.sort(avg_dB)[-nheis:]
290 beacon_heiIndexList = []
292 beacon_heiIndexList = []
291 for val in avg_dB.tolist():
293 for val in avg_dB.tolist():
292 if val >= beacon_dB[0]:
294 if val >= beacon_dB[0]:
293 beacon_heiIndexList.append(avg_dB.tolist().index(val))
295 beacon_heiIndexList.append(avg_dB.tolist().index(val))
294
296
295 data_cspc = None
297 data_cspc = None
296 if self.dataOut.data_cspc is not None:
298 if self.dataOut.data_cspc is not None:
297 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
299 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
298
300
299 data_dc = None
301 data_dc = None
300 if self.dataOut.data_dc is not None:
302 if self.dataOut.data_dc is not None:
301 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
303 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
302
304
303 self.dataOut.data_spc = data_spc
305 self.dataOut.data_spc = data_spc
304 self.dataOut.data_cspc = data_cspc
306 self.dataOut.data_cspc = data_cspc
305 self.dataOut.data_dc = data_dc
307 self.dataOut.data_dc = data_dc
306 self.dataOut.heightList = heightList
308 self.dataOut.heightList = heightList
307 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
309 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
308
310
309 return 1
311 return 1
310
312
311 def selectFFTsByIndex(self, minIndex, maxIndex):
313 def selectFFTsByIndex(self, minIndex, maxIndex):
312 """
314 """
313
315
314 """
316 """
315
317
316 if (minIndex < 0) or (minIndex > maxIndex):
318 if (minIndex < 0) or (minIndex > maxIndex):
317 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex))
319 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex))
318
320
319 if (maxIndex >= self.dataOut.nProfiles):
321 if (maxIndex >= self.dataOut.nProfiles):
320 maxIndex = self.dataOut.nProfiles-1
322 maxIndex = self.dataOut.nProfiles-1
321
323
322 #Spectra
324 #Spectra
323 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
325 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
324
326
325 data_cspc = None
327 data_cspc = None
326 if self.dataOut.data_cspc is not None:
328 if self.dataOut.data_cspc is not None:
327 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
329 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
328
330
329 data_dc = None
331 data_dc = None
330 if self.dataOut.data_dc is not None:
332 if self.dataOut.data_dc is not None:
331 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
333 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
332
334
333 self.dataOut.data_spc = data_spc
335 self.dataOut.data_spc = data_spc
334 self.dataOut.data_cspc = data_cspc
336 self.dataOut.data_cspc = data_cspc
335 self.dataOut.data_dc = data_dc
337 self.dataOut.data_dc = data_dc
336
338
337 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
339 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
338 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
340 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
339 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
341 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
340
342
341 return 1
343 return 1
342
344
343 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
345 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
344 # validacion de rango
346 # validacion de rango
345 if minHei == None:
347 if minHei == None:
346 minHei = self.dataOut.heightList[0]
348 minHei = self.dataOut.heightList[0]
347
349
348 if maxHei == None:
350 if maxHei == None:
349 maxHei = self.dataOut.heightList[-1]
351 maxHei = self.dataOut.heightList[-1]
350
352
351 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
353 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
352 print('minHei: %.2f is out of the heights range' % (minHei))
354 print('minHei: %.2f is out of the heights range' % (minHei))
353 print('minHei is setting to %.2f' % (self.dataOut.heightList[0]))
355 print('minHei is setting to %.2f' % (self.dataOut.heightList[0]))
354 minHei = self.dataOut.heightList[0]
356 minHei = self.dataOut.heightList[0]
355
357
356 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
358 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
357 print('maxHei: %.2f is out of the heights range' % (maxHei))
359 print('maxHei: %.2f is out of the heights range' % (maxHei))
358 print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1]))
360 print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1]))
359 maxHei = self.dataOut.heightList[-1]
361 maxHei = self.dataOut.heightList[-1]
360
362
361 # validacion de velocidades
363 # validacion de velocidades
362 velrange = self.dataOut.getVelRange(1)
364 velrange = self.dataOut.getVelRange(1)
363
365
364 if minVel == None:
366 if minVel == None:
365 minVel = velrange[0]
367 minVel = velrange[0]
366
368
367 if maxVel == None:
369 if maxVel == None:
368 maxVel = velrange[-1]
370 maxVel = velrange[-1]
369
371
370 if (minVel < velrange[0]) or (minVel > maxVel):
372 if (minVel < velrange[0]) or (minVel > maxVel):
371 print('minVel: %.2f is out of the velocity range' % (minVel))
373 print('minVel: %.2f is out of the velocity range' % (minVel))
372 print('minVel is setting to %.2f' % (velrange[0]))
374 print('minVel is setting to %.2f' % (velrange[0]))
373 minVel = velrange[0]
375 minVel = velrange[0]
374
376
375 if (maxVel > velrange[-1]) or (maxVel < minVel):
377 if (maxVel > velrange[-1]) or (maxVel < minVel):
376 print('maxVel: %.2f is out of the velocity range' % (maxVel))
378 print('maxVel: %.2f is out of the velocity range' % (maxVel))
377 print('maxVel is setting to %.2f' % (velrange[-1]))
379 print('maxVel is setting to %.2f' % (velrange[-1]))
378 maxVel = velrange[-1]
380 maxVel = velrange[-1]
379
381
380 # seleccion de indices para rango
382 # seleccion de indices para rango
381 minIndex = 0
383 minIndex = 0
382 maxIndex = 0
384 maxIndex = 0
383 heights = self.dataOut.heightList
385 heights = self.dataOut.heightList
384
386
385 inda = numpy.where(heights >= minHei)
387 inda = numpy.where(heights >= minHei)
386 indb = numpy.where(heights <= maxHei)
388 indb = numpy.where(heights <= maxHei)
387
389
388 try:
390 try:
389 minIndex = inda[0][0]
391 minIndex = inda[0][0]
390 except:
392 except:
391 minIndex = 0
393 minIndex = 0
392
394
393 try:
395 try:
394 maxIndex = indb[0][-1]
396 maxIndex = indb[0][-1]
395 except:
397 except:
396 maxIndex = len(heights)
398 maxIndex = len(heights)
397
399
398 if (minIndex < 0) or (minIndex > maxIndex):
400 if (minIndex < 0) or (minIndex > maxIndex):
399 raise ValueError("some value in (%d,%d) is not valid" % (
401 raise ValueError("some value in (%d,%d) is not valid" % (
400 minIndex, maxIndex))
402 minIndex, maxIndex))
401
403
402 if (maxIndex >= self.dataOut.nHeights):
404 if (maxIndex >= self.dataOut.nHeights):
403 maxIndex = self.dataOut.nHeights - 1
405 maxIndex = self.dataOut.nHeights - 1
404
406
405 # seleccion de indices para velocidades
407 # seleccion de indices para velocidades
406 indminvel = numpy.where(velrange >= minVel)
408 indminvel = numpy.where(velrange >= minVel)
407 indmaxvel = numpy.where(velrange <= maxVel)
409 indmaxvel = numpy.where(velrange <= maxVel)
408 try:
410 try:
409 minIndexVel = indminvel[0][0]
411 minIndexVel = indminvel[0][0]
410 except:
412 except:
411 minIndexVel = 0
413 minIndexVel = 0
412
414
413 try:
415 try:
414 maxIndexVel = indmaxvel[0][-1]
416 maxIndexVel = indmaxvel[0][-1]
415 except:
417 except:
416 maxIndexVel = len(velrange)
418 maxIndexVel = len(velrange)
417
419
418 # seleccion del espectro
420 # seleccion del espectro
419 data_spc = self.dataOut.data_spc[:,
421 data_spc = self.dataOut.data_spc[:,
420 minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1]
422 minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1]
421 # estimacion de ruido
423 # estimacion de ruido
422 noise = numpy.zeros(self.dataOut.nChannels)
424 noise = numpy.zeros(self.dataOut.nChannels)
423
425
424 for channel in range(self.dataOut.nChannels):
426 for channel in range(self.dataOut.nChannels):
425 daux = data_spc[channel, :, :]
427 daux = data_spc[channel, :, :]
426 sortdata = numpy.sort(daux, axis=None)
428 sortdata = numpy.sort(daux, axis=None)
427 noise[channel] = hildebrand_sekhon(sortdata, self.dataOut.nIncohInt)
429 noise[channel] = hildebrand_sekhon(sortdata, self.dataOut.nIncohInt)
428
430
429 self.dataOut.noise_estimation = noise.copy()
431 self.dataOut.noise_estimation = noise.copy()
430
432
431 return 1
433 return 1
432
434
433 class removeDC(Operation):
435 class removeDC(Operation):
434
436
435 def run(self, dataOut, mode=2):
437 def run(self, dataOut, mode=2):
436 self.dataOut = dataOut
438 self.dataOut = dataOut
437 jspectra = self.dataOut.data_spc
439 jspectra = self.dataOut.data_spc
438 jcspectra = self.dataOut.data_cspc
440 jcspectra = self.dataOut.data_cspc
439
441
440 num_chan = jspectra.shape[0]
442 num_chan = jspectra.shape[0]
441 num_hei = jspectra.shape[2]
443 num_hei = jspectra.shape[2]
442
444
443 if jcspectra is not None:
445 if jcspectra is not None:
444 jcspectraExist = True
446 jcspectraExist = True
445 num_pairs = jcspectra.shape[0]
447 num_pairs = jcspectra.shape[0]
446 else:
448 else:
447 jcspectraExist = False
449 jcspectraExist = False
448
450
449 freq_dc = int(jspectra.shape[1] / 2)
451 freq_dc = int(jspectra.shape[1] / 2)
450 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
452 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
451 ind_vel = ind_vel.astype(int)
453 ind_vel = ind_vel.astype(int)
452
454
453 if ind_vel[0] < 0:
455 if ind_vel[0] < 0:
454 ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof
456 ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof
455
457
456 if mode == 1:
458 if mode == 1:
457 jspectra[:, freq_dc, :] = (
459 jspectra[:, freq_dc, :] = (
458 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
460 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
459
461
460 if jcspectraExist:
462 if jcspectraExist:
461 jcspectra[:, freq_dc, :] = (
463 jcspectra[:, freq_dc, :] = (
462 jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2
464 jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2
463
465
464 if mode == 2:
466 if mode == 2:
465
467
466 vel = numpy.array([-2, -1, 1, 2])
468 vel = numpy.array([-2, -1, 1, 2])
467 xx = numpy.zeros([4, 4])
469 xx = numpy.zeros([4, 4])
468
470
469 for fil in range(4):
471 for fil in range(4):
470 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
472 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
471
473
472 xx_inv = numpy.linalg.inv(xx)
474 xx_inv = numpy.linalg.inv(xx)
473 xx_aux = xx_inv[0, :]
475 xx_aux = xx_inv[0, :]
474
476
475 for ich in range(num_chan):
477 for ich in range(num_chan):
476 yy = jspectra[ich, ind_vel, :]
478 yy = jspectra[ich, ind_vel, :]
477 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
479 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
478
480
479 junkid = jspectra[ich, freq_dc, :] <= 0
481 junkid = jspectra[ich, freq_dc, :] <= 0
480 cjunkid = sum(junkid)
482 cjunkid = sum(junkid)
481
483
482 if cjunkid.any():
484 if cjunkid.any():
483 jspectra[ich, freq_dc, junkid.nonzero()] = (
485 jspectra[ich, freq_dc, junkid.nonzero()] = (
484 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
486 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
485
487
486 if jcspectraExist:
488 if jcspectraExist:
487 for ip in range(num_pairs):
489 for ip in range(num_pairs):
488 yy = jcspectra[ip, ind_vel, :]
490 yy = jcspectra[ip, ind_vel, :]
489 jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy)
491 jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy)
490
492
491 self.dataOut.data_spc = jspectra
493 self.dataOut.data_spc = jspectra
492 self.dataOut.data_cspc = jcspectra
494 self.dataOut.data_cspc = jcspectra
493
495
494 return self.dataOut
496 return self.dataOut
495
497
496 class removeInterference(Operation):
498 class removeInterference(Operation):
497
499
498 def removeInterference2(self):
500 def removeInterference2(self):
499
501
500 cspc = self.dataOut.data_cspc
502 cspc = self.dataOut.data_cspc
501 spc = self.dataOut.data_spc
503 spc = self.dataOut.data_spc
502 Heights = numpy.arange(cspc.shape[2])
504 Heights = numpy.arange(cspc.shape[2])
503 realCspc = numpy.abs(cspc)
505 realCspc = numpy.abs(cspc)
504
506
505 for i in range(cspc.shape[0]):
507 for i in range(cspc.shape[0]):
506 LinePower= numpy.sum(realCspc[i], axis=0)
508 LinePower= numpy.sum(realCspc[i], axis=0)
507 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
509 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
508 SelectedHeights = Heights[ numpy.where(LinePower < Threshold) ]
510 SelectedHeights = Heights[ numpy.where(LinePower < Threshold) ]
509 InterferenceSum = numpy.sum(realCspc[i,:,SelectedHeights],axis=0)
511 InterferenceSum = numpy.sum(realCspc[i,:,SelectedHeights],axis=0)
510 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
512 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
511 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
513 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
512
514
513
515
514 InterferenceRange = numpy.where(([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
516 InterferenceRange = numpy.where(([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
515 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
517 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
516 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
518 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
517 cspc[i,InterferenceRange,:] = numpy.NaN
519 cspc[i,InterferenceRange,:] = numpy.NaN
518
520
519 self.dataOut.data_cspc = cspc
521 self.dataOut.data_cspc = cspc
520
522
521 def removeInterference(self, interf=2, hei_interf=None, nhei_interf=None, offhei_interf=None):
523 def removeInterference(self, interf=2, hei_interf=None, nhei_interf=None, offhei_interf=None):
522
524
523 jspectra = self.dataOut.data_spc
525 jspectra = self.dataOut.data_spc
524 jcspectra = self.dataOut.data_cspc
526 jcspectra = self.dataOut.data_cspc
525 jnoise = self.dataOut.getNoise()
527 jnoise = self.dataOut.getNoise()
526 num_incoh = self.dataOut.nIncohInt
528 num_incoh = self.dataOut.nIncohInt
527
529
528 num_channel = jspectra.shape[0]
530 num_channel = jspectra.shape[0]
529 num_prof = jspectra.shape[1]
531 num_prof = jspectra.shape[1]
530 num_hei = jspectra.shape[2]
532 num_hei = jspectra.shape[2]
531
533
532 # hei_interf
534 # hei_interf
533 if hei_interf is None:
535 if hei_interf is None:
534 count_hei = int(num_hei / 2)
536 count_hei = int(num_hei / 2)
535 hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei
537 hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei
536 hei_interf = numpy.asarray(hei_interf)[0]
538 hei_interf = numpy.asarray(hei_interf)[0]
537 # nhei_interf
539 # nhei_interf
538 if (nhei_interf == None):
540 if (nhei_interf == None):
539 nhei_interf = 5
541 nhei_interf = 5
540 if (nhei_interf < 1):
542 if (nhei_interf < 1):
541 nhei_interf = 1
543 nhei_interf = 1
542 if (nhei_interf > count_hei):
544 if (nhei_interf > count_hei):
543 nhei_interf = count_hei
545 nhei_interf = count_hei
544 if (offhei_interf == None):
546 if (offhei_interf == None):
545 offhei_interf = 0
547 offhei_interf = 0
546
548
547 ind_hei = list(range(num_hei))
549 ind_hei = list(range(num_hei))
548 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
550 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
549 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
551 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
550 mask_prof = numpy.asarray(list(range(num_prof)))
552 mask_prof = numpy.asarray(list(range(num_prof)))
551 num_mask_prof = mask_prof.size
553 num_mask_prof = mask_prof.size
552 comp_mask_prof = [0, num_prof / 2]
554 comp_mask_prof = [0, num_prof / 2]
553
555
554 # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
556 # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
555 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
557 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
556 jnoise = numpy.nan
558 jnoise = numpy.nan
557 noise_exist = jnoise[0] < numpy.Inf
559 noise_exist = jnoise[0] < numpy.Inf
558
560
559 # Subrutina de Remocion de la Interferencia
561 # Subrutina de Remocion de la Interferencia
560 for ich in range(num_channel):
562 for ich in range(num_channel):
561 # Se ordena los espectros segun su potencia (menor a mayor)
563 # Se ordena los espectros segun su potencia (menor a mayor)
562 power = jspectra[ich, mask_prof, :]
564 power = jspectra[ich, mask_prof, :]
563 power = power[:, hei_interf]
565 power = power[:, hei_interf]
564 power = power.sum(axis=0)
566 power = power.sum(axis=0)
565 psort = power.ravel().argsort()
567 psort = power.ravel().argsort()
566
568
567 # Se estima la interferencia promedio en los Espectros de Potencia empleando
569 # Se estima la interferencia promedio en los Espectros de Potencia empleando
568 junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range(
570 junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range(
569 offhei_interf, nhei_interf + offhei_interf))]]]
571 offhei_interf, nhei_interf + offhei_interf))]]]
570
572
571 if noise_exist:
573 if noise_exist:
572 # tmp_noise = jnoise[ich] / num_prof
574 # tmp_noise = jnoise[ich] / num_prof
573 tmp_noise = jnoise[ich]
575 tmp_noise = jnoise[ich]
574 junkspc_interf = junkspc_interf - tmp_noise
576 junkspc_interf = junkspc_interf - tmp_noise
575 #junkspc_interf[:,comp_mask_prof] = 0
577 #junkspc_interf[:,comp_mask_prof] = 0
576
578
577 jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf
579 jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf
578 jspc_interf = jspc_interf.transpose()
580 jspc_interf = jspc_interf.transpose()
579 # Calculando el espectro de interferencia promedio
581 # Calculando el espectro de interferencia promedio
580 noiseid = numpy.where(
582 noiseid = numpy.where(
581 jspc_interf <= tmp_noise / numpy.sqrt(num_incoh))
583 jspc_interf <= tmp_noise / numpy.sqrt(num_incoh))
582 noiseid = noiseid[0]
584 noiseid = noiseid[0]
583 cnoiseid = noiseid.size
585 cnoiseid = noiseid.size
584 interfid = numpy.where(
586 interfid = numpy.where(
585 jspc_interf > tmp_noise / numpy.sqrt(num_incoh))
587 jspc_interf > tmp_noise / numpy.sqrt(num_incoh))
586 interfid = interfid[0]
588 interfid = interfid[0]
587 cinterfid = interfid.size
589 cinterfid = interfid.size
588
590
589 if (cnoiseid > 0):
591 if (cnoiseid > 0):
590 jspc_interf[noiseid] = 0
592 jspc_interf[noiseid] = 0
591
593
592 # Expandiendo los perfiles a limpiar
594 # Expandiendo los perfiles a limpiar
593 if (cinterfid > 0):
595 if (cinterfid > 0):
594 new_interfid = (
596 new_interfid = (
595 numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof
597 numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof
596 new_interfid = numpy.asarray(new_interfid)
598 new_interfid = numpy.asarray(new_interfid)
597 new_interfid = {x for x in new_interfid}
599 new_interfid = {x for x in new_interfid}
598 new_interfid = numpy.array(list(new_interfid))
600 new_interfid = numpy.array(list(new_interfid))
599 new_cinterfid = new_interfid.size
601 new_cinterfid = new_interfid.size
600 else:
602 else:
601 new_cinterfid = 0
603 new_cinterfid = 0
602
604
603 for ip in range(new_cinterfid):
605 for ip in range(new_cinterfid):
604 ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort()
606 ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort()
605 jspc_interf[new_interfid[ip]
607 jspc_interf[new_interfid[ip]
606 ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]]
608 ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]]
607
609
608 jspectra[ich, :, ind_hei] = jspectra[ich, :,
610 jspectra[ich, :, ind_hei] = jspectra[ich, :,
609 ind_hei] - jspc_interf # Corregir indices
611 ind_hei] - jspc_interf # Corregir indices
610
612
611 # Removiendo la interferencia del punto de mayor interferencia
613 # Removiendo la interferencia del punto de mayor interferencia
612 ListAux = jspc_interf[mask_prof].tolist()
614 ListAux = jspc_interf[mask_prof].tolist()
613 maxid = ListAux.index(max(ListAux))
615 maxid = ListAux.index(max(ListAux))
614
616
615 if cinterfid > 0:
617 if cinterfid > 0:
616 for ip in range(cinterfid * (interf == 2) - 1):
618 for ip in range(cinterfid * (interf == 2) - 1):
617 ind = (jspectra[ich, interfid[ip], :] < tmp_noise *
619 ind = (jspectra[ich, interfid[ip], :] < tmp_noise *
618 (1 + 1 / numpy.sqrt(num_incoh))).nonzero()
620 (1 + 1 / numpy.sqrt(num_incoh))).nonzero()
619 cind = len(ind)
621 cind = len(ind)
620
622
621 if (cind > 0):
623 if (cind > 0):
622 jspectra[ich, interfid[ip], ind] = tmp_noise * \
624 jspectra[ich, interfid[ip], ind] = tmp_noise * \
623 (1 + (numpy.random.uniform(cind) - 0.5) /
625 (1 + (numpy.random.uniform(cind) - 0.5) /
624 numpy.sqrt(num_incoh))
626 numpy.sqrt(num_incoh))
625
627
626 ind = numpy.array([-2, -1, 1, 2])
628 ind = numpy.array([-2, -1, 1, 2])
627 xx = numpy.zeros([4, 4])
629 xx = numpy.zeros([4, 4])
628
630
629 for id1 in range(4):
631 for id1 in range(4):
630 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
632 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
631
633
632 xx_inv = numpy.linalg.inv(xx)
634 xx_inv = numpy.linalg.inv(xx)
633 xx = xx_inv[:, 0]
635 xx = xx_inv[:, 0]
634 ind = (ind + maxid + num_mask_prof) % num_mask_prof
636 ind = (ind + maxid + num_mask_prof) % num_mask_prof
635 yy = jspectra[ich, mask_prof[ind], :]
637 yy = jspectra[ich, mask_prof[ind], :]
636 jspectra[ich, mask_prof[maxid], :] = numpy.dot(
638 jspectra[ich, mask_prof[maxid], :] = numpy.dot(
637 yy.transpose(), xx)
639 yy.transpose(), xx)
638
640
639 indAux = (jspectra[ich, :, :] < tmp_noise *
641 indAux = (jspectra[ich, :, :] < tmp_noise *
640 (1 - 1 / numpy.sqrt(num_incoh))).nonzero()
642 (1 - 1 / numpy.sqrt(num_incoh))).nonzero()
641 jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \
643 jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \
642 (1 - 1 / numpy.sqrt(num_incoh))
644 (1 - 1 / numpy.sqrt(num_incoh))
643
645
644 # Remocion de Interferencia en el Cross Spectra
646 # Remocion de Interferencia en el Cross Spectra
645 if jcspectra is None:
647 if jcspectra is None:
646 return jspectra, jcspectra
648 return jspectra, jcspectra
647 num_pairs = int(jcspectra.size / (num_prof * num_hei))
649 num_pairs = int(jcspectra.size / (num_prof * num_hei))
648 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
650 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
649
651
650 for ip in range(num_pairs):
652 for ip in range(num_pairs):
651
653
652 #-------------------------------------------
654 #-------------------------------------------
653
655
654 cspower = numpy.abs(jcspectra[ip, mask_prof, :])
656 cspower = numpy.abs(jcspectra[ip, mask_prof, :])
655 cspower = cspower[:, hei_interf]
657 cspower = cspower[:, hei_interf]
656 cspower = cspower.sum(axis=0)
658 cspower = cspower.sum(axis=0)
657
659
658 cspsort = cspower.ravel().argsort()
660 cspsort = cspower.ravel().argsort()
659 junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range(
661 junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range(
660 offhei_interf, nhei_interf + offhei_interf))]]]
662 offhei_interf, nhei_interf + offhei_interf))]]]
661 junkcspc_interf = junkcspc_interf.transpose()
663 junkcspc_interf = junkcspc_interf.transpose()
662 jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf
664 jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf
663
665
664 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
666 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
665
667
666 median_real = int(numpy.median(numpy.real(
668 median_real = int(numpy.median(numpy.real(
667 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
669 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
668 median_imag = int(numpy.median(numpy.imag(
670 median_imag = int(numpy.median(numpy.imag(
669 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
671 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
670 comp_mask_prof = [int(e) for e in comp_mask_prof]
672 comp_mask_prof = [int(e) for e in comp_mask_prof]
671 junkcspc_interf[comp_mask_prof, :] = numpy.complex(
673 junkcspc_interf[comp_mask_prof, :] = numpy.complex(
672 median_real, median_imag)
674 median_real, median_imag)
673
675
674 for iprof in range(num_prof):
676 for iprof in range(num_prof):
675 ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort()
677 ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort()
676 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]]
678 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]]
677
679
678 # Removiendo la Interferencia
680 # Removiendo la Interferencia
679 jcspectra[ip, :, ind_hei] = jcspectra[ip,
681 jcspectra[ip, :, ind_hei] = jcspectra[ip,
680 :, ind_hei] - jcspc_interf
682 :, ind_hei] - jcspc_interf
681
683
682 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
684 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
683 maxid = ListAux.index(max(ListAux))
685 maxid = ListAux.index(max(ListAux))
684
686
685 ind = numpy.array([-2, -1, 1, 2])
687 ind = numpy.array([-2, -1, 1, 2])
686 xx = numpy.zeros([4, 4])
688 xx = numpy.zeros([4, 4])
687
689
688 for id1 in range(4):
690 for id1 in range(4):
689 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
691 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
690
692
691 xx_inv = numpy.linalg.inv(xx)
693 xx_inv = numpy.linalg.inv(xx)
692 xx = xx_inv[:, 0]
694 xx = xx_inv[:, 0]
693
695
694 ind = (ind + maxid + num_mask_prof) % num_mask_prof
696 ind = (ind + maxid + num_mask_prof) % num_mask_prof
695 yy = jcspectra[ip, mask_prof[ind], :]
697 yy = jcspectra[ip, mask_prof[ind], :]
696 jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx)
698 jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx)
697
699
698 # Guardar Resultados
700 # Guardar Resultados
699 self.dataOut.data_spc = jspectra
701 self.dataOut.data_spc = jspectra
700 self.dataOut.data_cspc = jcspectra
702 self.dataOut.data_cspc = jcspectra
701
703
702 return 1
704 return 1
703
705
704 def run(self, dataOut, interf=2,hei_interf=None, nhei_interf=None, offhei_interf=None, mode=1):
706 def run(self, dataOut, interf=2,hei_interf=None, nhei_interf=None, offhei_interf=None, mode=1):
705
707
706 self.dataOut = dataOut
708 self.dataOut = dataOut
707
709
708 if mode == 1:
710 if mode == 1:
709 self.removeInterference(interf=2,hei_interf=None, nhei_interf=None, offhei_interf=None)
711 self.removeInterference(interf=2,hei_interf=None, nhei_interf=None, offhei_interf=None)
710 elif mode == 2:
712 elif mode == 2:
711 self.removeInterference2()
713 self.removeInterference2()
712
714
713 return self.dataOut
715 return self.dataOut
714
716
715
717
716 class deflip(Operation):
718 class deflip(Operation):
717
719
718 def run(self, dataOut):
720 def run(self, dataOut):
719 # arreglo 1: (num_chan, num_profiles, num_heights)
721 # arreglo 1: (num_chan, num_profiles, num_heights)
720 self.dataOut = dataOut
722 self.dataOut = dataOut
721
723
722 # JULIA-oblicua, indice 2
724 # JULIA-oblicua, indice 2
723 # arreglo 2: (num_profiles, num_heights)
725 # arreglo 2: (num_profiles, num_heights)
724 jspectra = self.dataOut.data_spc[2]
726 jspectra = self.dataOut.data_spc[2]
725 jspectra_tmp=numpy.zeros(jspectra.shape)
727 jspectra_tmp=numpy.zeros(jspectra.shape)
726 num_profiles=jspectra.shape[0]
728 num_profiles=jspectra.shape[0]
727 freq_dc = int(num_profiles / 2)
729 freq_dc = int(num_profiles / 2)
728 # Flip con for
730 # Flip con for
729 for j in range(num_profiles):
731 for j in range(num_profiles):
730 jspectra_tmp[num_profiles-j-1]= jspectra[j]
732 jspectra_tmp[num_profiles-j-1]= jspectra[j]
731 # Intercambio perfil de DC con perfil inmediato anterior
733 # Intercambio perfil de DC con perfil inmediato anterior
732 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
734 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
733 jspectra_tmp[freq_dc]= jspectra[freq_dc]
735 jspectra_tmp[freq_dc]= jspectra[freq_dc]
734 # canal modificado es re-escrito en el arreglo de canales
736 # canal modificado es re-escrito en el arreglo de canales
735 self.dataOut.data_spc[2] = jspectra_tmp
737 self.dataOut.data_spc[2] = jspectra_tmp
736
738
737 return self.dataOut
739 return self.dataOut
738
740
739
741
740 class IncohInt(Operation):
742 class IncohInt(Operation):
741
743
742 __profIndex = 0
744 __profIndex = 0
743 __withOverapping = False
745 __withOverapping = False
744
746
745 __byTime = False
747 __byTime = False
746 __initime = None
748 __initime = None
747 __lastdatatime = None
749 __lastdatatime = None
748 __integrationtime = None
750 __integrationtime = None
749
751
750 __buffer_spc = None
752 __buffer_spc = None
751 __buffer_cspc = None
753 __buffer_cspc = None
752 __buffer_dc = None
754 __buffer_dc = None
753
755
754 __dataReady = False
756 __dataReady = False
755
757
756 __timeInterval = None
758 __timeInterval = None
757
759
758 n = None
760 n = None
759
761
760 def __init__(self):
762 def __init__(self):
761
763
762 Operation.__init__(self)
764 Operation.__init__(self)
763
765
764 def setup(self, n=None, timeInterval=None, overlapping=False):
766 def setup(self, n=None, timeInterval=None, overlapping=False):
765 """
767 """
766 Set the parameters of the integration class.
768 Set the parameters of the integration class.
767
769
768 Inputs:
770 Inputs:
769
771
770 n : Number of coherent integrations
772 n : Number of coherent integrations
771 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
773 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
772 overlapping :
774 overlapping :
773
775
774 """
776 """
775
777
776 self.__initime = None
778 self.__initime = None
777 self.__lastdatatime = 0
779 self.__lastdatatime = 0
778
780
779 self.__buffer_spc = 0
781 self.__buffer_spc = 0
780 self.__buffer_cspc = 0
782 self.__buffer_cspc = 0
781 self.__buffer_dc = 0
783 self.__buffer_dc = 0
782
784
783 self.__profIndex = 0
785 self.__profIndex = 0
784 self.__dataReady = False
786 self.__dataReady = False
785 self.__byTime = False
787 self.__byTime = False
786
788
787 if n is None and timeInterval is None:
789 if n is None and timeInterval is None:
788 raise ValueError("n or timeInterval should be specified ...")
790 raise ValueError("n or timeInterval should be specified ...")
789
791
790 if n is not None:
792 if n is not None:
791 self.n = int(n)
793 self.n = int(n)
792 else:
794 else:
793
795
794 self.__integrationtime = int(timeInterval)
796 self.__integrationtime = int(timeInterval)
795 self.n = None
797 self.n = None
796 self.__byTime = True
798 self.__byTime = True
797
799
798 def putData(self, data_spc, data_cspc, data_dc):
800 def putData(self, data_spc, data_cspc, data_dc):
799 """
801 """
800 Add a profile to the __buffer_spc and increase in one the __profileIndex
802 Add a profile to the __buffer_spc and increase in one the __profileIndex
801
803
802 """
804 """
803
805
804 self.__buffer_spc += data_spc
806 self.__buffer_spc += data_spc
805
807
806 if data_cspc is None:
808 if data_cspc is None:
807 self.__buffer_cspc = None
809 self.__buffer_cspc = None
808 else:
810 else:
809 self.__buffer_cspc += data_cspc
811 self.__buffer_cspc += data_cspc
810
812
811 if data_dc is None:
813 if data_dc is None:
812 self.__buffer_dc = None
814 self.__buffer_dc = None
813 else:
815 else:
814 self.__buffer_dc += data_dc
816 self.__buffer_dc += data_dc
815
817
816 self.__profIndex += 1
818 self.__profIndex += 1
817
819
818 return
820 return
819
821
820 def pushData(self):
822 def pushData(self):
821 """
823 """
822 Return the sum of the last profiles and the profiles used in the sum.
824 Return the sum of the last profiles and the profiles used in the sum.
823
825
824 Affected:
826 Affected:
825
827
826 self.__profileIndex
828 self.__profileIndex
827
829
828 """
830 """
829
831
830 data_spc = self.__buffer_spc
832 data_spc = self.__buffer_spc
831 data_cspc = self.__buffer_cspc
833 data_cspc = self.__buffer_cspc
832 data_dc = self.__buffer_dc
834 data_dc = self.__buffer_dc
833 n = self.__profIndex
835 n = self.__profIndex
834
836
835 self.__buffer_spc = 0
837 self.__buffer_spc = 0
836 self.__buffer_cspc = 0
838 self.__buffer_cspc = 0
837 self.__buffer_dc = 0
839 self.__buffer_dc = 0
838 self.__profIndex = 0
840 self.__profIndex = 0
839
841
840 return data_spc, data_cspc, data_dc, n
842 return data_spc, data_cspc, data_dc, n
841
843
842 def byProfiles(self, *args):
844 def byProfiles(self, *args):
843
845
844 self.__dataReady = False
846 self.__dataReady = False
845 avgdata_spc = None
847 avgdata_spc = None
846 avgdata_cspc = None
848 avgdata_cspc = None
847 avgdata_dc = None
849 avgdata_dc = None
848
850
849 self.putData(*args)
851 self.putData(*args)
850
852
851 if self.__profIndex == self.n:
853 if self.__profIndex == self.n:
852
854
853 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
855 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
854 self.n = n
856 self.n = n
855 self.__dataReady = True
857 self.__dataReady = True
856
858
857 return avgdata_spc, avgdata_cspc, avgdata_dc
859 return avgdata_spc, avgdata_cspc, avgdata_dc
858
860
859 def byTime(self, datatime, *args):
861 def byTime(self, datatime, *args):
860
862
861 self.__dataReady = False
863 self.__dataReady = False
862 avgdata_spc = None
864 avgdata_spc = None
863 avgdata_cspc = None
865 avgdata_cspc = None
864 avgdata_dc = None
866 avgdata_dc = None
865
867
866 self.putData(*args)
868 self.putData(*args)
867
869
868 if (datatime - self.__initime) >= self.__integrationtime:
870 if (datatime - self.__initime) >= self.__integrationtime:
869 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
871 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
870 self.n = n
872 self.n = n
871 self.__dataReady = True
873 self.__dataReady = True
872
874
873 return avgdata_spc, avgdata_cspc, avgdata_dc
875 return avgdata_spc, avgdata_cspc, avgdata_dc
874
876
875 def integrate(self, datatime, *args):
877 def integrate(self, datatime, *args):
876
878
877 if self.__profIndex == 0:
879 if self.__profIndex == 0:
878 self.__initime = datatime
880 self.__initime = datatime
879
881
880 if self.__byTime:
882 if self.__byTime:
881 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(
883 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(
882 datatime, *args)
884 datatime, *args)
883 else:
885 else:
884 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
886 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
885
887
886 if not self.__dataReady:
888 if not self.__dataReady:
887 return None, None, None, None
889 return None, None, None, None
888
890
889 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
891 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
890
892
891 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
893 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
892 if n == 1:
894 if n == 1:
893 return dataOut
895 return dataOut
894
896
895 dataOut.flagNoData = True
897 dataOut.flagNoData = True
896
898
897 if not self.isConfig:
899 if not self.isConfig:
898 self.setup(n, timeInterval, overlapping)
900 self.setup(n, timeInterval, overlapping)
899 self.isConfig = True
901 self.isConfig = True
900
902
901 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
903 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
902 dataOut.data_spc,
904 dataOut.data_spc,
903 dataOut.data_cspc,
905 dataOut.data_cspc,
904 dataOut.data_dc)
906 dataOut.data_dc)
905
907
906 if self.__dataReady:
908 if self.__dataReady:
907
909
908 dataOut.data_spc = avgdata_spc
910 dataOut.data_spc = avgdata_spc
909 dataOut.data_cspc = avgdata_cspc
911 dataOut.data_cspc = avgdata_cspc
910 dataOut.data_dc = avgdata_dc
912 dataOut.data_dc = avgdata_dc
911 dataOut.nIncohInt *= self.n
913 dataOut.nIncohInt *= self.n
912 dataOut.utctime = avgdatatime
914 dataOut.utctime = avgdatatime
913 dataOut.flagNoData = False
915 dataOut.flagNoData = False
914
916
915 return dataOut
917 return dataOut
916
918
917 class dopplerFlip(Operation):
919 class dopplerFlip(Operation):
918
920
919 def run(self, dataOut):
921 def run(self, dataOut):
920 # arreglo 1: (num_chan, num_profiles, num_heights)
922 # arreglo 1: (num_chan, num_profiles, num_heights)
921 self.dataOut = dataOut
923 self.dataOut = dataOut
922 # JULIA-oblicua, indice 2
924 # JULIA-oblicua, indice 2
923 # arreglo 2: (num_profiles, num_heights)
925 # arreglo 2: (num_profiles, num_heights)
924 jspectra = self.dataOut.data_spc[2]
926 jspectra = self.dataOut.data_spc[2]
925 jspectra_tmp = numpy.zeros(jspectra.shape)
927 jspectra_tmp = numpy.zeros(jspectra.shape)
926 num_profiles = jspectra.shape[0]
928 num_profiles = jspectra.shape[0]
927 freq_dc = int(num_profiles / 2)
929 freq_dc = int(num_profiles / 2)
928 # Flip con for
930 # Flip con for
929 for j in range(num_profiles):
931 for j in range(num_profiles):
930 jspectra_tmp[num_profiles-j-1]= jspectra[j]
932 jspectra_tmp[num_profiles-j-1]= jspectra[j]
931 # Intercambio perfil de DC con perfil inmediato anterior
933 # Intercambio perfil de DC con perfil inmediato anterior
932 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
934 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
933 jspectra_tmp[freq_dc]= jspectra[freq_dc]
935 jspectra_tmp[freq_dc]= jspectra[freq_dc]
934 # canal modificado es re-escrito en el arreglo de canales
936 # canal modificado es re-escrito en el arreglo de canales
935 self.dataOut.data_spc[2] = jspectra_tmp
937 self.dataOut.data_spc[2] = jspectra_tmp
936
938
937 return self.dataOut No newline at end of file
939 return self.dataOut
@@ -1,1627 +1,1625
1 import sys
1 import sys
2 import numpy,math
2 import numpy,math
3 from scipy import interpolate
3 from scipy import interpolate
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
5 from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon
5 from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon
6 from schainpy.utils import log
6 from schainpy.utils import log
7 from time import time
7 from time import time
8 # voltage proc master
8 # voltage proc master
9
9
10 class VoltageProc(ProcessingUnit):
10 class VoltageProc(ProcessingUnit):
11
11
12 def __init__(self):
12 def __init__(self):
13
13
14 ProcessingUnit.__init__(self)
14 ProcessingUnit.__init__(self)
15
15
16 self.dataOut = Voltage()
16 self.dataOut = Voltage()
17 self.flip = 1
17 self.flip = 1
18 self.setupReq = False
18 self.setupReq = False
19
19
20 def run(self, runNextUnit = 0):
20 def run(self, runNextUnit = 0):
21
21
22 if self.dataIn.type == 'AMISR':
22 if self.dataIn.type == 'AMISR':
23 self.__updateObjFromAmisrInput()
23 self.__updateObjFromAmisrInput()
24
24
25 if self.dataIn.type == 'Voltage':
25 if self.dataIn.type == 'Voltage':
26 self.dataOut.copy(self.dataIn)
26 self.dataOut.copy(self.dataIn)
27 self.dataOut.runNextUnit = runNextUnit
27 self.dataOut.runNextUnit = runNextUnit
28
28
29
29
30 def __updateObjFromAmisrInput(self):
30 def __updateObjFromAmisrInput(self):
31
31
32 self.dataOut.timeZone = self.dataIn.timeZone
32 self.dataOut.timeZone = self.dataIn.timeZone
33 self.dataOut.dstFlag = self.dataIn.dstFlag
33 self.dataOut.dstFlag = self.dataIn.dstFlag
34 self.dataOut.errorCount = self.dataIn.errorCount
34 self.dataOut.errorCount = self.dataIn.errorCount
35 self.dataOut.useLocalTime = self.dataIn.useLocalTime
35 self.dataOut.useLocalTime = self.dataIn.useLocalTime
36
36
37 self.dataOut.flagNoData = self.dataIn.flagNoData
37 self.dataOut.flagNoData = self.dataIn.flagNoData
38 self.dataOut.data = self.dataIn.data
38 self.dataOut.data = self.dataIn.data
39 self.dataOut.utctime = self.dataIn.utctime
39 self.dataOut.utctime = self.dataIn.utctime
40 self.dataOut.channelList = self.dataIn.channelList
40 self.dataOut.channelList = self.dataIn.channelList
41 #self.dataOut.timeInterval = self.dataIn.timeInterval
41 #self.dataOut.timeInterval = self.dataIn.timeInterval
42 self.dataOut.heightList = self.dataIn.heightList
42 self.dataOut.heightList = self.dataIn.heightList
43 self.dataOut.nProfiles = self.dataIn.nProfiles
43 self.dataOut.nProfiles = self.dataIn.nProfiles
44
44
45 self.dataOut.nCohInt = self.dataIn.nCohInt
45 self.dataOut.nCohInt = self.dataIn.nCohInt
46 self.dataOut.ippSeconds = self.dataIn.ippSeconds
46 self.dataOut.ippSeconds = self.dataIn.ippSeconds
47 self.dataOut.frequency = self.dataIn.frequency
47 self.dataOut.frequency = self.dataIn.frequency
48
48
49 self.dataOut.azimuth = self.dataIn.azimuth
49 self.dataOut.azimuth = self.dataIn.azimuth
50 self.dataOut.zenith = self.dataIn.zenith
50 self.dataOut.zenith = self.dataIn.zenith
51
51
52 self.dataOut.beam.codeList = self.dataIn.beam.codeList
52 self.dataOut.beam.codeList = self.dataIn.beam.codeList
53 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
53 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
54 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
54 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
55
55
56
56
57 class selectChannels(Operation):
57 class selectChannels(Operation):
58
58
59 def run(self, dataOut, channelList):
59 def run(self, dataOut, channelList):
60
60
61 channelIndexList = []
61 channelIndexList = []
62 self.dataOut = dataOut
62 self.dataOut = dataOut
63 for channel in channelList:
63 for channel in channelList:
64 if channel not in self.dataOut.channelList:
64 if channel not in self.dataOut.channelList:
65 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
65 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
66
66
67 index = self.dataOut.channelList.index(channel)
67 index = self.dataOut.channelList.index(channel)
68 channelIndexList.append(index)
68 channelIndexList.append(index)
69 self.selectChannelsByIndex(channelIndexList)
69 self.selectChannelsByIndex(channelIndexList)
70 return self.dataOut
70 return self.dataOut
71
71
72 def selectChannelsByIndex(self, channelIndexList):
72 def selectChannelsByIndex(self, channelIndexList):
73 """
73 """
74 Selecciona un bloque de datos en base a canales segun el channelIndexList
74 Selecciona un bloque de datos en base a canales segun el channelIndexList
75
75
76 Input:
76 Input:
77 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
77 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
78
78
79 Affected:
79 Affected:
80 self.dataOut.data
80 self.dataOut.data
81 self.dataOut.channelIndexList
81 self.dataOut.channelIndexList
82 self.dataOut.nChannels
82 self.dataOut.nChannels
83 self.dataOut.m_ProcessingHeader.totalSpectra
83 self.dataOut.m_ProcessingHeader.totalSpectra
84 self.dataOut.systemHeaderObj.numChannels
84 self.dataOut.systemHeaderObj.numChannels
85 self.dataOut.m_ProcessingHeader.blockSize
85 self.dataOut.m_ProcessingHeader.blockSize
86
86
87 Return:
87 Return:
88 None
88 None
89 """
89 """
90
90
91 for channelIndex in channelIndexList:
91 for channelIndex in channelIndexList:
92 if channelIndex not in self.dataOut.channelIndexList:
92 if channelIndex not in self.dataOut.channelIndexList:
93 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
93 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
94
94
95 if self.dataOut.type == 'Voltage':
95 if self.dataOut.type == 'Voltage':
96 if self.dataOut.flagDataAsBlock:
96 if self.dataOut.flagDataAsBlock:
97 """
97 """
98 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
98 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
99 """
99 """
100 data = self.dataOut.data[channelIndexList,:,:]
100 data = self.dataOut.data[channelIndexList,:,:]
101 else:
101 else:
102 data = self.dataOut.data[channelIndexList,:]
102 data = self.dataOut.data[channelIndexList,:]
103
103
104 self.dataOut.data = data
104 self.dataOut.data = data
105 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
105 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
106 self.dataOut.channelList = range(len(channelIndexList))
106 self.dataOut.channelList = range(len(channelIndexList))
107
107
108 elif self.dataOut.type == 'Spectra':
108 elif self.dataOut.type == 'Spectra':
109 data_spc = self.dataOut.data_spc[channelIndexList, :]
109 data_spc = self.dataOut.data_spc[channelIndexList, :]
110 data_dc = self.dataOut.data_dc[channelIndexList, :]
110 data_dc = self.dataOut.data_dc[channelIndexList, :]
111
111
112 self.dataOut.data_spc = data_spc
112 self.dataOut.data_spc = data_spc
113 self.dataOut.data_dc = data_dc
113 self.dataOut.data_dc = data_dc
114
114
115 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
115 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
116 self.dataOut.channelList = range(len(channelIndexList))
116 self.dataOut.channelList = range(len(channelIndexList))
117 self.__selectPairsByChannel(channelIndexList)
117 self.__selectPairsByChannel(channelIndexList)
118
118
119 return 1
119 return 1
120
120
121 def __selectPairsByChannel(self, channelList=None):
121 def __selectPairsByChannel(self, channelList=None):
122
122
123 if channelList == None:
123 if channelList == None:
124 return
124 return
125
125
126 pairsIndexListSelected = []
126 pairsIndexListSelected = []
127 for pairIndex in self.dataOut.pairsIndexList:
127 for pairIndex in self.dataOut.pairsIndexList:
128 # First pair
128 # First pair
129 if self.dataOut.pairsList[pairIndex][0] not in channelList:
129 if self.dataOut.pairsList[pairIndex][0] not in channelList:
130 continue
130 continue
131 # Second pair
131 # Second pair
132 if self.dataOut.pairsList[pairIndex][1] not in channelList:
132 if self.dataOut.pairsList[pairIndex][1] not in channelList:
133 continue
133 continue
134
134
135 pairsIndexListSelected.append(pairIndex)
135 pairsIndexListSelected.append(pairIndex)
136
136
137 if not pairsIndexListSelected:
137 if not pairsIndexListSelected:
138 self.dataOut.data_cspc = None
138 self.dataOut.data_cspc = None
139 self.dataOut.pairsList = []
139 self.dataOut.pairsList = []
140 return
140 return
141
141
142 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
142 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
143 self.dataOut.pairsList = [self.dataOut.pairsList[i]
143 self.dataOut.pairsList = [self.dataOut.pairsList[i]
144 for i in pairsIndexListSelected]
144 for i in pairsIndexListSelected]
145
145
146 return
146 return
147
147
148 class selectHeights(Operation):
148 class selectHeights(Operation):
149
149
150 def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None):
150 def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None):
151 """
151 """
152 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
152 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
153 minHei <= height <= maxHei
153 minHei <= height <= maxHei
154
154
155 Input:
155 Input:
156 minHei : valor minimo de altura a considerar
156 minHei : valor minimo de altura a considerar
157 maxHei : valor maximo de altura a considerar
157 maxHei : valor maximo de altura a considerar
158
158
159 Affected:
159 Affected:
160 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
160 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
161
161
162 Return:
162 Return:
163 1 si el metodo se ejecuto con exito caso contrario devuelve 0
163 1 si el metodo se ejecuto con exito caso contrario devuelve 0
164 """
164 """
165
165
166 self.dataOut = dataOut
166 self.dataOut = dataOut
167
167
168 if type(minHei) == int or type(minHei) == float:
168 if type(minHei) == int or type(minHei) == float:
169 v_minHei= True
169 v_minHei= True
170 else:
170 else:
171 v_minHei= False
171 v_minHei= False
172
172
173 if v_minHei and maxHei:
173 if v_minHei and maxHei:
174 if (minHei < self.dataOut.heightList[0]):
174 if (minHei < self.dataOut.heightList[0]):
175 minHei = self.dataOut.heightList[0]
175 minHei = self.dataOut.heightList[0]
176
176
177 if (maxHei > self.dataOut.heightList[-1]):
177 if (maxHei > self.dataOut.heightList[-1]):
178 maxHei = self.dataOut.heightList[-1]
178 maxHei = self.dataOut.heightList[-1]
179
179
180 minIndex = 0
180 minIndex = 0
181 maxIndex = 0
181 maxIndex = 0
182 heights = self.dataOut.heightList
182 heights = self.dataOut.heightList
183 inda = numpy.where(heights >= minHei)
183 inda = numpy.where(heights >= minHei)
184 indb = numpy.where(heights <= maxHei)
184 indb = numpy.where(heights <= maxHei)
185
185
186 try:
186 try:
187 minIndex = inda[0][0]
187 minIndex = inda[0][0]
188 except:
188 except:
189 minIndex = 0
189 minIndex = 0
190
190
191 try:
191 try:
192 maxIndex = indb[0][-1]
192 maxIndex = indb[0][-1]
193 except:
193 except:
194 maxIndex = len(heights)
194 maxIndex = len(heights)
195 self.selectHeightsByIndex(minIndex, maxIndex)
195 self.selectHeightsByIndex(minIndex, maxIndex)
196
196
197 return self.dataOut
197 return self.dataOut
198
198
199 def selectHeightsByIndex(self, minIndex, maxIndex):
199 def selectHeightsByIndex(self, minIndex, maxIndex):
200 """
200 """
201 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
201 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
202 minIndex <= index <= maxIndex
202 minIndex <= index <= maxIndex
203
203
204 Input:
204 Input:
205 minIndex : valor de indice minimo de altura a considerar
205 minIndex : valor de indice minimo de altura a considerar
206 maxIndex : valor de indice maximo de altura a considerar
206 maxIndex : valor de indice maximo de altura a considerar
207
207
208 Affected:
208 Affected:
209 self.dataOut.data
209 self.dataOut.data
210 self.dataOut.heightList
210 self.dataOut.heightList
211
211
212 Return:
212 Return:
213 1 si el metodo se ejecuto con exito caso contrario devuelve 0
213 1 si el metodo se ejecuto con exito caso contrario devuelve 0
214 """
214 """
215
215
216 if self.dataOut.type == 'Voltage':
216 if self.dataOut.type == 'Voltage':
217 print(minIndex)
218 print(maxIndex)
219 if (minIndex < 0) or (minIndex > maxIndex):
217 if (minIndex < 0) or (minIndex > maxIndex):
220 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
218 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
221
219
222 if (maxIndex >= self.dataOut.nHeights):
220 if (maxIndex >= self.dataOut.nHeights):
223 maxIndex = self.dataOut.nHeights
221 maxIndex = self.dataOut.nHeights
224
222
225 #voltage
223 #voltage
226 if self.dataOut.flagDataAsBlock:
224 if self.dataOut.flagDataAsBlock:
227 """
225 """
228 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
226 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
229 """
227 """
230 data = self.dataOut.data[:,:, minIndex:maxIndex]
228 data = self.dataOut.data[:,:, minIndex:maxIndex]
231 else:
229 else:
232 data = self.dataOut.data[:, minIndex:maxIndex]
230 data = self.dataOut.data[:, minIndex:maxIndex]
233
231
234 # firstHeight = self.dataOut.heightList[minIndex]
232 # firstHeight = self.dataOut.heightList[minIndex]
235
233
236 self.dataOut.data = data
234 self.dataOut.data = data
237 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
235 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
238
236
239 if self.dataOut.nHeights <= 1:
237 if self.dataOut.nHeights <= 1:
240 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
238 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
241 elif self.dataOut.type == 'Spectra':
239 elif self.dataOut.type == 'Spectra':
242 if (minIndex < 0) or (minIndex > maxIndex):
240 if (minIndex < 0) or (minIndex > maxIndex):
243 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
241 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
244 minIndex, maxIndex))
242 minIndex, maxIndex))
245
243
246 if (maxIndex >= self.dataOut.nHeights):
244 if (maxIndex >= self.dataOut.nHeights):
247 maxIndex = self.dataOut.nHeights - 1
245 maxIndex = self.dataOut.nHeights - 1
248
246
249 # Spectra
247 # Spectra
250 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
248 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
251
249
252 data_cspc = None
250 data_cspc = None
253 if self.dataOut.data_cspc is not None:
251 if self.dataOut.data_cspc is not None:
254 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
252 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
255
253
256 data_dc = None
254 data_dc = None
257 if self.dataOut.data_dc is not None:
255 if self.dataOut.data_dc is not None:
258 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
256 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
259
257
260 self.dataOut.data_spc = data_spc
258 self.dataOut.data_spc = data_spc
261 self.dataOut.data_cspc = data_cspc
259 self.dataOut.data_cspc = data_cspc
262 self.dataOut.data_dc = data_dc
260 self.dataOut.data_dc = data_dc
263
261
264 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
262 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
265
263
266 return 1
264 return 1
267
265
268
266
269 class filterByHeights(Operation):
267 class filterByHeights(Operation):
270
268
271 def run(self, dataOut, window):
269 def run(self, dataOut, window):
272
270
273 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
271 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
274
272
275 if window == None:
273 if window == None:
276 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
274 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
277
275
278 newdelta = deltaHeight * window
276 newdelta = deltaHeight * window
279 r = dataOut.nHeights % window
277 r = dataOut.nHeights % window
280 newheights = (dataOut.nHeights-r)/window
278 newheights = (dataOut.nHeights-r)/window
281
279
282 if newheights <= 1:
280 if newheights <= 1:
283 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
281 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
284
282
285 if dataOut.flagDataAsBlock:
283 if dataOut.flagDataAsBlock:
286 """
284 """
287 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
285 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
288 """
286 """
289 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
287 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
290 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
288 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
291 buffer = numpy.sum(buffer,3)
289 buffer = numpy.sum(buffer,3)
292
290
293 else:
291 else:
294 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
292 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
295 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
293 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
296 buffer = numpy.sum(buffer,2)
294 buffer = numpy.sum(buffer,2)
297
295
298 dataOut.data = buffer
296 dataOut.data = buffer
299 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
297 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
300 dataOut.windowOfFilter = window
298 dataOut.windowOfFilter = window
301
299
302 return dataOut
300 return dataOut
303
301
304
302
305 class setH0(Operation):
303 class setH0(Operation):
306
304
307 def run(self, dataOut, h0, deltaHeight = None):
305 def run(self, dataOut, h0, deltaHeight = None):
308
306
309 if not deltaHeight:
307 if not deltaHeight:
310 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
308 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
311
309
312 nHeights = dataOut.nHeights
310 nHeights = dataOut.nHeights
313
311
314 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
312 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
315
313
316 dataOut.heightList = newHeiRange
314 dataOut.heightList = newHeiRange
317
315
318 return dataOut
316 return dataOut
319
317
320
318
321 class deFlip(Operation):
319 class deFlip(Operation):
322
320
323 def run(self, dataOut, channelList = []):
321 def run(self, dataOut, channelList = []):
324
322
325 data = dataOut.data.copy()
323 data = dataOut.data.copy()
326
324
327 if dataOut.flagDataAsBlock:
325 if dataOut.flagDataAsBlock:
328 flip = self.flip
326 flip = self.flip
329 profileList = list(range(dataOut.nProfiles))
327 profileList = list(range(dataOut.nProfiles))
330
328
331 if not channelList:
329 if not channelList:
332 for thisProfile in profileList:
330 for thisProfile in profileList:
333 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
331 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
334 flip *= -1.0
332 flip *= -1.0
335 else:
333 else:
336 for thisChannel in channelList:
334 for thisChannel in channelList:
337 if thisChannel not in dataOut.channelList:
335 if thisChannel not in dataOut.channelList:
338 continue
336 continue
339
337
340 for thisProfile in profileList:
338 for thisProfile in profileList:
341 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
339 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
342 flip *= -1.0
340 flip *= -1.0
343
341
344 self.flip = flip
342 self.flip = flip
345
343
346 else:
344 else:
347 if not channelList:
345 if not channelList:
348 data[:,:] = data[:,:]*self.flip
346 data[:,:] = data[:,:]*self.flip
349 else:
347 else:
350 for thisChannel in channelList:
348 for thisChannel in channelList:
351 if thisChannel not in dataOut.channelList:
349 if thisChannel not in dataOut.channelList:
352 continue
350 continue
353
351
354 data[thisChannel,:] = data[thisChannel,:]*self.flip
352 data[thisChannel,:] = data[thisChannel,:]*self.flip
355
353
356 self.flip *= -1.
354 self.flip *= -1.
357
355
358 dataOut.data = data
356 dataOut.data = data
359
357
360 return dataOut
358 return dataOut
361
359
362
360
363 class setAttribute(Operation):
361 class setAttribute(Operation):
364 '''
362 '''
365 Set an arbitrary attribute(s) to dataOut
363 Set an arbitrary attribute(s) to dataOut
366 '''
364 '''
367
365
368 def __init__(self):
366 def __init__(self):
369
367
370 Operation.__init__(self)
368 Operation.__init__(self)
371 self._ready = False
369 self._ready = False
372
370
373 def run(self, dataOut, **kwargs):
371 def run(self, dataOut, **kwargs):
374
372
375 for key, value in kwargs.items():
373 for key, value in kwargs.items():
376 setattr(dataOut, key, value)
374 setattr(dataOut, key, value)
377
375
378 return dataOut
376 return dataOut
379
377
380
378
381 @MPDecorator
379 @MPDecorator
382 class printAttribute(Operation):
380 class printAttribute(Operation):
383 '''
381 '''
384 Print an arbitrary attribute of dataOut
382 Print an arbitrary attribute of dataOut
385 '''
383 '''
386
384
387 def __init__(self):
385 def __init__(self):
388
386
389 Operation.__init__(self)
387 Operation.__init__(self)
390
388
391 def run(self, dataOut, attributes):
389 def run(self, dataOut, attributes):
392
390
393 if isinstance(attributes, str):
391 if isinstance(attributes, str):
394 attributes = [attributes]
392 attributes = [attributes]
395 for attr in attributes:
393 for attr in attributes:
396 if hasattr(dataOut, attr):
394 if hasattr(dataOut, attr):
397 log.log(getattr(dataOut, attr), attr)
395 log.log(getattr(dataOut, attr), attr)
398
396
399
397
400 class interpolateHeights(Operation):
398 class interpolateHeights(Operation):
401
399
402 def run(self, dataOut, topLim, botLim):
400 def run(self, dataOut, topLim, botLim):
403 #69 al 72 para julia
401 #69 al 72 para julia
404 #82-84 para meteoros
402 #82-84 para meteoros
405 if len(numpy.shape(dataOut.data))==2:
403 if len(numpy.shape(dataOut.data))==2:
406 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
404 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
407 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
405 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
408 #dataOut.data[:,botLim:limSup+1] = sampInterp
406 #dataOut.data[:,botLim:limSup+1] = sampInterp
409 dataOut.data[:,botLim:topLim+1] = sampInterp
407 dataOut.data[:,botLim:topLim+1] = sampInterp
410 else:
408 else:
411 nHeights = dataOut.data.shape[2]
409 nHeights = dataOut.data.shape[2]
412 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
410 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
413 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
411 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
414 f = interpolate.interp1d(x, y, axis = 2)
412 f = interpolate.interp1d(x, y, axis = 2)
415 xnew = numpy.arange(botLim,topLim+1)
413 xnew = numpy.arange(botLim,topLim+1)
416 ynew = f(xnew)
414 ynew = f(xnew)
417 dataOut.data[:,:,botLim:topLim+1] = ynew
415 dataOut.data[:,:,botLim:topLim+1] = ynew
418
416
419 return dataOut
417 return dataOut
420
418
421
419
422 class CohInt(Operation):
420 class CohInt(Operation):
423
421
424 isConfig = False
422 isConfig = False
425 __profIndex = 0
423 __profIndex = 0
426 __byTime = False
424 __byTime = False
427 __initime = None
425 __initime = None
428 __lastdatatime = None
426 __lastdatatime = None
429 __integrationtime = None
427 __integrationtime = None
430 __buffer = None
428 __buffer = None
431 __bufferStride = []
429 __bufferStride = []
432 __dataReady = False
430 __dataReady = False
433 __profIndexStride = 0
431 __profIndexStride = 0
434 __dataToPutStride = False
432 __dataToPutStride = False
435 n = None
433 n = None
436
434
437 def __init__(self, **kwargs):
435 def __init__(self, **kwargs):
438
436
439 Operation.__init__(self, **kwargs)
437 Operation.__init__(self, **kwargs)
440
438
441 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
439 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
442 """
440 """
443 Set the parameters of the integration class.
441 Set the parameters of the integration class.
444
442
445 Inputs:
443 Inputs:
446
444
447 n : Number of coherent integrations
445 n : Number of coherent integrations
448 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
446 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
449 overlapping :
447 overlapping :
450 """
448 """
451
449
452 self.__initime = None
450 self.__initime = None
453 self.__lastdatatime = 0
451 self.__lastdatatime = 0
454 self.__buffer = None
452 self.__buffer = None
455 self.__dataReady = False
453 self.__dataReady = False
456 self.byblock = byblock
454 self.byblock = byblock
457 self.stride = stride
455 self.stride = stride
458
456
459 if n == None and timeInterval == None:
457 if n == None and timeInterval == None:
460 raise ValueError("n or timeInterval should be specified ...")
458 raise ValueError("n or timeInterval should be specified ...")
461
459
462 if n != None:
460 if n != None:
463 self.n = n
461 self.n = n
464 self.__byTime = False
462 self.__byTime = False
465 else:
463 else:
466 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
464 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
467 self.n = 9999
465 self.n = 9999
468 self.__byTime = True
466 self.__byTime = True
469
467
470 if overlapping:
468 if overlapping:
471 self.__withOverlapping = True
469 self.__withOverlapping = True
472 self.__buffer = None
470 self.__buffer = None
473 else:
471 else:
474 self.__withOverlapping = False
472 self.__withOverlapping = False
475 self.__buffer = 0
473 self.__buffer = 0
476
474
477 self.__profIndex = 0
475 self.__profIndex = 0
478
476
479 def putData(self, data):
477 def putData(self, data):
480
478
481 """
479 """
482 Add a profile to the __buffer and increase in one the __profileIndex
480 Add a profile to the __buffer and increase in one the __profileIndex
483
481
484 """
482 """
485
483
486 if not self.__withOverlapping:
484 if not self.__withOverlapping:
487 self.__buffer += data.copy()
485 self.__buffer += data.copy()
488 self.__profIndex += 1
486 self.__profIndex += 1
489 return
487 return
490
488
491 #Overlapping data
489 #Overlapping data
492 nChannels, nHeis = data.shape
490 nChannels, nHeis = data.shape
493 data = numpy.reshape(data, (1, nChannels, nHeis))
491 data = numpy.reshape(data, (1, nChannels, nHeis))
494
492
495 #If the buffer is empty then it takes the data value
493 #If the buffer is empty then it takes the data value
496 if self.__buffer is None:
494 if self.__buffer is None:
497 self.__buffer = data
495 self.__buffer = data
498 self.__profIndex += 1
496 self.__profIndex += 1
499 return
497 return
500
498
501 #If the buffer length is lower than n then stakcing the data value
499 #If the buffer length is lower than n then stakcing the data value
502 if self.__profIndex < self.n:
500 if self.__profIndex < self.n:
503 self.__buffer = numpy.vstack((self.__buffer, data))
501 self.__buffer = numpy.vstack((self.__buffer, data))
504 self.__profIndex += 1
502 self.__profIndex += 1
505 return
503 return
506
504
507 #If the buffer length is equal to n then replacing the last buffer value with the data value
505 #If the buffer length is equal to n then replacing the last buffer value with the data value
508 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
506 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
509 self.__buffer[self.n-1] = data
507 self.__buffer[self.n-1] = data
510 self.__profIndex = self.n
508 self.__profIndex = self.n
511 return
509 return
512
510
513
511
514 def pushData(self):
512 def pushData(self):
515 """
513 """
516 Return the sum of the last profiles and the profiles used in the sum.
514 Return the sum of the last profiles and the profiles used in the sum.
517
515
518 Affected:
516 Affected:
519
517
520 self.__profileIndex
518 self.__profileIndex
521
519
522 """
520 """
523
521
524 if not self.__withOverlapping:
522 if not self.__withOverlapping:
525 data = self.__buffer
523 data = self.__buffer
526 n = self.__profIndex
524 n = self.__profIndex
527
525
528 self.__buffer = 0
526 self.__buffer = 0
529 self.__profIndex = 0
527 self.__profIndex = 0
530
528
531 return data, n
529 return data, n
532
530
533 #Integration with Overlapping
531 #Integration with Overlapping
534 data = numpy.sum(self.__buffer, axis=0)
532 data = numpy.sum(self.__buffer, axis=0)
535 # print data
533 # print data
536 # raise
534 # raise
537 n = self.__profIndex
535 n = self.__profIndex
538
536
539 return data, n
537 return data, n
540
538
541 def byProfiles(self, data):
539 def byProfiles(self, data):
542
540
543 self.__dataReady = False
541 self.__dataReady = False
544 avgdata = None
542 avgdata = None
545 # n = None
543 # n = None
546 # print data
544 # print data
547 # raise
545 # raise
548 self.putData(data)
546 self.putData(data)
549
547
550 if self.__profIndex == self.n:
548 if self.__profIndex == self.n:
551 avgdata, n = self.pushData()
549 avgdata, n = self.pushData()
552 self.__dataReady = True
550 self.__dataReady = True
553
551
554 return avgdata
552 return avgdata
555
553
556 def byTime(self, data, datatime):
554 def byTime(self, data, datatime):
557
555
558 self.__dataReady = False
556 self.__dataReady = False
559 avgdata = None
557 avgdata = None
560 n = None
558 n = None
561
559
562 self.putData(data)
560 self.putData(data)
563
561
564 if (datatime - self.__initime) >= self.__integrationtime:
562 if (datatime - self.__initime) >= self.__integrationtime:
565 avgdata, n = self.pushData()
563 avgdata, n = self.pushData()
566 self.n = n
564 self.n = n
567 self.__dataReady = True
565 self.__dataReady = True
568
566
569 return avgdata
567 return avgdata
570
568
571 def integrateByStride(self, data, datatime):
569 def integrateByStride(self, data, datatime):
572 # print data
570 # print data
573 if self.__profIndex == 0:
571 if self.__profIndex == 0:
574 self.__buffer = [[data.copy(), datatime]]
572 self.__buffer = [[data.copy(), datatime]]
575 else:
573 else:
576 self.__buffer.append([data.copy(),datatime])
574 self.__buffer.append([data.copy(),datatime])
577 self.__profIndex += 1
575 self.__profIndex += 1
578 self.__dataReady = False
576 self.__dataReady = False
579
577
580 if self.__profIndex == self.n * self.stride :
578 if self.__profIndex == self.n * self.stride :
581 self.__dataToPutStride = True
579 self.__dataToPutStride = True
582 self.__profIndexStride = 0
580 self.__profIndexStride = 0
583 self.__profIndex = 0
581 self.__profIndex = 0
584 self.__bufferStride = []
582 self.__bufferStride = []
585 for i in range(self.stride):
583 for i in range(self.stride):
586 current = self.__buffer[i::self.stride]
584 current = self.__buffer[i::self.stride]
587 data = numpy.sum([t[0] for t in current], axis=0)
585 data = numpy.sum([t[0] for t in current], axis=0)
588 avgdatatime = numpy.average([t[1] for t in current])
586 avgdatatime = numpy.average([t[1] for t in current])
589 # print data
587 # print data
590 self.__bufferStride.append((data, avgdatatime))
588 self.__bufferStride.append((data, avgdatatime))
591
589
592 if self.__dataToPutStride:
590 if self.__dataToPutStride:
593 self.__dataReady = True
591 self.__dataReady = True
594 self.__profIndexStride += 1
592 self.__profIndexStride += 1
595 if self.__profIndexStride == self.stride:
593 if self.__profIndexStride == self.stride:
596 self.__dataToPutStride = False
594 self.__dataToPutStride = False
597 # print self.__bufferStride[self.__profIndexStride - 1]
595 # print self.__bufferStride[self.__profIndexStride - 1]
598 # raise
596 # raise
599 return self.__bufferStride[self.__profIndexStride - 1]
597 return self.__bufferStride[self.__profIndexStride - 1]
600
598
601
599
602 return None, None
600 return None, None
603
601
604 def integrate(self, data, datatime=None):
602 def integrate(self, data, datatime=None):
605
603
606 if self.__initime == None:
604 if self.__initime == None:
607 self.__initime = datatime
605 self.__initime = datatime
608
606
609 if self.__byTime:
607 if self.__byTime:
610 avgdata = self.byTime(data, datatime)
608 avgdata = self.byTime(data, datatime)
611 else:
609 else:
612 avgdata = self.byProfiles(data)
610 avgdata = self.byProfiles(data)
613
611
614
612
615 self.__lastdatatime = datatime
613 self.__lastdatatime = datatime
616
614
617 if avgdata is None:
615 if avgdata is None:
618 return None, None
616 return None, None
619
617
620 avgdatatime = self.__initime
618 avgdatatime = self.__initime
621
619
622 deltatime = datatime - self.__lastdatatime
620 deltatime = datatime - self.__lastdatatime
623
621
624 if not self.__withOverlapping:
622 if not self.__withOverlapping:
625 self.__initime = datatime
623 self.__initime = datatime
626 else:
624 else:
627 self.__initime += deltatime
625 self.__initime += deltatime
628
626
629 return avgdata, avgdatatime
627 return avgdata, avgdatatime
630
628
631 def integrateByBlock(self, dataOut):
629 def integrateByBlock(self, dataOut):
632
630
633 times = int(dataOut.data.shape[1]/self.n)
631 times = int(dataOut.data.shape[1]/self.n)
634 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
632 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
635
633
636 id_min = 0
634 id_min = 0
637 id_max = self.n
635 id_max = self.n
638
636
639 for i in range(times):
637 for i in range(times):
640 junk = dataOut.data[:,id_min:id_max,:]
638 junk = dataOut.data[:,id_min:id_max,:]
641 avgdata[:,i,:] = junk.sum(axis=1)
639 avgdata[:,i,:] = junk.sum(axis=1)
642 id_min += self.n
640 id_min += self.n
643 id_max += self.n
641 id_max += self.n
644
642
645 timeInterval = dataOut.ippSeconds*self.n
643 timeInterval = dataOut.ippSeconds*self.n
646 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
644 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
647 self.__dataReady = True
645 self.__dataReady = True
648 return avgdata, avgdatatime
646 return avgdata, avgdatatime
649
647
650 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
648 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
651
649
652 if not self.isConfig:
650 if not self.isConfig:
653 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
651 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
654 self.isConfig = True
652 self.isConfig = True
655 if dataOut.flagDataAsBlock:
653 if dataOut.flagDataAsBlock:
656 """
654 """
657 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
655 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
658 """
656 """
659 avgdata, avgdatatime = self.integrateByBlock(dataOut)
657 avgdata, avgdatatime = self.integrateByBlock(dataOut)
660 dataOut.nProfiles /= self.n
658 dataOut.nProfiles /= self.n
661 else:
659 else:
662 if stride is None:
660 if stride is None:
663 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
661 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
664 else:
662 else:
665 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
663 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
666
664
667
665
668 # dataOut.timeInterval *= n
666 # dataOut.timeInterval *= n
669 dataOut.flagNoData = True
667 dataOut.flagNoData = True
670
668
671 if self.__dataReady:
669 if self.__dataReady:
672 dataOut.data = avgdata
670 dataOut.data = avgdata
673 if not dataOut.flagCohInt:
671 if not dataOut.flagCohInt:
674 dataOut.nCohInt *= self.n
672 dataOut.nCohInt *= self.n
675 dataOut.flagCohInt = True
673 dataOut.flagCohInt = True
676 dataOut.utctime = avgdatatime
674 dataOut.utctime = avgdatatime
677 # print avgdata, avgdatatime
675 # print avgdata, avgdatatime
678 # raise
676 # raise
679 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
677 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
680 dataOut.flagNoData = False
678 dataOut.flagNoData = False
681 return dataOut
679 return dataOut
682
680
683 class Decoder(Operation):
681 class Decoder(Operation):
684
682
685 isConfig = False
683 isConfig = False
686 __profIndex = 0
684 __profIndex = 0
687
685
688 code = None
686 code = None
689
687
690 nCode = None
688 nCode = None
691 nBaud = None
689 nBaud = None
692
690
693 def __init__(self, **kwargs):
691 def __init__(self, **kwargs):
694
692
695 Operation.__init__(self, **kwargs)
693 Operation.__init__(self, **kwargs)
696
694
697 self.times = None
695 self.times = None
698 self.osamp = None
696 self.osamp = None
699 # self.__setValues = False
697 # self.__setValues = False
700 self.isConfig = False
698 self.isConfig = False
701 self.setupReq = False
699 self.setupReq = False
702 def setup(self, code, osamp, dataOut):
700 def setup(self, code, osamp, dataOut):
703
701
704 self.__profIndex = 0
702 self.__profIndex = 0
705
703
706 self.code = code
704 self.code = code
707
705
708 self.nCode = len(code)
706 self.nCode = len(code)
709 self.nBaud = len(code[0])
707 self.nBaud = len(code[0])
710
708
711 if (osamp != None) and (osamp >1):
709 if (osamp != None) and (osamp >1):
712 self.osamp = osamp
710 self.osamp = osamp
713 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
711 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
714 self.nBaud = self.nBaud*self.osamp
712 self.nBaud = self.nBaud*self.osamp
715
713
716 self.__nChannels = dataOut.nChannels
714 self.__nChannels = dataOut.nChannels
717 self.__nProfiles = dataOut.nProfiles
715 self.__nProfiles = dataOut.nProfiles
718 self.__nHeis = dataOut.nHeights
716 self.__nHeis = dataOut.nHeights
719
717
720 if self.__nHeis < self.nBaud:
718 if self.__nHeis < self.nBaud:
721 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
719 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
722
720
723 #Frequency
721 #Frequency
724 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
722 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
725
723
726 __codeBuffer[:,0:self.nBaud] = self.code
724 __codeBuffer[:,0:self.nBaud] = self.code
727
725
728 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
726 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
729
727
730 if dataOut.flagDataAsBlock:
728 if dataOut.flagDataAsBlock:
731
729
732 self.ndatadec = self.__nHeis #- self.nBaud + 1
730 self.ndatadec = self.__nHeis #- self.nBaud + 1
733
731
734 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
732 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
735
733
736 else:
734 else:
737
735
738 #Time
736 #Time
739 self.ndatadec = self.__nHeis #- self.nBaud + 1
737 self.ndatadec = self.__nHeis #- self.nBaud + 1
740
738
741 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
739 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
742
740
743 def __convolutionInFreq(self, data):
741 def __convolutionInFreq(self, data):
744
742
745 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
743 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
746
744
747 fft_data = numpy.fft.fft(data, axis=1)
745 fft_data = numpy.fft.fft(data, axis=1)
748
746
749 conv = fft_data*fft_code
747 conv = fft_data*fft_code
750
748
751 data = numpy.fft.ifft(conv,axis=1)
749 data = numpy.fft.ifft(conv,axis=1)
752
750
753 return data
751 return data
754
752
755 def __convolutionInFreqOpt(self, data):
753 def __convolutionInFreqOpt(self, data):
756
754
757 raise NotImplementedError
755 raise NotImplementedError
758
756
759 def __convolutionInTime(self, data):
757 def __convolutionInTime(self, data):
760
758
761 code = self.code[self.__profIndex]
759 code = self.code[self.__profIndex]
762 for i in range(self.__nChannels):
760 for i in range(self.__nChannels):
763 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
761 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
764
762
765 return self.datadecTime
763 return self.datadecTime
766
764
767 def __convolutionByBlockInTime(self, data):
765 def __convolutionByBlockInTime(self, data):
768
766
769 repetitions = int(self.__nProfiles / self.nCode)
767 repetitions = int(self.__nProfiles / self.nCode)
770 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
768 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
771 junk = junk.flatten()
769 junk = junk.flatten()
772 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
770 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
773 profilesList = range(self.__nProfiles)
771 profilesList = range(self.__nProfiles)
774
772
775 for i in range(self.__nChannels):
773 for i in range(self.__nChannels):
776 for j in profilesList:
774 for j in profilesList:
777 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
775 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
778 return self.datadecTime
776 return self.datadecTime
779
777
780 def __convolutionByBlockInFreq(self, data):
778 def __convolutionByBlockInFreq(self, data):
781
779
782 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
780 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
783
781
784
782
785 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
783 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
786
784
787 fft_data = numpy.fft.fft(data, axis=2)
785 fft_data = numpy.fft.fft(data, axis=2)
788
786
789 conv = fft_data*fft_code
787 conv = fft_data*fft_code
790
788
791 data = numpy.fft.ifft(conv,axis=2)
789 data = numpy.fft.ifft(conv,axis=2)
792
790
793 return data
791 return data
794
792
795
793
796 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
794 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
797
795
798 if dataOut.flagDecodeData:
796 if dataOut.flagDecodeData:
799 print("This data is already decoded, recoding again ...")
797 print("This data is already decoded, recoding again ...")
800
798
801 if not self.isConfig:
799 if not self.isConfig:
802
800
803 if code is None:
801 if code is None:
804 if dataOut.code is None:
802 if dataOut.code is None:
805 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
803 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
806
804
807 code = dataOut.code
805 code = dataOut.code
808 else:
806 else:
809 code = numpy.array(code).reshape(nCode,nBaud)
807 code = numpy.array(code).reshape(nCode,nBaud)
810 self.setup(code, osamp, dataOut)
808 self.setup(code, osamp, dataOut)
811
809
812 self.isConfig = True
810 self.isConfig = True
813
811
814 if mode == 3:
812 if mode == 3:
815 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
813 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
816
814
817 if times != None:
815 if times != None:
818 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
816 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
819
817
820 if self.code is None:
818 if self.code is None:
821 print("Fail decoding: Code is not defined.")
819 print("Fail decoding: Code is not defined.")
822 return
820 return
823
821
824 self.__nProfiles = dataOut.nProfiles
822 self.__nProfiles = dataOut.nProfiles
825 datadec = None
823 datadec = None
826
824
827 if mode == 3:
825 if mode == 3:
828 mode = 0
826 mode = 0
829
827
830 if dataOut.flagDataAsBlock:
828 if dataOut.flagDataAsBlock:
831 """
829 """
832 Decoding when data have been read as block,
830 Decoding when data have been read as block,
833 """
831 """
834
832
835 if mode == 0:
833 if mode == 0:
836 datadec = self.__convolutionByBlockInTime(dataOut.data)
834 datadec = self.__convolutionByBlockInTime(dataOut.data)
837 if mode == 1:
835 if mode == 1:
838 datadec = self.__convolutionByBlockInFreq(dataOut.data)
836 datadec = self.__convolutionByBlockInFreq(dataOut.data)
839 else:
837 else:
840 """
838 """
841 Decoding when data have been read profile by profile
839 Decoding when data have been read profile by profile
842 """
840 """
843 if mode == 0:
841 if mode == 0:
844 datadec = self.__convolutionInTime(dataOut.data)
842 datadec = self.__convolutionInTime(dataOut.data)
845
843
846 if mode == 1:
844 if mode == 1:
847 datadec = self.__convolutionInFreq(dataOut.data)
845 datadec = self.__convolutionInFreq(dataOut.data)
848
846
849 if mode == 2:
847 if mode == 2:
850 datadec = self.__convolutionInFreqOpt(dataOut.data)
848 datadec = self.__convolutionInFreqOpt(dataOut.data)
851
849
852 if datadec is None:
850 if datadec is None:
853 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
851 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
854
852
855 dataOut.code = self.code
853 dataOut.code = self.code
856 dataOut.nCode = self.nCode
854 dataOut.nCode = self.nCode
857 dataOut.nBaud = self.nBaud
855 dataOut.nBaud = self.nBaud
858
856
859 dataOut.data = datadec
857 dataOut.data = datadec
860 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
858 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
861
859
862 dataOut.flagDecodeData = True #asumo q la data esta decodificada
860 dataOut.flagDecodeData = True #asumo q la data esta decodificada
863
861
864 if self.__profIndex == self.nCode-1:
862 if self.__profIndex == self.nCode-1:
865 self.__profIndex = 0
863 self.__profIndex = 0
866 return dataOut
864 return dataOut
867
865
868 self.__profIndex += 1
866 self.__profIndex += 1
869
867
870 return dataOut
868 return dataOut
871
869
872
870
873 class ProfileConcat(Operation):
871 class ProfileConcat(Operation):
874
872
875 isConfig = False
873 isConfig = False
876 buffer = None
874 buffer = None
877
875
878 def __init__(self, **kwargs):
876 def __init__(self, **kwargs):
879
877
880 Operation.__init__(self, **kwargs)
878 Operation.__init__(self, **kwargs)
881 self.profileIndex = 0
879 self.profileIndex = 0
882
880
883 def reset(self):
881 def reset(self):
884 self.buffer = numpy.zeros_like(self.buffer)
882 self.buffer = numpy.zeros_like(self.buffer)
885 self.start_index = 0
883 self.start_index = 0
886 self.times = 1
884 self.times = 1
887
885
888 def setup(self, data, m, n=1):
886 def setup(self, data, m, n=1):
889 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
887 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
890 self.nHeights = data.shape[1]#.nHeights
888 self.nHeights = data.shape[1]#.nHeights
891 self.start_index = 0
889 self.start_index = 0
892 self.times = 1
890 self.times = 1
893
891
894 def concat(self, data):
892 def concat(self, data):
895
893
896 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
894 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
897 self.start_index = self.start_index + self.nHeights
895 self.start_index = self.start_index + self.nHeights
898
896
899 def run(self, dataOut, m):
897 def run(self, dataOut, m):
900 dataOut.flagNoData = True
898 dataOut.flagNoData = True
901
899
902 if not self.isConfig:
900 if not self.isConfig:
903 self.setup(dataOut.data, m, 1)
901 self.setup(dataOut.data, m, 1)
904 self.isConfig = True
902 self.isConfig = True
905
903
906 if dataOut.flagDataAsBlock:
904 if dataOut.flagDataAsBlock:
907 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
905 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
908
906
909 else:
907 else:
910 self.concat(dataOut.data)
908 self.concat(dataOut.data)
911 self.times += 1
909 self.times += 1
912 if self.times > m:
910 if self.times > m:
913 dataOut.data = self.buffer
911 dataOut.data = self.buffer
914 self.reset()
912 self.reset()
915 dataOut.flagNoData = False
913 dataOut.flagNoData = False
916 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
914 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
917 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
915 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
918 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
916 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
919 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
917 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
920 dataOut.ippSeconds *= m
918 dataOut.ippSeconds *= m
921 return dataOut
919 return dataOut
922
920
923 class ProfileSelector(Operation):
921 class ProfileSelector(Operation):
924
922
925 profileIndex = None
923 profileIndex = None
926 # Tamanho total de los perfiles
924 # Tamanho total de los perfiles
927 nProfiles = None
925 nProfiles = None
928
926
929 def __init__(self, **kwargs):
927 def __init__(self, **kwargs):
930
928
931 Operation.__init__(self, **kwargs)
929 Operation.__init__(self, **kwargs)
932 self.profileIndex = 0
930 self.profileIndex = 0
933
931
934 def incProfileIndex(self):
932 def incProfileIndex(self):
935
933
936 self.profileIndex += 1
934 self.profileIndex += 1
937
935
938 if self.profileIndex >= self.nProfiles:
936 if self.profileIndex >= self.nProfiles:
939 self.profileIndex = 0
937 self.profileIndex = 0
940
938
941 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
939 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
942
940
943 if profileIndex < minIndex:
941 if profileIndex < minIndex:
944 return False
942 return False
945
943
946 if profileIndex > maxIndex:
944 if profileIndex > maxIndex:
947 return False
945 return False
948
946
949 return True
947 return True
950
948
951 def isThisProfileInList(self, profileIndex, profileList):
949 def isThisProfileInList(self, profileIndex, profileList):
952
950
953 if profileIndex not in profileList:
951 if profileIndex not in profileList:
954 return False
952 return False
955
953
956 return True
954 return True
957
955
958 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
956 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
959
957
960 """
958 """
961 ProfileSelector:
959 ProfileSelector:
962
960
963 Inputs:
961 Inputs:
964 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
962 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
965
963
966 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
964 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
967
965
968 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
966 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
969
967
970 """
968 """
971
969
972 if rangeList is not None:
970 if rangeList is not None:
973 if type(rangeList[0]) not in (tuple, list):
971 if type(rangeList[0]) not in (tuple, list):
974 rangeList = [rangeList]
972 rangeList = [rangeList]
975
973
976 dataOut.flagNoData = True
974 dataOut.flagNoData = True
977
975
978 if dataOut.flagDataAsBlock:
976 if dataOut.flagDataAsBlock:
979 """
977 """
980 data dimension = [nChannels, nProfiles, nHeis]
978 data dimension = [nChannels, nProfiles, nHeis]
981 """
979 """
982 if profileList != None:
980 if profileList != None:
983 dataOut.data = dataOut.data[:,profileList,:]
981 dataOut.data = dataOut.data[:,profileList,:]
984
982
985 if profileRangeList != None:
983 if profileRangeList != None:
986 minIndex = profileRangeList[0]
984 minIndex = profileRangeList[0]
987 maxIndex = profileRangeList[1]
985 maxIndex = profileRangeList[1]
988 profileList = list(range(minIndex, maxIndex+1))
986 profileList = list(range(minIndex, maxIndex+1))
989
987
990 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
988 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
991
989
992 if rangeList != None:
990 if rangeList != None:
993
991
994 profileList = []
992 profileList = []
995
993
996 for thisRange in rangeList:
994 for thisRange in rangeList:
997 minIndex = thisRange[0]
995 minIndex = thisRange[0]
998 maxIndex = thisRange[1]
996 maxIndex = thisRange[1]
999
997
1000 profileList.extend(list(range(minIndex, maxIndex+1)))
998 profileList.extend(list(range(minIndex, maxIndex+1)))
1001
999
1002 dataOut.data = dataOut.data[:,profileList,:]
1000 dataOut.data = dataOut.data[:,profileList,:]
1003
1001
1004 dataOut.nProfiles = len(profileList)
1002 dataOut.nProfiles = len(profileList)
1005 dataOut.profileIndex = dataOut.nProfiles - 1
1003 dataOut.profileIndex = dataOut.nProfiles - 1
1006 dataOut.flagNoData = False
1004 dataOut.flagNoData = False
1007
1005
1008 return dataOut
1006 return dataOut
1009
1007
1010 """
1008 """
1011 data dimension = [nChannels, nHeis]
1009 data dimension = [nChannels, nHeis]
1012 """
1010 """
1013
1011
1014 if profileList != None:
1012 if profileList != None:
1015
1013
1016 if self.isThisProfileInList(dataOut.profileIndex, profileList):
1014 if self.isThisProfileInList(dataOut.profileIndex, profileList):
1017
1015
1018 self.nProfiles = len(profileList)
1016 self.nProfiles = len(profileList)
1019 dataOut.nProfiles = self.nProfiles
1017 dataOut.nProfiles = self.nProfiles
1020 dataOut.profileIndex = self.profileIndex
1018 dataOut.profileIndex = self.profileIndex
1021 dataOut.flagNoData = False
1019 dataOut.flagNoData = False
1022
1020
1023 self.incProfileIndex()
1021 self.incProfileIndex()
1024 return dataOut
1022 return dataOut
1025
1023
1026 if profileRangeList != None:
1024 if profileRangeList != None:
1027
1025
1028 minIndex = profileRangeList[0]
1026 minIndex = profileRangeList[0]
1029 maxIndex = profileRangeList[1]
1027 maxIndex = profileRangeList[1]
1030
1028
1031 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1029 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1032
1030
1033 self.nProfiles = maxIndex - minIndex + 1
1031 self.nProfiles = maxIndex - minIndex + 1
1034 dataOut.nProfiles = self.nProfiles
1032 dataOut.nProfiles = self.nProfiles
1035 dataOut.profileIndex = self.profileIndex
1033 dataOut.profileIndex = self.profileIndex
1036 dataOut.flagNoData = False
1034 dataOut.flagNoData = False
1037
1035
1038 self.incProfileIndex()
1036 self.incProfileIndex()
1039 return dataOut
1037 return dataOut
1040
1038
1041 if rangeList != None:
1039 if rangeList != None:
1042
1040
1043 nProfiles = 0
1041 nProfiles = 0
1044
1042
1045 for thisRange in rangeList:
1043 for thisRange in rangeList:
1046 minIndex = thisRange[0]
1044 minIndex = thisRange[0]
1047 maxIndex = thisRange[1]
1045 maxIndex = thisRange[1]
1048
1046
1049 nProfiles += maxIndex - minIndex + 1
1047 nProfiles += maxIndex - minIndex + 1
1050
1048
1051 for thisRange in rangeList:
1049 for thisRange in rangeList:
1052
1050
1053 minIndex = thisRange[0]
1051 minIndex = thisRange[0]
1054 maxIndex = thisRange[1]
1052 maxIndex = thisRange[1]
1055
1053
1056 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1054 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1057
1055
1058 self.nProfiles = nProfiles
1056 self.nProfiles = nProfiles
1059 dataOut.nProfiles = self.nProfiles
1057 dataOut.nProfiles = self.nProfiles
1060 dataOut.profileIndex = self.profileIndex
1058 dataOut.profileIndex = self.profileIndex
1061 dataOut.flagNoData = False
1059 dataOut.flagNoData = False
1062
1060
1063 self.incProfileIndex()
1061 self.incProfileIndex()
1064
1062
1065 break
1063 break
1066
1064
1067 return dataOut
1065 return dataOut
1068
1066
1069
1067
1070 if beam != None: #beam is only for AMISR data
1068 if beam != None: #beam is only for AMISR data
1071 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1069 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1072 dataOut.flagNoData = False
1070 dataOut.flagNoData = False
1073 dataOut.profileIndex = self.profileIndex
1071 dataOut.profileIndex = self.profileIndex
1074
1072
1075 self.incProfileIndex()
1073 self.incProfileIndex()
1076
1074
1077 return dataOut
1075 return dataOut
1078
1076
1079 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
1077 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
1080
1078
1081
1079
1082 class Reshaper(Operation):
1080 class Reshaper(Operation):
1083
1081
1084 def __init__(self, **kwargs):
1082 def __init__(self, **kwargs):
1085
1083
1086 Operation.__init__(self, **kwargs)
1084 Operation.__init__(self, **kwargs)
1087
1085
1088 self.__buffer = None
1086 self.__buffer = None
1089 self.__nitems = 0
1087 self.__nitems = 0
1090
1088
1091 def __appendProfile(self, dataOut, nTxs):
1089 def __appendProfile(self, dataOut, nTxs):
1092
1090
1093 if self.__buffer is None:
1091 if self.__buffer is None:
1094 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1092 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1095 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1093 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1096
1094
1097 ini = dataOut.nHeights * self.__nitems
1095 ini = dataOut.nHeights * self.__nitems
1098 end = ini + dataOut.nHeights
1096 end = ini + dataOut.nHeights
1099
1097
1100 self.__buffer[:, ini:end] = dataOut.data
1098 self.__buffer[:, ini:end] = dataOut.data
1101
1099
1102 self.__nitems += 1
1100 self.__nitems += 1
1103
1101
1104 return int(self.__nitems*nTxs)
1102 return int(self.__nitems*nTxs)
1105
1103
1106 def __getBuffer(self):
1104 def __getBuffer(self):
1107
1105
1108 if self.__nitems == int(1./self.__nTxs):
1106 if self.__nitems == int(1./self.__nTxs):
1109
1107
1110 self.__nitems = 0
1108 self.__nitems = 0
1111
1109
1112 return self.__buffer.copy()
1110 return self.__buffer.copy()
1113
1111
1114 return None
1112 return None
1115
1113
1116 def __checkInputs(self, dataOut, shape, nTxs):
1114 def __checkInputs(self, dataOut, shape, nTxs):
1117
1115
1118 if shape is None and nTxs is None:
1116 if shape is None and nTxs is None:
1119 raise ValueError("Reshaper: shape of factor should be defined")
1117 raise ValueError("Reshaper: shape of factor should be defined")
1120
1118
1121 if nTxs:
1119 if nTxs:
1122 if nTxs < 0:
1120 if nTxs < 0:
1123 raise ValueError("nTxs should be greater than 0")
1121 raise ValueError("nTxs should be greater than 0")
1124
1122
1125 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1123 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1126 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1124 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1127
1125
1128 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1126 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1129
1127
1130 return shape, nTxs
1128 return shape, nTxs
1131
1129
1132 if len(shape) != 2 and len(shape) != 3:
1130 if len(shape) != 2 and len(shape) != 3:
1133 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
1131 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
1134
1132
1135 if len(shape) == 2:
1133 if len(shape) == 2:
1136 shape_tuple = [dataOut.nChannels]
1134 shape_tuple = [dataOut.nChannels]
1137 shape_tuple.extend(shape)
1135 shape_tuple.extend(shape)
1138 else:
1136 else:
1139 shape_tuple = list(shape)
1137 shape_tuple = list(shape)
1140
1138
1141 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1139 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1142
1140
1143 return shape_tuple, nTxs
1141 return shape_tuple, nTxs
1144
1142
1145 def run(self, dataOut, shape=None, nTxs=None):
1143 def run(self, dataOut, shape=None, nTxs=None):
1146
1144
1147 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1145 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1148
1146
1149 dataOut.flagNoData = True
1147 dataOut.flagNoData = True
1150 profileIndex = None
1148 profileIndex = None
1151
1149
1152 if dataOut.flagDataAsBlock:
1150 if dataOut.flagDataAsBlock:
1153
1151
1154 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1152 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1155 dataOut.flagNoData = False
1153 dataOut.flagNoData = False
1156
1154
1157 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1155 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1158
1156
1159 else:
1157 else:
1160
1158
1161 if self.__nTxs < 1:
1159 if self.__nTxs < 1:
1162
1160
1163 self.__appendProfile(dataOut, self.__nTxs)
1161 self.__appendProfile(dataOut, self.__nTxs)
1164 new_data = self.__getBuffer()
1162 new_data = self.__getBuffer()
1165
1163
1166 if new_data is not None:
1164 if new_data is not None:
1167 dataOut.data = new_data
1165 dataOut.data = new_data
1168 dataOut.flagNoData = False
1166 dataOut.flagNoData = False
1169
1167
1170 profileIndex = dataOut.profileIndex*nTxs
1168 profileIndex = dataOut.profileIndex*nTxs
1171
1169
1172 else:
1170 else:
1173 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1171 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1174
1172
1175 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1173 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1176
1174
1177 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1175 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1178
1176
1179 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1177 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1180
1178
1181 dataOut.profileIndex = profileIndex
1179 dataOut.profileIndex = profileIndex
1182
1180
1183 dataOut.ippSeconds /= self.__nTxs
1181 dataOut.ippSeconds /= self.__nTxs
1184
1182
1185 return dataOut
1183 return dataOut
1186
1184
1187 class SplitProfiles(Operation):
1185 class SplitProfiles(Operation):
1188
1186
1189 def __init__(self, **kwargs):
1187 def __init__(self, **kwargs):
1190
1188
1191 Operation.__init__(self, **kwargs)
1189 Operation.__init__(self, **kwargs)
1192
1190
1193 def run(self, dataOut, n):
1191 def run(self, dataOut, n):
1194
1192
1195 dataOut.flagNoData = True
1193 dataOut.flagNoData = True
1196 profileIndex = None
1194 profileIndex = None
1197
1195
1198 if dataOut.flagDataAsBlock:
1196 if dataOut.flagDataAsBlock:
1199
1197
1200 #nchannels, nprofiles, nsamples
1198 #nchannels, nprofiles, nsamples
1201 shape = dataOut.data.shape
1199 shape = dataOut.data.shape
1202
1200
1203 if shape[2] % n != 0:
1201 if shape[2] % n != 0:
1204 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1202 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1205
1203
1206 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1204 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1207
1205
1208 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1206 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1209 dataOut.flagNoData = False
1207 dataOut.flagNoData = False
1210
1208
1211 profileIndex = int(dataOut.nProfiles/n) - 1
1209 profileIndex = int(dataOut.nProfiles/n) - 1
1212
1210
1213 else:
1211 else:
1214
1212
1215 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1213 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1216
1214
1217 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1215 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1218
1216
1219 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1217 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1220
1218
1221 dataOut.nProfiles = int(dataOut.nProfiles*n)
1219 dataOut.nProfiles = int(dataOut.nProfiles*n)
1222
1220
1223 dataOut.profileIndex = profileIndex
1221 dataOut.profileIndex = profileIndex
1224
1222
1225 dataOut.ippSeconds /= n
1223 dataOut.ippSeconds /= n
1226
1224
1227 return dataOut
1225 return dataOut
1228
1226
1229 class CombineProfiles(Operation):
1227 class CombineProfiles(Operation):
1230 def __init__(self, **kwargs):
1228 def __init__(self, **kwargs):
1231
1229
1232 Operation.__init__(self, **kwargs)
1230 Operation.__init__(self, **kwargs)
1233
1231
1234 self.__remData = None
1232 self.__remData = None
1235 self.__profileIndex = 0
1233 self.__profileIndex = 0
1236
1234
1237 def run(self, dataOut, n):
1235 def run(self, dataOut, n):
1238
1236
1239 dataOut.flagNoData = True
1237 dataOut.flagNoData = True
1240 profileIndex = None
1238 profileIndex = None
1241
1239
1242 if dataOut.flagDataAsBlock:
1240 if dataOut.flagDataAsBlock:
1243
1241
1244 #nchannels, nprofiles, nsamples
1242 #nchannels, nprofiles, nsamples
1245 shape = dataOut.data.shape
1243 shape = dataOut.data.shape
1246 new_shape = shape[0], shape[1]/n, shape[2]*n
1244 new_shape = shape[0], shape[1]/n, shape[2]*n
1247
1245
1248 if shape[1] % n != 0:
1246 if shape[1] % n != 0:
1249 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1247 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1250
1248
1251 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1249 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1252 dataOut.flagNoData = False
1250 dataOut.flagNoData = False
1253
1251
1254 profileIndex = int(dataOut.nProfiles*n) - 1
1252 profileIndex = int(dataOut.nProfiles*n) - 1
1255
1253
1256 else:
1254 else:
1257
1255
1258 #nchannels, nsamples
1256 #nchannels, nsamples
1259 if self.__remData is None:
1257 if self.__remData is None:
1260 newData = dataOut.data
1258 newData = dataOut.data
1261 else:
1259 else:
1262 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1260 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1263
1261
1264 self.__profileIndex += 1
1262 self.__profileIndex += 1
1265
1263
1266 if self.__profileIndex < n:
1264 if self.__profileIndex < n:
1267 self.__remData = newData
1265 self.__remData = newData
1268 #continue
1266 #continue
1269 return
1267 return
1270
1268
1271 self.__profileIndex = 0
1269 self.__profileIndex = 0
1272 self.__remData = None
1270 self.__remData = None
1273
1271
1274 dataOut.data = newData
1272 dataOut.data = newData
1275 dataOut.flagNoData = False
1273 dataOut.flagNoData = False
1276
1274
1277 profileIndex = dataOut.profileIndex/n
1275 profileIndex = dataOut.profileIndex/n
1278
1276
1279
1277
1280 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1278 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1281
1279
1282 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1280 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1283
1281
1284 dataOut.nProfiles = int(dataOut.nProfiles/n)
1282 dataOut.nProfiles = int(dataOut.nProfiles/n)
1285
1283
1286 dataOut.profileIndex = profileIndex
1284 dataOut.profileIndex = profileIndex
1287
1285
1288 dataOut.ippSeconds *= n
1286 dataOut.ippSeconds *= n
1289
1287
1290 return dataOut
1288 return dataOut
1291
1289
1292 class PulsePairVoltage(Operation):
1290 class PulsePairVoltage(Operation):
1293 '''
1291 '''
1294 Function PulsePair(Signal Power, Velocity)
1292 Function PulsePair(Signal Power, Velocity)
1295 The real component of Lag[0] provides Intensity Information
1293 The real component of Lag[0] provides Intensity Information
1296 The imag component of Lag[1] Phase provides Velocity Information
1294 The imag component of Lag[1] Phase provides Velocity Information
1297
1295
1298 Configuration Parameters:
1296 Configuration Parameters:
1299 nPRF = Number of Several PRF
1297 nPRF = Number of Several PRF
1300 theta = Degree Azimuth angel Boundaries
1298 theta = Degree Azimuth angel Boundaries
1301
1299
1302 Input:
1300 Input:
1303 self.dataOut
1301 self.dataOut
1304 lag[N]
1302 lag[N]
1305 Affected:
1303 Affected:
1306 self.dataOut.spc
1304 self.dataOut.spc
1307 '''
1305 '''
1308 isConfig = False
1306 isConfig = False
1309 __profIndex = 0
1307 __profIndex = 0
1310 __initime = None
1308 __initime = None
1311 __lastdatatime = None
1309 __lastdatatime = None
1312 __buffer = None
1310 __buffer = None
1313 noise = None
1311 noise = None
1314 __dataReady = False
1312 __dataReady = False
1315 n = None
1313 n = None
1316 __nch = 0
1314 __nch = 0
1317 __nHeis = 0
1315 __nHeis = 0
1318 removeDC = False
1316 removeDC = False
1319 ipp = None
1317 ipp = None
1320 lambda_ = 0
1318 lambda_ = 0
1321
1319
1322 def __init__(self,**kwargs):
1320 def __init__(self,**kwargs):
1323 Operation.__init__(self,**kwargs)
1321 Operation.__init__(self,**kwargs)
1324
1322
1325 def setup(self, dataOut, n = None, removeDC=False):
1323 def setup(self, dataOut, n = None, removeDC=False):
1326 '''
1324 '''
1327 n= Numero de PRF's de entrada
1325 n= Numero de PRF's de entrada
1328 '''
1326 '''
1329 self.__initime = None
1327 self.__initime = None
1330 self.__lastdatatime = 0
1328 self.__lastdatatime = 0
1331 self.__dataReady = False
1329 self.__dataReady = False
1332 self.__buffer = 0
1330 self.__buffer = 0
1333 self.__profIndex = 0
1331 self.__profIndex = 0
1334 self.noise = None
1332 self.noise = None
1335 self.__nch = dataOut.nChannels
1333 self.__nch = dataOut.nChannels
1336 self.__nHeis = dataOut.nHeights
1334 self.__nHeis = dataOut.nHeights
1337 self.removeDC = removeDC
1335 self.removeDC = removeDC
1338 self.lambda_ = 3.0e8/(9345.0e6)
1336 self.lambda_ = 3.0e8/(9345.0e6)
1339 self.ippSec = dataOut.ippSeconds
1337 self.ippSec = dataOut.ippSeconds
1340 self.nCohInt = dataOut.nCohInt
1338 self.nCohInt = dataOut.nCohInt
1341 print("IPPseconds",dataOut.ippSeconds)
1339 print("IPPseconds",dataOut.ippSeconds)
1342
1340
1343 print("ELVALOR DE n es:", n)
1341 print("ELVALOR DE n es:", n)
1344 if n == None:
1342 if n == None:
1345 raise ValueError("n should be specified.")
1343 raise ValueError("n should be specified.")
1346
1344
1347 if n != None:
1345 if n != None:
1348 if n<2:
1346 if n<2:
1349 raise ValueError("n should be greater than 2")
1347 raise ValueError("n should be greater than 2")
1350
1348
1351 self.n = n
1349 self.n = n
1352 self.__nProf = n
1350 self.__nProf = n
1353
1351
1354 self.__buffer = numpy.zeros((dataOut.nChannels,
1352 self.__buffer = numpy.zeros((dataOut.nChannels,
1355 n,
1353 n,
1356 dataOut.nHeights),
1354 dataOut.nHeights),
1357 dtype='complex')
1355 dtype='complex')
1358
1356
1359 def putData(self,data):
1357 def putData(self,data):
1360 '''
1358 '''
1361 Add a profile to he __buffer and increase in one the __profiel Index
1359 Add a profile to he __buffer and increase in one the __profiel Index
1362 '''
1360 '''
1363 self.__buffer[:,self.__profIndex,:]= data
1361 self.__buffer[:,self.__profIndex,:]= data
1364 self.__profIndex += 1
1362 self.__profIndex += 1
1365 return
1363 return
1366
1364
1367 def pushData(self,dataOut):
1365 def pushData(self,dataOut):
1368 '''
1366 '''
1369 Return the PULSEPAIR and the profiles used in the operation
1367 Return the PULSEPAIR and the profiles used in the operation
1370 Affected : self.__profileIndex
1368 Affected : self.__profileIndex
1371 '''
1369 '''
1372 #----------------- Remove DC-----------------------------------
1370 #----------------- Remove DC-----------------------------------
1373 if self.removeDC==True:
1371 if self.removeDC==True:
1374 mean = numpy.mean(self.__buffer,1)
1372 mean = numpy.mean(self.__buffer,1)
1375 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1373 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1376 dc= numpy.tile(tmp,[1,self.__nProf,1])
1374 dc= numpy.tile(tmp,[1,self.__nProf,1])
1377 self.__buffer = self.__buffer - dc
1375 self.__buffer = self.__buffer - dc
1378 #------------------Calculo de Potencia ------------------------
1376 #------------------Calculo de Potencia ------------------------
1379 pair0 = self.__buffer*numpy.conj(self.__buffer)
1377 pair0 = self.__buffer*numpy.conj(self.__buffer)
1380 pair0 = pair0.real
1378 pair0 = pair0.real
1381 lag_0 = numpy.sum(pair0,1)
1379 lag_0 = numpy.sum(pair0,1)
1382 #------------------Calculo de Ruido x canal--------------------
1380 #------------------Calculo de Ruido x canal--------------------
1383 self.noise = numpy.zeros(self.__nch)
1381 self.noise = numpy.zeros(self.__nch)
1384 for i in range(self.__nch):
1382 for i in range(self.__nch):
1385 daux = numpy.sort(pair0[i,:,:],axis= None)
1383 daux = numpy.sort(pair0[i,:,:],axis= None)
1386 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
1384 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
1387
1385
1388 self.noise = self.noise.reshape(self.__nch,1)
1386 self.noise = self.noise.reshape(self.__nch,1)
1389 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1387 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1390 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1388 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1391 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1389 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1392 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1390 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1393 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1391 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1394 #-------------------- Power --------------------------------------------------
1392 #-------------------- Power --------------------------------------------------
1395 data_power = lag_0/(self.n*self.nCohInt)
1393 data_power = lag_0/(self.n*self.nCohInt)
1396 #------------------ Senal ---------------------------------------------------
1394 #------------------ Senal ---------------------------------------------------
1397 data_intensity = pair0 - noise_buffer
1395 data_intensity = pair0 - noise_buffer
1398 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1396 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1399 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1397 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1400 for i in range(self.__nch):
1398 for i in range(self.__nch):
1401 for j in range(self.__nHeis):
1399 for j in range(self.__nHeis):
1402 if data_intensity[i][j] < 0:
1400 if data_intensity[i][j] < 0:
1403 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1401 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1404
1402
1405 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1403 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1406 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1404 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1407 lag_1 = numpy.sum(pair1,1)
1405 lag_1 = numpy.sum(pair1,1)
1408 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1406 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1409 data_velocity = (self.lambda_/2.0)*data_freq
1407 data_velocity = (self.lambda_/2.0)*data_freq
1410
1408
1411 #---------------- Potencia promedio estimada de la Senal-----------
1409 #---------------- Potencia promedio estimada de la Senal-----------
1412 lag_0 = lag_0/self.n
1410 lag_0 = lag_0/self.n
1413 S = lag_0-self.noise
1411 S = lag_0-self.noise
1414
1412
1415 #---------------- Frecuencia Doppler promedio ---------------------
1413 #---------------- Frecuencia Doppler promedio ---------------------
1416 lag_1 = lag_1/(self.n-1)
1414 lag_1 = lag_1/(self.n-1)
1417 R1 = numpy.abs(lag_1)
1415 R1 = numpy.abs(lag_1)
1418
1416
1419 #---------------- Calculo del SNR----------------------------------
1417 #---------------- Calculo del SNR----------------------------------
1420 data_snrPP = S/self.noise
1418 data_snrPP = S/self.noise
1421 for i in range(self.__nch):
1419 for i in range(self.__nch):
1422 for j in range(self.__nHeis):
1420 for j in range(self.__nHeis):
1423 if data_snrPP[i][j] < 1.e-20:
1421 if data_snrPP[i][j] < 1.e-20:
1424 data_snrPP[i][j] = 1.e-20
1422 data_snrPP[i][j] = 1.e-20
1425
1423
1426 #----------------- Calculo del ancho espectral ----------------------
1424 #----------------- Calculo del ancho espectral ----------------------
1427 L = S/R1
1425 L = S/R1
1428 L = numpy.where(L<0,1,L)
1426 L = numpy.where(L<0,1,L)
1429 L = numpy.log(L)
1427 L = numpy.log(L)
1430 tmp = numpy.sqrt(numpy.absolute(L))
1428 tmp = numpy.sqrt(numpy.absolute(L))
1431 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
1429 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
1432 n = self.__profIndex
1430 n = self.__profIndex
1433
1431
1434 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1432 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1435 self.__profIndex = 0
1433 self.__profIndex = 0
1436 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n
1434 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n
1437
1435
1438
1436
1439 def pulsePairbyProfiles(self,dataOut):
1437 def pulsePairbyProfiles(self,dataOut):
1440
1438
1441 self.__dataReady = False
1439 self.__dataReady = False
1442 data_power = None
1440 data_power = None
1443 data_intensity = None
1441 data_intensity = None
1444 data_velocity = None
1442 data_velocity = None
1445 data_specwidth = None
1443 data_specwidth = None
1446 data_snrPP = None
1444 data_snrPP = None
1447 self.putData(data=dataOut.data)
1445 self.putData(data=dataOut.data)
1448 if self.__profIndex == self.n:
1446 if self.__profIndex == self.n:
1449 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut)
1447 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut)
1450 self.__dataReady = True
1448 self.__dataReady = True
1451
1449
1452 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth
1450 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth
1453
1451
1454
1452
1455 def pulsePairOp(self, dataOut, datatime= None):
1453 def pulsePairOp(self, dataOut, datatime= None):
1456
1454
1457 if self.__initime == None:
1455 if self.__initime == None:
1458 self.__initime = datatime
1456 self.__initime = datatime
1459 data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut)
1457 data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut)
1460 self.__lastdatatime = datatime
1458 self.__lastdatatime = datatime
1461
1459
1462 if data_power is None:
1460 if data_power is None:
1463 return None, None, None,None,None,None
1461 return None, None, None,None,None,None
1464
1462
1465 avgdatatime = self.__initime
1463 avgdatatime = self.__initime
1466 deltatime = datatime - self.__lastdatatime
1464 deltatime = datatime - self.__lastdatatime
1467 self.__initime = datatime
1465 self.__initime = datatime
1468
1466
1469 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime
1467 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime
1470
1468
1471 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1469 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1472
1470
1473 if not self.isConfig:
1471 if not self.isConfig:
1474 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1472 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1475 self.isConfig = True
1473 self.isConfig = True
1476 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
1474 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
1477 dataOut.flagNoData = True
1475 dataOut.flagNoData = True
1478
1476
1479 if self.__dataReady:
1477 if self.__dataReady:
1480 dataOut.nCohInt *= self.n
1478 dataOut.nCohInt *= self.n
1481 dataOut.dataPP_POW = data_intensity # S
1479 dataOut.dataPP_POW = data_intensity # S
1482 dataOut.dataPP_POWER = data_power # P
1480 dataOut.dataPP_POWER = data_power # P
1483 dataOut.dataPP_DOP = data_velocity
1481 dataOut.dataPP_DOP = data_velocity
1484 dataOut.dataPP_SNR = data_snrPP
1482 dataOut.dataPP_SNR = data_snrPP
1485 dataOut.dataPP_WIDTH = data_specwidth
1483 dataOut.dataPP_WIDTH = data_specwidth
1486 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1484 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1487 dataOut.utctime = avgdatatime
1485 dataOut.utctime = avgdatatime
1488 dataOut.flagNoData = False
1486 dataOut.flagNoData = False
1489 return dataOut
1487 return dataOut
1490
1488
1491
1489
1492
1490
1493 # import collections
1491 # import collections
1494 # from scipy.stats import mode
1492 # from scipy.stats import mode
1495 #
1493 #
1496 # class Synchronize(Operation):
1494 # class Synchronize(Operation):
1497 #
1495 #
1498 # isConfig = False
1496 # isConfig = False
1499 # __profIndex = 0
1497 # __profIndex = 0
1500 #
1498 #
1501 # def __init__(self, **kwargs):
1499 # def __init__(self, **kwargs):
1502 #
1500 #
1503 # Operation.__init__(self, **kwargs)
1501 # Operation.__init__(self, **kwargs)
1504 # # self.isConfig = False
1502 # # self.isConfig = False
1505 # self.__powBuffer = None
1503 # self.__powBuffer = None
1506 # self.__startIndex = 0
1504 # self.__startIndex = 0
1507 # self.__pulseFound = False
1505 # self.__pulseFound = False
1508 #
1506 #
1509 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1507 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1510 #
1508 #
1511 # #Read data
1509 # #Read data
1512 #
1510 #
1513 # powerdB = dataOut.getPower(channel = channel)
1511 # powerdB = dataOut.getPower(channel = channel)
1514 # noisedB = dataOut.getNoise(channel = channel)[0]
1512 # noisedB = dataOut.getNoise(channel = channel)[0]
1515 #
1513 #
1516 # self.__powBuffer.extend(powerdB.flatten())
1514 # self.__powBuffer.extend(powerdB.flatten())
1517 #
1515 #
1518 # dataArray = numpy.array(self.__powBuffer)
1516 # dataArray = numpy.array(self.__powBuffer)
1519 #
1517 #
1520 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1518 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1521 #
1519 #
1522 # maxValue = numpy.nanmax(filteredPower)
1520 # maxValue = numpy.nanmax(filteredPower)
1523 #
1521 #
1524 # if maxValue < noisedB + 10:
1522 # if maxValue < noisedB + 10:
1525 # #No se encuentra ningun pulso de transmision
1523 # #No se encuentra ningun pulso de transmision
1526 # return None
1524 # return None
1527 #
1525 #
1528 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1526 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1529 #
1527 #
1530 # if len(maxValuesIndex) < 2:
1528 # if len(maxValuesIndex) < 2:
1531 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1529 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1532 # return None
1530 # return None
1533 #
1531 #
1534 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1532 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1535 #
1533 #
1536 # #Seleccionar solo valores con un espaciamiento de nSamples
1534 # #Seleccionar solo valores con un espaciamiento de nSamples
1537 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1535 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1538 #
1536 #
1539 # if len(pulseIndex) < 2:
1537 # if len(pulseIndex) < 2:
1540 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1538 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1541 # return None
1539 # return None
1542 #
1540 #
1543 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1541 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1544 #
1542 #
1545 # #remover senales que se distancien menos de 10 unidades o muestras
1543 # #remover senales que se distancien menos de 10 unidades o muestras
1546 # #(No deberian existir IPP menor a 10 unidades)
1544 # #(No deberian existir IPP menor a 10 unidades)
1547 #
1545 #
1548 # realIndex = numpy.where(spacing > 10 )[0]
1546 # realIndex = numpy.where(spacing > 10 )[0]
1549 #
1547 #
1550 # if len(realIndex) < 2:
1548 # if len(realIndex) < 2:
1551 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1549 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1552 # return None
1550 # return None
1553 #
1551 #
1554 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1552 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1555 # realPulseIndex = pulseIndex[realIndex]
1553 # realPulseIndex = pulseIndex[realIndex]
1556 #
1554 #
1557 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1555 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1558 #
1556 #
1559 # print "IPP = %d samples" %period
1557 # print "IPP = %d samples" %period
1560 #
1558 #
1561 # self.__newNSamples = dataOut.nHeights #int(period)
1559 # self.__newNSamples = dataOut.nHeights #int(period)
1562 # self.__startIndex = int(realPulseIndex[0])
1560 # self.__startIndex = int(realPulseIndex[0])
1563 #
1561 #
1564 # return 1
1562 # return 1
1565 #
1563 #
1566 #
1564 #
1567 # def setup(self, nSamples, nChannels, buffer_size = 4):
1565 # def setup(self, nSamples, nChannels, buffer_size = 4):
1568 #
1566 #
1569 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1567 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1570 # maxlen = buffer_size*nSamples)
1568 # maxlen = buffer_size*nSamples)
1571 #
1569 #
1572 # bufferList = []
1570 # bufferList = []
1573 #
1571 #
1574 # for i in range(nChannels):
1572 # for i in range(nChannels):
1575 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1573 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1576 # maxlen = buffer_size*nSamples)
1574 # maxlen = buffer_size*nSamples)
1577 #
1575 #
1578 # bufferList.append(bufferByChannel)
1576 # bufferList.append(bufferByChannel)
1579 #
1577 #
1580 # self.__nSamples = nSamples
1578 # self.__nSamples = nSamples
1581 # self.__nChannels = nChannels
1579 # self.__nChannels = nChannels
1582 # self.__bufferList = bufferList
1580 # self.__bufferList = bufferList
1583 #
1581 #
1584 # def run(self, dataOut, channel = 0):
1582 # def run(self, dataOut, channel = 0):
1585 #
1583 #
1586 # if not self.isConfig:
1584 # if not self.isConfig:
1587 # nSamples = dataOut.nHeights
1585 # nSamples = dataOut.nHeights
1588 # nChannels = dataOut.nChannels
1586 # nChannels = dataOut.nChannels
1589 # self.setup(nSamples, nChannels)
1587 # self.setup(nSamples, nChannels)
1590 # self.isConfig = True
1588 # self.isConfig = True
1591 #
1589 #
1592 # #Append new data to internal buffer
1590 # #Append new data to internal buffer
1593 # for thisChannel in range(self.__nChannels):
1591 # for thisChannel in range(self.__nChannels):
1594 # bufferByChannel = self.__bufferList[thisChannel]
1592 # bufferByChannel = self.__bufferList[thisChannel]
1595 # bufferByChannel.extend(dataOut.data[thisChannel])
1593 # bufferByChannel.extend(dataOut.data[thisChannel])
1596 #
1594 #
1597 # if self.__pulseFound:
1595 # if self.__pulseFound:
1598 # self.__startIndex -= self.__nSamples
1596 # self.__startIndex -= self.__nSamples
1599 #
1597 #
1600 # #Finding Tx Pulse
1598 # #Finding Tx Pulse
1601 # if not self.__pulseFound:
1599 # if not self.__pulseFound:
1602 # indexFound = self.__findTxPulse(dataOut, channel)
1600 # indexFound = self.__findTxPulse(dataOut, channel)
1603 #
1601 #
1604 # if indexFound == None:
1602 # if indexFound == None:
1605 # dataOut.flagNoData = True
1603 # dataOut.flagNoData = True
1606 # return
1604 # return
1607 #
1605 #
1608 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1606 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1609 # self.__pulseFound = True
1607 # self.__pulseFound = True
1610 # self.__startIndex = indexFound
1608 # self.__startIndex = indexFound
1611 #
1609 #
1612 # #If pulse was found ...
1610 # #If pulse was found ...
1613 # for thisChannel in range(self.__nChannels):
1611 # for thisChannel in range(self.__nChannels):
1614 # bufferByChannel = self.__bufferList[thisChannel]
1612 # bufferByChannel = self.__bufferList[thisChannel]
1615 # #print self.__startIndex
1613 # #print self.__startIndex
1616 # x = numpy.array(bufferByChannel)
1614 # x = numpy.array(bufferByChannel)
1617 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1615 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1618 #
1616 #
1619 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1617 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1620 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1618 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1621 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1619 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1622 #
1620 #
1623 # dataOut.data = self.__arrayBuffer
1621 # dataOut.data = self.__arrayBuffer
1624 #
1622 #
1625 # self.__startIndex += self.__newNSamples
1623 # self.__startIndex += self.__newNSamples
1626 #
1624 #
1627 # return No newline at end of file
1625 # return
General Comments 0
You need to be logged in to leave comments. Login now