##// END OF EJS Templates
antiguo comportamiento de cohint. Ej: 96 -> 24x4
José Chávez -
r1117:2d7be107f7bd
parent child
Show More
@@ -1,1321 +1,1319
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 __profIndex = 0
321 __profIndex = 0
322 __byTime = False
322 __byTime = False
323 __initime = None
323 __initime = None
324 __lastdatatime = None
324 __lastdatatime = None
325 __integrationtime = None
325 __integrationtime = None
326 __buffer = None
326 __buffer = None
327 __bufferStride = []
327 __bufferStride = []
328 __dataReady = False
328 __dataReady = False
329 __profIndexStride = 0
329 __profIndexStride = 0
330 __dataToPutStride = False
330 __dataToPutStride = False
331 n = None
331 n = None
332
332
333 def __init__(self, **kwargs):
333 def __init__(self, **kwargs):
334
334
335 Operation.__init__(self, **kwargs)
335 Operation.__init__(self, **kwargs)
336
336
337 # self.isConfig = False
337 # self.isConfig = False
338
338
339 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
339 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
340 """
340 """
341 Set the parameters of the integration class.
341 Set the parameters of the integration class.
342
342
343 Inputs:
343 Inputs:
344
344
345 n : Number of coherent integrations
345 n : Number of coherent integrations
346 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
347 overlapping :
347 overlapping :
348 """
348 """
349
349
350 self.__initime = None
350 self.__initime = None
351 self.__lastdatatime = 0
351 self.__lastdatatime = 0
352 self.__buffer = None
352 self.__buffer = None
353 self.__dataReady = False
353 self.__dataReady = False
354 self.byblock = byblock
354 self.byblock = byblock
355 self.stride = stride
355 self.stride = stride
356
356
357 if n == None and timeInterval == None:
357 if n == None and timeInterval == None:
358 raise ValueError, "n or timeInterval should be specified ..."
358 raise ValueError, "n or timeInterval should be specified ..."
359
359
360 if n != None:
360 if n != None:
361 self.n = n
361 self.n = n
362 self.__byTime = False
362 self.__byTime = False
363 else:
363 else:
364 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
364 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
365 self.n = 9999
365 self.n = 9999
366 self.__byTime = True
366 self.__byTime = True
367
367
368 if overlapping:
368 if overlapping:
369 self.__withOverlapping = True
369 self.__withOverlapping = True
370 self.__buffer = None
370 self.__buffer = None
371 else:
371 else:
372 self.__withOverlapping = False
372 self.__withOverlapping = False
373 self.__buffer = 0
373 self.__buffer = 0
374
374
375 self.__profIndex = 0
375 self.__profIndex = 0
376
376
377 def putData(self, data):
377 def putData(self, data):
378
378
379 """
379 """
380 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
381
381
382 """
382 """
383
383
384 if not self.__withOverlapping:
384 if not self.__withOverlapping:
385 self.__buffer += data.copy()
385 self.__buffer += data.copy()
386 self.__profIndex += 1
386 self.__profIndex += 1
387 return
387 return
388
388
389 #Overlapping data
389 #Overlapping data
390 nChannels, nHeis = data.shape
390 nChannels, nHeis = data.shape
391 data = numpy.reshape(data, (1, nChannels, nHeis))
391 data = numpy.reshape(data, (1, nChannels, nHeis))
392
392
393 #If the buffer is empty then it takes the data value
393 #If the buffer is empty then it takes the data value
394 if self.__buffer is None:
394 if self.__buffer is None:
395 self.__buffer = data
395 self.__buffer = data
396 self.__profIndex += 1
396 self.__profIndex += 1
397 return
397 return
398
398
399 #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
400 if self.__profIndex < self.n:
400 if self.__profIndex < self.n:
401 self.__buffer = numpy.vstack((self.__buffer, data))
401 self.__buffer = numpy.vstack((self.__buffer, data))
402 self.__profIndex += 1
402 self.__profIndex += 1
403 return
403 return
404
404
405 #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
406 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
406 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
407 self.__buffer[self.n-1] = data
407 self.__buffer[self.n-1] = data
408 self.__profIndex = self.n
408 self.__profIndex = self.n
409 return
409 return
410
410
411
411
412 def pushData(self):
412 def pushData(self):
413 """
413 """
414 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.
415
415
416 Affected:
416 Affected:
417
417
418 self.__profileIndex
418 self.__profileIndex
419
419
420 """
420 """
421
421
422 if not self.__withOverlapping:
422 if not self.__withOverlapping:
423 data = self.__buffer
423 data = self.__buffer
424 n = self.__profIndex
424 n = self.__profIndex
425
425
426 self.__buffer = 0
426 self.__buffer = 0
427 self.__profIndex = 0
427 self.__profIndex = 0
428
428
429 return data, n
429 return data, n
430
430
431 #Integration with Overlapping
431 #Integration with Overlapping
432 data = numpy.sum(self.__buffer, axis=0)
432 data = numpy.sum(self.__buffer, axis=0)
433 # print data
433 # print data
434 # raise
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 # print data
444 # print data
445 # raise
445 # raise
446 self.putData(data)
446 self.putData(data)
447
447
448 if self.__profIndex == self.n:
448 if self.__profIndex == self.n:
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):
469 def integrateByStride(self, data, datatime):
470 # print data
470 # print data
471 if self.__profIndex == 0:
471 if self.__profIndex == 0:
472 self.__buffer = [[data.copy(), datatime]]
472 self.__buffer = [[data.copy(), datatime]]
473 else:
473 else:
474 self.__buffer.append([data.copy(), datatime])
474 self.__buffer.append([data.copy(),datatime])
475 self.__profIndex += 1
475 self.__profIndex += 1
476 self.__dataReady = False
476 self.__dataReady = False
477
477
478 if self.__profIndex == self.n * self.stride :
478 if self.__profIndex == self.n * self.stride :
479 self.__dataToPutStride = True
479 self.__dataToPutStride = True
480 self.__profIndexStride = 0
480 self.__profIndexStride = 0
481 self.__profIndex = 0
481 self.__profIndex = 0
482 self.__bufferStride = []
482 self.__bufferStride = []
483 for i in range(self.stride):
483 for i in range(self.stride):
484 current = self.__buffer[i::self.stride]
484 current = self.__buffer[i::self.stride]
485 data = numpy.sum([t[0] for t in current], axis=0)
485 data = numpy.sum([t[0] for t in current], axis=0)
486 avgdatatime = numpy.average([t[1] for t in current])
486 avgdatatime = numpy.average([t[1] for t in current])
487 # print data
487 # print data
488 self.__bufferStride.append((data, avgdatatime))
488 self.__bufferStride.append((data, avgdatatime))
489
489
490 if self.__dataToPutStride:
490 if self.__dataToPutStride:
491 self.__dataReady = False
491 self.__dataReady = True
492 self.__profIndexStride += 1
492 self.__profIndexStride += 1
493 if self.__profIndexStride == self.stride:
493 if self.__profIndexStride == self.stride:
494 self.__dataReady = True
495 self.__dataToPutStride = False
494 self.__dataToPutStride = False
496 self.__profIndexStride = 0
497 # print self.__bufferStride[self.__profIndexStride - 1]
495 # print self.__bufferStride[self.__profIndexStride - 1]
498 # raise
496 # raise
499 return (numpy.sum([t[0] for t in self.__bufferStride], axis=0), numpy.average([t[1] for t in self.__bufferStride]))
497 return self.__bufferStride[self.__profIndexStride - 1]
500
498
501
499
502 return None, None
500 return None, None
503
501
504 def integrate(self, data, datatime=None):
502 def integrate(self, data, datatime=None):
505
503
506 if self.__initime == None:
504 if self.__initime == None:
507 self.__initime = datatime
505 self.__initime = datatime
508
506
509 if self.__byTime:
507 if self.__byTime:
510 avgdata = self.byTime(data, datatime)
508 avgdata = self.byTime(data, datatime)
511 else:
509 else:
512 avgdata = self.byProfiles(data)
510 avgdata = self.byProfiles(data)
513
511
514
512
515 self.__lastdatatime = datatime
513 self.__lastdatatime = datatime
516
514
517 if avgdata is None:
515 if avgdata is None:
518 return None, None
516 return None, None
519
517
520 avgdatatime = self.__initime
518 avgdatatime = self.__initime
521
519
522 deltatime = datatime - self.__lastdatatime
520 deltatime = datatime - self.__lastdatatime
523
521
524 if not self.__withOverlapping:
522 if not self.__withOverlapping:
525 self.__initime = datatime
523 self.__initime = datatime
526 else:
524 else:
527 self.__initime += deltatime
525 self.__initime += deltatime
528
526
529 return avgdata, avgdatatime
527 return avgdata, avgdatatime
530
528
531 def integrateByBlock(self, dataOut):
529 def integrateByBlock(self, dataOut):
532
530
533 times = int(dataOut.data.shape[1]/self.n)
531 times = int(dataOut.data.shape[1]/self.n)
534 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
532 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
535
533
536 id_min = 0
534 id_min = 0
537 id_max = self.n
535 id_max = self.n
538
536
539 for i in range(times):
537 for i in range(times):
540 junk = dataOut.data[:,id_min:id_max,:]
538 junk = dataOut.data[:,id_min:id_max,:]
541 avgdata[:,i,:] = junk.sum(axis=1)
539 avgdata[:,i,:] = junk.sum(axis=1)
542 id_min += self.n
540 id_min += self.n
543 id_max += self.n
541 id_max += self.n
544
542
545 timeInterval = dataOut.ippSeconds*self.n
543 timeInterval = dataOut.ippSeconds*self.n
546 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
544 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
547 self.__dataReady = True
545 self.__dataReady = True
548 return avgdata, avgdatatime
546 return avgdata, avgdatatime
549
547
550 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
548 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
551 if not self.isConfig:
549 if not self.isConfig:
552 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
550 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
553 self.isConfig = True
551 self.isConfig = True
554
552
555 if dataOut.flagDataAsBlock:
553 if dataOut.flagDataAsBlock:
556 """
554 """
557 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
555 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
558 """
556 """
559 avgdata, avgdatatime = self.integrateByBlock(dataOut)
557 avgdata, avgdatatime = self.integrateByBlock(dataOut)
560 dataOut.nProfiles /= self.n
558 dataOut.nProfiles /= self.n
561 else:
559 else:
562 if stride is None:
560 if stride is None:
563 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
561 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
564 else:
562 else:
565 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
563 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
566
564
567
565
568 # dataOut.timeInterval *= n
566 # dataOut.timeInterval *= n
569 dataOut.flagNoData = True
567 dataOut.flagNoData = True
570
568
571 if self.__dataReady:
569 if self.__dataReady:
572 dataOut.data = avgdata
570 dataOut.data = avgdata
573 dataOut.nCohInt *= self.n
571 dataOut.nCohInt *= self.n
574 dataOut.utctime = avgdatatime
572 dataOut.utctime = avgdatatime
575 # print avgdata, avgdatatime
573 # print avgdata, avgdatatime
576 # raise
574 # raise
577 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
575 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
578 dataOut.flagNoData = False
576 dataOut.flagNoData = False
579
577
580 class Decoder(Operation):
578 class Decoder(Operation):
581
579
582 isConfig = False
580 isConfig = False
583 __profIndex = 0
581 __profIndex = 0
584
582
585 code = None
583 code = None
586
584
587 nCode = None
585 nCode = None
588 nBaud = None
586 nBaud = None
589
587
590 def __init__(self, **kwargs):
588 def __init__(self, **kwargs):
591
589
592 Operation.__init__(self, **kwargs)
590 Operation.__init__(self, **kwargs)
593
591
594 self.times = None
592 self.times = None
595 self.osamp = None
593 self.osamp = None
596 # self.__setValues = False
594 # self.__setValues = False
597 self.isConfig = False
595 self.isConfig = False
598
596
599 def setup(self, code, osamp, dataOut):
597 def setup(self, code, osamp, dataOut):
600
598
601 self.__profIndex = 0
599 self.__profIndex = 0
602
600
603 self.code = code
601 self.code = code
604
602
605 self.nCode = len(code)
603 self.nCode = len(code)
606 self.nBaud = len(code[0])
604 self.nBaud = len(code[0])
607
605
608 if (osamp != None) and (osamp >1):
606 if (osamp != None) and (osamp >1):
609 self.osamp = osamp
607 self.osamp = osamp
610 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
608 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
611 self.nBaud = self.nBaud*self.osamp
609 self.nBaud = self.nBaud*self.osamp
612
610
613 self.__nChannels = dataOut.nChannels
611 self.__nChannels = dataOut.nChannels
614 self.__nProfiles = dataOut.nProfiles
612 self.__nProfiles = dataOut.nProfiles
615 self.__nHeis = dataOut.nHeights
613 self.__nHeis = dataOut.nHeights
616
614
617 if self.__nHeis < self.nBaud:
615 if self.__nHeis < self.nBaud:
618 raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)
616 raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)
619
617
620 #Frequency
618 #Frequency
621 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
619 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
622
620
623 __codeBuffer[:,0:self.nBaud] = self.code
621 __codeBuffer[:,0:self.nBaud] = self.code
624
622
625 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
623 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
626
624
627 if dataOut.flagDataAsBlock:
625 if dataOut.flagDataAsBlock:
628
626
629 self.ndatadec = self.__nHeis #- self.nBaud + 1
627 self.ndatadec = self.__nHeis #- self.nBaud + 1
630
628
631 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
629 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
632
630
633 else:
631 else:
634
632
635 #Time
633 #Time
636 self.ndatadec = self.__nHeis #- self.nBaud + 1
634 self.ndatadec = self.__nHeis #- self.nBaud + 1
637
635
638 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
636 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
639
637
640 def __convolutionInFreq(self, data):
638 def __convolutionInFreq(self, data):
641
639
642 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
640 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
643
641
644 fft_data = numpy.fft.fft(data, axis=1)
642 fft_data = numpy.fft.fft(data, axis=1)
645
643
646 conv = fft_data*fft_code
644 conv = fft_data*fft_code
647
645
648 data = numpy.fft.ifft(conv,axis=1)
646 data = numpy.fft.ifft(conv,axis=1)
649
647
650 return data
648 return data
651
649
652 def __convolutionInFreqOpt(self, data):
650 def __convolutionInFreqOpt(self, data):
653
651
654 raise NotImplementedError
652 raise NotImplementedError
655
653
656 def __convolutionInTime(self, data):
654 def __convolutionInTime(self, data):
657
655
658 code = self.code[self.__profIndex]
656 code = self.code[self.__profIndex]
659 for i in range(self.__nChannels):
657 for i in range(self.__nChannels):
660 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
658 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
661
659
662 return self.datadecTime
660 return self.datadecTime
663
661
664 def __convolutionByBlockInTime(self, data):
662 def __convolutionByBlockInTime(self, data):
665
663
666 repetitions = self.__nProfiles / self.nCode
664 repetitions = self.__nProfiles / self.nCode
667
665
668 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
666 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
669 junk = junk.flatten()
667 junk = junk.flatten()
670 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
668 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
671 profilesList = xrange(self.__nProfiles)
669 profilesList = xrange(self.__nProfiles)
672
670
673 for i in range(self.__nChannels):
671 for i in range(self.__nChannels):
674 for j in profilesList:
672 for j in profilesList:
675 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
673 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
676 return self.datadecTime
674 return self.datadecTime
677
675
678 def __convolutionByBlockInFreq(self, data):
676 def __convolutionByBlockInFreq(self, data):
679
677
680 raise NotImplementedError, "Decoder by frequency fro Blocks not implemented"
678 raise NotImplementedError, "Decoder by frequency fro Blocks not implemented"
681
679
682
680
683 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
681 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
684
682
685 fft_data = numpy.fft.fft(data, axis=2)
683 fft_data = numpy.fft.fft(data, axis=2)
686
684
687 conv = fft_data*fft_code
685 conv = fft_data*fft_code
688
686
689 data = numpy.fft.ifft(conv,axis=2)
687 data = numpy.fft.ifft(conv,axis=2)
690
688
691 return data
689 return data
692
690
693
691
694 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
692 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
695
693
696 if dataOut.flagDecodeData:
694 if dataOut.flagDecodeData:
697 print "This data is already decoded, recoding again ..."
695 print "This data is already decoded, recoding again ..."
698
696
699 if not self.isConfig:
697 if not self.isConfig:
700
698
701 if code is None:
699 if code is None:
702 if dataOut.code is None:
700 if dataOut.code is None:
703 raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type
701 raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type
704
702
705 code = dataOut.code
703 code = dataOut.code
706 else:
704 else:
707 code = numpy.array(code).reshape(nCode,nBaud)
705 code = numpy.array(code).reshape(nCode,nBaud)
708 self.setup(code, osamp, dataOut)
706 self.setup(code, osamp, dataOut)
709
707
710 self.isConfig = True
708 self.isConfig = True
711
709
712 if mode == 3:
710 if mode == 3:
713 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
711 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
714
712
715 if times != None:
713 if times != None:
716 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
714 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
717
715
718 if self.code is None:
716 if self.code is None:
719 print "Fail decoding: Code is not defined."
717 print "Fail decoding: Code is not defined."
720 return
718 return
721
719
722 self.__nProfiles = dataOut.nProfiles
720 self.__nProfiles = dataOut.nProfiles
723 datadec = None
721 datadec = None
724
722
725 if mode == 3:
723 if mode == 3:
726 mode = 0
724 mode = 0
727
725
728 if dataOut.flagDataAsBlock:
726 if dataOut.flagDataAsBlock:
729 """
727 """
730 Decoding when data have been read as block,
728 Decoding when data have been read as block,
731 """
729 """
732
730
733 if mode == 0:
731 if mode == 0:
734 datadec = self.__convolutionByBlockInTime(dataOut.data)
732 datadec = self.__convolutionByBlockInTime(dataOut.data)
735 if mode == 1:
733 if mode == 1:
736 datadec = self.__convolutionByBlockInFreq(dataOut.data)
734 datadec = self.__convolutionByBlockInFreq(dataOut.data)
737 else:
735 else:
738 """
736 """
739 Decoding when data have been read profile by profile
737 Decoding when data have been read profile by profile
740 """
738 """
741 if mode == 0:
739 if mode == 0:
742 datadec = self.__convolutionInTime(dataOut.data)
740 datadec = self.__convolutionInTime(dataOut.data)
743
741
744 if mode == 1:
742 if mode == 1:
745 datadec = self.__convolutionInFreq(dataOut.data)
743 datadec = self.__convolutionInFreq(dataOut.data)
746
744
747 if mode == 2:
745 if mode == 2:
748 datadec = self.__convolutionInFreqOpt(dataOut.data)
746 datadec = self.__convolutionInFreqOpt(dataOut.data)
749
747
750 if datadec is None:
748 if datadec is None:
751 raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode
749 raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode
752
750
753 dataOut.code = self.code
751 dataOut.code = self.code
754 dataOut.nCode = self.nCode
752 dataOut.nCode = self.nCode
755 dataOut.nBaud = self.nBaud
753 dataOut.nBaud = self.nBaud
756
754
757 dataOut.data = datadec
755 dataOut.data = datadec
758
756
759 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
757 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
760
758
761 dataOut.flagDecodeData = True #asumo q la data esta decodificada
759 dataOut.flagDecodeData = True #asumo q la data esta decodificada
762
760
763 if self.__profIndex == self.nCode-1:
761 if self.__profIndex == self.nCode-1:
764 self.__profIndex = 0
762 self.__profIndex = 0
765 return 1
763 return 1
766
764
767 self.__profIndex += 1
765 self.__profIndex += 1
768
766
769 return 1
767 return 1
770 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
768 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
771
769
772
770
773 class ProfileConcat(Operation):
771 class ProfileConcat(Operation):
774
772
775 isConfig = False
773 isConfig = False
776 buffer = None
774 buffer = None
777
775
778 def __init__(self, **kwargs):
776 def __init__(self, **kwargs):
779
777
780 Operation.__init__(self, **kwargs)
778 Operation.__init__(self, **kwargs)
781 self.profileIndex = 0
779 self.profileIndex = 0
782
780
783 def reset(self):
781 def reset(self):
784 self.buffer = numpy.zeros_like(self.buffer)
782 self.buffer = numpy.zeros_like(self.buffer)
785 self.start_index = 0
783 self.start_index = 0
786 self.times = 1
784 self.times = 1
787
785
788 def setup(self, data, m, n=1):
786 def setup(self, data, m, n=1):
789 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
787 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
790 self.nHeights = data.shape[1]#.nHeights
788 self.nHeights = data.shape[1]#.nHeights
791 self.start_index = 0
789 self.start_index = 0
792 self.times = 1
790 self.times = 1
793
791
794 def concat(self, data):
792 def concat(self, data):
795
793
796 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
794 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
797 self.start_index = self.start_index + self.nHeights
795 self.start_index = self.start_index + self.nHeights
798
796
799 def run(self, dataOut, m):
797 def run(self, dataOut, m):
800
798
801 dataOut.flagNoData = True
799 dataOut.flagNoData = True
802
800
803 if not self.isConfig:
801 if not self.isConfig:
804 self.setup(dataOut.data, m, 1)
802 self.setup(dataOut.data, m, 1)
805 self.isConfig = True
803 self.isConfig = True
806
804
807 if dataOut.flagDataAsBlock:
805 if dataOut.flagDataAsBlock:
808 raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False"
806 raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False"
809
807
810 else:
808 else:
811 self.concat(dataOut.data)
809 self.concat(dataOut.data)
812 self.times += 1
810 self.times += 1
813 if self.times > m:
811 if self.times > m:
814 dataOut.data = self.buffer
812 dataOut.data = self.buffer
815 self.reset()
813 self.reset()
816 dataOut.flagNoData = False
814 dataOut.flagNoData = False
817 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
815 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
818 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
816 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
819 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
817 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
820 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
818 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
821 dataOut.ippSeconds *= m
819 dataOut.ippSeconds *= m
822
820
823 class ProfileSelector(Operation):
821 class ProfileSelector(Operation):
824
822
825 profileIndex = None
823 profileIndex = None
826 # Tamanho total de los perfiles
824 # Tamanho total de los perfiles
827 nProfiles = None
825 nProfiles = None
828
826
829 def __init__(self, **kwargs):
827 def __init__(self, **kwargs):
830
828
831 Operation.__init__(self, **kwargs)
829 Operation.__init__(self, **kwargs)
832 self.profileIndex = 0
830 self.profileIndex = 0
833
831
834 def incProfileIndex(self):
832 def incProfileIndex(self):
835
833
836 self.profileIndex += 1
834 self.profileIndex += 1
837
835
838 if self.profileIndex >= self.nProfiles:
836 if self.profileIndex >= self.nProfiles:
839 self.profileIndex = 0
837 self.profileIndex = 0
840
838
841 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
839 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
842
840
843 if profileIndex < minIndex:
841 if profileIndex < minIndex:
844 return False
842 return False
845
843
846 if profileIndex > maxIndex:
844 if profileIndex > maxIndex:
847 return False
845 return False
848
846
849 return True
847 return True
850
848
851 def isThisProfileInList(self, profileIndex, profileList):
849 def isThisProfileInList(self, profileIndex, profileList):
852
850
853 if profileIndex not in profileList:
851 if profileIndex not in profileList:
854 return False
852 return False
855
853
856 return True
854 return True
857
855
858 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
856 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
859
857
860 """
858 """
861 ProfileSelector:
859 ProfileSelector:
862
860
863 Inputs:
861 Inputs:
864 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
862 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
865
863
866 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
864 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
867
865
868 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
866 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
869
867
870 """
868 """
871
869
872 if rangeList is not None:
870 if rangeList is not None:
873 if type(rangeList[0]) not in (tuple, list):
871 if type(rangeList[0]) not in (tuple, list):
874 rangeList = [rangeList]
872 rangeList = [rangeList]
875
873
876 dataOut.flagNoData = True
874 dataOut.flagNoData = True
877
875
878 if dataOut.flagDataAsBlock:
876 if dataOut.flagDataAsBlock:
879 """
877 """
880 data dimension = [nChannels, nProfiles, nHeis]
878 data dimension = [nChannels, nProfiles, nHeis]
881 """
879 """
882 if profileList != None:
880 if profileList != None:
883 dataOut.data = dataOut.data[:,profileList,:]
881 dataOut.data = dataOut.data[:,profileList,:]
884
882
885 if profileRangeList != None:
883 if profileRangeList != None:
886 minIndex = profileRangeList[0]
884 minIndex = profileRangeList[0]
887 maxIndex = profileRangeList[1]
885 maxIndex = profileRangeList[1]
888 profileList = range(minIndex, maxIndex+1)
886 profileList = range(minIndex, maxIndex+1)
889
887
890 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
888 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
891
889
892 if rangeList != None:
890 if rangeList != None:
893
891
894 profileList = []
892 profileList = []
895
893
896 for thisRange in rangeList:
894 for thisRange in rangeList:
897 minIndex = thisRange[0]
895 minIndex = thisRange[0]
898 maxIndex = thisRange[1]
896 maxIndex = thisRange[1]
899
897
900 profileList.extend(range(minIndex, maxIndex+1))
898 profileList.extend(range(minIndex, maxIndex+1))
901
899
902 dataOut.data = dataOut.data[:,profileList,:]
900 dataOut.data = dataOut.data[:,profileList,:]
903
901
904 dataOut.nProfiles = len(profileList)
902 dataOut.nProfiles = len(profileList)
905 dataOut.profileIndex = dataOut.nProfiles - 1
903 dataOut.profileIndex = dataOut.nProfiles - 1
906 dataOut.flagNoData = False
904 dataOut.flagNoData = False
907
905
908 return True
906 return True
909
907
910 """
908 """
911 data dimension = [nChannels, nHeis]
909 data dimension = [nChannels, nHeis]
912 """
910 """
913
911
914 if profileList != None:
912 if profileList != None:
915
913
916 if self.isThisProfileInList(dataOut.profileIndex, profileList):
914 if self.isThisProfileInList(dataOut.profileIndex, profileList):
917
915
918 self.nProfiles = len(profileList)
916 self.nProfiles = len(profileList)
919 dataOut.nProfiles = self.nProfiles
917 dataOut.nProfiles = self.nProfiles
920 dataOut.profileIndex = self.profileIndex
918 dataOut.profileIndex = self.profileIndex
921 dataOut.flagNoData = False
919 dataOut.flagNoData = False
922
920
923 self.incProfileIndex()
921 self.incProfileIndex()
924 return True
922 return True
925
923
926 if profileRangeList != None:
924 if profileRangeList != None:
927
925
928 minIndex = profileRangeList[0]
926 minIndex = profileRangeList[0]
929 maxIndex = profileRangeList[1]
927 maxIndex = profileRangeList[1]
930
928
931 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
929 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
932
930
933 self.nProfiles = maxIndex - minIndex + 1
931 self.nProfiles = maxIndex - minIndex + 1
934 dataOut.nProfiles = self.nProfiles
932 dataOut.nProfiles = self.nProfiles
935 dataOut.profileIndex = self.profileIndex
933 dataOut.profileIndex = self.profileIndex
936 dataOut.flagNoData = False
934 dataOut.flagNoData = False
937
935
938 self.incProfileIndex()
936 self.incProfileIndex()
939 return True
937 return True
940
938
941 if rangeList != None:
939 if rangeList != None:
942
940
943 nProfiles = 0
941 nProfiles = 0
944
942
945 for thisRange in rangeList:
943 for thisRange in rangeList:
946 minIndex = thisRange[0]
944 minIndex = thisRange[0]
947 maxIndex = thisRange[1]
945 maxIndex = thisRange[1]
948
946
949 nProfiles += maxIndex - minIndex + 1
947 nProfiles += maxIndex - minIndex + 1
950
948
951 for thisRange in rangeList:
949 for thisRange in rangeList:
952
950
953 minIndex = thisRange[0]
951 minIndex = thisRange[0]
954 maxIndex = thisRange[1]
952 maxIndex = thisRange[1]
955
953
956 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
954 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
957
955
958 self.nProfiles = nProfiles
956 self.nProfiles = nProfiles
959 dataOut.nProfiles = self.nProfiles
957 dataOut.nProfiles = self.nProfiles
960 dataOut.profileIndex = self.profileIndex
958 dataOut.profileIndex = self.profileIndex
961 dataOut.flagNoData = False
959 dataOut.flagNoData = False
962
960
963 self.incProfileIndex()
961 self.incProfileIndex()
964
962
965 break
963 break
966
964
967 return True
965 return True
968
966
969
967
970 if beam != None: #beam is only for AMISR data
968 if beam != None: #beam is only for AMISR data
971 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
969 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
972 dataOut.flagNoData = False
970 dataOut.flagNoData = False
973 dataOut.profileIndex = self.profileIndex
971 dataOut.profileIndex = self.profileIndex
974
972
975 self.incProfileIndex()
973 self.incProfileIndex()
976
974
977 return True
975 return True
978
976
979 raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter"
977 raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter"
980
978
981 return False
979 return False
982
980
983 class Reshaper(Operation):
981 class Reshaper(Operation):
984
982
985 def __init__(self, **kwargs):
983 def __init__(self, **kwargs):
986
984
987 Operation.__init__(self, **kwargs)
985 Operation.__init__(self, **kwargs)
988
986
989 self.__buffer = None
987 self.__buffer = None
990 self.__nitems = 0
988 self.__nitems = 0
991
989
992 def __appendProfile(self, dataOut, nTxs):
990 def __appendProfile(self, dataOut, nTxs):
993
991
994 if self.__buffer is None:
992 if self.__buffer is None:
995 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
993 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
996 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
994 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
997
995
998 ini = dataOut.nHeights * self.__nitems
996 ini = dataOut.nHeights * self.__nitems
999 end = ini + dataOut.nHeights
997 end = ini + dataOut.nHeights
1000
998
1001 self.__buffer[:, ini:end] = dataOut.data
999 self.__buffer[:, ini:end] = dataOut.data
1002
1000
1003 self.__nitems += 1
1001 self.__nitems += 1
1004
1002
1005 return int(self.__nitems*nTxs)
1003 return int(self.__nitems*nTxs)
1006
1004
1007 def __getBuffer(self):
1005 def __getBuffer(self):
1008
1006
1009 if self.__nitems == int(1./self.__nTxs):
1007 if self.__nitems == int(1./self.__nTxs):
1010
1008
1011 self.__nitems = 0
1009 self.__nitems = 0
1012
1010
1013 return self.__buffer.copy()
1011 return self.__buffer.copy()
1014
1012
1015 return None
1013 return None
1016
1014
1017 def __checkInputs(self, dataOut, shape, nTxs):
1015 def __checkInputs(self, dataOut, shape, nTxs):
1018
1016
1019 if shape is None and nTxs is None:
1017 if shape is None and nTxs is None:
1020 raise ValueError, "Reshaper: shape of factor should be defined"
1018 raise ValueError, "Reshaper: shape of factor should be defined"
1021
1019
1022 if nTxs:
1020 if nTxs:
1023 if nTxs < 0:
1021 if nTxs < 0:
1024 raise ValueError, "nTxs should be greater than 0"
1022 raise ValueError, "nTxs should be greater than 0"
1025
1023
1026 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1024 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1027 raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))
1025 raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))
1028
1026
1029 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1027 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1030
1028
1031 return shape, nTxs
1029 return shape, nTxs
1032
1030
1033 if len(shape) != 2 and len(shape) != 3:
1031 if len(shape) != 2 and len(shape) != 3:
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)
1032 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)
1035
1033
1036 if len(shape) == 2:
1034 if len(shape) == 2:
1037 shape_tuple = [dataOut.nChannels]
1035 shape_tuple = [dataOut.nChannels]
1038 shape_tuple.extend(shape)
1036 shape_tuple.extend(shape)
1039 else:
1037 else:
1040 shape_tuple = list(shape)
1038 shape_tuple = list(shape)
1041
1039
1042 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1040 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1043
1041
1044 return shape_tuple, nTxs
1042 return shape_tuple, nTxs
1045
1043
1046 def run(self, dataOut, shape=None, nTxs=None):
1044 def run(self, dataOut, shape=None, nTxs=None):
1047
1045
1048 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1046 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1049
1047
1050 dataOut.flagNoData = True
1048 dataOut.flagNoData = True
1051 profileIndex = None
1049 profileIndex = None
1052
1050
1053 if dataOut.flagDataAsBlock:
1051 if dataOut.flagDataAsBlock:
1054
1052
1055 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1053 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1056 dataOut.flagNoData = False
1054 dataOut.flagNoData = False
1057
1055
1058 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1056 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1059
1057
1060 else:
1058 else:
1061
1059
1062 if self.__nTxs < 1:
1060 if self.__nTxs < 1:
1063
1061
1064 self.__appendProfile(dataOut, self.__nTxs)
1062 self.__appendProfile(dataOut, self.__nTxs)
1065 new_data = self.__getBuffer()
1063 new_data = self.__getBuffer()
1066
1064
1067 if new_data is not None:
1065 if new_data is not None:
1068 dataOut.data = new_data
1066 dataOut.data = new_data
1069 dataOut.flagNoData = False
1067 dataOut.flagNoData = False
1070
1068
1071 profileIndex = dataOut.profileIndex*nTxs
1069 profileIndex = dataOut.profileIndex*nTxs
1072
1070
1073 else:
1071 else:
1074 raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)"
1072 raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)"
1075
1073
1076 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1074 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1077
1075
1078 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1076 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1079
1077
1080 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1078 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1081
1079
1082 dataOut.profileIndex = profileIndex
1080 dataOut.profileIndex = profileIndex
1083
1081
1084 dataOut.ippSeconds /= self.__nTxs
1082 dataOut.ippSeconds /= self.__nTxs
1085
1083
1086 class SplitProfiles(Operation):
1084 class SplitProfiles(Operation):
1087
1085
1088 def __init__(self, **kwargs):
1086 def __init__(self, **kwargs):
1089
1087
1090 Operation.__init__(self, **kwargs)
1088 Operation.__init__(self, **kwargs)
1091
1089
1092 def run(self, dataOut, n):
1090 def run(self, dataOut, n):
1093
1091
1094 dataOut.flagNoData = True
1092 dataOut.flagNoData = True
1095 profileIndex = None
1093 profileIndex = None
1096
1094
1097 if dataOut.flagDataAsBlock:
1095 if dataOut.flagDataAsBlock:
1098
1096
1099 #nchannels, nprofiles, nsamples
1097 #nchannels, nprofiles, nsamples
1100 shape = dataOut.data.shape
1098 shape = dataOut.data.shape
1101
1099
1102 if shape[2] % n != 0:
1100 if shape[2] % n != 0:
1103 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])
1101 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])
1104
1102
1105 new_shape = shape[0], shape[1]*n, shape[2]/n
1103 new_shape = shape[0], shape[1]*n, shape[2]/n
1106
1104
1107 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1105 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1108 dataOut.flagNoData = False
1106 dataOut.flagNoData = False
1109
1107
1110 profileIndex = int(dataOut.nProfiles/n) - 1
1108 profileIndex = int(dataOut.nProfiles/n) - 1
1111
1109
1112 else:
1110 else:
1113
1111
1114 raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)"
1112 raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)"
1115
1113
1116 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1114 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1117
1115
1118 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1116 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1119
1117
1120 dataOut.nProfiles = int(dataOut.nProfiles*n)
1118 dataOut.nProfiles = int(dataOut.nProfiles*n)
1121
1119
1122 dataOut.profileIndex = profileIndex
1120 dataOut.profileIndex = profileIndex
1123
1121
1124 dataOut.ippSeconds /= n
1122 dataOut.ippSeconds /= n
1125
1123
1126 class CombineProfiles(Operation):
1124 class CombineProfiles(Operation):
1127 def __init__(self, **kwargs):
1125 def __init__(self, **kwargs):
1128
1126
1129 Operation.__init__(self, **kwargs)
1127 Operation.__init__(self, **kwargs)
1130
1128
1131 self.__remData = None
1129 self.__remData = None
1132 self.__profileIndex = 0
1130 self.__profileIndex = 0
1133
1131
1134 def run(self, dataOut, n):
1132 def run(self, dataOut, n):
1135
1133
1136 dataOut.flagNoData = True
1134 dataOut.flagNoData = True
1137 profileIndex = None
1135 profileIndex = None
1138
1136
1139 if dataOut.flagDataAsBlock:
1137 if dataOut.flagDataAsBlock:
1140
1138
1141 #nchannels, nprofiles, nsamples
1139 #nchannels, nprofiles, nsamples
1142 shape = dataOut.data.shape
1140 shape = dataOut.data.shape
1143 new_shape = shape[0], shape[1]/n, shape[2]*n
1141 new_shape = shape[0], shape[1]/n, shape[2]*n
1144
1142
1145 if shape[1] % n != 0:
1143 if shape[1] % n != 0:
1146 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])
1144 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])
1147
1145
1148 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1146 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1149 dataOut.flagNoData = False
1147 dataOut.flagNoData = False
1150
1148
1151 profileIndex = int(dataOut.nProfiles*n) - 1
1149 profileIndex = int(dataOut.nProfiles*n) - 1
1152
1150
1153 else:
1151 else:
1154
1152
1155 #nchannels, nsamples
1153 #nchannels, nsamples
1156 if self.__remData is None:
1154 if self.__remData is None:
1157 newData = dataOut.data
1155 newData = dataOut.data
1158 else:
1156 else:
1159 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1157 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1160
1158
1161 self.__profileIndex += 1
1159 self.__profileIndex += 1
1162
1160
1163 if self.__profileIndex < n:
1161 if self.__profileIndex < n:
1164 self.__remData = newData
1162 self.__remData = newData
1165 #continue
1163 #continue
1166 return
1164 return
1167
1165
1168 self.__profileIndex = 0
1166 self.__profileIndex = 0
1169 self.__remData = None
1167 self.__remData = None
1170
1168
1171 dataOut.data = newData
1169 dataOut.data = newData
1172 dataOut.flagNoData = False
1170 dataOut.flagNoData = False
1173
1171
1174 profileIndex = dataOut.profileIndex/n
1172 profileIndex = dataOut.profileIndex/n
1175
1173
1176
1174
1177 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1175 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1178
1176
1179 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1177 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1180
1178
1181 dataOut.nProfiles = int(dataOut.nProfiles/n)
1179 dataOut.nProfiles = int(dataOut.nProfiles/n)
1182
1180
1183 dataOut.profileIndex = profileIndex
1181 dataOut.profileIndex = profileIndex
1184
1182
1185 dataOut.ippSeconds *= n
1183 dataOut.ippSeconds *= n
1186
1184
1187 # import collections
1185 # import collections
1188 # from scipy.stats import mode
1186 # from scipy.stats import mode
1189 #
1187 #
1190 # class Synchronize(Operation):
1188 # class Synchronize(Operation):
1191 #
1189 #
1192 # isConfig = False
1190 # isConfig = False
1193 # __profIndex = 0
1191 # __profIndex = 0
1194 #
1192 #
1195 # def __init__(self, **kwargs):
1193 # def __init__(self, **kwargs):
1196 #
1194 #
1197 # Operation.__init__(self, **kwargs)
1195 # Operation.__init__(self, **kwargs)
1198 # # self.isConfig = False
1196 # # self.isConfig = False
1199 # self.__powBuffer = None
1197 # self.__powBuffer = None
1200 # self.__startIndex = 0
1198 # self.__startIndex = 0
1201 # self.__pulseFound = False
1199 # self.__pulseFound = False
1202 #
1200 #
1203 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1201 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1204 #
1202 #
1205 # #Read data
1203 # #Read data
1206 #
1204 #
1207 # powerdB = dataOut.getPower(channel = channel)
1205 # powerdB = dataOut.getPower(channel = channel)
1208 # noisedB = dataOut.getNoise(channel = channel)[0]
1206 # noisedB = dataOut.getNoise(channel = channel)[0]
1209 #
1207 #
1210 # self.__powBuffer.extend(powerdB.flatten())
1208 # self.__powBuffer.extend(powerdB.flatten())
1211 #
1209 #
1212 # dataArray = numpy.array(self.__powBuffer)
1210 # dataArray = numpy.array(self.__powBuffer)
1213 #
1211 #
1214 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1212 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1215 #
1213 #
1216 # maxValue = numpy.nanmax(filteredPower)
1214 # maxValue = numpy.nanmax(filteredPower)
1217 #
1215 #
1218 # if maxValue < noisedB + 10:
1216 # if maxValue < noisedB + 10:
1219 # #No se encuentra ningun pulso de transmision
1217 # #No se encuentra ningun pulso de transmision
1220 # return None
1218 # return None
1221 #
1219 #
1222 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1220 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1223 #
1221 #
1224 # if len(maxValuesIndex) < 2:
1222 # if len(maxValuesIndex) < 2:
1225 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1223 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1226 # return None
1224 # return None
1227 #
1225 #
1228 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1226 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1229 #
1227 #
1230 # #Seleccionar solo valores con un espaciamiento de nSamples
1228 # #Seleccionar solo valores con un espaciamiento de nSamples
1231 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1229 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1232 #
1230 #
1233 # if len(pulseIndex) < 2:
1231 # if len(pulseIndex) < 2:
1234 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1232 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1235 # return None
1233 # return None
1236 #
1234 #
1237 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1235 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1238 #
1236 #
1239 # #remover senales que se distancien menos de 10 unidades o muestras
1237 # #remover senales que se distancien menos de 10 unidades o muestras
1240 # #(No deberian existir IPP menor a 10 unidades)
1238 # #(No deberian existir IPP menor a 10 unidades)
1241 #
1239 #
1242 # realIndex = numpy.where(spacing > 10 )[0]
1240 # realIndex = numpy.where(spacing > 10 )[0]
1243 #
1241 #
1244 # if len(realIndex) < 2:
1242 # if len(realIndex) < 2:
1245 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1243 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1246 # return None
1244 # return None
1247 #
1245 #
1248 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1246 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1249 # realPulseIndex = pulseIndex[realIndex]
1247 # realPulseIndex = pulseIndex[realIndex]
1250 #
1248 #
1251 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1249 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1252 #
1250 #
1253 # print "IPP = %d samples" %period
1251 # print "IPP = %d samples" %period
1254 #
1252 #
1255 # self.__newNSamples = dataOut.nHeights #int(period)
1253 # self.__newNSamples = dataOut.nHeights #int(period)
1256 # self.__startIndex = int(realPulseIndex[0])
1254 # self.__startIndex = int(realPulseIndex[0])
1257 #
1255 #
1258 # return 1
1256 # return 1
1259 #
1257 #
1260 #
1258 #
1261 # def setup(self, nSamples, nChannels, buffer_size = 4):
1259 # def setup(self, nSamples, nChannels, buffer_size = 4):
1262 #
1260 #
1263 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1261 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1264 # maxlen = buffer_size*nSamples)
1262 # maxlen = buffer_size*nSamples)
1265 #
1263 #
1266 # bufferList = []
1264 # bufferList = []
1267 #
1265 #
1268 # for i in range(nChannels):
1266 # for i in range(nChannels):
1269 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1267 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1270 # maxlen = buffer_size*nSamples)
1268 # maxlen = buffer_size*nSamples)
1271 #
1269 #
1272 # bufferList.append(bufferByChannel)
1270 # bufferList.append(bufferByChannel)
1273 #
1271 #
1274 # self.__nSamples = nSamples
1272 # self.__nSamples = nSamples
1275 # self.__nChannels = nChannels
1273 # self.__nChannels = nChannels
1276 # self.__bufferList = bufferList
1274 # self.__bufferList = bufferList
1277 #
1275 #
1278 # def run(self, dataOut, channel = 0):
1276 # def run(self, dataOut, channel = 0):
1279 #
1277 #
1280 # if not self.isConfig:
1278 # if not self.isConfig:
1281 # nSamples = dataOut.nHeights
1279 # nSamples = dataOut.nHeights
1282 # nChannels = dataOut.nChannels
1280 # nChannels = dataOut.nChannels
1283 # self.setup(nSamples, nChannels)
1281 # self.setup(nSamples, nChannels)
1284 # self.isConfig = True
1282 # self.isConfig = True
1285 #
1283 #
1286 # #Append new data to internal buffer
1284 # #Append new data to internal buffer
1287 # for thisChannel in range(self.__nChannels):
1285 # for thisChannel in range(self.__nChannels):
1288 # bufferByChannel = self.__bufferList[thisChannel]
1286 # bufferByChannel = self.__bufferList[thisChannel]
1289 # bufferByChannel.extend(dataOut.data[thisChannel])
1287 # bufferByChannel.extend(dataOut.data[thisChannel])
1290 #
1288 #
1291 # if self.__pulseFound:
1289 # if self.__pulseFound:
1292 # self.__startIndex -= self.__nSamples
1290 # self.__startIndex -= self.__nSamples
1293 #
1291 #
1294 # #Finding Tx Pulse
1292 # #Finding Tx Pulse
1295 # if not self.__pulseFound:
1293 # if not self.__pulseFound:
1296 # indexFound = self.__findTxPulse(dataOut, channel)
1294 # indexFound = self.__findTxPulse(dataOut, channel)
1297 #
1295 #
1298 # if indexFound == None:
1296 # if indexFound == None:
1299 # dataOut.flagNoData = True
1297 # dataOut.flagNoData = True
1300 # return
1298 # return
1301 #
1299 #
1302 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1300 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1303 # self.__pulseFound = True
1301 # self.__pulseFound = True
1304 # self.__startIndex = indexFound
1302 # self.__startIndex = indexFound
1305 #
1303 #
1306 # #If pulse was found ...
1304 # #If pulse was found ...
1307 # for thisChannel in range(self.__nChannels):
1305 # for thisChannel in range(self.__nChannels):
1308 # bufferByChannel = self.__bufferList[thisChannel]
1306 # bufferByChannel = self.__bufferList[thisChannel]
1309 # #print self.__startIndex
1307 # #print self.__startIndex
1310 # x = numpy.array(bufferByChannel)
1308 # x = numpy.array(bufferByChannel)
1311 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1309 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1312 #
1310 #
1313 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1311 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1314 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1312 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1315 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1313 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1316 #
1314 #
1317 # dataOut.data = self.__arrayBuffer
1315 # dataOut.data = self.__arrayBuffer
1318 #
1316 #
1319 # self.__startIndex += self.__newNSamples
1317 # self.__startIndex += self.__newNSamples
1320 #
1318 #
1321 # return
1319 # return
General Comments 0
You need to be logged in to leave comments. Login now