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