##// END OF EJS Templates
Para graficos se ha habilitado escritura de graficos en disco. Para el caso de RTI el intervalo[xmin,xmax] de ploteo en el eje X esta dado en segundos
Daniel Valdez -
r158:610e58680afb
parent child
Show More
@@ -1,391 +1,412
1 import numpy
1 import numpy
2 import datetime
2 import datetime
3 import time
3 import time
4 import os
4 import os
5 from schainPlotLib import Driver
5 from schainPlotLib import Driver
6
6
7 class Figure:
7 class Figure:
8
8
9 __isDriverOpen = False
9 __isDriverOpen = False
10 __isFigureOpen = False
10 __isFigureOpen = False
11 __isConfig = False
11 __isConfig = False
12
12 __counter = 0
13 drvObj = None
13 drvObj = None
14 driver = None
14 driver = None
15 idfigure = None
15 idfigure = None
16 nframes = None
16 nframes = None
17 wintitle = None
17 wintitle = None
18 colormap = None
18 colormap = None
19 overplot = None
19 overplot = None
20 colorbar = None
20 colorbar = None
21
21
22 frameObjList = []
22 frameObjList = []
23
23
24 xw = None
24 xw = None
25 yw = None
25 yw = None
26
26
27 xmin = None
27 xmin = None
28 xmax = None
28 xmax = None
29 ymin = None
29 ymin = None
30 ymax = None
30 ymax = None
31
31
32 minvalue = None
32 minvalue = None
33 maxvalue = None
33 maxvalue = None
34 deltax = None
34 deltax = None
35 deltay = None
35 deltay = None
36
36
37
37
38 figuretitle = ""
38 figuretitle = ""
39 xrangestep = None
39 xrangestep = None
40
40
41 def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap=None, colorbar= True, *args):
41 def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap=None, colorbar= True, *args):
42
42
43 self.__isDriverOpen = False
43 self.__isDriverOpen = False
44 self.__isFigureOpen = False
44 self.__isFigureOpen = False
45 self.__isConfig = False
45 self.__isConfig = False
46 self.__counter = 0
46
47
47 self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
48 self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
48 self.driver = driver
49 self.driver = driver
49 self.idfigure = idfigure
50 self.idfigure = idfigure
50 self.nframes = nframes
51 self.nframes = nframes
51 self.wintitle = wintitle
52 self.wintitle = wintitle
52 self.colormap = colormap
53 self.colormap = colormap
53 self.overplot = overplot
54 self.overplot = overplot
54 self.colorbar = colorbar
55 self.colorbar = colorbar
55
56
56 self.xw = xw
57 self.xw = xw
57 self.yw = yw
58 self.yw = yw
58
59
59 self.frameObjList = []
60 self.frameObjList = []
60
61
61 self.drvObj.driver.setFigure()
62 self.drvObj.driver.setFigure()
62 self.drvObj.driver.setColormap(colormap)
63 self.drvObj.driver.setColormap(colormap)
63
64
64 def __openDriver(self):
65 def __openDriver(self):
65
66
66 self.drvObj.driver.openDriver()
67 self.drvObj.driver.openDriver()
67
68
68 def __newPage(self):
69 def __newPage(self):
69
70
70
71
71 self.drvObj.driver.openPage()
72 self.drvObj.driver.openPage()
72 nrows, ncolumns = self.getSubplots()
73 nrows, ncolumns = self.getSubplots()
73 self.drvObj.driver.setFigTitle(self.figuretitle)
74 self.drvObj.driver.setFigTitle(self.figuretitle)
74 self.drvObj.driver.setSubPlots(nrows, ncolumns)
75 self.drvObj.driver.setSubPlots(nrows, ncolumns)
75
76
76 def __closePage(self):
77 def __closePage(self):
77
78
78 self.drvObj.driver.closeFigure()
79 self.drvObj.driver.closeFigure()
79
80
80 def selectFigure(self):
81 def selectFigure(self):
81
82
82 self.drvObj.driver.selectFigure()
83 self.drvObj.driver.selectFigure()
83
84
84 def __isOutOfXRange(self,x):
85 def __isOutOfXRange(self,x):
85 try:
86 try:
86 if ((x>=self.xmin) and (x<self.xmax)):
87 if ((x>=self.xmin) and (x<self.xmax)):
87 return 0
88 return 0
88 except:
89 except:
89 return 0
90 return 0
90
91
91 return 1
92 return 1
92
93
93 def changeXRange(self,x):
94 def changeXRange(self,x):
94
95
95 pass
96 pass
96
97
97 def __refresh(self):
98 def __refresh(self):
98 self.drvObj.driver.refresh()
99 self.drvObj.driver.refresh()
99
100
100 def createFrames(self):
101 def createFrames(self):
101
102
102 self.frameObjList = []
103 self.frameObjList = []
103
104
104 raise ValueError, "No implemented"
105 raise ValueError, "No implemented"
105
106
106 def save(self,filename):
107 def save(self,filename):
107
108
108 self.drvObj.driver.save(filename)
109 self.drvObj.driver.save(filename)
109
110
110 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'):
111 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./', ratio=1):
111
112
112 nx, ny = data1D.shape
113 nx, ny = data1D.shape
113
114
114 if channelList == None:
115 if channelList == None:
115 channelList = range(nx)
116 channelList = range(nx)
116
117
117 if x == None:
118 if x == None:
118 x = numpy.arange(data1D.size)
119 x = numpy.arange(data1D.size)
119
120
120 if figuretitle == None:
121 if figuretitle == None:
121 self.figuretitle = ""
122 self.figuretitle = ""
122 else:
123 else:
123 self.figuretitle = figuretitle
124 self.figuretitle = figuretitle
124
125
125 if not(self.__isDriverOpen):
126 if not(self.__isDriverOpen):
126 self.__openDriver()
127 self.__openDriver()
127 self.__isDriverOpen = True
128 self.__isDriverOpen = True
128
129
129 if not(self.__isConfig):
130 if not(self.__isConfig):
130 self.xmin = xmin
131 self.xmin = xmin
131 self.xmax = xmax
132 self.xmax = xmax
132 self.minvalue = minvalue
133 self.minvalue = minvalue
133 self.maxvalue = maxvalue
134 self.maxvalue = maxvalue
134
135
135 if self.xmin == None: self.xmin = numpy.min(x)
136 if self.xmin == None: self.xmin = numpy.min(x)
136 if self.xmax == None: self.xmax = numpy.max(x)
137 if self.xmax == None: self.xmax = numpy.max(x)
137 if self.minvalue == None: self.minvalue = numpy.min(data1D)
138 if self.minvalue == None: self.minvalue = numpy.min(data1D)
138 if self.maxvalue == None: self.maxvalue = numpy.max(data1D)
139 if self.maxvalue == None: self.maxvalue = numpy.max(data1D)
139
140
140 self.createFrames()
141 self.createFrames()
141 self.__isConfig = True
142 self.__isConfig = True
142
143
143
144
144
145
145 self.selectFigure()
146 self.selectFigure()
146 self.__newPage()
147 self.__newPage()
147
148
148
149
149 for channel in channelList:
150 for channel in range(len(channelList)):
150 frameObj = self.frameObjList[channel]
151 frameObj = self.frameObjList[channel]
151 frameObj.init(xmin=self.xmin,
152 frameObj.init(xmin=self.xmin,
152 xmax=self.xmax,
153 xmax=self.xmax,
153 ymin=self.minvalue,
154 ymin=self.minvalue,
154 ymax=self.maxvalue,
155 ymax=self.maxvalue,
155 minvalue=self.minvalue,
156 minvalue=self.minvalue,
156 maxvalue=self.maxvalue)
157 maxvalue=self.maxvalue)
157
158
158 for channel in channelList:
159 for channel in range(len(channelList)):
159 dataCh = data1D[channel,:]
160 dataCh = data1D[channel,:]
160 frameObj = self.frameObjList[channel]
161 frameObj = self.frameObjList[channel]
161 frameObj.plot(x, dataCh)
162 frameObj.plot(x, dataCh)
162
163
163 self.__refresh()
164 self.__refresh()
164
165
165
166 if save:
166 if save:
167 path = gpath
167 if self.__counter == 0:
168 now = datetime.datetime.now()
168 path = gpath
169 file = "scope_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond)
169 now = datetime.datetime.now()
170 filename = os.path.join(path,file)
170 file = "plot_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond)
171 self.save(filename)
171 filename = os.path.join(path,file)
172 self.save(filename)
173 self.__counter += 1
174
175 if self.__counter == ratio:
176 self.__counter = 0
177
172
178
173 self.__closePage()
179 self.__closePage()
174
180
175
181
176 def plotPcolor(self,data,
182 def plotPcolor(self,data,
177 x=None,
183 x=None,
178 y=None,
184 y=None,
179 channelList=None,
185 channelList=None,
180 xmin=None,
186 xmin=None,
181 xmax=None,
187 xmax=None,
182 ymin=None,
188 ymin=None,
183 ymax=None,
189 ymax=None,
184 minvalue=None,
190 minvalue=None,
185 maxvalue=None,
191 maxvalue=None,
186 figuretitle=None,
192 figuretitle=None,
187 xrangestep=None,
193 xrangestep=None,
188 deltax=None,
194 deltax=None,
189 save=False,
195 save=False,
190 gpath='./',
196 gpath='./',
197 ratio=1,
191 cleardata=False,
198 cleardata=False,
192 *args):
199 *args):
193
200
194
201
195 if figuretitle == None:
202 if figuretitle == None:
196 self.figuretitle = ""
203 self.figuretitle = ""
197 else:
204 else:
198 self.figuretitle = figuretitle
205 self.figuretitle = figuretitle
199
206
200
207
201 if not(self.__isDriverOpen):
208 if not(self.__isDriverOpen):
202 self.__openDriver()
209 self.__openDriver()
203 self.__isDriverOpen = True
210 self.__isDriverOpen = True
204
211
205 if not(self.__isConfig):
212 if not(self.__isConfig):
206
213
207 self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep,deltax)
214 self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep,deltax)
208
215
209 self.createFrames()
216 self.createFrames()
210 self.__isConfig = True
217 self.__isConfig = True
211
218
212 if (self.__isOutOfXRange(x)):
219 if (self.__isOutOfXRange(x)):
213
220
214 if not(self.changeXRange(x)):
221 if not(self.changeXRange(x)):
215 return 0
222 return 0
216
223
217 self.__closePage()
224 self.__closePage()
218 self.__isFigureOpen = False
225 self.__isFigureOpen = False
219
226
220 self.selectFigure()
227 self.selectFigure()
221
228
222 if not(self.__isFigureOpen):
229 if not(self.__isFigureOpen):
223 self.__newPage()
230 self.__newPage()
224 self.__isFigureOpen = True
231 self.__isFigureOpen = True
225
232
226 for channel in channelList:
233 for channel in range(len(channelList)):
227 if len(args) != 0: value = args[0][channel]
234 if len(args) != 0: value = args[0][channel]
228 else: value = args
235 else: value = args
229
236
230 frameObj = self.frameObjList[channel]
237 frameObj = self.frameObjList[channel]
231 frameObj.init(self.xmin,
238 frameObj.init(self.xmin,
232 self.xmax,
239 self.xmax,
233 self.ymin,
240 self.ymin,
234 self.ymax,
241 self.ymax,
235 self.minvalue,
242 self.minvalue,
236 self.maxvalue,
243 self.maxvalue,
237 self.deltax,
244 self.deltax,
238 self.deltay,
245 self.deltay,
239 self.colorbar,
246 self.colorbar,
240 value)
247 value)
241
248
242
249
243 for channel in channelList:
250 for channel in range(len(channelList)):
244 dataCh = data[channel,:]
251 dataCh = data[channel,:]
245 frameObj = self.frameObjList[channel]
252 frameObj = self.frameObjList[channel]
246 frameObj.plot(x, y, dataCh)
253 frameObj.plot(x, y, dataCh)
247
254
248
255
249 self.__refresh()
256 self.__refresh()
257
258 if save:
259 if self.__counter == 0:
260 path = gpath
261 now = datetime.datetime.now()
262 file = "pcolor_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond)
263 filename = os.path.join(path,file)
264 self.save(filename)
265 self.__counter += 1
266
267 if self.__counter == ratio:
268 self.__counter = 0
269
270
250 if cleardata == True:
271 if cleardata == True:
251 self.__closePage()
272 self.__closePage()
252 self.__isFigureOpen = False
273 self.__isFigureOpen = False
253
274
254
275
255
276
256
277
257 class Frame:
278 class Frame:
258
279
259 drvObj = None
280 drvObj = None
260 idFrame = None
281 idFrame = None
261 nplots = None
282 nplots = None
262 plotObjList = []
283 plotObjList = []
263 title = ""
284 title = ""
264
285
265 def __init__(self,drvObj, idframe):
286 def __init__(self,drvObj, idframe):
266
287
267 self.drvObj = drvObj
288 self.drvObj = drvObj
268 self.idframe = idframe
289 self.idframe = idframe
269 nplots = None
290 nplots = None
270 self.plotObjList = []
291 self.plotObjList = []
271
292
272 self.createPlots()
293 self.createPlots()
273
294
274 def createPlots(self):
295 def createPlots(self):
275 raise ValueError, "No implemented"
296 raise ValueError, "No implemented"
276
297
277 def getScreenPosMainPlot(self):
298 def getScreenPosMainPlot(self):
278 raise ValueError, "No implemented"
299 raise ValueError, "No implemented"
279
300
280 def getScreenPosGraph1(self):
301 def getScreenPosGraph1(self):
281 raise ValueError, "No implemented"
302 raise ValueError, "No implemented"
282
303
283 def getScreenPos(self, nplot):
304 def getScreenPos(self, nplot):
284
305
285 if nplot == 0:
306 if nplot == 0:
286 xi, yi, xw, yw = self.getScreenPosMainPlot()
307 xi, yi, xw, yw = self.getScreenPosMainPlot()
287
308
288 if nplot == 1:
309 if nplot == 1:
289 xi, yi, xw, yw = self.getScreenPosGraph1()
310 xi, yi, xw, yw = self.getScreenPosGraph1()
290
311
291 return xi, yi, xw, yw
312 return xi, yi, xw, yw
292
313
293
314
294 def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=False, *args):
315 def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=False, *args):
295
316
296 for plotObj in self.plotObjList:
317 for plotObj in self.plotObjList:
297 plotObj.setBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay, colorbar, *args)
318 plotObj.setBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay, colorbar, *args)
298 plotObj.plotBox()
319 plotObj.plotBox()
299
320
300
321
301
322
302 class Plot:
323 class Plot:
303
324
304 drvObj = None
325 drvObj = None
305 idframe = None
326 idframe = None
306 idplot = None
327 idplot = None
307 xi = None
328 xi = None
308 yi = None
329 yi = None
309 xw = None
330 xw = None
310 yw = None
331 yw = None
311
332
312 title = ""
333 title = ""
313 xlabel = ""
334 xlabel = ""
314 ylabel = ""
335 ylabel = ""
315 xaxisastime = None
336 xaxisastime = None
316 timefmt = None
337 timefmt = None
317 xopt = ""
338 xopt = ""
318 yopt = ""
339 yopt = ""
319 xpos = None
340 xpos = None
320 ypos = None
341 ypos = None
321 szchar = None
342 szchar = None
322 idframe = None
343 idframe = None
323 idplot = None
344 idplot = None
324 colorbar = None
345 colorbar = None
325 cbxpos = None
346 cbxpos = None
326 cbypos = None
347 cbypos = None
327
348
328 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
349 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
329
350
330 self.drvObj = drvObj
351 self.drvObj = drvObj
331 self.idframe = idframe
352 self.idframe = idframe
332 self.idplot = idplot
353 self.idplot = idplot
333 self.xi = xi
354 self.xi = xi
334 self.yi = yi
355 self.yi = yi
335 self.xw = xw
356 self.xw = xw
336 self.yw = yw
357 self.yw = yw
337
358
338
359
339 def plotBox(self):
360 def plotBox(self):
340
361
341 self.drvObj.driver.plotBox(self.idframe,
362 self.drvObj.driver.plotBox(self.idframe,
342 self.xpos,
363 self.xpos,
343 self.ypos,
364 self.ypos,
344 self.xmin,
365 self.xmin,
345 self.xmax,
366 self.xmax,
346 self.ymin,
367 self.ymin,
347 self.ymax,
368 self.ymax,
348 self.minvalue,
369 self.minvalue,
349 self.maxvalue,
370 self.maxvalue,
350 self.xopt,
371 self.xopt,
351 self.yopt,
372 self.yopt,
352 self.szchar,
373 self.szchar,
353 self.xaxisastime,
374 self.xaxisastime,
354 self.timefmt)
375 self.timefmt)
355
376
356 self.drvObj.driver.setPlotLabels(self.idframe, self.xlabel, self.ylabel, self.title)
377 self.drvObj.driver.setPlotLabels(self.idframe, self.xlabel, self.ylabel, self.title)
357
378
358 if self.colorbar:
379 if self.colorbar:
359 self.drvObj.driver.plotColorbar(self.minvalue, self.maxvalue, self.cbxpos,self.cbypos)
380 self.drvObj.driver.plotColorbar(self.minvalue, self.maxvalue, self.cbxpos,self.cbypos)
360
381
361 def plotPcolor(self, x, y, z, deltax, deltay, getGrid):
382 def plotPcolor(self, x, y, z, deltax, deltay, getGrid):
362
383
363 self.drvObj.driver.pcolor(self.idframe,
384 self.drvObj.driver.pcolor(self.idframe,
364 self.xpos,
385 self.xpos,
365 self.ypos,
386 self.ypos,
366 z,
387 z,
367 x,
388 x,
368 y,
389 y,
369 self.xmin,
390 self.xmin,
370 self.xmax,
391 self.xmax,
371 self.ymin,
392 self.ymin,
372 self.ymax,
393 self.ymax,
373 self.minvalue,
394 self.minvalue,
374 self.maxvalue,
395 self.maxvalue,
375 deltax,
396 deltax,
376 deltay,
397 deltay,
377 getGrid,
398 getGrid,
378 self.xaxisastime,
399 self.xaxisastime,
379 self.timefmt)
400 self.timefmt)
380
401
381 def plotBasicLine(self,x, y, color):
402 def plotBasicLine(self,x, y, color):
382 """
403 """
383 Inputs:
404 Inputs:
384 x:
405 x:
385
406
386 y:
407 y:
387
408
388 color:
409 color:
389 """
410 """
390 self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color)
411 self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color)
391 No newline at end of file
412
@@ -1,665 +1,695
1 import numpy
1 import numpy
2 import datetime
2 import datetime
3 import time
3 import time
4 from schainPlot import *
4 from schainPlot import *
5
5
6 class CrossSpc(Figure):
6 class CrossSpc(Figure):
7 overplot = 0
7 overplot = 0
8 xw = 900
8 xw = 900
9 yw = 650
9 yw = 650
10 showprofile = False
10 showprofile = False
11 signalA = None
11 signalA = None
12 signalB = None
12 signalB = None
13 coherence = None
13 coherence = None
14 phase = None
14 phase = None
15
15
16 def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
16 def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
17 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
17 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
18
18
19 self.showprofile = showprofile
19 self.showprofile = showprofile
20 self.signalA = None
20 self.signalA = None
21 self.signalB = None
21 self.signalB = None
22 self.coherence = None
22 self.coherence = None
23 self.phase = None
23 self.phase = None
24
24
25 def getSubplots(self):
25 def getSubplots(self):
26 nrows = self.nframes
26 nrows = self.nframes
27 ncolumns = 1
27 ncolumns = 1
28 return nrows, ncolumns
28 return nrows, ncolumns
29
29
30 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
30 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
31
31
32 if xmin == None: xmin = numpy.min(x)
32 if xmin == None: xmin = numpy.min(x)
33 if xmax == None: xmax = numpy.max(x)
33 if xmax == None: xmax = numpy.max(x)
34 if ymin == None: ymin = numpy.min(y)
34 if ymin == None: ymin = numpy.min(y)
35 if ymax == None: ymax = numpy.max(y)
35 if ymax == None: ymax = numpy.max(y)
36 if minvalue == None: minvalue = 20.
36 if minvalue == None: minvalue = 20.
37 if maxvalue == None: maxvalue = 90.
37 if maxvalue == None: maxvalue = 90.
38
38
39 self.signalA = self.data[0]
39 self.signalA = self.data[0]
40 self.signalB = self.data[1]
40 self.signalB = self.data[1]
41 self.coherence = self.data[2]
41 self.coherence = self.data[2]
42 self.phase = self.data[3]
42 self.phase = self.data[3]
43
43
44 self.xmin = xmin
44 self.xmin = xmin
45 self.xmax = xmax
45 self.xmax = xmax
46 self.minrange = ymin
46 self.minrange = ymin
47 self.maxrange = ymax
47 self.maxrange = ymax
48 self.ymin = ymin
48 self.ymin = ymin
49 self.ymax = ymax
49 self.ymax = ymax
50 self.minvalue = minvalue
50 self.minvalue = minvalue
51 self.maxvalue = maxvalue
51 self.maxvalue = maxvalue
52
52
53 def changeXRange(self, *args):
53 def changeXRange(self, *args):
54 pass
54 pass
55
55
56 def createFrames(self):
56 def createFrames(self):
57 self.frameObjList = []
57 self.frameObjList = []
58
58
59 for frame in range(self.nframes):
59 for frame in range(self.nframes):
60 frameObj = CrossSpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
60 frameObj = CrossSpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
61 self.frameObjList.append(frameObj)
61 self.frameObjList.append(frameObj)
62
62
63
63
64 class CrossSpcFrame(Frame):
64 class CrossSpcFrame(Frame):
65 xi = None
66 xw = None
67 yi = None
68 yw = None
69 alpha = None
65 def __init__(self):
70 def __init__(self):
66 self.drvObj = drvObj
71 self.drvObj = drvObj
67 self.idframe = idframe
72 self.idframe = idframe
68 self.nplots = 4
73 self.nplots = 4
69
74
70 if showprofile:
75 if showprofile:
71 self.nplots += 4
76 self.nplots += 4
72
77
73 self.colorbar = colorbar
78 self.colorbar = colorbar
74 self.showprofile = showprofile
79 self.showprofile = showprofile
80 self.xi = 0.
81 self.xw = 0.
82 self.yi = 0.
83 self.yw = 0.
84 self.alpha = 1.
85
75 self.createPlots()
86 self.createPlots()
76
87
77 def createPlots(self):
88 def createPlots(self):
78 plotObjList = []
89 plotObjList = []
79 idplot = 0
90 idplot = 0
80 counter_plot = 0
91 counter_plot = 0
81 for i in range(self.nplots):
92 for i in range(self.nplots):
82 xi, yi, xw, yw = self.getScreenPos(idplot)
93 xi, yi, xw, yw = self.getScreenPos(idplot)
83 plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
94 plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
84 plotObjList.append(plotObj)
95 plotObjList.append(plotObj)
85
96
86 if self.showprofile:
97 if self.showprofile:
87 xi, yi, xw, yw = self.getScreenPos(idplot)
98 xi, yi, xw, yw = self.getScreenPosGraph1(idplot)
88 type = "pwbox"
99 type = "pwbox"
89 title = ""
100 title = ""
90 xlabel = "dB"
101 xlabel = "dB"
91 ylabel = ""
102 ylabel = ""
92 idplot += 1
103 idplot += 1
93 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
104 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
94 plotObjList.append(plotObj)
105 plotObjList.append(plotObj)
95 idplot += 1
106 idplot += 1
96
107
97 self.plotObjList = plotObjList
108 self.plotObjList = plotObjList
98
109
99 def getScreenPos(self,idplot):
110 # def getScreenPos(self,idplot):
100 pass
111 # pass
101
112
102 def getScreenPosMainPlot(self):
113 def getScreenPos(self, diplot):
103 xi = 0.15
114
115 xi = self.xi
116 xw = self.xw
104
117
105 if self.showprofile:
118 if self.showprofile:
106 xw = 0.55
119 width = 0.55
120 xw += width
121
122
123
124
125 self.xi = 0.15 + idplot*self.alpha
126
127 if self.showprofile:
128 width = 0.55
129 self.xw += width
107
130
108 else:
131 else:
109 xw = 0.65
132 width = 0.65
133 self.xw += width
110
134
111 if self.colorbar:
135 if self.colorbar:
112 xw = xw - 0.06
136 self.xw = self.xw - 0.06
137
138
139 self.alpha = self.xw
113
140
114 yi = 0.20; yw = 0.75
141 yi = 0.20; yw = 0.75
115
142
116 return xi, yi, xw, yw
143 return xi, yi, xw, yw
117
144
118 def getScreenPosGraph1(self):
145 def getScreenPosGraph1(self):
119 if self.colorbar:
146 if self.colorbar:
120 xi = 0.65 + 0.08
147 xi = self.xw + 0.08
121 else:
148 else:
122 xi = 0.75 + 0.05
149 xi = self.xw + 0.05
150
151 xw = xi + 0.2
152
153 self.alpha = xw
154
155 if self.colorbar:
156 self.xi = 0.65 + 0.08
157 else:
158 self.xi = 0.75 + 0.05
123
159
124 xw = xi + 0.2
160 xw = xi + 0.2
125
161
126 yi = 0.2; yw = 0.75
162 yi = 0.2; yw = 0.75
127
163
128 return xi, yi, xw, yw
164 return xi, yi, xw, yw
129
165
130 def plot(self,x, y, data):
166 def plot(self,x, y, data):
131 plotObj = self.plotObjList[0]
167 plotObj = self.plotObjList[0]
132 plotObj.plot(x,y,data)
168 plotObj.plot(x,y,data)
133
169
134 if self.showprofile:
170 if self.showprofile:
135 plotObj = self.plotObjList[1]
171 plotObj = self.plotObjList[1]
136 avg_data = numpy.average(data, axis=0)
172 avg_data = numpy.average(data, axis=0)
137 plotObj.plot(avg_data,y)
173 plotObj.plot(avg_data,y)
138
174
139
175
140 class SpcFigure(Figure):
176 class SpcFigure(Figure):
141 overplot = 0
177 overplot = 0
142 xw = 900
178 xw = 900
143 yw = 650
179 yw = 650
144 showprofile = False
180 showprofile = False
145
181
146 def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
182 def __init__(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
147 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
183 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
148
184
149 self.showprofile = showprofile
185 self.showprofile = showprofile
150
186
151 def getSubplots(self):
187 def getSubplots(self):
152 ncolumns = int(numpy.sqrt(self.nframes)+0.9)
188 ncolumns = int(numpy.sqrt(self.nframes)+0.9)
153 nrows = int(self.nframes*1./ncolumns + 0.9)
189 nrows = int(self.nframes*1./ncolumns + 0.9)
154
190
155 return nrows, ncolumns
191 return nrows, ncolumns
156
192
157 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
193 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
158
194
159 if xmin == None: xmin = numpy.min(x)
195 if xmin == None: xmin = numpy.min(x)
160 if xmax == None: xmax = numpy.max(x)
196 if xmax == None: xmax = numpy.max(x)
161 if ymin == None: ymin = numpy.min(y)
197 if ymin == None: ymin = numpy.min(y)
162 if ymax == None: ymax = numpy.max(y)
198 if ymax == None: ymax = numpy.max(y)
163 if minvalue == None: minvalue = 20.
199 if minvalue == None: minvalue = 20.
164 if maxvalue == None: maxvalue = 90.
200 if maxvalue == None: maxvalue = 90.
165
201
166 self.xmin = xmin
202 self.xmin = xmin
167 self.xmax = xmax
203 self.xmax = xmax
168 self.minrange = ymin
204 self.minrange = ymin
169 self.maxrange = ymax
205 self.maxrange = ymax
170 self.ymin = ymin
206 self.ymin = ymin
171 self.ymax = ymax
207 self.ymax = ymax
172 self.minvalue = minvalue
208 self.minvalue = minvalue
173 self.maxvalue = maxvalue
209 self.maxvalue = maxvalue
174
210
175
211
176 def changeXRange(self, *args):
212 def changeXRange(self, *args):
177 pass
213 pass
178
214
179 def createFrames(self):
215 def createFrames(self):
180
216
181 self.frameObjList = []
217 self.frameObjList = []
182
218
183 for frame in range(self.nframes):
219 for frame in range(self.nframes):
184 frameObj = SpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
220 frameObj = SpcFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
185 self.frameObjList.append(frameObj)
221 self.frameObjList.append(frameObj)
186
222
187 class SpcFrame(Frame):
223 class SpcFrame(Frame):
188 def __init__(self,drvObj,idframe,colorbar,showprofile):
224 def __init__(self,drvObj,idframe,colorbar,showprofile):
189 self.drvObj = drvObj
225 self.drvObj = drvObj
190 self.idframe = idframe
226 self.idframe = idframe
191 self.nplots = 1
227 self.nplots = 1
192
228
193 if showprofile:
229 if showprofile:
194 self.nplots += 1
230 self.nplots += 1
195
231
196 self.colorbar = colorbar
232 self.colorbar = colorbar
197 self.showprofile = showprofile
233 self.showprofile = showprofile
198 self.createPlots()
234 self.createPlots()
199
235
200 def createPlots(self):
236 def createPlots(self):
201 plotObjList = []
237 plotObjList = []
202 idplot = 0
238 idplot = 0
203 xi, yi, xw, yw = self.getScreenPos(idplot)
239 xi, yi, xw, yw = self.getScreenPos(idplot)
204 plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
240 plotObj = SpcPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
205 plotObjList.append(plotObj)
241 plotObjList.append(plotObj)
206
242
207 if self.showprofile:
243 if self.showprofile:
208 idplot = 1
244 idplot = 1
209 xi, yi, xw, yw = self.getScreenPos(idplot)
245 xi, yi, xw, yw = self.getScreenPos(idplot)
210 type = "pwbox"
246 type = "pwbox"
211 title = ""
247 title = ""
212 xlabel = "dB"
248 xlabel = "dB"
213 ylabel = ""
249 ylabel = ""
214 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
250 szchar = 0.70
251 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel, szchar)
215 plotObjList.append(plotObj)
252 plotObjList.append(plotObj)
216
253
217 self.plotObjList = plotObjList
254 self.plotObjList = plotObjList
218
255
219 def getScreenPosMainPlot(self):
256 def getScreenPosMainPlot(self):
220 xi = 0.15
257 xi = 0.15
221
258
222 if self.showprofile:
259 if self.showprofile:
223 xw = 0.55
260 xw = 0.55
224
261
225 else:
262 else:
226 xw = 0.65
263 xw = 0.65
227
264
228 if self.colorbar:
265 if self.colorbar:
229 xw = xw - 0.06
266 xw = xw - 0.06
230
267
231 yi = 0.20; yw = 0.75
268 yi = 0.20; yw = 0.75
232
269
233 return xi, yi, xw, yw
270 return xi, yi, xw, yw
234
271
235 def getScreenPosGraph1(self):
272 def getScreenPosGraph1(self):
236 if self.colorbar:
273 if self.colorbar:
237 xi = 0.65 + 0.08
274 xi = 0.65 + 0.08
238 else:
275 else:
239 xi = 0.75 + 0.05
276 xi = 0.75 + 0.05
240
277
241 xw = xi + 0.2
278 xw = xi + 0.2
242
279
243 yi = 0.2; yw = 0.75
280 yi = 0.2; yw = 0.75
244
281
245 return xi, yi, xw, yw
282 return xi, yi, xw, yw
246
283
247 def plot(self,x, y, data):
284 def plot(self,x, y, data):
248 plotObj = self.plotObjList[0]
285 plotObj = self.plotObjList[0]
249 plotObj.plot(x,y,data)
286 plotObj.plot(x,y,data)
250
287
251 if self.showprofile:
288 if self.showprofile:
252 plotObj = self.plotObjList[1]
289 plotObj = self.plotObjList[1]
253 avg_data = numpy.average(data, axis=0)
290 avg_data = numpy.average(data, axis=0)
254 plotObj.plot(avg_data,y)
291 plotObj.plot(avg_data,y)
255
292
256 class SpcPlot(Plot):
293 class SpcPlot(Plot):
257
294
258 getGrid = True
295 getGrid = True
259
296
260 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
297 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
261 self.drvObj = drvObj
298 self.drvObj = drvObj
262 self.idframe = idframe
299 self.idframe = idframe
263 self.idplot = idplot
300 self.idplot = idplot
264 self.xi = xi
301 self.xi = xi
265 self.yi = yi
302 self.yi = yi
266 self.xw = xw
303 self.xw = xw
267 self.yw = yw
304 self.yw = yw
268 self.colorbar = colorbar
305 self.colorbar = colorbar
269
306
270 if self.colorbar:
307 if self.colorbar:
271 cbxi = xw + 0.03
308 cbxi = xw + 0.03
272 cbxw = cbxi + 0.03
309 cbxw = cbxi + 0.03
273 cbyi = yi
310 cbyi = yi
274 cbyw = yw
311 cbyw = yw
275 self.cbxpos = [cbxi,cbxw]
312 self.cbxpos = [cbxi,cbxw]
276 self.cbypos = [cbyi,cbyw]
313 self.cbypos = [cbyi,cbyw]
277
314
278 self.xpos = [self.xi,self.xw]
315 self.xpos = [self.xi,self.xw]
279 self.ypos = [self.yi,self.yw]
316 self.ypos = [self.yi,self.yw]
280 self.xaxisastime = False
317 self.xaxisastime = False
281 self.timefmt = None
318 self.timefmt = None
282 self.xopt = "bcnst"
319 self.xopt = "bcnst"
283 self.yopt = "bcnstv"
320 self.yopt = "bcnstv"
284
321
285 self.szchar = 0.7
322 self.szchar = 0.7
286 self.strforchannel = "Channel %d"%self.idframe
323 self.strforchannel = "Channel %d"%self.idframe
287 self.xlabel = "m/s"
324 self.xlabel = "m/s"
288 self.ylabel = "Range (Km)"
325 self.ylabel = "Range (Km)"
289
326
290 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
327 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
291 self.xmin = xmin
328 self.xmin = xmin
292 self.xmax = xmax
329 self.xmax = xmax
293 self.ymin = ymin
330 self.ymin = ymin
294 self.ymax = ymax
331 self.ymax = ymax
295 self.minvalue = minvalue
332 self.minvalue = minvalue
296 self.maxvalue = maxvalue
333 self.maxvalue = maxvalue
297 self.colorbar = args[2]
334 self.colorbar = args[2]
298 self.title = "%s - %s"%(self.strforchannel,args[3])
335 self.title = "%s - %s"%(self.strforchannel,args[3])
299
336
300
337
301
338
302 def plot(self, x, y, data):
339 def plot(self, x, y, data):
303 z = data
340 z = data
304 deltax = None
341 deltax = None
305 deltay = None
342 deltay = None
306 self.plotPcolor(x, y, z, deltax, deltay, self.getGrid)
343 self.plotPcolor(x, y, z, deltax, deltay, self.getGrid)
307 self.getGrid = False
344 self.getGrid = False
308
345
309
346
310 class RTIFigure(Figure):
347 class RTIFigure(Figure):
311 overplot = 1
348 overplot = 1
312 xw = 700
349 xw = 700
313 yw = 650
350 yw = 650
314 showprofile = False
351 showprofile = False
315 starttime = None
352 starttime = None
316 endtime = None
353 endtime = None
317 minrange = None
354 minrange = None
318 maxrange = None
355 maxrange = None
319 minvalue = None
356 minvalue = None
320 maxvalue = None
357 maxvalue = None
321 xrangestepinsecs = None
358 xrangestepinsecs = None
322
359 timefmt=None
323
360
324 def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False):
361 def __init__(self, idfigure, nframes, wintitle, driver, colormap="br_green", colorbar= True, showprofile=False):
325 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
362 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
326
363
327 self.showprofile = showprofile
364 self.showprofile = showprofile
328
365
329 def getSubplots(self):
366 def getSubplots(self):
330 nrows = self.nframes
367 nrows = self.nframes
331 ncolumns = 1
368 ncolumns = 1
332 return nrows, ncolumns
369 return nrows, ncolumns
333
370
334 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep, deltax):
371 def setParms(self, data, x, y, xmin, xmax, ymin, ymax, minvalue, maxvalue, xrangestep, deltax):
335
372
336 self.starttime = xmin
373 self.starttime = xmin
337 self.endtime = xmax
374 self.endtime = xmax
338
375
339 cdatetime = datetime.datetime.utcfromtimestamp(x)
376 cdatetime = datetime.datetime.utcfromtimestamp(x)
340
377
341 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second)
378 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.starttime.hour,self.starttime.minute,self.starttime.second)
342 if ((xrangestep == 0) or (xrangestep == None)):
379
343 maxdatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,self.endtime.hour,self.endtime.minute,self.endtime.second)
380 maxdatetime = mindatetime + datetime.timedelta(seconds=xrangestep)
344 self.xrangestepinsecs = time.mktime(maxdatetime.timetuple()) - time.mktime(mindatetime.timetuple())
381 self.xrangestepinsecs = xrangestep
345 npoints = 1000.
346 if xrangestep == 1:
347 maxdatetime = mindatetime + datetime.timedelta(hours=1)
348 self.xrangestepinsecs = 60*60.
349 npoints = 500.
350 if xrangestep == 2:
351 maxdatetime = mindatetime + datetime.timedelta(minutes=1)
352 self.xrangestepinsecs = 60.
353 npoints = 250.
354 if xrangestep == 3:
355 maxdatetime = mindatetime + datetime.timedelta(seconds=1)
356 self.xrangestepinsecs = 1.
357 npoints = 125.
358
382
359 xmin = time.mktime(mindatetime.timetuple())
383 xmin = time.mktime(mindatetime.timetuple())
360 xmax = time.mktime(maxdatetime.timetuple())
384 xmax = time.mktime(maxdatetime.timetuple())
361
385
362 deltax1 = (xmax-xmin) / npoints
386 if self.xrangestepinsecs<=60.:
363 # deltax = timeInterval
387 self.timefmt="%H:%M:%S"
388
389 if self.xrangestepinsecs>0. and self.xrangestepinsecs<=1200.:
390 self.timefmt="%H:%M:%S"
391
392 if self.xrangestepinsecs>1200. and self.xrangestepinsecs<=86400.:
393 self.timefmt="%H:%M"
364
394
395 if self.xrangestepinsecs>86400.:
396 self.timefmt="%y:%m:%d:%H"
365
397
366 if ymin == None: ymin = numpy.min(y)
398 if ymin == None: ymin = numpy.min(y)
367 if ymax == None: ymax = numpy.max(y)
399 if ymax == None: ymax = numpy.max(y)
368
400
369 if minvalue == None: minvalue = 0.
401 if minvalue == None: minvalue = 0.
370 if maxvalue == None: maxvalue = 50.
402 if maxvalue == None: maxvalue = 50.
371
403
372 self.xmin = xmin
404 self.xmin = xmin
373 self.xmax = xmax
405 self.xmax = xmax
374 self.minrange = ymin
406 self.minrange = ymin
375 self.maxrange = ymax
407 self.maxrange = ymax
376 self.ymin = ymin
408 self.ymin = ymin
377 self.ymax = ymax
409 self.ymax = ymax
378 self.minvalue = minvalue
410 self.minvalue = minvalue
379 self.maxvalue = maxvalue
411 self.maxvalue = maxvalue
380 self.xrangestep = xrangestep
412 self.xrangestep = xrangestep
381 self.deltax = deltax
413 self.deltax = deltax
382
414
383 def changeXRange(self,x):
415 def changeXRange(self,x):
384
416
385 cdatetime = datetime.datetime.utcfromtimestamp(x)
417 cdatetime = datetime.datetime.utcfromtimestamp(x)
386
418
387 if ((cdatetime.time()>=self.starttime) and (cdatetime.time()<self.endtime)):
419 if ((cdatetime.time()>=self.starttime) and (cdatetime.time()<self.endtime)):
388 if self.xrangestep == 1:
420
389 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,self.starttime.minute,self.starttime.second)
421 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,cdatetime.second)
390
391 if self.xrangestep == 2:
392 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,self.starttime.second)
393
394 if self.xrangestep == 3:
395 mindatetime = datetime.datetime(cdatetime.year,cdatetime.month,cdatetime.day,cdatetime.hour,cdatetime.minute,cdatetime.second)
396
422
397 self.xmin = time.mktime(mindatetime.timetuple()) - time.timezone
423 self.xmin = time.mktime(mindatetime.timetuple()) - time.timezone
398 self.xmax = self.xmin + self.xrangestepinsecs
424 self.xmax = self.xmin + self.xrangestepinsecs
399
425
400 self.figuretitle = "%s %s : %s"%(self.figuretitle,
426 self.figuretitle = "%s %s : %s"%(self.figuretitle,
401 datetime.datetime.utcfromtimestamp(self.xmin).strftime("%d-%b-%Y %H:%M:%S"),
427 datetime.datetime.utcfromtimestamp(self.xmin).strftime("%d-%b-%Y %H:%M:%S"),
402 datetime.datetime.utcfromtimestamp(self.xmax).strftime("%d-%b-%Y %H:%M:%S"))
428 datetime.datetime.utcfromtimestamp(self.xmax).strftime("%d-%b-%Y %H:%M:%S"))
403 return 1
429 return 1
404
430
405 return 0
431 return 0
406
432
407 def createFrames(self):
433 def createFrames(self):
408
434
409 self.frameObjList = []
435 self.frameObjList = []
410
436
411 for frame in range(self.nframes):
437 for frame in range(self.nframes):
412 frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile)
438 frameObj = RTIFrame(self.drvObj,frame + 1, self.colorbar, self.showprofile, self.timefmt)
413 self.frameObjList.append(frameObj)
439 self.frameObjList.append(frameObj)
414
440
415 class RTIFrame(Frame):
441 class RTIFrame(Frame):
416 def __init__(self,drvObj,idframe,colorbar,showprofile):
442 def __init__(self,drvObj,idframe,colorbar,showprofile, timefmt):
417 self.drvObj = drvObj
443 self.drvObj = drvObj
418 self.idframe = idframe
444 self.idframe = idframe
419 self.nplots = 1
445 self.nplots = 1
420
446
421 if showprofile:
447 if showprofile:
422 self.nplots += 1
448 self.nplots += 1
423
449
424 self.colorbar = colorbar
450 self.colorbar = colorbar
425 self.showprofile = showprofile
451 self.showprofile = showprofile
452 self.timefmt = timefmt
426 self.createPlots()
453 self.createPlots()
427
454
428 def createPlots(self):
455 def createPlots(self):
429 plotObjList = []
456 plotObjList = []
430
457
431 idplot = 0
458 idplot = 0
432 xi, yi, xw, yw = self.getScreenPos(idplot)
459 xi, yi, xw, yw = self.getScreenPos(idplot)
433
460
434 plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar)
461 plotObj = RTIPlot(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, self.colorbar, self.timefmt)
435 plotObjList.append(plotObj)
462 plotObjList.append(plotObj)
436
463
437 if self.showprofile:
464 if self.showprofile:
438 idplot = 1
465 idplot = 1
439 xi, yi, xw, yw = self.getScreenPos(idplot)
466 xi, yi, xw, yw = self.getScreenPos(idplot)
440 type = "pwbox"
467 type = "pwbox"
441 title = ""
468 title = ""
442 xlabel = "dB"
469 xlabel = "dB"
443 ylabel = ""
470 ylabel = ""
444 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
471 szchar = 0.75
472 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel, szchar)
445 plotObjList.append(plotObj)
473 plotObjList.append(plotObj)
446
474
447 self.plotObjList = plotObjList
475 self.plotObjList = plotObjList
448
476
449 def getScreenPosMainPlot(self):
477 def getScreenPosMainPlot(self):
450 xi = 0.07
478 xi = 0.07
451 if self.showprofile:
479 if self.showprofile:
452 xw = 0.65
480 xw = 0.65
453 else:
481 else:
454 xw = 0.9
482 xw = 0.9
455
483
456 if self.colorbar:
484 if self.colorbar:
457 xw = xw - 0.06
485 xw = xw - 0.06
458
486
459 yi = 0.20; yw = 0.75
487 yi = 0.20; yw = 0.75
460
488
461 return xi, yi, xw, yw
489 return xi, yi, xw, yw
462
490
463 def getScreenPosGraph1(self):
491 def getScreenPosGraph1(self):
464 if self.colorbar:
492 if self.colorbar:
465 xi = 0.65 + 0.08
493 xi = 0.65 + 0.08
466 else:
494 else:
467 xi = 0.9 + 0.05
495 xi = 0.9 + 0.05
468
496
469 xw = xi + 0.2
497 xw = xi + 0.2
470
498
471 yi = 0.2; yw = 0.75
499 yi = 0.2; yw = 0.75
472
500
473 return xi, yi, xw, yw
501 return xi, yi, xw, yw
474
502
475 def plot(self, currenttime, range, data):
503 def plot(self, currenttime, range, data):
476 plotObj = self.plotObjList[0]
504 plotObj = self.plotObjList[0]
477 plotObj.plot(currenttime,range,data)
505 plotObj.plot(currenttime,range,data)
478
506
479 if self.showprofile:
507 if self.showprofile:
480 plotObj = self.plotObjList[1]
508 plotObj = self.plotObjList[1]
481 plotObj.plot(data,range)
509 plotObj.plot(data,range)
482
510
483
511
484 class RTIPlot(Plot):
512 class RTIPlot(Plot):
485 deltax = None
513 deltax = None
486 deltay = None
514 deltay = None
487 xrange = [None,None]
515 xrange = [None,None]
488 xminpos = None
516 xminpos = None
489 xmaxpos = None
517 xmaxpos = None
490 xg = None
518 xg = None
491 yg = None
519 yg = None
492
520
493 def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar):
521 def __init__(self,drvObj, idframe, idplot, xi, yi, xw, yw, colorbar, timefmt):
494 self.drvObj = drvObj
522 self.drvObj = drvObj
495 self.idframe = idframe
523 self.idframe = idframe
496 self.idplot = idplot
524 self.idplot = idplot
497 self.xi = xi
525 self.xi = xi
498 self.yi = yi
526 self.yi = yi
499 self.xw = xw
527 self.xw = xw
500 self.yw = yw
528 self.yw = yw
501 self.colorbar = colorbar
529 self.colorbar = colorbar
502
530
503 if self.colorbar:
531 if self.colorbar:
504 cbxi = xw + 0.03
532 cbxi = xw + 0.03
505 cbxw = cbxi + 0.03
533 cbxw = cbxi + 0.03
506 cbyi = yi
534 cbyi = yi
507 cbyw = yw
535 cbyw = yw
508 self.cbxpos = [cbxi,cbxw]
536 self.cbxpos = [cbxi,cbxw]
509 self.cbypos = [cbyi,cbyw]
537 self.cbypos = [cbyi,cbyw]
510
538
511 self.xpos = [self.xi,self.xw]
539 self.xpos = [self.xi,self.xw]
512 self.ypos = [self.yi,self.yw]
540 self.ypos = [self.yi,self.yw]
513 self.xaxisastime = True
541 self.xaxisastime = True
514 self.timefmt = "%H:%M:%S"
542 self.timefmt = timefmt
515 self.xopt = "bcnstd"
543 self.xopt = "bcnstd"
516 self.yopt = "bcnstv"
544 self.yopt = "bcnstv"
517
545
518 self.szchar = 1.0
546 self.szchar = 1.0
519 self.title = "Channel %d"%self.idframe
547 self.title = "Channel %d"%self.idframe
520 self.xlabel = "Local Time"
548 self.xlabel = "Local Time"
521 self.ylabel = "Range (Km)"
549 self.ylabel = "Range (Km)"
522
550
523
551
524 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=True, *args):
552 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=True, *args):
525 self.xmin = xmin
553 self.xmin = xmin
526 self.xmax = xmax
554 self.xmax = xmax
527 self.ymin = ymin
555 self.ymin = ymin
528 self.ymax = ymax
556 self.ymax = ymax
529 self.minvalue = minvalue
557 self.minvalue = minvalue
530 self.maxvalue = maxvalue
558 self.maxvalue = maxvalue
531 self.deltax = deltax
559 self.deltax = deltax
532 self.deltay = deltay
560 self.deltay = deltay
533 self.colorbar = colorbar
561 self.colorbar = colorbar
534
562
535 def plot(self, currenttime, range, data):
563 def plot(self, currenttime, range, data):
536
564
537 if self.xmaxpos == None:
565 if self.xmaxpos == None:
538 self.xmaxpos = currenttime
566 self.xmaxpos = currenttime
539
567
540 # if currenttime >= self.xmaxpos:
568 # if currenttime >= self.xmaxpos:
541
569
542 self.xminpos = currenttime
570 self.xminpos = currenttime
543 self.xmaxpos = currenttime + self.deltax
571 self.xmaxpos = currenttime + self.deltax
544 x = [currenttime]
572 x = [currenttime]
545 y = range
573 y = range
546 z = numpy.reshape(data, (1,-1))
574 z = numpy.reshape(data, (1,-1))
547 getGrid = True
575 getGrid = True
548
576
549 self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid)
577 self.plotPcolor(x, y, z, self.deltax, self.deltay, getGrid)
550
578
551
579
552 class ScopeFigure(Figure):
580 class ScopeFigure(Figure):
553 overplot = 0
581 overplot = 0
554 xw = 700
582 xw = 700
555 yw = 650
583 yw = 650
556 colorbar = None
584 colorbar = None
557
585
558 def __init__(self,idfigure,nframes,wintitle,driver):
586 def __init__(self,idfigure,nframes,wintitle,driver):
559 colormap = None
587 colormap = None
560 colorbar = False
588 colorbar = False
561
589
562 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
590 Figure.__init__(self,idfigure, nframes, wintitle, self.xw, self.yw, self.overplot, driver, colormap, colorbar)
563
591
564
592
565 def getSubplots(self):
593 def getSubplots(self):
566 nrows = self.nframes
594 nrows = self.nframes
567 ncolumns = 1
595 ncolumns = 1
568 return nrows, ncolumns
596 return nrows, ncolumns
569
597
570 def createFrames(self):
598 def createFrames(self):
571
599
572 self.frameObjList = []
600 self.frameObjList = []
573
601
574 for frame in range(self.nframes):
602 for frame in range(self.nframes):
575 frameObj = ScopeFrame(self.drvObj,frame + 1)
603 frameObj = ScopeFrame(self.drvObj,frame + 1)
576 self.frameObjList.append(frameObj)
604 self.frameObjList.append(frameObj)
577
605
578
606
579 class ScopeFrame(Frame):
607 class ScopeFrame(Frame):
580 # plotObjList = []
581 xlabel = ""
608 xlabel = ""
582 ylabel = ""
609 ylabel = ""
583 title = ""
610 title = ""
611 szchar = 1.1
612
584 def __init__(self,drvObj,idframe):
613 def __init__(self,drvObj,idframe):
585 self.drvObj = drvObj
614 self.drvObj = drvObj
586 self.idframe = idframe
615 self.idframe = idframe
587 self.nplots = 1 #nplots/frame
616 self.nplots = 1
588 self.createPlots()
617 self.createPlots()
589 # Frame.__init__(self, drvObj, idframe)
618 # Frame.__init__(self, drvObj, idframe)
590
619
591 def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots
620 def getScreenPosMainPlot(self):#cada Frame determina las coordenadas de los plots
592 xi = 0.08; xw = 0.9
621 xi = 0.08; xw = 0.9
593 yi = 0.20; yw = 0.75
622 yi = 0.20; yw = 0.75
594 return xi,yi,xw,yw
623 return xi,yi,xw,yw
595
624
596 def createPlots(self):
625 def createPlots(self):
597 plotObjList = []
626 plotObjList = []
598 for idplot in range(self.nplots):
627 for idplot in range(self.nplots):
599 xi, yi, xw, yw = self.getScreenPos(idplot)
628 xi, yi, xw, yw = self.getScreenPos(idplot)
600 type = "scopebox"
629 type = "scopebox"
601 title = "Channel %d"%self.idframe
630 title = "Channel %d"%self.idframe
602 xlabel = "range (Km)"
631 xlabel = "range (Km)"
603 ylabel = "intensity"
632 ylabel = "intensity"
604 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel)
633 plotObj = Plot1D(self.drvObj, self.idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel, self.szchar)
605 plotObjList.append(plotObj)
634 plotObjList.append(plotObj)
635
606 self.plotObjList = plotObjList
636 self.plotObjList = plotObjList
607 # self.plotObjList.append(plotObj)
637
608
638
609 def plot(self, x, y, z=None):
639 def plot(self, x, y, z=None):
610 for plotObj in self.plotObjList:
640 for plotObj in self.plotObjList:
611 plotObj.plot(x, y)
641 plotObj.plot(x, y)
612
642
613
643
614 class Plot1D(Plot):
644 class Plot1D(Plot):
615 # type, title, xlabel, ylabel
645 # type, title, xlabel, ylabel
616 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel):
646 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw, type, title, xlabel, ylabel, szchar):
617 self.drvObj = drvObj
647 self.drvObj = drvObj
618 self.idframe = idframe
648 self.idframe = idframe
619 self.idplot = idplot
649 self.idplot = idplot
620 self.xi = xi
650 self.xi = xi
621 self.yi = yi
651 self.yi = yi
622 self.xw = xw
652 self.xw = xw
623 self.yw = yw
653 self.yw = yw
624 self.xpos = [self.xi,self.xw]
654 self.xpos = [self.xi,self.xw]
625 self.ypos = [self.yi,self.yw]
655 self.ypos = [self.yi,self.yw]
626 self.xaxisastime = False
656 self.xaxisastime = False
627 self.timefmt = None
657 self.timefmt = None
628 self.xopt = "bcnst"
658 self.xopt = "bcnst"
629 self.yopt = "bcnstv"
659 self.yopt = "bcnstv"
630 self.szchar = 0.7
660 self.szchar = szchar
631 self.type = type
661 self.type = type
632 self.title = title
662 self.title = title
633 self.xlabel = xlabel
663 self.xlabel = xlabel
634 self.ylabel = ylabel
664 self.ylabel = ylabel
635
665
636
666
637
667
638 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
668 def setBox(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, *args):
639 if self.type == "pwbox":
669 if self.type == "pwbox":
640 self.xmin = minvalue
670 self.xmin = minvalue
641 self.xmax = maxvalue
671 self.xmax = maxvalue
642 self.ymin = ymin
672 self.ymin = ymin
643 self.ymax = ymax
673 self.ymax = ymax
644 self.minvalue = minvalue
674 self.minvalue = minvalue
645 self.maxvalue = maxvalue
675 self.maxvalue = maxvalue
646
676
647 else:
677 else:
648 self.xmin = xmin
678 self.xmin = xmin
649 self.xmax = xmax
679 self.xmax = xmax
650 self.ymin = ymin
680 self.ymin = ymin
651 self.ymax = ymax
681 self.ymax = ymax
652 self.minvalue = minvalue
682 self.minvalue = minvalue
653 self.maxvalue = maxvalue
683 self.maxvalue = maxvalue
654
684
655 self.colorbar = False
685 self.colorbar = False
656
686
657 def plot(self,x,y):
687 def plot(self,x,y):
658 if y.dtype == "complex128":
688 if y.dtype == "complex128":
659 color="blue"
689 color="blue"
660 self.plotBasicLine(x, y.real, color)
690 self.plotBasicLine(x, y.real, color)
661 color="red"
691 color="red"
662 self.plotBasicLine(x, y.imag, color)
692 self.plotBasicLine(x, y.imag, color)
663 else:
693 else:
664 color="blue"
694 color="blue"
665 self.plotBasicLine(x, y, color)
695 self.plotBasicLine(x, y, color)
@@ -1,638 +1,639
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, SpectraHeis
14 from Data.JROData import Spectra, SpectraHeis
15 from IO.SpectraIO import SpectraWriter
15 from IO.SpectraIO import SpectraWriter
16 from Graphics.schainPlotTypes import ScopeFigure, SpcFigure
16 from Graphics.schainPlotTypes import ScopeFigure, 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.integratorOst = []
49 self.integratorOst = []
50 self.plotObjList = []
50 self.plotObjList = []
51 self.noiseObj = []
51 self.noiseObj = []
52 self.writerObjList = []
52 self.writerObjList = []
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, pairsList=None):
56 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairsList=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
64
65
65
66
66
67 if dataInObj.type == "Spectra":
67 if dataInObj.type == "Spectra":
68 if nFFTPoints != None:
68 if nFFTPoints != None:
69 raise ValueError, "The nFFTPoints cannot be selected to this object type"
69 raise ValueError, "The nFFTPoints cannot be selected to this object type"
70
70
71 nFFTPoints = dataInObj.nFFTPoints
71 nFFTPoints = dataInObj.nFFTPoints
72
72
73 if pairsList == None:
73 if pairsList == None:
74 pairsList = dataInObj.pairsList
74 pairsList = dataInObj.pairsList
75
75
76 if pairsList == None:
76 if pairsList == None:
77 nPairs = 0
77 nPairs = 0
78 else:
78 else:
79 nPairs = len(pairsList)
79 nPairs = len(pairsList)
80
80
81 self.dataInObj = dataInObj
81 self.dataInObj = dataInObj
82
82
83 if dataOutObj == None:
83 if dataOutObj == None:
84 dataOutObj = Spectra()
84 dataOutObj = Spectra()
85
85
86 self.dataOutObj = dataOutObj
86 self.dataOutObj = dataOutObj
87 self.dataOutObj.nFFTPoints = nFFTPoints
87 self.dataOutObj.nFFTPoints = nFFTPoints
88 self.dataOutObj.pairsList = pairsList
88 self.dataOutObj.pairsList = pairsList
89 self.dataOutObj.nPairs = nPairs
89 self.dataOutObj.nPairs = nPairs
90
90
91 return self.dataOutObj
91 return self.dataOutObj
92
92
93 def init(self):
93 def init(self):
94
94
95 self.dataOutObj.flagNoData = True
95 self.dataOutObj.flagNoData = True
96
96
97 if self.dataInObj.flagNoData:
97 if self.dataInObj.flagNoData:
98 return 0
98 return 0
99
99
100 self.integratorObjIndex = 0
100 self.integratorObjIndex = 0
101 self.writerObjIndex = 0
101 self.writerObjIndex = 0
102 self.plotObjIndex = 0
102 self.plotObjIndex = 0
103
103
104
104
105 if self.dataInObj.type == "Spectra":
105 if self.dataInObj.type == "Spectra":
106
106
107 self.dataOutObj.copy(self.dataInObj)
107 self.dataOutObj.copy(self.dataInObj)
108 self.dataOutObj.flagNoData = False
108 self.dataOutObj.flagNoData = False
109 return
109 return
110
110
111 if self.dataInObj.type == "Voltage":
111 if self.dataInObj.type == "Voltage":
112
112
113 if self.buffer == None:
113 if self.buffer == None:
114 self.buffer = numpy.zeros((self.dataInObj.nChannels,
114 self.buffer = numpy.zeros((self.dataInObj.nChannels,
115 self.dataOutObj.nFFTPoints,
115 self.dataOutObj.nFFTPoints,
116 self.dataInObj.nHeights),
116 self.dataInObj.nHeights),
117 dtype='complex')
117 dtype='complex')
118
118
119 self.buffer[:,self.profIndex,:] = self.dataInObj.data
119 self.buffer[:,self.profIndex,:] = self.dataInObj.data
120 self.profIndex += 1
120 self.profIndex += 1
121
121
122 if self.profIndex == self.dataOutObj.nFFTPoints:
122 if self.profIndex == self.dataOutObj.nFFTPoints:
123
123
124 self.__updateObjFromInput()
124 self.__updateObjFromInput()
125 self.__getFft()
125 self.__getFft()
126
126
127 self.dataOutObj.flagNoData = False
127 self.dataOutObj.flagNoData = False
128
128
129 self.buffer = None
129 self.buffer = None
130 self.profIndex = 0
130 self.profIndex = 0
131
131
132 return
132 return
133
133
134 #Other kind of data
134 #Other kind of data
135 raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type)
135 raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type)
136
136
137 def __getFft(self):
137 def __getFft(self):
138 """
138 """
139 Convierte valores de Voltaje a Spectra
139 Convierte valores de Voltaje a Spectra
140
140
141 Affected:
141 Affected:
142 self.dataOutObj.data_spc
142 self.dataOutObj.data_spc
143 self.dataOutObj.data_cspc
143 self.dataOutObj.data_cspc
144 self.dataOutObj.data_dc
144 self.dataOutObj.data_dc
145 self.dataOutObj.heightList
145 self.dataOutObj.heightList
146 self.dataOutObj.m_BasicHeader
146 self.dataOutObj.m_BasicHeader
147 self.dataOutObj.m_ProcessingHeader
147 self.dataOutObj.m_ProcessingHeader
148 self.dataOutObj.radarControllerHeaderObj
148 self.dataOutObj.radarControllerHeaderObj
149 self.dataOutObj.systemHeaderObj
149 self.dataOutObj.systemHeaderObj
150 self.profIndex
150 self.profIndex
151 self.buffer
151 self.buffer
152 self.dataOutObj.flagNoData
152 self.dataOutObj.flagNoData
153 self.dataOutObj.dtype
153 self.dataOutObj.dtype
154 self.dataOutObj.nPairs
154 self.dataOutObj.nPairs
155 self.dataOutObj.nChannels
155 self.dataOutObj.nChannels
156 self.dataOutObj.nProfiles
156 self.dataOutObj.nProfiles
157 self.dataOutObj.systemHeaderObj.numChannels
157 self.dataOutObj.systemHeaderObj.numChannels
158 self.dataOutObj.m_ProcessingHeader.totalSpectra
158 self.dataOutObj.m_ProcessingHeader.totalSpectra
159 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
159 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
160 self.dataOutObj.m_ProcessingHeader.numHeights
160 self.dataOutObj.m_ProcessingHeader.numHeights
161 self.dataOutObj.m_ProcessingHeader.spectraComb
161 self.dataOutObj.m_ProcessingHeader.spectraComb
162 self.dataOutObj.m_ProcessingHeader.shif_fft
162 self.dataOutObj.m_ProcessingHeader.shif_fft
163 """
163 """
164
164
165 fft_volt = numpy.fft.fft(self.buffer,axis=1)
165 fft_volt = numpy.fft.fft(self.buffer,axis=1)
166 dc = fft_volt[:,0,:]
166 dc = fft_volt[:,0,:]
167
167
168 #calculo de self-spectra
168 #calculo de self-spectra
169 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
169 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
170 spc = fft_volt * numpy.conjugate(fft_volt)
170 spc = fft_volt * numpy.conjugate(fft_volt)
171 spc = spc.real
171 spc = spc.real
172
172
173 blocksize = 0
173 blocksize = 0
174 blocksize += dc.size
174 blocksize += dc.size
175 blocksize += spc.size
175 blocksize += spc.size
176
176
177 cspc = None
177 cspc = None
178 pairIndex = 0
178 pairIndex = 0
179 if self.dataOutObj.pairsList != None:
179 if self.dataOutObj.pairsList != None:
180 #calculo de cross-spectra
180 #calculo de cross-spectra
181 cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex')
181 cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex')
182 for pair in self.dataOutObj.pairsList:
182 for pair in self.dataOutObj.pairsList:
183 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
183 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
184 pairIndex += 1
184 pairIndex += 1
185 blocksize += cspc.size
185 blocksize += cspc.size
186
186
187 self.dataOutObj.data_spc = spc
187 self.dataOutObj.data_spc = spc
188 self.dataOutObj.data_cspc = cspc
188 self.dataOutObj.data_cspc = cspc
189 self.dataOutObj.data_dc = dc
189 self.dataOutObj.data_dc = dc
190 self.dataOutObj.blockSize = blocksize
190 self.dataOutObj.blockSize = blocksize
191
191
192 # self.getNoise()
192 # self.getNoise()
193
193
194 def __updateObjFromInput(self):
194 def __updateObjFromInput(self):
195
195
196 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
196 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
197 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
197 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
198 self.dataOutObj.channelList = self.dataInObj.channelList
198 self.dataOutObj.channelList = self.dataInObj.channelList
199 self.dataOutObj.heightList = self.dataInObj.heightList
199 self.dataOutObj.heightList = self.dataInObj.heightList
200 self.dataOutObj.dtype = self.dataInObj.dtype
200 self.dataOutObj.dtype = self.dataInObj.dtype
201 self.dataOutObj.nHeights = self.dataInObj.nHeights
201 self.dataOutObj.nHeights = self.dataInObj.nHeights
202 self.dataOutObj.nChannels = self.dataInObj.nChannels
202 self.dataOutObj.nChannels = self.dataInObj.nChannels
203 self.dataOutObj.nBaud = self.dataInObj.nBaud
203 self.dataOutObj.nBaud = self.dataInObj.nBaud
204 self.dataOutObj.nCode = self.dataInObj.nCode
204 self.dataOutObj.nCode = self.dataInObj.nCode
205 self.dataOutObj.code = self.dataInObj.code
205 self.dataOutObj.code = self.dataInObj.code
206 self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints
206 self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints
207 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
207 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
208 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
208 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
209 self.dataOutObj.utctime = self.dataInObj.utctime
209 self.dataOutObj.utctime = self.dataInObj.utctime
210 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
210 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
211 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
211 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
212 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
212 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
213 self.dataOutObj.nIncohInt = 1
213 self.dataOutObj.nIncohInt = 1
214
214
215 def addWriter(self, wrpath, blocksPerFile):
215 def addWriter(self, wrpath, blocksPerFile):
216
216
217 objWriter = SpectraWriter(self.dataOutObj)
217 objWriter = SpectraWriter(self.dataOutObj)
218 objWriter.setup(wrpath, blocksPerFile)
218 objWriter.setup(wrpath, blocksPerFile)
219 self.writerObjList.append(objWriter)
219 self.writerObjList.append(objWriter)
220
220
221 def addIntegrator(self,N,timeInterval):
221 def addIntegrator(self,N,timeInterval):
222
222
223 objIncohInt = IncoherentIntegration(N,timeInterval)
223 objIncohInt = IncoherentIntegration(N,timeInterval)
224 self.integratorObjList.append(objIncohInt)
224 self.integratorObjList.append(objIncohInt)
225
225
226 def addCrossSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
226 def addCrossSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
227 crossSpcObj = CrossSpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
227 crossSpcObj = CrossSpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
228 self.plotObjList.append(crossSpcObj)
228 self.plotObjList.append(crossSpcObj)
229
229
230 def plotCrossSpc(self, idfigure=None,
230 def plotCrossSpc(self, idfigure=None,
231 xmin=None,
231 xmin=None,
232 xmax=None,
232 xmax=None,
233 ymin=None,
233 ymin=None,
234 ymax=None,
234 ymax=None,
235 minvalue=None,
235 minvalue=None,
236 maxvalue=None,
236 maxvalue=None,
237 wintitle='',
237 wintitle='',
238 driver='plplot',
238 driver='plplot',
239 colormap='br_green',
239 colormap='br_green',
240 colorbar=True,
240 colorbar=True,
241 showprofile=False,
241 showprofile=False,
242 save=False,
242 save=False,
243 gpath=None,
243 gpath=None,
244 pairsList = None):
244 pairsList = None):
245
245
246 if self.dataOutObj.flagNoData:
246 if self.dataOutObj.flagNoData:
247 return 0
247 return 0
248
248
249 if pairsList == None:
249 if pairsList == None:
250 pairsList = self.dataOutObj.pairsList
250 pairsList = self.dataOutObj.pairsList
251
251
252 nframes = len(pairsList)
252 nframes = len(pairsList)
253
253
254 x = numpy.arange(self.dataOutObj.nFFTPoints)
254 x = numpy.arange(self.dataOutObj.nFFTPoints)
255
255
256 y = self.dataOutObj.heightList
256 y = self.dataOutObj.heightList
257
257
258
258
259
259
260
260
261 if len(self.plotObjList) <= self.plotObjIndex:
261 if len(self.plotObjList) <= self.plotObjIndex:
262 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
262 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
263
263
264
264
265
265
266
266
267 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
267 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
268
268
269 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
269 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
270 self.plotObjList.append(spcObj)
270 self.plotObjList.append(spcObj)
271
271
272 def plotSpc(self, idfigure=None,
272 def plotSpc(self, idfigure=None,
273 xmin=None,
273 xmin=None,
274 xmax=None,
274 xmax=None,
275 ymin=None,
275 ymin=None,
276 ymax=None,
276 ymax=None,
277 minvalue=None,
277 minvalue=None,
278 maxvalue=None,
278 maxvalue=None,
279 wintitle='',
279 wintitle='',
280 driver='plplot',
280 driver='plplot',
281 colormap='br_green',
281 colormap='br_green',
282 colorbar=True,
282 colorbar=True,
283 showprofile=False,
283 showprofile=False,
284 save=False,
284 save=False,
285 gpath=None,
285 gpath=None,
286 channelList = None):
286 ratio=1,
287 channelList=None):
287
288
288 if self.dataOutObj.flagNoData:
289 if self.dataOutObj.flagNoData:
289 return 0
290 return 0
290
291
291 if channelList == None:
292 if channelList == None:
292 channelList = self.dataOutObj.channelList
293 channelList = self.dataOutObj.channelList
293
294
294 nframes = len(channelList)
295 nframes = len(channelList)
295
296
296 if len(self.plotObjList) <= self.plotObjIndex:
297 if len(self.plotObjList) <= self.plotObjIndex:
297 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
298 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
298
299
299 x = numpy.arange(self.dataOutObj.nFFTPoints)
300 x = numpy.arange(self.dataOutObj.nFFTPoints)
300
301
301 y = self.dataOutObj.heightList
302 y = self.dataOutObj.heightList
302
303
303 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
304 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
304 # noisedB = 10.*numpy.log10(noise)
305 # noisedB = 10.*numpy.log10(noise)
305 noisedB = numpy.arange(len(channelList)+1)
306 noisedB = numpy.arange(len(channelList)+1)
306 noisedB = noisedB *1.2
307 noisedB = noisedB *1.2
307 titleList = []
308 titleList = []
308 for i in range(len(noisedB)):
309 for i in range(len(noisedB)):
309 title = "%.2f"%noisedB[i]
310 title = "%.2f"%noisedB[i]
310 titleList.append(title)
311 titleList.append(title)
311
312
312 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
313 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
313 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
314 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
314 figuretitle = "Spc Radar Data: %s"%dateTime
315 figuretitle = "Spc Radar Data: %s"%dateTime
315
316
316 cleardata = True
317 cleardata = True
317
318
318 plotObj = self.plotObjList[self.plotObjIndex]
319 plotObj = self.plotObjList[self.plotObjIndex]
319
320
320 plotObj.plotPcolor(data=data,
321 plotObj.plotPcolor(data=data,
321 x=x,
322 x=x,
322 y=y,
323 y=y,
323 channelList=channelList,
324 channelList=channelList,
324 xmin=xmin,
325 xmin=xmin,
325 xmax=xmax,
326 xmax=xmax,
326 ymin=ymin,
327 ymin=ymin,
327 ymax=ymax,
328 ymax=ymax,
328 minvalue=minvalue,
329 minvalue=minvalue,
329 maxvalue=maxvalue,
330 maxvalue=maxvalue,
330 figuretitle=figuretitle,
331 figuretitle=figuretitle,
331 xrangestep=None,
332 xrangestep=None,
332 deltax=None,
333 deltax=None,
333 save=save,
334 save=save,
334 gpath=gpath,
335 gpath=gpath,
335 cleardata=cleardata
336 cleardata=cleardata
336 )
337 )
337
338
338 self.plotObjIndex += 1
339 self.plotObjIndex += 1
339
340
340
341
341 def writeData(self, wrpath, blocksPerFile):
342 def writeData(self, wrpath, blocksPerFile):
342
343
343 if self.dataOutObj.flagNoData:
344 if self.dataOutObj.flagNoData:
344 return 0
345 return 0
345
346
346 if len(self.writerObjList) <= self.writerObjIndex:
347 if len(self.writerObjList) <= self.writerObjIndex:
347 self.addWriter(wrpath, blocksPerFile)
348 self.addWriter(wrpath, blocksPerFile)
348
349
349 self.writerObjList[self.writerObjIndex].putData()
350 self.writerObjList[self.writerObjIndex].putData()
350
351
351 self.writerObjIndex += 1
352 self.writerObjIndex += 1
352
353
353 def integrator(self, N=None, timeInterval=None):
354 def integrator(self, N=None, timeInterval=None):
354
355
355 if self.dataOutObj.flagNoData:
356 if self.dataOutObj.flagNoData:
356 return 0
357 return 0
357
358
358 if len(self.integratorObjList) <= self.integratorObjIndex:
359 if len(self.integratorObjList) <= self.integratorObjIndex:
359 self.addIntegrator(N,timeInterval)
360 self.addIntegrator(N,timeInterval)
360
361
361 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
362 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
362 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
363 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
363
364
364 if myIncohIntObj.isReady:
365 if myIncohIntObj.isReady:
365 self.dataOutObj.data_spc = myIncohIntObj.data
366 self.dataOutObj.data_spc = myIncohIntObj.data
366 self.dataOutObj.nAvg = myIncohIntObj.navg
367 self.dataOutObj.nAvg = myIncohIntObj.navg
367 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
368 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
368 self.dataOutObj.flagNoData = False
369 self.dataOutObj.flagNoData = False
369
370
370 """Calcular el ruido"""
371 """Calcular el ruido"""
371 self.getNoise()
372 self.getNoise()
372 else:
373 else:
373 self.dataOutObj.flagNoData = True
374 self.dataOutObj.flagNoData = True
374
375
375 self.integratorObjIndex += 1
376 self.integratorObjIndex += 1
376
377
377
378
378 class SpectraHeisProcessor:
379 class SpectraHeisProcessor:
379
380
380 def __init__(self):
381 def __init__(self):
381
382
382 self.integratorObjIndex = None
383 self.integratorObjIndex = None
383 self.writerObjIndex = None
384 self.writerObjIndex = None
384 self.plotObjIndex = None
385 self.plotObjIndex = None
385 self.integratorObjList = []
386 self.integratorObjList = []
386 self.writerObjList = []
387 self.writerObjList = []
387 self.plotObjList = []
388 self.plotObjList = []
388 #self.noiseObj = Noise()
389 #self.noiseObj = Noise()
389
390
390 def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None):
391 def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None):
391
392
392 if nFFTPoints == None:
393 if nFFTPoints == None:
393 nFFTPoints = self.dataInObj.nHeights
394 nFFTPoints = self.dataInObj.nHeights
394
395
395 self.dataInObj = dataInObj
396 self.dataInObj = dataInObj
396
397
397 if dataOutObj == None:
398 if dataOutObj == None:
398 dataOutObj = SpectraHeis()
399 dataOutObj = SpectraHeis()
399
400
400 self.dataOutObj = dataOutObj
401 self.dataOutObj = dataOutObj
401
402
402 return self.dataOutObj
403 return self.dataOutObj
403
404
404 def init(self):
405 def init(self):
405
406
406 self.dataOutObj.flagNoData = True
407 self.dataOutObj.flagNoData = True
407
408
408 if self.dataInObj.flagNoData:
409 if self.dataInObj.flagNoData:
409 return 0
410 return 0
410
411
411 self.integratorObjIndex = 0
412 self.integratorObjIndex = 0
412 self.writerObjIndex = 0
413 self.writerObjIndex = 0
413 self.plotObjIndex = 0
414 self.plotObjIndex = 0
414
415
415 if self.dataInObj.type == "Voltage":
416 if self.dataInObj.type == "Voltage":
416 self.__updateObjFromInput()
417 self.__updateObjFromInput()
417 self.__getFft()
418 self.__getFft()
418 self.dataOutObj.flagNoData = False
419 self.dataOutObj.flagNoData = False
419 return
420 return
420
421
421 #Other kind of data
422 #Other kind of data
422 if self.dataInObj.type == "SpectraHeis":
423 if self.dataInObj.type == "SpectraHeis":
423 self.dataOutObj.copy(self.dataInObj)
424 self.dataOutObj.copy(self.dataInObj)
424 self.dataOutObj.flagNoData = False
425 self.dataOutObj.flagNoData = False
425 return
426 return
426
427
427 raise ValueError, "The type is not valid"
428 raise ValueError, "The type is not valid"
428
429
429 def __updateObjFromInput(self):
430 def __updateObjFromInput(self):
430
431
431 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
432 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
432 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
433 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
433 self.dataOutObj.channelList = self.dataInObj.channelList
434 self.dataOutObj.channelList = self.dataInObj.channelList
434 self.dataOutObj.heightList = self.dataInObj.heightList
435 self.dataOutObj.heightList = self.dataInObj.heightList
435 self.dataOutObj.dtype = self.dataInObj.dtype
436 self.dataOutObj.dtype = self.dataInObj.dtype
436 self.dataOutObj.nHeights = self.dataInObj.nHeights
437 self.dataOutObj.nHeights = self.dataInObj.nHeights
437 self.dataOutObj.nChannels = self.dataInObj.nChannels
438 self.dataOutObj.nChannels = self.dataInObj.nChannels
438 self.dataOutObj.nBaud = self.dataInObj.nBaud
439 self.dataOutObj.nBaud = self.dataInObj.nBaud
439 self.dataOutObj.nCode = self.dataInObj.nCode
440 self.dataOutObj.nCode = self.dataInObj.nCode
440 self.dataOutObj.code = self.dataInObj.code
441 self.dataOutObj.code = self.dataInObj.code
441 self.dataOutObj.nProfiles = 1
442 self.dataOutObj.nProfiles = 1
442 self.dataOutObj.nFFTPoints = self.dataInObj.nHeights
443 self.dataOutObj.nFFTPoints = self.dataInObj.nHeights
443 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
444 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
444 self.dataOutObj.flagNoData = self.dataInObj.flagNoData
445 self.dataOutObj.flagNoData = self.dataInObj.flagNoData
445 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
446 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
446 self.dataOutObj.utctime = self.dataInObj.utctime
447 self.dataOutObj.utctime = self.dataInObj.utctime
447 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
448 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
448 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
449 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
449 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
450 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
450 self.dataOutObj.nIncohInt = 1
451 self.dataOutObj.nIncohInt = 1
451
452
452 def __getFft(self):
453 def __getFft(self):
453
454
454 fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1)
455 fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1)
455 #print fft_volt
456 #print fft_volt
456 #calculo de self-spectra
457 #calculo de self-spectra
457 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
458 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
458
459
459 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
460 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
460 self.dataOutObj.data_spc = spc
461 self.dataOutObj.data_spc = spc
461
462
462 def getSpectra(self):
463 def getSpectra(self):
463
464
464 return self.dataOutObj.data_spc
465 return self.dataOutObj.data_spc
465
466
466 def getFrecuencies(self):
467 def getFrecuencies(self):
467
468
468 print self.nFFTPoints
469 print self.nFFTPoints
469 return numpy.arange(int(self.nFFTPoints))
470 return numpy.arange(int(self.nFFTPoints))
470
471
471 def addIntegrator(self,N,timeInterval):
472 def addIntegrator(self,N,timeInterval):
472
473
473 objIncohInt = IncoherentIntegration(N,timeInterval)
474 objIncohInt = IncoherentIntegration(N,timeInterval)
474 self.integratorObjList.append(objIncohInt)
475 self.integratorObjList.append(objIncohInt)
475
476
476 def integrator(self, N=None, timeInterval=None):
477 def integrator(self, N=None, timeInterval=None):
477
478
478 if self.dataOutObj.flagNoData:
479 if self.dataOutObj.flagNoData:
479 return 0
480 return 0
480
481
481 if len(self.integratorObjList) <= self.integratorObjIndex:
482 if len(self.integratorObjList) <= self.integratorObjIndex:
482 self.addIntegrator(N,timeInterval)
483 self.addIntegrator(N,timeInterval)
483
484
484 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
485 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
485 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime)
486 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime)
486
487
487 if myIncohIntObj.isReady:
488 if myIncohIntObj.isReady:
488 self.dataOutObj.data_spc = myIncohIntObj.data
489 self.dataOutObj.data_spc = myIncohIntObj.data
489 self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg
490 self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg
490 self.dataOutObj.flagNoData = False
491 self.dataOutObj.flagNoData = False
491
492
492 #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
493 #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
493 # self.getNoise(type="sort", parm=16)
494 # self.getNoise(type="sort", parm=16)
494
495
495 else:
496 else:
496 self.dataOutObj.flagNoData = True
497 self.dataOutObj.flagNoData = True
497
498
498 self.integratorObjIndex += 1
499 self.integratorObjIndex += 1
499
500
500
501
501 def addScope(self, idfigure, nframes, wintitle, driver):
502 def addScope(self, idfigure, nframes, wintitle, driver):
502
503
503 if idfigure==None:
504 if idfigure==None:
504 idfigure = self.plotObjIndex
505 idfigure = self.plotObjIndex
505
506
506 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
507 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
507 self.plotObjList.append(scopeObj)
508 self.plotObjList.append(scopeObj)
508
509
509 def plotScope(self,
510 def plotScope(self,
510 idfigure=None,
511 idfigure=None,
511 minvalue=None,
512 minvalue=None,
512 maxvalue=None,
513 maxvalue=None,
513 xmin=None,
514 xmin=None,
514 xmax=None,
515 xmax=None,
515 wintitle='',
516 wintitle='',
516 driver='plplot',
517 driver='plplot',
517 save=False,
518 save=False,
518 gpath=None,
519 gpath=None,
519 titleList=None,
520 titleList=None,
520 xlabelList=None,
521 xlabelList=None,
521 ylabelList=None):
522 ylabelList=None):
522
523
523 if self.dataOutObj.flagNoData:
524 if self.dataOutObj.flagNoData:
524 return 0
525 return 0
525
526
526 nframes = len(self.dataOutObj.channelList)
527 nframes = len(self.dataOutObj.channelList)
527
528
528 if len(self.plotObjList) <= self.plotObjIndex:
529 if len(self.plotObjList) <= self.plotObjIndex:
529 self.addScope(idfigure, nframes, wintitle, driver)
530 self.addScope(idfigure, nframes, wintitle, driver)
530
531
531
532
532 data1D = self.dataOutObj.data_spc
533 data1D = self.dataOutObj.data_spc
533
534
534 x = numpy.arange(self.dataOutObj.nHeights)
535 x = numpy.arange(self.dataOutObj.nHeights)
535
536
536 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
537 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
537
538
538 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
539 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
539 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
540 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
540
541
541 figureTitle = "Scope Plot Radar Data: " + date
542 figureTitle = "Scope Plot Radar Data: " + date
542
543
543 plotObj = self.plotObjList[self.plotObjIndex]
544 plotObj = self.plotObjList[self.plotObjIndex]
544
545
545 plotObj.plot1DArray(data1D,
546 plotObj.plot1DArray(data1D,
546 x,
547 x,
547 self.dataOutObj.channelList,
548 self.dataOutObj.channelList,
548 xmin,
549 xmin,
549 xmax,
550 xmax,
550 minvalue,
551 minvalue,
551 maxvalue,
552 maxvalue,
552 figureTitle,
553 figureTitle,
553 save,
554 save,
554 gpath)
555 gpath)
555
556
556 self.plotObjIndex += 1
557 self.plotObjIndex += 1
557
558
558 class IncoherentIntegration:
559 class IncoherentIntegration:
559
560
560 integ_counter = None
561 integ_counter = None
561 data = None
562 data = None
562 navg = None
563 navg = None
563 buffer = None
564 buffer = None
564 nIncohInt = None
565 nIncohInt = None
565
566
566 def __init__(self, N = None, timeInterval = None):
567 def __init__(self, N = None, timeInterval = None):
567 """
568 """
568 N
569 N
569 timeInterval - interval time [min], integer value
570 timeInterval - interval time [min], integer value
570 """
571 """
571
572
572 self.data = None
573 self.data = None
573 self.navg = None
574 self.navg = None
574 self.buffer = None
575 self.buffer = None
575 self.timeOut = None
576 self.timeOut = None
576 self.exitCondition = False
577 self.exitCondition = False
577 self.isReady = False
578 self.isReady = False
578 self.nIncohInt = N
579 self.nIncohInt = N
579 self.integ_counter = 0
580 self.integ_counter = 0
580 if timeInterval!=None:
581 if timeInterval!=None:
581 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
582 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
582
583
583 if ((timeInterval==None) and (N==None)):
584 if ((timeInterval==None) and (N==None)):
584 print 'N = None ; timeInterval = None'
585 print 'N = None ; timeInterval = None'
585 sys.exit(0)
586 sys.exit(0)
586 elif timeInterval == None:
587 elif timeInterval == None:
587 self.timeFlag = False
588 self.timeFlag = False
588 else:
589 else:
589 self.timeFlag = True
590 self.timeFlag = True
590
591
591
592
592 def exe(self,data,timeOfData):
593 def exe(self,data,timeOfData):
593 """
594 """
594 data
595 data
595
596
596 timeOfData [seconds]
597 timeOfData [seconds]
597 """
598 """
598
599
599 if self.timeFlag:
600 if self.timeFlag:
600 if self.timeOut == None:
601 if self.timeOut == None:
601 self.timeOut = timeOfData + self.timeIntervalInSeconds
602 self.timeOut = timeOfData + self.timeIntervalInSeconds
602
603
603 if timeOfData < self.timeOut:
604 if timeOfData < self.timeOut:
604 if self.buffer == None:
605 if self.buffer == None:
605 self.buffer = data
606 self.buffer = data
606 else:
607 else:
607 self.buffer = self.buffer + data
608 self.buffer = self.buffer + data
608 self.integ_counter += 1
609 self.integ_counter += 1
609 else:
610 else:
610 self.exitCondition = True
611 self.exitCondition = True
611
612
612 else:
613 else:
613 if self.integ_counter < self.nIncohInt:
614 if self.integ_counter < self.nIncohInt:
614 if self.buffer == None:
615 if self.buffer == None:
615 self.buffer = data
616 self.buffer = data
616 else:
617 else:
617 self.buffer = self.buffer + data
618 self.buffer = self.buffer + data
618
619
619 self.integ_counter += 1
620 self.integ_counter += 1
620
621
621 if self.integ_counter == self.nIncohInt:
622 if self.integ_counter == self.nIncohInt:
622 self.exitCondition = True
623 self.exitCondition = True
623
624
624 if self.exitCondition:
625 if self.exitCondition:
625 self.data = self.buffer
626 self.data = self.buffer
626 self.navg = self.integ_counter
627 self.navg = self.integ_counter
627 self.isReady = True
628 self.isReady = True
628 self.buffer = None
629 self.buffer = None
629 self.timeOut = None
630 self.timeOut = None
630 self.integ_counter = 0
631 self.integ_counter = 0
631 self.exitCondition = False
632 self.exitCondition = False
632
633
633 if self.timeFlag:
634 if self.timeFlag:
634 self.buffer = data
635 self.buffer = data
635 self.timeOut = timeOfData + self.timeIntervalInSeconds
636 self.timeOut = timeOfData + self.timeIntervalInSeconds
636 else:
637 else:
637 self.isReady = False
638 self.isReady = False
638 No newline at end of file
639
@@ -1,416 +1,419
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 ratio=1,
77 channelList=None):
76
78
77 if self.dataOutObj.flagNoData:
79 if self.dataOutObj.flagNoData:
78 return 0
80 return 0
79
81
80 nframes = len(self.dataOutObj.channelList)
82 if channelList == None:
83 channelList = self.dataOutObj.channelList
84
85 nframes = len(channelList)
81
86
82 if len(self.plotObjList) <= self.plotObjIndex:
87 if len(self.plotObjList) <= self.plotObjIndex:
83 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
88 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
84
89
85 data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
90 data = self.dataOutObj.data[channelList,:] * numpy.conjugate(self.dataOutObj.data[channelList,:])
86 data = 10*numpy.log10(data.real)
91 data = 10*numpy.log10(data.real)
87
92
88 # currenttime = self.dataOutObj.utctime
89 # if timezone == "lt":
90 currenttime = self.dataOutObj.utctime - time.timezone
93 currenttime = self.dataOutObj.utctime - time.timezone
91
94
92 range = self.dataOutObj.heightList
95 range = self.dataOutObj.heightList
93
96
94 channelList = self.dataOutObj.channelList
95
96 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
97 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
97 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
98 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
98 date = "%s"%(thisdatetime.strftime("%d-%b-%Y"))
99 date = "%s"%(thisdatetime.strftime("%d-%b-%Y"))
99 print thisdatetime
100 print thisdatetime
100 figuretitle = "RTI Plot Radar Data" #+ date
101 figuretitle = "RTI Plot Radar Data" #+ date
101
102
102 plotObj = self.plotObjList[self.plotObjIndex]
103 plotObj = self.plotObjList[self.plotObjIndex]
103
104
104 cleardata = False
105 cleardata = False
105
106
106 deltax = self.dataOutObj.timeInterval
107 deltax = self.dataOutObj.timeInterval
107
108
108 plotObj.plotPcolor(data=data,
109 plotObj.plotPcolor(data=data,
109 x=currenttime,
110 x=currenttime,
110 y=range,
111 y=range,
111 channelList=channelList,
112 channelList=channelList,
112 xmin=starttime,
113 xmin=starttime,
113 xmax=endtime,
114 xmax=endtime,
114 ymin=rangemin,
115 ymin=rangemin,
115 ymax=rangemax,
116 ymax=rangemax,
116 minvalue=minvalue,
117 minvalue=minvalue,
117 maxvalue=maxvalue,
118 maxvalue=maxvalue,
118 figuretitle=figuretitle,
119 figuretitle=figuretitle,
119 xrangestep=xrangestep,
120 xrangestep=xrangestep,
120 deltax=deltax,
121 deltax=deltax,
121 save=save,
122 save=save,
122 gpath=gpath,
123 gpath=gpath,
123 cleardata=cleardata)
124 ratio=ratio,
125 cleardata=cleardata
126 )
124
127
125
128
126 self.plotObjIndex += 1
129 self.plotObjIndex += 1
127
130
128 def addScope(self, idfigure, nframes, wintitle, driver):
131 def addScope(self, idfigure, nframes, wintitle, driver):
129 if idfigure==None:
132 if idfigure==None:
130 idfigure = self.plotObjIndex
133 idfigure = self.plotObjIndex
131
134
132 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
135 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
133 self.plotObjList.append(scopeObj)
136 self.plotObjList.append(scopeObj)
134
137
135 def plotScope(self,
138 def plotScope(self,
136 idfigure=None,
139 idfigure=None,
137 minvalue=None,
140 minvalue=None,
138 maxvalue=None,
141 maxvalue=None,
139 xmin=None,
142 xmin=None,
140 xmax=None,
143 xmax=None,
141 wintitle='',
144 wintitle='',
142 driver='plplot',
145 driver='plplot',
143 save=False,
146 save=False,
144 gpath=None,
147 gpath=None,
145 titleList=None,
148 ratio=1,
146 xlabelList=None,
147 ylabelList=None,
148 type="power"):
149 type="power"):
149
150
150 if self.dataOutObj.flagNoData:
151 if self.dataOutObj.flagNoData:
151 return 0
152 return 0
152
153
153 nframes = len(self.dataOutObj.channelList)
154 nframes = len(self.dataOutObj.channelList)
154
155
155 if len(self.plotObjList) <= self.plotObjIndex:
156 if len(self.plotObjList) <= self.plotObjIndex:
156 self.addScope(idfigure, nframes, wintitle, driver)
157 self.addScope(idfigure, nframes, wintitle, driver)
157
158
158
159
159 if type=="power":
160 if type=="power":
160 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
161 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
161 data1D = data1D.real
162 data1D = data1D.real
162
163
163 if type =="iq":
164 if type =="iq":
164 data1D = self.dataOutObj.data
165 data1D = self.dataOutObj.data
165
166
166 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
167 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
167
168
168 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
169 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
169 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
170 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
170
171
171 figuretitle = "Scope Plot Radar Data: " + date
172 figuretitle = "Scope Plot Radar Data: " + date
172
173
173 plotObj = self.plotObjList[self.plotObjIndex]
174 plotObj = self.plotObjList[self.plotObjIndex]
174
175
175 plotObj.plot1DArray(data1D=data1D,
176 plotObj.plot1DArray(data1D=data1D,
176 x=self.dataOutObj.heightList,
177 x=self.dataOutObj.heightList,
177 channelList=self.dataOutObj.channelList,
178 channelList=self.dataOutObj.channelList,
178 xmin=xmin,
179 xmin=xmin,
179 xmax=xmax,
180 xmax=xmax,
180 minvalue=minvalue,
181 minvalue=minvalue,
181 maxvalue=maxvalue,
182 maxvalue=maxvalue,
182 figuretitle=figuretitle,
183 figuretitle=figuretitle,
183 save=save,
184 save=save,
184 gpath=gpath)
185 gpath=gpath,
186 ratio=ratio)
185
187
186
188
187 self.plotObjIndex += 1
189 self.plotObjIndex += 1
188
190
189
191
190 def addIntegrator(self, *args):
192 def addIntegrator(self, *args):
191 objCohInt = CoherentIntegrator(*args)
193 objCohInt = CoherentIntegrator(*args)
192 self.integratorObjList.append(objCohInt)
194 self.integratorObjList.append(objCohInt)
193
195
194 def addWriter(self, *args):
196 def addWriter(self, *args):
195 writerObj = VoltageWriter(self.dataOutObj)
197 writerObj = VoltageWriter(self.dataOutObj)
196 writerObj.setup(*args)
198 writerObj.setup(*args)
197 self.writerObjList.append(writerObj)
199 self.writerObjList.append(writerObj)
198
200
199 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
201 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
200
202
201 if self.dataOutObj.flagNoData:
203 if self.dataOutObj.flagNoData:
202 return 0
204 return 0
203
205
204 if len(self.writerObjList) <= self.writerObjIndex:
206 if len(self.writerObjList) <= self.writerObjIndex:
205 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
207 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
206
208
207 self.writerObjList[self.writerObjIndex].putData()
209 self.writerObjList[self.writerObjIndex].putData()
208
210
209 self.writerObjIndex += 1
211 self.writerObjIndex += 1
210
212
211 def integrator(self, nCohInt=None, timeInterval=None, overlapping=False):
213 def integrator(self, nCohInt=None, timeInterval=None, overlapping=False):
212
214
213 if self.dataOutObj.flagNoData:
215 if self.dataOutObj.flagNoData:
214 return 0
216 return 0
215
217
216 if len(self.integratorObjList) <= self.integratorObjIndex:
218 if len(self.integratorObjList) <= self.integratorObjIndex:
217 self.addIntegrator(nCohInt, timeInterval, overlapping)
219 self.addIntegrator(nCohInt, timeInterval, overlapping)
218
220
219 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
221 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
220 myCohIntObj.exe(data = self.dataOutObj.data, datatime=None)
222 myCohIntObj.exe(data = self.dataOutObj.data, datatime=None)
221
223
222 self.dataOutObj.timeInterval *= nCohInt
224 self.dataOutObj.timeInterval *= nCohInt
223 self.dataOutObj.flagNoData = True
225 self.dataOutObj.flagNoData = True
224
226
225 if myCohIntObj.isReady:
227 if myCohIntObj.isReady:
228 self.dataOutObj.timeInterval = myCohIntObj.nCohInt * self.dataOutObj.timeInterval
226 self.dataOutObj.flagNoData = False
229 self.dataOutObj.flagNoData = False
227
230
228 def selectChannels(self, channelList):
231 def selectChannels(self, channelList):
229
232
230 self.selectChannelsByIndex(channelList)
233 self.selectChannelsByIndex(channelList)
231
234
232 def selectChannelsByIndex(self, channelIndexList):
235 def selectChannelsByIndex(self, channelIndexList):
233 """
236 """
234 Selecciona un bloque de datos en base a canales segun el channelIndexList
237 Selecciona un bloque de datos en base a canales segun el channelIndexList
235
238
236 Input:
239 Input:
237 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
240 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
238
241
239 Affected:
242 Affected:
240 self.dataOutObj.data
243 self.dataOutObj.data
241 self.dataOutObj.channelIndexList
244 self.dataOutObj.channelIndexList
242 self.dataOutObj.nChannels
245 self.dataOutObj.nChannels
243 self.dataOutObj.m_ProcessingHeader.totalSpectra
246 self.dataOutObj.m_ProcessingHeader.totalSpectra
244 self.dataOutObj.systemHeaderObj.numChannels
247 self.dataOutObj.systemHeaderObj.numChannels
245 self.dataOutObj.m_ProcessingHeader.blockSize
248 self.dataOutObj.m_ProcessingHeader.blockSize
246
249
247 Return:
250 Return:
248 None
251 None
249 """
252 """
250 if self.dataOutObj.flagNoData:
253 if self.dataOutObj.flagNoData:
251 return 0
254 return 0
252
255
253 for channel in channelIndexList:
256 for channel in channelIndexList:
254 if channel not in self.dataOutObj.channelIndexList:
257 if channel not in self.dataOutObj.channelIndexList:
255 raise ValueError, "The value %d in channelIndexList is not valid" %channel
258 raise ValueError, "The value %d in channelIndexList is not valid" %channel
256
259
257 nChannels = len(channelIndexList)
260 nChannels = len(channelIndexList)
258
261
259 data = self.dataOutObj.data[channelIndexList,:]
262 data = self.dataOutObj.data[channelIndexList,:]
260
263
261 self.dataOutObj.data = data
264 self.dataOutObj.data = data
262 self.dataOutObj.channelIndexList = channelIndexList
265 self.dataOutObj.channelIndexList = channelIndexList
263 self.dataOutObj.channelList = [self.dataOutObj.channelList[i] for i in channelIndexList]
266 self.dataOutObj.channelList = [self.dataOutObj.channelList[i] for i in channelIndexList]
264 self.dataOutObj.nChannels = nChannels
267 self.dataOutObj.nChannels = nChannels
265
268
266 return 1
269 return 1
267
270
268 class CoherentIntegrator:
271 class CoherentIntegrator:
269
272
270
273
271 __profIndex = 0
274 __profIndex = 0
272 __withOverapping = False
275 __withOverapping = False
273
276
274 __isByTime = False
277 __isByTime = False
275 __initime = None
278 __initime = None
276 __integrationtime = None
279 __integrationtime = None
277
280
278 __buffer = None
281 __buffer = None
279
282
280 isReady = False
283 isReady = False
281 nCohInt = None
284 nCohInt = None
282
285
283
286
284 def __init__(self, nCohInt=None, timeInterval=None, overlapping=False):
287 def __init__(self, nCohInt=None, timeInterval=None, overlapping=False):
285
288
286 """
289 """
287 Set the parameters of the integration class.
290 Set the parameters of the integration class.
288
291
289 Inputs:
292 Inputs:
290
293
291 nCohInt : Number of coherent integrations
294 nCohInt : Number of coherent integrations
292 timeInterval : Time of integration. If nCohInt is selected this parameter does not work
295 timeInterval : Time of integration. If nCohInt is selected this parameter does not work
293 overlapping :
296 overlapping :
294
297
295 """
298 """
296
299
297 self.__buffer = None
300 self.__buffer = None
298 self.isReady = False
301 self.isReady = False
299
302
300 if nCohInt == None and timeInterval == None:
303 if nCohInt == None and timeInterval == None:
301 raise ValueError, "nCohInt or timeInterval should be specified ..."
304 raise ValueError, "nCohInt or timeInterval should be specified ..."
302
305
303 if nCohInt != None:
306 if nCohInt != None:
304 self.nCohInt = nCohInt
307 self.nCohInt = nCohInt
305 self.__isByTime = False
308 self.__isByTime = False
306 else:
309 else:
307 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
310 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
308 self.__isByTime = True
311 self.__isByTime = True
309
312
310 if overlapping:
313 if overlapping:
311 self.__withOverapping = True
314 self.__withOverapping = True
312 self.__buffer = None
315 self.__buffer = None
313 else:
316 else:
314 self.__withOverapping = False
317 self.__withOverapping = False
315 self.__buffer = 0
318 self.__buffer = 0
316
319
317 self.__profIndex = 0
320 self.__profIndex = 0
318
321
319 def putData(self, data):
322 def putData(self, data):
320
323
321 """
324 """
322 Add a profile to the __buffer and increase in one the __profileIndex
325 Add a profile to the __buffer and increase in one the __profileIndex
323
326
324 """
327 """
325 if not self.__withOverapping:
328 if not self.__withOverapping:
326 self.__buffer += data
329 self.__buffer += data
327 self.__profIndex += 1
330 self.__profIndex += 1
328 return
331 return
329
332
330 #Overlapping data
333 #Overlapping data
331 nChannels, nHeis = data.shape
334 nChannels, nHeis = data.shape
332 data = numpy.reshape(data, (1, nChannels, nHeis))
335 data = numpy.reshape(data, (1, nChannels, nHeis))
333
336
334 if self.__buffer == None:
337 if self.__buffer == None:
335 self.__buffer = data
338 self.__buffer = data
336 self.__profIndex += 1
339 self.__profIndex += 1
337 return
340 return
338
341
339 if self.__profIndex < self.nCohInt:
342 if self.__profIndex < self.nCohInt:
340 self.__buffer = numpy.vstack((self.__buffer, data))
343 self.__buffer = numpy.vstack((self.__buffer, data))
341 self.__profIndex += 1
344 self.__profIndex += 1
342 return
345 return
343
346
344 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
347 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
345 self.__buffer[self.nCohInt-1] = data
348 self.__buffer[self.nCohInt-1] = data
346 #self.__profIndex = self.nCohInt
349 #self.__profIndex = self.nCohInt
347 return
350 return
348
351
349
352
350 def pushData(self):
353 def pushData(self):
351 """
354 """
352 Return the sum of the last profiles and the profiles used in the sum.
355 Return the sum of the last profiles and the profiles used in the sum.
353
356
354 Affected:
357 Affected:
355
358
356 self.__profileIndex
359 self.__profileIndex
357
360
358 """
361 """
359
362
360 if not self.__withOverapping:
363 if not self.__withOverapping:
361 data = self.__buffer
364 data = self.__buffer
362 nCohInt = self.__profIndex
365 nCohInt = self.__profIndex
363
366
364 self.__buffer = 0
367 self.__buffer = 0
365 self.__profIndex = 0
368 self.__profIndex = 0
366
369
367 return data, nCohInt
370 return data, nCohInt
368
371
369 #Overlapping data
372 #Overlapping data
370 data = numpy.sum(self.__buffer, axis=0)
373 data = numpy.sum(self.__buffer, axis=0)
371 nCohInt = self.__profIndex
374 nCohInt = self.__profIndex
372
375
373 return data, nCohInt
376 return data, nCohInt
374
377
375 def byProfiles(self, data):
378 def byProfiles(self, data):
376
379
377 self.isReady = False
380 self.isReady = False
378 avg_data = None
381 avg_data = None
379
382
380 self.putData(data)
383 self.putData(data)
381
384
382 if self.__profIndex == self.nCohInt:
385 if self.__profIndex == self.nCohInt:
383 avg_data, nCohInt = self.pushData()
386 avg_data, nCohInt = self.pushData()
384 self.isReady = True
387 self.isReady = True
385
388
386 return avg_data
389 return avg_data
387
390
388 def byTime(self, data, datatime):
391 def byTime(self, data, datatime):
389
392
390 self.isReady = False
393 self.isReady = False
391 avg_data = None
394 avg_data = None
392
395
393 if self.__initime == None:
396 if self.__initime == None:
394 self.__initime = datatime
397 self.__initime = datatime
395
398
396 self.putData(data)
399 self.putData(data)
397
400
398 if (datatime - self.__initime) >= self.__integrationtime:
401 if (datatime - self.__initime) >= self.__integrationtime:
399 avg_data, nCohInt = self.pushData()
402 avg_data, nCohInt = self.pushData()
400 self.nCohInt = nCohInt
403 self.nCohInt = nCohInt
401 self.isReady = True
404 self.isReady = True
402
405
403 return avg_data
406 return avg_data
404
407
405 def exe(self, data, datatime=None):
408 def exe(self, data, datatime=None):
406
409
407 if not self.__isByTime:
410 if not self.__isByTime:
408 avg_data = self.byProfiles(data)
411 avg_data = self.byProfiles(data)
409 else:
412 else:
410 avg_data = self.byTime(data, datatime)
413 avg_data = self.byTime(data, datatime)
411
414
412 self.data = avg_data
415 self.data = avg_data
413
416
414 return avg_data
417 return avg_data
415
418
416
419
General Comments 0
You need to be logged in to leave comments. Login now