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