##// END OF EJS Templates
Se añadio la clase SpectraHeis
Alexander Valdez -
r145:0d184bf86479
parent child
Show More
@@ -1,371 +1,516
1 '''
1 '''
2
2
3 $Author$
3 $Author$
4 $Id$
4 $Id$
5 '''
5 '''
6
6
7 import os, sys
7 import os, sys
8 import numpy
8 import numpy
9 import time
9 import time
10 import datetime
10 import datetime
11 path = os.path.split(os.getcwd())[0]
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
12 sys.path.append(path)
13
13
14 from Data.JROData import Spectra
14 from Data.JROData import SpectraHeis
15 from IO.SpectraIO import SpectraWriter
15 from IO.SpectraIO import SpectraWriter
16 from Graphics.schainPlotTypes import SpcFigure
16 #from Graphics.schainPlotTypes import SpcFigure
17 #from JRONoise import Noise
17 #from JRONoise import Noise
18
18
19 class SpectraProcessor:
19 class SpectraProcessor:
20 '''
20 '''
21 classdocs
21 classdocs
22 '''
22 '''
23
23
24 dataInObj = None
24 dataInObj = None
25
25
26 dataOutObj = None
26 dataOutObj = None
27
27
28 noiseObj = None
28 noiseObj = None
29
29
30 integratorObjList = []
30 integratorObjList = []
31
31
32 writerObjList = []
32 writerObjList = []
33
33
34 integratorObjIndex = None
34 integratorObjIndex = None
35
35
36 writerObjIndex = None
36 writerObjIndex = None
37
37
38 profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage
38 profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage
39
39
40
40
41 def __init__(self):
41 def __init__(self):
42 '''
42 '''
43 Constructor
43 Constructor
44 '''
44 '''
45
45
46 self.integratorObjIndex = None
46 self.integratorObjIndex = None
47 self.writerObjIndex = None
47 self.writerObjIndex = None
48 self.plotObjIndex = None
48 self.plotObjIndex = None
49 self.integratorObjList = []
49 self.integratorOst = []
50 self.writerObjList = []
51 self.plotObjList = []
50 self.plotObjList = []
52 self.noiseObj = None
51 self.noiseObj = bjList = []
52 self.writerObjLiNone
53 self.buffer = None
53 self.buffer = None
54 self.profIndex = 0
54 self.profIndex = 0
55
55
56 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
56 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
57
57
58 if dataInObj == None:
58 if dataInObj == None:
59 raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable"
59 raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable"
60
60
61 if dataInObj.type == "Voltage":
61 if dataInObj.type == "Voltage":
62 if nFFTPoints == None:
62 if nFFTPoints == None:
63 raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable"
63 raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable"
64 else:
64 else:
65 nFFTPoints = dataInObj.nFFTPoints
65 nFFTPoints = dataInObj.nFFTPoints
66
66
67 self.dataInObj = dataInObj
67 self.dataInObj = dataInObj
68
68
69 if dataOutObj == None:
69 if dataOutObj == None:
70 dataOutObj = Spectra()
70 dataOutObj = Spectra()
71
71
72 self.dataOutObj = dataOutObj
72 self.dataOutObj = dataOutObj
73
73
74 return self.dataOutObj
74 return self.dataOutObj
75
75
76 def init(self):
76 def init(self):
77
77
78 self.integratorObjIndex = 0
78 self.integratorObjIndex = 0
79 self.writerObjIndex = 0
79 self.writerObjIndex = 0
80 self.plotObjIndex = 0
80 self.plotObjIndex = 0
81 if self.dataInObj.type == "Voltage":
81 if self.dataInObj.type == "Voltage":
82
82
83 if self.buffer == None:
83 if self.buffer == None:
84 self.buffer = numpy.zeros((self.nChannels,
84 self.buffer = numpy.zeros((self.nChannels,
85 self.nFFTPoints,
85 self.nFFTPoints,
86 self.dataInObj.nHeights),
86 self.dataInObj.nHeights),
87 dtype='complex')
87 dtype='complex')
88
88
89 self.buffer[:,self.profIndex,:] = self.dataInObj.data
89 self.buffer[:,self.profIndex,:] = self.dataInObj.data
90 self.profIndex += 1
90 self.profIndex += 1
91
91
92 if self.profIndex == self.nFFTPoints:
92 if self.profIndex == self.nFFTPoints:
93 self.__getFft()
93 self.__getFft()
94 self.dataOutObj.flagNoData = False
94 self.dataOutObj.flagNoData = False
95
95
96 self.buffer = None
96 self.buffer = None
97 self.profIndex = 0
97 self.profIndex = 0
98 return
98 return
99
99
100 self.dataOutObj.flagNoData = True
100 self.dataOutObj.flagNoData = True
101
101
102 return
102 return
103
103
104 #Other kind of data
104 #Other kind of data
105 if self.dataInObj.type == "Spectra":
105 if self.dataInObj.type == "Spectra":
106 self.dataOutObj.copy(self.dataInObj)
106 self.dataOutObj.copy(self.dataInObj)
107 self.dataOutObj.flagNoData = False
107 self.dataOutObj.flagNoData = False
108 return
108 return
109
109
110 raise ValueError, "The datatype is not valid"
110 raise ValueError, "The datatype is not valid"
111
111
112 def __getFft(self):
112 def __getFft(self):
113 """
113 """
114 Convierte valores de Voltaje a Spectra
114 Convierte valores de Voltaje a Spectra
115
115
116 Affected:
116 Affected:
117 self.dataOutObj.data_spc
117 self.dataOutObj.data_spc
118 self.dataOutObj.data_cspc
118 self.dataOutObj.data_cspc
119 self.dataOutObj.data_dc
119 self.dataOutObj.data_dc
120 self.dataOutObj.heightList
120 self.dataOutObj.heightList
121 self.dataOutObj.m_BasicHeader
121 self.dataOutObj.m_BasicHeader
122 self.dataOutObj.m_ProcessingHeader
122 self.dataOutObj.m_ProcessingHeader
123 self.dataOutObj.m_RadarControllerHeader
123 self.dataOutObj.m_RadarControllerHeader
124 self.dataOutObj.m_SystemHeader
124 self.dataOutObj.m_SystemHeader
125 self.profIndex
125 self.profIndex
126 self.buffer
126 self.buffer
127 self.dataOutObj.flagNoData
127 self.dataOutObj.flagNoData
128 self.dataOutObj.dataType
128 self.dataOutObj.dataType
129 self.dataOutObj.nPairs
129 self.dataOutObj.nPairs
130 self.dataOutObj.nChannels
130 self.dataOutObj.nChannels
131 self.dataOutObj.nProfiles
131 self.dataOutObj.nProfiles
132 self.dataOutObj.m_SystemHeader.numChannels
132 self.dataOutObj.m_SystemHeader.numChannels
133 self.dataOutObj.m_ProcessingHeader.totalSpectra
133 self.dataOutObj.m_ProcessingHeader.totalSpectra
134 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
134 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
135 self.dataOutObj.m_ProcessingHeader.numHeights
135 self.dataOutObj.m_ProcessingHeader.numHeights
136 self.dataOutObj.m_ProcessingHeader.spectraComb
136 self.dataOutObj.m_ProcessingHeader.spectraComb
137 self.dataOutObj.m_ProcessingHeader.shif_fft
137 self.dataOutObj.m_ProcessingHeader.shif_fft
138 """
138 """
139
139
140 if self.dataInObj.flagNoData:
140 if self.dataInObj.flagNoData:
141 return 0
141 return 0
142
142
143 fft_volt = numpy.fft.fft(self.buffer,axis=1)
143 fft_volt = numpy.fft.fft(self.buffer,axis=1)
144 dc = fft_volt[:,0,:]
144 dc = fft_volt[:,0,:]
145
145
146 #calculo de self-spectra
146 #calculo de self-spectra
147 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
147 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
148 spc = fft_volt * numpy.conjugate(fft_volt)
148 spc = fft_volt * numpy.conjugate(fft_volt)
149 spc = spc.real
149 spc = spc.real
150
150
151 blocksize = 0
151 blocksize = 0
152 blocksize += dc.size
152 blocksize += dc.size
153 blocksize += spc.size
153 blocksize += spc.size
154
154
155 cspc = None
155 cspc = None
156 pairIndex = 0
156 pairIndex = 0
157 if self.pairList != None:
157 if self.pairList != None:
158 #calculo de cross-spectra
158 #calculo de cross-spectra
159 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
159 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
160 for pair in self.pairList:
160 for pair in self.pairList:
161 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
161 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
162 pairIndex += 1
162 pairIndex += 1
163 blocksize += cspc.size
163 blocksize += cspc.size
164
164
165 self.dataOutObj.data_spc = spc
165 self.dataOutObj.data_spc = spc
166 self.dataOutObj.data_cspc = cspc
166 self.dataOutObj.data_cspc = cspc
167 self.dataOutObj.data_dc = dc
167 self.dataOutObj.data_dc = dc
168 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
168 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
169 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
169 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
170
170
171 # self.getNoise()
171 # self.getNoise()
172
172
173 def addWriter(self, wrpath, blocksPerFile):
173 def addWriter(self, wrpath, blocksPerFile):
174 objWriter = SpectraWriter(self.dataOutObj)
174 objWriter = SpectraWriter(self.dataOutObj)
175 objWriter.setup(wrpath, blocksPerFile)
175 objWriter.setup(wrpath, blocksPerFile)
176 self.writerObjList.append(objWriter)
176 self.writerObjList.append(objWriter)
177
177
178 def addIntegrator(self,N,timeInterval):
178 def addIntegrator(self,N,timeInterval):
179
179
180 objIncohInt = IncoherentIntegration(N,timeInterval)
180 objIncohInt = IncoherentIntegration(N,timeInterval)
181 self.integratorObjList.append(objIncohInt)
181 self.integratorObjList.append(objIncohInt)
182
182
183 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
183 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
184 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
184 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
185 self.plotObjList.append(spcObj)
185 self.plotObjList.append(spcObj)
186
186
187 def plotSpc(self, idfigure=None,
187 def plotSpc(self, idfigure=None,
188 xmin=None,
188 xmin=None,
189 xmax=None,
189 xmax=None,
190 ymin=None,
190 ymin=None,
191 ymax=None,
191 ymax=None,
192 minvalue=None,
192 minvalue=None,
193 maxvalue=None,
193 maxvalue=None,
194 wintitle='',
194 wintitle='',
195 driver='plplot',
195 driver='plplot',
196 colormap='br_greeen',
196 colormap='br_greeen',
197 colorbar=True,
197 colorbar=True,
198 showprofile=False,
198 showprofile=False,
199 save=False,
199 save=False,
200 gpath=None):
200 gpath=None):
201
201
202 if self.dataOutObj.flagNoData:
202 if self.dataOutObj.flagNoData:
203 return 0
203 return 0
204
204
205 nframes = len(self.dataOutObj.channelList)
205 nframes = len(self.dataOutObj.channelList)
206
206
207 if len(self.plotObjList) <= self.plotObjIndex:
207 if len(self.plotObjList) <= self.plotObjIndex:
208 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
208 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
209
209
210 x = numpy.arange(self.dataOutObj.nFFTPoints)
210 x = numpy.arange(self.dataOutObj.nFFTPoints)
211
211
212 y = self.dataOutObj.heightList
212 y = self.dataOutObj.heightList
213
213
214 channelList = self.dataOutObj.channelList
214 channelList = self.dataOutObj.channelList
215
215
216 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
216 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
217 # noisedB = 10.*numpy.log10(noise)
217 # noisedB = 10.*numpy.log10(noise)
218 noisedB = numpy.arange(len(channelList)+1)
218 noisedB = numpy.arange(len(channelList)+1)
219 noisedB = noisedB *1.2
219 noisedB = noisedB *1.2
220 titleList = []
220 titleList = []
221 for i in range(len(noisedB)):
221 for i in range(len(noisedB)):
222 title = "%.2f"%noisedB[i]
222 title = "%.2f"%noisedB[i]
223 titleList.append(title)
223 titleList.append(title)
224
224
225 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
225 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
226 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
226 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
227 figuretitle = "Spc Radar Data: %s"%dateTime
227 figuretitle = "Spc Radar Data: %s"%dateTime
228
228
229 cleardata = True
229 cleardata = True
230
230
231 plotObj = self.plotObjList[self.plotObjIndex]
231 plotObj = self.plotObjList[self.plotObjIndex]
232
232
233 plotObj.plotPcolor(data,
233 plotObj.plotPcolor(data,
234 x,
234 x,
235 y,
235 y,
236 channelList,
236 channelList,
237 xmin,
237 xmin,
238 xmax,
238 xmax,
239 ymin,
239 ymin,
240 ymax,
240 ymax,
241 minvalue,
241 minvalue,
242 maxvalue,
242 maxvalue,
243 figuretitle,
243 figuretitle,
244 None,
244 None,
245 save,
245 save,
246 gpath,
246 gpath,
247 cleardata,
247 cleardata,
248 titleList)
248 titleList)
249
249
250 self.plotObjIndex += 1
250 self.plotObjIndex += 1
251
251
252
252
253 def writeData(self, wrpath, blocksPerFile):
253 def writeData(self, wrpath, blocksPerFile):
254 if self.dataOutObj.flagNoData:
254 if self.dataOutObj.flagNoData:
255 return 0
255 return 0
256
256
257 if len(self.writerObjList) <= self.writerObjIndex:
257 if len(self.writerObjList) <= self.writerObjIndex:
258 self.addWriter(wrpath, blocksPerFile)
258 self.addWriter(wrpath, blocksPerFile)
259
259
260 self.writerObjList[self.writerObjIndex].putData()
260 self.writerObjList[self.writerObjIndex].putData()
261
261
262 self.writerObjIndex += 1
262 self.writerObjIndex += 1
263
263
264 def integrator(self, N=None, timeInterval=None):
264 def integrator(self, N=None, timeInterval=None):
265
265
266 if self.dataOutObj.flagNoData:
266 if self.dataOutObj.flagNoData:
267 return 0
267 return 0
268
268
269 if len(self.integratorObjList) <= self.integratorObjIndex:
269 if len(self.integratorObjList) <= self.integratorObjIndex:
270 self.addIntegrator(N,timeInterval)
270 self.addIntegrator(N,timeInterval)
271
271
272 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
272 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
273 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
273 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
274
274
275 if myIncohIntObj.isReady:
275 if myIncohIntObj.isReady:
276 self.dataOutObj.data_spc = myIncohIntObj.data
276 self.dataOutObj.data_spc = myIncohIntObj.data
277 self.dataOutObj.nAvg = myIncohIntObj.navg
277 self.dataOutObj.nAvg = myIncohIntObj.navg
278 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
278 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
279 self.dataOutObj.flagNoData = False
279 self.dataOutObj.flagNoData = False
280
280
281 """Calcular el ruido"""
281 """Calcular el ruido"""
282 self.getNoise()
282 self.getNoise()
283 else:
283 else:
284 self.dataOutObj.flagNoData = True
284 self.dataOutObj.flagNoData = True
285
285
286 self.integratorObjIndex += 1
286 self.integratorObjIndex += 1
287
287
288
289 class SpectraHeisProcessor:
290 def __init__(self):
291 self.integratorObjIndex = None
292 self.writerObjIndex = None
293 self.plotterObjIndex = None
294 self.integratorObjList = []
295 self.writerObjList = []
296 self.plotterObjList = []
297 #self.noiseObj = Noise()
298
299 def setup(self,dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
300 if dataInObj == None:
301 raise ValueError, ""
302
303 if nFFTPoints == None:
304 raise ValueError, ""
305
306 self.dataInObj = dataInObj
307
308 if dataOutObj == None:
309 dataOutObj = SpectraHeis()
310
311 self.dataOutObj = dataOutObj
312 # self.noiseObj = Noise()
313
314 ##########################################
315 self.nFFTPoints = nFFTPoints
316 self.nChannels = self.dataInObj.nChannels
317 self.nHeights = self.dataInObj.nHeights
318 self.pairList = pairList
319 if pairList != None:
320 self.nPairs = len(pairList)
321 else:
322 self.nPairs = 0
323
324 self.dataOutObj.heightList = self.dataInObj.heightList
325 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
326 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
327 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
328
329 self.dataOutObj.dataType = self.dataInObj.dataType
330 self.dataOutObj.nPairs = self.nPairs
331 self.dataOutObj.nChannels = self.nChannels
332 self.dataOutObj.nProfiles = self.nFFTPoints
333 self.dataOutObj.nHeights = self.nHeights
334 self.dataOutObj.nFFTPoints = self.nFFTPoints
335 #self.dataOutObj.data = None
336
337 self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
338 self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
339
340 self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
341 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
342 self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
343 self.dataOutObj.m_ProcessingHeader.shif_fft = True
344
345 spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
346 k = 0
347 for i in range( 0,self.nChannels*2,2 ):
348 spectraComb[i] = k
349 spectraComb[i+1] = k
350 k += 1
351
352 k *= 2
353
354 if self.pairList != None:
355
356 for pair in self.pairList:
357 spectraComb[k] = pair[0]
358 spectraComb[k+1] = pair[1]
359 k += 2
360
361 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
362
363 return self.dataOutObj
364
365 def init(self):
366 self.integratorObjIndex = 0
367 self.writerObjIndex = 0
368 self.plotterObjIndex = 0
288
369
370 if self.dataInObj.type == "Voltage":
371 self.__getFft()
372 self.dataOutObj.flagNoData = False
373 return
374
375 #Other kind of data
376 if self.dataInObj.type == "SpectraHeis":
377 self.dataOutObj.copy(self.dataInObj)
378 self.dataOutObj.flagNoData = False
379 return
380
381 raise ValueError, "The datatype is not valid"
382
383 def __getFft(self):
384 if self.dataInObj.flagNoData:
385 return 0
386
387 fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1)
388 #print fft_volt
389 #calculo de self-spectra
390 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
391
392 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
393 self.dataOutObj.data_spc = spc
394 #print spc
395
396 def getSpectra(self):
397
398 return self.dataOutObj.data_spc
399
400 def getFrecuencies(self):
401
402 print self.nFFTPoints
403 return numpy.arange(int(self.nFFTPoints))
404
405 def addIntegrator(self,N,timeInterval):
406 objIncohInt = IncoherentIntegration(N,timeInterval)
407 self.integratorObjList.append(objIncohInt)
408
409 def integrator(self, N=None, timeInterval=None):
410 if self.dataOutObj.flagNoData:
411 return 0
412
413 if len(self.integratorObjList) <= self.integratorObjIndex:
414 self.addIntegrator(N,timeInterval)
415
416 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
417 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
418
419 if myIncohIntObj.isReady:
420 self.dataOutObj.data_spc = myIncohIntObj.data
421 self.dataOutObj.nAvg = myIncohIntObj.navg
422 self.dataOutObj.m_ProcessingHeader.incoherentInt *= myIncohIntObj.navg
423 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
424 self.dataOutObj.flagNoData = False
425
426 #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
427 # self.getNoise(type="sort", parm=16)
428
429 else:
430 self.dataOutObj.flagNoData = True
431
432 self.integratorObjIndex += 1
433
289
434
290
435
291 class IncoherentIntegration:
436 class IncoherentIntegration:
292
437
293 integ_counter = None
438 integ_counter = None
294 data = None
439 data = None
295 navg = None
440 navg = None
296 buffer = None
441 buffer = None
297 nIncohInt = None
442 nIncohInt = None
298
443
299 def __init__(self, N = None, timeInterval = None):
444 def __init__(self, N = None, timeInterval = None):
300 """
445 """
301 N
446 N
302 timeInterval - interval time [min], integer value
447 timeInterval - interval time [min], integer value
303 """
448 """
304
449
305 self.data = None
450 self.data = None
306 self.navg = None
451 self.navg = None
307 self.buffer = None
452 self.buffer = None
308 self.timeOut = None
453 self.timeOut = None
309 self.exitCondition = False
454 self.exitCondition = False
310 self.isReady = False
455 self.isReady = False
311 self.nIncohInt = N
456 self.nIncohInt = N
312 self.integ_counter = 0
457 self.integ_counter = 0
313 if timeInterval!=None:
458 if timeInterval!=None:
314 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
459 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
315
460
316 if ((timeInterval==None) and (N==None)):
461 if ((timeInterval==None) and (N==None)):
317 print 'N = None ; timeInterval = None'
462 print 'N = None ; timeInterval = None'
318 sys.exit(0)
463 sys.exit(0)
319 elif timeInterval == None:
464 elif timeInterval == None:
320 self.timeFlag = False
465 self.timeFlag = False
321 else:
466 else:
322 self.timeFlag = True
467 self.timeFlag = True
323
468
324
469
325 def exe(self,data,timeOfData):
470 def exe(self,data,timeOfData):
326 """
471 """
327 data
472 data
328
473
329 timeOfData [seconds]
474 timeOfData [seconds]
330 """
475 """
331
476
332 if self.timeFlag:
477 if self.timeFlag:
333 if self.timeOut == None:
478 if self.timeOut == None:
334 self.timeOut = timeOfData + self.timeIntervalInSeconds
479 self.timeOut = timeOfData + self.timeIntervalInSeconds
335
480
336 if timeOfData < self.timeOut:
481 if timeOfData < self.timeOut:
337 if self.buffer == None:
482 if self.buffer == None:
338 self.buffer = data
483 self.buffer = data
339 else:
484 else:
340 self.buffer = self.buffer + data
485 self.buffer = self.buffer + data
341 self.integ_counter += 1
486 self.integ_counter += 1
342 else:
487 else:
343 self.exitCondition = True
488 self.exitCondition = True
344
489
345 else:
490 else:
346 if self.integ_counter < self.nIncohInt:
491 if self.integ_counter < self.nIncohInt:
347 if self.buffer == None:
492 if self.buffer == None:
348 self.buffer = data
493 self.buffer = data
349 else:
494 else:
350 self.buffer = self.buffer + data
495 self.buffer = self.buffer + data
351
496
352 self.integ_counter += 1
497 self.integ_counter += 1
353
498
354 if self.integ_counter == self.nIncohInt:
499 if self.integ_counter == self.nIncohInt:
355 self.exitCondition = True
500 self.exitCondition = True
356
501
357 if self.exitCondition:
502 if self.exitCondition:
358 self.data = self.buffer
503 self.data = self.buffer
359 self.navg = self.integ_counter
504 self.navg = self.integ_counter
360 self.isReady = True
505 self.isReady = True
361 self.buffer = None
506 self.buffer = None
362 self.timeOut = None
507 self.timeOut = None
363 self.integ_counter = 0
508 self.integ_counter = 0
364 self.exitCondition = False
509 self.exitCondition = False
365
510
366 if self.timeFlag:
511 if self.timeFlag:
367 self.buffer = data
512 self.buffer = data
368 self.timeOut = timeOfData + self.timeIntervalInSeconds
513 self.timeOut = timeOfData + self.timeIntervalInSeconds
369 else:
514 else:
370 self.isReady = False
515 self.isReady = False
371 No newline at end of file
516
General Comments 0
You need to be logged in to leave comments. Login now