##// END OF EJS Templates
Bug fixed in Reshaper: factor variable should be a real value
Miguel Valdez -
r522:b46cf7c20599
parent child
Show More
@@ -1,758 +1,762
1 import numpy
1 import numpy
2
2
3 from jroproc_base import ProcessingUnit, Operation
3 from jroproc_base import ProcessingUnit, Operation
4 from model.data.jrodata import Voltage
4 from 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 index = self.dataOut.channelList.index(channel)
70 index = self.dataOut.channelList.index(channel)
71 channelIndexList.append(index)
71 channelIndexList.append(index)
72
72
73 self.selectChannelsByIndex(channelIndexList)
73 self.selectChannelsByIndex(channelIndexList)
74
74
75 def selectChannelsByIndex(self, channelIndexList):
75 def selectChannelsByIndex(self, channelIndexList):
76 """
76 """
77 Selecciona un bloque de datos en base a canales segun el channelIndexList
77 Selecciona un bloque de datos en base a canales segun el channelIndexList
78
78
79 Input:
79 Input:
80 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
80 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
81
81
82 Affected:
82 Affected:
83 self.dataOut.data
83 self.dataOut.data
84 self.dataOut.channelIndexList
84 self.dataOut.channelIndexList
85 self.dataOut.nChannels
85 self.dataOut.nChannels
86 self.dataOut.m_ProcessingHeader.totalSpectra
86 self.dataOut.m_ProcessingHeader.totalSpectra
87 self.dataOut.systemHeaderObj.numChannels
87 self.dataOut.systemHeaderObj.numChannels
88 self.dataOut.m_ProcessingHeader.blockSize
88 self.dataOut.m_ProcessingHeader.blockSize
89
89
90 Return:
90 Return:
91 None
91 None
92 """
92 """
93
93
94 for channelIndex in channelIndexList:
94 for channelIndex in channelIndexList:
95 if channelIndex not in self.dataOut.channelIndexList:
95 if channelIndex not in self.dataOut.channelIndexList:
96 print channelIndexList
96 print channelIndexList
97 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
97 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
98
98
99 # nChannels = len(channelIndexList)
99 # nChannels = len(channelIndexList)
100
100
101 data = self.dataOut.data[channelIndexList,:]
101 data = self.dataOut.data[channelIndexList,:]
102
102
103 self.dataOut.data = data
103 self.dataOut.data = data
104 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
104 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
105 # self.dataOut.nChannels = nChannels
105 # self.dataOut.nChannels = nChannels
106
106
107 return 1
107 return 1
108
108
109 def selectHeights(self, minHei=None, maxHei=None):
109 def selectHeights(self, minHei=None, maxHei=None):
110 """
110 """
111 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
111 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
112 minHei <= height <= maxHei
112 minHei <= height <= maxHei
113
113
114 Input:
114 Input:
115 minHei : valor minimo de altura a considerar
115 minHei : valor minimo de altura a considerar
116 maxHei : valor maximo de altura a considerar
116 maxHei : valor maximo de altura a considerar
117
117
118 Affected:
118 Affected:
119 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
119 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
120
120
121 Return:
121 Return:
122 1 si el metodo se ejecuto con exito caso contrario devuelve 0
122 1 si el metodo se ejecuto con exito caso contrario devuelve 0
123 """
123 """
124
124
125 if minHei == None:
125 if minHei == None:
126 minHei = self.dataOut.heightList[0]
126 minHei = self.dataOut.heightList[0]
127
127
128 if maxHei == None:
128 if maxHei == None:
129 maxHei = self.dataOut.heightList[-1]
129 maxHei = self.dataOut.heightList[-1]
130
130
131 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
131 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
132 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
132 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
133
133
134
134
135 if (maxHei > self.dataOut.heightList[-1]):
135 if (maxHei > self.dataOut.heightList[-1]):
136 maxHei = self.dataOut.heightList[-1]
136 maxHei = self.dataOut.heightList[-1]
137 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
137 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
138
138
139 minIndex = 0
139 minIndex = 0
140 maxIndex = 0
140 maxIndex = 0
141 heights = self.dataOut.heightList
141 heights = self.dataOut.heightList
142
142
143 inda = numpy.where(heights >= minHei)
143 inda = numpy.where(heights >= minHei)
144 indb = numpy.where(heights <= maxHei)
144 indb = numpy.where(heights <= maxHei)
145
145
146 try:
146 try:
147 minIndex = inda[0][0]
147 minIndex = inda[0][0]
148 except:
148 except:
149 minIndex = 0
149 minIndex = 0
150
150
151 try:
151 try:
152 maxIndex = indb[0][-1]
152 maxIndex = indb[0][-1]
153 except:
153 except:
154 maxIndex = len(heights)
154 maxIndex = len(heights)
155
155
156 self.selectHeightsByIndex(minIndex, maxIndex)
156 self.selectHeightsByIndex(minIndex, maxIndex)
157
157
158 return 1
158 return 1
159
159
160
160
161 def selectHeightsByIndex(self, minIndex, maxIndex):
161 def selectHeightsByIndex(self, minIndex, maxIndex):
162 """
162 """
163 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
163 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
164 minIndex <= index <= maxIndex
164 minIndex <= index <= maxIndex
165
165
166 Input:
166 Input:
167 minIndex : valor de indice minimo de altura a considerar
167 minIndex : valor de indice minimo de altura a considerar
168 maxIndex : valor de indice maximo de altura a considerar
168 maxIndex : valor de indice maximo de altura a considerar
169
169
170 Affected:
170 Affected:
171 self.dataOut.data
171 self.dataOut.data
172 self.dataOut.heightList
172 self.dataOut.heightList
173
173
174 Return:
174 Return:
175 1 si el metodo se ejecuto con exito caso contrario devuelve 0
175 1 si el metodo se ejecuto con exito caso contrario devuelve 0
176 """
176 """
177
177
178 if (minIndex < 0) or (minIndex > maxIndex):
178 if (minIndex < 0) or (minIndex > maxIndex):
179 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
179 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
180
180
181 if (maxIndex >= self.dataOut.nHeights):
181 if (maxIndex >= self.dataOut.nHeights):
182 maxIndex = self.dataOut.nHeights-1
182 maxIndex = self.dataOut.nHeights-1
183 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
183 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
184
184
185 # nHeights = maxIndex - minIndex + 1
185 # nHeights = maxIndex - minIndex + 1
186
186
187 #voltage
187 #voltage
188 data = self.dataOut.data[:,minIndex:maxIndex+1]
188 data = self.dataOut.data[:,minIndex:maxIndex+1]
189
189
190 # firstHeight = self.dataOut.heightList[minIndex]
190 # firstHeight = self.dataOut.heightList[minIndex]
191
191
192 self.dataOut.data = data
192 self.dataOut.data = data
193 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
193 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
194
194
195 return 1
195 return 1
196
196
197
197
198 def filterByHeights(self, window, axis=1):
198 def filterByHeights(self, window, axis=1):
199 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
199 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
200
200
201 if window == None:
201 if window == None:
202 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
202 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
203
203
204 newdelta = deltaHeight * window
204 newdelta = deltaHeight * window
205 r = self.dataOut.data.shape[axis] % window
205 r = self.dataOut.data.shape[axis] % window
206 if axis == 1:
206 if axis == 1:
207 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[axis]-r]
207 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[axis]-r]
208 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[axis]/window,window)
208 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[axis]/window,window)
209 buffer = numpy.sum(buffer,axis+1)
209 buffer = numpy.sum(buffer,axis+1)
210
210
211 elif axis == 2:
211 elif axis == 2:
212 buffer = self.dataOut.data[:, :, 0:self.dataOut.data.shape[axis]-r]
212 buffer = self.dataOut.data[:, :, 0:self.dataOut.data.shape[axis]-r]
213 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1],self.dataOut.data.shape[axis]/window,window)
213 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1],self.dataOut.data.shape[axis]/window,window)
214 buffer = numpy.sum(buffer,axis+1)
214 buffer = numpy.sum(buffer,axis+1)
215
215
216 else:
216 else:
217 raise ValueError, "axis value should be 1 or 2, the input value %d is not valid" % (axis)
217 raise ValueError, "axis value should be 1 or 2, the input value %d is not valid" % (axis)
218
218
219 self.dataOut.data = buffer.copy()
219 self.dataOut.data = buffer.copy()
220 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta)
220 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta)
221 self.dataOut.windowOfFilter = window
221 self.dataOut.windowOfFilter = window
222
222
223 return 1
223 return 1
224
224
225 def deFlip(self):
225 def deFlip(self):
226 self.dataOut.data *= self.flip
226 self.dataOut.data *= self.flip
227 self.flip *= -1.
227 self.flip *= -1.
228
228
229 def setRadarFrequency(self, frequency=None):
229 def setRadarFrequency(self, frequency=None):
230 if frequency != None:
230 if frequency != None:
231 self.dataOut.frequency = frequency
231 self.dataOut.frequency = frequency
232
232
233 return 1
233 return 1
234
234
235 class CohInt(Operation):
235 class CohInt(Operation):
236
236
237 isConfig = False
237 isConfig = False
238
238
239 __profIndex = 0
239 __profIndex = 0
240 __withOverapping = False
240 __withOverapping = False
241
241
242 __byTime = False
242 __byTime = False
243 __initime = None
243 __initime = None
244 __lastdatatime = None
244 __lastdatatime = None
245 __integrationtime = None
245 __integrationtime = None
246
246
247 __buffer = None
247 __buffer = None
248
248
249 __dataReady = False
249 __dataReady = False
250
250
251 n = None
251 n = None
252
252
253
253
254 def __init__(self):
254 def __init__(self):
255
255
256 Operation.__init__(self)
256 Operation.__init__(self)
257
257
258 # self.isConfig = False
258 # self.isConfig = False
259
259
260 def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False):
260 def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False):
261 """
261 """
262 Set the parameters of the integration class.
262 Set the parameters of the integration class.
263
263
264 Inputs:
264 Inputs:
265
265
266 n : Number of coherent integrations
266 n : Number of coherent integrations
267 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
267 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
268 overlapping :
268 overlapping :
269
269
270 """
270 """
271
271
272 self.__initime = None
272 self.__initime = None
273 self.__lastdatatime = 0
273 self.__lastdatatime = 0
274 self.__buffer = None
274 self.__buffer = None
275 self.__dataReady = False
275 self.__dataReady = False
276 self.byblock = byblock
276 self.byblock = byblock
277
277
278 if n == None and timeInterval == None:
278 if n == None and timeInterval == None:
279 raise ValueError, "n or timeInterval should be specified ..."
279 raise ValueError, "n or timeInterval should be specified ..."
280
280
281 if n != None:
281 if n != None:
282 self.n = n
282 self.n = n
283 self.__byTime = False
283 self.__byTime = False
284 else:
284 else:
285 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
285 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
286 self.n = 9999
286 self.n = 9999
287 self.__byTime = True
287 self.__byTime = True
288
288
289 if overlapping:
289 if overlapping:
290 self.__withOverapping = True
290 self.__withOverapping = True
291 self.__buffer = None
291 self.__buffer = None
292 else:
292 else:
293 self.__withOverapping = False
293 self.__withOverapping = False
294 self.__buffer = 0
294 self.__buffer = 0
295
295
296 self.__profIndex = 0
296 self.__profIndex = 0
297
297
298 def putData(self, data):
298 def putData(self, data):
299
299
300 """
300 """
301 Add a profile to the __buffer and increase in one the __profileIndex
301 Add a profile to the __buffer and increase in one the __profileIndex
302
302
303 """
303 """
304
304
305 if not self.__withOverapping:
305 if not self.__withOverapping:
306 self.__buffer += data.copy()
306 self.__buffer += data.copy()
307 self.__profIndex += 1
307 self.__profIndex += 1
308 return
308 return
309
309
310 #Overlapping data
310 #Overlapping data
311 nChannels, nHeis = data.shape
311 nChannels, nHeis = data.shape
312 data = numpy.reshape(data, (1, nChannels, nHeis))
312 data = numpy.reshape(data, (1, nChannels, nHeis))
313
313
314 #If the buffer is empty then it takes the data value
314 #If the buffer is empty then it takes the data value
315 if self.__buffer == None:
315 if self.__buffer == None:
316 self.__buffer = data
316 self.__buffer = data
317 self.__profIndex += 1
317 self.__profIndex += 1
318 return
318 return
319
319
320 #If the buffer length is lower than n then stakcing the data value
320 #If the buffer length is lower than n then stakcing the data value
321 if self.__profIndex < self.n:
321 if self.__profIndex < self.n:
322 self.__buffer = numpy.vstack((self.__buffer, data))
322 self.__buffer = numpy.vstack((self.__buffer, data))
323 self.__profIndex += 1
323 self.__profIndex += 1
324 return
324 return
325
325
326 #If the buffer length is equal to n then replacing the last buffer value with the data value
326 #If the buffer length is equal to n then replacing the last buffer value with the data value
327 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
327 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
328 self.__buffer[self.n-1] = data
328 self.__buffer[self.n-1] = data
329 self.__profIndex = self.n
329 self.__profIndex = self.n
330 return
330 return
331
331
332
332
333 def pushData(self):
333 def pushData(self):
334 """
334 """
335 Return the sum of the last profiles and the profiles used in the sum.
335 Return the sum of the last profiles and the profiles used in the sum.
336
336
337 Affected:
337 Affected:
338
338
339 self.__profileIndex
339 self.__profileIndex
340
340
341 """
341 """
342
342
343 if not self.__withOverapping:
343 if not self.__withOverapping:
344 data = self.__buffer
344 data = self.__buffer
345 n = self.__profIndex
345 n = self.__profIndex
346
346
347 self.__buffer = 0
347 self.__buffer = 0
348 self.__profIndex = 0
348 self.__profIndex = 0
349
349
350 return data, n
350 return data, n
351
351
352 #Integration with Overlapping
352 #Integration with Overlapping
353 data = numpy.sum(self.__buffer, axis=0)
353 data = numpy.sum(self.__buffer, axis=0)
354 n = self.__profIndex
354 n = self.__profIndex
355
355
356 return data, n
356 return data, n
357
357
358 def byProfiles(self, data):
358 def byProfiles(self, data):
359
359
360 self.__dataReady = False
360 self.__dataReady = False
361 avgdata = None
361 avgdata = None
362 # n = None
362 # n = None
363
363
364 self.putData(data)
364 self.putData(data)
365
365
366 if self.__profIndex == self.n:
366 if self.__profIndex == self.n:
367
367
368 avgdata, n = self.pushData()
368 avgdata, n = self.pushData()
369 self.__dataReady = True
369 self.__dataReady = True
370
370
371 return avgdata
371 return avgdata
372
372
373 def byTime(self, data, datatime):
373 def byTime(self, data, datatime):
374
374
375 self.__dataReady = False
375 self.__dataReady = False
376 avgdata = None
376 avgdata = None
377 n = None
377 n = None
378
378
379 self.putData(data)
379 self.putData(data)
380
380
381 if (datatime - self.__initime) >= self.__integrationtime:
381 if (datatime - self.__initime) >= self.__integrationtime:
382 avgdata, n = self.pushData()
382 avgdata, n = self.pushData()
383 self.n = n
383 self.n = n
384 self.__dataReady = True
384 self.__dataReady = True
385
385
386 return avgdata
386 return avgdata
387
387
388 def integrate(self, data, datatime=None):
388 def integrate(self, data, datatime=None):
389
389
390 if self.__initime == None:
390 if self.__initime == None:
391 self.__initime = datatime
391 self.__initime = datatime
392
392
393 if self.__byTime:
393 if self.__byTime:
394 avgdata = self.byTime(data, datatime)
394 avgdata = self.byTime(data, datatime)
395 else:
395 else:
396 avgdata = self.byProfiles(data)
396 avgdata = self.byProfiles(data)
397
397
398
398
399 self.__lastdatatime = datatime
399 self.__lastdatatime = datatime
400
400
401 if avgdata == None:
401 if avgdata == None:
402 return None, None
402 return None, None
403
403
404 avgdatatime = self.__initime
404 avgdatatime = self.__initime
405
405
406 deltatime = datatime -self.__lastdatatime
406 deltatime = datatime -self.__lastdatatime
407
407
408 if not self.__withOverapping:
408 if not self.__withOverapping:
409 self.__initime = datatime
409 self.__initime = datatime
410 else:
410 else:
411 self.__initime += deltatime
411 self.__initime += deltatime
412
412
413 return avgdata, avgdatatime
413 return avgdata, avgdatatime
414
414
415 def integrateByBlock(self, dataOut):
415 def integrateByBlock(self, dataOut):
416 times = int(dataOut.data.shape[1]/self.n)
416 times = int(dataOut.data.shape[1]/self.n)
417 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
417 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
418
418
419 id_min = 0
419 id_min = 0
420 id_max = self.n
420 id_max = self.n
421
421
422 for i in range(times):
422 for i in range(times):
423 junk = dataOut.data[:,id_min:id_max,:]
423 junk = dataOut.data[:,id_min:id_max,:]
424 avgdata[:,i,:] = junk.sum(axis=1)
424 avgdata[:,i,:] = junk.sum(axis=1)
425 id_min += self.n
425 id_min += self.n
426 id_max += self.n
426 id_max += self.n
427
427
428 timeInterval = dataOut.ippSeconds*self.n
428 timeInterval = dataOut.ippSeconds*self.n
429 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
429 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
430 self.__dataReady = True
430 self.__dataReady = True
431 return avgdata, avgdatatime
431 return avgdata, avgdatatime
432
432
433 def run(self, dataOut, **kwargs):
433 def run(self, dataOut, **kwargs):
434
434
435 if not self.isConfig:
435 if not self.isConfig:
436 self.setup(**kwargs)
436 self.setup(**kwargs)
437 self.isConfig = True
437 self.isConfig = True
438
438
439 if self.byblock:
439 if self.byblock:
440 avgdata, avgdatatime = self.integrateByBlock(dataOut)
440 avgdata, avgdatatime = self.integrateByBlock(dataOut)
441 else:
441 else:
442 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
442 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
443
443
444 # dataOut.timeInterval *= n
444 # dataOut.timeInterval *= n
445 dataOut.flagNoData = True
445 dataOut.flagNoData = True
446
446
447 if self.__dataReady:
447 if self.__dataReady:
448 dataOut.data = avgdata
448 dataOut.data = avgdata
449 dataOut.nCohInt *= self.n
449 dataOut.nCohInt *= self.n
450 dataOut.utctime = avgdatatime
450 dataOut.utctime = avgdatatime
451 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
451 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
452 dataOut.flagNoData = False
452 dataOut.flagNoData = False
453
453
454 class Decoder(Operation):
454 class Decoder(Operation):
455
455
456 isConfig = False
456 isConfig = False
457 __profIndex = 0
457 __profIndex = 0
458
458
459 code = None
459 code = None
460
460
461 nCode = None
461 nCode = None
462 nBaud = None
462 nBaud = None
463
463
464
464
465 def __init__(self):
465 def __init__(self):
466
466
467 Operation.__init__(self)
467 Operation.__init__(self)
468
468
469 self.times = None
469 self.times = None
470 self.osamp = None
470 self.osamp = None
471 self.__setValues = False
471 self.__setValues = False
472 # self.isConfig = False
472 # self.isConfig = False
473
473
474 def setup(self, code, shape, times, osamp):
474 def setup(self, code, shape, times, osamp):
475
475
476 self.__profIndex = 0
476 self.__profIndex = 0
477
477
478 self.code = code
478 self.code = code
479
479
480 self.nCode = len(code)
480 self.nCode = len(code)
481 self.nBaud = len(code[0])
481 self.nBaud = len(code[0])
482
482
483 if times != None:
483 if times != None:
484 self.times = times
484 self.times = times
485
485
486 if ((osamp != None) and (osamp >1)):
486 if ((osamp != None) and (osamp >1)):
487 self.osamp = osamp
487 self.osamp = osamp
488 self.code = numpy.repeat(code, repeats=self.osamp,axis=1)
488 self.code = numpy.repeat(code, repeats=self.osamp,axis=1)
489 self.nBaud = self.nBaud*self.osamp
489 self.nBaud = self.nBaud*self.osamp
490
490
491 if len(shape) == 2:
491 if len(shape) == 2:
492 self.__nChannels, self.__nHeis = shape
492 self.__nChannels, self.__nHeis = shape
493
493
494 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
494 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
495
495
496 __codeBuffer[:,0:self.nBaud] = self.code
496 __codeBuffer[:,0:self.nBaud] = self.code
497
497
498 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
498 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
499
499
500 self.ndatadec = self.__nHeis - self.nBaud + 1
500 self.ndatadec = self.__nHeis - self.nBaud + 1
501
501
502 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
502 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
503 else:
503 else:
504 self.__nChannels, self.__nProfiles, self.__nHeis = shape
504 self.__nChannels, self.__nProfiles, self.__nHeis = shape
505
505
506 self.ndatadec = self.__nHeis - self.nBaud + 1
506 self.ndatadec = self.__nHeis - self.nBaud + 1
507
507
508 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
508 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
509
509
510
510
511
511
512 def convolutionInFreq(self, data):
512 def convolutionInFreq(self, data):
513
513
514 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
514 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
515
515
516 fft_data = numpy.fft.fft(data, axis=1)
516 fft_data = numpy.fft.fft(data, axis=1)
517
517
518 conv = fft_data*fft_code
518 conv = fft_data*fft_code
519
519
520 data = numpy.fft.ifft(conv,axis=1)
520 data = numpy.fft.ifft(conv,axis=1)
521
521
522 datadec = data[:,:-self.nBaud+1]
522 datadec = data[:,:-self.nBaud+1]
523
523
524 return datadec
524 return datadec
525
525
526 def convolutionInFreqOpt(self, data):
526 def convolutionInFreqOpt(self, data):
527
527
528 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
528 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
529
529
530 data = cfunctions.decoder(fft_code, data)
530 data = cfunctions.decoder(fft_code, data)
531
531
532 datadec = data[:,:-self.nBaud+1]
532 datadec = data[:,:-self.nBaud+1]
533
533
534 return datadec
534 return datadec
535
535
536 def convolutionInTime(self, data):
536 def convolutionInTime(self, data):
537
537
538 code = self.code[self.__profIndex]
538 code = self.code[self.__profIndex]
539
539
540 for i in range(self.__nChannels):
540 for i in range(self.__nChannels):
541 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
541 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
542
542
543 return self.datadecTime
543 return self.datadecTime
544
544
545 def convolutionByBlockInTime(self, data):
545 def convolutionByBlockInTime(self, data):
546 junk = numpy.lib.stride_tricks.as_strided(self.code, (self.times, self.code.size), (0, self.code.itemsize))
546 junk = numpy.lib.stride_tricks.as_strided(self.code, (self.times, self.code.size), (0, self.code.itemsize))
547 junk = junk.flatten()
547 junk = junk.flatten()
548 code_block = numpy.reshape(junk, (self.nCode*self.times,self.nBaud))
548 code_block = numpy.reshape(junk, (self.nCode*self.times,self.nBaud))
549
549
550 for i in range(self.__nChannels):
550 for i in range(self.__nChannels):
551 for j in range(self.__nProfiles):
551 for j in range(self.__nProfiles):
552 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='valid')
552 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='valid')
553
553
554 return self.datadecTime
554 return self.datadecTime
555
555
556 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, times=None, osamp=None):
556 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, times=None, osamp=None):
557
557
558 if code == None:
558 if code == None:
559 code = dataOut.code
559 code = dataOut.code
560 else:
560 else:
561 code = numpy.array(code).reshape(nCode,nBaud)
561 code = numpy.array(code).reshape(nCode,nBaud)
562
562
563
563
564
564
565 if not self.isConfig:
565 if not self.isConfig:
566
566
567 self.setup(code, dataOut.data.shape, times, osamp)
567 self.setup(code, dataOut.data.shape, times, osamp)
568
568
569 dataOut.code = code
569 dataOut.code = code
570 dataOut.nCode = nCode
570 dataOut.nCode = nCode
571 dataOut.nBaud = nBaud
571 dataOut.nBaud = nBaud
572 dataOut.radarControllerHeaderObj.code = code
572 dataOut.radarControllerHeaderObj.code = code
573 dataOut.radarControllerHeaderObj.nCode = nCode
573 dataOut.radarControllerHeaderObj.nCode = nCode
574 dataOut.radarControllerHeaderObj.nBaud = nBaud
574 dataOut.radarControllerHeaderObj.nBaud = nBaud
575
575
576 self.isConfig = True
576 self.isConfig = True
577
577
578 if mode == 0:
578 if mode == 0:
579 datadec = self.convolutionInTime(dataOut.data)
579 datadec = self.convolutionInTime(dataOut.data)
580
580
581 if mode == 1:
581 if mode == 1:
582 datadec = self.convolutionInFreq(dataOut.data)
582 datadec = self.convolutionInFreq(dataOut.data)
583
583
584 if mode == 2:
584 if mode == 2:
585 datadec = self.convolutionInFreqOpt(dataOut.data)
585 datadec = self.convolutionInFreqOpt(dataOut.data)
586
586
587 if mode == 3:
587 if mode == 3:
588 datadec = self.convolutionByBlockInTime(dataOut.data)
588 datadec = self.convolutionByBlockInTime(dataOut.data)
589
589
590 if not(self.__setValues):
590 if not(self.__setValues):
591 dataOut.code = self.code
591 dataOut.code = self.code
592 dataOut.nCode = self.nCode
592 dataOut.nCode = self.nCode
593 dataOut.nBaud = self.nBaud
593 dataOut.nBaud = self.nBaud
594 dataOut.radarControllerHeaderObj.code = self.code
594 dataOut.radarControllerHeaderObj.code = self.code
595 dataOut.radarControllerHeaderObj.nCode = self.nCode
595 dataOut.radarControllerHeaderObj.nCode = self.nCode
596 dataOut.radarControllerHeaderObj.nBaud = self.nBaud
596 dataOut.radarControllerHeaderObj.nBaud = self.nBaud
597 #self.__setValues = True
597 #self.__setValues = True
598
598
599 dataOut.data = datadec
599 dataOut.data = datadec
600
600
601 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
601 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
602
602
603 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
603 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
604
604
605 if self.__profIndex == self.nCode-1:
605 if self.__profIndex == self.nCode-1:
606 self.__profIndex = 0
606 self.__profIndex = 0
607 return 1
607 return 1
608
608
609 self.__profIndex += 1
609 self.__profIndex += 1
610
610
611 return 1
611 return 1
612 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
612 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
613
613
614
614
615 class ProfileConcat(Operation):
615 class ProfileConcat(Operation):
616
616
617 isConfig = False
617 isConfig = False
618 buffer = None
618 buffer = None
619
619
620 def __init__(self):
620 def __init__(self):
621
621
622 Operation.__init__(self)
622 Operation.__init__(self)
623 self.profileIndex = 0
623 self.profileIndex = 0
624
624
625 def reset(self):
625 def reset(self):
626 self.buffer = numpy.zeros_like(self.buffer)
626 self.buffer = numpy.zeros_like(self.buffer)
627 self.start_index = 0
627 self.start_index = 0
628 self.times = 1
628 self.times = 1
629
629
630 def setup(self, data, m, n=1):
630 def setup(self, data, m, n=1):
631 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
631 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
632 self.profiles = data.shape[1]
632 self.profiles = data.shape[1]
633 self.start_index = 0
633 self.start_index = 0
634 self.times = 1
634 self.times = 1
635
635
636 def concat(self, data):
636 def concat(self, data):
637
637
638 self.buffer[:,self.start_index:self.profiles*self.times] = data.copy()
638 self.buffer[:,self.start_index:self.profiles*self.times] = data.copy()
639 self.start_index = self.start_index + self.profiles
639 self.start_index = self.start_index + self.profiles
640
640
641 def run(self, dataOut, m):
641 def run(self, dataOut, m):
642
642
643 dataOut.flagNoData = True
643 dataOut.flagNoData = True
644
644
645 if not self.isConfig:
645 if not self.isConfig:
646 self.setup(dataOut.data, m, 1)
646 self.setup(dataOut.data, m, 1)
647 self.isConfig = True
647 self.isConfig = True
648
648
649 self.concat(dataOut.data)
649 self.concat(dataOut.data)
650 self.times += 1
650 self.times += 1
651 if self.times > m:
651 if self.times > m:
652 dataOut.data = self.buffer
652 dataOut.data = self.buffer
653 self.reset()
653 self.reset()
654 dataOut.flagNoData = False
654 dataOut.flagNoData = False
655 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
655 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
656 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
656 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
657 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5
657 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5
658 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
658 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
659
659
660 class ProfileSelector(Operation):
660 class ProfileSelector(Operation):
661
661
662 profileIndex = None
662 profileIndex = None
663 # Tamanho total de los perfiles
663 # Tamanho total de los perfiles
664 nProfiles = None
664 nProfiles = None
665
665
666 def __init__(self):
666 def __init__(self):
667
667
668 Operation.__init__(self)
668 Operation.__init__(self)
669 self.profileIndex = 0
669 self.profileIndex = 0
670
670
671 def incIndex(self):
671 def incIndex(self):
672 self.profileIndex += 1
672 self.profileIndex += 1
673
673
674 if self.profileIndex >= self.nProfiles:
674 if self.profileIndex >= self.nProfiles:
675 self.profileIndex = 0
675 self.profileIndex = 0
676
676
677 def isProfileInRange(self, minIndex, maxIndex):
677 def isProfileInRange(self, minIndex, maxIndex):
678
678
679 if self.profileIndex < minIndex:
679 if self.profileIndex < minIndex:
680 return False
680 return False
681
681
682 if self.profileIndex > maxIndex:
682 if self.profileIndex > maxIndex:
683 return False
683 return False
684
684
685 return True
685 return True
686
686
687 def isProfileInList(self, profileList):
687 def isProfileInList(self, profileList):
688
688
689 if self.profileIndex not in profileList:
689 if self.profileIndex not in profileList:
690 return False
690 return False
691
691
692 return True
692 return True
693
693
694 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False):
694 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False):
695
695
696 dataOut.flagNoData = True
696 dataOut.flagNoData = True
697 self.nProfiles = dataOut.nProfiles
697 self.nProfiles = dataOut.nProfiles
698
698
699 if byblock:
699 if byblock:
700
700
701 if profileList != None:
701 if profileList != None:
702 dataOut.data = dataOut.data[:,profileList,:]
702 dataOut.data = dataOut.data[:,profileList,:]
703 pass
703 pass
704 else:
704 else:
705 pmin = profileRangeList[0]
705 pmin = profileRangeList[0]
706 pmax = profileRangeList[1]
706 pmax = profileRangeList[1]
707 dataOut.data = dataOut.data[:,pmin:pmax+1,:]
707 dataOut.data = dataOut.data[:,pmin:pmax+1,:]
708 dataOut.flagNoData = False
708 dataOut.flagNoData = False
709 self.profileIndex = 0
709 self.profileIndex = 0
710 return 1
710 return 1
711
711
712 if profileList != None:
712 if profileList != None:
713 if self.isProfileInList(profileList):
713 if self.isProfileInList(profileList):
714 dataOut.flagNoData = False
714 dataOut.flagNoData = False
715
715
716 self.incIndex()
716 self.incIndex()
717 return 1
717 return 1
718
718
719
719
720 elif profileRangeList != None:
720 elif profileRangeList != None:
721 minIndex = profileRangeList[0]
721 minIndex = profileRangeList[0]
722 maxIndex = profileRangeList[1]
722 maxIndex = profileRangeList[1]
723 if self.isProfileInRange(minIndex, maxIndex):
723 if self.isProfileInRange(minIndex, maxIndex):
724 dataOut.flagNoData = False
724 dataOut.flagNoData = False
725
725
726 self.incIndex()
726 self.incIndex()
727 return 1
727 return 1
728 elif beam != None: #beam is only for AMISR data
728 elif beam != None: #beam is only for AMISR data
729 if self.isProfileInList(dataOut.beamRangeDict[beam]):
729 if self.isProfileInList(dataOut.beamRangeDict[beam]):
730 dataOut.flagNoData = False
730 dataOut.flagNoData = False
731
731
732 self.incIndex()
732 self.incIndex()
733 return 1
733 return 1
734
734
735 else:
735 else:
736 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
736 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
737
737
738 return 0
738 return 0
739
739
740
740
741
741
742 class Reshaper(Operation):
742 class Reshaper(Operation):
743
743 def __init__(self):
744 def __init__(self):
745
744 Operation.__init__(self)
746 Operation.__init__(self)
745 self.updateNewHeights = False
747 self.updateNewHeights = True
746
748
747 def run(self, dataOut, shape):
749 def run(self, dataOut, shape):
750
748 shape_tuple = tuple(shape)
751 shape_tuple = tuple(shape)
749 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
752 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
750 dataOut.flagNoData = False
753 dataOut.flagNoData = False
751
754
752 if not(self.updateNewHeights):
755 if self.updateNewHeights:
756
753 old_nheights = dataOut.nHeights
757 old_nheights = dataOut.nHeights
754 new_nheights = dataOut.data.shape[2]
758 new_nheights = dataOut.data.shape[2]
755 factor = new_nheights / old_nheights
759 factor = 1.0*new_nheights / old_nheights
756 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
760 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
757 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor
761 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor
758 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) No newline at end of file
762 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
General Comments 0
You need to be logged in to leave comments. Login now