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