##// END OF EJS Templates
fix minHei
Alexander Valdez -
r1676:077ec9b5e257
parent child
Show More
@@ -1,1629 +1,1627
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 print(minIndex)
196 print(maxIndex)
197 self.selectHeightsByIndex(minIndex, maxIndex)
195 self.selectHeightsByIndex(minIndex, maxIndex)
198
196
199 return self.dataOut
197 return self.dataOut
200
198
201 def selectHeightsByIndex(self, minIndex, maxIndex):
199 def selectHeightsByIndex(self, minIndex, maxIndex):
202 """
200 """
203 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
204 minIndex <= index <= maxIndex
202 minIndex <= index <= maxIndex
205
203
206 Input:
204 Input:
207 minIndex : valor de indice minimo de altura a considerar
205 minIndex : valor de indice minimo de altura a considerar
208 maxIndex : valor de indice maximo de altura a considerar
206 maxIndex : valor de indice maximo de altura a considerar
209
207
210 Affected:
208 Affected:
211 self.dataOut.data
209 self.dataOut.data
212 self.dataOut.heightList
210 self.dataOut.heightList
213
211
214 Return:
212 Return:
215 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
216 """
214 """
217
215
218 if self.dataOut.type == 'Voltage':
216 if self.dataOut.type == 'Voltage':
219 print(minIndex)
217 print(minIndex)
220 print(maxIndex)
218 print(maxIndex)
221 if (minIndex < 0) or (minIndex > maxIndex):
219 if (minIndex < 0) or (minIndex > maxIndex):
222 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
220 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
223
221
224 if (maxIndex >= self.dataOut.nHeights):
222 if (maxIndex >= self.dataOut.nHeights):
225 maxIndex = self.dataOut.nHeights
223 maxIndex = self.dataOut.nHeights
226
224
227 #voltage
225 #voltage
228 if self.dataOut.flagDataAsBlock:
226 if self.dataOut.flagDataAsBlock:
229 """
227 """
230 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
228 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
231 """
229 """
232 data = self.dataOut.data[:,:, minIndex:maxIndex]
230 data = self.dataOut.data[:,:, minIndex:maxIndex]
233 else:
231 else:
234 data = self.dataOut.data[:, minIndex:maxIndex]
232 data = self.dataOut.data[:, minIndex:maxIndex]
235
233
236 # firstHeight = self.dataOut.heightList[minIndex]
234 # firstHeight = self.dataOut.heightList[minIndex]
237
235
238 self.dataOut.data = data
236 self.dataOut.data = data
239 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
237 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
240
238
241 if self.dataOut.nHeights <= 1:
239 if self.dataOut.nHeights <= 1:
242 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
240 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
243 elif self.dataOut.type == 'Spectra':
241 elif self.dataOut.type == 'Spectra':
244 if (minIndex < 0) or (minIndex > maxIndex):
242 if (minIndex < 0) or (minIndex > maxIndex):
245 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
243 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
246 minIndex, maxIndex))
244 minIndex, maxIndex))
247
245
248 if (maxIndex >= self.dataOut.nHeights):
246 if (maxIndex >= self.dataOut.nHeights):
249 maxIndex = self.dataOut.nHeights - 1
247 maxIndex = self.dataOut.nHeights - 1
250
248
251 # Spectra
249 # Spectra
252 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
250 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
253
251
254 data_cspc = None
252 data_cspc = None
255 if self.dataOut.data_cspc is not None:
253 if self.dataOut.data_cspc is not None:
256 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
254 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
257
255
258 data_dc = None
256 data_dc = None
259 if self.dataOut.data_dc is not None:
257 if self.dataOut.data_dc is not None:
260 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
258 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
261
259
262 self.dataOut.data_spc = data_spc
260 self.dataOut.data_spc = data_spc
263 self.dataOut.data_cspc = data_cspc
261 self.dataOut.data_cspc = data_cspc
264 self.dataOut.data_dc = data_dc
262 self.dataOut.data_dc = data_dc
265
263
266 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
264 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
267
265
268 return 1
266 return 1
269
267
270
268
271 class filterByHeights(Operation):
269 class filterByHeights(Operation):
272
270
273 def run(self, dataOut, window):
271 def run(self, dataOut, window):
274
272
275 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
273 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
276
274
277 if window == None:
275 if window == None:
278 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
276 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
279
277
280 newdelta = deltaHeight * window
278 newdelta = deltaHeight * window
281 r = dataOut.nHeights % window
279 r = dataOut.nHeights % window
282 newheights = (dataOut.nHeights-r)/window
280 newheights = (dataOut.nHeights-r)/window
283
281
284 if newheights <= 1:
282 if newheights <= 1:
285 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
283 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
286
284
287 if dataOut.flagDataAsBlock:
285 if dataOut.flagDataAsBlock:
288 """
286 """
289 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
287 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
290 """
288 """
291 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
289 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
292 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
290 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
293 buffer = numpy.sum(buffer,3)
291 buffer = numpy.sum(buffer,3)
294
292
295 else:
293 else:
296 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
294 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
297 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
295 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
298 buffer = numpy.sum(buffer,2)
296 buffer = numpy.sum(buffer,2)
299
297
300 dataOut.data = buffer
298 dataOut.data = buffer
301 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
299 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
302 dataOut.windowOfFilter = window
300 dataOut.windowOfFilter = window
303
301
304 return dataOut
302 return dataOut
305
303
306
304
307 class setH0(Operation):
305 class setH0(Operation):
308
306
309 def run(self, dataOut, h0, deltaHeight = None):
307 def run(self, dataOut, h0, deltaHeight = None):
310
308
311 if not deltaHeight:
309 if not deltaHeight:
312 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
310 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
313
311
314 nHeights = dataOut.nHeights
312 nHeights = dataOut.nHeights
315
313
316 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
314 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
317
315
318 dataOut.heightList = newHeiRange
316 dataOut.heightList = newHeiRange
319
317
320 return dataOut
318 return dataOut
321
319
322
320
323 class deFlip(Operation):
321 class deFlip(Operation):
324
322
325 def run(self, dataOut, channelList = []):
323 def run(self, dataOut, channelList = []):
326
324
327 data = dataOut.data.copy()
325 data = dataOut.data.copy()
328
326
329 if dataOut.flagDataAsBlock:
327 if dataOut.flagDataAsBlock:
330 flip = self.flip
328 flip = self.flip
331 profileList = list(range(dataOut.nProfiles))
329 profileList = list(range(dataOut.nProfiles))
332
330
333 if not channelList:
331 if not channelList:
334 for thisProfile in profileList:
332 for thisProfile in profileList:
335 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
333 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
336 flip *= -1.0
334 flip *= -1.0
337 else:
335 else:
338 for thisChannel in channelList:
336 for thisChannel in channelList:
339 if thisChannel not in dataOut.channelList:
337 if thisChannel not in dataOut.channelList:
340 continue
338 continue
341
339
342 for thisProfile in profileList:
340 for thisProfile in profileList:
343 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
341 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
344 flip *= -1.0
342 flip *= -1.0
345
343
346 self.flip = flip
344 self.flip = flip
347
345
348 else:
346 else:
349 if not channelList:
347 if not channelList:
350 data[:,:] = data[:,:]*self.flip
348 data[:,:] = data[:,:]*self.flip
351 else:
349 else:
352 for thisChannel in channelList:
350 for thisChannel in channelList:
353 if thisChannel not in dataOut.channelList:
351 if thisChannel not in dataOut.channelList:
354 continue
352 continue
355
353
356 data[thisChannel,:] = data[thisChannel,:]*self.flip
354 data[thisChannel,:] = data[thisChannel,:]*self.flip
357
355
358 self.flip *= -1.
356 self.flip *= -1.
359
357
360 dataOut.data = data
358 dataOut.data = data
361
359
362 return dataOut
360 return dataOut
363
361
364
362
365 class setAttribute(Operation):
363 class setAttribute(Operation):
366 '''
364 '''
367 Set an arbitrary attribute(s) to dataOut
365 Set an arbitrary attribute(s) to dataOut
368 '''
366 '''
369
367
370 def __init__(self):
368 def __init__(self):
371
369
372 Operation.__init__(self)
370 Operation.__init__(self)
373 self._ready = False
371 self._ready = False
374
372
375 def run(self, dataOut, **kwargs):
373 def run(self, dataOut, **kwargs):
376
374
377 for key, value in kwargs.items():
375 for key, value in kwargs.items():
378 setattr(dataOut, key, value)
376 setattr(dataOut, key, value)
379
377
380 return dataOut
378 return dataOut
381
379
382
380
383 @MPDecorator
381 @MPDecorator
384 class printAttribute(Operation):
382 class printAttribute(Operation):
385 '''
383 '''
386 Print an arbitrary attribute of dataOut
384 Print an arbitrary attribute of dataOut
387 '''
385 '''
388
386
389 def __init__(self):
387 def __init__(self):
390
388
391 Operation.__init__(self)
389 Operation.__init__(self)
392
390
393 def run(self, dataOut, attributes):
391 def run(self, dataOut, attributes):
394
392
395 if isinstance(attributes, str):
393 if isinstance(attributes, str):
396 attributes = [attributes]
394 attributes = [attributes]
397 for attr in attributes:
395 for attr in attributes:
398 if hasattr(dataOut, attr):
396 if hasattr(dataOut, attr):
399 log.log(getattr(dataOut, attr), attr)
397 log.log(getattr(dataOut, attr), attr)
400
398
401
399
402 class interpolateHeights(Operation):
400 class interpolateHeights(Operation):
403
401
404 def run(self, dataOut, topLim, botLim):
402 def run(self, dataOut, topLim, botLim):
405 #69 al 72 para julia
403 #69 al 72 para julia
406 #82-84 para meteoros
404 #82-84 para meteoros
407 if len(numpy.shape(dataOut.data))==2:
405 if len(numpy.shape(dataOut.data))==2:
408 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
406 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
409 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
407 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
410 #dataOut.data[:,botLim:limSup+1] = sampInterp
408 #dataOut.data[:,botLim:limSup+1] = sampInterp
411 dataOut.data[:,botLim:topLim+1] = sampInterp
409 dataOut.data[:,botLim:topLim+1] = sampInterp
412 else:
410 else:
413 nHeights = dataOut.data.shape[2]
411 nHeights = dataOut.data.shape[2]
414 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
412 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
415 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
413 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
416 f = interpolate.interp1d(x, y, axis = 2)
414 f = interpolate.interp1d(x, y, axis = 2)
417 xnew = numpy.arange(botLim,topLim+1)
415 xnew = numpy.arange(botLim,topLim+1)
418 ynew = f(xnew)
416 ynew = f(xnew)
419 dataOut.data[:,:,botLim:topLim+1] = ynew
417 dataOut.data[:,:,botLim:topLim+1] = ynew
420
418
421 return dataOut
419 return dataOut
422
420
423
421
424 class CohInt(Operation):
422 class CohInt(Operation):
425
423
426 isConfig = False
424 isConfig = False
427 __profIndex = 0
425 __profIndex = 0
428 __byTime = False
426 __byTime = False
429 __initime = None
427 __initime = None
430 __lastdatatime = None
428 __lastdatatime = None
431 __integrationtime = None
429 __integrationtime = None
432 __buffer = None
430 __buffer = None
433 __bufferStride = []
431 __bufferStride = []
434 __dataReady = False
432 __dataReady = False
435 __profIndexStride = 0
433 __profIndexStride = 0
436 __dataToPutStride = False
434 __dataToPutStride = False
437 n = None
435 n = None
438
436
439 def __init__(self, **kwargs):
437 def __init__(self, **kwargs):
440
438
441 Operation.__init__(self, **kwargs)
439 Operation.__init__(self, **kwargs)
442
440
443 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
441 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
444 """
442 """
445 Set the parameters of the integration class.
443 Set the parameters of the integration class.
446
444
447 Inputs:
445 Inputs:
448
446
449 n : Number of coherent integrations
447 n : Number of coherent integrations
450 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
448 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
451 overlapping :
449 overlapping :
452 """
450 """
453
451
454 self.__initime = None
452 self.__initime = None
455 self.__lastdatatime = 0
453 self.__lastdatatime = 0
456 self.__buffer = None
454 self.__buffer = None
457 self.__dataReady = False
455 self.__dataReady = False
458 self.byblock = byblock
456 self.byblock = byblock
459 self.stride = stride
457 self.stride = stride
460
458
461 if n == None and timeInterval == None:
459 if n == None and timeInterval == None:
462 raise ValueError("n or timeInterval should be specified ...")
460 raise ValueError("n or timeInterval should be specified ...")
463
461
464 if n != None:
462 if n != None:
465 self.n = n
463 self.n = n
466 self.__byTime = False
464 self.__byTime = False
467 else:
465 else:
468 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
466 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
469 self.n = 9999
467 self.n = 9999
470 self.__byTime = True
468 self.__byTime = True
471
469
472 if overlapping:
470 if overlapping:
473 self.__withOverlapping = True
471 self.__withOverlapping = True
474 self.__buffer = None
472 self.__buffer = None
475 else:
473 else:
476 self.__withOverlapping = False
474 self.__withOverlapping = False
477 self.__buffer = 0
475 self.__buffer = 0
478
476
479 self.__profIndex = 0
477 self.__profIndex = 0
480
478
481 def putData(self, data):
479 def putData(self, data):
482
480
483 """
481 """
484 Add a profile to the __buffer and increase in one the __profileIndex
482 Add a profile to the __buffer and increase in one the __profileIndex
485
483
486 """
484 """
487
485
488 if not self.__withOverlapping:
486 if not self.__withOverlapping:
489 self.__buffer += data.copy()
487 self.__buffer += data.copy()
490 self.__profIndex += 1
488 self.__profIndex += 1
491 return
489 return
492
490
493 #Overlapping data
491 #Overlapping data
494 nChannels, nHeis = data.shape
492 nChannels, nHeis = data.shape
495 data = numpy.reshape(data, (1, nChannels, nHeis))
493 data = numpy.reshape(data, (1, nChannels, nHeis))
496
494
497 #If the buffer is empty then it takes the data value
495 #If the buffer is empty then it takes the data value
498 if self.__buffer is None:
496 if self.__buffer is None:
499 self.__buffer = data
497 self.__buffer = data
500 self.__profIndex += 1
498 self.__profIndex += 1
501 return
499 return
502
500
503 #If the buffer length is lower than n then stakcing the data value
501 #If the buffer length is lower than n then stakcing the data value
504 if self.__profIndex < self.n:
502 if self.__profIndex < self.n:
505 self.__buffer = numpy.vstack((self.__buffer, data))
503 self.__buffer = numpy.vstack((self.__buffer, data))
506 self.__profIndex += 1
504 self.__profIndex += 1
507 return
505 return
508
506
509 #If the buffer length is equal to n then replacing the last buffer value with the data value
507 #If the buffer length is equal to n then replacing the last buffer value with the data value
510 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
508 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
511 self.__buffer[self.n-1] = data
509 self.__buffer[self.n-1] = data
512 self.__profIndex = self.n
510 self.__profIndex = self.n
513 return
511 return
514
512
515
513
516 def pushData(self):
514 def pushData(self):
517 """
515 """
518 Return the sum of the last profiles and the profiles used in the sum.
516 Return the sum of the last profiles and the profiles used in the sum.
519
517
520 Affected:
518 Affected:
521
519
522 self.__profileIndex
520 self.__profileIndex
523
521
524 """
522 """
525
523
526 if not self.__withOverlapping:
524 if not self.__withOverlapping:
527 data = self.__buffer
525 data = self.__buffer
528 n = self.__profIndex
526 n = self.__profIndex
529
527
530 self.__buffer = 0
528 self.__buffer = 0
531 self.__profIndex = 0
529 self.__profIndex = 0
532
530
533 return data, n
531 return data, n
534
532
535 #Integration with Overlapping
533 #Integration with Overlapping
536 data = numpy.sum(self.__buffer, axis=0)
534 data = numpy.sum(self.__buffer, axis=0)
537 # print data
535 # print data
538 # raise
536 # raise
539 n = self.__profIndex
537 n = self.__profIndex
540
538
541 return data, n
539 return data, n
542
540
543 def byProfiles(self, data):
541 def byProfiles(self, data):
544
542
545 self.__dataReady = False
543 self.__dataReady = False
546 avgdata = None
544 avgdata = None
547 # n = None
545 # n = None
548 # print data
546 # print data
549 # raise
547 # raise
550 self.putData(data)
548 self.putData(data)
551
549
552 if self.__profIndex == self.n:
550 if self.__profIndex == self.n:
553 avgdata, n = self.pushData()
551 avgdata, n = self.pushData()
554 self.__dataReady = True
552 self.__dataReady = True
555
553
556 return avgdata
554 return avgdata
557
555
558 def byTime(self, data, datatime):
556 def byTime(self, data, datatime):
559
557
560 self.__dataReady = False
558 self.__dataReady = False
561 avgdata = None
559 avgdata = None
562 n = None
560 n = None
563
561
564 self.putData(data)
562 self.putData(data)
565
563
566 if (datatime - self.__initime) >= self.__integrationtime:
564 if (datatime - self.__initime) >= self.__integrationtime:
567 avgdata, n = self.pushData()
565 avgdata, n = self.pushData()
568 self.n = n
566 self.n = n
569 self.__dataReady = True
567 self.__dataReady = True
570
568
571 return avgdata
569 return avgdata
572
570
573 def integrateByStride(self, data, datatime):
571 def integrateByStride(self, data, datatime):
574 # print data
572 # print data
575 if self.__profIndex == 0:
573 if self.__profIndex == 0:
576 self.__buffer = [[data.copy(), datatime]]
574 self.__buffer = [[data.copy(), datatime]]
577 else:
575 else:
578 self.__buffer.append([data.copy(),datatime])
576 self.__buffer.append([data.copy(),datatime])
579 self.__profIndex += 1
577 self.__profIndex += 1
580 self.__dataReady = False
578 self.__dataReady = False
581
579
582 if self.__profIndex == self.n * self.stride :
580 if self.__profIndex == self.n * self.stride :
583 self.__dataToPutStride = True
581 self.__dataToPutStride = True
584 self.__profIndexStride = 0
582 self.__profIndexStride = 0
585 self.__profIndex = 0
583 self.__profIndex = 0
586 self.__bufferStride = []
584 self.__bufferStride = []
587 for i in range(self.stride):
585 for i in range(self.stride):
588 current = self.__buffer[i::self.stride]
586 current = self.__buffer[i::self.stride]
589 data = numpy.sum([t[0] for t in current], axis=0)
587 data = numpy.sum([t[0] for t in current], axis=0)
590 avgdatatime = numpy.average([t[1] for t in current])
588 avgdatatime = numpy.average([t[1] for t in current])
591 # print data
589 # print data
592 self.__bufferStride.append((data, avgdatatime))
590 self.__bufferStride.append((data, avgdatatime))
593
591
594 if self.__dataToPutStride:
592 if self.__dataToPutStride:
595 self.__dataReady = True
593 self.__dataReady = True
596 self.__profIndexStride += 1
594 self.__profIndexStride += 1
597 if self.__profIndexStride == self.stride:
595 if self.__profIndexStride == self.stride:
598 self.__dataToPutStride = False
596 self.__dataToPutStride = False
599 # print self.__bufferStride[self.__profIndexStride - 1]
597 # print self.__bufferStride[self.__profIndexStride - 1]
600 # raise
598 # raise
601 return self.__bufferStride[self.__profIndexStride - 1]
599 return self.__bufferStride[self.__profIndexStride - 1]
602
600
603
601
604 return None, None
602 return None, None
605
603
606 def integrate(self, data, datatime=None):
604 def integrate(self, data, datatime=None):
607
605
608 if self.__initime == None:
606 if self.__initime == None:
609 self.__initime = datatime
607 self.__initime = datatime
610
608
611 if self.__byTime:
609 if self.__byTime:
612 avgdata = self.byTime(data, datatime)
610 avgdata = self.byTime(data, datatime)
613 else:
611 else:
614 avgdata = self.byProfiles(data)
612 avgdata = self.byProfiles(data)
615
613
616
614
617 self.__lastdatatime = datatime
615 self.__lastdatatime = datatime
618
616
619 if avgdata is None:
617 if avgdata is None:
620 return None, None
618 return None, None
621
619
622 avgdatatime = self.__initime
620 avgdatatime = self.__initime
623
621
624 deltatime = datatime - self.__lastdatatime
622 deltatime = datatime - self.__lastdatatime
625
623
626 if not self.__withOverlapping:
624 if not self.__withOverlapping:
627 self.__initime = datatime
625 self.__initime = datatime
628 else:
626 else:
629 self.__initime += deltatime
627 self.__initime += deltatime
630
628
631 return avgdata, avgdatatime
629 return avgdata, avgdatatime
632
630
633 def integrateByBlock(self, dataOut):
631 def integrateByBlock(self, dataOut):
634
632
635 times = int(dataOut.data.shape[1]/self.n)
633 times = int(dataOut.data.shape[1]/self.n)
636 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
634 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
637
635
638 id_min = 0
636 id_min = 0
639 id_max = self.n
637 id_max = self.n
640
638
641 for i in range(times):
639 for i in range(times):
642 junk = dataOut.data[:,id_min:id_max,:]
640 junk = dataOut.data[:,id_min:id_max,:]
643 avgdata[:,i,:] = junk.sum(axis=1)
641 avgdata[:,i,:] = junk.sum(axis=1)
644 id_min += self.n
642 id_min += self.n
645 id_max += self.n
643 id_max += self.n
646
644
647 timeInterval = dataOut.ippSeconds*self.n
645 timeInterval = dataOut.ippSeconds*self.n
648 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
646 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
649 self.__dataReady = True
647 self.__dataReady = True
650 return avgdata, avgdatatime
648 return avgdata, avgdatatime
651
649
652 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
650 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
653
651
654 if not self.isConfig:
652 if not self.isConfig:
655 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
653 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
656 self.isConfig = True
654 self.isConfig = True
657 if dataOut.flagDataAsBlock:
655 if dataOut.flagDataAsBlock:
658 """
656 """
659 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
657 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
660 """
658 """
661 avgdata, avgdatatime = self.integrateByBlock(dataOut)
659 avgdata, avgdatatime = self.integrateByBlock(dataOut)
662 dataOut.nProfiles /= self.n
660 dataOut.nProfiles /= self.n
663 else:
661 else:
664 if stride is None:
662 if stride is None:
665 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
663 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
666 else:
664 else:
667 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
665 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
668
666
669
667
670 # dataOut.timeInterval *= n
668 # dataOut.timeInterval *= n
671 dataOut.flagNoData = True
669 dataOut.flagNoData = True
672
670
673 if self.__dataReady:
671 if self.__dataReady:
674 dataOut.data = avgdata
672 dataOut.data = avgdata
675 if not dataOut.flagCohInt:
673 if not dataOut.flagCohInt:
676 dataOut.nCohInt *= self.n
674 dataOut.nCohInt *= self.n
677 dataOut.flagCohInt = True
675 dataOut.flagCohInt = True
678 dataOut.utctime = avgdatatime
676 dataOut.utctime = avgdatatime
679 # print avgdata, avgdatatime
677 # print avgdata, avgdatatime
680 # raise
678 # raise
681 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
679 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
682 dataOut.flagNoData = False
680 dataOut.flagNoData = False
683 return dataOut
681 return dataOut
684
682
685 class Decoder(Operation):
683 class Decoder(Operation):
686
684
687 isConfig = False
685 isConfig = False
688 __profIndex = 0
686 __profIndex = 0
689
687
690 code = None
688 code = None
691
689
692 nCode = None
690 nCode = None
693 nBaud = None
691 nBaud = None
694
692
695 def __init__(self, **kwargs):
693 def __init__(self, **kwargs):
696
694
697 Operation.__init__(self, **kwargs)
695 Operation.__init__(self, **kwargs)
698
696
699 self.times = None
697 self.times = None
700 self.osamp = None
698 self.osamp = None
701 # self.__setValues = False
699 # self.__setValues = False
702 self.isConfig = False
700 self.isConfig = False
703 self.setupReq = False
701 self.setupReq = False
704 def setup(self, code, osamp, dataOut):
702 def setup(self, code, osamp, dataOut):
705
703
706 self.__profIndex = 0
704 self.__profIndex = 0
707
705
708 self.code = code
706 self.code = code
709
707
710 self.nCode = len(code)
708 self.nCode = len(code)
711 self.nBaud = len(code[0])
709 self.nBaud = len(code[0])
712
710
713 if (osamp != None) and (osamp >1):
711 if (osamp != None) and (osamp >1):
714 self.osamp = osamp
712 self.osamp = osamp
715 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
713 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
716 self.nBaud = self.nBaud*self.osamp
714 self.nBaud = self.nBaud*self.osamp
717
715
718 self.__nChannels = dataOut.nChannels
716 self.__nChannels = dataOut.nChannels
719 self.__nProfiles = dataOut.nProfiles
717 self.__nProfiles = dataOut.nProfiles
720 self.__nHeis = dataOut.nHeights
718 self.__nHeis = dataOut.nHeights
721
719
722 if self.__nHeis < self.nBaud:
720 if self.__nHeis < self.nBaud:
723 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
721 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
724
722
725 #Frequency
723 #Frequency
726 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
724 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
727
725
728 __codeBuffer[:,0:self.nBaud] = self.code
726 __codeBuffer[:,0:self.nBaud] = self.code
729
727
730 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
728 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
731
729
732 if dataOut.flagDataAsBlock:
730 if dataOut.flagDataAsBlock:
733
731
734 self.ndatadec = self.__nHeis #- self.nBaud + 1
732 self.ndatadec = self.__nHeis #- self.nBaud + 1
735
733
736 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
734 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
737
735
738 else:
736 else:
739
737
740 #Time
738 #Time
741 self.ndatadec = self.__nHeis #- self.nBaud + 1
739 self.ndatadec = self.__nHeis #- self.nBaud + 1
742
740
743 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
741 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
744
742
745 def __convolutionInFreq(self, data):
743 def __convolutionInFreq(self, data):
746
744
747 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
745 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
748
746
749 fft_data = numpy.fft.fft(data, axis=1)
747 fft_data = numpy.fft.fft(data, axis=1)
750
748
751 conv = fft_data*fft_code
749 conv = fft_data*fft_code
752
750
753 data = numpy.fft.ifft(conv,axis=1)
751 data = numpy.fft.ifft(conv,axis=1)
754
752
755 return data
753 return data
756
754
757 def __convolutionInFreqOpt(self, data):
755 def __convolutionInFreqOpt(self, data):
758
756
759 raise NotImplementedError
757 raise NotImplementedError
760
758
761 def __convolutionInTime(self, data):
759 def __convolutionInTime(self, data):
762
760
763 code = self.code[self.__profIndex]
761 code = self.code[self.__profIndex]
764 for i in range(self.__nChannels):
762 for i in range(self.__nChannels):
765 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
763 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
766
764
767 return self.datadecTime
765 return self.datadecTime
768
766
769 def __convolutionByBlockInTime(self, data):
767 def __convolutionByBlockInTime(self, data):
770
768
771 repetitions = int(self.__nProfiles / self.nCode)
769 repetitions = int(self.__nProfiles / self.nCode)
772 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
770 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
773 junk = junk.flatten()
771 junk = junk.flatten()
774 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
772 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
775 profilesList = range(self.__nProfiles)
773 profilesList = range(self.__nProfiles)
776
774
777 for i in range(self.__nChannels):
775 for i in range(self.__nChannels):
778 for j in profilesList:
776 for j in profilesList:
779 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
777 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
780 return self.datadecTime
778 return self.datadecTime
781
779
782 def __convolutionByBlockInFreq(self, data):
780 def __convolutionByBlockInFreq(self, data):
783
781
784 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
782 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
785
783
786
784
787 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
785 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
788
786
789 fft_data = numpy.fft.fft(data, axis=2)
787 fft_data = numpy.fft.fft(data, axis=2)
790
788
791 conv = fft_data*fft_code
789 conv = fft_data*fft_code
792
790
793 data = numpy.fft.ifft(conv,axis=2)
791 data = numpy.fft.ifft(conv,axis=2)
794
792
795 return data
793 return data
796
794
797
795
798 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
796 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
799
797
800 if dataOut.flagDecodeData:
798 if dataOut.flagDecodeData:
801 print("This data is already decoded, recoding again ...")
799 print("This data is already decoded, recoding again ...")
802
800
803 if not self.isConfig:
801 if not self.isConfig:
804
802
805 if code is None:
803 if code is None:
806 if dataOut.code is None:
804 if dataOut.code is None:
807 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
805 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
808
806
809 code = dataOut.code
807 code = dataOut.code
810 else:
808 else:
811 code = numpy.array(code).reshape(nCode,nBaud)
809 code = numpy.array(code).reshape(nCode,nBaud)
812 self.setup(code, osamp, dataOut)
810 self.setup(code, osamp, dataOut)
813
811
814 self.isConfig = True
812 self.isConfig = True
815
813
816 if mode == 3:
814 if mode == 3:
817 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
815 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
818
816
819 if times != None:
817 if times != None:
820 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
818 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
821
819
822 if self.code is None:
820 if self.code is None:
823 print("Fail decoding: Code is not defined.")
821 print("Fail decoding: Code is not defined.")
824 return
822 return
825
823
826 self.__nProfiles = dataOut.nProfiles
824 self.__nProfiles = dataOut.nProfiles
827 datadec = None
825 datadec = None
828
826
829 if mode == 3:
827 if mode == 3:
830 mode = 0
828 mode = 0
831
829
832 if dataOut.flagDataAsBlock:
830 if dataOut.flagDataAsBlock:
833 """
831 """
834 Decoding when data have been read as block,
832 Decoding when data have been read as block,
835 """
833 """
836
834
837 if mode == 0:
835 if mode == 0:
838 datadec = self.__convolutionByBlockInTime(dataOut.data)
836 datadec = self.__convolutionByBlockInTime(dataOut.data)
839 if mode == 1:
837 if mode == 1:
840 datadec = self.__convolutionByBlockInFreq(dataOut.data)
838 datadec = self.__convolutionByBlockInFreq(dataOut.data)
841 else:
839 else:
842 """
840 """
843 Decoding when data have been read profile by profile
841 Decoding when data have been read profile by profile
844 """
842 """
845 if mode == 0:
843 if mode == 0:
846 datadec = self.__convolutionInTime(dataOut.data)
844 datadec = self.__convolutionInTime(dataOut.data)
847
845
848 if mode == 1:
846 if mode == 1:
849 datadec = self.__convolutionInFreq(dataOut.data)
847 datadec = self.__convolutionInFreq(dataOut.data)
850
848
851 if mode == 2:
849 if mode == 2:
852 datadec = self.__convolutionInFreqOpt(dataOut.data)
850 datadec = self.__convolutionInFreqOpt(dataOut.data)
853
851
854 if datadec is None:
852 if datadec is None:
855 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
853 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
856
854
857 dataOut.code = self.code
855 dataOut.code = self.code
858 dataOut.nCode = self.nCode
856 dataOut.nCode = self.nCode
859 dataOut.nBaud = self.nBaud
857 dataOut.nBaud = self.nBaud
860
858
861 dataOut.data = datadec
859 dataOut.data = datadec
862 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
860 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
863
861
864 dataOut.flagDecodeData = True #asumo q la data esta decodificada
862 dataOut.flagDecodeData = True #asumo q la data esta decodificada
865
863
866 if self.__profIndex == self.nCode-1:
864 if self.__profIndex == self.nCode-1:
867 self.__profIndex = 0
865 self.__profIndex = 0
868 return dataOut
866 return dataOut
869
867
870 self.__profIndex += 1
868 self.__profIndex += 1
871
869
872 return dataOut
870 return dataOut
873
871
874
872
875 class ProfileConcat(Operation):
873 class ProfileConcat(Operation):
876
874
877 isConfig = False
875 isConfig = False
878 buffer = None
876 buffer = None
879
877
880 def __init__(self, **kwargs):
878 def __init__(self, **kwargs):
881
879
882 Operation.__init__(self, **kwargs)
880 Operation.__init__(self, **kwargs)
883 self.profileIndex = 0
881 self.profileIndex = 0
884
882
885 def reset(self):
883 def reset(self):
886 self.buffer = numpy.zeros_like(self.buffer)
884 self.buffer = numpy.zeros_like(self.buffer)
887 self.start_index = 0
885 self.start_index = 0
888 self.times = 1
886 self.times = 1
889
887
890 def setup(self, data, m, n=1):
888 def setup(self, data, m, n=1):
891 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
889 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
892 self.nHeights = data.shape[1]#.nHeights
890 self.nHeights = data.shape[1]#.nHeights
893 self.start_index = 0
891 self.start_index = 0
894 self.times = 1
892 self.times = 1
895
893
896 def concat(self, data):
894 def concat(self, data):
897
895
898 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
896 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
899 self.start_index = self.start_index + self.nHeights
897 self.start_index = self.start_index + self.nHeights
900
898
901 def run(self, dataOut, m):
899 def run(self, dataOut, m):
902 dataOut.flagNoData = True
900 dataOut.flagNoData = True
903
901
904 if not self.isConfig:
902 if not self.isConfig:
905 self.setup(dataOut.data, m, 1)
903 self.setup(dataOut.data, m, 1)
906 self.isConfig = True
904 self.isConfig = True
907
905
908 if dataOut.flagDataAsBlock:
906 if dataOut.flagDataAsBlock:
909 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
907 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
910
908
911 else:
909 else:
912 self.concat(dataOut.data)
910 self.concat(dataOut.data)
913 self.times += 1
911 self.times += 1
914 if self.times > m:
912 if self.times > m:
915 dataOut.data = self.buffer
913 dataOut.data = self.buffer
916 self.reset()
914 self.reset()
917 dataOut.flagNoData = False
915 dataOut.flagNoData = False
918 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
916 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
919 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
917 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
920 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
918 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
921 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
919 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
922 dataOut.ippSeconds *= m
920 dataOut.ippSeconds *= m
923 return dataOut
921 return dataOut
924
922
925 class ProfileSelector(Operation):
923 class ProfileSelector(Operation):
926
924
927 profileIndex = None
925 profileIndex = None
928 # Tamanho total de los perfiles
926 # Tamanho total de los perfiles
929 nProfiles = None
927 nProfiles = None
930
928
931 def __init__(self, **kwargs):
929 def __init__(self, **kwargs):
932
930
933 Operation.__init__(self, **kwargs)
931 Operation.__init__(self, **kwargs)
934 self.profileIndex = 0
932 self.profileIndex = 0
935
933
936 def incProfileIndex(self):
934 def incProfileIndex(self):
937
935
938 self.profileIndex += 1
936 self.profileIndex += 1
939
937
940 if self.profileIndex >= self.nProfiles:
938 if self.profileIndex >= self.nProfiles:
941 self.profileIndex = 0
939 self.profileIndex = 0
942
940
943 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
941 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
944
942
945 if profileIndex < minIndex:
943 if profileIndex < minIndex:
946 return False
944 return False
947
945
948 if profileIndex > maxIndex:
946 if profileIndex > maxIndex:
949 return False
947 return False
950
948
951 return True
949 return True
952
950
953 def isThisProfileInList(self, profileIndex, profileList):
951 def isThisProfileInList(self, profileIndex, profileList):
954
952
955 if profileIndex not in profileList:
953 if profileIndex not in profileList:
956 return False
954 return False
957
955
958 return True
956 return True
959
957
960 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
958 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
961
959
962 """
960 """
963 ProfileSelector:
961 ProfileSelector:
964
962
965 Inputs:
963 Inputs:
966 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
964 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
967
965
968 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
966 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
969
967
970 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
968 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
971
969
972 """
970 """
973
971
974 if rangeList is not None:
972 if rangeList is not None:
975 if type(rangeList[0]) not in (tuple, list):
973 if type(rangeList[0]) not in (tuple, list):
976 rangeList = [rangeList]
974 rangeList = [rangeList]
977
975
978 dataOut.flagNoData = True
976 dataOut.flagNoData = True
979
977
980 if dataOut.flagDataAsBlock:
978 if dataOut.flagDataAsBlock:
981 """
979 """
982 data dimension = [nChannels, nProfiles, nHeis]
980 data dimension = [nChannels, nProfiles, nHeis]
983 """
981 """
984 if profileList != None:
982 if profileList != None:
985 dataOut.data = dataOut.data[:,profileList,:]
983 dataOut.data = dataOut.data[:,profileList,:]
986
984
987 if profileRangeList != None:
985 if profileRangeList != None:
988 minIndex = profileRangeList[0]
986 minIndex = profileRangeList[0]
989 maxIndex = profileRangeList[1]
987 maxIndex = profileRangeList[1]
990 profileList = list(range(minIndex, maxIndex+1))
988 profileList = list(range(minIndex, maxIndex+1))
991
989
992 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
990 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
993
991
994 if rangeList != None:
992 if rangeList != None:
995
993
996 profileList = []
994 profileList = []
997
995
998 for thisRange in rangeList:
996 for thisRange in rangeList:
999 minIndex = thisRange[0]
997 minIndex = thisRange[0]
1000 maxIndex = thisRange[1]
998 maxIndex = thisRange[1]
1001
999
1002 profileList.extend(list(range(minIndex, maxIndex+1)))
1000 profileList.extend(list(range(minIndex, maxIndex+1)))
1003
1001
1004 dataOut.data = dataOut.data[:,profileList,:]
1002 dataOut.data = dataOut.data[:,profileList,:]
1005
1003
1006 dataOut.nProfiles = len(profileList)
1004 dataOut.nProfiles = len(profileList)
1007 dataOut.profileIndex = dataOut.nProfiles - 1
1005 dataOut.profileIndex = dataOut.nProfiles - 1
1008 dataOut.flagNoData = False
1006 dataOut.flagNoData = False
1009
1007
1010 return dataOut
1008 return dataOut
1011
1009
1012 """
1010 """
1013 data dimension = [nChannels, nHeis]
1011 data dimension = [nChannels, nHeis]
1014 """
1012 """
1015
1013
1016 if profileList != None:
1014 if profileList != None:
1017
1015
1018 if self.isThisProfileInList(dataOut.profileIndex, profileList):
1016 if self.isThisProfileInList(dataOut.profileIndex, profileList):
1019
1017
1020 self.nProfiles = len(profileList)
1018 self.nProfiles = len(profileList)
1021 dataOut.nProfiles = self.nProfiles
1019 dataOut.nProfiles = self.nProfiles
1022 dataOut.profileIndex = self.profileIndex
1020 dataOut.profileIndex = self.profileIndex
1023 dataOut.flagNoData = False
1021 dataOut.flagNoData = False
1024
1022
1025 self.incProfileIndex()
1023 self.incProfileIndex()
1026 return dataOut
1024 return dataOut
1027
1025
1028 if profileRangeList != None:
1026 if profileRangeList != None:
1029
1027
1030 minIndex = profileRangeList[0]
1028 minIndex = profileRangeList[0]
1031 maxIndex = profileRangeList[1]
1029 maxIndex = profileRangeList[1]
1032
1030
1033 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1031 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1034
1032
1035 self.nProfiles = maxIndex - minIndex + 1
1033 self.nProfiles = maxIndex - minIndex + 1
1036 dataOut.nProfiles = self.nProfiles
1034 dataOut.nProfiles = self.nProfiles
1037 dataOut.profileIndex = self.profileIndex
1035 dataOut.profileIndex = self.profileIndex
1038 dataOut.flagNoData = False
1036 dataOut.flagNoData = False
1039
1037
1040 self.incProfileIndex()
1038 self.incProfileIndex()
1041 return dataOut
1039 return dataOut
1042
1040
1043 if rangeList != None:
1041 if rangeList != None:
1044
1042
1045 nProfiles = 0
1043 nProfiles = 0
1046
1044
1047 for thisRange in rangeList:
1045 for thisRange in rangeList:
1048 minIndex = thisRange[0]
1046 minIndex = thisRange[0]
1049 maxIndex = thisRange[1]
1047 maxIndex = thisRange[1]
1050
1048
1051 nProfiles += maxIndex - minIndex + 1
1049 nProfiles += maxIndex - minIndex + 1
1052
1050
1053 for thisRange in rangeList:
1051 for thisRange in rangeList:
1054
1052
1055 minIndex = thisRange[0]
1053 minIndex = thisRange[0]
1056 maxIndex = thisRange[1]
1054 maxIndex = thisRange[1]
1057
1055
1058 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1056 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
1059
1057
1060 self.nProfiles = nProfiles
1058 self.nProfiles = nProfiles
1061 dataOut.nProfiles = self.nProfiles
1059 dataOut.nProfiles = self.nProfiles
1062 dataOut.profileIndex = self.profileIndex
1060 dataOut.profileIndex = self.profileIndex
1063 dataOut.flagNoData = False
1061 dataOut.flagNoData = False
1064
1062
1065 self.incProfileIndex()
1063 self.incProfileIndex()
1066
1064
1067 break
1065 break
1068
1066
1069 return dataOut
1067 return dataOut
1070
1068
1071
1069
1072 if beam != None: #beam is only for AMISR data
1070 if beam != None: #beam is only for AMISR data
1073 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1071 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
1074 dataOut.flagNoData = False
1072 dataOut.flagNoData = False
1075 dataOut.profileIndex = self.profileIndex
1073 dataOut.profileIndex = self.profileIndex
1076
1074
1077 self.incProfileIndex()
1075 self.incProfileIndex()
1078
1076
1079 return dataOut
1077 return dataOut
1080
1078
1081 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
1079 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
1082
1080
1083
1081
1084 class Reshaper(Operation):
1082 class Reshaper(Operation):
1085
1083
1086 def __init__(self, **kwargs):
1084 def __init__(self, **kwargs):
1087
1085
1088 Operation.__init__(self, **kwargs)
1086 Operation.__init__(self, **kwargs)
1089
1087
1090 self.__buffer = None
1088 self.__buffer = None
1091 self.__nitems = 0
1089 self.__nitems = 0
1092
1090
1093 def __appendProfile(self, dataOut, nTxs):
1091 def __appendProfile(self, dataOut, nTxs):
1094
1092
1095 if self.__buffer is None:
1093 if self.__buffer is None:
1096 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1094 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
1097 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1095 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
1098
1096
1099 ini = dataOut.nHeights * self.__nitems
1097 ini = dataOut.nHeights * self.__nitems
1100 end = ini + dataOut.nHeights
1098 end = ini + dataOut.nHeights
1101
1099
1102 self.__buffer[:, ini:end] = dataOut.data
1100 self.__buffer[:, ini:end] = dataOut.data
1103
1101
1104 self.__nitems += 1
1102 self.__nitems += 1
1105
1103
1106 return int(self.__nitems*nTxs)
1104 return int(self.__nitems*nTxs)
1107
1105
1108 def __getBuffer(self):
1106 def __getBuffer(self):
1109
1107
1110 if self.__nitems == int(1./self.__nTxs):
1108 if self.__nitems == int(1./self.__nTxs):
1111
1109
1112 self.__nitems = 0
1110 self.__nitems = 0
1113
1111
1114 return self.__buffer.copy()
1112 return self.__buffer.copy()
1115
1113
1116 return None
1114 return None
1117
1115
1118 def __checkInputs(self, dataOut, shape, nTxs):
1116 def __checkInputs(self, dataOut, shape, nTxs):
1119
1117
1120 if shape is None and nTxs is None:
1118 if shape is None and nTxs is None:
1121 raise ValueError("Reshaper: shape of factor should be defined")
1119 raise ValueError("Reshaper: shape of factor should be defined")
1122
1120
1123 if nTxs:
1121 if nTxs:
1124 if nTxs < 0:
1122 if nTxs < 0:
1125 raise ValueError("nTxs should be greater than 0")
1123 raise ValueError("nTxs should be greater than 0")
1126
1124
1127 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1125 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1128 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1126 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
1129
1127
1130 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1128 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1131
1129
1132 return shape, nTxs
1130 return shape, nTxs
1133
1131
1134 if len(shape) != 2 and len(shape) != 3:
1132 if len(shape) != 2 and len(shape) != 3:
1135 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))
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))
1136
1134
1137 if len(shape) == 2:
1135 if len(shape) == 2:
1138 shape_tuple = [dataOut.nChannels]
1136 shape_tuple = [dataOut.nChannels]
1139 shape_tuple.extend(shape)
1137 shape_tuple.extend(shape)
1140 else:
1138 else:
1141 shape_tuple = list(shape)
1139 shape_tuple = list(shape)
1142
1140
1143 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1141 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1144
1142
1145 return shape_tuple, nTxs
1143 return shape_tuple, nTxs
1146
1144
1147 def run(self, dataOut, shape=None, nTxs=None):
1145 def run(self, dataOut, shape=None, nTxs=None):
1148
1146
1149 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1147 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1150
1148
1151 dataOut.flagNoData = True
1149 dataOut.flagNoData = True
1152 profileIndex = None
1150 profileIndex = None
1153
1151
1154 if dataOut.flagDataAsBlock:
1152 if dataOut.flagDataAsBlock:
1155
1153
1156 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1154 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1157 dataOut.flagNoData = False
1155 dataOut.flagNoData = False
1158
1156
1159 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1157 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1160
1158
1161 else:
1159 else:
1162
1160
1163 if self.__nTxs < 1:
1161 if self.__nTxs < 1:
1164
1162
1165 self.__appendProfile(dataOut, self.__nTxs)
1163 self.__appendProfile(dataOut, self.__nTxs)
1166 new_data = self.__getBuffer()
1164 new_data = self.__getBuffer()
1167
1165
1168 if new_data is not None:
1166 if new_data is not None:
1169 dataOut.data = new_data
1167 dataOut.data = new_data
1170 dataOut.flagNoData = False
1168 dataOut.flagNoData = False
1171
1169
1172 profileIndex = dataOut.profileIndex*nTxs
1170 profileIndex = dataOut.profileIndex*nTxs
1173
1171
1174 else:
1172 else:
1175 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1173 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
1176
1174
1177 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1175 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1178
1176
1179 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1177 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1180
1178
1181 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1179 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1182
1180
1183 dataOut.profileIndex = profileIndex
1181 dataOut.profileIndex = profileIndex
1184
1182
1185 dataOut.ippSeconds /= self.__nTxs
1183 dataOut.ippSeconds /= self.__nTxs
1186
1184
1187 return dataOut
1185 return dataOut
1188
1186
1189 class SplitProfiles(Operation):
1187 class SplitProfiles(Operation):
1190
1188
1191 def __init__(self, **kwargs):
1189 def __init__(self, **kwargs):
1192
1190
1193 Operation.__init__(self, **kwargs)
1191 Operation.__init__(self, **kwargs)
1194
1192
1195 def run(self, dataOut, n):
1193 def run(self, dataOut, n):
1196
1194
1197 dataOut.flagNoData = True
1195 dataOut.flagNoData = True
1198 profileIndex = None
1196 profileIndex = None
1199
1197
1200 if dataOut.flagDataAsBlock:
1198 if dataOut.flagDataAsBlock:
1201
1199
1202 #nchannels, nprofiles, nsamples
1200 #nchannels, nprofiles, nsamples
1203 shape = dataOut.data.shape
1201 shape = dataOut.data.shape
1204
1202
1205 if shape[2] % n != 0:
1203 if shape[2] % n != 0:
1206 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1204 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
1207
1205
1208 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1206 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
1209
1207
1210 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1208 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1211 dataOut.flagNoData = False
1209 dataOut.flagNoData = False
1212
1210
1213 profileIndex = int(dataOut.nProfiles/n) - 1
1211 profileIndex = int(dataOut.nProfiles/n) - 1
1214
1212
1215 else:
1213 else:
1216
1214
1217 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1215 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
1218
1216
1219 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1217 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1220
1218
1221 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1219 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1222
1220
1223 dataOut.nProfiles = int(dataOut.nProfiles*n)
1221 dataOut.nProfiles = int(dataOut.nProfiles*n)
1224
1222
1225 dataOut.profileIndex = profileIndex
1223 dataOut.profileIndex = profileIndex
1226
1224
1227 dataOut.ippSeconds /= n
1225 dataOut.ippSeconds /= n
1228
1226
1229 return dataOut
1227 return dataOut
1230
1228
1231 class CombineProfiles(Operation):
1229 class CombineProfiles(Operation):
1232 def __init__(self, **kwargs):
1230 def __init__(self, **kwargs):
1233
1231
1234 Operation.__init__(self, **kwargs)
1232 Operation.__init__(self, **kwargs)
1235
1233
1236 self.__remData = None
1234 self.__remData = None
1237 self.__profileIndex = 0
1235 self.__profileIndex = 0
1238
1236
1239 def run(self, dataOut, n):
1237 def run(self, dataOut, n):
1240
1238
1241 dataOut.flagNoData = True
1239 dataOut.flagNoData = True
1242 profileIndex = None
1240 profileIndex = None
1243
1241
1244 if dataOut.flagDataAsBlock:
1242 if dataOut.flagDataAsBlock:
1245
1243
1246 #nchannels, nprofiles, nsamples
1244 #nchannels, nprofiles, nsamples
1247 shape = dataOut.data.shape
1245 shape = dataOut.data.shape
1248 new_shape = shape[0], shape[1]/n, shape[2]*n
1246 new_shape = shape[0], shape[1]/n, shape[2]*n
1249
1247
1250 if shape[1] % n != 0:
1248 if shape[1] % n != 0:
1251 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1249 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1252
1250
1253 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1251 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1254 dataOut.flagNoData = False
1252 dataOut.flagNoData = False
1255
1253
1256 profileIndex = int(dataOut.nProfiles*n) - 1
1254 profileIndex = int(dataOut.nProfiles*n) - 1
1257
1255
1258 else:
1256 else:
1259
1257
1260 #nchannels, nsamples
1258 #nchannels, nsamples
1261 if self.__remData is None:
1259 if self.__remData is None:
1262 newData = dataOut.data
1260 newData = dataOut.data
1263 else:
1261 else:
1264 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1262 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1265
1263
1266 self.__profileIndex += 1
1264 self.__profileIndex += 1
1267
1265
1268 if self.__profileIndex < n:
1266 if self.__profileIndex < n:
1269 self.__remData = newData
1267 self.__remData = newData
1270 #continue
1268 #continue
1271 return
1269 return
1272
1270
1273 self.__profileIndex = 0
1271 self.__profileIndex = 0
1274 self.__remData = None
1272 self.__remData = None
1275
1273
1276 dataOut.data = newData
1274 dataOut.data = newData
1277 dataOut.flagNoData = False
1275 dataOut.flagNoData = False
1278
1276
1279 profileIndex = dataOut.profileIndex/n
1277 profileIndex = dataOut.profileIndex/n
1280
1278
1281
1279
1282 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1280 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1283
1281
1284 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1282 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1285
1283
1286 dataOut.nProfiles = int(dataOut.nProfiles/n)
1284 dataOut.nProfiles = int(dataOut.nProfiles/n)
1287
1285
1288 dataOut.profileIndex = profileIndex
1286 dataOut.profileIndex = profileIndex
1289
1287
1290 dataOut.ippSeconds *= n
1288 dataOut.ippSeconds *= n
1291
1289
1292 return dataOut
1290 return dataOut
1293
1291
1294 class PulsePairVoltage(Operation):
1292 class PulsePairVoltage(Operation):
1295 '''
1293 '''
1296 Function PulsePair(Signal Power, Velocity)
1294 Function PulsePair(Signal Power, Velocity)
1297 The real component of Lag[0] provides Intensity Information
1295 The real component of Lag[0] provides Intensity Information
1298 The imag component of Lag[1] Phase provides Velocity Information
1296 The imag component of Lag[1] Phase provides Velocity Information
1299
1297
1300 Configuration Parameters:
1298 Configuration Parameters:
1301 nPRF = Number of Several PRF
1299 nPRF = Number of Several PRF
1302 theta = Degree Azimuth angel Boundaries
1300 theta = Degree Azimuth angel Boundaries
1303
1301
1304 Input:
1302 Input:
1305 self.dataOut
1303 self.dataOut
1306 lag[N]
1304 lag[N]
1307 Affected:
1305 Affected:
1308 self.dataOut.spc
1306 self.dataOut.spc
1309 '''
1307 '''
1310 isConfig = False
1308 isConfig = False
1311 __profIndex = 0
1309 __profIndex = 0
1312 __initime = None
1310 __initime = None
1313 __lastdatatime = None
1311 __lastdatatime = None
1314 __buffer = None
1312 __buffer = None
1315 noise = None
1313 noise = None
1316 __dataReady = False
1314 __dataReady = False
1317 n = None
1315 n = None
1318 __nch = 0
1316 __nch = 0
1319 __nHeis = 0
1317 __nHeis = 0
1320 removeDC = False
1318 removeDC = False
1321 ipp = None
1319 ipp = None
1322 lambda_ = 0
1320 lambda_ = 0
1323
1321
1324 def __init__(self,**kwargs):
1322 def __init__(self,**kwargs):
1325 Operation.__init__(self,**kwargs)
1323 Operation.__init__(self,**kwargs)
1326
1324
1327 def setup(self, dataOut, n = None, removeDC=False):
1325 def setup(self, dataOut, n = None, removeDC=False):
1328 '''
1326 '''
1329 n= Numero de PRF's de entrada
1327 n= Numero de PRF's de entrada
1330 '''
1328 '''
1331 self.__initime = None
1329 self.__initime = None
1332 self.__lastdatatime = 0
1330 self.__lastdatatime = 0
1333 self.__dataReady = False
1331 self.__dataReady = False
1334 self.__buffer = 0
1332 self.__buffer = 0
1335 self.__profIndex = 0
1333 self.__profIndex = 0
1336 self.noise = None
1334 self.noise = None
1337 self.__nch = dataOut.nChannels
1335 self.__nch = dataOut.nChannels
1338 self.__nHeis = dataOut.nHeights
1336 self.__nHeis = dataOut.nHeights
1339 self.removeDC = removeDC
1337 self.removeDC = removeDC
1340 self.lambda_ = 3.0e8/(9345.0e6)
1338 self.lambda_ = 3.0e8/(9345.0e6)
1341 self.ippSec = dataOut.ippSeconds
1339 self.ippSec = dataOut.ippSeconds
1342 self.nCohInt = dataOut.nCohInt
1340 self.nCohInt = dataOut.nCohInt
1343 print("IPPseconds",dataOut.ippSeconds)
1341 print("IPPseconds",dataOut.ippSeconds)
1344
1342
1345 print("ELVALOR DE n es:", n)
1343 print("ELVALOR DE n es:", n)
1346 if n == None:
1344 if n == None:
1347 raise ValueError("n should be specified.")
1345 raise ValueError("n should be specified.")
1348
1346
1349 if n != None:
1347 if n != None:
1350 if n<2:
1348 if n<2:
1351 raise ValueError("n should be greater than 2")
1349 raise ValueError("n should be greater than 2")
1352
1350
1353 self.n = n
1351 self.n = n
1354 self.__nProf = n
1352 self.__nProf = n
1355
1353
1356 self.__buffer = numpy.zeros((dataOut.nChannels,
1354 self.__buffer = numpy.zeros((dataOut.nChannels,
1357 n,
1355 n,
1358 dataOut.nHeights),
1356 dataOut.nHeights),
1359 dtype='complex')
1357 dtype='complex')
1360
1358
1361 def putData(self,data):
1359 def putData(self,data):
1362 '''
1360 '''
1363 Add a profile to he __buffer and increase in one the __profiel Index
1361 Add a profile to he __buffer and increase in one the __profiel Index
1364 '''
1362 '''
1365 self.__buffer[:,self.__profIndex,:]= data
1363 self.__buffer[:,self.__profIndex,:]= data
1366 self.__profIndex += 1
1364 self.__profIndex += 1
1367 return
1365 return
1368
1366
1369 def pushData(self,dataOut):
1367 def pushData(self,dataOut):
1370 '''
1368 '''
1371 Return the PULSEPAIR and the profiles used in the operation
1369 Return the PULSEPAIR and the profiles used in the operation
1372 Affected : self.__profileIndex
1370 Affected : self.__profileIndex
1373 '''
1371 '''
1374 #----------------- Remove DC-----------------------------------
1372 #----------------- Remove DC-----------------------------------
1375 if self.removeDC==True:
1373 if self.removeDC==True:
1376 mean = numpy.mean(self.__buffer,1)
1374 mean = numpy.mean(self.__buffer,1)
1377 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1375 tmp = mean.reshape(self.__nch,1,self.__nHeis)
1378 dc= numpy.tile(tmp,[1,self.__nProf,1])
1376 dc= numpy.tile(tmp,[1,self.__nProf,1])
1379 self.__buffer = self.__buffer - dc
1377 self.__buffer = self.__buffer - dc
1380 #------------------Calculo de Potencia ------------------------
1378 #------------------Calculo de Potencia ------------------------
1381 pair0 = self.__buffer*numpy.conj(self.__buffer)
1379 pair0 = self.__buffer*numpy.conj(self.__buffer)
1382 pair0 = pair0.real
1380 pair0 = pair0.real
1383 lag_0 = numpy.sum(pair0,1)
1381 lag_0 = numpy.sum(pair0,1)
1384 #------------------Calculo de Ruido x canal--------------------
1382 #------------------Calculo de Ruido x canal--------------------
1385 self.noise = numpy.zeros(self.__nch)
1383 self.noise = numpy.zeros(self.__nch)
1386 for i in range(self.__nch):
1384 for i in range(self.__nch):
1387 daux = numpy.sort(pair0[i,:,:],axis= None)
1385 daux = numpy.sort(pair0[i,:,:],axis= None)
1388 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
1386 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
1389
1387
1390 self.noise = self.noise.reshape(self.__nch,1)
1388 self.noise = self.noise.reshape(self.__nch,1)
1391 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1389 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
1392 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1390 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
1393 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1391 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
1394 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1392 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
1395 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1393 #------------------ P= S+N ,P=lag_0/N ---------------------------------
1396 #-------------------- Power --------------------------------------------------
1394 #-------------------- Power --------------------------------------------------
1397 data_power = lag_0/(self.n*self.nCohInt)
1395 data_power = lag_0/(self.n*self.nCohInt)
1398 #------------------ Senal ---------------------------------------------------
1396 #------------------ Senal ---------------------------------------------------
1399 data_intensity = pair0 - noise_buffer
1397 data_intensity = pair0 - noise_buffer
1400 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1398 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
1401 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1399 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
1402 for i in range(self.__nch):
1400 for i in range(self.__nch):
1403 for j in range(self.__nHeis):
1401 for j in range(self.__nHeis):
1404 if data_intensity[i][j] < 0:
1402 if data_intensity[i][j] < 0:
1405 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1403 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
1406
1404
1407 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1405 #----------------- Calculo de Frecuencia y Velocidad doppler--------
1408 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1406 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
1409 lag_1 = numpy.sum(pair1,1)
1407 lag_1 = numpy.sum(pair1,1)
1410 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1408 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
1411 data_velocity = (self.lambda_/2.0)*data_freq
1409 data_velocity = (self.lambda_/2.0)*data_freq
1412
1410
1413 #---------------- Potencia promedio estimada de la Senal-----------
1411 #---------------- Potencia promedio estimada de la Senal-----------
1414 lag_0 = lag_0/self.n
1412 lag_0 = lag_0/self.n
1415 S = lag_0-self.noise
1413 S = lag_0-self.noise
1416
1414
1417 #---------------- Frecuencia Doppler promedio ---------------------
1415 #---------------- Frecuencia Doppler promedio ---------------------
1418 lag_1 = lag_1/(self.n-1)
1416 lag_1 = lag_1/(self.n-1)
1419 R1 = numpy.abs(lag_1)
1417 R1 = numpy.abs(lag_1)
1420
1418
1421 #---------------- Calculo del SNR----------------------------------
1419 #---------------- Calculo del SNR----------------------------------
1422 data_snrPP = S/self.noise
1420 data_snrPP = S/self.noise
1423 for i in range(self.__nch):
1421 for i in range(self.__nch):
1424 for j in range(self.__nHeis):
1422 for j in range(self.__nHeis):
1425 if data_snrPP[i][j] < 1.e-20:
1423 if data_snrPP[i][j] < 1.e-20:
1426 data_snrPP[i][j] = 1.e-20
1424 data_snrPP[i][j] = 1.e-20
1427
1425
1428 #----------------- Calculo del ancho espectral ----------------------
1426 #----------------- Calculo del ancho espectral ----------------------
1429 L = S/R1
1427 L = S/R1
1430 L = numpy.where(L<0,1,L)
1428 L = numpy.where(L<0,1,L)
1431 L = numpy.log(L)
1429 L = numpy.log(L)
1432 tmp = numpy.sqrt(numpy.absolute(L))
1430 tmp = numpy.sqrt(numpy.absolute(L))
1433 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
1431 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
1434 n = self.__profIndex
1432 n = self.__profIndex
1435
1433
1436 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1434 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
1437 self.__profIndex = 0
1435 self.__profIndex = 0
1438 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n
1436 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n
1439
1437
1440
1438
1441 def pulsePairbyProfiles(self,dataOut):
1439 def pulsePairbyProfiles(self,dataOut):
1442
1440
1443 self.__dataReady = False
1441 self.__dataReady = False
1444 data_power = None
1442 data_power = None
1445 data_intensity = None
1443 data_intensity = None
1446 data_velocity = None
1444 data_velocity = None
1447 data_specwidth = None
1445 data_specwidth = None
1448 data_snrPP = None
1446 data_snrPP = None
1449 self.putData(data=dataOut.data)
1447 self.putData(data=dataOut.data)
1450 if self.__profIndex == self.n:
1448 if self.__profIndex == self.n:
1451 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut)
1449 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut)
1452 self.__dataReady = True
1450 self.__dataReady = True
1453
1451
1454 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth
1452 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth
1455
1453
1456
1454
1457 def pulsePairOp(self, dataOut, datatime= None):
1455 def pulsePairOp(self, dataOut, datatime= None):
1458
1456
1459 if self.__initime == None:
1457 if self.__initime == None:
1460 self.__initime = datatime
1458 self.__initime = datatime
1461 data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut)
1459 data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut)
1462 self.__lastdatatime = datatime
1460 self.__lastdatatime = datatime
1463
1461
1464 if data_power is None:
1462 if data_power is None:
1465 return None, None, None,None,None,None
1463 return None, None, None,None,None,None
1466
1464
1467 avgdatatime = self.__initime
1465 avgdatatime = self.__initime
1468 deltatime = datatime - self.__lastdatatime
1466 deltatime = datatime - self.__lastdatatime
1469 self.__initime = datatime
1467 self.__initime = datatime
1470
1468
1471 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime
1469 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime
1472
1470
1473 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1471 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
1474
1472
1475 if not self.isConfig:
1473 if not self.isConfig:
1476 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1474 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
1477 self.isConfig = True
1475 self.isConfig = True
1478 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
1476 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
1479 dataOut.flagNoData = True
1477 dataOut.flagNoData = True
1480
1478
1481 if self.__dataReady:
1479 if self.__dataReady:
1482 dataOut.nCohInt *= self.n
1480 dataOut.nCohInt *= self.n
1483 dataOut.dataPP_POW = data_intensity # S
1481 dataOut.dataPP_POW = data_intensity # S
1484 dataOut.dataPP_POWER = data_power # P
1482 dataOut.dataPP_POWER = data_power # P
1485 dataOut.dataPP_DOP = data_velocity
1483 dataOut.dataPP_DOP = data_velocity
1486 dataOut.dataPP_SNR = data_snrPP
1484 dataOut.dataPP_SNR = data_snrPP
1487 dataOut.dataPP_WIDTH = data_specwidth
1485 dataOut.dataPP_WIDTH = data_specwidth
1488 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1486 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
1489 dataOut.utctime = avgdatatime
1487 dataOut.utctime = avgdatatime
1490 dataOut.flagNoData = False
1488 dataOut.flagNoData = False
1491 return dataOut
1489 return dataOut
1492
1490
1493
1491
1494
1492
1495 # import collections
1493 # import collections
1496 # from scipy.stats import mode
1494 # from scipy.stats import mode
1497 #
1495 #
1498 # class Synchronize(Operation):
1496 # class Synchronize(Operation):
1499 #
1497 #
1500 # isConfig = False
1498 # isConfig = False
1501 # __profIndex = 0
1499 # __profIndex = 0
1502 #
1500 #
1503 # def __init__(self, **kwargs):
1501 # def __init__(self, **kwargs):
1504 #
1502 #
1505 # Operation.__init__(self, **kwargs)
1503 # Operation.__init__(self, **kwargs)
1506 # # self.isConfig = False
1504 # # self.isConfig = False
1507 # self.__powBuffer = None
1505 # self.__powBuffer = None
1508 # self.__startIndex = 0
1506 # self.__startIndex = 0
1509 # self.__pulseFound = False
1507 # self.__pulseFound = False
1510 #
1508 #
1511 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1509 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1512 #
1510 #
1513 # #Read data
1511 # #Read data
1514 #
1512 #
1515 # powerdB = dataOut.getPower(channel = channel)
1513 # powerdB = dataOut.getPower(channel = channel)
1516 # noisedB = dataOut.getNoise(channel = channel)[0]
1514 # noisedB = dataOut.getNoise(channel = channel)[0]
1517 #
1515 #
1518 # self.__powBuffer.extend(powerdB.flatten())
1516 # self.__powBuffer.extend(powerdB.flatten())
1519 #
1517 #
1520 # dataArray = numpy.array(self.__powBuffer)
1518 # dataArray = numpy.array(self.__powBuffer)
1521 #
1519 #
1522 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1520 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1523 #
1521 #
1524 # maxValue = numpy.nanmax(filteredPower)
1522 # maxValue = numpy.nanmax(filteredPower)
1525 #
1523 #
1526 # if maxValue < noisedB + 10:
1524 # if maxValue < noisedB + 10:
1527 # #No se encuentra ningun pulso de transmision
1525 # #No se encuentra ningun pulso de transmision
1528 # return None
1526 # return None
1529 #
1527 #
1530 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1528 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1531 #
1529 #
1532 # if len(maxValuesIndex) < 2:
1530 # if len(maxValuesIndex) < 2:
1533 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1531 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1534 # return None
1532 # return None
1535 #
1533 #
1536 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1534 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1537 #
1535 #
1538 # #Seleccionar solo valores con un espaciamiento de nSamples
1536 # #Seleccionar solo valores con un espaciamiento de nSamples
1539 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1537 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1540 #
1538 #
1541 # if len(pulseIndex) < 2:
1539 # if len(pulseIndex) < 2:
1542 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1540 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1543 # return None
1541 # return None
1544 #
1542 #
1545 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1543 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1546 #
1544 #
1547 # #remover senales que se distancien menos de 10 unidades o muestras
1545 # #remover senales que se distancien menos de 10 unidades o muestras
1548 # #(No deberian existir IPP menor a 10 unidades)
1546 # #(No deberian existir IPP menor a 10 unidades)
1549 #
1547 #
1550 # realIndex = numpy.where(spacing > 10 )[0]
1548 # realIndex = numpy.where(spacing > 10 )[0]
1551 #
1549 #
1552 # if len(realIndex) < 2:
1550 # if len(realIndex) < 2:
1553 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1551 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1554 # return None
1552 # return None
1555 #
1553 #
1556 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1554 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1557 # realPulseIndex = pulseIndex[realIndex]
1555 # realPulseIndex = pulseIndex[realIndex]
1558 #
1556 #
1559 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1557 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1560 #
1558 #
1561 # print "IPP = %d samples" %period
1559 # print "IPP = %d samples" %period
1562 #
1560 #
1563 # self.__newNSamples = dataOut.nHeights #int(period)
1561 # self.__newNSamples = dataOut.nHeights #int(period)
1564 # self.__startIndex = int(realPulseIndex[0])
1562 # self.__startIndex = int(realPulseIndex[0])
1565 #
1563 #
1566 # return 1
1564 # return 1
1567 #
1565 #
1568 #
1566 #
1569 # def setup(self, nSamples, nChannels, buffer_size = 4):
1567 # def setup(self, nSamples, nChannels, buffer_size = 4):
1570 #
1568 #
1571 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1569 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1572 # maxlen = buffer_size*nSamples)
1570 # maxlen = buffer_size*nSamples)
1573 #
1571 #
1574 # bufferList = []
1572 # bufferList = []
1575 #
1573 #
1576 # for i in range(nChannels):
1574 # for i in range(nChannels):
1577 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1575 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1578 # maxlen = buffer_size*nSamples)
1576 # maxlen = buffer_size*nSamples)
1579 #
1577 #
1580 # bufferList.append(bufferByChannel)
1578 # bufferList.append(bufferByChannel)
1581 #
1579 #
1582 # self.__nSamples = nSamples
1580 # self.__nSamples = nSamples
1583 # self.__nChannels = nChannels
1581 # self.__nChannels = nChannels
1584 # self.__bufferList = bufferList
1582 # self.__bufferList = bufferList
1585 #
1583 #
1586 # def run(self, dataOut, channel = 0):
1584 # def run(self, dataOut, channel = 0):
1587 #
1585 #
1588 # if not self.isConfig:
1586 # if not self.isConfig:
1589 # nSamples = dataOut.nHeights
1587 # nSamples = dataOut.nHeights
1590 # nChannels = dataOut.nChannels
1588 # nChannels = dataOut.nChannels
1591 # self.setup(nSamples, nChannels)
1589 # self.setup(nSamples, nChannels)
1592 # self.isConfig = True
1590 # self.isConfig = True
1593 #
1591 #
1594 # #Append new data to internal buffer
1592 # #Append new data to internal buffer
1595 # for thisChannel in range(self.__nChannels):
1593 # for thisChannel in range(self.__nChannels):
1596 # bufferByChannel = self.__bufferList[thisChannel]
1594 # bufferByChannel = self.__bufferList[thisChannel]
1597 # bufferByChannel.extend(dataOut.data[thisChannel])
1595 # bufferByChannel.extend(dataOut.data[thisChannel])
1598 #
1596 #
1599 # if self.__pulseFound:
1597 # if self.__pulseFound:
1600 # self.__startIndex -= self.__nSamples
1598 # self.__startIndex -= self.__nSamples
1601 #
1599 #
1602 # #Finding Tx Pulse
1600 # #Finding Tx Pulse
1603 # if not self.__pulseFound:
1601 # if not self.__pulseFound:
1604 # indexFound = self.__findTxPulse(dataOut, channel)
1602 # indexFound = self.__findTxPulse(dataOut, channel)
1605 #
1603 #
1606 # if indexFound == None:
1604 # if indexFound == None:
1607 # dataOut.flagNoData = True
1605 # dataOut.flagNoData = True
1608 # return
1606 # return
1609 #
1607 #
1610 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1608 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1611 # self.__pulseFound = True
1609 # self.__pulseFound = True
1612 # self.__startIndex = indexFound
1610 # self.__startIndex = indexFound
1613 #
1611 #
1614 # #If pulse was found ...
1612 # #If pulse was found ...
1615 # for thisChannel in range(self.__nChannels):
1613 # for thisChannel in range(self.__nChannels):
1616 # bufferByChannel = self.__bufferList[thisChannel]
1614 # bufferByChannel = self.__bufferList[thisChannel]
1617 # #print self.__startIndex
1615 # #print self.__startIndex
1618 # x = numpy.array(bufferByChannel)
1616 # x = numpy.array(bufferByChannel)
1619 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1617 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1620 #
1618 #
1621 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1619 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1622 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1620 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1623 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1621 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1624 #
1622 #
1625 # dataOut.data = self.__arrayBuffer
1623 # dataOut.data = self.__arrayBuffer
1626 #
1624 #
1627 # self.__startIndex += self.__newNSamples
1625 # self.__startIndex += self.__newNSamples
1628 #
1626 #
1629 # return No newline at end of file
1627 # return
General Comments 0
You need to be logged in to leave comments. Login now