##// END OF EJS Templates
Se añadio el modulo de integración incluyendo overlapping
Miguel Valdez -
r143:d8eaadd4a3f7
parent child
Show More
@@ -1,288 +1,372
1 '''
1 '''
2
2
3 $Author$
3 $Author$
4 $Id$
4 $Id$
5 '''
5 '''
6
6
7 import os
7 import os
8 import sys
8 import sys
9 import numpy
9 import numpy
10 import datetime
10 import datetime
11 import time
11 import time
12
12
13 path = os.path.split(os.getcwd())[0]
13 path = os.path.split(os.getcwd())[0]
14 sys.path.append(path)
14 sys.path.append(path)
15
15
16 from Data.JROData import Voltage
16 from Data.JROData import Voltage
17 from IO.VoltageIO import VoltageWriter
17 from IO.VoltageIO import VoltageWriter
18 from Graphics.schainPlotTypes import ScopeFigure, RTIFigure
18 from Graphics.schainPlotTypes import ScopeFigure, RTIFigure
19
19
20 class VoltageProcessor:
20 class VoltageProcessor:
21
21
22 dataInObj = None
22 dataInObj = None
23 dataOutObj = None
23 dataOutObj = None
24 integratorObjIndex = None
24 integratorObjIndex = None
25 writerObjIndex = None
25 writerObjIndex = None
26 integratorObjList = None
26 integratorObjList = None
27 writerObjList = None
27 writerObjList = None
28
28
29 def __init__(self):
29 def __init__(self):
30 self.integratorObjIndex = None
30 self.integratorObjIndex = None
31 self.writerObjIndex = None
31 self.writerObjIndex = None
32 self.plotObjIndex = None
32 self.plotObjIndex = None
33 self.integratorObjList = []
33 self.integratorObjList = []
34 self.writerObjList = []
34 self.writerObjList = []
35 self.plotObjList = []
35 self.plotObjList = []
36
36
37 def setup(self,dataInObj=None,dataOutObj=None):
37 def setup(self,dataInObj=None,dataOutObj=None):
38 self.dataInObj = dataInObj
38 self.dataInObj = dataInObj
39
39
40 if self.dataOutObj == None:
40 if self.dataOutObj == None:
41 dataOutObj = Voltage()
41 dataOutObj = Voltage()
42
42
43 self.dataOutObj = dataOutObj
43 self.dataOutObj = dataOutObj
44
44
45 return self.dataOutObj
45 return self.dataOutObj
46
46
47 def init(self):
47 def init(self):
48 self.integratorObjIndex = 0
48 self.integratorObjIndex = 0
49 self.writerObjIndex = 0
49 self.writerObjIndex = 0
50 self.plotObjIndex = 0
50 self.plotObjIndex = 0
51
51
52 if not(self.dataInObj.flagNoData):
52 if not(self.dataInObj.flagNoData):
53 self.dataOutObj.copy(self.dataInObj)
53 self.dataOutObj.copy(self.dataInObj)
54 # No necesita copiar en cada init() los atributos de dataInObj
54 # No necesita copiar en cada init() los atributos de dataInObj
55 # la copia deberia hacerse por cada nuevo bloque de datos
55 # la copia deberia hacerse por cada nuevo bloque de datos
56
56
57 def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
57 def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
58 rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
58 rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
59 self.plotObjList.append(rtiObj)
59 self.plotObjList.append(rtiObj)
60
60
61 def plotRti(self, idfigure=None,
61 def plotRti(self, idfigure=None,
62 starttime=None,
62 starttime=None,
63 endtime=None,
63 endtime=None,
64 rangemin=None,
64 rangemin=None,
65 rangemax=None,
65 rangemax=None,
66 minvalue=None,
66 minvalue=None,
67 maxvalue=None,
67 maxvalue=None,
68 wintitle='',
68 wintitle='',
69 driver='plplot',
69 driver='plplot',
70 colormap='br_greeen',
70 colormap='br_greeen',
71 colorbar=True,
71 colorbar=True,
72 showprofile=False,
72 showprofile=False,
73 xrangestep=None,
73 xrangestep=None,
74 save=False,
74 save=False,
75 gpath=None):
75 gpath=None):
76
76
77 if self.dataOutObj.flagNoData:
77 if self.dataOutObj.flagNoData:
78 return 0
78 return 0
79
79
80 nframes = len(self.dataOutObj.channelList)
80 nframes = len(self.dataOutObj.channelList)
81
81
82 if len(self.plotObjList) <= self.plotObjIndex:
82 if len(self.plotObjList) <= self.plotObjIndex:
83 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
83 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
84
84
85 data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
85 data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
86 data = 10*numpy.log10(data.real)
86 data = 10*numpy.log10(data.real)
87
87
88 # currenttime = self.dataOutObj.dataUtcTime
88 # currenttime = self.dataOutObj.dataUtcTime
89 # if timezone == "lt":
89 # if timezone == "lt":
90 currenttime = self.dataOutObj.dataUtcTime - time.timezone
90 currenttime = self.dataOutObj.dataUtcTime - time.timezone
91
91
92 range = self.dataOutObj.heightList
92 range = self.dataOutObj.heightList
93
93
94 channelList = self.dataOutObj.channelList
94 channelList = self.dataOutObj.channelList
95
95
96 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
96 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
97 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
97 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
98 date = "%s"%(thisdatetime.strftime("%d-%b-%Y"))
98 date = "%s"%(thisdatetime.strftime("%d-%b-%Y"))
99
99
100 figuretitle = "RTI Plot Radar Data" #+ date
100 figuretitle = "RTI Plot Radar Data" #+ date
101
101
102 plotObj = self.plotObjList[self.plotObjIndex]
102 plotObj = self.plotObjList[self.plotObjIndex]
103
103
104 cleardata = False
104 cleardata = False
105
105
106 plotObj.plotPcolor(data,
106 plotObj.plotPcolor(data,
107 currenttime,
107 currenttime,
108 range,
108 range,
109 channelList,
109 channelList,
110 starttime,
110 starttime,
111 endtime,
111 endtime,
112 rangemin,
112 rangemin,
113 rangemax,
113 rangemax,
114 minvalue,
114 minvalue,
115 maxvalue,
115 maxvalue,
116 figuretitle,
116 figuretitle,
117 xrangestep,
117 xrangestep,
118 save,
118 save,
119 gpath,
119 gpath,
120 cleardata)
120 cleardata)
121
121
122 self.plotObjIndex += 1
122 self.plotObjIndex += 1
123
123
124 def addScope(self, idfigure, nframes, wintitle, driver):
124 def addScope(self, idfigure, nframes, wintitle, driver):
125 if idfigure==None:
125 if idfigure==None:
126 idfigure = self.plotObjIndex
126 idfigure = self.plotObjIndex
127
127
128 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
128 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
129 self.plotObjList.append(scopeObj)
129 self.plotObjList.append(scopeObj)
130
130
131 def plotScope(self,
131 def plotScope(self,
132 idfigure=None,
132 idfigure=None,
133 minvalue=None,
133 minvalue=None,
134 maxvalue=None,
134 maxvalue=None,
135 xmin=None,
135 xmin=None,
136 xmax=None,
136 xmax=None,
137 wintitle='',
137 wintitle='',
138 driver='plplot',
138 driver='plplot',
139 save=False,
139 save=False,
140 gpath=None,
140 gpath=None,
141 titleList=None,
141 titleList=None,
142 xlabelList=None,
142 xlabelList=None,
143 ylabelList=None,
143 ylabelList=None,
144 type="power"):
144 type="power"):
145
145
146 if self.dataOutObj.flagNoData:
146 if self.dataOutObj.flagNoData:
147 return 0
147 return 0
148
148
149 nframes = len(self.dataOutObj.channelList)
149 nframes = len(self.dataOutObj.channelList)
150
150
151 if len(self.plotObjList) <= self.plotObjIndex:
151 if len(self.plotObjList) <= self.plotObjIndex:
152 self.addScope(idfigure, nframes, wintitle, driver)
152 self.addScope(idfigure, nframes, wintitle, driver)
153
153
154
154
155 if type=="power":
155 if type=="power":
156 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
156 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
157 data1D = data1D.real
157 data1D = data1D.real
158
158
159 if type =="iq":
159 if type =="iq":
160 data1D = self.dataOutObj.data
160 data1D = self.dataOutObj.data
161
161
162 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
162 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
163
163
164 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
164 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
165 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
165 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
166
166
167 figureTitle = "Scope Plot Radar Data: " + date
167 figureTitle = "Scope Plot Radar Data: " + date
168
168
169 plotObj = self.plotObjList[self.plotObjIndex]
169 plotObj = self.plotObjList[self.plotObjIndex]
170
170
171 plotObj.plot1DArray(data1D,
171 plotObj.plot1DArray(data1D,
172 self.dataOutObj.heightList,
172 self.dataOutObj.heightList,
173 self.dataOutObj.channelList,
173 self.dataOutObj.channelList,
174 xmin,
174 xmin,
175 xmax,
175 xmax,
176 minvalue,
176 minvalue,
177 maxvalue,
177 maxvalue,
178 figureTitle,
178 figureTitle,
179 save,
179 save,
180 gpath)
180 gpath)
181
181
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):
195
195
196 if self.dataOutObj.flagNoData:
196 if self.dataOutObj.flagNoData:
197 return 0
197 return 0
198
198
199 if len(self.writerObjList) <= self.writerObjIndex:
199 if len(self.writerObjList) <= self.writerObjIndex:
200 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
200 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
201
201
202 self.writerObjList[self.writerObjIndex].putData()
202 self.writerObjList[self.writerObjIndex].putData()
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