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