##// END OF EJS Templates
Se agrega la Operacion ProfileConcat para concatenar perfiles de radar, esta operacion se pretende usar en el Experimento MST-ISR.
Daniel Valdez -
r430:9c7dee303a91
parent child
Show More
@@ -1,1656 +1,1702
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=None, maxHei=None):
276 def selectHeights(self, minHei=None, maxHei=None):
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
291
292 if minHei == None:
292 if minHei == None:
293 minHei = self.dataOut.heightList[0]
293 minHei = self.dataOut.heightList[0]
294
294
295 if maxHei == None:
295 if maxHei == None:
296 maxHei = self.dataOut.heightList[-1]
296 maxHei = self.dataOut.heightList[-1]
297
297
298 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
298 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
299 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
299 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
300
300
301
301
302 if (maxHei > self.dataOut.heightList[-1]):
302 if (maxHei > self.dataOut.heightList[-1]):
303 maxHei = self.dataOut.heightList[-1]
303 maxHei = self.dataOut.heightList[-1]
304 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
304 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
305
305
306 minIndex = 0
306 minIndex = 0
307 maxIndex = 0
307 maxIndex = 0
308 heights = self.dataOut.heightList
308 heights = self.dataOut.heightList
309
309
310 inda = numpy.where(heights >= minHei)
310 inda = numpy.where(heights >= minHei)
311 indb = numpy.where(heights <= maxHei)
311 indb = numpy.where(heights <= maxHei)
312
312
313 try:
313 try:
314 minIndex = inda[0][0]
314 minIndex = inda[0][0]
315 except:
315 except:
316 minIndex = 0
316 minIndex = 0
317
317
318 try:
318 try:
319 maxIndex = indb[0][-1]
319 maxIndex = indb[0][-1]
320 except:
320 except:
321 maxIndex = len(heights)
321 maxIndex = len(heights)
322
322
323 self.selectHeightsByIndex(minIndex, maxIndex)
323 self.selectHeightsByIndex(minIndex, maxIndex)
324
324
325 return 1
325 return 1
326
326
327
327
328 def selectHeightsByIndex(self, minIndex, maxIndex):
328 def selectHeightsByIndex(self, minIndex, maxIndex):
329 """
329 """
330 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
330 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
331 minIndex <= index <= maxIndex
331 minIndex <= index <= maxIndex
332
332
333 Input:
333 Input:
334 minIndex : valor de indice minimo de altura a considerar
334 minIndex : valor de indice minimo de altura a considerar
335 maxIndex : valor de indice maximo de altura a considerar
335 maxIndex : valor de indice maximo de altura a considerar
336
336
337 Affected:
337 Affected:
338 self.dataOut.data
338 self.dataOut.data
339 self.dataOut.heightList
339 self.dataOut.heightList
340
340
341 Return:
341 Return:
342 1 si el metodo se ejecuto con exito caso contrario devuelve 0
342 1 si el metodo se ejecuto con exito caso contrario devuelve 0
343 """
343 """
344
344
345 if (minIndex < 0) or (minIndex > maxIndex):
345 if (minIndex < 0) or (minIndex > maxIndex):
346 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
346 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
347
347
348 if (maxIndex >= self.dataOut.nHeights):
348 if (maxIndex >= self.dataOut.nHeights):
349 maxIndex = self.dataOut.nHeights-1
349 maxIndex = self.dataOut.nHeights-1
350 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
350 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
351
351
352 nHeights = maxIndex - minIndex + 1
352 nHeights = maxIndex - minIndex + 1
353
353
354 #voltage
354 #voltage
355 data = self.dataOut.data[:,minIndex:maxIndex+1]
355 data = self.dataOut.data[:,minIndex:maxIndex+1]
356
356
357 firstHeight = self.dataOut.heightList[minIndex]
357 firstHeight = self.dataOut.heightList[minIndex]
358
358
359 self.dataOut.data = data
359 self.dataOut.data = data
360 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
360 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
361
361
362 return 1
362 return 1
363
363
364
364
365 def filterByHeights(self, window):
365 def filterByHeights(self, window):
366 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
366 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
367
367
368 if window == None:
368 if window == None:
369 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
369 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
370
370
371 newdelta = deltaHeight * window
371 newdelta = deltaHeight * window
372 r = self.dataOut.data.shape[1] % window
372 r = self.dataOut.data.shape[1] % window
373 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
373 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
374 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
374 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
375 buffer = numpy.sum(buffer,2)
375 buffer = numpy.sum(buffer,2)
376 self.dataOut.data = buffer
376 self.dataOut.data = buffer
377 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta)
377 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta)
378 self.dataOut.windowOfFilter = window
378 self.dataOut.windowOfFilter = window
379
379
380 def deFlip(self):
380 def deFlip(self):
381 self.dataOut.data *= self.flip
381 self.dataOut.data *= self.flip
382 self.flip *= -1.
382 self.flip *= -1.
383
383
384 def setRadarFrequency(self, frequency=None):
384 def setRadarFrequency(self, frequency=None):
385 if frequency != None:
385 if frequency != None:
386 self.dataOut.frequency = frequency
386 self.dataOut.frequency = frequency
387
387
388 return 1
388 return 1
389
389
390 class CohInt(Operation):
390 class CohInt(Operation):
391
391
392 __isConfig = False
392 __isConfig = False
393
393
394 __profIndex = 0
394 __profIndex = 0
395 __withOverapping = False
395 __withOverapping = False
396
396
397 __byTime = False
397 __byTime = False
398 __initime = None
398 __initime = None
399 __lastdatatime = None
399 __lastdatatime = None
400 __integrationtime = None
400 __integrationtime = None
401
401
402 __buffer = None
402 __buffer = None
403
403
404 __dataReady = False
404 __dataReady = False
405
405
406 n = None
406 n = None
407
407
408
408
409 def __init__(self):
409 def __init__(self):
410
410
411 self.__isConfig = False
411 self.__isConfig = False
412
412
413 def setup(self, n=None, timeInterval=None, overlapping=False):
413 def setup(self, n=None, timeInterval=None, overlapping=False):
414 """
414 """
415 Set the parameters of the integration class.
415 Set the parameters of the integration class.
416
416
417 Inputs:
417 Inputs:
418
418
419 n : Number of coherent integrations
419 n : Number of coherent integrations
420 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
420 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
421 overlapping :
421 overlapping :
422
422
423 """
423 """
424
424
425 self.__initime = None
425 self.__initime = None
426 self.__lastdatatime = 0
426 self.__lastdatatime = 0
427 self.__buffer = None
427 self.__buffer = None
428 self.__dataReady = False
428 self.__dataReady = False
429
429
430
430
431 if n == None and timeInterval == None:
431 if n == None and timeInterval == None:
432 raise ValueError, "n or timeInterval should be specified ..."
432 raise ValueError, "n or timeInterval should be specified ..."
433
433
434 if n != None:
434 if n != None:
435 self.n = n
435 self.n = n
436 self.__byTime = False
436 self.__byTime = False
437 else:
437 else:
438 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
438 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
439 self.n = 9999
439 self.n = 9999
440 self.__byTime = True
440 self.__byTime = True
441
441
442 if overlapping:
442 if overlapping:
443 self.__withOverapping = True
443 self.__withOverapping = True
444 self.__buffer = None
444 self.__buffer = None
445 else:
445 else:
446 self.__withOverapping = False
446 self.__withOverapping = False
447 self.__buffer = 0
447 self.__buffer = 0
448
448
449 self.__profIndex = 0
449 self.__profIndex = 0
450
450
451 def putData(self, data):
451 def putData(self, data):
452
452
453 """
453 """
454 Add a profile to the __buffer and increase in one the __profileIndex
454 Add a profile to the __buffer and increase in one the __profileIndex
455
455
456 """
456 """
457
457
458 if not self.__withOverapping:
458 if not self.__withOverapping:
459 self.__buffer += data.copy()
459 self.__buffer += data.copy()
460 self.__profIndex += 1
460 self.__profIndex += 1
461 return
461 return
462
462
463 #Overlapping data
463 #Overlapping data
464 nChannels, nHeis = data.shape
464 nChannels, nHeis = data.shape
465 data = numpy.reshape(data, (1, nChannels, nHeis))
465 data = numpy.reshape(data, (1, nChannels, nHeis))
466
466
467 #If the buffer is empty then it takes the data value
467 #If the buffer is empty then it takes the data value
468 if self.__buffer == None:
468 if self.__buffer == None:
469 self.__buffer = data
469 self.__buffer = data
470 self.__profIndex += 1
470 self.__profIndex += 1
471 return
471 return
472
472
473 #If the buffer length is lower than n then stakcing the data value
473 #If the buffer length is lower than n then stakcing the data value
474 if self.__profIndex < self.n:
474 if self.__profIndex < self.n:
475 self.__buffer = numpy.vstack((self.__buffer, data))
475 self.__buffer = numpy.vstack((self.__buffer, data))
476 self.__profIndex += 1
476 self.__profIndex += 1
477 return
477 return
478
478
479 #If the buffer length is equal to n then replacing the last buffer value with the data value
479 #If the buffer length is equal to n then replacing the last buffer value with the data value
480 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
480 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
481 self.__buffer[self.n-1] = data
481 self.__buffer[self.n-1] = data
482 self.__profIndex = self.n
482 self.__profIndex = self.n
483 return
483 return
484
484
485
485
486 def pushData(self):
486 def pushData(self):
487 """
487 """
488 Return the sum of the last profiles and the profiles used in the sum.
488 Return the sum of the last profiles and the profiles used in the sum.
489
489
490 Affected:
490 Affected:
491
491
492 self.__profileIndex
492 self.__profileIndex
493
493
494 """
494 """
495
495
496 if not self.__withOverapping:
496 if not self.__withOverapping:
497 data = self.__buffer
497 data = self.__buffer
498 n = self.__profIndex
498 n = self.__profIndex
499
499
500 self.__buffer = 0
500 self.__buffer = 0
501 self.__profIndex = 0
501 self.__profIndex = 0
502
502
503 return data, n
503 return data, n
504
504
505 #Integration with Overlapping
505 #Integration with Overlapping
506 data = numpy.sum(self.__buffer, axis=0)
506 data = numpy.sum(self.__buffer, axis=0)
507 n = self.__profIndex
507 n = self.__profIndex
508
508
509 return data, n
509 return data, n
510
510
511 def byProfiles(self, data):
511 def byProfiles(self, data):
512
512
513 self.__dataReady = False
513 self.__dataReady = False
514 avgdata = None
514 avgdata = None
515 n = None
515 n = None
516
516
517 self.putData(data)
517 self.putData(data)
518
518
519 if self.__profIndex == self.n:
519 if self.__profIndex == self.n:
520
520
521 avgdata, n = self.pushData()
521 avgdata, n = self.pushData()
522 self.__dataReady = True
522 self.__dataReady = True
523
523
524 return avgdata
524 return avgdata
525
525
526 def byTime(self, data, datatime):
526 def byTime(self, data, datatime):
527
527
528 self.__dataReady = False
528 self.__dataReady = False
529 avgdata = None
529 avgdata = None
530 n = None
530 n = None
531
531
532 self.putData(data)
532 self.putData(data)
533
533
534 if (datatime - self.__initime) >= self.__integrationtime:
534 if (datatime - self.__initime) >= self.__integrationtime:
535 avgdata, n = self.pushData()
535 avgdata, n = self.pushData()
536 self.n = n
536 self.n = n
537 self.__dataReady = True
537 self.__dataReady = True
538
538
539 return avgdata
539 return avgdata
540
540
541 def integrate(self, data, datatime=None):
541 def integrate(self, data, datatime=None):
542
542
543 if self.__initime == None:
543 if self.__initime == None:
544 self.__initime = datatime
544 self.__initime = datatime
545
545
546 if self.__byTime:
546 if self.__byTime:
547 avgdata = self.byTime(data, datatime)
547 avgdata = self.byTime(data, datatime)
548 else:
548 else:
549 avgdata = self.byProfiles(data)
549 avgdata = self.byProfiles(data)
550
550
551
551
552 self.__lastdatatime = datatime
552 self.__lastdatatime = datatime
553
553
554 if avgdata == None:
554 if avgdata == None:
555 return None, None
555 return None, None
556
556
557 avgdatatime = self.__initime
557 avgdatatime = self.__initime
558
558
559 deltatime = datatime -self.__lastdatatime
559 deltatime = datatime -self.__lastdatatime
560
560
561 if not self.__withOverapping:
561 if not self.__withOverapping:
562 self.__initime = datatime
562 self.__initime = datatime
563 else:
563 else:
564 self.__initime += deltatime
564 self.__initime += deltatime
565
565
566 return avgdata, avgdatatime
566 return avgdata, avgdatatime
567
567
568 def run(self, dataOut, **kwargs):
568 def run(self, dataOut, **kwargs):
569
569
570 if not self.__isConfig:
570 if not self.__isConfig:
571 self.setup(**kwargs)
571 self.setup(**kwargs)
572 self.__isConfig = True
572 self.__isConfig = True
573
573
574 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
574 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
575
575
576 # dataOut.timeInterval *= n
576 # dataOut.timeInterval *= n
577 dataOut.flagNoData = True
577 dataOut.flagNoData = True
578
578
579 if self.__dataReady:
579 if self.__dataReady:
580 dataOut.data = avgdata
580 dataOut.data = avgdata
581 dataOut.nCohInt *= self.n
581 dataOut.nCohInt *= self.n
582 dataOut.utctime = avgdatatime
582 dataOut.utctime = avgdatatime
583 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
583 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
584 dataOut.flagNoData = False
584 dataOut.flagNoData = False
585
585
586
586
587 class Decoder(Operation):
587 class Decoder(Operation):
588
588
589 __isConfig = False
589 __isConfig = False
590 __profIndex = 0
590 __profIndex = 0
591
591
592 code = None
592 code = None
593
593
594 nCode = None
594 nCode = None
595 nBaud = None
595 nBaud = None
596
596
597 def __init__(self):
597 def __init__(self):
598
598
599 self.__isConfig = False
599 self.__isConfig = False
600
600
601 def setup(self, code, shape):
601 def setup(self, code, shape):
602
602
603 self.__profIndex = 0
603 self.__profIndex = 0
604
604
605 self.code = code
605 self.code = code
606
606
607 self.nCode = len(code)
607 self.nCode = len(code)
608 self.nBaud = len(code[0])
608 self.nBaud = len(code[0])
609
609
610 self.__nChannels, self.__nHeis = shape
610 self.__nChannels, self.__nHeis = shape
611
611
612 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
612 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
613
613
614 __codeBuffer[:,0:self.nBaud] = self.code
614 __codeBuffer[:,0:self.nBaud] = self.code
615
615
616 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
616 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
617
617
618 self.ndatadec = self.__nHeis - self.nBaud + 1
618 self.ndatadec = self.__nHeis - self.nBaud + 1
619
619
620 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
620 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
621
621
622 def convolutionInFreq(self, data):
622 def convolutionInFreq(self, data):
623
623
624 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
624 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
625
625
626 fft_data = numpy.fft.fft(data, axis=1)
626 fft_data = numpy.fft.fft(data, axis=1)
627
627
628 conv = fft_data*fft_code
628 conv = fft_data*fft_code
629
629
630 data = numpy.fft.ifft(conv,axis=1)
630 data = numpy.fft.ifft(conv,axis=1)
631
631
632 datadec = data[:,:-self.nBaud+1]
632 datadec = data[:,:-self.nBaud+1]
633
633
634 return datadec
634 return datadec
635
635
636 def convolutionInFreqOpt(self, data):
636 def convolutionInFreqOpt(self, data):
637
637
638 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
638 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
639
639
640 data = cfunctions.decoder(fft_code, data)
640 data = cfunctions.decoder(fft_code, data)
641
641
642 datadec = data[:,:-self.nBaud+1]
642 datadec = data[:,:-self.nBaud+1]
643
643
644 return datadec
644 return datadec
645
645
646 def convolutionInTime(self, data):
646 def convolutionInTime(self, data):
647
647
648 code = self.code[self.__profIndex]
648 code = self.code[self.__profIndex]
649
649
650 for i in range(self.__nChannels):
650 for i in range(self.__nChannels):
651 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
651 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
652
652
653 return self.datadecTime
653 return self.datadecTime
654
654
655 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
655 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
656
656
657 if not self.__isConfig:
657 if not self.__isConfig:
658
658
659 if code == None:
659 if code == None:
660 code = dataOut.code
660 code = dataOut.code
661 else:
661 else:
662 code = numpy.array(code).reshape(nCode,nBaud)
662 code = numpy.array(code).reshape(nCode,nBaud)
663 dataOut.code = code
663 dataOut.code = code
664 dataOut.nCode = nCode
664 dataOut.nCode = nCode
665 dataOut.nBaud = nBaud
665 dataOut.nBaud = nBaud
666
666
667 if code == None:
667 if code == None:
668 return 1
668 return 1
669
669
670 self.setup(code, dataOut.data.shape)
670 self.setup(code, dataOut.data.shape)
671 self.__isConfig = True
671 self.__isConfig = True
672
672
673 if mode == 0:
673 if mode == 0:
674 datadec = self.convolutionInTime(dataOut.data)
674 datadec = self.convolutionInTime(dataOut.data)
675
675
676 if mode == 1:
676 if mode == 1:
677 datadec = self.convolutionInFreq(dataOut.data)
677 datadec = self.convolutionInFreq(dataOut.data)
678
678
679 if mode == 2:
679 if mode == 2:
680 datadec = self.convolutionInFreqOpt(dataOut.data)
680 datadec = self.convolutionInFreqOpt(dataOut.data)
681
681
682 dataOut.data = datadec
682 dataOut.data = datadec
683
683
684 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
684 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
685
685
686 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
686 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
687
687
688 if self.__profIndex == self.nCode-1:
688 if self.__profIndex == self.nCode-1:
689 self.__profIndex = 0
689 self.__profIndex = 0
690 return 1
690 return 1
691
691
692 self.__profIndex += 1
692 self.__profIndex += 1
693
693
694 return 1
694 return 1
695 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
695 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
696
696
697
697
698
698
699 class SpectraProc(ProcessingUnit):
699 class SpectraProc(ProcessingUnit):
700
700
701 def __init__(self):
701 def __init__(self):
702
702
703 self.objectDict = {}
703 self.objectDict = {}
704 self.buffer = None
704 self.buffer = None
705 self.firstdatatime = None
705 self.firstdatatime = None
706 self.profIndex = 0
706 self.profIndex = 0
707 self.dataOut = Spectra()
707 self.dataOut = Spectra()
708
708
709 def __updateObjFromInput(self):
709 def __updateObjFromInput(self):
710
710
711 self.dataOut.timeZone = self.dataIn.timeZone
711 self.dataOut.timeZone = self.dataIn.timeZone
712 self.dataOut.dstFlag = self.dataIn.dstFlag
712 self.dataOut.dstFlag = self.dataIn.dstFlag
713 self.dataOut.errorCount = self.dataIn.errorCount
713 self.dataOut.errorCount = self.dataIn.errorCount
714 self.dataOut.useLocalTime = self.dataIn.useLocalTime
714 self.dataOut.useLocalTime = self.dataIn.useLocalTime
715
715
716 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
716 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
717 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
717 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
718 self.dataOut.channelList = self.dataIn.channelList
718 self.dataOut.channelList = self.dataIn.channelList
719 self.dataOut.heightList = self.dataIn.heightList
719 self.dataOut.heightList = self.dataIn.heightList
720 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
720 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
721 # self.dataOut.nHeights = self.dataIn.nHeights
721 # self.dataOut.nHeights = self.dataIn.nHeights
722 # self.dataOut.nChannels = self.dataIn.nChannels
722 # self.dataOut.nChannels = self.dataIn.nChannels
723 self.dataOut.nBaud = self.dataIn.nBaud
723 self.dataOut.nBaud = self.dataIn.nBaud
724 self.dataOut.nCode = self.dataIn.nCode
724 self.dataOut.nCode = self.dataIn.nCode
725 self.dataOut.code = self.dataIn.code
725 self.dataOut.code = self.dataIn.code
726 self.dataOut.nProfiles = self.dataOut.nFFTPoints
726 self.dataOut.nProfiles = self.dataOut.nFFTPoints
727 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
727 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
728 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
728 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
729 self.dataOut.utctime = self.firstdatatime
729 self.dataOut.utctime = self.firstdatatime
730 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
730 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
731 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
731 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
732 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
732 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
733 self.dataOut.nCohInt = self.dataIn.nCohInt
733 self.dataOut.nCohInt = self.dataIn.nCohInt
734 self.dataOut.nIncohInt = 1
734 self.dataOut.nIncohInt = 1
735 self.dataOut.ippSeconds = self.dataIn.ippSeconds
735 self.dataOut.ippSeconds = self.dataIn.ippSeconds
736 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
736 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
737
737
738 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
738 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
739 self.dataOut.frequency = self.dataIn.frequency
739 self.dataOut.frequency = self.dataIn.frequency
740 self.dataOut.realtime = self.dataIn.realtime
740 self.dataOut.realtime = self.dataIn.realtime
741
741
742 def __getFft(self):
742 def __getFft(self):
743 """
743 """
744 Convierte valores de Voltaje a Spectra
744 Convierte valores de Voltaje a Spectra
745
745
746 Affected:
746 Affected:
747 self.dataOut.data_spc
747 self.dataOut.data_spc
748 self.dataOut.data_cspc
748 self.dataOut.data_cspc
749 self.dataOut.data_dc
749 self.dataOut.data_dc
750 self.dataOut.heightList
750 self.dataOut.heightList
751 self.profIndex
751 self.profIndex
752 self.buffer
752 self.buffer
753 self.dataOut.flagNoData
753 self.dataOut.flagNoData
754 """
754 """
755 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
755 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
756 fft_volt = fft_volt.astype(numpy.dtype('complex'))
756 fft_volt = fft_volt.astype(numpy.dtype('complex'))
757 dc = fft_volt[:,0,:]
757 dc = fft_volt[:,0,:]
758
758
759 #calculo de self-spectra
759 #calculo de self-spectra
760 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
760 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
761 spc = fft_volt * numpy.conjugate(fft_volt)
761 spc = fft_volt * numpy.conjugate(fft_volt)
762 spc = spc.real
762 spc = spc.real
763
763
764 blocksize = 0
764 blocksize = 0
765 blocksize += dc.size
765 blocksize += dc.size
766 blocksize += spc.size
766 blocksize += spc.size
767
767
768 cspc = None
768 cspc = None
769 pairIndex = 0
769 pairIndex = 0
770 if self.dataOut.pairsList != None:
770 if self.dataOut.pairsList != None:
771 #calculo de cross-spectra
771 #calculo de cross-spectra
772 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
772 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
773 for pair in self.dataOut.pairsList:
773 for pair in self.dataOut.pairsList:
774 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
774 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
775 pairIndex += 1
775 pairIndex += 1
776 blocksize += cspc.size
776 blocksize += cspc.size
777
777
778 self.dataOut.data_spc = spc
778 self.dataOut.data_spc = spc
779 self.dataOut.data_cspc = cspc
779 self.dataOut.data_cspc = cspc
780 self.dataOut.data_dc = dc
780 self.dataOut.data_dc = dc
781 self.dataOut.blockSize = blocksize
781 self.dataOut.blockSize = blocksize
782 self.dataOut.flagShiftFFT = False
782 self.dataOut.flagShiftFFT = False
783
783
784 def init(self, nProfiles=None, nFFTPoints=None, pairsList=None):
784 def init(self, nProfiles=None, nFFTPoints=None, pairsList=None):
785
785
786 self.dataOut.flagNoData = True
786 self.dataOut.flagNoData = True
787
787
788 if self.dataIn.type == "Spectra":
788 if self.dataIn.type == "Spectra":
789 self.dataOut.copy(self.dataIn)
789 self.dataOut.copy(self.dataIn)
790 return
790 return
791
791
792 if self.dataIn.type == "Voltage":
792 if self.dataIn.type == "Voltage":
793
793
794 if nFFTPoints == None:
794 if nFFTPoints == None:
795 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
795 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
796
796
797 if pairsList == None:
797 if pairsList == None:
798 nPairs = 0
798 nPairs = 0
799 else:
799 else:
800 nPairs = len(pairsList)
800 nPairs = len(pairsList)
801
801
802 self.dataOut.nFFTPoints = nFFTPoints
802 self.dataOut.nFFTPoints = nFFTPoints
803 self.dataOut.pairsList = pairsList
803 self.dataOut.pairsList = pairsList
804 self.dataOut.nPairs = nPairs
804 self.dataOut.nPairs = nPairs
805
805
806 if self.buffer == None:
806 if self.buffer == None:
807 self.buffer = numpy.zeros((self.dataIn.nChannels,
807 self.buffer = numpy.zeros((self.dataIn.nChannels,
808 nProfiles,
808 nProfiles,
809 self.dataIn.nHeights),
809 self.dataIn.nHeights),
810 dtype='complex')
810 dtype='complex')
811
811
812
812
813 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
813 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
814 self.profIndex += 1
814 self.profIndex += 1
815
815
816 if self.firstdatatime == None:
816 if self.firstdatatime == None:
817 self.firstdatatime = self.dataIn.utctime
817 self.firstdatatime = self.dataIn.utctime
818
818
819 if self.profIndex == nProfiles:
819 if self.profIndex == nProfiles:
820 self.__updateObjFromInput()
820 self.__updateObjFromInput()
821 self.__getFft()
821 self.__getFft()
822
822
823 self.dataOut.flagNoData = False
823 self.dataOut.flagNoData = False
824
824
825 self.buffer = None
825 self.buffer = None
826 self.firstdatatime = None
826 self.firstdatatime = None
827 self.profIndex = 0
827 self.profIndex = 0
828
828
829 return
829 return
830
830
831 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
831 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
832
832
833 def selectChannels(self, channelList):
833 def selectChannels(self, channelList):
834
834
835 channelIndexList = []
835 channelIndexList = []
836
836
837 for channel in channelList:
837 for channel in channelList:
838 index = self.dataOut.channelList.index(channel)
838 index = self.dataOut.channelList.index(channel)
839 channelIndexList.append(index)
839 channelIndexList.append(index)
840
840
841 self.selectChannelsByIndex(channelIndexList)
841 self.selectChannelsByIndex(channelIndexList)
842
842
843 def selectChannelsByIndex(self, channelIndexList):
843 def selectChannelsByIndex(self, channelIndexList):
844 """
844 """
845 Selecciona un bloque de datos en base a canales segun el channelIndexList
845 Selecciona un bloque de datos en base a canales segun el channelIndexList
846
846
847 Input:
847 Input:
848 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
848 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
849
849
850 Affected:
850 Affected:
851 self.dataOut.data_spc
851 self.dataOut.data_spc
852 self.dataOut.channelIndexList
852 self.dataOut.channelIndexList
853 self.dataOut.nChannels
853 self.dataOut.nChannels
854
854
855 Return:
855 Return:
856 None
856 None
857 """
857 """
858
858
859 for channelIndex in channelIndexList:
859 for channelIndex in channelIndexList:
860 if channelIndex not in self.dataOut.channelIndexList:
860 if channelIndex not in self.dataOut.channelIndexList:
861 print channelIndexList
861 print channelIndexList
862 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
862 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
863
863
864 nChannels = len(channelIndexList)
864 nChannels = len(channelIndexList)
865
865
866 data_spc = self.dataOut.data_spc[channelIndexList,:]
866 data_spc = self.dataOut.data_spc[channelIndexList,:]
867
867
868 self.dataOut.data_spc = data_spc
868 self.dataOut.data_spc = data_spc
869 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
869 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
870 # self.dataOut.nChannels = nChannels
870 # self.dataOut.nChannels = nChannels
871
871
872 return 1
872 return 1
873
873
874 def selectHeights(self, minHei, maxHei):
874 def selectHeights(self, minHei, maxHei):
875 """
875 """
876 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
876 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
877 minHei <= height <= maxHei
877 minHei <= height <= maxHei
878
878
879 Input:
879 Input:
880 minHei : valor minimo de altura a considerar
880 minHei : valor minimo de altura a considerar
881 maxHei : valor maximo de altura a considerar
881 maxHei : valor maximo de altura a considerar
882
882
883 Affected:
883 Affected:
884 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
884 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
885
885
886 Return:
886 Return:
887 1 si el metodo se ejecuto con exito caso contrario devuelve 0
887 1 si el metodo se ejecuto con exito caso contrario devuelve 0
888 """
888 """
889 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
889 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
890 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
890 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
891
891
892 if (maxHei > self.dataOut.heightList[-1]):
892 if (maxHei > self.dataOut.heightList[-1]):
893 maxHei = self.dataOut.heightList[-1]
893 maxHei = self.dataOut.heightList[-1]
894 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
894 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
895
895
896 minIndex = 0
896 minIndex = 0
897 maxIndex = 0
897 maxIndex = 0
898 heights = self.dataOut.heightList
898 heights = self.dataOut.heightList
899
899
900 inda = numpy.where(heights >= minHei)
900 inda = numpy.where(heights >= minHei)
901 indb = numpy.where(heights <= maxHei)
901 indb = numpy.where(heights <= maxHei)
902
902
903 try:
903 try:
904 minIndex = inda[0][0]
904 minIndex = inda[0][0]
905 except:
905 except:
906 minIndex = 0
906 minIndex = 0
907
907
908 try:
908 try:
909 maxIndex = indb[0][-1]
909 maxIndex = indb[0][-1]
910 except:
910 except:
911 maxIndex = len(heights)
911 maxIndex = len(heights)
912
912
913 self.selectHeightsByIndex(minIndex, maxIndex)
913 self.selectHeightsByIndex(minIndex, maxIndex)
914
914
915 return 1
915 return 1
916
916
917
917
918 def selectHeightsByIndex(self, minIndex, maxIndex):
918 def selectHeightsByIndex(self, minIndex, maxIndex):
919 """
919 """
920 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
920 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
921 minIndex <= index <= maxIndex
921 minIndex <= index <= maxIndex
922
922
923 Input:
923 Input:
924 minIndex : valor de indice minimo de altura a considerar
924 minIndex : valor de indice minimo de altura a considerar
925 maxIndex : valor de indice maximo de altura a considerar
925 maxIndex : valor de indice maximo de altura a considerar
926
926
927 Affected:
927 Affected:
928 self.dataOut.data_spc
928 self.dataOut.data_spc
929 self.dataOut.data_cspc
929 self.dataOut.data_cspc
930 self.dataOut.data_dc
930 self.dataOut.data_dc
931 self.dataOut.heightList
931 self.dataOut.heightList
932
932
933 Return:
933 Return:
934 1 si el metodo se ejecuto con exito caso contrario devuelve 0
934 1 si el metodo se ejecuto con exito caso contrario devuelve 0
935 """
935 """
936
936
937 if (minIndex < 0) or (minIndex > maxIndex):
937 if (minIndex < 0) or (minIndex > maxIndex):
938 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
938 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
939
939
940 if (maxIndex >= self.dataOut.nHeights):
940 if (maxIndex >= self.dataOut.nHeights):
941 maxIndex = self.dataOut.nHeights-1
941 maxIndex = self.dataOut.nHeights-1
942 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
942 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
943
943
944 nHeights = maxIndex - minIndex + 1
944 nHeights = maxIndex - minIndex + 1
945
945
946 #Spectra
946 #Spectra
947 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
947 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
948
948
949 data_cspc = None
949 data_cspc = None
950 if self.dataOut.data_cspc != None:
950 if self.dataOut.data_cspc != None:
951 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
951 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
952
952
953 data_dc = None
953 data_dc = None
954 if self.dataOut.data_dc != None:
954 if self.dataOut.data_dc != None:
955 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
955 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
956
956
957 self.dataOut.data_spc = data_spc
957 self.dataOut.data_spc = data_spc
958 self.dataOut.data_cspc = data_cspc
958 self.dataOut.data_cspc = data_cspc
959 self.dataOut.data_dc = data_dc
959 self.dataOut.data_dc = data_dc
960
960
961 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
961 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
962
962
963 return 1
963 return 1
964
964
965 def removeDC(self, mode = 1):
965 def removeDC(self, mode = 1):
966
966
967 dc_index = 0
967 dc_index = 0
968 freq_index = numpy.array([-2,-1,1,2])
968 freq_index = numpy.array([-2,-1,1,2])
969 data_spc = self.dataOut.data_spc
969 data_spc = self.dataOut.data_spc
970 data_cspc = self.dataOut.data_cspc
970 data_cspc = self.dataOut.data_cspc
971 data_dc = self.dataOut.data_dc
971 data_dc = self.dataOut.data_dc
972
972
973 if self.dataOut.flagShiftFFT:
973 if self.dataOut.flagShiftFFT:
974 dc_index += self.dataOut.nFFTPoints/2
974 dc_index += self.dataOut.nFFTPoints/2
975 freq_index += self.dataOut.nFFTPoints/2
975 freq_index += self.dataOut.nFFTPoints/2
976
976
977 if mode == 1:
977 if mode == 1:
978 data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2
978 data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2
979 if data_cspc != None:
979 if data_cspc != None:
980 data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2
980 data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2
981 return 1
981 return 1
982
982
983 if mode == 2:
983 if mode == 2:
984 pass
984 pass
985
985
986 if mode == 3:
986 if mode == 3:
987 pass
987 pass
988
988
989 raise ValueError, "mode parameter has to be 1, 2 or 3"
989 raise ValueError, "mode parameter has to be 1, 2 or 3"
990
990
991 def removeInterference(self):
991 def removeInterference(self):
992
992
993 pass
993 pass
994
994
995 def setRadarFrequency(self, frequency=None):
995 def setRadarFrequency(self, frequency=None):
996 if frequency != None:
996 if frequency != None:
997 self.dataOut.frequency = frequency
997 self.dataOut.frequency = frequency
998
998
999 return 1
999 return 1
1000
1000
1001
1001
1002 class IncohInt(Operation):
1002 class IncohInt(Operation):
1003
1003
1004
1004
1005 __profIndex = 0
1005 __profIndex = 0
1006 __withOverapping = False
1006 __withOverapping = False
1007
1007
1008 __byTime = False
1008 __byTime = False
1009 __initime = None
1009 __initime = None
1010 __lastdatatime = None
1010 __lastdatatime = None
1011 __integrationtime = None
1011 __integrationtime = None
1012
1012
1013 __buffer_spc = None
1013 __buffer_spc = None
1014 __buffer_cspc = None
1014 __buffer_cspc = None
1015 __buffer_dc = None
1015 __buffer_dc = None
1016
1016
1017 __dataReady = False
1017 __dataReady = False
1018
1018
1019 __timeInterval = None
1019 __timeInterval = None
1020
1020
1021 n = None
1021 n = None
1022
1022
1023
1023
1024
1024
1025 def __init__(self):
1025 def __init__(self):
1026
1026
1027 self.__isConfig = False
1027 self.__isConfig = False
1028
1028
1029 def setup(self, n=None, timeInterval=None, overlapping=False):
1029 def setup(self, n=None, timeInterval=None, overlapping=False):
1030 """
1030 """
1031 Set the parameters of the integration class.
1031 Set the parameters of the integration class.
1032
1032
1033 Inputs:
1033 Inputs:
1034
1034
1035 n : Number of coherent integrations
1035 n : Number of coherent integrations
1036 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1036 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1037 overlapping :
1037 overlapping :
1038
1038
1039 """
1039 """
1040
1040
1041 self.__initime = None
1041 self.__initime = None
1042 self.__lastdatatime = 0
1042 self.__lastdatatime = 0
1043 self.__buffer_spc = None
1043 self.__buffer_spc = None
1044 self.__buffer_cspc = None
1044 self.__buffer_cspc = None
1045 self.__buffer_dc = None
1045 self.__buffer_dc = None
1046 self.__dataReady = False
1046 self.__dataReady = False
1047
1047
1048
1048
1049 if n == None and timeInterval == None:
1049 if n == None and timeInterval == None:
1050 raise ValueError, "n or timeInterval should be specified ..."
1050 raise ValueError, "n or timeInterval should be specified ..."
1051
1051
1052 if n != None:
1052 if n != None:
1053 self.n = n
1053 self.n = n
1054 self.__byTime = False
1054 self.__byTime = False
1055 else:
1055 else:
1056 self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line
1056 self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line
1057 self.n = 9999
1057 self.n = 9999
1058 self.__byTime = True
1058 self.__byTime = True
1059
1059
1060 if overlapping:
1060 if overlapping:
1061 self.__withOverapping = True
1061 self.__withOverapping = True
1062 else:
1062 else:
1063 self.__withOverapping = False
1063 self.__withOverapping = False
1064 self.__buffer_spc = 0
1064 self.__buffer_spc = 0
1065 self.__buffer_cspc = 0
1065 self.__buffer_cspc = 0
1066 self.__buffer_dc = 0
1066 self.__buffer_dc = 0
1067
1067
1068 self.__profIndex = 0
1068 self.__profIndex = 0
1069
1069
1070 def putData(self, data_spc, data_cspc, data_dc):
1070 def putData(self, data_spc, data_cspc, data_dc):
1071
1071
1072 """
1072 """
1073 Add a profile to the __buffer_spc and increase in one the __profileIndex
1073 Add a profile to the __buffer_spc and increase in one the __profileIndex
1074
1074
1075 """
1075 """
1076
1076
1077 if not self.__withOverapping:
1077 if not self.__withOverapping:
1078 self.__buffer_spc += data_spc
1078 self.__buffer_spc += data_spc
1079
1079
1080 if data_cspc == None:
1080 if data_cspc == None:
1081 self.__buffer_cspc = None
1081 self.__buffer_cspc = None
1082 else:
1082 else:
1083 self.__buffer_cspc += data_cspc
1083 self.__buffer_cspc += data_cspc
1084
1084
1085 if data_dc == None:
1085 if data_dc == None:
1086 self.__buffer_dc = None
1086 self.__buffer_dc = None
1087 else:
1087 else:
1088 self.__buffer_dc += data_dc
1088 self.__buffer_dc += data_dc
1089
1089
1090 self.__profIndex += 1
1090 self.__profIndex += 1
1091 return
1091 return
1092
1092
1093 #Overlapping data
1093 #Overlapping data
1094 nChannels, nFFTPoints, nHeis = data_spc.shape
1094 nChannels, nFFTPoints, nHeis = data_spc.shape
1095 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1095 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1096 if data_cspc != None:
1096 if data_cspc != None:
1097 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1097 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1098 if data_dc != None:
1098 if data_dc != None:
1099 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1099 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1100
1100
1101 #If the buffer is empty then it takes the data value
1101 #If the buffer is empty then it takes the data value
1102 if self.__buffer_spc == None:
1102 if self.__buffer_spc == None:
1103 self.__buffer_spc = data_spc
1103 self.__buffer_spc = data_spc
1104
1104
1105 if data_cspc == None:
1105 if data_cspc == None:
1106 self.__buffer_cspc = None
1106 self.__buffer_cspc = None
1107 else:
1107 else:
1108 self.__buffer_cspc += data_cspc
1108 self.__buffer_cspc += data_cspc
1109
1109
1110 if data_dc == None:
1110 if data_dc == None:
1111 self.__buffer_dc = None
1111 self.__buffer_dc = None
1112 else:
1112 else:
1113 self.__buffer_dc += data_dc
1113 self.__buffer_dc += data_dc
1114
1114
1115 self.__profIndex += 1
1115 self.__profIndex += 1
1116 return
1116 return
1117
1117
1118 #If the buffer length is lower than n then stakcing the data value
1118 #If the buffer length is lower than n then stakcing the data value
1119 if self.__profIndex < self.n:
1119 if self.__profIndex < self.n:
1120 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1120 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1121
1121
1122 if data_cspc != None:
1122 if data_cspc != None:
1123 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1123 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1124
1124
1125 if data_dc != None:
1125 if data_dc != None:
1126 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1126 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1127
1127
1128 self.__profIndex += 1
1128 self.__profIndex += 1
1129 return
1129 return
1130
1130
1131 #If the buffer length is equal to n then replacing the last buffer value with the data value
1131 #If the buffer length is equal to n then replacing the last buffer value with the data value
1132 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1132 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1133 self.__buffer_spc[self.n-1] = data_spc
1133 self.__buffer_spc[self.n-1] = data_spc
1134
1134
1135 if data_cspc != None:
1135 if data_cspc != None:
1136 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1136 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1137 self.__buffer_cspc[self.n-1] = data_cspc
1137 self.__buffer_cspc[self.n-1] = data_cspc
1138
1138
1139 if data_dc != None:
1139 if data_dc != None:
1140 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1140 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1141 self.__buffer_dc[self.n-1] = data_dc
1141 self.__buffer_dc[self.n-1] = data_dc
1142
1142
1143 self.__profIndex = self.n
1143 self.__profIndex = self.n
1144 return
1144 return
1145
1145
1146
1146
1147 def pushData(self):
1147 def pushData(self):
1148 """
1148 """
1149 Return the sum of the last profiles and the profiles used in the sum.
1149 Return the sum of the last profiles and the profiles used in the sum.
1150
1150
1151 Affected:
1151 Affected:
1152
1152
1153 self.__profileIndex
1153 self.__profileIndex
1154
1154
1155 """
1155 """
1156 data_spc = None
1156 data_spc = None
1157 data_cspc = None
1157 data_cspc = None
1158 data_dc = None
1158 data_dc = None
1159
1159
1160 if not self.__withOverapping:
1160 if not self.__withOverapping:
1161 data_spc = self.__buffer_spc
1161 data_spc = self.__buffer_spc
1162 data_cspc = self.__buffer_cspc
1162 data_cspc = self.__buffer_cspc
1163 data_dc = self.__buffer_dc
1163 data_dc = self.__buffer_dc
1164
1164
1165 n = self.__profIndex
1165 n = self.__profIndex
1166
1166
1167 self.__buffer_spc = 0
1167 self.__buffer_spc = 0
1168 self.__buffer_cspc = 0
1168 self.__buffer_cspc = 0
1169 self.__buffer_dc = 0
1169 self.__buffer_dc = 0
1170 self.__profIndex = 0
1170 self.__profIndex = 0
1171
1171
1172 return data_spc, data_cspc, data_dc, n
1172 return data_spc, data_cspc, data_dc, n
1173
1173
1174 #Integration with Overlapping
1174 #Integration with Overlapping
1175 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1175 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1176
1176
1177 if self.__buffer_cspc != None:
1177 if self.__buffer_cspc != None:
1178 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1178 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1179
1179
1180 if self.__buffer_dc != None:
1180 if self.__buffer_dc != None:
1181 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1181 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1182
1182
1183 n = self.__profIndex
1183 n = self.__profIndex
1184
1184
1185 return data_spc, data_cspc, data_dc, n
1185 return data_spc, data_cspc, data_dc, n
1186
1186
1187 def byProfiles(self, *args):
1187 def byProfiles(self, *args):
1188
1188
1189 self.__dataReady = False
1189 self.__dataReady = False
1190 avgdata_spc = None
1190 avgdata_spc = None
1191 avgdata_cspc = None
1191 avgdata_cspc = None
1192 avgdata_dc = None
1192 avgdata_dc = None
1193 n = None
1193 n = None
1194
1194
1195 self.putData(*args)
1195 self.putData(*args)
1196
1196
1197 if self.__profIndex == self.n:
1197 if self.__profIndex == self.n:
1198
1198
1199 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1199 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1200 self.__dataReady = True
1200 self.__dataReady = True
1201
1201
1202 return avgdata_spc, avgdata_cspc, avgdata_dc
1202 return avgdata_spc, avgdata_cspc, avgdata_dc
1203
1203
1204 def byTime(self, datatime, *args):
1204 def byTime(self, datatime, *args):
1205
1205
1206 self.__dataReady = False
1206 self.__dataReady = False
1207 avgdata_spc = None
1207 avgdata_spc = None
1208 avgdata_cspc = None
1208 avgdata_cspc = None
1209 avgdata_dc = None
1209 avgdata_dc = None
1210 n = None
1210 n = None
1211
1211
1212 self.putData(*args)
1212 self.putData(*args)
1213
1213
1214 if (datatime - self.__initime) >= self.__integrationtime:
1214 if (datatime - self.__initime) >= self.__integrationtime:
1215 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1215 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1216 self.n = n
1216 self.n = n
1217 self.__dataReady = True
1217 self.__dataReady = True
1218
1218
1219 return avgdata_spc, avgdata_cspc, avgdata_dc
1219 return avgdata_spc, avgdata_cspc, avgdata_dc
1220
1220
1221 def integrate(self, datatime, *args):
1221 def integrate(self, datatime, *args):
1222
1222
1223 if self.__initime == None:
1223 if self.__initime == None:
1224 self.__initime = datatime
1224 self.__initime = datatime
1225
1225
1226 if self.__byTime:
1226 if self.__byTime:
1227 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1227 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1228 else:
1228 else:
1229 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1229 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1230
1230
1231 self.__lastdatatime = datatime
1231 self.__lastdatatime = datatime
1232
1232
1233 if avgdata_spc == None:
1233 if avgdata_spc == None:
1234 return None, None, None, None
1234 return None, None, None, None
1235
1235
1236 avgdatatime = self.__initime
1236 avgdatatime = self.__initime
1237 try:
1237 try:
1238 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1238 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1239 except:
1239 except:
1240 self.__timeInterval = self.__lastdatatime - self.__initime
1240 self.__timeInterval = self.__lastdatatime - self.__initime
1241
1241
1242 deltatime = datatime -self.__lastdatatime
1242 deltatime = datatime -self.__lastdatatime
1243
1243
1244 if not self.__withOverapping:
1244 if not self.__withOverapping:
1245 self.__initime = datatime
1245 self.__initime = datatime
1246 else:
1246 else:
1247 self.__initime += deltatime
1247 self.__initime += deltatime
1248
1248
1249 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1249 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1250
1250
1251 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1251 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1252
1252
1253 if n==1:
1253 if n==1:
1254 dataOut.flagNoData = False
1254 dataOut.flagNoData = False
1255 return
1255 return
1256
1256
1257 if not self.__isConfig:
1257 if not self.__isConfig:
1258 self.setup(n, timeInterval, overlapping)
1258 self.setup(n, timeInterval, overlapping)
1259 self.__isConfig = True
1259 self.__isConfig = True
1260
1260
1261 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1261 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1262 dataOut.data_spc,
1262 dataOut.data_spc,
1263 dataOut.data_cspc,
1263 dataOut.data_cspc,
1264 dataOut.data_dc)
1264 dataOut.data_dc)
1265
1265
1266 # dataOut.timeInterval *= n
1266 # dataOut.timeInterval *= n
1267 dataOut.flagNoData = True
1267 dataOut.flagNoData = True
1268
1268
1269 if self.__dataReady:
1269 if self.__dataReady:
1270
1270
1271 dataOut.data_spc = avgdata_spc
1271 dataOut.data_spc = avgdata_spc
1272 dataOut.data_cspc = avgdata_cspc
1272 dataOut.data_cspc = avgdata_cspc
1273 dataOut.data_dc = avgdata_dc
1273 dataOut.data_dc = avgdata_dc
1274
1274
1275 dataOut.nIncohInt *= self.n
1275 dataOut.nIncohInt *= self.n
1276 dataOut.utctime = avgdatatime
1276 dataOut.utctime = avgdatatime
1277 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1277 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1278 dataOut.timeInterval = self.__timeInterval*self.n
1278 dataOut.timeInterval = self.__timeInterval*self.n
1279 dataOut.flagNoData = False
1279 dataOut.flagNoData = False
1280
1280
1281 class ProfileConcat(Operation):
1282
1283 __isConfig = False
1284 buffer = None
1285
1286 def __init__(self):
1287
1288 self.profileIndex = 0
1289
1290 def reset(self):
1291 self.buffer = numpy.zeros_like(self.buffer)
1292 self.start_index = 0
1293 self.times = 1
1294
1295 def setup(self, data, m, n=1):
1296 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
1297 self.profiles = data.shape[1]
1298 self.start_index = 0
1299 self.times = 1
1300
1301 def concat(self, data):
1302
1303 self.buffer[:,self.start_index:self.profiles*self.times] = data.copy()
1304 self.start_index = self.start_index + self.profiles
1305
1306 def run(self, dataOut, m):
1307
1308 dataOut.flagNoData = True
1309
1310 if not self.__isConfig:
1311 self.setup(dataOut.data, m, 1)
1312 self.__isConfig = True
1313
1314 self.concat(dataOut.data)
1315 self.times += 1
1316 if self.times > m:
1317 dataOut.data = self.buffer
1318 self.reset()
1319 dataOut.flagNoData = False
1320 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
1321 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1322 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5
1323 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
1324
1325
1326
1281 class ProfileSelector(Operation):
1327 class ProfileSelector(Operation):
1282
1328
1283 profileIndex = None
1329 profileIndex = None
1284 # Tamanho total de los perfiles
1330 # Tamanho total de los perfiles
1285 nProfiles = None
1331 nProfiles = None
1286
1332
1287 def __init__(self):
1333 def __init__(self):
1288
1334
1289 self.profileIndex = 0
1335 self.profileIndex = 0
1290
1336
1291 def incIndex(self):
1337 def incIndex(self):
1292 self.profileIndex += 1
1338 self.profileIndex += 1
1293
1339
1294 if self.profileIndex >= self.nProfiles:
1340 if self.profileIndex >= self.nProfiles:
1295 self.profileIndex = 0
1341 self.profileIndex = 0
1296
1342
1297 def isProfileInRange(self, minIndex, maxIndex):
1343 def isProfileInRange(self, minIndex, maxIndex):
1298
1344
1299 if self.profileIndex < minIndex:
1345 if self.profileIndex < minIndex:
1300 return False
1346 return False
1301
1347
1302 if self.profileIndex > maxIndex:
1348 if self.profileIndex > maxIndex:
1303 return False
1349 return False
1304
1350
1305 return True
1351 return True
1306
1352
1307 def isProfileInList(self, profileList):
1353 def isProfileInList(self, profileList):
1308
1354
1309 if self.profileIndex not in profileList:
1355 if self.profileIndex not in profileList:
1310 return False
1356 return False
1311
1357
1312 return True
1358 return True
1313
1359
1314 def run(self, dataOut, profileList=None, profileRangeList=None):
1360 def run(self, dataOut, profileList=None, profileRangeList=None):
1315
1361
1316 dataOut.flagNoData = True
1362 dataOut.flagNoData = True
1317 self.nProfiles = dataOut.nProfiles
1363 self.nProfiles = dataOut.nProfiles
1318
1364
1319 if profileList != None:
1365 if profileList != None:
1320 if self.isProfileInList(profileList):
1366 if self.isProfileInList(profileList):
1321 dataOut.flagNoData = False
1367 dataOut.flagNoData = False
1322
1368
1323 self.incIndex()
1369 self.incIndex()
1324 return 1
1370 return 1
1325
1371
1326
1372
1327 elif profileRangeList != None:
1373 elif profileRangeList != None:
1328 minIndex = profileRangeList[0]
1374 minIndex = profileRangeList[0]
1329 maxIndex = profileRangeList[1]
1375 maxIndex = profileRangeList[1]
1330 if self.isProfileInRange(minIndex, maxIndex):
1376 if self.isProfileInRange(minIndex, maxIndex):
1331 dataOut.flagNoData = False
1377 dataOut.flagNoData = False
1332
1378
1333 self.incIndex()
1379 self.incIndex()
1334 return 1
1380 return 1
1335
1381
1336 else:
1382 else:
1337 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1383 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1338
1384
1339 return 0
1385 return 0
1340
1386
1341 class SpectraHeisProc(ProcessingUnit):
1387 class SpectraHeisProc(ProcessingUnit):
1342 def __init__(self):
1388 def __init__(self):
1343 self.objectDict = {}
1389 self.objectDict = {}
1344 # self.buffer = None
1390 # self.buffer = None
1345 # self.firstdatatime = None
1391 # self.firstdatatime = None
1346 # self.profIndex = 0
1392 # self.profIndex = 0
1347 self.dataOut = SpectraHeis()
1393 self.dataOut = SpectraHeis()
1348
1394
1349 def __updateObjFromInput(self):
1395 def __updateObjFromInput(self):
1350 self.dataOut.timeZone = self.dataIn.timeZone
1396 self.dataOut.timeZone = self.dataIn.timeZone
1351 self.dataOut.dstFlag = self.dataIn.dstFlag
1397 self.dataOut.dstFlag = self.dataIn.dstFlag
1352 self.dataOut.errorCount = self.dataIn.errorCount
1398 self.dataOut.errorCount = self.dataIn.errorCount
1353 self.dataOut.useLocalTime = self.dataIn.useLocalTime
1399 self.dataOut.useLocalTime = self.dataIn.useLocalTime
1354
1400
1355 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
1401 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
1356 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
1402 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
1357 self.dataOut.channelList = self.dataIn.channelList
1403 self.dataOut.channelList = self.dataIn.channelList
1358 self.dataOut.heightList = self.dataIn.heightList
1404 self.dataOut.heightList = self.dataIn.heightList
1359 # self.dataOut.dtype = self.dataIn.dtype
1405 # self.dataOut.dtype = self.dataIn.dtype
1360 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
1406 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
1361 # self.dataOut.nHeights = self.dataIn.nHeights
1407 # self.dataOut.nHeights = self.dataIn.nHeights
1362 # self.dataOut.nChannels = self.dataIn.nChannels
1408 # self.dataOut.nChannels = self.dataIn.nChannels
1363 self.dataOut.nBaud = self.dataIn.nBaud
1409 self.dataOut.nBaud = self.dataIn.nBaud
1364 self.dataOut.nCode = self.dataIn.nCode
1410 self.dataOut.nCode = self.dataIn.nCode
1365 self.dataOut.code = self.dataIn.code
1411 self.dataOut.code = self.dataIn.code
1366 # self.dataOut.nProfiles = 1
1412 # self.dataOut.nProfiles = 1
1367 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
1413 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
1368 self.dataOut.nFFTPoints = self.dataIn.nHeights
1414 self.dataOut.nFFTPoints = self.dataIn.nHeights
1369 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
1415 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
1370 # self.dataOut.flagNoData = self.dataIn.flagNoData
1416 # self.dataOut.flagNoData = self.dataIn.flagNoData
1371 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
1417 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
1372 self.dataOut.utctime = self.dataIn.utctime
1418 self.dataOut.utctime = self.dataIn.utctime
1373 # self.dataOut.utctime = self.firstdatatime
1419 # self.dataOut.utctime = self.firstdatatime
1374 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
1420 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
1375 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
1421 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
1376 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
1422 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
1377 self.dataOut.nCohInt = self.dataIn.nCohInt
1423 self.dataOut.nCohInt = self.dataIn.nCohInt
1378 self.dataOut.nIncohInt = 1
1424 self.dataOut.nIncohInt = 1
1379 self.dataOut.ippSeconds= self.dataIn.ippSeconds
1425 self.dataOut.ippSeconds= self.dataIn.ippSeconds
1380 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
1426 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
1381
1427
1382 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
1428 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
1383 # self.dataOut.set=self.dataIn.set
1429 # self.dataOut.set=self.dataIn.set
1384 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
1430 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
1385
1431
1386
1432
1387 def __getFft(self):
1433 def __getFft(self):
1388
1434
1389 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
1435 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
1390 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
1436 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
1391 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
1437 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
1392 self.dataOut.data_spc = spc
1438 self.dataOut.data_spc = spc
1393
1439
1394 def init(self):
1440 def init(self):
1395
1441
1396 self.dataOut.flagNoData = True
1442 self.dataOut.flagNoData = True
1397
1443
1398 if self.dataIn.type == "SpectraHeis":
1444 if self.dataIn.type == "SpectraHeis":
1399 self.dataOut.copy(self.dataIn)
1445 self.dataOut.copy(self.dataIn)
1400 return
1446 return
1401
1447
1402 if self.dataIn.type == "Voltage":
1448 if self.dataIn.type == "Voltage":
1403 self.__updateObjFromInput()
1449 self.__updateObjFromInput()
1404 self.__getFft()
1450 self.__getFft()
1405 self.dataOut.flagNoData = False
1451 self.dataOut.flagNoData = False
1406
1452
1407 return
1453 return
1408
1454
1409 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
1455 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
1410
1456
1411
1457
1412 def selectChannels(self, channelList):
1458 def selectChannels(self, channelList):
1413
1459
1414 channelIndexList = []
1460 channelIndexList = []
1415
1461
1416 for channel in channelList:
1462 for channel in channelList:
1417 index = self.dataOut.channelList.index(channel)
1463 index = self.dataOut.channelList.index(channel)
1418 channelIndexList.append(index)
1464 channelIndexList.append(index)
1419
1465
1420 self.selectChannelsByIndex(channelIndexList)
1466 self.selectChannelsByIndex(channelIndexList)
1421
1467
1422 def selectChannelsByIndex(self, channelIndexList):
1468 def selectChannelsByIndex(self, channelIndexList):
1423 """
1469 """
1424 Selecciona un bloque de datos en base a canales segun el channelIndexList
1470 Selecciona un bloque de datos en base a canales segun el channelIndexList
1425
1471
1426 Input:
1472 Input:
1427 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
1473 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
1428
1474
1429 Affected:
1475 Affected:
1430 self.dataOut.data
1476 self.dataOut.data
1431 self.dataOut.channelIndexList
1477 self.dataOut.channelIndexList
1432 self.dataOut.nChannels
1478 self.dataOut.nChannels
1433 self.dataOut.m_ProcessingHeader.totalSpectra
1479 self.dataOut.m_ProcessingHeader.totalSpectra
1434 self.dataOut.systemHeaderObj.numChannels
1480 self.dataOut.systemHeaderObj.numChannels
1435 self.dataOut.m_ProcessingHeader.blockSize
1481 self.dataOut.m_ProcessingHeader.blockSize
1436
1482
1437 Return:
1483 Return:
1438 None
1484 None
1439 """
1485 """
1440
1486
1441 for channelIndex in channelIndexList:
1487 for channelIndex in channelIndexList:
1442 if channelIndex not in self.dataOut.channelIndexList:
1488 if channelIndex not in self.dataOut.channelIndexList:
1443 print channelIndexList
1489 print channelIndexList
1444 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
1490 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
1445
1491
1446 nChannels = len(channelIndexList)
1492 nChannels = len(channelIndexList)
1447
1493
1448 data_spc = self.dataOut.data_spc[channelIndexList,:]
1494 data_spc = self.dataOut.data_spc[channelIndexList,:]
1449
1495
1450 self.dataOut.data_spc = data_spc
1496 self.dataOut.data_spc = data_spc
1451 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
1497 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
1452
1498
1453 return 1
1499 return 1
1454
1500
1455 class IncohInt4SpectraHeis(Operation):
1501 class IncohInt4SpectraHeis(Operation):
1456
1502
1457 __isConfig = False
1503 __isConfig = False
1458
1504
1459 __profIndex = 0
1505 __profIndex = 0
1460 __withOverapping = False
1506 __withOverapping = False
1461
1507
1462 __byTime = False
1508 __byTime = False
1463 __initime = None
1509 __initime = None
1464 __lastdatatime = None
1510 __lastdatatime = None
1465 __integrationtime = None
1511 __integrationtime = None
1466
1512
1467 __buffer = None
1513 __buffer = None
1468
1514
1469 __dataReady = False
1515 __dataReady = False
1470
1516
1471 n = None
1517 n = None
1472
1518
1473
1519
1474 def __init__(self):
1520 def __init__(self):
1475
1521
1476 self.__isConfig = False
1522 self.__isConfig = False
1477
1523
1478 def setup(self, n=None, timeInterval=None, overlapping=False):
1524 def setup(self, n=None, timeInterval=None, overlapping=False):
1479 """
1525 """
1480 Set the parameters of the integration class.
1526 Set the parameters of the integration class.
1481
1527
1482 Inputs:
1528 Inputs:
1483
1529
1484 n : Number of coherent integrations
1530 n : Number of coherent integrations
1485 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1531 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1486 overlapping :
1532 overlapping :
1487
1533
1488 """
1534 """
1489
1535
1490 self.__initime = None
1536 self.__initime = None
1491 self.__lastdatatime = 0
1537 self.__lastdatatime = 0
1492 self.__buffer = None
1538 self.__buffer = None
1493 self.__dataReady = False
1539 self.__dataReady = False
1494
1540
1495
1541
1496 if n == None and timeInterval == None:
1542 if n == None and timeInterval == None:
1497 raise ValueError, "n or timeInterval should be specified ..."
1543 raise ValueError, "n or timeInterval should be specified ..."
1498
1544
1499 if n != None:
1545 if n != None:
1500 self.n = n
1546 self.n = n
1501 self.__byTime = False
1547 self.__byTime = False
1502 else:
1548 else:
1503 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
1549 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
1504 self.n = 9999
1550 self.n = 9999
1505 self.__byTime = True
1551 self.__byTime = True
1506
1552
1507 if overlapping:
1553 if overlapping:
1508 self.__withOverapping = True
1554 self.__withOverapping = True
1509 self.__buffer = None
1555 self.__buffer = None
1510 else:
1556 else:
1511 self.__withOverapping = False
1557 self.__withOverapping = False
1512 self.__buffer = 0
1558 self.__buffer = 0
1513
1559
1514 self.__profIndex = 0
1560 self.__profIndex = 0
1515
1561
1516 def putData(self, data):
1562 def putData(self, data):
1517
1563
1518 """
1564 """
1519 Add a profile to the __buffer and increase in one the __profileIndex
1565 Add a profile to the __buffer and increase in one the __profileIndex
1520
1566
1521 """
1567 """
1522
1568
1523 if not self.__withOverapping:
1569 if not self.__withOverapping:
1524 self.__buffer += data.copy()
1570 self.__buffer += data.copy()
1525 self.__profIndex += 1
1571 self.__profIndex += 1
1526 return
1572 return
1527
1573
1528 #Overlapping data
1574 #Overlapping data
1529 nChannels, nHeis = data.shape
1575 nChannels, nHeis = data.shape
1530 data = numpy.reshape(data, (1, nChannels, nHeis))
1576 data = numpy.reshape(data, (1, nChannels, nHeis))
1531
1577
1532 #If the buffer is empty then it takes the data value
1578 #If the buffer is empty then it takes the data value
1533 if self.__buffer == None:
1579 if self.__buffer == None:
1534 self.__buffer = data
1580 self.__buffer = data
1535 self.__profIndex += 1
1581 self.__profIndex += 1
1536 return
1582 return
1537
1583
1538 #If the buffer length is lower than n then stakcing the data value
1584 #If the buffer length is lower than n then stakcing the data value
1539 if self.__profIndex < self.n:
1585 if self.__profIndex < self.n:
1540 self.__buffer = numpy.vstack((self.__buffer, data))
1586 self.__buffer = numpy.vstack((self.__buffer, data))
1541 self.__profIndex += 1
1587 self.__profIndex += 1
1542 return
1588 return
1543
1589
1544 #If the buffer length is equal to n then replacing the last buffer value with the data value
1590 #If the buffer length is equal to n then replacing the last buffer value with the data value
1545 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
1591 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
1546 self.__buffer[self.n-1] = data
1592 self.__buffer[self.n-1] = data
1547 self.__profIndex = self.n
1593 self.__profIndex = self.n
1548 return
1594 return
1549
1595
1550
1596
1551 def pushData(self):
1597 def pushData(self):
1552 """
1598 """
1553 Return the sum of the last profiles and the profiles used in the sum.
1599 Return the sum of the last profiles and the profiles used in the sum.
1554
1600
1555 Affected:
1601 Affected:
1556
1602
1557 self.__profileIndex
1603 self.__profileIndex
1558
1604
1559 """
1605 """
1560
1606
1561 if not self.__withOverapping:
1607 if not self.__withOverapping:
1562 data = self.__buffer
1608 data = self.__buffer
1563 n = self.__profIndex
1609 n = self.__profIndex
1564
1610
1565 self.__buffer = 0
1611 self.__buffer = 0
1566 self.__profIndex = 0
1612 self.__profIndex = 0
1567
1613
1568 return data, n
1614 return data, n
1569
1615
1570 #Integration with Overlapping
1616 #Integration with Overlapping
1571 data = numpy.sum(self.__buffer, axis=0)
1617 data = numpy.sum(self.__buffer, axis=0)
1572 n = self.__profIndex
1618 n = self.__profIndex
1573
1619
1574 return data, n
1620 return data, n
1575
1621
1576 def byProfiles(self, data):
1622 def byProfiles(self, data):
1577
1623
1578 self.__dataReady = False
1624 self.__dataReady = False
1579 avgdata = None
1625 avgdata = None
1580 n = None
1626 n = None
1581
1627
1582 self.putData(data)
1628 self.putData(data)
1583
1629
1584 if self.__profIndex == self.n:
1630 if self.__profIndex == self.n:
1585
1631
1586 avgdata, n = self.pushData()
1632 avgdata, n = self.pushData()
1587 self.__dataReady = True
1633 self.__dataReady = True
1588
1634
1589 return avgdata
1635 return avgdata
1590
1636
1591 def byTime(self, data, datatime):
1637 def byTime(self, data, datatime):
1592
1638
1593 self.__dataReady = False
1639 self.__dataReady = False
1594 avgdata = None
1640 avgdata = None
1595 n = None
1641 n = None
1596
1642
1597 self.putData(data)
1643 self.putData(data)
1598
1644
1599 if (datatime - self.__initime) >= self.__integrationtime:
1645 if (datatime - self.__initime) >= self.__integrationtime:
1600 avgdata, n = self.pushData()
1646 avgdata, n = self.pushData()
1601 self.n = n
1647 self.n = n
1602 self.__dataReady = True
1648 self.__dataReady = True
1603
1649
1604 return avgdata
1650 return avgdata
1605
1651
1606 def integrate(self, data, datatime=None):
1652 def integrate(self, data, datatime=None):
1607
1653
1608 if self.__initime == None:
1654 if self.__initime == None:
1609 self.__initime = datatime
1655 self.__initime = datatime
1610
1656
1611 if self.__byTime:
1657 if self.__byTime:
1612 avgdata = self.byTime(data, datatime)
1658 avgdata = self.byTime(data, datatime)
1613 else:
1659 else:
1614 avgdata = self.byProfiles(data)
1660 avgdata = self.byProfiles(data)
1615
1661
1616
1662
1617 self.__lastdatatime = datatime
1663 self.__lastdatatime = datatime
1618
1664
1619 if avgdata == None:
1665 if avgdata == None:
1620 return None, None
1666 return None, None
1621
1667
1622 avgdatatime = self.__initime
1668 avgdatatime = self.__initime
1623
1669
1624 deltatime = datatime -self.__lastdatatime
1670 deltatime = datatime -self.__lastdatatime
1625
1671
1626 if not self.__withOverapping:
1672 if not self.__withOverapping:
1627 self.__initime = datatime
1673 self.__initime = datatime
1628 else:
1674 else:
1629 self.__initime += deltatime
1675 self.__initime += deltatime
1630
1676
1631 return avgdata, avgdatatime
1677 return avgdata, avgdatatime
1632
1678
1633 def run(self, dataOut, **kwargs):
1679 def run(self, dataOut, **kwargs):
1634
1680
1635 if not self.__isConfig:
1681 if not self.__isConfig:
1636 self.setup(**kwargs)
1682 self.setup(**kwargs)
1637 self.__isConfig = True
1683 self.__isConfig = True
1638
1684
1639 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
1685 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
1640
1686
1641 # dataOut.timeInterval *= n
1687 # dataOut.timeInterval *= n
1642 dataOut.flagNoData = True
1688 dataOut.flagNoData = True
1643
1689
1644 if self.__dataReady:
1690 if self.__dataReady:
1645 dataOut.data_spc = avgdata
1691 dataOut.data_spc = avgdata
1646 dataOut.nIncohInt *= self.n
1692 dataOut.nIncohInt *= self.n
1647 # dataOut.nCohInt *= self.n
1693 # dataOut.nCohInt *= self.n
1648 dataOut.utctime = avgdatatime
1694 dataOut.utctime = avgdatatime
1649 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
1695 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
1650 # dataOut.timeInterval = self.__timeInterval*self.n
1696 # dataOut.timeInterval = self.__timeInterval*self.n
1651 dataOut.flagNoData = False
1697 dataOut.flagNoData = False
1652
1698
1653
1699
1654
1700
1655
1701
1656 No newline at end of file
1702
General Comments 0
You need to be logged in to leave comments. Login now