##// END OF EJS Templates
Decoder: nProfiles var updated in run
Juan C. Espinoza -
r997:ae42ba4492f7
parent child
Show More
@@ -1,1283 +1,1285
1 import sys
1 import sys
2 import numpy
2 import numpy
3 from scipy import interpolate
3 from scipy import interpolate
4
4
5 from jroproc_base import ProcessingUnit, Operation
5 from jroproc_base import ProcessingUnit, Operation
6 from schainpy.model.data.jrodata import Voltage
6 from schainpy.model.data.jrodata import Voltage
7
7
8 class VoltageProc(ProcessingUnit):
8 class VoltageProc(ProcessingUnit):
9
9
10
10
11 def __init__(self, **kwargs):
11 def __init__(self, **kwargs):
12
12
13 ProcessingUnit.__init__(self, **kwargs)
13 ProcessingUnit.__init__(self, **kwargs)
14
14
15 # self.objectDict = {}
15 # self.objectDict = {}
16 self.dataOut = Voltage()
16 self.dataOut = Voltage()
17 self.flip = 1
17 self.flip = 1
18
18
19 def run(self):
19 def run(self):
20 if self.dataIn.type == 'AMISR':
20 if self.dataIn.type == 'AMISR':
21 self.__updateObjFromAmisrInput()
21 self.__updateObjFromAmisrInput()
22
22
23 if self.dataIn.type == 'Voltage':
23 if self.dataIn.type == 'Voltage':
24 self.dataOut.copy(self.dataIn)
24 self.dataOut.copy(self.dataIn)
25
25
26 # self.dataOut.copy(self.dataIn)
26 # self.dataOut.copy(self.dataIn)
27
27
28 def __updateObjFromAmisrInput(self):
28 def __updateObjFromAmisrInput(self):
29
29
30 self.dataOut.timeZone = self.dataIn.timeZone
30 self.dataOut.timeZone = self.dataIn.timeZone
31 self.dataOut.dstFlag = self.dataIn.dstFlag
31 self.dataOut.dstFlag = self.dataIn.dstFlag
32 self.dataOut.errorCount = self.dataIn.errorCount
32 self.dataOut.errorCount = self.dataIn.errorCount
33 self.dataOut.useLocalTime = self.dataIn.useLocalTime
33 self.dataOut.useLocalTime = self.dataIn.useLocalTime
34
34
35 self.dataOut.flagNoData = self.dataIn.flagNoData
35 self.dataOut.flagNoData = self.dataIn.flagNoData
36 self.dataOut.data = self.dataIn.data
36 self.dataOut.data = self.dataIn.data
37 self.dataOut.utctime = self.dataIn.utctime
37 self.dataOut.utctime = self.dataIn.utctime
38 self.dataOut.channelList = self.dataIn.channelList
38 self.dataOut.channelList = self.dataIn.channelList
39 # self.dataOut.timeInterval = self.dataIn.timeInterval
39 # self.dataOut.timeInterval = self.dataIn.timeInterval
40 self.dataOut.heightList = self.dataIn.heightList
40 self.dataOut.heightList = self.dataIn.heightList
41 self.dataOut.nProfiles = self.dataIn.nProfiles
41 self.dataOut.nProfiles = self.dataIn.nProfiles
42
42
43 self.dataOut.nCohInt = self.dataIn.nCohInt
43 self.dataOut.nCohInt = self.dataIn.nCohInt
44 self.dataOut.ippSeconds = self.dataIn.ippSeconds
44 self.dataOut.ippSeconds = self.dataIn.ippSeconds
45 self.dataOut.frequency = self.dataIn.frequency
45 self.dataOut.frequency = self.dataIn.frequency
46
46
47 self.dataOut.azimuth = self.dataIn.azimuth
47 self.dataOut.azimuth = self.dataIn.azimuth
48 self.dataOut.zenith = self.dataIn.zenith
48 self.dataOut.zenith = self.dataIn.zenith
49
49
50 self.dataOut.beam.codeList = self.dataIn.beam.codeList
50 self.dataOut.beam.codeList = self.dataIn.beam.codeList
51 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
51 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
52 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
52 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
53 #
53 #
54 # pass#
54 # pass#
55 #
55 #
56 # def init(self):
56 # def init(self):
57 #
57 #
58 #
58 #
59 # if self.dataIn.type == 'AMISR':
59 # if self.dataIn.type == 'AMISR':
60 # self.__updateObjFromAmisrInput()
60 # self.__updateObjFromAmisrInput()
61 #
61 #
62 # if self.dataIn.type == 'Voltage':
62 # if self.dataIn.type == 'Voltage':
63 # self.dataOut.copy(self.dataIn)
63 # self.dataOut.copy(self.dataIn)
64 # # No necesita copiar en cada init() los atributos de dataIn
64 # # No necesita copiar en cada init() los atributos de dataIn
65 # # la copia deberia hacerse por cada nuevo bloque de datos
65 # # la copia deberia hacerse por cada nuevo bloque de datos
66
66
67 def selectChannels(self, channelList):
67 def selectChannels(self, channelList):
68
68
69 channelIndexList = []
69 channelIndexList = []
70
70
71 for channel in channelList:
71 for channel in channelList:
72 if channel not in self.dataOut.channelList:
72 if channel not in self.dataOut.channelList:
73 raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList))
73 raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList))
74
74
75 index = self.dataOut.channelList.index(channel)
75 index = self.dataOut.channelList.index(channel)
76 channelIndexList.append(index)
76 channelIndexList.append(index)
77
77
78 self.selectChannelsByIndex(channelIndexList)
78 self.selectChannelsByIndex(channelIndexList)
79
79
80 def selectChannelsByIndex(self, channelIndexList):
80 def selectChannelsByIndex(self, channelIndexList):
81 """
81 """
82 Selecciona un bloque de datos en base a canales segun el channelIndexList
82 Selecciona un bloque de datos en base a canales segun el channelIndexList
83
83
84 Input:
84 Input:
85 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
85 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
86
86
87 Affected:
87 Affected:
88 self.dataOut.data
88 self.dataOut.data
89 self.dataOut.channelIndexList
89 self.dataOut.channelIndexList
90 self.dataOut.nChannels
90 self.dataOut.nChannels
91 self.dataOut.m_ProcessingHeader.totalSpectra
91 self.dataOut.m_ProcessingHeader.totalSpectra
92 self.dataOut.systemHeaderObj.numChannels
92 self.dataOut.systemHeaderObj.numChannels
93 self.dataOut.m_ProcessingHeader.blockSize
93 self.dataOut.m_ProcessingHeader.blockSize
94
94
95 Return:
95 Return:
96 None
96 None
97 """
97 """
98
98
99 for channelIndex in channelIndexList:
99 for channelIndex in channelIndexList:
100 if channelIndex not in self.dataOut.channelIndexList:
100 if channelIndex not in self.dataOut.channelIndexList:
101 print channelIndexList
101 print channelIndexList
102 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
102 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
103
103
104 if self.dataOut.flagDataAsBlock:
104 if self.dataOut.flagDataAsBlock:
105 """
105 """
106 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
106 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
107 """
107 """
108 data = self.dataOut.data[channelIndexList,:,:]
108 data = self.dataOut.data[channelIndexList,:,:]
109 else:
109 else:
110 data = self.dataOut.data[channelIndexList,:]
110 data = self.dataOut.data[channelIndexList,:]
111
111
112 self.dataOut.data = data
112 self.dataOut.data = data
113 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
113 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
114 # self.dataOut.nChannels = nChannels
114 # self.dataOut.nChannels = nChannels
115
115
116 return 1
116 return 1
117
117
118 def selectHeights(self, minHei=None, maxHei=None):
118 def selectHeights(self, minHei=None, maxHei=None):
119 """
119 """
120 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
120 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
121 minHei <= height <= maxHei
121 minHei <= height <= maxHei
122
122
123 Input:
123 Input:
124 minHei : valor minimo de altura a considerar
124 minHei : valor minimo de altura a considerar
125 maxHei : valor maximo de altura a considerar
125 maxHei : valor maximo de altura a considerar
126
126
127 Affected:
127 Affected:
128 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
128 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
129
129
130 Return:
130 Return:
131 1 si el metodo se ejecuto con exito caso contrario devuelve 0
131 1 si el metodo se ejecuto con exito caso contrario devuelve 0
132 """
132 """
133
133
134 if minHei == None:
134 if minHei == None:
135 minHei = self.dataOut.heightList[0]
135 minHei = self.dataOut.heightList[0]
136
136
137 if maxHei == None:
137 if maxHei == None:
138 maxHei = self.dataOut.heightList[-1]
138 maxHei = self.dataOut.heightList[-1]
139
139
140 if (minHei < self.dataOut.heightList[0]):
140 if (minHei < self.dataOut.heightList[0]):
141 minHei = self.dataOut.heightList[0]
141 minHei = self.dataOut.heightList[0]
142
142
143 if (maxHei > self.dataOut.heightList[-1]):
143 if (maxHei > self.dataOut.heightList[-1]):
144 maxHei = self.dataOut.heightList[-1]
144 maxHei = self.dataOut.heightList[-1]
145
145
146 minIndex = 0
146 minIndex = 0
147 maxIndex = 0
147 maxIndex = 0
148 heights = self.dataOut.heightList
148 heights = self.dataOut.heightList
149
149
150 inda = numpy.where(heights >= minHei)
150 inda = numpy.where(heights >= minHei)
151 indb = numpy.where(heights <= maxHei)
151 indb = numpy.where(heights <= maxHei)
152
152
153 try:
153 try:
154 minIndex = inda[0][0]
154 minIndex = inda[0][0]
155 except:
155 except:
156 minIndex = 0
156 minIndex = 0
157
157
158 try:
158 try:
159 maxIndex = indb[0][-1]
159 maxIndex = indb[0][-1]
160 except:
160 except:
161 maxIndex = len(heights)
161 maxIndex = len(heights)
162
162
163 self.selectHeightsByIndex(minIndex, maxIndex)
163 self.selectHeightsByIndex(minIndex, maxIndex)
164
164
165 return 1
165 return 1
166
166
167
167
168 def selectHeightsByIndex(self, minIndex, maxIndex):
168 def selectHeightsByIndex(self, minIndex, maxIndex):
169 """
169 """
170 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
170 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
171 minIndex <= index <= maxIndex
171 minIndex <= index <= maxIndex
172
172
173 Input:
173 Input:
174 minIndex : valor de indice minimo de altura a considerar
174 minIndex : valor de indice minimo de altura a considerar
175 maxIndex : valor de indice maximo de altura a considerar
175 maxIndex : valor de indice maximo de altura a considerar
176
176
177 Affected:
177 Affected:
178 self.dataOut.data
178 self.dataOut.data
179 self.dataOut.heightList
179 self.dataOut.heightList
180
180
181 Return:
181 Return:
182 1 si el metodo se ejecuto con exito caso contrario devuelve 0
182 1 si el metodo se ejecuto con exito caso contrario devuelve 0
183 """
183 """
184
184
185 if (minIndex < 0) or (minIndex > maxIndex):
185 if (minIndex < 0) or (minIndex > maxIndex):
186 raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex)
186 raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex)
187
187
188 if (maxIndex >= self.dataOut.nHeights):
188 if (maxIndex >= self.dataOut.nHeights):
189 maxIndex = self.dataOut.nHeights
189 maxIndex = self.dataOut.nHeights
190
190
191 #voltage
191 #voltage
192 if self.dataOut.flagDataAsBlock:
192 if self.dataOut.flagDataAsBlock:
193 """
193 """
194 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
194 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
195 """
195 """
196 data = self.dataOut.data[:,:, minIndex:maxIndex]
196 data = self.dataOut.data[:,:, minIndex:maxIndex]
197 else:
197 else:
198 data = self.dataOut.data[:, minIndex:maxIndex]
198 data = self.dataOut.data[:, minIndex:maxIndex]
199
199
200 # firstHeight = self.dataOut.heightList[minIndex]
200 # firstHeight = self.dataOut.heightList[minIndex]
201
201
202 self.dataOut.data = data
202 self.dataOut.data = data
203 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
203 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
204
204
205 if self.dataOut.nHeights <= 1:
205 if self.dataOut.nHeights <= 1:
206 raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)
206 raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)
207
207
208 return 1
208 return 1
209
209
210
210
211 def filterByHeights(self, window):
211 def filterByHeights(self, window):
212
212
213 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
213 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
214
214
215 if window == None:
215 if window == None:
216 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
216 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
217
217
218 newdelta = deltaHeight * window
218 newdelta = deltaHeight * window
219 r = self.dataOut.nHeights % window
219 r = self.dataOut.nHeights % window
220 newheights = (self.dataOut.nHeights-r)/window
220 newheights = (self.dataOut.nHeights-r)/window
221
221
222 if newheights <= 1:
222 if newheights <= 1:
223 raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window)
223 raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window)
224
224
225 if self.dataOut.flagDataAsBlock:
225 if self.dataOut.flagDataAsBlock:
226 """
226 """
227 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
227 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
228 """
228 """
229 buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r]
229 buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r]
230 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window)
230 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window)
231 buffer = numpy.sum(buffer,3)
231 buffer = numpy.sum(buffer,3)
232
232
233 else:
233 else:
234 buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r]
234 buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r]
235 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window)
235 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window)
236 buffer = numpy.sum(buffer,2)
236 buffer = numpy.sum(buffer,2)
237
237
238 self.dataOut.data = buffer
238 self.dataOut.data = buffer
239 self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta
239 self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta
240 self.dataOut.windowOfFilter = window
240 self.dataOut.windowOfFilter = window
241
241
242 def setH0(self, h0, deltaHeight = None):
242 def setH0(self, h0, deltaHeight = None):
243
243
244 if not deltaHeight:
244 if not deltaHeight:
245 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
245 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
246
246
247 nHeights = self.dataOut.nHeights
247 nHeights = self.dataOut.nHeights
248
248
249 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
249 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
250
250
251 self.dataOut.heightList = newHeiRange
251 self.dataOut.heightList = newHeiRange
252
252
253 def deFlip(self, channelList = []):
253 def deFlip(self, channelList = []):
254
254
255 data = self.dataOut.data.copy()
255 data = self.dataOut.data.copy()
256
256
257 if self.dataOut.flagDataAsBlock:
257 if self.dataOut.flagDataAsBlock:
258 flip = self.flip
258 flip = self.flip
259 profileList = range(self.dataOut.nProfiles)
259 profileList = range(self.dataOut.nProfiles)
260
260
261 if not channelList:
261 if not channelList:
262 for thisProfile in profileList:
262 for thisProfile in profileList:
263 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
263 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
264 flip *= -1.0
264 flip *= -1.0
265 else:
265 else:
266 for thisChannel in channelList:
266 for thisChannel in channelList:
267 if thisChannel not in self.dataOut.channelList:
267 if thisChannel not in self.dataOut.channelList:
268 continue
268 continue
269
269
270 for thisProfile in profileList:
270 for thisProfile in profileList:
271 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
271 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
272 flip *= -1.0
272 flip *= -1.0
273
273
274 self.flip = flip
274 self.flip = flip
275
275
276 else:
276 else:
277 if not channelList:
277 if not channelList:
278 data[:,:] = data[:,:]*self.flip
278 data[:,:] = data[:,:]*self.flip
279 else:
279 else:
280 for thisChannel in channelList:
280 for thisChannel in channelList:
281 if thisChannel not in self.dataOut.channelList:
281 if thisChannel not in self.dataOut.channelList:
282 continue
282 continue
283
283
284 data[thisChannel,:] = data[thisChannel,:]*self.flip
284 data[thisChannel,:] = data[thisChannel,:]*self.flip
285
285
286 self.flip *= -1.
286 self.flip *= -1.
287
287
288 self.dataOut.data = data
288 self.dataOut.data = data
289
289
290 def setRadarFrequency(self, frequency=None):
290 def setRadarFrequency(self, frequency=None):
291
291
292 if frequency != None:
292 if frequency != None:
293 self.dataOut.frequency = frequency
293 self.dataOut.frequency = frequency
294
294
295 return 1
295 return 1
296
296
297 def interpolateHeights(self, topLim, botLim):
297 def interpolateHeights(self, topLim, botLim):
298 #69 al 72 para julia
298 #69 al 72 para julia
299 #82-84 para meteoros
299 #82-84 para meteoros
300 if len(numpy.shape(self.dataOut.data))==2:
300 if len(numpy.shape(self.dataOut.data))==2:
301 sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2
301 sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2
302 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
302 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
303 #self.dataOut.data[:,botLim:limSup+1] = sampInterp
303 #self.dataOut.data[:,botLim:limSup+1] = sampInterp
304 self.dataOut.data[:,botLim:topLim+1] = sampInterp
304 self.dataOut.data[:,botLim:topLim+1] = sampInterp
305 else:
305 else:
306 nHeights = self.dataOut.data.shape[2]
306 nHeights = self.dataOut.data.shape[2]
307 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
307 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
308 y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)]
308 y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)]
309 f = interpolate.interp1d(x, y, axis = 2)
309 f = interpolate.interp1d(x, y, axis = 2)
310 xnew = numpy.arange(botLim,topLim+1)
310 xnew = numpy.arange(botLim,topLim+1)
311 ynew = f(xnew)
311 ynew = f(xnew)
312
312
313 self.dataOut.data[:,:,botLim:topLim+1] = ynew
313 self.dataOut.data[:,:,botLim:topLim+1] = ynew
314
314
315 # import collections
315 # import collections
316
316
317 class CohInt(Operation):
317 class CohInt(Operation):
318
318
319 isConfig = False
319 isConfig = False
320
320
321 __profIndex = 0
321 __profIndex = 0
322 __withOverapping = False
322 __withOverapping = False
323
323
324 __byTime = False
324 __byTime = False
325 __initime = None
325 __initime = None
326 __lastdatatime = None
326 __lastdatatime = None
327 __integrationtime = None
327 __integrationtime = None
328
328
329 __buffer = None
329 __buffer = None
330
330
331 __dataReady = False
331 __dataReady = False
332
332
333 n = None
333 n = None
334
334
335
335
336 def __init__(self, **kwargs):
336 def __init__(self, **kwargs):
337
337
338 Operation.__init__(self, **kwargs)
338 Operation.__init__(self, **kwargs)
339
339
340 # self.isConfig = False
340 # self.isConfig = False
341
341
342 def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False):
342 def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False):
343 """
343 """
344 Set the parameters of the integration class.
344 Set the parameters of the integration class.
345
345
346 Inputs:
346 Inputs:
347
347
348 n : Number of coherent integrations
348 n : Number of coherent integrations
349 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
349 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
350 overlapping :
350 overlapping :
351
351
352 """
352 """
353
353
354 self.__initime = None
354 self.__initime = None
355 self.__lastdatatime = 0
355 self.__lastdatatime = 0
356 self.__buffer = None
356 self.__buffer = None
357 self.__dataReady = False
357 self.__dataReady = False
358 self.byblock = byblock
358 self.byblock = byblock
359
359
360 if n == None and timeInterval == None:
360 if n == None and timeInterval == None:
361 raise ValueError, "n or timeInterval should be specified ..."
361 raise ValueError, "n or timeInterval should be specified ..."
362
362
363 if n != None:
363 if n != None:
364 self.n = n
364 self.n = n
365 self.__byTime = False
365 self.__byTime = False
366 else:
366 else:
367 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
367 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
368 self.n = 9999
368 self.n = 9999
369 self.__byTime = True
369 self.__byTime = True
370
370
371 if overlapping:
371 if overlapping:
372 self.__withOverapping = True
372 self.__withOverapping = True
373 self.__buffer = None
373 self.__buffer = None
374 else:
374 else:
375 self.__withOverapping = False
375 self.__withOverapping = False
376 self.__buffer = 0
376 self.__buffer = 0
377
377
378 self.__profIndex = 0
378 self.__profIndex = 0
379
379
380 def putData(self, data):
380 def putData(self, data):
381
381
382 """
382 """
383 Add a profile to the __buffer and increase in one the __profileIndex
383 Add a profile to the __buffer and increase in one the __profileIndex
384
384
385 """
385 """
386
386
387 if not self.__withOverapping:
387 if not self.__withOverapping:
388 self.__buffer += data.copy()
388 self.__buffer += data.copy()
389 self.__profIndex += 1
389 self.__profIndex += 1
390 return
390 return
391
391
392 #Overlapping data
392 #Overlapping data
393 nChannels, nHeis = data.shape
393 nChannels, nHeis = data.shape
394 data = numpy.reshape(data, (1, nChannels, nHeis))
394 data = numpy.reshape(data, (1, nChannels, nHeis))
395
395
396 #If the buffer is empty then it takes the data value
396 #If the buffer is empty then it takes the data value
397 if self.__buffer is None:
397 if self.__buffer is None:
398 self.__buffer = data
398 self.__buffer = data
399 self.__profIndex += 1
399 self.__profIndex += 1
400 return
400 return
401
401
402 #If the buffer length is lower than n then stakcing the data value
402 #If the buffer length is lower than n then stakcing the data value
403 if self.__profIndex < self.n:
403 if self.__profIndex < self.n:
404 self.__buffer = numpy.vstack((self.__buffer, data))
404 self.__buffer = numpy.vstack((self.__buffer, data))
405 self.__profIndex += 1
405 self.__profIndex += 1
406 return
406 return
407
407
408 #If the buffer length is equal to n then replacing the last buffer value with the data value
408 #If the buffer length is equal to n then replacing the last buffer value with the data value
409 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
409 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
410 self.__buffer[self.n-1] = data
410 self.__buffer[self.n-1] = data
411 self.__profIndex = self.n
411 self.__profIndex = self.n
412 return
412 return
413
413
414
414
415 def pushData(self):
415 def pushData(self):
416 """
416 """
417 Return the sum of the last profiles and the profiles used in the sum.
417 Return the sum of the last profiles and the profiles used in the sum.
418
418
419 Affected:
419 Affected:
420
420
421 self.__profileIndex
421 self.__profileIndex
422
422
423 """
423 """
424
424
425 if not self.__withOverapping:
425 if not self.__withOverapping:
426 data = self.__buffer
426 data = self.__buffer
427 n = self.__profIndex
427 n = self.__profIndex
428
428
429 self.__buffer = 0
429 self.__buffer = 0
430 self.__profIndex = 0
430 self.__profIndex = 0
431
431
432 return data, n
432 return data, n
433
433
434 #Integration with Overlapping
434 #Integration with Overlapping
435 data = numpy.sum(self.__buffer, axis=0)
435 data = numpy.sum(self.__buffer, axis=0)
436 n = self.__profIndex
436 n = self.__profIndex
437
437
438 return data, n
438 return data, n
439
439
440 def byProfiles(self, data):
440 def byProfiles(self, data):
441
441
442 self.__dataReady = False
442 self.__dataReady = False
443 avgdata = None
443 avgdata = None
444 # n = None
444 # n = None
445
445
446 self.putData(data)
446 self.putData(data)
447
447
448 if self.__profIndex == self.n:
448 if self.__profIndex == self.n:
449
449
450 avgdata, n = self.pushData()
450 avgdata, n = self.pushData()
451 self.__dataReady = True
451 self.__dataReady = True
452
452
453 return avgdata
453 return avgdata
454
454
455 def byTime(self, data, datatime):
455 def byTime(self, data, datatime):
456
456
457 self.__dataReady = False
457 self.__dataReady = False
458 avgdata = None
458 avgdata = None
459 n = None
459 n = None
460
460
461 self.putData(data)
461 self.putData(data)
462
462
463 if (datatime - self.__initime) >= self.__integrationtime:
463 if (datatime - self.__initime) >= self.__integrationtime:
464 avgdata, n = self.pushData()
464 avgdata, n = self.pushData()
465 self.n = n
465 self.n = n
466 self.__dataReady = True
466 self.__dataReady = True
467
467
468 return avgdata
468 return avgdata
469
469
470 def integrate(self, data, datatime=None):
470 def integrate(self, data, datatime=None):
471
471
472 if self.__initime == None:
472 if self.__initime == None:
473 self.__initime = datatime
473 self.__initime = datatime
474
474
475 if self.__byTime:
475 if self.__byTime:
476 avgdata = self.byTime(data, datatime)
476 avgdata = self.byTime(data, datatime)
477 else:
477 else:
478 avgdata = self.byProfiles(data)
478 avgdata = self.byProfiles(data)
479
479
480
480
481 self.__lastdatatime = datatime
481 self.__lastdatatime = datatime
482
482
483 if avgdata is None:
483 if avgdata is None:
484 return None, None
484 return None, None
485
485
486 avgdatatime = self.__initime
486 avgdatatime = self.__initime
487
487
488 deltatime = datatime -self.__lastdatatime
488 deltatime = datatime -self.__lastdatatime
489
489
490 if not self.__withOverapping:
490 if not self.__withOverapping:
491 self.__initime = datatime
491 self.__initime = datatime
492 else:
492 else:
493 self.__initime += deltatime
493 self.__initime += deltatime
494
494
495 return avgdata, avgdatatime
495 return avgdata, avgdatatime
496
496
497 def integrateByBlock(self, dataOut):
497 def integrateByBlock(self, dataOut):
498
498
499 times = int(dataOut.data.shape[1]/self.n)
499 times = int(dataOut.data.shape[1]/self.n)
500 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
500 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
501
501
502 id_min = 0
502 id_min = 0
503 id_max = self.n
503 id_max = self.n
504
504
505 for i in range(times):
505 for i in range(times):
506 junk = dataOut.data[:,id_min:id_max,:]
506 junk = dataOut.data[:,id_min:id_max,:]
507 avgdata[:,i,:] = junk.sum(axis=1)
507 avgdata[:,i,:] = junk.sum(axis=1)
508 id_min += self.n
508 id_min += self.n
509 id_max += self.n
509 id_max += self.n
510
510
511 timeInterval = dataOut.ippSeconds*self.n
511 timeInterval = dataOut.ippSeconds*self.n
512 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
512 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
513 self.__dataReady = True
513 self.__dataReady = True
514 return avgdata, avgdatatime
514 return avgdata, avgdatatime
515
515
516
516
517 def run(self, dataOut, n=None, timeInterval=None, overlapping=False, byblock=False, **kwargs):
517 def run(self, dataOut, n=None, timeInterval=None, overlapping=False, byblock=False, **kwargs):
518 if not self.isConfig:
518 if not self.isConfig:
519 self.setup(n=n, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
519 self.setup(n=n, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
520 self.isConfig = True
520 self.isConfig = True
521
521
522 if dataOut.flagDataAsBlock:
522 if dataOut.flagDataAsBlock:
523 """
523 """
524 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
524 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
525 """
525 """
526 avgdata, avgdatatime = self.integrateByBlock(dataOut)
526 avgdata, avgdatatime = self.integrateByBlock(dataOut)
527 dataOut.nProfiles /= self.n
527 dataOut.nProfiles /= self.n
528 else:
528 else:
529 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
529 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
530
530
531 # dataOut.timeInterval *= n
531 # dataOut.timeInterval *= n
532 dataOut.flagNoData = True
532 dataOut.flagNoData = True
533
533
534 if self.__dataReady:
534 if self.__dataReady:
535 dataOut.data = avgdata
535 dataOut.data = avgdata
536 dataOut.nCohInt *= self.n
536 dataOut.nCohInt *= self.n
537 dataOut.utctime = avgdatatime
537 dataOut.utctime = avgdatatime
538 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
538 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
539 dataOut.flagNoData = False
539 dataOut.flagNoData = False
540
540
541 class Decoder(Operation):
541 class Decoder(Operation):
542
542
543 isConfig = False
543 isConfig = False
544 __profIndex = 0
544 __profIndex = 0
545
545
546 code = None
546 code = None
547
547
548 nCode = None
548 nCode = None
549 nBaud = None
549 nBaud = None
550
550
551
551
552 def __init__(self, **kwargs):
552 def __init__(self, **kwargs):
553
553
554 Operation.__init__(self, **kwargs)
554 Operation.__init__(self, **kwargs)
555
555
556 self.times = None
556 self.times = None
557 self.osamp = None
557 self.osamp = None
558 # self.__setValues = False
558 # self.__setValues = False
559 self.isConfig = False
559 self.isConfig = False
560
560
561 def setup(self, code, osamp, dataOut):
561 def setup(self, code, osamp, dataOut):
562
562
563 self.__profIndex = 0
563 self.__profIndex = 0
564
564
565 self.code = code
565 self.code = code
566
566
567 self.nCode = len(code)
567 self.nCode = len(code)
568 self.nBaud = len(code[0])
568 self.nBaud = len(code[0])
569
569
570 if (osamp != None) and (osamp >1):
570 if (osamp != None) and (osamp >1):
571 self.osamp = osamp
571 self.osamp = osamp
572 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
572 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
573 self.nBaud = self.nBaud*self.osamp
573 self.nBaud = self.nBaud*self.osamp
574
574
575 self.__nChannels = dataOut.nChannels
575 self.__nChannels = dataOut.nChannels
576 self.__nProfiles = dataOut.nProfiles
576 self.__nProfiles = dataOut.nProfiles
577 self.__nHeis = dataOut.nHeights
577 self.__nHeis = dataOut.nHeights
578
578
579 if self.__nHeis < self.nBaud:
579 if self.__nHeis < self.nBaud:
580 raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)
580 raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)
581
581
582 #Frequency
582 #Frequency
583 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
583 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
584
584
585 __codeBuffer[:,0:self.nBaud] = self.code
585 __codeBuffer[:,0:self.nBaud] = self.code
586
586
587 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
587 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
588
588
589 if dataOut.flagDataAsBlock:
589 if dataOut.flagDataAsBlock:
590
590
591 self.ndatadec = self.__nHeis #- self.nBaud + 1
591 self.ndatadec = self.__nHeis #- self.nBaud + 1
592
592
593 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
593 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
594
594
595 else:
595 else:
596
596
597 #Time
597 #Time
598 self.ndatadec = self.__nHeis #- self.nBaud + 1
598 self.ndatadec = self.__nHeis #- self.nBaud + 1
599
599
600 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
600 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
601
601
602 def __convolutionInFreq(self, data):
602 def __convolutionInFreq(self, data):
603
603
604 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
604 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
605
605
606 fft_data = numpy.fft.fft(data, axis=1)
606 fft_data = numpy.fft.fft(data, axis=1)
607
607
608 conv = fft_data*fft_code
608 conv = fft_data*fft_code
609
609
610 data = numpy.fft.ifft(conv,axis=1)
610 data = numpy.fft.ifft(conv,axis=1)
611
611
612 return data
612 return data
613
613
614 def __convolutionInFreqOpt(self, data):
614 def __convolutionInFreqOpt(self, data):
615
615
616 raise NotImplementedError
616 raise NotImplementedError
617
617
618 def __convolutionInTime(self, data):
618 def __convolutionInTime(self, data):
619
619
620 code = self.code[self.__profIndex]
620 code = self.code[self.__profIndex]
621
621
622 for i in range(self.__nChannels):
622 for i in range(self.__nChannels):
623 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
623 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
624
624
625 return self.datadecTime
625 return self.datadecTime
626
626
627 def __convolutionByBlockInTime(self, data):
627 def __convolutionByBlockInTime(self, data):
628
628
629 repetitions = self.__nProfiles / self.nCode
629 repetitions = self.__nProfiles / self.nCode
630
630
631 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
631 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
632 junk = junk.flatten()
632 junk = junk.flatten()
633 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
633 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
634
634
635 for i in range(self.__nChannels):
635 for i in range(self.__nChannels):
636 for j in range(self.__nProfiles):
636 for j in range(self.__nProfiles):
637 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
637 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
638
638
639 return self.datadecTime
639 return self.datadecTime
640
640
641 def __convolutionByBlockInFreq(self, data):
641 def __convolutionByBlockInFreq(self, data):
642
642
643 raise NotImplementedError, "Decoder by frequency fro Blocks not implemented"
643 raise NotImplementedError, "Decoder by frequency fro Blocks not implemented"
644
644
645
645
646 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
646 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
647
647
648 fft_data = numpy.fft.fft(data, axis=2)
648 fft_data = numpy.fft.fft(data, axis=2)
649
649
650 conv = fft_data*fft_code
650 conv = fft_data*fft_code
651
651
652 data = numpy.fft.ifft(conv,axis=2)
652 data = numpy.fft.ifft(conv,axis=2)
653
653
654 return data
654 return data
655
655
656 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
656 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
657
657
658 if dataOut.flagDecodeData:
658 if dataOut.flagDecodeData:
659 print "This data is already decoded, recoding again ..."
659 print "This data is already decoded, recoding again ..."
660
660
661 if not self.isConfig:
661 if not self.isConfig:
662
662
663 if code is None:
663 if code is None:
664 if dataOut.code is None:
664 if dataOut.code is None:
665 raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type
665 raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type
666
666
667 code = dataOut.code
667 code = dataOut.code
668 else:
668 else:
669 code = numpy.array(code).reshape(nCode,nBaud)
669 code = numpy.array(code).reshape(nCode,nBaud)
670
670
671 self.setup(code, osamp, dataOut)
671 self.setup(code, osamp, dataOut)
672
672
673 self.isConfig = True
673 self.isConfig = True
674
674
675 if mode == 3:
675 if mode == 3:
676 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
676 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
677
677
678 if times != None:
678 if times != None:
679 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
679 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
680
680
681 if self.code is None:
681 if self.code is None:
682 print "Fail decoding: Code is not defined."
682 print "Fail decoding: Code is not defined."
683 return
683 return
684
684
685 self.__nProfiles = dataOut.nProfiles
685 datadec = None
686 datadec = None
687
686 if mode == 3:
688 if mode == 3:
687 mode = 0
689 mode = 0
688
690
689 if dataOut.flagDataAsBlock:
691 if dataOut.flagDataAsBlock:
690 """
692 """
691 Decoding when data have been read as block,
693 Decoding when data have been read as block,
692 """
694 """
693
695
694 if mode == 0:
696 if mode == 0:
695 datadec = self.__convolutionByBlockInTime(dataOut.data)
697 datadec = self.__convolutionByBlockInTime(dataOut.data)
696 if mode == 1:
698 if mode == 1:
697 datadec = self.__convolutionByBlockInFreq(dataOut.data)
699 datadec = self.__convolutionByBlockInFreq(dataOut.data)
698 else:
700 else:
699 """
701 """
700 Decoding when data have been read profile by profile
702 Decoding when data have been read profile by profile
701 """
703 """
702 if mode == 0:
704 if mode == 0:
703 datadec = self.__convolutionInTime(dataOut.data)
705 datadec = self.__convolutionInTime(dataOut.data)
704
706
705 if mode == 1:
707 if mode == 1:
706 datadec = self.__convolutionInFreq(dataOut.data)
708 datadec = self.__convolutionInFreq(dataOut.data)
707
709
708 if mode == 2:
710 if mode == 2:
709 datadec = self.__convolutionInFreqOpt(dataOut.data)
711 datadec = self.__convolutionInFreqOpt(dataOut.data)
710
712
711 if datadec is None:
713 if datadec is None:
712 raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode
714 raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode
713
715
714 dataOut.code = self.code
716 dataOut.code = self.code
715 dataOut.nCode = self.nCode
717 dataOut.nCode = self.nCode
716 dataOut.nBaud = self.nBaud
718 dataOut.nBaud = self.nBaud
717
719
718 dataOut.data = datadec
720 dataOut.data = datadec
719
721
720 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
722 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
721
723
722 dataOut.flagDecodeData = True #asumo q la data esta decodificada
724 dataOut.flagDecodeData = True #asumo q la data esta decodificada
723
725
724 if self.__profIndex == self.nCode-1:
726 if self.__profIndex == self.nCode-1:
725 self.__profIndex = 0
727 self.__profIndex = 0
726 return 1
728 return 1
727
729
728 self.__profIndex += 1
730 self.__profIndex += 1
729
731
730 return 1
732 return 1
731 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
733 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
732
734
733
735
734 class ProfileConcat(Operation):
736 class ProfileConcat(Operation):
735
737
736 isConfig = False
738 isConfig = False
737 buffer = None
739 buffer = None
738
740
739 def __init__(self, **kwargs):
741 def __init__(self, **kwargs):
740
742
741 Operation.__init__(self, **kwargs)
743 Operation.__init__(self, **kwargs)
742 self.profileIndex = 0
744 self.profileIndex = 0
743
745
744 def reset(self):
746 def reset(self):
745 self.buffer = numpy.zeros_like(self.buffer)
747 self.buffer = numpy.zeros_like(self.buffer)
746 self.start_index = 0
748 self.start_index = 0
747 self.times = 1
749 self.times = 1
748
750
749 def setup(self, data, m, n=1):
751 def setup(self, data, m, n=1):
750 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
752 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
751 self.nHeights = data.shape[1]#.nHeights
753 self.nHeights = data.shape[1]#.nHeights
752 self.start_index = 0
754 self.start_index = 0
753 self.times = 1
755 self.times = 1
754
756
755 def concat(self, data):
757 def concat(self, data):
756
758
757 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
759 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
758 self.start_index = self.start_index + self.nHeights
760 self.start_index = self.start_index + self.nHeights
759
761
760 def run(self, dataOut, m):
762 def run(self, dataOut, m):
761
763
762 dataOut.flagNoData = True
764 dataOut.flagNoData = True
763
765
764 if not self.isConfig:
766 if not self.isConfig:
765 self.setup(dataOut.data, m, 1)
767 self.setup(dataOut.data, m, 1)
766 self.isConfig = True
768 self.isConfig = True
767
769
768 if dataOut.flagDataAsBlock:
770 if dataOut.flagDataAsBlock:
769 raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False"
771 raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False"
770
772
771 else:
773 else:
772 self.concat(dataOut.data)
774 self.concat(dataOut.data)
773 self.times += 1
775 self.times += 1
774 if self.times > m:
776 if self.times > m:
775 dataOut.data = self.buffer
777 dataOut.data = self.buffer
776 self.reset()
778 self.reset()
777 dataOut.flagNoData = False
779 dataOut.flagNoData = False
778 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
780 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
779 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
781 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
780 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
782 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
781 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
783 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
782 dataOut.ippSeconds *= m
784 dataOut.ippSeconds *= m
783
785
784 class ProfileSelector(Operation):
786 class ProfileSelector(Operation):
785
787
786 profileIndex = None
788 profileIndex = None
787 # Tamanho total de los perfiles
789 # Tamanho total de los perfiles
788 nProfiles = None
790 nProfiles = None
789
791
790 def __init__(self, **kwargs):
792 def __init__(self, **kwargs):
791
793
792 Operation.__init__(self, **kwargs)
794 Operation.__init__(self, **kwargs)
793 self.profileIndex = 0
795 self.profileIndex = 0
794
796
795 def incProfileIndex(self):
797 def incProfileIndex(self):
796
798
797 self.profileIndex += 1
799 self.profileIndex += 1
798
800
799 if self.profileIndex >= self.nProfiles:
801 if self.profileIndex >= self.nProfiles:
800 self.profileIndex = 0
802 self.profileIndex = 0
801
803
802 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
804 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
803
805
804 if profileIndex < minIndex:
806 if profileIndex < minIndex:
805 return False
807 return False
806
808
807 if profileIndex > maxIndex:
809 if profileIndex > maxIndex:
808 return False
810 return False
809
811
810 return True
812 return True
811
813
812 def isThisProfileInList(self, profileIndex, profileList):
814 def isThisProfileInList(self, profileIndex, profileList):
813
815
814 if profileIndex not in profileList:
816 if profileIndex not in profileList:
815 return False
817 return False
816
818
817 return True
819 return True
818
820
819 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
821 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
820
822
821 """
823 """
822 ProfileSelector:
824 ProfileSelector:
823
825
824 Inputs:
826 Inputs:
825 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
827 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
826
828
827 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
829 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
828
830
829 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
831 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
830
832
831 """
833 """
832
834
833 if rangeList is not None:
835 if rangeList is not None:
834 if type(rangeList[0]) not in (tuple, list):
836 if type(rangeList[0]) not in (tuple, list):
835 rangeList = [rangeList]
837 rangeList = [rangeList]
836
838
837 dataOut.flagNoData = True
839 dataOut.flagNoData = True
838
840
839 if dataOut.flagDataAsBlock:
841 if dataOut.flagDataAsBlock:
840 """
842 """
841 data dimension = [nChannels, nProfiles, nHeis]
843 data dimension = [nChannels, nProfiles, nHeis]
842 """
844 """
843 if profileList != None:
845 if profileList != None:
844 dataOut.data = dataOut.data[:,profileList,:]
846 dataOut.data = dataOut.data[:,profileList,:]
845
847
846 if profileRangeList != None:
848 if profileRangeList != None:
847 minIndex = profileRangeList[0]
849 minIndex = profileRangeList[0]
848 maxIndex = profileRangeList[1]
850 maxIndex = profileRangeList[1]
849 profileList = range(minIndex, maxIndex+1)
851 profileList = range(minIndex, maxIndex+1)
850
852
851 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
853 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
852
854
853 if rangeList != None:
855 if rangeList != None:
854
856
855 profileList = []
857 profileList = []
856
858
857 for thisRange in rangeList:
859 for thisRange in rangeList:
858 minIndex = thisRange[0]
860 minIndex = thisRange[0]
859 maxIndex = thisRange[1]
861 maxIndex = thisRange[1]
860
862
861 profileList.extend(range(minIndex, maxIndex+1))
863 profileList.extend(range(minIndex, maxIndex+1))
862
864
863 dataOut.data = dataOut.data[:,profileList,:]
865 dataOut.data = dataOut.data[:,profileList,:]
864
866
865 dataOut.nProfiles = len(profileList)
867 dataOut.nProfiles = len(profileList)
866 dataOut.profileIndex = dataOut.nProfiles - 1
868 dataOut.profileIndex = dataOut.nProfiles - 1
867 dataOut.flagNoData = False
869 dataOut.flagNoData = False
868
870
869 return True
871 return True
870
872
871 """
873 """
872 data dimension = [nChannels, nHeis]
874 data dimension = [nChannels, nHeis]
873 """
875 """
874
876
875 if profileList != None:
877 if profileList != None:
876
878
877 if self.isThisProfileInList(dataOut.profileIndex, profileList):
879 if self.isThisProfileInList(dataOut.profileIndex, profileList):
878
880
879 self.nProfiles = len(profileList)
881 self.nProfiles = len(profileList)
880 dataOut.nProfiles = self.nProfiles
882 dataOut.nProfiles = self.nProfiles
881 dataOut.profileIndex = self.profileIndex
883 dataOut.profileIndex = self.profileIndex
882 dataOut.flagNoData = False
884 dataOut.flagNoData = False
883
885
884 self.incProfileIndex()
886 self.incProfileIndex()
885 return True
887 return True
886
888
887 if profileRangeList != None:
889 if profileRangeList != None:
888
890
889 minIndex = profileRangeList[0]
891 minIndex = profileRangeList[0]
890 maxIndex = profileRangeList[1]
892 maxIndex = profileRangeList[1]
891
893
892 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
894 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
893
895
894 self.nProfiles = maxIndex - minIndex + 1
896 self.nProfiles = maxIndex - minIndex + 1
895 dataOut.nProfiles = self.nProfiles
897 dataOut.nProfiles = self.nProfiles
896 dataOut.profileIndex = self.profileIndex
898 dataOut.profileIndex = self.profileIndex
897 dataOut.flagNoData = False
899 dataOut.flagNoData = False
898
900
899 self.incProfileIndex()
901 self.incProfileIndex()
900 return True
902 return True
901
903
902 if rangeList != None:
904 if rangeList != None:
903
905
904 nProfiles = 0
906 nProfiles = 0
905
907
906 for thisRange in rangeList:
908 for thisRange in rangeList:
907 minIndex = thisRange[0]
909 minIndex = thisRange[0]
908 maxIndex = thisRange[1]
910 maxIndex = thisRange[1]
909
911
910 nProfiles += maxIndex - minIndex + 1
912 nProfiles += maxIndex - minIndex + 1
911
913
912 for thisRange in rangeList:
914 for thisRange in rangeList:
913
915
914 minIndex = thisRange[0]
916 minIndex = thisRange[0]
915 maxIndex = thisRange[1]
917 maxIndex = thisRange[1]
916
918
917 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
919 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
918
920
919 self.nProfiles = nProfiles
921 self.nProfiles = nProfiles
920 dataOut.nProfiles = self.nProfiles
922 dataOut.nProfiles = self.nProfiles
921 dataOut.profileIndex = self.profileIndex
923 dataOut.profileIndex = self.profileIndex
922 dataOut.flagNoData = False
924 dataOut.flagNoData = False
923
925
924 self.incProfileIndex()
926 self.incProfileIndex()
925
927
926 break
928 break
927
929
928 return True
930 return True
929
931
930
932
931 if beam != None: #beam is only for AMISR data
933 if beam != None: #beam is only for AMISR data
932 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
934 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
933 dataOut.flagNoData = False
935 dataOut.flagNoData = False
934 dataOut.profileIndex = self.profileIndex
936 dataOut.profileIndex = self.profileIndex
935
937
936 self.incProfileIndex()
938 self.incProfileIndex()
937
939
938 return True
940 return True
939
941
940 raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter"
942 raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter"
941
943
942 return False
944 return False
943
945
944 class Reshaper(Operation):
946 class Reshaper(Operation):
945
947
946 def __init__(self, **kwargs):
948 def __init__(self, **kwargs):
947
949
948 Operation.__init__(self, **kwargs)
950 Operation.__init__(self, **kwargs)
949
951
950 self.__buffer = None
952 self.__buffer = None
951 self.__nitems = 0
953 self.__nitems = 0
952
954
953 def __appendProfile(self, dataOut, nTxs):
955 def __appendProfile(self, dataOut, nTxs):
954
956
955 if self.__buffer is None:
957 if self.__buffer is None:
956 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
958 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
957 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
959 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
958
960
959 ini = dataOut.nHeights * self.__nitems
961 ini = dataOut.nHeights * self.__nitems
960 end = ini + dataOut.nHeights
962 end = ini + dataOut.nHeights
961
963
962 self.__buffer[:, ini:end] = dataOut.data
964 self.__buffer[:, ini:end] = dataOut.data
963
965
964 self.__nitems += 1
966 self.__nitems += 1
965
967
966 return int(self.__nitems*nTxs)
968 return int(self.__nitems*nTxs)
967
969
968 def __getBuffer(self):
970 def __getBuffer(self):
969
971
970 if self.__nitems == int(1./self.__nTxs):
972 if self.__nitems == int(1./self.__nTxs):
971
973
972 self.__nitems = 0
974 self.__nitems = 0
973
975
974 return self.__buffer.copy()
976 return self.__buffer.copy()
975
977
976 return None
978 return None
977
979
978 def __checkInputs(self, dataOut, shape, nTxs):
980 def __checkInputs(self, dataOut, shape, nTxs):
979
981
980 if shape is None and nTxs is None:
982 if shape is None and nTxs is None:
981 raise ValueError, "Reshaper: shape of factor should be defined"
983 raise ValueError, "Reshaper: shape of factor should be defined"
982
984
983 if nTxs:
985 if nTxs:
984 if nTxs < 0:
986 if nTxs < 0:
985 raise ValueError, "nTxs should be greater than 0"
987 raise ValueError, "nTxs should be greater than 0"
986
988
987 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
989 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
988 raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))
990 raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))
989
991
990 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
992 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
991
993
992 return shape, nTxs
994 return shape, nTxs
993
995
994 if len(shape) != 2 and len(shape) != 3:
996 if len(shape) != 2 and len(shape) != 3:
995 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)
997 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)
996
998
997 if len(shape) == 2:
999 if len(shape) == 2:
998 shape_tuple = [dataOut.nChannels]
1000 shape_tuple = [dataOut.nChannels]
999 shape_tuple.extend(shape)
1001 shape_tuple.extend(shape)
1000 else:
1002 else:
1001 shape_tuple = list(shape)
1003 shape_tuple = list(shape)
1002
1004
1003 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1005 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1004
1006
1005 return shape_tuple, nTxs
1007 return shape_tuple, nTxs
1006
1008
1007 def run(self, dataOut, shape=None, nTxs=None):
1009 def run(self, dataOut, shape=None, nTxs=None):
1008
1010
1009 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1011 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1010
1012
1011 dataOut.flagNoData = True
1013 dataOut.flagNoData = True
1012 profileIndex = None
1014 profileIndex = None
1013
1015
1014 if dataOut.flagDataAsBlock:
1016 if dataOut.flagDataAsBlock:
1015
1017
1016 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1018 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1017 dataOut.flagNoData = False
1019 dataOut.flagNoData = False
1018
1020
1019 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1021 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1020
1022
1021 else:
1023 else:
1022
1024
1023 if self.__nTxs < 1:
1025 if self.__nTxs < 1:
1024
1026
1025 self.__appendProfile(dataOut, self.__nTxs)
1027 self.__appendProfile(dataOut, self.__nTxs)
1026 new_data = self.__getBuffer()
1028 new_data = self.__getBuffer()
1027
1029
1028 if new_data is not None:
1030 if new_data is not None:
1029 dataOut.data = new_data
1031 dataOut.data = new_data
1030 dataOut.flagNoData = False
1032 dataOut.flagNoData = False
1031
1033
1032 profileIndex = dataOut.profileIndex*nTxs
1034 profileIndex = dataOut.profileIndex*nTxs
1033
1035
1034 else:
1036 else:
1035 raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)"
1037 raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)"
1036
1038
1037 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1039 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1038
1040
1039 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1041 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1040
1042
1041 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1043 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1042
1044
1043 dataOut.profileIndex = profileIndex
1045 dataOut.profileIndex = profileIndex
1044
1046
1045 dataOut.ippSeconds /= self.__nTxs
1047 dataOut.ippSeconds /= self.__nTxs
1046
1048
1047 class SplitProfiles(Operation):
1049 class SplitProfiles(Operation):
1048
1050
1049 def __init__(self, **kwargs):
1051 def __init__(self, **kwargs):
1050
1052
1051 Operation.__init__(self, **kwargs)
1053 Operation.__init__(self, **kwargs)
1052
1054
1053 def run(self, dataOut, n):
1055 def run(self, dataOut, n):
1054
1056
1055 dataOut.flagNoData = True
1057 dataOut.flagNoData = True
1056 profileIndex = None
1058 profileIndex = None
1057
1059
1058 if dataOut.flagDataAsBlock:
1060 if dataOut.flagDataAsBlock:
1059
1061
1060 #nchannels, nprofiles, nsamples
1062 #nchannels, nprofiles, nsamples
1061 shape = dataOut.data.shape
1063 shape = dataOut.data.shape
1062
1064
1063 if shape[2] % n != 0:
1065 if shape[2] % n != 0:
1064 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])
1066 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])
1065
1067
1066 new_shape = shape[0], shape[1]*n, shape[2]/n
1068 new_shape = shape[0], shape[1]*n, shape[2]/n
1067
1069
1068 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1070 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1069 dataOut.flagNoData = False
1071 dataOut.flagNoData = False
1070
1072
1071 profileIndex = int(dataOut.nProfiles/n) - 1
1073 profileIndex = int(dataOut.nProfiles/n) - 1
1072
1074
1073 else:
1075 else:
1074
1076
1075 raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)"
1077 raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)"
1076
1078
1077 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1079 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1078
1080
1079 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1081 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1080
1082
1081 dataOut.nProfiles = int(dataOut.nProfiles*n)
1083 dataOut.nProfiles = int(dataOut.nProfiles*n)
1082
1084
1083 dataOut.profileIndex = profileIndex
1085 dataOut.profileIndex = profileIndex
1084
1086
1085 dataOut.ippSeconds /= n
1087 dataOut.ippSeconds /= n
1086
1088
1087 class CombineProfiles(Operation):
1089 class CombineProfiles(Operation):
1088
1090
1089 def __init__(self, **kwargs):
1091 def __init__(self, **kwargs):
1090
1092
1091 Operation.__init__(self, **kwargs)
1093 Operation.__init__(self, **kwargs)
1092
1094
1093 self.__remData = None
1095 self.__remData = None
1094 self.__profileIndex = 0
1096 self.__profileIndex = 0
1095
1097
1096 def run(self, dataOut, n):
1098 def run(self, dataOut, n):
1097
1099
1098 dataOut.flagNoData = True
1100 dataOut.flagNoData = True
1099 profileIndex = None
1101 profileIndex = None
1100
1102
1101 if dataOut.flagDataAsBlock:
1103 if dataOut.flagDataAsBlock:
1102
1104
1103 #nchannels, nprofiles, nsamples
1105 #nchannels, nprofiles, nsamples
1104 shape = dataOut.data.shape
1106 shape = dataOut.data.shape
1105 new_shape = shape[0], shape[1]/n, shape[2]*n
1107 new_shape = shape[0], shape[1]/n, shape[2]*n
1106
1108
1107 if shape[1] % n != 0:
1109 if shape[1] % n != 0:
1108 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])
1110 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])
1109
1111
1110 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1112 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1111 dataOut.flagNoData = False
1113 dataOut.flagNoData = False
1112
1114
1113 profileIndex = int(dataOut.nProfiles*n) - 1
1115 profileIndex = int(dataOut.nProfiles*n) - 1
1114
1116
1115 else:
1117 else:
1116
1118
1117 #nchannels, nsamples
1119 #nchannels, nsamples
1118 if self.__remData is None:
1120 if self.__remData is None:
1119 newData = dataOut.data
1121 newData = dataOut.data
1120 else:
1122 else:
1121 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1123 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1122
1124
1123 self.__profileIndex += 1
1125 self.__profileIndex += 1
1124
1126
1125 if self.__profileIndex < n:
1127 if self.__profileIndex < n:
1126 self.__remData = newData
1128 self.__remData = newData
1127 #continue
1129 #continue
1128 return
1130 return
1129
1131
1130 self.__profileIndex = 0
1132 self.__profileIndex = 0
1131 self.__remData = None
1133 self.__remData = None
1132
1134
1133 dataOut.data = newData
1135 dataOut.data = newData
1134 dataOut.flagNoData = False
1136 dataOut.flagNoData = False
1135
1137
1136 profileIndex = dataOut.profileIndex/n
1138 profileIndex = dataOut.profileIndex/n
1137
1139
1138
1140
1139 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1141 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1140
1142
1141 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1143 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1142
1144
1143 dataOut.nProfiles = int(dataOut.nProfiles/n)
1145 dataOut.nProfiles = int(dataOut.nProfiles/n)
1144
1146
1145 dataOut.profileIndex = profileIndex
1147 dataOut.profileIndex = profileIndex
1146
1148
1147 dataOut.ippSeconds *= n
1149 dataOut.ippSeconds *= n
1148
1150
1149 # import collections
1151 # import collections
1150 # from scipy.stats import mode
1152 # from scipy.stats import mode
1151 #
1153 #
1152 # class Synchronize(Operation):
1154 # class Synchronize(Operation):
1153 #
1155 #
1154 # isConfig = False
1156 # isConfig = False
1155 # __profIndex = 0
1157 # __profIndex = 0
1156 #
1158 #
1157 # def __init__(self, **kwargs):
1159 # def __init__(self, **kwargs):
1158 #
1160 #
1159 # Operation.__init__(self, **kwargs)
1161 # Operation.__init__(self, **kwargs)
1160 # # self.isConfig = False
1162 # # self.isConfig = False
1161 # self.__powBuffer = None
1163 # self.__powBuffer = None
1162 # self.__startIndex = 0
1164 # self.__startIndex = 0
1163 # self.__pulseFound = False
1165 # self.__pulseFound = False
1164 #
1166 #
1165 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1167 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1166 #
1168 #
1167 # #Read data
1169 # #Read data
1168 #
1170 #
1169 # powerdB = dataOut.getPower(channel = channel)
1171 # powerdB = dataOut.getPower(channel = channel)
1170 # noisedB = dataOut.getNoise(channel = channel)[0]
1172 # noisedB = dataOut.getNoise(channel = channel)[0]
1171 #
1173 #
1172 # self.__powBuffer.extend(powerdB.flatten())
1174 # self.__powBuffer.extend(powerdB.flatten())
1173 #
1175 #
1174 # dataArray = numpy.array(self.__powBuffer)
1176 # dataArray = numpy.array(self.__powBuffer)
1175 #
1177 #
1176 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1178 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1177 #
1179 #
1178 # maxValue = numpy.nanmax(filteredPower)
1180 # maxValue = numpy.nanmax(filteredPower)
1179 #
1181 #
1180 # if maxValue < noisedB + 10:
1182 # if maxValue < noisedB + 10:
1181 # #No se encuentra ningun pulso de transmision
1183 # #No se encuentra ningun pulso de transmision
1182 # return None
1184 # return None
1183 #
1185 #
1184 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1186 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1185 #
1187 #
1186 # if len(maxValuesIndex) < 2:
1188 # if len(maxValuesIndex) < 2:
1187 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1189 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1188 # return None
1190 # return None
1189 #
1191 #
1190 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1192 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1191 #
1193 #
1192 # #Seleccionar solo valores con un espaciamiento de nSamples
1194 # #Seleccionar solo valores con un espaciamiento de nSamples
1193 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1195 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1194 #
1196 #
1195 # if len(pulseIndex) < 2:
1197 # if len(pulseIndex) < 2:
1196 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1198 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1197 # return None
1199 # return None
1198 #
1200 #
1199 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1201 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1200 #
1202 #
1201 # #remover senales que se distancien menos de 10 unidades o muestras
1203 # #remover senales que se distancien menos de 10 unidades o muestras
1202 # #(No deberian existir IPP menor a 10 unidades)
1204 # #(No deberian existir IPP menor a 10 unidades)
1203 #
1205 #
1204 # realIndex = numpy.where(spacing > 10 )[0]
1206 # realIndex = numpy.where(spacing > 10 )[0]
1205 #
1207 #
1206 # if len(realIndex) < 2:
1208 # if len(realIndex) < 2:
1207 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1209 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1208 # return None
1210 # return None
1209 #
1211 #
1210 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1212 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1211 # realPulseIndex = pulseIndex[realIndex]
1213 # realPulseIndex = pulseIndex[realIndex]
1212 #
1214 #
1213 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1215 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1214 #
1216 #
1215 # print "IPP = %d samples" %period
1217 # print "IPP = %d samples" %period
1216 #
1218 #
1217 # self.__newNSamples = dataOut.nHeights #int(period)
1219 # self.__newNSamples = dataOut.nHeights #int(period)
1218 # self.__startIndex = int(realPulseIndex[0])
1220 # self.__startIndex = int(realPulseIndex[0])
1219 #
1221 #
1220 # return 1
1222 # return 1
1221 #
1223 #
1222 #
1224 #
1223 # def setup(self, nSamples, nChannels, buffer_size = 4):
1225 # def setup(self, nSamples, nChannels, buffer_size = 4):
1224 #
1226 #
1225 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1227 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1226 # maxlen = buffer_size*nSamples)
1228 # maxlen = buffer_size*nSamples)
1227 #
1229 #
1228 # bufferList = []
1230 # bufferList = []
1229 #
1231 #
1230 # for i in range(nChannels):
1232 # for i in range(nChannels):
1231 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1233 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1232 # maxlen = buffer_size*nSamples)
1234 # maxlen = buffer_size*nSamples)
1233 #
1235 #
1234 # bufferList.append(bufferByChannel)
1236 # bufferList.append(bufferByChannel)
1235 #
1237 #
1236 # self.__nSamples = nSamples
1238 # self.__nSamples = nSamples
1237 # self.__nChannels = nChannels
1239 # self.__nChannels = nChannels
1238 # self.__bufferList = bufferList
1240 # self.__bufferList = bufferList
1239 #
1241 #
1240 # def run(self, dataOut, channel = 0):
1242 # def run(self, dataOut, channel = 0):
1241 #
1243 #
1242 # if not self.isConfig:
1244 # if not self.isConfig:
1243 # nSamples = dataOut.nHeights
1245 # nSamples = dataOut.nHeights
1244 # nChannels = dataOut.nChannels
1246 # nChannels = dataOut.nChannels
1245 # self.setup(nSamples, nChannels)
1247 # self.setup(nSamples, nChannels)
1246 # self.isConfig = True
1248 # self.isConfig = True
1247 #
1249 #
1248 # #Append new data to internal buffer
1250 # #Append new data to internal buffer
1249 # for thisChannel in range(self.__nChannels):
1251 # for thisChannel in range(self.__nChannels):
1250 # bufferByChannel = self.__bufferList[thisChannel]
1252 # bufferByChannel = self.__bufferList[thisChannel]
1251 # bufferByChannel.extend(dataOut.data[thisChannel])
1253 # bufferByChannel.extend(dataOut.data[thisChannel])
1252 #
1254 #
1253 # if self.__pulseFound:
1255 # if self.__pulseFound:
1254 # self.__startIndex -= self.__nSamples
1256 # self.__startIndex -= self.__nSamples
1255 #
1257 #
1256 # #Finding Tx Pulse
1258 # #Finding Tx Pulse
1257 # if not self.__pulseFound:
1259 # if not self.__pulseFound:
1258 # indexFound = self.__findTxPulse(dataOut, channel)
1260 # indexFound = self.__findTxPulse(dataOut, channel)
1259 #
1261 #
1260 # if indexFound == None:
1262 # if indexFound == None:
1261 # dataOut.flagNoData = True
1263 # dataOut.flagNoData = True
1262 # return
1264 # return
1263 #
1265 #
1264 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1266 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1265 # self.__pulseFound = True
1267 # self.__pulseFound = True
1266 # self.__startIndex = indexFound
1268 # self.__startIndex = indexFound
1267 #
1269 #
1268 # #If pulse was found ...
1270 # #If pulse was found ...
1269 # for thisChannel in range(self.__nChannels):
1271 # for thisChannel in range(self.__nChannels):
1270 # bufferByChannel = self.__bufferList[thisChannel]
1272 # bufferByChannel = self.__bufferList[thisChannel]
1271 # #print self.__startIndex
1273 # #print self.__startIndex
1272 # x = numpy.array(bufferByChannel)
1274 # x = numpy.array(bufferByChannel)
1273 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1275 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1274 #
1276 #
1275 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1277 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1276 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1278 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1277 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1279 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1278 #
1280 #
1279 # dataOut.data = self.__arrayBuffer
1281 # dataOut.data = self.__arrayBuffer
1280 #
1282 #
1281 # self.__startIndex += self.__newNSamples
1283 # self.__startIndex += self.__newNSamples
1282 #
1284 #
1283 # return
1285 # return
General Comments 0
You need to be logged in to leave comments. Login now