##// 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 182 self.plotObjIndex += 1
183 183
184 184
185 def addIntegrator(self,N,timeInterval):
186 objCohInt = CoherentIntegrator(N,timeInterval)
185 def addIntegrator(self, *args):
186 objCohInt = CoherentIntegrator(*args)
187 187 self.integratorObjList.append(objCohInt)
188 188
189 def addWriter(self, wrpath, blocksPerFile, profilesPerBlock):
189 def addWriter(self, *args):
190 190 writerObj = VoltageWriter(self.dataOutObj)
191 writerObj.setup(wrpath,blocksPerFile,profilesPerBlock)
191 writerObj.setup(*args)
192 192 self.writerObjList.append(writerObj)
193 193
194 194 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
@@ -203,86 +203,170 class VoltageProcessor:
203 203
204 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 208 if self.dataOutObj.flagNoData:
208 209 return 0
210
209 211 if len(self.integratorObjList) <= self.integratorObjIndex:
210 self.addIntegrator(N,timeInterval)
212 self.addIntegrator(nCohInt, timeInterval, overlapping)
211 213
212 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 224 class CoherentIntegrator:
218 225
219 integ_counter = None
220 data = None
221 navg = None
222 buffer = None
226
227 __profIndex = 0
228 __withOverapping = False
229
230 __isByTime = False
231 __initime = None
232 __integrationtime = None
233
234 __buffer = None
235
236 isReady = False
223 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
228 self.navg = None
229 self.buffer = None
230 self.timeOut = None
231 self.exitCondition = False
247 nCohInt : Number of coherent integrations
248 timeInterval : Time of integration. If nCohInt is selected this parameter does not work
249 overlapping :
250
251 """
252
253 self.__buffer = None
232 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)):
239 raise ValueError, "N = None ; timeInterval = None"
256 if nCohInt == None and timeInterval == None:
257 raise ValueError, "nCohInt or timeInterval should be specified ..."
240 258
241 if timeInterval == None:
242 self.timeFlag = False
259 if nCohInt != None:
260 self.nCohInt = nCohInt
261 self.__isByTime = False
243 262 else:
244 self.timeFlag = True
245
246 def exe(self, data, timeOfData):
263 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
264 self.__isByTime = True
247 265
248 if self.timeFlag:
249 if self.timeOut == None:
250 self.timeOut = timeOfData + self.timeIntervalInSeconds
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
266 if overlapping:
267 self.__withOverapping = True
268 self.__buffer = None
261 269 else:
262 if self.integ_counter < self.nCohInt:
263 if self.buffer == None:
264 self.buffer = data
265 else:
266 self.buffer = self.buffer + data
270 self.__withOverapping = False
271 self.__buffer = 0
272
273 self.__profIndex = 0
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
269
270 if self.integ_counter == self.nCohInt:
271 self.exitCondition = True
272
273 if self.exitCondition:
274 self.data = self.buffer
275 self.navg = self.integ_counter
323 return data, nCohInt
324
325 #Overlapping data
326 data = numpy.sum(self.__buffer, axis=0)
327 nCohInt = self.__profIndex
328
329 return data, nCohInt
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 340 self.isReady = True
277 self.buffer = None
278 self.timeOut = None
279 self.integ_counter = 0
280 self.exitCondition = False
281
282 if self.timeFlag:
283 self.buffer = data
284 self.timeOut = timeOfData + self.timeIntervalInSeconds
341
342 return avg_data
343
344 def byTime(self, data, datatime):
345
346 self.isReady = False
347 avg_data = None
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 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