##// END OF EJS Templates
Se añadio el modulo de integración incluyendo overlapping
Miguel Valdez -
r143:d8eaadd4a3f7
parent child
Show More
@@ -182,13 +182,13 class VoltageProcessor:
182 self.plotObjIndex += 1
182 self.plotObjIndex += 1
183
183
184
184
185 def addIntegrator(self,N,timeInterval):
185 def addIntegrator(self, *args):
186 objCohInt = CoherentIntegrator(N,timeInterval)
186 objCohInt = CoherentIntegrator(*args)
187 self.integratorObjList.append(objCohInt)
187 self.integratorObjList.append(objCohInt)
188
188
189 def addWriter(self, wrpath, blocksPerFile, profilesPerBlock):
189 def addWriter(self, *args):
190 writerObj = VoltageWriter(self.dataOutObj)
190 writerObj = VoltageWriter(self.dataOutObj)
191 writerObj.setup(wrpath,blocksPerFile,profilesPerBlock)
191 writerObj.setup(*args)
192 self.writerObjList.append(writerObj)
192 self.writerObjList.append(writerObj)
193
193
194 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
194 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
@@ -203,86 +203,170 class VoltageProcessor:
203
203
204 self.writerObjIndex += 1
204 self.writerObjIndex += 1
205
205
206 def integrator(self, N=None, timeInterval=None):
206 def integrator(self, nCohInt=None, timeInterval=None, overlapping=False):
207
207 if self.dataOutObj.flagNoData:
208 if self.dataOutObj.flagNoData:
208 return 0
209 return 0
210
209 if len(self.integratorObjList) <= self.integratorObjIndex:
211 if len(self.integratorObjList) <= self.integratorObjIndex:
210 self.addIntegrator(N,timeInterval)
212 self.addIntegrator(nCohInt, timeInterval, overlapping)
211
213
212 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
214 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
213 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=None)
215 myCohIntObj.exe(data = self.dataOutObj.data, datatime=None)
216
217 self.dataOutObj.flagNoData = True
218
219 if myCohIntObj.isReady:
220 self.dataOutObj.flagNoData = False
214
221
215
222
216
223
217 class CoherentIntegrator:
224 class CoherentIntegrator:
218
225
219 integ_counter = None
226
220 data = None
227 __profIndex = 0
221 navg = None
228 __withOverapping = False
222 buffer = None
229
230 __isByTime = False
231 __initime = None
232 __integrationtime = None
233
234 __buffer = None
235
236 isReady = False
223 nCohInt = None
237 nCohInt = None
224
238
225 def __init__(self, N=None,timeInterval=None):
239
240 def __init__(self, nCohInt=None, timeInterval=None, overlapping=False):
241
242 """
243 Set the parameters of the integration class.
244
245 Inputs:
226
246
227 self.data = None
247 nCohInt : Number of coherent integrations
228 self.navg = None
248 timeInterval : Time of integration. If nCohInt is selected this parameter does not work
229 self.buffer = None
249 overlapping :
230 self.timeOut = None
250
231 self.exitCondition = False
251 """
252
253 self.__buffer = None
232 self.isReady = False
254 self.isReady = False
233 self.nCohInt = N
234 self.integ_counter = 0
235 if timeInterval!=None:
236 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
237
255
238 if ((timeInterval==None) and (N==None)):
256 if nCohInt == None and timeInterval == None:
239 raise ValueError, "N = None ; timeInterval = None"
257 raise ValueError, "nCohInt or timeInterval should be specified ..."
240
258
241 if timeInterval == None:
259 if nCohInt != None:
242 self.timeFlag = False
260 self.nCohInt = nCohInt
261 self.__isByTime = False
243 else:
262 else:
244 self.timeFlag = True
263 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
245
264 self.__isByTime = True
246 def exe(self, data, timeOfData):
247
265
248 if self.timeFlag:
266 if overlapping:
249 if self.timeOut == None:
267 self.__withOverapping = True
250 self.timeOut = timeOfData + self.timeIntervalInSeconds
268 self.__buffer = None
251
252 if timeOfData < self.timeOut:
253 if self.buffer == None:
254 self.buffer = data
255 else:
256 self.buffer = self.buffer + data
257 self.integ_counter += 1
258 else:
259 self.exitCondition = True
260
261 else:
269 else:
262 if self.integ_counter < self.nCohInt:
270 self.__withOverapping = False
263 if self.buffer == None:
271 self.__buffer = 0
264 self.buffer = data
272
265 else:
273 self.__profIndex = 0
266 self.buffer = self.buffer + data
274
275 def putData(self, data):
276
277 """
278 Add a profile to the __buffer and increase in one the __profileIndex
279
280 """
281 if not self.__withOverapping:
282 self.__buffer += data
283 self.__profIndex += 1
284 return
285
286 #Overlapping data
287 nChannels, nProfiles = data.shape
288 data = numpy.reshape(data, (1, nChannels, nProfiles))
289
290 if self.__buffer == None:
291 self.__buffer = data
292 self.__profIndex += 1
293 return
294
295 if self.__profIndex < self.nCohInt:
296 self.__buffer = numpy.vstack((self.__buffer, data))
297 self.__profIndex += 1
298 return
299
300 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
301 self.__buffer[self.nCohInt-1] = data
302 #self.__profIndex = self.nCohInt
303 return
304
305
306 def pushData(self):
307 """
308 Return the sum of the last profiles and the profiles used in the sum.
309
310 Affected:
311
312 self.__profileIndex
313
314 """
315
316 if not self.__withOverapping:
317 data = self.__buffer
318 nCohInt = self.__profIndex
319
320 self.__buffer = 0
321 self.__profIndex = 0
267
322
268 self.integ_counter += 1
323 return data, nCohInt
269
324
270 if self.integ_counter == self.nCohInt:
325 #Overlapping data
271 self.exitCondition = True
326 data = numpy.sum(self.__buffer, axis=0)
272
327 nCohInt = self.__profIndex
273 if self.exitCondition:
328
274 self.data = self.buffer
329 return data, nCohInt
275 self.navg = self.integ_counter
330
331 def byProfiles(self, data):
332
333 self.isReady = False
334 avg_data = None
335
336 self.putData(data)
337
338 if self.__profIndex == self.nCohInt:
339 avg_data, nCohInt = self.pushData()
276 self.isReady = True
340 self.isReady = True
277 self.buffer = None
341
278 self.timeOut = None
342 return avg_data
279 self.integ_counter = 0
343
280 self.exitCondition = False
344 def byTime(self, data, datatime):
281
345
282 if self.timeFlag:
346 self.isReady = False
283 self.buffer = data
347 avg_data = None
284 self.timeOut = timeOfData + self.timeIntervalInSeconds
348
349 if self.__initime == None:
350 self.__initime = datatime
351
352 self.putData(data)
353
354 if (datatime - self.__initime) >= self.__integrationtime:
355 avg_data, nCohInt = self.pushData()
356 self.nCohInt = nCohInt
357 self.isReady = True
358
359 return avg_data
360
361 def exe(self, data, datatime=None):
362
363 if not self.__isByTime:
364 avg_data = self.byProfiles(data)
285 else:
365 else:
286 self.isReady = False
366 avg_data = self.byTime(data, datatime)
367
368 self.data = avg_data
369
370 return avg_data
287
371
288
372
General Comments 0
You need to be logged in to leave comments. Login now