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