##// END OF EJS Templates
Test codification OK
Miguel Valdez -
r316:7582d4034b2c
parent child
Show More
@@ -1,1332 +1,1306
1 '''
1 '''
2
2
3 $Author: dsuarez $
3 $Author: dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
5 '''
5 '''
6 import os
6 import os
7 import numpy
7 import numpy
8 import datetime
8 import datetime
9 import time
9 import time
10
10
11 from jrodata import *
11 from jrodata import *
12 from jrodataIO import *
12 from jrodataIO import *
13 from jroplot import *
13 from jroplot import *
14
14
15 try:
15 try:
16 import cfunctions
16 import cfunctions
17 except:
17 except:
18 pass
18 pass
19
19
20 class ProcessingUnit:
20 class ProcessingUnit:
21
21
22 """
22 """
23 Esta es la clase base para el procesamiento de datos.
23 Esta es la clase base para el procesamiento de datos.
24
24
25 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
25 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
26 - Metodos internos (callMethod)
26 - Metodos internos (callMethod)
27 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
27 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
28 tienen que ser agreagados con el metodo "add".
28 tienen que ser agreagados con el metodo "add".
29
29
30 """
30 """
31 # objeto de datos de entrada (Voltage, Spectra o Correlation)
31 # objeto de datos de entrada (Voltage, Spectra o Correlation)
32 dataIn = None
32 dataIn = None
33
33
34 # objeto de datos de entrada (Voltage, Spectra o Correlation)
34 # objeto de datos de entrada (Voltage, Spectra o Correlation)
35 dataOut = None
35 dataOut = None
36
36
37
37
38 objectDict = None
38 objectDict = None
39
39
40 def __init__(self):
40 def __init__(self):
41
41
42 self.objectDict = {}
42 self.objectDict = {}
43
43
44 def init(self):
44 def init(self):
45
45
46 raise ValueError, "Not implemented"
46 raise ValueError, "Not implemented"
47
47
48 def addOperation(self, object, objId):
48 def addOperation(self, object, objId):
49
49
50 """
50 """
51 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
51 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
52 identificador asociado a este objeto.
52 identificador asociado a este objeto.
53
53
54 Input:
54 Input:
55
55
56 object : objeto de la clase "Operation"
56 object : objeto de la clase "Operation"
57
57
58 Return:
58 Return:
59
59
60 objId : identificador del objeto, necesario para ejecutar la operacion
60 objId : identificador del objeto, necesario para ejecutar la operacion
61 """
61 """
62
62
63 self.objectDict[objId] = object
63 self.objectDict[objId] = object
64
64
65 return objId
65 return objId
66
66
67 def operation(self, **kwargs):
67 def operation(self, **kwargs):
68
68
69 """
69 """
70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
71 atributos del objeto dataOut
71 atributos del objeto dataOut
72
72
73 Input:
73 Input:
74
74
75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
76 """
76 """
77
77
78 raise ValueError, "ImplementedError"
78 raise ValueError, "ImplementedError"
79
79
80 def callMethod(self, name, **kwargs):
80 def callMethod(self, name, **kwargs):
81
81
82 """
82 """
83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
84
84
85 Input:
85 Input:
86 name : nombre del metodo a ejecutar
86 name : nombre del metodo a ejecutar
87
87
88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
89
89
90 """
90 """
91 if name != 'run':
91 if name != 'run':
92
92
93 if name == 'init' and self.dataIn.isEmpty():
93 if name == 'init' and self.dataIn.isEmpty():
94 self.dataOut.flagNoData = True
94 self.dataOut.flagNoData = True
95 return False
95 return False
96
96
97 if name != 'init' and self.dataOut.isEmpty():
97 if name != 'init' and self.dataOut.isEmpty():
98 return False
98 return False
99
99
100 methodToCall = getattr(self, name)
100 methodToCall = getattr(self, name)
101
101
102 methodToCall(**kwargs)
102 methodToCall(**kwargs)
103
103
104 if name != 'run':
104 if name != 'run':
105 return True
105 return True
106
106
107 if self.dataOut.isEmpty():
107 if self.dataOut.isEmpty():
108 return False
108 return False
109
109
110 return True
110 return True
111
111
112 def callObject(self, objId, **kwargs):
112 def callObject(self, objId, **kwargs):
113
113
114 """
114 """
115 Ejecuta la operacion asociada al identificador del objeto "objId"
115 Ejecuta la operacion asociada al identificador del objeto "objId"
116
116
117 Input:
117 Input:
118
118
119 objId : identificador del objeto a ejecutar
119 objId : identificador del objeto a ejecutar
120
120
121 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
121 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
122
122
123 Return:
123 Return:
124
124
125 None
125 None
126 """
126 """
127
127
128 if self.dataOut.isEmpty():
128 if self.dataOut.isEmpty():
129 return False
129 return False
130
130
131 object = self.objectDict[objId]
131 object = self.objectDict[objId]
132
132
133 object.run(self.dataOut, **kwargs)
133 object.run(self.dataOut, **kwargs)
134
134
135 return True
135 return True
136
136
137 def call(self, operationConf, **kwargs):
137 def call(self, operationConf, **kwargs):
138
138
139 """
139 """
140 Return True si ejecuta la operacion "operationConf.name" con los
140 Return True si ejecuta la operacion "operationConf.name" con los
141 argumentos "**kwargs". False si la operacion no se ha ejecutado.
141 argumentos "**kwargs". False si la operacion no se ha ejecutado.
142 La operacion puede ser de dos tipos:
142 La operacion puede ser de dos tipos:
143
143
144 1. Un metodo propio de esta clase:
144 1. Un metodo propio de esta clase:
145
145
146 operation.type = "self"
146 operation.type = "self"
147
147
148 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
148 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
149 operation.type = "other".
149 operation.type = "other".
150
150
151 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
151 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
152 "addOperation" e identificado con el operation.id
152 "addOperation" e identificado con el operation.id
153
153
154
154
155 con el id de la operacion.
155 con el id de la operacion.
156
156
157 Input:
157 Input:
158
158
159 Operation : Objeto del tipo operacion con los atributos: name, type y id.
159 Operation : Objeto del tipo operacion con los atributos: name, type y id.
160
160
161 """
161 """
162
162
163 if operationConf.type == 'self':
163 if operationConf.type == 'self':
164 sts = self.callMethod(operationConf.name, **kwargs)
164 sts = self.callMethod(operationConf.name, **kwargs)
165
165
166 if operationConf.type == 'other':
166 if operationConf.type == 'other':
167 sts = self.callObject(operationConf.id, **kwargs)
167 sts = self.callObject(operationConf.id, **kwargs)
168
168
169 return sts
169 return sts
170
170
171 def setInput(self, dataIn):
171 def setInput(self, dataIn):
172
172
173 self.dataIn = dataIn
173 self.dataIn = dataIn
174
174
175 def getOutput(self):
175 def getOutput(self):
176
176
177 return self.dataOut
177 return self.dataOut
178
178
179 class Operation():
179 class Operation():
180
180
181 """
181 """
182 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
182 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
183 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
183 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
184 acumulacion dentro de esta clase
184 acumulacion dentro de esta clase
185
185
186 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
186 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
187
187
188 """
188 """
189
189
190 __buffer = None
190 __buffer = None
191 __isConfig = False
191 __isConfig = False
192
192
193 def __init__(self):
193 def __init__(self):
194
194
195 pass
195 pass
196
196
197 def run(self, dataIn, **kwargs):
197 def run(self, dataIn, **kwargs):
198
198
199 """
199 """
200 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
200 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
201
201
202 Input:
202 Input:
203
203
204 dataIn : objeto del tipo JROData
204 dataIn : objeto del tipo JROData
205
205
206 Return:
206 Return:
207
207
208 None
208 None
209
209
210 Affected:
210 Affected:
211 __buffer : buffer de recepcion de datos.
211 __buffer : buffer de recepcion de datos.
212
212
213 """
213 """
214
214
215 raise ValueError, "ImplementedError"
215 raise ValueError, "ImplementedError"
216
216
217 class VoltageProc(ProcessingUnit):
217 class VoltageProc(ProcessingUnit):
218
218
219
219
220 def __init__(self):
220 def __init__(self):
221
221
222 self.objectDict = {}
222 self.objectDict = {}
223 self.dataOut = Voltage()
223 self.dataOut = Voltage()
224 self.flip = 1
224 self.flip = 1
225
225
226 def init(self):
226 def init(self):
227
227
228 self.dataOut.copy(self.dataIn)
228 self.dataOut.copy(self.dataIn)
229 # No necesita copiar en cada init() los atributos de dataIn
229 # No necesita copiar en cada init() los atributos de dataIn
230 # la copia deberia hacerse por cada nuevo bloque de datos
230 # la copia deberia hacerse por cada nuevo bloque de datos
231
231
232 def selectChannels(self, channelList):
232 def selectChannels(self, channelList):
233
233
234 channelIndexList = []
234 channelIndexList = []
235
235
236 for channel in channelList:
236 for channel in channelList:
237 index = self.dataOut.channelList.index(channel)
237 index = self.dataOut.channelList.index(channel)
238 channelIndexList.append(index)
238 channelIndexList.append(index)
239
239
240 self.selectChannelsByIndex(channelIndexList)
240 self.selectChannelsByIndex(channelIndexList)
241
241
242 def selectChannelsByIndex(self, channelIndexList):
242 def selectChannelsByIndex(self, channelIndexList):
243 """
243 """
244 Selecciona un bloque de datos en base a canales segun el channelIndexList
244 Selecciona un bloque de datos en base a canales segun el channelIndexList
245
245
246 Input:
246 Input:
247 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
247 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
248
248
249 Affected:
249 Affected:
250 self.dataOut.data
250 self.dataOut.data
251 self.dataOut.channelIndexList
251 self.dataOut.channelIndexList
252 self.dataOut.nChannels
252 self.dataOut.nChannels
253 self.dataOut.m_ProcessingHeader.totalSpectra
253 self.dataOut.m_ProcessingHeader.totalSpectra
254 self.dataOut.systemHeaderObj.numChannels
254 self.dataOut.systemHeaderObj.numChannels
255 self.dataOut.m_ProcessingHeader.blockSize
255 self.dataOut.m_ProcessingHeader.blockSize
256
256
257 Return:
257 Return:
258 None
258 None
259 """
259 """
260
260
261 for channelIndex in channelIndexList:
261 for channelIndex in channelIndexList:
262 if channelIndex not in self.dataOut.channelIndexList:
262 if channelIndex not in self.dataOut.channelIndexList:
263 print channelIndexList
263 print channelIndexList
264 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
264 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
265
265
266 nChannels = len(channelIndexList)
266 nChannels = len(channelIndexList)
267
267
268 data = self.dataOut.data[channelIndexList,:]
268 data = self.dataOut.data[channelIndexList,:]
269
269
270 self.dataOut.data = data
270 self.dataOut.data = data
271 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
271 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
272 # self.dataOut.nChannels = nChannels
272 # self.dataOut.nChannels = nChannels
273
273
274 return 1
274 return 1
275
275
276 def selectHeights(self, minHei, maxHei):
276 def selectHeights(self, minHei, maxHei):
277 """
277 """
278 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
278 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
279 minHei <= height <= maxHei
279 minHei <= height <= maxHei
280
280
281 Input:
281 Input:
282 minHei : valor minimo de altura a considerar
282 minHei : valor minimo de altura a considerar
283 maxHei : valor maximo de altura a considerar
283 maxHei : valor maximo de altura a considerar
284
284
285 Affected:
285 Affected:
286 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
286 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
287
287
288 Return:
288 Return:
289 1 si el metodo se ejecuto con exito caso contrario devuelve 0
289 1 si el metodo se ejecuto con exito caso contrario devuelve 0
290 """
290 """
291 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
291 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
292 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
292 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
293
293
294 if (maxHei > self.dataOut.heightList[-1]):
294 if (maxHei > self.dataOut.heightList[-1]):
295 maxHei = self.dataOut.heightList[-1]
295 maxHei = self.dataOut.heightList[-1]
296 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
296 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
297
297
298 minIndex = 0
298 minIndex = 0
299 maxIndex = 0
299 maxIndex = 0
300 heights = self.dataOut.heightList
300 heights = self.dataOut.heightList
301
301
302 inda = numpy.where(heights >= minHei)
302 inda = numpy.where(heights >= minHei)
303 indb = numpy.where(heights <= maxHei)
303 indb = numpy.where(heights <= maxHei)
304
304
305 try:
305 try:
306 minIndex = inda[0][0]
306 minIndex = inda[0][0]
307 except:
307 except:
308 minIndex = 0
308 minIndex = 0
309
309
310 try:
310 try:
311 maxIndex = indb[0][-1]
311 maxIndex = indb[0][-1]
312 except:
312 except:
313 maxIndex = len(heights)
313 maxIndex = len(heights)
314
314
315 self.selectHeightsByIndex(minIndex, maxIndex)
315 self.selectHeightsByIndex(minIndex, maxIndex)
316
316
317 return 1
317 return 1
318
318
319
319
320 def selectHeightsByIndex(self, minIndex, maxIndex):
320 def selectHeightsByIndex(self, minIndex, maxIndex):
321 """
321 """
322 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
322 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
323 minIndex <= index <= maxIndex
323 minIndex <= index <= maxIndex
324
324
325 Input:
325 Input:
326 minIndex : valor de indice minimo de altura a considerar
326 minIndex : valor de indice minimo de altura a considerar
327 maxIndex : valor de indice maximo de altura a considerar
327 maxIndex : valor de indice maximo de altura a considerar
328
328
329 Affected:
329 Affected:
330 self.dataOut.data
330 self.dataOut.data
331 self.dataOut.heightList
331 self.dataOut.heightList
332
332
333 Return:
333 Return:
334 1 si el metodo se ejecuto con exito caso contrario devuelve 0
334 1 si el metodo se ejecuto con exito caso contrario devuelve 0
335 """
335 """
336
336
337 if (minIndex < 0) or (minIndex > maxIndex):
337 if (minIndex < 0) or (minIndex > maxIndex):
338 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
338 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
339
339
340 if (maxIndex >= self.dataOut.nHeights):
340 if (maxIndex >= self.dataOut.nHeights):
341 maxIndex = self.dataOut.nHeights-1
341 maxIndex = self.dataOut.nHeights-1
342 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
342 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
343
343
344 nHeights = maxIndex - minIndex + 1
344 nHeights = maxIndex - minIndex + 1
345
345
346 #voltage
346 #voltage
347 data = self.dataOut.data[:,minIndex:maxIndex+1]
347 data = self.dataOut.data[:,minIndex:maxIndex+1]
348
348
349 firstHeight = self.dataOut.heightList[minIndex]
349 firstHeight = self.dataOut.heightList[minIndex]
350
350
351 self.dataOut.data = data
351 self.dataOut.data = data
352 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
352 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
353
353
354 return 1
354 return 1
355
355
356
356
357 def filterByHeights(self, window):
357 def filterByHeights(self, window):
358 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
358 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
359
359
360 if window == None:
360 if window == None:
361 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
361 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
362
362
363 newdelta = deltaHeight * window
363 newdelta = deltaHeight * window
364 r = self.dataOut.data.shape[1] % window
364 r = self.dataOut.data.shape[1] % window
365 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
365 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
366 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
366 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
367 buffer = numpy.sum(buffer,2)
367 buffer = numpy.sum(buffer,2)
368 self.dataOut.data = buffer
368 self.dataOut.data = buffer
369 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window-newdelta,newdelta)
369 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window-newdelta,newdelta)
370 self.dataOut.windowOfFilter = window
370 self.dataOut.windowOfFilter = window
371
371
372 def deFlip(self):
372 def deFlip(self):
373 self.dataOut.data *= self.flip
373 self.dataOut.data *= self.flip
374 self.flip *= -1.
374 self.flip *= -1.
375
375
376
376
377 class CohInt(Operation):
377 class CohInt(Operation):
378
378
379 __isConfig = False
379 __isConfig = False
380
380
381 __profIndex = 0
381 __profIndex = 0
382 __withOverapping = False
382 __withOverapping = False
383
383
384 __byTime = False
384 __byTime = False
385 __initime = None
385 __initime = None
386 __lastdatatime = None
386 __lastdatatime = None
387 __integrationtime = None
387 __integrationtime = None
388
388
389 __buffer = None
389 __buffer = None
390
390
391 __dataReady = False
391 __dataReady = False
392
392
393 n = None
393 n = None
394
394
395
395
396 def __init__(self):
396 def __init__(self):
397
397
398 self.__isConfig = False
398 self.__isConfig = False
399
399
400 def setup(self, n=None, timeInterval=None, overlapping=False):
400 def setup(self, n=None, timeInterval=None, overlapping=False):
401 """
401 """
402 Set the parameters of the integration class.
402 Set the parameters of the integration class.
403
403
404 Inputs:
404 Inputs:
405
405
406 n : Number of coherent integrations
406 n : Number of coherent integrations
407 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
407 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
408 overlapping :
408 overlapping :
409
409
410 """
410 """
411
411
412 self.__initime = None
412 self.__initime = None
413 self.__lastdatatime = 0
413 self.__lastdatatime = 0
414 self.__buffer = None
414 self.__buffer = None
415 self.__dataReady = False
415 self.__dataReady = False
416
416
417
417
418 if n == None and timeInterval == None:
418 if n == None and timeInterval == None:
419 raise ValueError, "n or timeInterval should be specified ..."
419 raise ValueError, "n or timeInterval should be specified ..."
420
420
421 if n != None:
421 if n != None:
422 self.n = n
422 self.n = n
423 self.__byTime = False
423 self.__byTime = False
424 else:
424 else:
425 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
425 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
426 self.n = 9999
426 self.n = 9999
427 self.__byTime = True
427 self.__byTime = True
428
428
429 if overlapping:
429 if overlapping:
430 self.__withOverapping = True
430 self.__withOverapping = True
431 self.__buffer = None
431 self.__buffer = None
432 else:
432 else:
433 self.__withOverapping = False
433 self.__withOverapping = False
434 self.__buffer = 0
434 self.__buffer = 0
435
435
436 self.__profIndex = 0
436 self.__profIndex = 0
437
437
438 def putData(self, data):
438 def putData(self, data):
439
439
440 """
440 """
441 Add a profile to the __buffer and increase in one the __profileIndex
441 Add a profile to the __buffer and increase in one the __profileIndex
442
442
443 """
443 """
444
444
445 if not self.__withOverapping:
445 if not self.__withOverapping:
446 self.__buffer += data.copy()
446 self.__buffer += data.copy()
447 self.__profIndex += 1
447 self.__profIndex += 1
448 return
448 return
449
449
450 #Overlapping data
450 #Overlapping data
451 nChannels, nHeis = data.shape
451 nChannels, nHeis = data.shape
452 data = numpy.reshape(data, (1, nChannels, nHeis))
452 data = numpy.reshape(data, (1, nChannels, nHeis))
453
453
454 #If the buffer is empty then it takes the data value
454 #If the buffer is empty then it takes the data value
455 if self.__buffer == None:
455 if self.__buffer == None:
456 self.__buffer = data
456 self.__buffer = data
457 self.__profIndex += 1
457 self.__profIndex += 1
458 return
458 return
459
459
460 #If the buffer length is lower than n then stakcing the data value
460 #If the buffer length is lower than n then stakcing the data value
461 if self.__profIndex < self.n:
461 if self.__profIndex < self.n:
462 self.__buffer = numpy.vstack((self.__buffer, data))
462 self.__buffer = numpy.vstack((self.__buffer, data))
463 self.__profIndex += 1
463 self.__profIndex += 1
464 return
464 return
465
465
466 #If the buffer length is equal to n then replacing the last buffer value with the data value
466 #If the buffer length is equal to n then replacing the last buffer value with the data value
467 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
467 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
468 self.__buffer[self.n-1] = data
468 self.__buffer[self.n-1] = data
469 self.__profIndex = self.n
469 self.__profIndex = self.n
470 return
470 return
471
471
472
472
473 def pushData(self):
473 def pushData(self):
474 """
474 """
475 Return the sum of the last profiles and the profiles used in the sum.
475 Return the sum of the last profiles and the profiles used in the sum.
476
476
477 Affected:
477 Affected:
478
478
479 self.__profileIndex
479 self.__profileIndex
480
480
481 """
481 """
482
482
483 if not self.__withOverapping:
483 if not self.__withOverapping:
484 data = self.__buffer
484 data = self.__buffer
485 n = self.__profIndex
485 n = self.__profIndex
486
486
487 self.__buffer = 0
487 self.__buffer = 0
488 self.__profIndex = 0
488 self.__profIndex = 0
489
489
490 return data, n
490 return data, n
491
491
492 #Integration with Overlapping
492 #Integration with Overlapping
493 data = numpy.sum(self.__buffer, axis=0)
493 data = numpy.sum(self.__buffer, axis=0)
494 n = self.__profIndex
494 n = self.__profIndex
495
495
496 return data, n
496 return data, n
497
497
498 def byProfiles(self, data):
498 def byProfiles(self, data):
499
499
500 self.__dataReady = False
500 self.__dataReady = False
501 avgdata = None
501 avgdata = None
502 n = None
502 n = None
503
503
504 self.putData(data)
504 self.putData(data)
505
505
506 if self.__profIndex == self.n:
506 if self.__profIndex == self.n:
507
507
508 avgdata, n = self.pushData()
508 avgdata, n = self.pushData()
509 self.__dataReady = True
509 self.__dataReady = True
510
510
511 return avgdata
511 return avgdata
512
512
513 def byTime(self, data, datatime):
513 def byTime(self, data, datatime):
514
514
515 self.__dataReady = False
515 self.__dataReady = False
516 avgdata = None
516 avgdata = None
517 n = None
517 n = None
518
518
519 self.putData(data)
519 self.putData(data)
520
520
521 if (datatime - self.__initime) >= self.__integrationtime:
521 if (datatime - self.__initime) >= self.__integrationtime:
522 avgdata, n = self.pushData()
522 avgdata, n = self.pushData()
523 self.n = n
523 self.n = n
524 self.__dataReady = True
524 self.__dataReady = True
525
525
526 return avgdata
526 return avgdata
527
527
528 def integrate(self, data, datatime=None):
528 def integrate(self, data, datatime=None):
529
529
530 if self.__initime == None:
530 if self.__initime == None:
531 self.__initime = datatime
531 self.__initime = datatime
532
532
533 if self.__byTime:
533 if self.__byTime:
534 avgdata = self.byTime(data, datatime)
534 avgdata = self.byTime(data, datatime)
535 else:
535 else:
536 avgdata = self.byProfiles(data)
536 avgdata = self.byProfiles(data)
537
537
538
538
539 self.__lastdatatime = datatime
539 self.__lastdatatime = datatime
540
540
541 if avgdata == None:
541 if avgdata == None:
542 return None, None
542 return None, None
543
543
544 avgdatatime = self.__initime
544 avgdatatime = self.__initime
545
545
546 deltatime = datatime -self.__lastdatatime
546 deltatime = datatime -self.__lastdatatime
547
547
548 if not self.__withOverapping:
548 if not self.__withOverapping:
549 self.__initime = datatime
549 self.__initime = datatime
550 else:
550 else:
551 self.__initime += deltatime
551 self.__initime += deltatime
552
552
553 return avgdata, avgdatatime
553 return avgdata, avgdatatime
554
554
555 def run(self, dataOut, **kwargs):
555 def run(self, dataOut, **kwargs):
556
556
557 if not self.__isConfig:
557 if not self.__isConfig:
558 self.setup(**kwargs)
558 self.setup(**kwargs)
559 self.__isConfig = True
559 self.__isConfig = True
560
560
561 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
561 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
562
562
563 # dataOut.timeInterval *= n
563 # dataOut.timeInterval *= n
564 dataOut.flagNoData = True
564 dataOut.flagNoData = True
565
565
566 if self.__dataReady:
566 if self.__dataReady:
567 dataOut.data = avgdata
567 dataOut.data = avgdata
568 dataOut.nCohInt *= self.n
568 dataOut.nCohInt *= self.n
569 dataOut.utctime = avgdatatime
569 dataOut.utctime = avgdatatime
570 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
570 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
571 dataOut.flagNoData = False
571 dataOut.flagNoData = False
572
572
573
573
574 class Decoder(Operation):
574 class Decoder(Operation):
575
575
576 __isConfig = False
576 __isConfig = False
577 __profIndex = 0
577 __profIndex = 0
578
578
579 code = None
579 code = None
580
580
581 nCode = None
581 nCode = None
582 nBaud = None
582 nBaud = None
583
583
584 def __init__(self):
584 def __init__(self):
585
585
586 self.__isConfig = False
586 self.__isConfig = False
587
587
588 def setup(self, code, shape):
588 def setup(self, code, shape):
589
589
590 self.__profIndex = 0
590 self.__profIndex = 0
591
591
592 self.code = code
592 self.code = code
593
593
594 self.nCode = len(code)
594 self.nCode = len(code)
595 self.nBaud = len(code[0])
595 self.nBaud = len(code[0])
596
596
597 self.__nChannels, self.__nHeis = shape
597 self.__nChannels, self.__nHeis = shape
598
598
599 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.float32)
599 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.float32)
600
600
601 __codeBuffer[:,0:self.nBaud] = self.code
601 __codeBuffer[:,0:self.nBaud] = self.code
602
602
603 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
603 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
604
604
605 self.ndatadec = self.__nHeis - self.nBaud + 1
605 self.ndatadec = self.__nHeis - self.nBaud + 1
606
606
607 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
607 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
608
608
609 def convolutionInFreq(self, data):
609 def convolutionInFreq(self, data):
610
610
611 ini = time.time()
612
613 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
611 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
614
612
615 print "Freq0 ", time.time() - ini
616
617 fft_data = numpy.fft.fft(data, axis=1)
613 fft_data = numpy.fft.fft(data, axis=1)
618
614
619 print "Freq1 ", time.time() - ini
620
621 conv = fft_data*fft_code
615 conv = fft_data*fft_code
622
623 print "Freq2 ", time.time() - ini
624
616
625 data = numpy.fft.ifft(conv,axis=1)
617 data = numpy.fft.ifft(conv,axis=1)
626
618
627 print "Freq3 ", time.time() - ini
628
629 datadec = data[:,:-self.nBaud+1]
619 datadec = data[:,:-self.nBaud+1]
630
620
631 print "Freq4 ", time.time() - ini
632
633 return datadec
621 return datadec
634
622
635 def convolutionInFreqOpt(self, data):
623 def convolutionInFreqOpt(self, data):
636
624
637 ini = time.time()
638
639 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
625 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
640
626
641 data = cfunctions.decoder(fft_code, data)
627 data = cfunctions.decoder(fft_code, data)
642
628
643 datadec = data[:,:-self.nBaud+1]
629 datadec = data[:,:-self.nBaud+1]
644
630
645 print "OptFreq ", time.time() - ini
646
647 return datadec
631 return datadec
648
632
649 def convolutionInTime(self, data):
633 def convolutionInTime(self, data):
650
634
651 ini = time.time()
652
653 code = self.code[self.__profIndex]
635 code = self.code[self.__profIndex]
654
636
655 print self.datadecTime.shape, data.shape, code.shape
656
657 for i in range(self.__nChannels):
637 for i in range(self.__nChannels):
658 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
638 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
659
639
660 print "Time ", time.time() - ini
661
662 return self.datadecTime
640 return self.datadecTime
663
641
664 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
642 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
665 ini = time.time()
643
666 if not self.__isConfig:
644 if not self.__isConfig:
667
645
668 if code == None:
646 if code == None:
669 code = dataOut.code
647 code = dataOut.code
670 else:
648 else:
671 code = numpy.array(code).reshape(nCode,nBaud)
649 code = numpy.array(code).reshape(nCode,nBaud)
672 dataOut.code = code
650 dataOut.code = code
673 dataOut.nCode = nCode
651 dataOut.nCode = nCode
674 dataOut.nBaud = nBaud
652 dataOut.nBaud = nBaud
675
653
676 if code == None:
654 if code == None:
677 return 1
655 return 1
678
656
679 self.setup(code, dataOut.data.shape)
657 self.setup(code, dataOut.data.shape)
680 self.__isConfig = True
658 self.__isConfig = True
681
659
682 print "DAta shape ", dataOut.data.shape
683
684 if mode == 0:
660 if mode == 0:
685 datadec = self.convolutionInFreq(dataOut.data)
661 datadec = self.convolutionInTime(dataOut.data)
686
662
687 if mode == 1:
663 if mode == 1:
688 datadec = self.convolutionInTime(dataOut.data)
664 datadec = self.convolutionInFreq(dataOut.data)
689
665
690 if mode == 2:
666 if mode == 2:
691 datadec = self.convolutionInFreqOpt(dataOut.data)
667 datadec = self.convolutionInFreqOpt(dataOut.data)
692
668
693 dataOut.data = datadec
669 dataOut.data = datadec
694
670
695 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
671 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
696
672
697 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
673 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
698
699 print time.time() - ini, "prof = %d, nCode=%d" %(self.__profIndex, self.nCode)
700
674
701 if self.__profIndex == self.nCode-1:
675 if self.__profIndex == self.nCode-1:
702 self.__profIndex = 0
676 self.__profIndex = 0
703 return 1
677 return 1
704
678
705 self.__profIndex += 1
679 self.__profIndex += 1
706
680
707 return 1
681 return 1
708 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
682 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
709
683
710
684
711
685
712 class SpectraProc(ProcessingUnit):
686 class SpectraProc(ProcessingUnit):
713
687
714 def __init__(self):
688 def __init__(self):
715
689
716 self.objectDict = {}
690 self.objectDict = {}
717 self.buffer = None
691 self.buffer = None
718 self.firstdatatime = None
692 self.firstdatatime = None
719 self.profIndex = 0
693 self.profIndex = 0
720 self.dataOut = Spectra()
694 self.dataOut = Spectra()
721
695
722 def __updateObjFromInput(self):
696 def __updateObjFromInput(self):
723
697
724 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
698 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
725 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
699 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
726 self.dataOut.channelList = self.dataIn.channelList
700 self.dataOut.channelList = self.dataIn.channelList
727 self.dataOut.heightList = self.dataIn.heightList
701 self.dataOut.heightList = self.dataIn.heightList
728 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
702 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
729 # self.dataOut.nHeights = self.dataIn.nHeights
703 # self.dataOut.nHeights = self.dataIn.nHeights
730 # self.dataOut.nChannels = self.dataIn.nChannels
704 # self.dataOut.nChannels = self.dataIn.nChannels
731 self.dataOut.nBaud = self.dataIn.nBaud
705 self.dataOut.nBaud = self.dataIn.nBaud
732 self.dataOut.nCode = self.dataIn.nCode
706 self.dataOut.nCode = self.dataIn.nCode
733 self.dataOut.code = self.dataIn.code
707 self.dataOut.code = self.dataIn.code
734 self.dataOut.nProfiles = self.dataOut.nFFTPoints
708 self.dataOut.nProfiles = self.dataOut.nFFTPoints
735 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
709 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
736 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
710 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
737 self.dataOut.utctime = self.firstdatatime
711 self.dataOut.utctime = self.firstdatatime
738 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
712 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
739 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
713 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
740 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
714 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
741 self.dataOut.nCohInt = self.dataIn.nCohInt
715 self.dataOut.nCohInt = self.dataIn.nCohInt
742 self.dataOut.nIncohInt = 1
716 self.dataOut.nIncohInt = 1
743 self.dataOut.ippSeconds = self.dataIn.ippSeconds
717 self.dataOut.ippSeconds = self.dataIn.ippSeconds
744 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
718 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
745
719
746 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
720 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
747
721
748 def __getFft(self):
722 def __getFft(self):
749 """
723 """
750 Convierte valores de Voltaje a Spectra
724 Convierte valores de Voltaje a Spectra
751
725
752 Affected:
726 Affected:
753 self.dataOut.data_spc
727 self.dataOut.data_spc
754 self.dataOut.data_cspc
728 self.dataOut.data_cspc
755 self.dataOut.data_dc
729 self.dataOut.data_dc
756 self.dataOut.heightList
730 self.dataOut.heightList
757 self.profIndex
731 self.profIndex
758 self.buffer
732 self.buffer
759 self.dataOut.flagNoData
733 self.dataOut.flagNoData
760 """
734 """
761 fft_volt = numpy.fft.fft(self.buffer,axis=1)
735 fft_volt = numpy.fft.fft(self.buffer,axis=1)
762 fft_volt = fft_volt.astype(numpy.dtype('complex'))
736 fft_volt = fft_volt.astype(numpy.dtype('complex'))
763 dc = fft_volt[:,0,:]
737 dc = fft_volt[:,0,:]
764
738
765 #calculo de self-spectra
739 #calculo de self-spectra
766 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
740 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
767 spc = fft_volt * numpy.conjugate(fft_volt)
741 spc = fft_volt * numpy.conjugate(fft_volt)
768 spc = spc.real
742 spc = spc.real
769
743
770 blocksize = 0
744 blocksize = 0
771 blocksize += dc.size
745 blocksize += dc.size
772 blocksize += spc.size
746 blocksize += spc.size
773
747
774 cspc = None
748 cspc = None
775 pairIndex = 0
749 pairIndex = 0
776 if self.dataOut.pairsList != None:
750 if self.dataOut.pairsList != None:
777 #calculo de cross-spectra
751 #calculo de cross-spectra
778 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
752 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
779 for pair in self.dataOut.pairsList:
753 for pair in self.dataOut.pairsList:
780 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
754 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
781 pairIndex += 1
755 pairIndex += 1
782 blocksize += cspc.size
756 blocksize += cspc.size
783
757
784 self.dataOut.data_spc = spc
758 self.dataOut.data_spc = spc
785 self.dataOut.data_cspc = cspc
759 self.dataOut.data_cspc = cspc
786 self.dataOut.data_dc = dc
760 self.dataOut.data_dc = dc
787 self.dataOut.blockSize = blocksize
761 self.dataOut.blockSize = blocksize
788
762
789 def init(self, nFFTPoints=None, pairsList=None):
763 def init(self, nFFTPoints=None, pairsList=None):
790
764
791 self.dataOut.flagNoData = True
765 self.dataOut.flagNoData = True
792
766
793 if self.dataIn.type == "Spectra":
767 if self.dataIn.type == "Spectra":
794 self.dataOut.copy(self.dataIn)
768 self.dataOut.copy(self.dataIn)
795 return
769 return
796
770
797 if self.dataIn.type == "Voltage":
771 if self.dataIn.type == "Voltage":
798
772
799 if nFFTPoints == None:
773 if nFFTPoints == None:
800 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
774 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
801
775
802 if pairsList == None:
776 if pairsList == None:
803 nPairs = 0
777 nPairs = 0
804 else:
778 else:
805 nPairs = len(pairsList)
779 nPairs = len(pairsList)
806
780
807 self.dataOut.nFFTPoints = nFFTPoints
781 self.dataOut.nFFTPoints = nFFTPoints
808 self.dataOut.pairsList = pairsList
782 self.dataOut.pairsList = pairsList
809 self.dataOut.nPairs = nPairs
783 self.dataOut.nPairs = nPairs
810
784
811 if self.buffer == None:
785 if self.buffer == None:
812 self.buffer = numpy.zeros((self.dataIn.nChannels,
786 self.buffer = numpy.zeros((self.dataIn.nChannels,
813 self.dataOut.nFFTPoints,
787 self.dataOut.nFFTPoints,
814 self.dataIn.nHeights),
788 self.dataIn.nHeights),
815 dtype='complex')
789 dtype='complex')
816
790
817
791
818 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
792 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
819 self.profIndex += 1
793 self.profIndex += 1
820
794
821 if self.firstdatatime == None:
795 if self.firstdatatime == None:
822 self.firstdatatime = self.dataIn.utctime
796 self.firstdatatime = self.dataIn.utctime
823
797
824 if self.profIndex == self.dataOut.nFFTPoints:
798 if self.profIndex == self.dataOut.nFFTPoints:
825 self.__updateObjFromInput()
799 self.__updateObjFromInput()
826 self.__getFft()
800 self.__getFft()
827
801
828 self.dataOut.flagNoData = False
802 self.dataOut.flagNoData = False
829
803
830 self.buffer = None
804 self.buffer = None
831 self.firstdatatime = None
805 self.firstdatatime = None
832 self.profIndex = 0
806 self.profIndex = 0
833
807
834 return
808 return
835
809
836 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
810 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
837
811
838 def selectChannels(self, channelList):
812 def selectChannels(self, channelList):
839
813
840 channelIndexList = []
814 channelIndexList = []
841
815
842 for channel in channelList:
816 for channel in channelList:
843 index = self.dataOut.channelList.index(channel)
817 index = self.dataOut.channelList.index(channel)
844 channelIndexList.append(index)
818 channelIndexList.append(index)
845
819
846 self.selectChannelsByIndex(channelIndexList)
820 self.selectChannelsByIndex(channelIndexList)
847
821
848 def selectChannelsByIndex(self, channelIndexList):
822 def selectChannelsByIndex(self, channelIndexList):
849 """
823 """
850 Selecciona un bloque de datos en base a canales segun el channelIndexList
824 Selecciona un bloque de datos en base a canales segun el channelIndexList
851
825
852 Input:
826 Input:
853 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
827 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
854
828
855 Affected:
829 Affected:
856 self.dataOut.data_spc
830 self.dataOut.data_spc
857 self.dataOut.channelIndexList
831 self.dataOut.channelIndexList
858 self.dataOut.nChannels
832 self.dataOut.nChannels
859
833
860 Return:
834 Return:
861 None
835 None
862 """
836 """
863
837
864 for channelIndex in channelIndexList:
838 for channelIndex in channelIndexList:
865 if channelIndex not in self.dataOut.channelIndexList:
839 if channelIndex not in self.dataOut.channelIndexList:
866 print channelIndexList
840 print channelIndexList
867 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
841 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
868
842
869 nChannels = len(channelIndexList)
843 nChannels = len(channelIndexList)
870
844
871 data_spc = self.dataOut.data_spc[channelIndexList,:]
845 data_spc = self.dataOut.data_spc[channelIndexList,:]
872
846
873 self.dataOut.data_spc = data_spc
847 self.dataOut.data_spc = data_spc
874 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
848 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
875 # self.dataOut.nChannels = nChannels
849 # self.dataOut.nChannels = nChannels
876
850
877 return 1
851 return 1
878
852
879 def selectHeights(self, minHei, maxHei):
853 def selectHeights(self, minHei, maxHei):
880 """
854 """
881 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
855 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
882 minHei <= height <= maxHei
856 minHei <= height <= maxHei
883
857
884 Input:
858 Input:
885 minHei : valor minimo de altura a considerar
859 minHei : valor minimo de altura a considerar
886 maxHei : valor maximo de altura a considerar
860 maxHei : valor maximo de altura a considerar
887
861
888 Affected:
862 Affected:
889 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
863 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
890
864
891 Return:
865 Return:
892 1 si el metodo se ejecuto con exito caso contrario devuelve 0
866 1 si el metodo se ejecuto con exito caso contrario devuelve 0
893 """
867 """
894 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
868 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
895 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
869 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
896
870
897 if (maxHei > self.dataOut.heightList[-1]):
871 if (maxHei > self.dataOut.heightList[-1]):
898 maxHei = self.dataOut.heightList[-1]
872 maxHei = self.dataOut.heightList[-1]
899 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
873 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
900
874
901 minIndex = 0
875 minIndex = 0
902 maxIndex = 0
876 maxIndex = 0
903 heights = self.dataOut.heightList
877 heights = self.dataOut.heightList
904
878
905 inda = numpy.where(heights >= minHei)
879 inda = numpy.where(heights >= minHei)
906 indb = numpy.where(heights <= maxHei)
880 indb = numpy.where(heights <= maxHei)
907
881
908 try:
882 try:
909 minIndex = inda[0][0]
883 minIndex = inda[0][0]
910 except:
884 except:
911 minIndex = 0
885 minIndex = 0
912
886
913 try:
887 try:
914 maxIndex = indb[0][-1]
888 maxIndex = indb[0][-1]
915 except:
889 except:
916 maxIndex = len(heights)
890 maxIndex = len(heights)
917
891
918 self.selectHeightsByIndex(minIndex, maxIndex)
892 self.selectHeightsByIndex(minIndex, maxIndex)
919
893
920 return 1
894 return 1
921
895
922
896
923 def selectHeightsByIndex(self, minIndex, maxIndex):
897 def selectHeightsByIndex(self, minIndex, maxIndex):
924 """
898 """
925 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
899 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
926 minIndex <= index <= maxIndex
900 minIndex <= index <= maxIndex
927
901
928 Input:
902 Input:
929 minIndex : valor de indice minimo de altura a considerar
903 minIndex : valor de indice minimo de altura a considerar
930 maxIndex : valor de indice maximo de altura a considerar
904 maxIndex : valor de indice maximo de altura a considerar
931
905
932 Affected:
906 Affected:
933 self.dataOut.data_spc
907 self.dataOut.data_spc
934 self.dataOut.data_cspc
908 self.dataOut.data_cspc
935 self.dataOut.data_dc
909 self.dataOut.data_dc
936 self.dataOut.heightList
910 self.dataOut.heightList
937
911
938 Return:
912 Return:
939 1 si el metodo se ejecuto con exito caso contrario devuelve 0
913 1 si el metodo se ejecuto con exito caso contrario devuelve 0
940 """
914 """
941
915
942 if (minIndex < 0) or (minIndex > maxIndex):
916 if (minIndex < 0) or (minIndex > maxIndex):
943 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
917 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
944
918
945 if (maxIndex >= self.dataOut.nHeights):
919 if (maxIndex >= self.dataOut.nHeights):
946 maxIndex = self.dataOut.nHeights-1
920 maxIndex = self.dataOut.nHeights-1
947 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
921 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
948
922
949 nHeights = maxIndex - minIndex + 1
923 nHeights = maxIndex - minIndex + 1
950
924
951 #Spectra
925 #Spectra
952 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
926 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
953
927
954 data_cspc = None
928 data_cspc = None
955 if self.dataOut.data_cspc != None:
929 if self.dataOut.data_cspc != None:
956 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
930 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
957
931
958 data_dc = None
932 data_dc = None
959 if self.dataOut.data_dc != None:
933 if self.dataOut.data_dc != None:
960 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
934 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
961
935
962 self.dataOut.data_spc = data_spc
936 self.dataOut.data_spc = data_spc
963 self.dataOut.data_cspc = data_cspc
937 self.dataOut.data_cspc = data_cspc
964 self.dataOut.data_dc = data_dc
938 self.dataOut.data_dc = data_dc
965
939
966 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
940 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
967
941
968 return 1
942 return 1
969
943
970 def removeDC(self, mode = 1):
944 def removeDC(self, mode = 1):
971
945
972 dc_index = 0
946 dc_index = 0
973 freq_index = numpy.array([-2,-1,1,2])
947 freq_index = numpy.array([-2,-1,1,2])
974 data_spc = self.dataOut.data_spc
948 data_spc = self.dataOut.data_spc
975 data_cspc = self.dataOut.data_cspc
949 data_cspc = self.dataOut.data_cspc
976 data_dc = self.dataOut.data_dc
950 data_dc = self.dataOut.data_dc
977
951
978 if self.dataOut.flagShiftFFT:
952 if self.dataOut.flagShiftFFT:
979 dc_index += self.dataOut.nFFTPoints/2
953 dc_index += self.dataOut.nFFTPoints/2
980 freq_index += self.dataOut.nFFTPoints/2
954 freq_index += self.dataOut.nFFTPoints/2
981
955
982 if mode == 1:
956 if mode == 1:
983 data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2
957 data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2
984 if data_cspc != None:
958 if data_cspc != None:
985 data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2
959 data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2
986 return 1
960 return 1
987
961
988 if mode == 2:
962 if mode == 2:
989 pass
963 pass
990
964
991 if mode == 3:
965 if mode == 3:
992 pass
966 pass
993
967
994 raise ValueError, "mode parameter has to be 1, 2 or 3"
968 raise ValueError, "mode parameter has to be 1, 2 or 3"
995
969
996 def removeInterference(self):
970 def removeInterference(self):
997
971
998 pass
972 pass
999
973
1000
974
1001 class IncohInt(Operation):
975 class IncohInt(Operation):
1002
976
1003
977
1004 __profIndex = 0
978 __profIndex = 0
1005 __withOverapping = False
979 __withOverapping = False
1006
980
1007 __byTime = False
981 __byTime = False
1008 __initime = None
982 __initime = None
1009 __lastdatatime = None
983 __lastdatatime = None
1010 __integrationtime = None
984 __integrationtime = None
1011
985
1012 __buffer_spc = None
986 __buffer_spc = None
1013 __buffer_cspc = None
987 __buffer_cspc = None
1014 __buffer_dc = None
988 __buffer_dc = None
1015
989
1016 __dataReady = False
990 __dataReady = False
1017
991
1018 __timeInterval = None
992 __timeInterval = None
1019
993
1020 n = None
994 n = None
1021
995
1022
996
1023
997
1024 def __init__(self):
998 def __init__(self):
1025
999
1026 self.__isConfig = False
1000 self.__isConfig = False
1027
1001
1028 def setup(self, n=None, timeInterval=None, overlapping=False):
1002 def setup(self, n=None, timeInterval=None, overlapping=False):
1029 """
1003 """
1030 Set the parameters of the integration class.
1004 Set the parameters of the integration class.
1031
1005
1032 Inputs:
1006 Inputs:
1033
1007
1034 n : Number of coherent integrations
1008 n : Number of coherent integrations
1035 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1009 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1036 overlapping :
1010 overlapping :
1037
1011
1038 """
1012 """
1039
1013
1040 self.__initime = None
1014 self.__initime = None
1041 self.__lastdatatime = 0
1015 self.__lastdatatime = 0
1042 self.__buffer_spc = None
1016 self.__buffer_spc = None
1043 self.__buffer_cspc = None
1017 self.__buffer_cspc = None
1044 self.__buffer_dc = None
1018 self.__buffer_dc = None
1045 self.__dataReady = False
1019 self.__dataReady = False
1046
1020
1047
1021
1048 if n == None and timeInterval == None:
1022 if n == None and timeInterval == None:
1049 raise ValueError, "n or timeInterval should be specified ..."
1023 raise ValueError, "n or timeInterval should be specified ..."
1050
1024
1051 if n != None:
1025 if n != None:
1052 self.n = n
1026 self.n = n
1053 self.__byTime = False
1027 self.__byTime = False
1054 else:
1028 else:
1055 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
1029 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
1056 self.n = 9999
1030 self.n = 9999
1057 self.__byTime = True
1031 self.__byTime = True
1058
1032
1059 if overlapping:
1033 if overlapping:
1060 self.__withOverapping = True
1034 self.__withOverapping = True
1061 else:
1035 else:
1062 self.__withOverapping = False
1036 self.__withOverapping = False
1063 self.__buffer_spc = 0
1037 self.__buffer_spc = 0
1064 self.__buffer_cspc = 0
1038 self.__buffer_cspc = 0
1065 self.__buffer_dc = 0
1039 self.__buffer_dc = 0
1066
1040
1067 self.__profIndex = 0
1041 self.__profIndex = 0
1068
1042
1069 def putData(self, data_spc, data_cspc, data_dc):
1043 def putData(self, data_spc, data_cspc, data_dc):
1070
1044
1071 """
1045 """
1072 Add a profile to the __buffer_spc and increase in one the __profileIndex
1046 Add a profile to the __buffer_spc and increase in one the __profileIndex
1073
1047
1074 """
1048 """
1075
1049
1076 if not self.__withOverapping:
1050 if not self.__withOverapping:
1077 self.__buffer_spc += data_spc
1051 self.__buffer_spc += data_spc
1078
1052
1079 if data_cspc == None:
1053 if data_cspc == None:
1080 self.__buffer_cspc = None
1054 self.__buffer_cspc = None
1081 else:
1055 else:
1082 self.__buffer_cspc += data_cspc
1056 self.__buffer_cspc += data_cspc
1083
1057
1084 if data_dc == None:
1058 if data_dc == None:
1085 self.__buffer_dc = None
1059 self.__buffer_dc = None
1086 else:
1060 else:
1087 self.__buffer_dc += data_dc
1061 self.__buffer_dc += data_dc
1088
1062
1089 self.__profIndex += 1
1063 self.__profIndex += 1
1090 return
1064 return
1091
1065
1092 #Overlapping data
1066 #Overlapping data
1093 nChannels, nFFTPoints, nHeis = data_spc.shape
1067 nChannels, nFFTPoints, nHeis = data_spc.shape
1094 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1068 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1095 if data_cspc != None:
1069 if data_cspc != None:
1096 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1070 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1097 if data_dc != None:
1071 if data_dc != None:
1098 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1072 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1099
1073
1100 #If the buffer is empty then it takes the data value
1074 #If the buffer is empty then it takes the data value
1101 if self.__buffer_spc == None:
1075 if self.__buffer_spc == None:
1102 self.__buffer_spc = data_spc
1076 self.__buffer_spc = data_spc
1103
1077
1104 if data_cspc == None:
1078 if data_cspc == None:
1105 self.__buffer_cspc = None
1079 self.__buffer_cspc = None
1106 else:
1080 else:
1107 self.__buffer_cspc += data_cspc
1081 self.__buffer_cspc += data_cspc
1108
1082
1109 if data_dc == None:
1083 if data_dc == None:
1110 self.__buffer_dc = None
1084 self.__buffer_dc = None
1111 else:
1085 else:
1112 self.__buffer_dc += data_dc
1086 self.__buffer_dc += data_dc
1113
1087
1114 self.__profIndex += 1
1088 self.__profIndex += 1
1115 return
1089 return
1116
1090
1117 #If the buffer length is lower than n then stakcing the data value
1091 #If the buffer length is lower than n then stakcing the data value
1118 if self.__profIndex < self.n:
1092 if self.__profIndex < self.n:
1119 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1093 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1120
1094
1121 if data_cspc != None:
1095 if data_cspc != None:
1122 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1096 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1123
1097
1124 if data_dc != None:
1098 if data_dc != None:
1125 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1099 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1126
1100
1127 self.__profIndex += 1
1101 self.__profIndex += 1
1128 return
1102 return
1129
1103
1130 #If the buffer length is equal to n then replacing the last buffer value with the data value
1104 #If the buffer length is equal to n then replacing the last buffer value with the data value
1131 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1105 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1132 self.__buffer_spc[self.n-1] = data_spc
1106 self.__buffer_spc[self.n-1] = data_spc
1133
1107
1134 if data_cspc != None:
1108 if data_cspc != None:
1135 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1109 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1136 self.__buffer_cspc[self.n-1] = data_cspc
1110 self.__buffer_cspc[self.n-1] = data_cspc
1137
1111
1138 if data_dc != None:
1112 if data_dc != None:
1139 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1113 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1140 self.__buffer_dc[self.n-1] = data_dc
1114 self.__buffer_dc[self.n-1] = data_dc
1141
1115
1142 self.__profIndex = self.n
1116 self.__profIndex = self.n
1143 return
1117 return
1144
1118
1145
1119
1146 def pushData(self):
1120 def pushData(self):
1147 """
1121 """
1148 Return the sum of the last profiles and the profiles used in the sum.
1122 Return the sum of the last profiles and the profiles used in the sum.
1149
1123
1150 Affected:
1124 Affected:
1151
1125
1152 self.__profileIndex
1126 self.__profileIndex
1153
1127
1154 """
1128 """
1155 data_spc = None
1129 data_spc = None
1156 data_cspc = None
1130 data_cspc = None
1157 data_dc = None
1131 data_dc = None
1158
1132
1159 if not self.__withOverapping:
1133 if not self.__withOverapping:
1160 data_spc = self.__buffer_spc
1134 data_spc = self.__buffer_spc
1161 data_cspc = self.__buffer_cspc
1135 data_cspc = self.__buffer_cspc
1162 data_dc = self.__buffer_dc
1136 data_dc = self.__buffer_dc
1163
1137
1164 n = self.__profIndex
1138 n = self.__profIndex
1165
1139
1166 self.__buffer_spc = 0
1140 self.__buffer_spc = 0
1167 self.__buffer_cspc = 0
1141 self.__buffer_cspc = 0
1168 self.__buffer_dc = 0
1142 self.__buffer_dc = 0
1169 self.__profIndex = 0
1143 self.__profIndex = 0
1170
1144
1171 return data_spc, data_cspc, data_dc, n
1145 return data_spc, data_cspc, data_dc, n
1172
1146
1173 #Integration with Overlapping
1147 #Integration with Overlapping
1174 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1148 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1175
1149
1176 if self.__buffer_cspc != None:
1150 if self.__buffer_cspc != None:
1177 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1151 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1178
1152
1179 if self.__buffer_dc != None:
1153 if self.__buffer_dc != None:
1180 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1154 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1181
1155
1182 n = self.__profIndex
1156 n = self.__profIndex
1183
1157
1184 return data_spc, data_cspc, data_dc, n
1158 return data_spc, data_cspc, data_dc, n
1185
1159
1186 def byProfiles(self, *args):
1160 def byProfiles(self, *args):
1187
1161
1188 self.__dataReady = False
1162 self.__dataReady = False
1189 avgdata_spc = None
1163 avgdata_spc = None
1190 avgdata_cspc = None
1164 avgdata_cspc = None
1191 avgdata_dc = None
1165 avgdata_dc = None
1192 n = None
1166 n = None
1193
1167
1194 self.putData(*args)
1168 self.putData(*args)
1195
1169
1196 if self.__profIndex == self.n:
1170 if self.__profIndex == self.n:
1197
1171
1198 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1172 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1199 self.__dataReady = True
1173 self.__dataReady = True
1200
1174
1201 return avgdata_spc, avgdata_cspc, avgdata_dc
1175 return avgdata_spc, avgdata_cspc, avgdata_dc
1202
1176
1203 def byTime(self, datatime, *args):
1177 def byTime(self, datatime, *args):
1204
1178
1205 self.__dataReady = False
1179 self.__dataReady = False
1206 avgdata_spc = None
1180 avgdata_spc = None
1207 avgdata_cspc = None
1181 avgdata_cspc = None
1208 avgdata_dc = None
1182 avgdata_dc = None
1209 n = None
1183 n = None
1210
1184
1211 self.putData(*args)
1185 self.putData(*args)
1212
1186
1213 if (datatime - self.__initime) >= self.__integrationtime:
1187 if (datatime - self.__initime) >= self.__integrationtime:
1214 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1188 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1215 self.n = n
1189 self.n = n
1216 self.__dataReady = True
1190 self.__dataReady = True
1217
1191
1218 return avgdata_spc, avgdata_cspc, avgdata_dc
1192 return avgdata_spc, avgdata_cspc, avgdata_dc
1219
1193
1220 def integrate(self, datatime, *args):
1194 def integrate(self, datatime, *args):
1221
1195
1222 if self.__initime == None:
1196 if self.__initime == None:
1223 self.__initime = datatime
1197 self.__initime = datatime
1224
1198
1225 if self.__byTime:
1199 if self.__byTime:
1226 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1200 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1227 else:
1201 else:
1228 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1202 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1229
1203
1230 self.__lastdatatime = datatime
1204 self.__lastdatatime = datatime
1231
1205
1232 if avgdata_spc == None:
1206 if avgdata_spc == None:
1233 return None, None, None, None
1207 return None, None, None, None
1234
1208
1235 avgdatatime = self.__initime
1209 avgdatatime = self.__initime
1236 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1210 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1237
1211
1238 deltatime = datatime -self.__lastdatatime
1212 deltatime = datatime -self.__lastdatatime
1239
1213
1240 if not self.__withOverapping:
1214 if not self.__withOverapping:
1241 self.__initime = datatime
1215 self.__initime = datatime
1242 else:
1216 else:
1243 self.__initime += deltatime
1217 self.__initime += deltatime
1244
1218
1245 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1219 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1246
1220
1247 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1221 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1248
1222
1249 if not self.__isConfig:
1223 if not self.__isConfig:
1250 self.setup(n, timeInterval, overlapping)
1224 self.setup(n, timeInterval, overlapping)
1251 self.__isConfig = True
1225 self.__isConfig = True
1252
1226
1253 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1227 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1254 dataOut.data_spc,
1228 dataOut.data_spc,
1255 dataOut.data_cspc,
1229 dataOut.data_cspc,
1256 dataOut.data_dc)
1230 dataOut.data_dc)
1257
1231
1258 # dataOut.timeInterval *= n
1232 # dataOut.timeInterval *= n
1259 dataOut.flagNoData = True
1233 dataOut.flagNoData = True
1260
1234
1261 if self.__dataReady:
1235 if self.__dataReady:
1262
1236
1263 dataOut.data_spc = avgdata_spc
1237 dataOut.data_spc = avgdata_spc
1264 dataOut.data_cspc = avgdata_cspc
1238 dataOut.data_cspc = avgdata_cspc
1265 dataOut.data_dc = avgdata_dc
1239 dataOut.data_dc = avgdata_dc
1266
1240
1267 dataOut.nIncohInt *= self.n
1241 dataOut.nIncohInt *= self.n
1268 dataOut.utctime = avgdatatime
1242 dataOut.utctime = avgdatatime
1269 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1243 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1270 dataOut.timeInterval = self.__timeInterval*self.n
1244 dataOut.timeInterval = self.__timeInterval*self.n
1271 dataOut.flagNoData = False
1245 dataOut.flagNoData = False
1272
1246
1273 class ProfileSelector(Operation):
1247 class ProfileSelector(Operation):
1274
1248
1275 profileIndex = None
1249 profileIndex = None
1276 # Tamanho total de los perfiles
1250 # Tamanho total de los perfiles
1277 nProfiles = None
1251 nProfiles = None
1278
1252
1279 def __init__(self):
1253 def __init__(self):
1280
1254
1281 self.profileIndex = 0
1255 self.profileIndex = 0
1282
1256
1283 def incIndex(self):
1257 def incIndex(self):
1284 self.profileIndex += 1
1258 self.profileIndex += 1
1285
1259
1286 if self.profileIndex >= self.nProfiles:
1260 if self.profileIndex >= self.nProfiles:
1287 self.profileIndex = 0
1261 self.profileIndex = 0
1288
1262
1289 def isProfileInRange(self, minIndex, maxIndex):
1263 def isProfileInRange(self, minIndex, maxIndex):
1290
1264
1291 if self.profileIndex < minIndex:
1265 if self.profileIndex < minIndex:
1292 return False
1266 return False
1293
1267
1294 if self.profileIndex > maxIndex:
1268 if self.profileIndex > maxIndex:
1295 return False
1269 return False
1296
1270
1297 return True
1271 return True
1298
1272
1299 def isProfileInList(self, profileList):
1273 def isProfileInList(self, profileList):
1300
1274
1301 if self.profileIndex not in profileList:
1275 if self.profileIndex not in profileList:
1302 return False
1276 return False
1303
1277
1304 return True
1278 return True
1305
1279
1306 def run(self, dataOut, profileList=None, profileRangeList=None):
1280 def run(self, dataOut, profileList=None, profileRangeList=None):
1307
1281
1308 dataOut.flagNoData = True
1282 dataOut.flagNoData = True
1309 self.nProfiles = dataOut.nProfiles
1283 self.nProfiles = dataOut.nProfiles
1310
1284
1311 if profileList != None:
1285 if profileList != None:
1312 if self.isProfileInList(profileList):
1286 if self.isProfileInList(profileList):
1313 dataOut.flagNoData = False
1287 dataOut.flagNoData = False
1314
1288
1315 self.incIndex()
1289 self.incIndex()
1316 return 1
1290 return 1
1317
1291
1318
1292
1319 elif profileRangeList != None:
1293 elif profileRangeList != None:
1320 minIndex = profileRangeList[0]
1294 minIndex = profileRangeList[0]
1321 maxIndex = profileRangeList[1]
1295 maxIndex = profileRangeList[1]
1322 if self.isProfileInRange(minIndex, maxIndex):
1296 if self.isProfileInRange(minIndex, maxIndex):
1323 dataOut.flagNoData = False
1297 dataOut.flagNoData = False
1324
1298
1325 self.incIndex()
1299 self.incIndex()
1326 return 1
1300 return 1
1327
1301
1328 else:
1302 else:
1329 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1303 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1330
1304
1331 return 0
1305 return 0
1332
1306
General Comments 0
You need to be logged in to leave comments. Login now