@@ -1,1157 +1,1157 | |||||
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 |
|
|
295 | heights = self.dataOut.heightList | |
296 |
|
296 | |||
297 | for i,val in enumerate(data): |
|
297 | inda = numpy.where(heights >= minHei) | |
298 | if val < minHei: |
|
298 | indb = numpy.where(heights <= maxHei) | |
299 | continue |
|
|||
300 | else: |
|
|||
301 | minIndex = i; |
|
|||
302 | break |
|
|||
303 |
|
299 | |||
304 | for i,val in enumerate(data): |
|
300 | try: | |
305 | if val <= maxHei: |
|
301 | minIndex = inda[0][0] | |
306 | maxIndex = i; |
|
302 | except: | |
307 |
|
|
303 | minIndex = 0 | |
308 | break |
|
304 | ||
|
305 | try: | |||
|
306 | maxIndex = indb[0][-1] | |||
|
307 | except: | |||
|
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.average(buffer,2) |
|
362 | buffer = numpy.average(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 |
|
365 | |||
366 | def deFlip(self): |
|
366 | def deFlip(self): | |
367 | self.dataOut.data *= self.flip |
|
367 | self.dataOut.data *= self.flip | |
368 | self.flip *= -1. |
|
368 | self.flip *= -1. | |
369 |
|
369 | |||
370 |
|
370 | |||
371 | class CohInt(Operation): |
|
371 | class CohInt(Operation): | |
372 |
|
372 | |||
373 | __isConfig = False |
|
373 | __isConfig = False | |
374 |
|
374 | |||
375 | __profIndex = 0 |
|
375 | __profIndex = 0 | |
376 | __withOverapping = False |
|
376 | __withOverapping = False | |
377 |
|
377 | |||
378 | __byTime = False |
|
378 | __byTime = False | |
379 | __initime = None |
|
379 | __initime = None | |
380 | __lastdatatime = None |
|
380 | __lastdatatime = None | |
381 | __integrationtime = None |
|
381 | __integrationtime = None | |
382 |
|
382 | |||
383 | __buffer = None |
|
383 | __buffer = None | |
384 |
|
384 | |||
385 | __dataReady = False |
|
385 | __dataReady = False | |
386 |
|
386 | |||
387 | n = None |
|
387 | n = None | |
388 |
|
388 | |||
389 |
|
389 | |||
390 | def __init__(self): |
|
390 | def __init__(self): | |
391 |
|
391 | |||
392 | self.__isConfig = False |
|
392 | self.__isConfig = False | |
393 |
|
393 | |||
394 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
394 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
395 | """ |
|
395 | """ | |
396 | Set the parameters of the integration class. |
|
396 | Set the parameters of the integration class. | |
397 |
|
397 | |||
398 | Inputs: |
|
398 | Inputs: | |
399 |
|
399 | |||
400 | n : Number of coherent integrations |
|
400 | n : Number of coherent integrations | |
401 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
401 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
402 | overlapping : |
|
402 | overlapping : | |
403 |
|
403 | |||
404 | """ |
|
404 | """ | |
405 |
|
405 | |||
406 | self.__initime = None |
|
406 | self.__initime = None | |
407 | self.__lastdatatime = 0 |
|
407 | self.__lastdatatime = 0 | |
408 | self.__buffer = None |
|
408 | self.__buffer = None | |
409 | self.__dataReady = False |
|
409 | self.__dataReady = False | |
410 |
|
410 | |||
411 |
|
411 | |||
412 | if n == None and timeInterval == None: |
|
412 | if n == None and timeInterval == None: | |
413 | raise ValueError, "n or timeInterval should be specified ..." |
|
413 | raise ValueError, "n or timeInterval should be specified ..." | |
414 |
|
414 | |||
415 | if n != None: |
|
415 | if n != None: | |
416 | self.n = n |
|
416 | self.n = n | |
417 | self.__byTime = False |
|
417 | self.__byTime = False | |
418 | else: |
|
418 | else: | |
419 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
419 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
420 | self.n = 9999 |
|
420 | self.n = 9999 | |
421 | self.__byTime = True |
|
421 | self.__byTime = True | |
422 |
|
422 | |||
423 | if overlapping: |
|
423 | if overlapping: | |
424 | self.__withOverapping = True |
|
424 | self.__withOverapping = True | |
425 | self.__buffer = None |
|
425 | self.__buffer = None | |
426 | else: |
|
426 | else: | |
427 | self.__withOverapping = False |
|
427 | self.__withOverapping = False | |
428 | self.__buffer = 0 |
|
428 | self.__buffer = 0 | |
429 |
|
429 | |||
430 | self.__profIndex = 0 |
|
430 | self.__profIndex = 0 | |
431 |
|
431 | |||
432 | def putData(self, data): |
|
432 | def putData(self, data): | |
433 |
|
433 | |||
434 | """ |
|
434 | """ | |
435 | Add a profile to the __buffer and increase in one the __profileIndex |
|
435 | Add a profile to the __buffer and increase in one the __profileIndex | |
436 |
|
436 | |||
437 | """ |
|
437 | """ | |
438 |
|
438 | |||
439 | if not self.__withOverapping: |
|
439 | if not self.__withOverapping: | |
440 | self.__buffer += data.copy() |
|
440 | self.__buffer += data.copy() | |
441 | self.__profIndex += 1 |
|
441 | self.__profIndex += 1 | |
442 | return |
|
442 | return | |
443 |
|
443 | |||
444 | #Overlapping data |
|
444 | #Overlapping data | |
445 | nChannels, nHeis = data.shape |
|
445 | nChannels, nHeis = data.shape | |
446 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
446 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
447 |
|
447 | |||
448 | #If the buffer is empty then it takes the data value |
|
448 | #If the buffer is empty then it takes the data value | |
449 | if self.__buffer == None: |
|
449 | if self.__buffer == None: | |
450 | self.__buffer = data |
|
450 | self.__buffer = data | |
451 | self.__profIndex += 1 |
|
451 | self.__profIndex += 1 | |
452 | return |
|
452 | return | |
453 |
|
453 | |||
454 | #If the buffer length is lower than n then stakcing the data value |
|
454 | #If the buffer length is lower than n then stakcing the data value | |
455 | if self.__profIndex < self.n: |
|
455 | if self.__profIndex < self.n: | |
456 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
456 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
457 | self.__profIndex += 1 |
|
457 | self.__profIndex += 1 | |
458 | return |
|
458 | return | |
459 |
|
459 | |||
460 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
460 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
461 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
461 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
462 | self.__buffer[self.n-1] = data |
|
462 | self.__buffer[self.n-1] = data | |
463 | self.__profIndex = self.n |
|
463 | self.__profIndex = self.n | |
464 | return |
|
464 | return | |
465 |
|
465 | |||
466 |
|
466 | |||
467 | def pushData(self): |
|
467 | def pushData(self): | |
468 | """ |
|
468 | """ | |
469 | Return the sum of the last profiles and the profiles used in the sum. |
|
469 | Return the sum of the last profiles and the profiles used in the sum. | |
470 |
|
470 | |||
471 | Affected: |
|
471 | Affected: | |
472 |
|
472 | |||
473 | self.__profileIndex |
|
473 | self.__profileIndex | |
474 |
|
474 | |||
475 | """ |
|
475 | """ | |
476 |
|
476 | |||
477 | if not self.__withOverapping: |
|
477 | if not self.__withOverapping: | |
478 | data = self.__buffer |
|
478 | data = self.__buffer | |
479 | n = self.__profIndex |
|
479 | n = self.__profIndex | |
480 |
|
480 | |||
481 | self.__buffer = 0 |
|
481 | self.__buffer = 0 | |
482 | self.__profIndex = 0 |
|
482 | self.__profIndex = 0 | |
483 |
|
483 | |||
484 | return data, n |
|
484 | return data, n | |
485 |
|
485 | |||
486 | #Integration with Overlapping |
|
486 | #Integration with Overlapping | |
487 | data = numpy.sum(self.__buffer, axis=0) |
|
487 | data = numpy.sum(self.__buffer, axis=0) | |
488 | n = self.__profIndex |
|
488 | n = self.__profIndex | |
489 |
|
489 | |||
490 | return data, n |
|
490 | return data, n | |
491 |
|
491 | |||
492 | def byProfiles(self, data): |
|
492 | def byProfiles(self, data): | |
493 |
|
493 | |||
494 | self.__dataReady = False |
|
494 | self.__dataReady = False | |
495 | avgdata = None |
|
495 | avgdata = None | |
496 | n = None |
|
496 | n = None | |
497 |
|
497 | |||
498 | self.putData(data) |
|
498 | self.putData(data) | |
499 |
|
499 | |||
500 | if self.__profIndex == self.n: |
|
500 | if self.__profIndex == self.n: | |
501 |
|
501 | |||
502 | avgdata, n = self.pushData() |
|
502 | avgdata, n = self.pushData() | |
503 | self.__dataReady = True |
|
503 | self.__dataReady = True | |
504 |
|
504 | |||
505 | return avgdata |
|
505 | return avgdata | |
506 |
|
506 | |||
507 | def byTime(self, data, datatime): |
|
507 | def byTime(self, data, datatime): | |
508 |
|
508 | |||
509 | self.__dataReady = False |
|
509 | self.__dataReady = False | |
510 | avgdata = None |
|
510 | avgdata = None | |
511 | n = None |
|
511 | n = None | |
512 |
|
512 | |||
513 | self.putData(data) |
|
513 | self.putData(data) | |
514 |
|
514 | |||
515 | if (datatime - self.__initime) >= self.__integrationtime: |
|
515 | if (datatime - self.__initime) >= self.__integrationtime: | |
516 | avgdata, n = self.pushData() |
|
516 | avgdata, n = self.pushData() | |
517 | self.n = n |
|
517 | self.n = n | |
518 | self.__dataReady = True |
|
518 | self.__dataReady = True | |
519 |
|
519 | |||
520 | return avgdata |
|
520 | return avgdata | |
521 |
|
521 | |||
522 | def integrate(self, data, datatime=None): |
|
522 | def integrate(self, data, datatime=None): | |
523 |
|
523 | |||
524 | if self.__initime == None: |
|
524 | if self.__initime == None: | |
525 | self.__initime = datatime |
|
525 | self.__initime = datatime | |
526 |
|
526 | |||
527 | if self.__byTime: |
|
527 | if self.__byTime: | |
528 | avgdata = self.byTime(data, datatime) |
|
528 | avgdata = self.byTime(data, datatime) | |
529 | else: |
|
529 | else: | |
530 | avgdata = self.byProfiles(data) |
|
530 | avgdata = self.byProfiles(data) | |
531 |
|
531 | |||
532 |
|
532 | |||
533 | self.__lastdatatime = datatime |
|
533 | self.__lastdatatime = datatime | |
534 |
|
534 | |||
535 | if avgdata == None: |
|
535 | if avgdata == None: | |
536 | return None, None |
|
536 | return None, None | |
537 |
|
537 | |||
538 | avgdatatime = self.__initime |
|
538 | avgdatatime = self.__initime | |
539 |
|
539 | |||
540 | deltatime = datatime -self.__lastdatatime |
|
540 | deltatime = datatime -self.__lastdatatime | |
541 |
|
541 | |||
542 | if not self.__withOverapping: |
|
542 | if not self.__withOverapping: | |
543 | self.__initime = datatime |
|
543 | self.__initime = datatime | |
544 | else: |
|
544 | else: | |
545 | self.__initime += deltatime |
|
545 | self.__initime += deltatime | |
546 |
|
546 | |||
547 | return avgdata, avgdatatime |
|
547 | return avgdata, avgdatatime | |
548 |
|
548 | |||
549 | def run(self, dataOut, **kwargs): |
|
549 | def run(self, dataOut, **kwargs): | |
550 |
|
550 | |||
551 | if not self.__isConfig: |
|
551 | if not self.__isConfig: | |
552 | self.setup(**kwargs) |
|
552 | self.setup(**kwargs) | |
553 | self.__isConfig = True |
|
553 | self.__isConfig = True | |
554 |
|
554 | |||
555 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
555 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
556 |
|
556 | |||
557 | # dataOut.timeInterval *= n |
|
557 | # dataOut.timeInterval *= n | |
558 | dataOut.flagNoData = True |
|
558 | dataOut.flagNoData = True | |
559 |
|
559 | |||
560 | if self.__dataReady: |
|
560 | if self.__dataReady: | |
561 | dataOut.data = avgdata |
|
561 | dataOut.data = avgdata | |
562 | dataOut.nCohInt *= self.n |
|
562 | dataOut.nCohInt *= self.n | |
563 | dataOut.utctime = avgdatatime |
|
563 | dataOut.utctime = avgdatatime | |
564 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
564 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
565 | dataOut.flagNoData = False |
|
565 | dataOut.flagNoData = False | |
566 |
|
566 | |||
567 |
|
567 | |||
568 | class Decoder(Operation): |
|
568 | class Decoder(Operation): | |
569 |
|
569 | |||
570 | __isConfig = False |
|
570 | __isConfig = False | |
571 | __profIndex = 0 |
|
571 | __profIndex = 0 | |
572 |
|
572 | |||
573 | code = None |
|
573 | code = None | |
574 |
|
574 | |||
575 | nCode = None |
|
575 | nCode = None | |
576 | nBaud = None |
|
576 | nBaud = None | |
577 |
|
577 | |||
578 | def __init__(self): |
|
578 | def __init__(self): | |
579 |
|
579 | |||
580 | self.__isConfig = False |
|
580 | self.__isConfig = False | |
581 |
|
581 | |||
582 | def setup(self, code): |
|
582 | def setup(self, code): | |
583 |
|
583 | |||
584 | self.__profIndex = 0 |
|
584 | self.__profIndex = 0 | |
585 |
|
585 | |||
586 | self.code = code |
|
586 | self.code = code | |
587 |
|
587 | |||
588 | self.nCode = len(code) |
|
588 | self.nCode = len(code) | |
589 | self.nBaud = len(code[0]) |
|
589 | self.nBaud = len(code[0]) | |
590 |
|
590 | |||
591 | def convolutionInFreq(self, data): |
|
591 | def convolutionInFreq(self, data): | |
592 |
|
592 | |||
593 | nchannel, ndata = data.shape |
|
593 | nchannel, ndata = data.shape | |
594 | newcode = numpy.zeros(ndata) |
|
594 | newcode = numpy.zeros(ndata) | |
595 | newcode[0:self.nBaud] = self.code[self.__profIndex] |
|
595 | newcode[0:self.nBaud] = self.code[self.__profIndex] | |
596 |
|
596 | |||
597 | fft_data = numpy.fft.fft(data, axis=1) |
|
597 | fft_data = numpy.fft.fft(data, axis=1) | |
598 | fft_code = numpy.conj(numpy.fft.fft(newcode)) |
|
598 | fft_code = numpy.conj(numpy.fft.fft(newcode)) | |
599 | fft_code = fft_code.reshape(1,len(fft_code)) |
|
599 | fft_code = fft_code.reshape(1,len(fft_code)) | |
600 |
|
600 | |||
601 | # conv = fft_data.copy() |
|
601 | # conv = fft_data.copy() | |
602 | # conv.fill(0) |
|
602 | # conv.fill(0) | |
603 |
|
603 | |||
604 | conv = fft_data*fft_code |
|
604 | conv = fft_data*fft_code | |
605 |
|
605 | |||
606 | data = numpy.fft.ifft(conv,axis=1) |
|
606 | data = numpy.fft.ifft(conv,axis=1) | |
607 |
|
607 | |||
608 | datadec = data[:,:-self.nBaud+1] |
|
608 | datadec = data[:,:-self.nBaud+1] | |
609 | ndatadec = ndata - self.nBaud + 1 |
|
609 | ndatadec = ndata - self.nBaud + 1 | |
610 |
|
610 | |||
611 | if self.__profIndex == self.nCode-1: |
|
611 | if self.__profIndex == self.nCode-1: | |
612 | self.__profIndex = 0 |
|
612 | self.__profIndex = 0 | |
613 | return ndatadec, datadec |
|
613 | return ndatadec, datadec | |
614 |
|
614 | |||
615 | self.__profIndex += 1 |
|
615 | self.__profIndex += 1 | |
616 |
|
616 | |||
617 | return ndatadec, datadec |
|
617 | return ndatadec, datadec | |
618 |
|
618 | |||
619 |
|
619 | |||
620 | def convolutionInTime(self, data): |
|
620 | def convolutionInTime(self, data): | |
621 |
|
621 | |||
622 | nchannel, ndata = data.shape |
|
622 | nchannel, ndata = data.shape | |
623 | newcode = self.code[self.__profIndex] |
|
623 | newcode = self.code[self.__profIndex] | |
624 | ndatadec = ndata - self.nBaud + 1 |
|
624 | ndatadec = ndata - self.nBaud + 1 | |
625 |
|
625 | |||
626 | datadec = numpy.zeros((nchannel, ndatadec)) |
|
626 | datadec = numpy.zeros((nchannel, ndatadec)) | |
627 |
|
627 | |||
628 | for i in range(nchannel): |
|
628 | for i in range(nchannel): | |
629 | datadec[i,:] = numpy.correlate(data[i,:], newcode) |
|
629 | datadec[i,:] = numpy.correlate(data[i,:], newcode) | |
630 |
|
630 | |||
631 | if self.__profIndex == self.nCode-1: |
|
631 | if self.__profIndex == self.nCode-1: | |
632 | self.__profIndex = 0 |
|
632 | self.__profIndex = 0 | |
633 | return ndatadec, datadec |
|
633 | return ndatadec, datadec | |
634 |
|
634 | |||
635 | self.__profIndex += 1 |
|
635 | self.__profIndex += 1 | |
636 |
|
636 | |||
637 | return ndatadec, datadec |
|
637 | return ndatadec, datadec | |
638 |
|
638 | |||
639 | def run(self, dataOut, code=None, mode = 0): |
|
639 | def run(self, dataOut, code=None, mode = 0): | |
640 |
|
640 | |||
641 | if not self.__isConfig: |
|
641 | if not self.__isConfig: | |
642 |
|
642 | |||
643 | if code == None: |
|
643 | if code == None: | |
644 | code = dataOut.code |
|
644 | code = dataOut.code | |
645 |
|
645 | |||
646 | self.setup(code) |
|
646 | self.setup(code) | |
647 | self.__isConfig = True |
|
647 | self.__isConfig = True | |
648 |
|
648 | |||
649 | if mode == 0: |
|
649 | if mode == 0: | |
650 | ndatadec, datadec = self.convolutionInFreq(dataOut.data) |
|
650 | ndatadec, datadec = self.convolutionInFreq(dataOut.data) | |
651 |
|
651 | |||
652 | if mode == 1: |
|
652 | if mode == 1: | |
653 | print "This function is not implemented" |
|
653 | print "This function is not implemented" | |
654 | # ndatadec, datadec = self.convolutionInTime(dataOut.data) |
|
654 | # ndatadec, datadec = self.convolutionInTime(dataOut.data) | |
655 |
|
655 | |||
656 | dataOut.data = datadec |
|
656 | dataOut.data = datadec | |
657 |
|
657 | |||
658 | dataOut.heightList = dataOut.heightList[0:ndatadec] |
|
658 | dataOut.heightList = dataOut.heightList[0:ndatadec] | |
659 |
|
659 | |||
660 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada |
|
660 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada | |
661 |
|
661 | |||
662 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
662 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
663 |
|
663 | |||
664 |
|
664 | |||
665 | class SpectraProc(ProcessingUnit): |
|
665 | class SpectraProc(ProcessingUnit): | |
666 |
|
666 | |||
667 | def __init__(self): |
|
667 | def __init__(self): | |
668 |
|
668 | |||
669 | self.objectDict = {} |
|
669 | self.objectDict = {} | |
670 | self.buffer = None |
|
670 | self.buffer = None | |
671 | self.firstdatatime = None |
|
671 | self.firstdatatime = None | |
672 | self.profIndex = 0 |
|
672 | self.profIndex = 0 | |
673 | self.dataOut = Spectra() |
|
673 | self.dataOut = Spectra() | |
674 |
|
674 | |||
675 | def __updateObjFromInput(self): |
|
675 | def __updateObjFromInput(self): | |
676 |
|
676 | |||
677 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
677 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
678 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
678 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
679 | self.dataOut.channelList = self.dataIn.channelList |
|
679 | self.dataOut.channelList = self.dataIn.channelList | |
680 | self.dataOut.heightList = self.dataIn.heightList |
|
680 | self.dataOut.heightList = self.dataIn.heightList | |
681 | self.dataOut.dtype = self.dataIn.dtype |
|
681 | self.dataOut.dtype = self.dataIn.dtype | |
682 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
682 | # self.dataOut.nHeights = self.dataIn.nHeights | |
683 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
683 | # self.dataOut.nChannels = self.dataIn.nChannels | |
684 | self.dataOut.nBaud = self.dataIn.nBaud |
|
684 | self.dataOut.nBaud = self.dataIn.nBaud | |
685 | self.dataOut.nCode = self.dataIn.nCode |
|
685 | self.dataOut.nCode = self.dataIn.nCode | |
686 | self.dataOut.code = self.dataIn.code |
|
686 | self.dataOut.code = self.dataIn.code | |
687 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
687 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
688 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
688 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
689 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
689 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
690 | self.dataOut.utctime = self.firstdatatime |
|
690 | self.dataOut.utctime = self.firstdatatime | |
691 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
691 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
692 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
692 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
693 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
693 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
694 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
694 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
695 | self.dataOut.nIncohInt = 1 |
|
695 | self.dataOut.nIncohInt = 1 | |
696 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
696 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
697 |
|
697 | |||
698 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
698 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
699 |
|
699 | |||
700 | def __getFft(self): |
|
700 | def __getFft(self): | |
701 | """ |
|
701 | """ | |
702 | Convierte valores de Voltaje a Spectra |
|
702 | Convierte valores de Voltaje a Spectra | |
703 |
|
703 | |||
704 | Affected: |
|
704 | Affected: | |
705 | self.dataOut.data_spc |
|
705 | self.dataOut.data_spc | |
706 | self.dataOut.data_cspc |
|
706 | self.dataOut.data_cspc | |
707 | self.dataOut.data_dc |
|
707 | self.dataOut.data_dc | |
708 | self.dataOut.heightList |
|
708 | self.dataOut.heightList | |
709 | self.profIndex |
|
709 | self.profIndex | |
710 | self.buffer |
|
710 | self.buffer | |
711 | self.dataOut.flagNoData |
|
711 | self.dataOut.flagNoData | |
712 | """ |
|
712 | """ | |
713 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
713 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
714 | dc = fft_volt[:,0,:] |
|
714 | dc = fft_volt[:,0,:] | |
715 |
|
715 | |||
716 | #calculo de self-spectra |
|
716 | #calculo de self-spectra | |
717 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
717 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
718 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
718 | spc = fft_volt * numpy.conjugate(fft_volt) | |
719 | spc = spc.real |
|
719 | spc = spc.real | |
720 |
|
720 | |||
721 | blocksize = 0 |
|
721 | blocksize = 0 | |
722 | blocksize += dc.size |
|
722 | blocksize += dc.size | |
723 | blocksize += spc.size |
|
723 | blocksize += spc.size | |
724 |
|
724 | |||
725 | cspc = None |
|
725 | cspc = None | |
726 | pairIndex = 0 |
|
726 | pairIndex = 0 | |
727 | if self.dataOut.pairsList != None: |
|
727 | if self.dataOut.pairsList != None: | |
728 | #calculo de cross-spectra |
|
728 | #calculo de cross-spectra | |
729 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
729 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
730 | for pair in self.dataOut.pairsList: |
|
730 | for pair in self.dataOut.pairsList: | |
731 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) |
|
731 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) | |
732 | pairIndex += 1 |
|
732 | pairIndex += 1 | |
733 | blocksize += cspc.size |
|
733 | blocksize += cspc.size | |
734 |
|
734 | |||
735 | self.dataOut.data_spc = spc |
|
735 | self.dataOut.data_spc = spc | |
736 | self.dataOut.data_cspc = cspc |
|
736 | self.dataOut.data_cspc = cspc | |
737 | self.dataOut.data_dc = dc |
|
737 | self.dataOut.data_dc = dc | |
738 | self.dataOut.blockSize = blocksize |
|
738 | self.dataOut.blockSize = blocksize | |
739 |
|
739 | |||
740 | def init(self, nFFTPoints=None, pairsList=None): |
|
740 | def init(self, nFFTPoints=None, pairsList=None): | |
741 |
|
741 | |||
742 | self.dataOut.flagNoData = True |
|
742 | self.dataOut.flagNoData = True | |
743 |
|
743 | |||
744 | if self.dataIn.type == "Spectra": |
|
744 | if self.dataIn.type == "Spectra": | |
745 | self.dataOut.copy(self.dataIn) |
|
745 | self.dataOut.copy(self.dataIn) | |
746 | return |
|
746 | return | |
747 |
|
747 | |||
748 | if self.dataIn.type == "Voltage": |
|
748 | if self.dataIn.type == "Voltage": | |
749 |
|
749 | |||
750 | if nFFTPoints == None: |
|
750 | if nFFTPoints == None: | |
751 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" |
|
751 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" | |
752 |
|
752 | |||
753 | if pairsList == None: |
|
753 | if pairsList == None: | |
754 | nPairs = 0 |
|
754 | nPairs = 0 | |
755 | else: |
|
755 | else: | |
756 | nPairs = len(pairsList) |
|
756 | nPairs = len(pairsList) | |
757 |
|
757 | |||
758 | self.dataOut.nFFTPoints = nFFTPoints |
|
758 | self.dataOut.nFFTPoints = nFFTPoints | |
759 | self.dataOut.pairsList = pairsList |
|
759 | self.dataOut.pairsList = pairsList | |
760 | self.dataOut.nPairs = nPairs |
|
760 | self.dataOut.nPairs = nPairs | |
761 |
|
761 | |||
762 | if self.buffer == None: |
|
762 | if self.buffer == None: | |
763 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
763 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
764 | self.dataOut.nFFTPoints, |
|
764 | self.dataOut.nFFTPoints, | |
765 | self.dataIn.nHeights), |
|
765 | self.dataIn.nHeights), | |
766 | dtype='complex') |
|
766 | dtype='complex') | |
767 |
|
767 | |||
768 |
|
768 | |||
769 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() |
|
769 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() | |
770 | self.profIndex += 1 |
|
770 | self.profIndex += 1 | |
771 |
|
771 | |||
772 | if self.firstdatatime == None: |
|
772 | if self.firstdatatime == None: | |
773 | self.firstdatatime = self.dataIn.utctime |
|
773 | self.firstdatatime = self.dataIn.utctime | |
774 |
|
774 | |||
775 | if self.profIndex == self.dataOut.nFFTPoints: |
|
775 | if self.profIndex == self.dataOut.nFFTPoints: | |
776 | self.__updateObjFromInput() |
|
776 | self.__updateObjFromInput() | |
777 | self.__getFft() |
|
777 | self.__getFft() | |
778 |
|
778 | |||
779 | self.dataOut.flagNoData = False |
|
779 | self.dataOut.flagNoData = False | |
780 |
|
780 | |||
781 | self.buffer = None |
|
781 | self.buffer = None | |
782 | self.firstdatatime = None |
|
782 | self.firstdatatime = None | |
783 | self.profIndex = 0 |
|
783 | self.profIndex = 0 | |
784 |
|
784 | |||
785 | return |
|
785 | return | |
786 |
|
786 | |||
787 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) |
|
787 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) | |
788 |
|
788 | |||
789 | def selectChannels(self, channelList): |
|
789 | def selectChannels(self, channelList): | |
790 |
|
790 | |||
791 | channelIndexList = [] |
|
791 | channelIndexList = [] | |
792 |
|
792 | |||
793 | for channel in channelList: |
|
793 | for channel in channelList: | |
794 | index = self.dataOut.channelList.index(channel) |
|
794 | index = self.dataOut.channelList.index(channel) | |
795 | channelIndexList.append(index) |
|
795 | channelIndexList.append(index) | |
796 |
|
796 | |||
797 | self.selectChannelsByIndex(channelIndexList) |
|
797 | self.selectChannelsByIndex(channelIndexList) | |
798 |
|
798 | |||
799 | def selectChannelsByIndex(self, channelIndexList): |
|
799 | def selectChannelsByIndex(self, channelIndexList): | |
800 | """ |
|
800 | """ | |
801 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
801 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
802 |
|
802 | |||
803 | Input: |
|
803 | Input: | |
804 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
804 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
805 |
|
805 | |||
806 | Affected: |
|
806 | Affected: | |
807 | self.dataOut.data_spc |
|
807 | self.dataOut.data_spc | |
808 | self.dataOut.channelIndexList |
|
808 | self.dataOut.channelIndexList | |
809 | self.dataOut.nChannels |
|
809 | self.dataOut.nChannels | |
810 |
|
810 | |||
811 | Return: |
|
811 | Return: | |
812 | None |
|
812 | None | |
813 | """ |
|
813 | """ | |
814 |
|
814 | |||
815 | for channelIndex in channelIndexList: |
|
815 | for channelIndex in channelIndexList: | |
816 | if channelIndex not in self.dataOut.channelIndexList: |
|
816 | if channelIndex not in self.dataOut.channelIndexList: | |
817 | print channelIndexList |
|
817 | print channelIndexList | |
818 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
818 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
819 |
|
819 | |||
820 | nChannels = len(channelIndexList) |
|
820 | nChannels = len(channelIndexList) | |
821 |
|
821 | |||
822 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
822 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
823 |
|
823 | |||
824 | self.dataOut.data_spc = data_spc |
|
824 | self.dataOut.data_spc = data_spc | |
825 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
825 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
826 | # self.dataOut.nChannels = nChannels |
|
826 | # self.dataOut.nChannels = nChannels | |
827 |
|
827 | |||
828 | return 1 |
|
828 | return 1 | |
829 |
|
829 | |||
830 |
|
830 | |||
831 | class IncohInt(Operation): |
|
831 | class IncohInt(Operation): | |
832 |
|
832 | |||
833 |
|
833 | |||
834 | __profIndex = 0 |
|
834 | __profIndex = 0 | |
835 | __withOverapping = False |
|
835 | __withOverapping = False | |
836 |
|
836 | |||
837 | __byTime = False |
|
837 | __byTime = False | |
838 | __initime = None |
|
838 | __initime = None | |
839 | __lastdatatime = None |
|
839 | __lastdatatime = None | |
840 | __integrationtime = None |
|
840 | __integrationtime = None | |
841 |
|
841 | |||
842 | __buffer_spc = None |
|
842 | __buffer_spc = None | |
843 | __buffer_cspc = None |
|
843 | __buffer_cspc = None | |
844 | __buffer_dc = None |
|
844 | __buffer_dc = None | |
845 |
|
845 | |||
846 | __dataReady = False |
|
846 | __dataReady = False | |
847 |
|
847 | |||
848 | n = None |
|
848 | n = None | |
849 |
|
849 | |||
850 |
|
850 | |||
851 | def __init__(self): |
|
851 | def __init__(self): | |
852 |
|
852 | |||
853 | self.__isConfig = False |
|
853 | self.__isConfig = False | |
854 |
|
854 | |||
855 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
855 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
856 | """ |
|
856 | """ | |
857 | Set the parameters of the integration class. |
|
857 | Set the parameters of the integration class. | |
858 |
|
858 | |||
859 | Inputs: |
|
859 | Inputs: | |
860 |
|
860 | |||
861 | n : Number of coherent integrations |
|
861 | n : Number of coherent integrations | |
862 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
862 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
863 | overlapping : |
|
863 | overlapping : | |
864 |
|
864 | |||
865 | """ |
|
865 | """ | |
866 |
|
866 | |||
867 | self.__initime = None |
|
867 | self.__initime = None | |
868 | self.__lastdatatime = 0 |
|
868 | self.__lastdatatime = 0 | |
869 | self.__buffer_spc = None |
|
869 | self.__buffer_spc = None | |
870 | self.__buffer_cspc = None |
|
870 | self.__buffer_cspc = None | |
871 | self.__buffer_dc = None |
|
871 | self.__buffer_dc = None | |
872 | self.__dataReady = False |
|
872 | self.__dataReady = False | |
873 |
|
873 | |||
874 |
|
874 | |||
875 | if n == None and timeInterval == None: |
|
875 | if n == None and timeInterval == None: | |
876 | raise ValueError, "n or timeInterval should be specified ..." |
|
876 | raise ValueError, "n or timeInterval should be specified ..." | |
877 |
|
877 | |||
878 | if n != None: |
|
878 | if n != None: | |
879 | self.n = n |
|
879 | self.n = n | |
880 | self.__byTime = False |
|
880 | self.__byTime = False | |
881 | else: |
|
881 | else: | |
882 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
882 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
883 | self.n = 9999 |
|
883 | self.n = 9999 | |
884 | self.__byTime = True |
|
884 | self.__byTime = True | |
885 |
|
885 | |||
886 | if overlapping: |
|
886 | if overlapping: | |
887 | self.__withOverapping = True |
|
887 | self.__withOverapping = True | |
888 | else: |
|
888 | else: | |
889 | self.__withOverapping = False |
|
889 | self.__withOverapping = False | |
890 | self.__buffer_spc = 0 |
|
890 | self.__buffer_spc = 0 | |
891 | self.__buffer_cspc = 0 |
|
891 | self.__buffer_cspc = 0 | |
892 | self.__buffer_dc = 0 |
|
892 | self.__buffer_dc = 0 | |
893 |
|
893 | |||
894 | self.__profIndex = 0 |
|
894 | self.__profIndex = 0 | |
895 |
|
895 | |||
896 | def putData(self, data_spc, data_cspc, data_dc): |
|
896 | def putData(self, data_spc, data_cspc, data_dc): | |
897 |
|
897 | |||
898 | """ |
|
898 | """ | |
899 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
899 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
900 |
|
900 | |||
901 | """ |
|
901 | """ | |
902 |
|
902 | |||
903 | if not self.__withOverapping: |
|
903 | if not self.__withOverapping: | |
904 | self.__buffer_spc += data_spc |
|
904 | self.__buffer_spc += data_spc | |
905 |
|
905 | |||
906 | if data_cspc == None: |
|
906 | if data_cspc == None: | |
907 | self.__buffer_cspc = None |
|
907 | self.__buffer_cspc = None | |
908 | else: |
|
908 | else: | |
909 | self.__buffer_cspc += data_cspc |
|
909 | self.__buffer_cspc += data_cspc | |
910 |
|
910 | |||
911 | if data_dc == None: |
|
911 | if data_dc == None: | |
912 | self.__buffer_dc = None |
|
912 | self.__buffer_dc = None | |
913 | else: |
|
913 | else: | |
914 | self.__buffer_dc += data_dc |
|
914 | self.__buffer_dc += data_dc | |
915 |
|
915 | |||
916 | self.__profIndex += 1 |
|
916 | self.__profIndex += 1 | |
917 | return |
|
917 | return | |
918 |
|
918 | |||
919 | #Overlapping data |
|
919 | #Overlapping data | |
920 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
920 | nChannels, nFFTPoints, nHeis = data_spc.shape | |
921 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
921 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) | |
922 | if data_cspc != None: |
|
922 | if data_cspc != None: | |
923 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
923 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) | |
924 | if data_dc != None: |
|
924 | if data_dc != None: | |
925 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
925 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) | |
926 |
|
926 | |||
927 | #If the buffer is empty then it takes the data value |
|
927 | #If the buffer is empty then it takes the data value | |
928 | if self.__buffer_spc == None: |
|
928 | if self.__buffer_spc == None: | |
929 | self.__buffer_spc = data_spc |
|
929 | self.__buffer_spc = data_spc | |
930 |
|
930 | |||
931 | if data_cspc == None: |
|
931 | if data_cspc == None: | |
932 | self.__buffer_cspc = None |
|
932 | self.__buffer_cspc = None | |
933 | else: |
|
933 | else: | |
934 | self.__buffer_cspc += data_cspc |
|
934 | self.__buffer_cspc += data_cspc | |
935 |
|
935 | |||
936 | if data_dc == None: |
|
936 | if data_dc == None: | |
937 | self.__buffer_dc = None |
|
937 | self.__buffer_dc = None | |
938 | else: |
|
938 | else: | |
939 | self.__buffer_dc += data_dc |
|
939 | self.__buffer_dc += data_dc | |
940 |
|
940 | |||
941 | self.__profIndex += 1 |
|
941 | self.__profIndex += 1 | |
942 | return |
|
942 | return | |
943 |
|
943 | |||
944 | #If the buffer length is lower than n then stakcing the data value |
|
944 | #If the buffer length is lower than n then stakcing the data value | |
945 | if self.__profIndex < self.n: |
|
945 | if self.__profIndex < self.n: | |
946 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
946 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) | |
947 |
|
947 | |||
948 | if data_cspc != None: |
|
948 | if data_cspc != None: | |
949 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
949 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) | |
950 |
|
950 | |||
951 | if data_dc != None: |
|
951 | if data_dc != None: | |
952 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
952 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) | |
953 |
|
953 | |||
954 | self.__profIndex += 1 |
|
954 | self.__profIndex += 1 | |
955 | return |
|
955 | return | |
956 |
|
956 | |||
957 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
957 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
958 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
958 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) | |
959 | self.__buffer_spc[self.n-1] = data_spc |
|
959 | self.__buffer_spc[self.n-1] = data_spc | |
960 |
|
960 | |||
961 | if data_cspc != None: |
|
961 | if data_cspc != None: | |
962 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
962 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) | |
963 | self.__buffer_cspc[self.n-1] = data_cspc |
|
963 | self.__buffer_cspc[self.n-1] = data_cspc | |
964 |
|
964 | |||
965 | if data_dc != None: |
|
965 | if data_dc != None: | |
966 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
966 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) | |
967 | self.__buffer_dc[self.n-1] = data_dc |
|
967 | self.__buffer_dc[self.n-1] = data_dc | |
968 |
|
968 | |||
969 | self.__profIndex = self.n |
|
969 | self.__profIndex = self.n | |
970 | return |
|
970 | return | |
971 |
|
971 | |||
972 |
|
972 | |||
973 | def pushData(self): |
|
973 | def pushData(self): | |
974 | """ |
|
974 | """ | |
975 | Return the sum of the last profiles and the profiles used in the sum. |
|
975 | Return the sum of the last profiles and the profiles used in the sum. | |
976 |
|
976 | |||
977 | Affected: |
|
977 | Affected: | |
978 |
|
978 | |||
979 | self.__profileIndex |
|
979 | self.__profileIndex | |
980 |
|
980 | |||
981 | """ |
|
981 | """ | |
982 | data_spc = None |
|
982 | data_spc = None | |
983 | data_cspc = None |
|
983 | data_cspc = None | |
984 | data_dc = None |
|
984 | data_dc = None | |
985 |
|
985 | |||
986 | if not self.__withOverapping: |
|
986 | if not self.__withOverapping: | |
987 | data_spc = self.__buffer_spc |
|
987 | data_spc = self.__buffer_spc | |
988 | data_cspc = self.__buffer_cspc |
|
988 | data_cspc = self.__buffer_cspc | |
989 | data_dc = self.__buffer_dc |
|
989 | data_dc = self.__buffer_dc | |
990 |
|
990 | |||
991 | n = self.__profIndex |
|
991 | n = self.__profIndex | |
992 |
|
992 | |||
993 | self.__buffer_spc = 0 |
|
993 | self.__buffer_spc = 0 | |
994 | self.__buffer_cspc = 0 |
|
994 | self.__buffer_cspc = 0 | |
995 | self.__buffer_dc = 0 |
|
995 | self.__buffer_dc = 0 | |
996 | self.__profIndex = 0 |
|
996 | self.__profIndex = 0 | |
997 |
|
997 | |||
998 | return data_spc, data_cspc, data_dc, n |
|
998 | return data_spc, data_cspc, data_dc, n | |
999 |
|
999 | |||
1000 | #Integration with Overlapping |
|
1000 | #Integration with Overlapping | |
1001 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
1001 | data_spc = numpy.sum(self.__buffer_spc, axis=0) | |
1002 |
|
1002 | |||
1003 | if self.__buffer_cspc != None: |
|
1003 | if self.__buffer_cspc != None: | |
1004 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
1004 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) | |
1005 |
|
1005 | |||
1006 | if self.__buffer_dc != None: |
|
1006 | if self.__buffer_dc != None: | |
1007 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
1007 | data_dc = numpy.sum(self.__buffer_dc, axis=0) | |
1008 |
|
1008 | |||
1009 | n = self.__profIndex |
|
1009 | n = self.__profIndex | |
1010 |
|
1010 | |||
1011 | return data_spc, data_cspc, data_dc, n |
|
1011 | return data_spc, data_cspc, data_dc, n | |
1012 |
|
1012 | |||
1013 | def byProfiles(self, *args): |
|
1013 | def byProfiles(self, *args): | |
1014 |
|
1014 | |||
1015 | self.__dataReady = False |
|
1015 | self.__dataReady = False | |
1016 | avgdata_spc = None |
|
1016 | avgdata_spc = None | |
1017 | avgdata_cspc = None |
|
1017 | avgdata_cspc = None | |
1018 | avgdata_dc = None |
|
1018 | avgdata_dc = None | |
1019 | n = None |
|
1019 | n = None | |
1020 |
|
1020 | |||
1021 | self.putData(*args) |
|
1021 | self.putData(*args) | |
1022 |
|
1022 | |||
1023 | if self.__profIndex == self.n: |
|
1023 | if self.__profIndex == self.n: | |
1024 |
|
1024 | |||
1025 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1025 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
1026 | self.__dataReady = True |
|
1026 | self.__dataReady = True | |
1027 |
|
1027 | |||
1028 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1028 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1029 |
|
1029 | |||
1030 | def byTime(self, datatime, *args): |
|
1030 | def byTime(self, datatime, *args): | |
1031 |
|
1031 | |||
1032 | self.__dataReady = False |
|
1032 | self.__dataReady = False | |
1033 | avgdata_spc = None |
|
1033 | avgdata_spc = None | |
1034 | avgdata_cspc = None |
|
1034 | avgdata_cspc = None | |
1035 | avgdata_dc = None |
|
1035 | avgdata_dc = None | |
1036 | n = None |
|
1036 | n = None | |
1037 |
|
1037 | |||
1038 | self.putData(*args) |
|
1038 | self.putData(*args) | |
1039 |
|
1039 | |||
1040 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1040 | if (datatime - self.__initime) >= self.__integrationtime: | |
1041 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1041 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
1042 | self.n = n |
|
1042 | self.n = n | |
1043 | self.__dataReady = True |
|
1043 | self.__dataReady = True | |
1044 |
|
1044 | |||
1045 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1045 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1046 |
|
1046 | |||
1047 | def integrate(self, datatime, *args): |
|
1047 | def integrate(self, datatime, *args): | |
1048 |
|
1048 | |||
1049 | if self.__initime == None: |
|
1049 | if self.__initime == None: | |
1050 | self.__initime = datatime |
|
1050 | self.__initime = datatime | |
1051 |
|
1051 | |||
1052 | if self.__byTime: |
|
1052 | if self.__byTime: | |
1053 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
1053 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) | |
1054 | else: |
|
1054 | else: | |
1055 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
1055 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
1056 |
|
1056 | |||
1057 | self.__lastdatatime = datatime |
|
1057 | self.__lastdatatime = datatime | |
1058 |
|
1058 | |||
1059 | if avgdata_spc == None: |
|
1059 | if avgdata_spc == None: | |
1060 | return None, None, None, None |
|
1060 | return None, None, None, None | |
1061 |
|
1061 | |||
1062 | avgdatatime = self.__initime |
|
1062 | avgdatatime = self.__initime | |
1063 |
|
1063 | |||
1064 | deltatime = datatime -self.__lastdatatime |
|
1064 | deltatime = datatime -self.__lastdatatime | |
1065 |
|
1065 | |||
1066 | if not self.__withOverapping: |
|
1066 | if not self.__withOverapping: | |
1067 | self.__initime = datatime |
|
1067 | self.__initime = datatime | |
1068 | else: |
|
1068 | else: | |
1069 | self.__initime += deltatime |
|
1069 | self.__initime += deltatime | |
1070 |
|
1070 | |||
1071 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
1071 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc | |
1072 |
|
1072 | |||
1073 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
1073 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
1074 |
|
1074 | |||
1075 | if not self.__isConfig: |
|
1075 | if not self.__isConfig: | |
1076 | self.setup(n, timeInterval, overlapping) |
|
1076 | self.setup(n, timeInterval, overlapping) | |
1077 | self.__isConfig = True |
|
1077 | self.__isConfig = True | |
1078 |
|
1078 | |||
1079 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
1079 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, | |
1080 | dataOut.data_spc, |
|
1080 | dataOut.data_spc, | |
1081 | dataOut.data_cspc, |
|
1081 | dataOut.data_cspc, | |
1082 | dataOut.data_dc) |
|
1082 | dataOut.data_dc) | |
1083 |
|
1083 | |||
1084 | # dataOut.timeInterval *= n |
|
1084 | # dataOut.timeInterval *= n | |
1085 | dataOut.flagNoData = True |
|
1085 | dataOut.flagNoData = True | |
1086 |
|
1086 | |||
1087 | if self.__dataReady: |
|
1087 | if self.__dataReady: | |
1088 |
|
1088 | |||
1089 | dataOut.data_spc = avgdata_spc / self.n |
|
1089 | dataOut.data_spc = avgdata_spc / self.n | |
1090 | dataOut.data_cspc = avgdata_cspc / self.n |
|
1090 | dataOut.data_cspc = avgdata_cspc / self.n | |
1091 | dataOut.data_dc = avgdata_dc / self.n |
|
1091 | dataOut.data_dc = avgdata_dc / self.n | |
1092 |
|
1092 | |||
1093 | dataOut.nIncohInt *= self.n |
|
1093 | dataOut.nIncohInt *= self.n | |
1094 | dataOut.utctime = avgdatatime |
|
1094 | dataOut.utctime = avgdatatime | |
1095 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
1095 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints | |
1096 | dataOut.flagNoData = False |
|
1096 | dataOut.flagNoData = False | |
1097 |
|
1097 | |||
1098 | class ProfileSelector(Operation): |
|
1098 | class ProfileSelector(Operation): | |
1099 |
|
1099 | |||
1100 | profileIndex = None |
|
1100 | profileIndex = None | |
1101 | # Tamanho total de los perfiles |
|
1101 | # Tamanho total de los perfiles | |
1102 | nProfiles = None |
|
1102 | nProfiles = None | |
1103 |
|
1103 | |||
1104 | def __init__(self): |
|
1104 | def __init__(self): | |
1105 |
|
1105 | |||
1106 | self.profileIndex = 0 |
|
1106 | self.profileIndex = 0 | |
1107 |
|
1107 | |||
1108 | def incIndex(self): |
|
1108 | def incIndex(self): | |
1109 | self.profileIndex += 1 |
|
1109 | self.profileIndex += 1 | |
1110 |
|
1110 | |||
1111 | if self.profileIndex >= self.nProfiles: |
|
1111 | if self.profileIndex >= self.nProfiles: | |
1112 | self.profileIndex = 0 |
|
1112 | self.profileIndex = 0 | |
1113 |
|
1113 | |||
1114 | def isProfileInRange(self, minIndex, maxIndex): |
|
1114 | def isProfileInRange(self, minIndex, maxIndex): | |
1115 |
|
1115 | |||
1116 | if self.profileIndex < minIndex: |
|
1116 | if self.profileIndex < minIndex: | |
1117 | return False |
|
1117 | return False | |
1118 |
|
1118 | |||
1119 | if self.profileIndex > maxIndex: |
|
1119 | if self.profileIndex > maxIndex: | |
1120 | return False |
|
1120 | return False | |
1121 |
|
1121 | |||
1122 | return True |
|
1122 | return True | |
1123 |
|
1123 | |||
1124 | def isProfileInList(self, profileList): |
|
1124 | def isProfileInList(self, profileList): | |
1125 |
|
1125 | |||
1126 | if self.profileIndex not in profileList: |
|
1126 | if self.profileIndex not in profileList: | |
1127 | return False |
|
1127 | return False | |
1128 |
|
1128 | |||
1129 | return True |
|
1129 | return True | |
1130 |
|
1130 | |||
1131 | def run(self, dataOut, profileList=None, profileRangeList=None): |
|
1131 | def run(self, dataOut, profileList=None, profileRangeList=None): | |
1132 |
|
1132 | |||
1133 | dataOut.flagNoData = True |
|
1133 | dataOut.flagNoData = True | |
1134 | self.nProfiles = dataOut.nProfiles |
|
1134 | self.nProfiles = dataOut.nProfiles | |
1135 |
|
1135 | |||
1136 | if profileList != None: |
|
1136 | if profileList != None: | |
1137 | if self.isProfileInList(profileList): |
|
1137 | if self.isProfileInList(profileList): | |
1138 | dataOut.flagNoData = False |
|
1138 | dataOut.flagNoData = False | |
1139 |
|
1139 | |||
1140 | self.incIndex() |
|
1140 | self.incIndex() | |
1141 | return 1 |
|
1141 | return 1 | |
1142 |
|
1142 | |||
1143 |
|
1143 | |||
1144 | elif profileRangeList != None: |
|
1144 | elif profileRangeList != None: | |
1145 | minIndex = profileRangeList[0] |
|
1145 | minIndex = profileRangeList[0] | |
1146 | maxIndex = profileRangeList[1] |
|
1146 | maxIndex = profileRangeList[1] | |
1147 | if self.isProfileInRange(minIndex, maxIndex): |
|
1147 | if self.isProfileInRange(minIndex, maxIndex): | |
1148 | dataOut.flagNoData = False |
|
1148 | dataOut.flagNoData = False | |
1149 |
|
1149 | |||
1150 | self.incIndex() |
|
1150 | self.incIndex() | |
1151 | return 1 |
|
1151 | return 1 | |
1152 |
|
1152 | |||
1153 | else: |
|
1153 | else: | |
1154 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" |
|
1154 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" | |
1155 |
|
1155 | |||
1156 | return 0 |
|
1156 | return 0 | |
1157 |
|
1157 |
General Comments 0
You need to be logged in to leave comments.
Login now