##// END OF EJS Templates
Getnoise se agrega al metodo getFft de SpectraProcessor.
Daniel Valdez -
r111:9c1626ca5c6a
parent child
Show More
@@ -1,963 +1,965
1 """
1 """
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @autor $Author$
4 @autor $Author$
5 @version $Id$
5 @version $Id$
6
6
7 """
7 """
8 import os
8 import os
9 import numpy
9 import numpy
10 import sys
10 import sys
11 import time
11 import time
12 import datetime
12 import datetime
13 import time
13 import time
14 import plplot
14 import plplot
15
15
16
16
17 def cmap1_init(colormap="gray"):
17 def cmap1_init(colormap="gray"):
18
18
19 if colormap == None:
19 if colormap == None:
20 return
20 return
21
21
22 ncolor = None
22 ncolor = None
23 rgb_lvl = None
23 rgb_lvl = None
24
24
25 # Routine for defining a specific color map 1 in HLS space.
25 # Routine for defining a specific color map 1 in HLS space.
26 # if gray is true, use basic grayscale variation from half-dark to light.
26 # if gray is true, use basic grayscale variation from half-dark to light.
27 # otherwise use false color variation from blue (240 deg) to red (360 deg).
27 # otherwise use false color variation from blue (240 deg) to red (360 deg).
28
28
29 # Independent variable of control points.
29 # Independent variable of control points.
30 i = numpy.array((0., 1.))
30 i = numpy.array((0., 1.))
31 if colormap=="gray":
31 if colormap=="gray":
32 ncolor = 256
32 ncolor = 256
33 # Hue for control points. Doesn't matter since saturation is zero.
33 # Hue for control points. Doesn't matter since saturation is zero.
34 h = numpy.array((0., 0.))
34 h = numpy.array((0., 0.))
35 # Lightness ranging from half-dark (for interest) to light.
35 # Lightness ranging from half-dark (for interest) to light.
36 l = numpy.array((0.5, 1.))
36 l = numpy.array((0.5, 1.))
37 # Gray scale has zero saturation
37 # Gray scale has zero saturation
38 s = numpy.array((0., 0.))
38 s = numpy.array((0., 0.))
39
39
40 # number of cmap1 colours is 256 in this case.
40 # number of cmap1 colours is 256 in this case.
41 plplot.plscmap1n(ncolor)
41 plplot.plscmap1n(ncolor)
42 # Interpolate between control points to set up cmap1.
42 # Interpolate between control points to set up cmap1.
43 plplot.plscmap1l(0, i, h, l, s)
43 plplot.plscmap1l(0, i, h, l, s)
44
44
45 return None
45 return None
46
46
47 if colormap == 'jet':
47 if colormap == 'jet':
48 ncolor = 256
48 ncolor = 256
49 pos = numpy.zeros((ncolor))
49 pos = numpy.zeros((ncolor))
50 r = numpy.zeros((ncolor))
50 r = numpy.zeros((ncolor))
51 g = numpy.zeros((ncolor))
51 g = numpy.zeros((ncolor))
52 b = numpy.zeros((ncolor))
52 b = numpy.zeros((ncolor))
53
53
54 for i in range(ncolor):
54 for i in range(ncolor):
55 if(i <= 35.0/100*(ncolor-1)): rf = 0.0
55 if(i <= 35.0/100*(ncolor-1)): rf = 0.0
56 elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
56 elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
57 elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
57 elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
58 else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
58 else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
59
59
60 if(i <= 12.0/100*(ncolor-1)): gf = 0.0
60 if(i <= 12.0/100*(ncolor-1)): gf = 0.0
61 elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
61 elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
62 elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
62 elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
63 elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
63 elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
64 else: gf = 0.0
64 else: gf = 0.0
65
65
66 if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
66 if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
67 elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
67 elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
68 elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
68 elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
69 else: bf = 0
69 else: bf = 0
70
70
71 r[i] = rf
71 r[i] = rf
72 g[i] = gf
72 g[i] = gf
73 b[i] = bf
73 b[i] = bf
74
74
75 pos[i] = float(i)/float(ncolor-1)
75 pos[i] = float(i)/float(ncolor-1)
76
76
77
77
78 plplot.plscmap1n(ncolor)
78 plplot.plscmap1n(ncolor)
79 plplot.plscmap1l(1, pos, r, g, b)
79 plplot.plscmap1l(1, pos, r, g, b)
80
80
81
81
82
82
83 if colormap=="br_green":
83 if colormap=="br_green":
84 ncolor = 256
84 ncolor = 256
85 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
85 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
86 h = numpy.array((240., 0.))
86 h = numpy.array((240., 0.))
87 # Lightness and saturation are constant (values taken from C example).
87 # Lightness and saturation are constant (values taken from C example).
88 l = numpy.array((0.6, 0.6))
88 l = numpy.array((0.6, 0.6))
89 s = numpy.array((0.8, 0.8))
89 s = numpy.array((0.8, 0.8))
90
90
91 # number of cmap1 colours is 256 in this case.
91 # number of cmap1 colours is 256 in this case.
92 plplot.plscmap1n(ncolor)
92 plplot.plscmap1n(ncolor)
93 # Interpolate between control points to set up cmap1.
93 # Interpolate between control points to set up cmap1.
94 plplot.plscmap1l(0, i, h, l, s)
94 plplot.plscmap1l(0, i, h, l, s)
95
95
96 return None
96 return None
97
97
98 if colormap=="tricolor":
98 if colormap=="tricolor":
99 ncolor = 3
99 ncolor = 3
100 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
100 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
101 h = numpy.array((240., 0.))
101 h = numpy.array((240., 0.))
102 # Lightness and saturation are constant (values taken from C example).
102 # Lightness and saturation are constant (values taken from C example).
103 l = numpy.array((0.6, 0.6))
103 l = numpy.array((0.6, 0.6))
104 s = numpy.array((0.8, 0.8))
104 s = numpy.array((0.8, 0.8))
105
105
106 # number of cmap1 colours is 256 in this case.
106 # number of cmap1 colours is 256 in this case.
107 plplot.plscmap1n(ncolor)
107 plplot.plscmap1n(ncolor)
108 # Interpolate between control points to set up cmap1.
108 # Interpolate between control points to set up cmap1.
109 plplot.plscmap1l(0, i, h, l, s)
109 plplot.plscmap1l(0, i, h, l, s)
110
110
111 return None
111 return None
112
112
113 if colormap == 'rgb' or colormap == 'rgb666':
113 if colormap == 'rgb' or colormap == 'rgb666':
114
114
115 color_sz = 6
115 color_sz = 6
116 ncolor = color_sz*color_sz*color_sz
116 ncolor = color_sz*color_sz*color_sz
117 pos = numpy.zeros((ncolor))
117 pos = numpy.zeros((ncolor))
118 r = numpy.zeros((ncolor))
118 r = numpy.zeros((ncolor))
119 g = numpy.zeros((ncolor))
119 g = numpy.zeros((ncolor))
120 b = numpy.zeros((ncolor))
120 b = numpy.zeros((ncolor))
121 ind = 0
121 ind = 0
122 for ri in range(color_sz):
122 for ri in range(color_sz):
123 for gi in range(color_sz):
123 for gi in range(color_sz):
124 for bi in range(color_sz):
124 for bi in range(color_sz):
125 r[ind] = ri/(color_sz-1.0)
125 r[ind] = ri/(color_sz-1.0)
126 g[ind] = gi/(color_sz-1.0)
126 g[ind] = gi/(color_sz-1.0)
127 b[ind] = bi/(color_sz-1.0)
127 b[ind] = bi/(color_sz-1.0)
128 pos[ind] = ind/(ncolor-1.0)
128 pos[ind] = ind/(ncolor-1.0)
129 ind += 1
129 ind += 1
130 rgb_lvl = [6,6,6] #Levels for RGB colors
130 rgb_lvl = [6,6,6] #Levels for RGB colors
131
131
132 if colormap == 'rgb676':
132 if colormap == 'rgb676':
133 ncolor = 6*7*6
133 ncolor = 6*7*6
134 pos = numpy.zeros((ncolor))
134 pos = numpy.zeros((ncolor))
135 r = numpy.zeros((ncolor))
135 r = numpy.zeros((ncolor))
136 g = numpy.zeros((ncolor))
136 g = numpy.zeros((ncolor))
137 b = numpy.zeros((ncolor))
137 b = numpy.zeros((ncolor))
138 ind = 0
138 ind = 0
139 for ri in range(8):
139 for ri in range(8):
140 for gi in range(8):
140 for gi in range(8):
141 for bi in range(4):
141 for bi in range(4):
142 r[ind] = ri/(6-1.0)
142 r[ind] = ri/(6-1.0)
143 g[ind] = gi/(7-1.0)
143 g[ind] = gi/(7-1.0)
144 b[ind] = bi/(6-1.0)
144 b[ind] = bi/(6-1.0)
145 pos[ind] = ind/(ncolor-1.0)
145 pos[ind] = ind/(ncolor-1.0)
146 ind += 1
146 ind += 1
147 rgb_lvl = [6,7,6] #Levels for RGB colors
147 rgb_lvl = [6,7,6] #Levels for RGB colors
148
148
149 if colormap == 'rgb685':
149 if colormap == 'rgb685':
150 ncolor = 6*8*5
150 ncolor = 6*8*5
151 pos = numpy.zeros((ncolor))
151 pos = numpy.zeros((ncolor))
152 r = numpy.zeros((ncolor))
152 r = numpy.zeros((ncolor))
153 g = numpy.zeros((ncolor))
153 g = numpy.zeros((ncolor))
154 b = numpy.zeros((ncolor))
154 b = numpy.zeros((ncolor))
155 ind = 0
155 ind = 0
156 for ri in range(8):
156 for ri in range(8):
157 for gi in range(8):
157 for gi in range(8):
158 for bi in range(4):
158 for bi in range(4):
159 r[ind] = ri/(6-1.0)
159 r[ind] = ri/(6-1.0)
160 g[ind] = gi/(8-1.0)
160 g[ind] = gi/(8-1.0)
161 b[ind] = bi/(5-1.0)
161 b[ind] = bi/(5-1.0)
162 pos[ind] = ind/(ncolor-1.0)
162 pos[ind] = ind/(ncolor-1.0)
163 ind += 1
163 ind += 1
164 rgb_lvl = [6,8,5] #Levels for RGB colors
164 rgb_lvl = [6,8,5] #Levels for RGB colors
165
165
166 if colormap == 'rgb884':
166 if colormap == 'rgb884':
167 ncolor = 8*8*4
167 ncolor = 8*8*4
168 pos = numpy.zeros((ncolor))
168 pos = numpy.zeros((ncolor))
169 r = numpy.zeros((ncolor))
169 r = numpy.zeros((ncolor))
170 g = numpy.zeros((ncolor))
170 g = numpy.zeros((ncolor))
171 b = numpy.zeros((ncolor))
171 b = numpy.zeros((ncolor))
172 ind = 0
172 ind = 0
173 for ri in range(8):
173 for ri in range(8):
174 for gi in range(8):
174 for gi in range(8):
175 for bi in range(4):
175 for bi in range(4):
176 r[ind] = ri/(8-1.0)
176 r[ind] = ri/(8-1.0)
177 g[ind] = gi/(8-1.0)
177 g[ind] = gi/(8-1.0)
178 b[ind] = bi/(4-1.0)
178 b[ind] = bi/(4-1.0)
179 pos[ind] = ind/(ncolor-1.0)
179 pos[ind] = ind/(ncolor-1.0)
180 ind += 1
180 ind += 1
181 rgb_lvl = [8,8,4] #Levels for RGB colors
181 rgb_lvl = [8,8,4] #Levels for RGB colors
182
182
183 if ncolor == None:
183 if ncolor == None:
184 raise ValueError, "The colormap selected is not valid"
184 raise ValueError, "The colormap selected is not valid"
185
185
186 plplot.plscmap1n(ncolor)
186 plplot.plscmap1n(ncolor)
187 plplot.plscmap1l(1, pos, r, g, b)
187 plplot.plscmap1l(1, pos, r, g, b)
188
188
189 return rgb_lvl
189 return rgb_lvl
190
190
191 def setColormap(colormap="jet"):
191 def setColormap(colormap="jet"):
192 cmap1_init(colormap)
192 cmap1_init(colormap)
193
193
194 def savePlplot(indexPlot,filename,ncol,nrow,width,height):
194 def savePlplot(filename,width,height):
195 curr_strm = plplot.plgstrm()
195 curr_strm = plplot.plgstrm()
196 save_strm = plplot.plmkstrm()
196 save_strm = plplot.plmkstrm()
197 plplot.plsetopt("geometry", "%dx%d"%(width*ncol,height*nrow))
197 plplot.plsetopt("geometry", "%dx%d"%(width,height))
198 plplot.plsdev("pngcairo")
198 plplot.plsdev("png")
199 plplot.plsfnam(filename)
199 plplot.plsfnam(filename)
200 plplot.plcpstrm(curr_strm,0)
200 plplot.plcpstrm(curr_strm,0)
201 plplot.plreplot()
201 plplot.plreplot()
202 plplot.plclear()
202 plplot.plend1()
203 plplot.plend1()
203 plplot.plsstrm(indexPlot)
204 plplot.plsstrm(curr_strm)
204 print ''
205
205
206
206
207 def initPlplot(indexPlot,ncol,nrow,winTitle,width,height):
207 def initPlplot(indexPlot,ncol,nrow,winTitle,width,height):
208 plplot.plsstrm(indexPlot)
208 plplot.plsstrm(indexPlot)
209 plplot.plparseopts([winTitle],plplot.PL_PARSE_FULL)
209 plplot.plparseopts([winTitle],plplot.PL_PARSE_FULL)
210 plplot.plsetopt("geometry", "%dx%d"%(width*ncol,height*nrow))
210 plplot.plsetopt("geometry", "%dx%d"%(width*ncol,height*nrow))
211 plplot.plsdev("xwin")
211 plplot.plsdev("xwin")
212 plplot.plscolbg(255,255,255)
212 plplot.plscolbg(255,255,255)
213 plplot.plscol0(1,0,0,0)
213 plplot.plscol0(1,0,0,0)
214 plplot.plinit()
214 plplot.plinit()
215 plplot.plspause(False)
215 plplot.plspause(False)
216 plplot.plssub(ncol,nrow)
216 plplot.plssub(ncol,nrow)
217
217
218 def clearData(objGraph):
218 def clearData(objGraph):
219 objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bc", "bc")
219 objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bc", "bc")
220
220
221 objGraph.setColor(15) #Setting Line Color to White
221 objGraph.setColor(15) #Setting Line Color to White
222
222
223 if objGraph.datatype == "complex":
223 if objGraph.datatype == "complex":
224 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real)
224 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.real)
225 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag)
225 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata.imag)
226
226
227 if objGraph.datatype == "real":
227 if objGraph.datatype == "real":
228 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata)
228 objGraph.basicXYPlot(objGraph.xdata,objGraph.ydata)
229
229
230 objGraph.setColor(1) #Setting Line Color to Black
230 objGraph.setColor(1) #Setting Line Color to Black
231 # objGraph.setLineStyle(2)
231 # objGraph.setLineStyle(2)
232 # objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bcntg", "bc")
232 # objGraph.plotBox(objGraph.xrange[0], objGraph.xrange[1], objGraph.yrange[0], objGraph.yrange[1], "bcntg", "bc")
233 # objGraph.setLineStyle(1)
233 # objGraph.setLineStyle(1)
234
234
235 def setStrm(indexPlot):
235 def setStrm(indexPlot):
236 plplot.plsstrm(indexPlot)
236 plplot.plsstrm(indexPlot)
237
237
238 def plFlush():
238 def plFlush():
239 plplot.plflush()
239 plplot.plflush()
240
240
241 def setPlTitle(pltitle,color):
241 def setPlTitle(pltitle,color):
242 setSubpages(1, 0)
242 setSubpages(1, 0)
243 plplot.pladv(0)
243 plplot.pladv(0)
244 plplot.plvpor(0., 1., 0., 1.)
244 plplot.plvpor(0., 1., 0., 1.)
245
245
246 if color == "black":
246 if color == "black":
247 plplot.plcol0(1)
247 plplot.plcol0(1)
248 if color == "white":
248 if color == "white":
249 plplot.plcol0(15)
249 plplot.plcol0(15)
250
250
251 plplot.plmtex("t",-1., 0.5, 0.5, pltitle)
251 plplot.plmtex("t",-1., 0.5, 0.5, pltitle)
252
252
253 def setSubpages(ncol,nrow):
253 def setSubpages(ncol,nrow):
254 plplot.plssub(ncol,nrow)
254 plplot.plssub(ncol,nrow)
255
255
256 class BaseGraph:
256 class BaseGraph:
257 __name = None
257 __name = None
258 __xpos = None
258 __xpos = None
259 __ypos = None
259 __ypos = None
260 __subplot = None
260 __subplot = None
261 __xg = None
261 __xg = None
262 __yg = None
262 __yg = None
263 xdata = None
263 xdata = None
264 ydata = None
264 ydata = None
265 getGrid = True
265 getGrid = True
266 xaxisIsTime = False
266 xaxisIsTime = False
267 deltax = None
267 deltax = None
268 xmin = None
268 xmin = None
269 xmax = None
269 xmax = None
270 def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0):
270 def __init__(self,name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange=None,deltax=1.0):
271 self.setName(name)
271 self.setName(name)
272 self.setScreenPos(xpos, ypos)
272 self.setScreenPos(xpos, ypos)
273 self.setLabels(xlabel,ylabel,title)
273 self.setLabels(xlabel,ylabel,title)
274 self.setSubPlot(subplot)
274 self.setSubPlot(subplot)
275 self.setSizeOfChar(szchar)
275 self.setSizeOfChar(szchar)
276 self.setXYZrange(xrange,yrange,zrange)
276 self.setXYZrange(xrange,yrange,zrange)
277 self.getGrid = True
277 self.getGrid = True
278 self.xaxisIsTime = False
278 self.xaxisIsTime = False
279 self.deltax = deltax
279 self.deltax = deltax
280
280
281 def setXYZrange(self,xrange,yrange,zrange):
281 def setXYZrange(self,xrange,yrange,zrange):
282 self.xrange = xrange
282 self.xrange = xrange
283 self.yrange = yrange
283 self.yrange = yrange
284 self.zrange = zrange
284 self.zrange = zrange
285
285
286 def setName(self, name):
286 def setName(self, name):
287 self.__name = name
287 self.__name = name
288
288
289 def setScreenPos(self,xpos,ypos):
289 def setScreenPos(self,xpos,ypos):
290 self.__xpos = xpos
290 self.__xpos = xpos
291 self.__ypos = ypos
291 self.__ypos = ypos
292
292
293 def setXYData(self,xdata=None,ydata=None,datatype="real"):
293 def setXYData(self,xdata=None,ydata=None,datatype="real"):
294 if((xdata != None) and (ydata != None)):
294 if((xdata != None) and (ydata != None)):
295 self.xdata = xdata
295 self.xdata = xdata
296 self.ydata = ydata
296 self.ydata = ydata
297 self.datatype = datatype
297 self.datatype = datatype
298
298
299 if((self.xdata == None) and (self.ydata == None)):
299 if((self.xdata == None) and (self.ydata == None)):
300 return None
300 return None
301
301
302 return 1
302 return 1
303
303
304
304
305 def setLabels(self,xlabel=None,ylabel=None,title=None):
305 def setLabels(self,xlabel=None,ylabel=None,title=None):
306 if xlabel != None: self.xlabel = xlabel
306 if xlabel != None: self.xlabel = xlabel
307 if ylabel != None: self.ylabel = ylabel
307 if ylabel != None: self.ylabel = ylabel
308 if title != None: self.title = title
308 if title != None: self.title = title
309
309
310 def setSubPlot(self,subplot):
310 def setSubPlot(self,subplot):
311 self.__subplot = subplot
311 self.__subplot = subplot
312
312
313 def setSizeOfChar(self,szchar):
313 def setSizeOfChar(self,szchar):
314 self.__szchar = szchar
314 self.__szchar = szchar
315
315
316 def setLineStyle(self,style):
316 def setLineStyle(self,style):
317 plplot.pllsty(style)
317 plplot.pllsty(style)
318
318
319 def setColor(self,color):
319 def setColor(self,color):
320 plplot.plcol0(color)
320 plplot.plcol0(color)
321
321
322 def setXAxisAsTime(self,value=False):
322 def setXAxisAsTime(self,value=False):
323 self.xaxisIsTime = value
323 self.xaxisIsTime = value
324
324
325 def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1):
325 def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1):
326
326
327 if xmin == None: xmin = x[0]
327 if xmin == None: xmin = x[0]
328 if xmax == None: xmax = x[-1]
328 if xmax == None: xmax = x[-1]
329 if ymin == None: ymin = y[0]
329 if ymin == None: ymin = y[0]
330 if ymax == None: ymax = y[-1]
330 if ymax == None: ymax = y[-1]
331
331
332 plplot.plcol0(colline)
332 plplot.plcol0(colline)
333 plplot.plline(x, y)
333 plplot.plline(x, y)
334 plplot.plcol0(1)
334 plplot.plcol0(1)
335
335
336 def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None):
336 def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None):
337
337
338 if xmin == None: xmin = x[0]
338 if xmin == None: xmin = x[0]
339 if xmax == None: xmax = x[-1]
339 if xmax == None: xmax = x[-1]
340 if ymin == None: ymin = y[0]
340 if ymin == None: ymin = y[0]
341 if ymax == None: ymax = y[-1]
341 if ymax == None: ymax = y[-1]
342
342
343 plplot.plline(x, y)
343 plplot.plline(x, y)
344
344
345 def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
345 def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
346 """
346 """
347 """
347 """
348 if xmin == None: xmin = x[0]
348 if xmin == None: xmin = x[0]
349 if xmax == None: xmax = x[-1]
349 if xmax == None: xmax = x[-1]
350 if ymin == None: ymin = y[0]
350 if ymin == None: ymin = y[0]
351 if ymax == None: ymax = y[-1]
351 if ymax == None: ymax = y[-1]
352 if zmin == None: zmin = numpy.nanmin(data)
352 if zmin == None: zmin = numpy.nanmin(data)
353 if zmax == None: zmax = numpy.nanmax(data)
353 if zmax == None: zmax = numpy.nanmax(data)
354
354
355 plplot.plimage(data,
355 plplot.plimage(data,
356 float(x[0]),
356 float(x[0]),
357 float(x[-1]),
357 float(x[-1]),
358 float(y[0]),
358 float(y[0]),
359 float(y[-1]),
359 float(y[-1]),
360 float(zmin),
360 float(zmin),
361 float(zmax),
361 float(zmax),
362 float(xmin),
362 float(xmin),
363 float(xmax),
363 float(xmax),
364 float(ymin),
364 float(ymin),
365 float(ymax)
365 float(ymax)
366 )
366 )
367
367
368 def __getBoxpltr(self, x, y, deltax=None, deltay=None):
368 def __getBoxpltr(self, x, y, deltax=None, deltay=None):
369
369
370 if not(len(x)>0 and len(y)>0):
370 if not(len(x)>0 and len(y)>0):
371 raise ValueError, "x axis and y axis are empty"
371 raise ValueError, "x axis and y axis are empty"
372
372
373 if deltax == None: deltax = x[-1] - x[-2]
373 if deltax == None: deltax = x[-1] - x[-2]
374 if deltay == None: deltay = y[-1] - y[-2]
374 if deltay == None: deltay = y[-1] - y[-2]
375
375
376 x1 = numpy.append(x, x[-1] + deltax)
376 x1 = numpy.append(x, x[-1] + deltax)
377 y1 = numpy.append(y, y[-1] + deltay)
377 y1 = numpy.append(y, y[-1] + deltay)
378
378
379 xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
379 xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
380 yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
380 yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
381
381
382 self.__xg = xg
382 self.__xg = xg
383 self.__yg = yg
383 self.__yg = yg
384
384
385 return xg, yg
385 return xg, yg
386
386
387
387
388 def advPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True):
388 def advPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True):
389 if getGrid:
389 if getGrid:
390 xg, yg = self.__getBoxpltr(x, y, deltax, deltay)
390 xg, yg = self.__getBoxpltr(x, y, deltax, deltay)
391 else:
391 else:
392 xg = self.__xg
392 xg = self.__xg
393 yg = self.__yg
393 yg = self.__yg
394
394
395 plplot.plimagefr(data,
395 plplot.plimagefr(data,
396 float(xmin),
396 float(xmin),
397 float(xmax),
397 float(xmax),
398 float(ymin),
398 float(ymin),
399 float(ymax),
399 float(ymax),
400 0.,
400 0.,
401 0.,
401 0.,
402 float(zmin),
402 float(zmin),
403 float(zmax),
403 float(zmax),
404 plplot.pltr2,
404 plplot.pltr2,
405 xg,
405 xg,
406 yg)
406 yg)
407
407
408
408
409 def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.):
409 def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.):
410 data = numpy.arange(256)
410 data = numpy.arange(256)
411 data = numpy.reshape(data, (1,-1))
411 data = numpy.reshape(data, (1,-1))
412
412
413 plplot.plimage(data,
413 plplot.plimage(data,
414 float(xmin),
414 float(xmin),
415 float(xmax),
415 float(xmax),
416 float(ymin),
416 float(ymin),
417 float(ymax),
417 float(ymax),
418 0.,
418 0.,
419 255.,
419 255.,
420 float(xmin),
420 float(xmin),
421 float(xmax),
421 float(xmax),
422 float(ymin),
422 float(ymin),
423 float(ymax))
423 float(ymax))
424
424
425 def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False):
425 def plotBox(self, xmin, xmax, ymin, ymax, xopt, yopt, nolabels=False):
426
426
427 plplot.plschr(0.0,self.__szchar-0.05)
427 plplot.plschr(0.0,self.__szchar-0.05)
428 plplot.pladv(self.__subplot)
428 plplot.pladv(self.__subplot)
429 plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1])
429 plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1])
430 plplot.plwind(float(xmin), # self.xrange[0]
430 plplot.plwind(float(xmin), # self.xrange[0]
431 float(xmax), # self.xrange[1]
431 float(xmax), # self.xrange[1]
432 float(ymin), # self.yrange[0]
432 float(ymin), # self.yrange[0]
433 float(ymax) # self.yrange[1]
433 float(ymax) # self.yrange[1]
434 )
434 )
435
435
436
436
437
437
438 if self.xaxisIsTime:
438 if self.xaxisIsTime:
439 plplot.pltimefmt("%H:%M")
439 plplot.pltimefmt("%H:%M")
440 timedelta = (xmax - xmin + 1)/8.
440 timedelta = (xmax - xmin + 1)/8.
441 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
441 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
442 else:
442 else:
443 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
443 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
444
444
445
445
446 if not(nolabels):
446 if not(nolabels):
447 plplot.pllab(self.xlabel, self.ylabel, self.title)
447 plplot.pllab(self.xlabel, self.ylabel, self.title)
448
448
449
449
450 def delLabels(self):
450 def delLabels(self):
451 self.setColor(15) #Setting Line Color to White
451 self.setColor(15) #Setting Line Color to White
452 plplot.pllab(self.xlabel, self.ylabel, self.title)
452 plplot.pllab(self.xlabel, self.ylabel, self.title)
453 self.setColor(1) #Setting Line Color to Black
453 self.setColor(1) #Setting Line Color to Black
454
454
455
455
456
456
457 def plotImage(self,x,y,z,xrange,yrange,zrange):
457 def plotImage(self,x,y,z,xrange,yrange,zrange):
458 xi = x[0]
458 xi = x[0]
459 xf = x[-1]
459 xf = x[-1]
460 yi = y[0]
460 yi = y[0]
461 yf = y[-1]
461 yf = y[-1]
462
462
463 plplot.plimage(z,
463 plplot.plimage(z,
464 float(xi),
464 float(xi),
465 float(xf),
465 float(xf),
466 float(yi),
466 float(yi),
467 float(yf),
467 float(yf),
468 float(zrange[0]),
468 float(zrange[0]),
469 float(zrange[1]),
469 float(zrange[1]),
470 float(xi),
470 float(xi),
471 float(xf),
471 float(xf),
472 float(yrange[0]),
472 float(yrange[0]),
473 yrange[1])
473 yrange[1])
474
474
475 class LinearPlot:
475 class LinearPlot:
476 linearObjDic = {}
476 linearObjDic = {}
477 __xpos = None
477 __xpos = None
478 __ypos = None
478 __ypos = None
479 def __init__(self,indexPlot,nsubplot,winTitle):
479 def __init__(self,indexPlot,nsubplot,winTitle):
480 self.width = 700
480 self.width = 700
481 self.height = 150
481 self.height = 150
482 ncol = 1
482 ncol = 1
483 nrow = nsubplot
483 nrow = nsubplot
484 initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height)
484 initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height)
485
485
486
486
487 def setFigure(self,indexPlot):
487 def setFigure(self,indexPlot):
488 setStrm(indexPlot)
488 setStrm(indexPlot)
489
489
490 def setPosition(self):
490 def setPosition(self):
491
491
492 xi = 0.07; xf = 0.9 #0.8,0.7,0.5
492 xi = 0.07; xf = 0.9 #0.8,0.7,0.5
493 yi = 0.15; yf = 0.8
493 yi = 0.15; yf = 0.8
494
494
495 xpos = [xi,xf]
495 xpos = [xi,xf]
496 ypos = [yi,yf]
496 ypos = [yi,yf]
497
497
498 self.__xpos = xpos
498 self.__xpos = xpos
499 self.__ypos = ypos
499 self.__ypos = ypos
500
500
501 return xpos,ypos
501 return xpos,ypos
502
502
503 def refresh(self):
503 def refresh(self):
504 plFlush()
504 plFlush()
505
505
506 def setup(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel):
506 def setup(self,subplot,xmin,xmax,ymin,ymax,title,xlabel,ylabel):
507 szchar = 1.10
507 szchar = 1.10
508 name = "linear"
508 name = "linear"
509 key = name + "%d"%subplot
509 key = name + "%d"%subplot
510 xrange = [xmin,xmax]
510 xrange = [xmin,xmax]
511 yrange = [ymin,ymax]
511 yrange = [ymin,ymax]
512
512
513 xpos,ypos = self.setPosition()
513 xpos,ypos = self.setPosition()
514 linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange)
514 linearObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange)
515 linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcnst", "bcnstv")
515 linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcnst", "bcnstv")
516 self.linearObjDic[key] = linearObj
516 self.linearObjDic[key] = linearObj
517
517
518 def plot(self,subplot,x,y,type="power"):
518 def plot(self,subplot,x,y,type="power"):
519 name = "linear"
519 name = "linear"
520 key = name + "%d"%subplot
520 key = name + "%d"%subplot
521
521
522 linearObj = self.linearObjDic[key]
522 linearObj = self.linearObjDic[key]
523 linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst")
523 linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst")
524
524
525 if linearObj.setXYData() != None:
525 if linearObj.setXYData() != None:
526 clearData(linearObj)
526 clearData(linearObj)
527
527
528 else:
528 else:
529 if type.lower() == 'power':
529 if type.lower() == 'power':
530 linearObj.setXYData(x,abs(y),"real")
530 linearObj.setXYData(x,abs(y),"real")
531 if type.lower() == 'iq':
531 if type.lower() == 'iq':
532 linearObj.setXYData(x,y,"complex")
532 linearObj.setXYData(x,y,"complex")
533
533
534 if type.lower() == 'power':
534 if type.lower() == 'power':
535 colline = 9
535 colline = 9
536 linearObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline)
536 linearObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline)
537 linearObj.setXYData(x,abs(y),"real")
537 linearObj.setXYData(x,abs(y),"real")
538
538
539 if type.lower() == 'iq':
539 if type.lower() == 'iq':
540 colline = 9
540 colline = 9
541 linearObj.basicLineTimePlot(x=x, y=y.real, colline=colline)
541 linearObj.basicLineTimePlot(x=x, y=y.real, colline=colline)
542 colline = 13
542 colline = 13
543 linearObj.basicLineTimePlot(x=x, y=y.imag, colline=colline)
543 linearObj.basicLineTimePlot(x=x, y=y.imag, colline=colline)
544
544
545 linearObj.setXYData(x,y,"complex")
545 linearObj.setXYData(x,y,"complex")
546
546
547 linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst")
547 linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bcst", "bcst")
548
548
549
549
550 # linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bc", "bc")
550 # linearObj.plotBox(linearObj.xrange[0], linearObj.xrange[1], linearObj.yrange[0], linearObj.yrange[1], "bc", "bc")
551 # linearObj.basicXYPlot(data,y)
551 # linearObj.basicXYPlot(data,y)
552 # linearObj.setXYData(data,y)
552 # linearObj.setXYData(data,y)
553
553
554
554
555
555
556 class SpectraPlot:
556 class SpectraPlot:
557 pcolorObjDic = {}
557 pcolorObjDic = {}
558 colorbarObjDic = {}
558 colorbarObjDic = {}
559 pwprofileObjDic = {}
559 pwprofileObjDic = {}
560 showColorbar = None
560 showColorbar = None
561 showPowerProfile = None
561 showPowerProfile = None
562 XAxisAsTime = None
562 XAxisAsTime = None
563 width = None
563 width = None
564 height = None
564 height = None
565 __spcxpos = None
565 __spcxpos = None
566 __spcypos = None
566 __spcypos = None
567 __cmapxpos = None
567 __cmapxpos = None
568 __cmapypos = None
568 __cmapypos = None
569 __profxpos = None
569 __profxpos = None
570 __profypos = None
570 __profypos = None
571 __lastTitle = None
571 __lastTitle = None
572
572
573 def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime):
573 def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime):
574 self.width = 460
574 self.width = 460
575 self.height = 300
575 self.height = 300
576 self.showColorbar = showColorbar
576 self.showColorbar = showColorbar
577 self.showPowerProfile = showPowerProfile
577 self.showPowerProfile = showPowerProfile
578 self.XAxisAsTime = XAxisAsTime
578 self.XAxisAsTime = XAxisAsTime
579
579
580 nrow = 2
580 nrow = 2
581 if (nsubplot%2)==0:
581 if (nsubplot%2)==0:
582 ncol = nsubplot/nrow
582 ncol = nsubplot/nrow
583 else:
583 else:
584 ncol = int(nsubplot)/nrow + 1
584 ncol = int(nsubplot)/nrow + 1
585
585
586 initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height)
586 initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height)
587 setColormap(colormap)
587 setColormap(colormap)
588 self.ncol = ncol
588 self.ncol = ncol
589 self.nrow = nrow
589 self.nrow = nrow
590
590
591 def setFigure(self,indexPlot):
591 def setFigure(self,indexPlot):
592 setStrm(indexPlot)
592 setStrm(indexPlot)
593
593
594 def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile
594 def setSpectraPos(self): #modificar valores de acuerdo al colorbar y pwprofile
595 if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075
595 if self.showPowerProfile: xi = 0.09; xf = 0.6 #0.075
596 else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5
596 else: xi = 0.15; xf = 0.8 #0.8,0.7,0.5
597 yi = 0.15; yf = 0.80
597 yi = 0.15; yf = 0.80
598
598
599 xpos = [xi,xf]
599 xpos = [xi,xf]
600 ypos = [yi,yf]
600 ypos = [yi,yf]
601
601
602 self.__spcxpos = xpos
602 self.__spcxpos = xpos
603 self.__spcypos = ypos
603 self.__spcypos = ypos
604
604
605 return xpos,ypos
605 return xpos,ypos
606
606
607 def setColorbarScreenPos(self):
607 def setColorbarScreenPos(self):
608
608
609 xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03
609 xi = self.__spcxpos[1] + 0.03; xf = xi + 0.03
610 yi = self.__spcypos[0]; yf = self.__spcypos[1]
610 yi = self.__spcypos[0]; yf = self.__spcypos[1]
611
611
612 xpos = [xi,xf]
612 xpos = [xi,xf]
613 ypos = [yi,yf]
613 ypos = [yi,yf]
614
614
615 self.__cmapxpos = xpos
615 self.__cmapxpos = xpos
616 self.__cmapypos = ypos
616 self.__cmapypos = ypos
617
617
618 return xpos,ypos
618 return xpos,ypos
619
619
620 def setPowerprofileScreenPos(self):
620 def setPowerprofileScreenPos(self):
621
621
622 xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25
622 xi = self.__cmapxpos[1] + 0.07; xf = xi + 0.25
623 yi = self.__spcypos[0]; yf = self.__spcypos[1]
623 yi = self.__spcypos[0]; yf = self.__spcypos[1]
624
624
625 xpos = [xi,xf]
625 xpos = [xi,xf]
626 ypos = [yi,yf]
626 ypos = [yi,yf]
627
627
628 self.__profxpos = [xi,xf]
628 self.__profxpos = [xi,xf]
629 self.__profypos = [yi,yf]
629 self.__profypos = [yi,yf]
630
630
631 return xpos,ypos
631 return xpos,ypos
632
632
633 def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel):
633 def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel):
634 # Config Spectra plot
634 # Config Spectra plot
635 szchar = 0.7
635 szchar = 0.7
636 name = "spc"
636 name = "spc"
637 key = name + "%d"%subplot
637 key = name + "%d"%subplot
638 xrange = [xmin,xmax]
638 xrange = [xmin,xmax]
639 yrange = [ymin,ymax]
639 yrange = [ymin,ymax]
640 zrange = [zmin,zmax]
640 zrange = [zmin,zmax]
641
641
642 xpos,ypos = self.setSpectraPos()
642 xpos,ypos = self.setSpectraPos()
643 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange)
643 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange)
644 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcnst", "bcnstv")
644 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcnst", "bcnstv")
645 self.pcolorObjDic[key] = pcolorObj
645 self.pcolorObjDic[key] = pcolorObj
646
646
647 # Config Colorbar
647 # Config Colorbar
648 if self.showColorbar:
648 if self.showColorbar:
649 szchar = 0.65
649 szchar = 0.65
650 name = "colorbar"
650 name = "colorbar"
651 key = name + "%d"%subplot
651 key = name + "%d"%subplot
652
652
653 xpos,ypos = self.setColorbarScreenPos()
653 xpos,ypos = self.setColorbarScreenPos()
654 xrange = [0.,1.]
654 xrange = [0.,1.]
655 yrange = [zmin,zmax]
655 yrange = [zmin,zmax]
656 cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange)
656 cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange)
657 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm")
657 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm")
658 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
658 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
659 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv")
659 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv")
660 self.colorbarObjDic[key] = cmapObj
660 self.colorbarObjDic[key] = cmapObj
661
661
662 # Config Power profile
662 # Config Power profile
663 if self.showPowerProfile:
663 if self.showPowerProfile:
664 szchar = 0.55
664 szchar = 0.55
665 name = "pwprofile"
665 name = "pwprofile"
666 key = name + "%d"%subplot
666 key = name + "%d"%subplot
667
667
668 xpos,ypos = self.setPowerprofileScreenPos()
668 xpos,ypos = self.setPowerprofileScreenPos()
669 xrange = [zmin,zmax]
669 xrange = [zmin,zmax]
670 yrange = [ymin,ymax]
670 yrange = [ymin,ymax]
671 powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange)
671 powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange)
672 powObj.setLineStyle(2)
672 powObj.setLineStyle(2)
673 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
673 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
674 powObj.setLineStyle(1)
674 powObj.setLineStyle(1)
675 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
675 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
676 self.pwprofileObjDic[key] = powObj
676 self.pwprofileObjDic[key] = powObj
677
677
678 def printTitle(self,pltitle):
678 def printTitle(self,pltitle):
679 if self.__lastTitle != None:
679 if self.__lastTitle != None:
680 setPlTitle(self.__lastTitle,"white")
680 setPlTitle(self.__lastTitle,"white")
681
681
682 self.__lastTitle = pltitle
682 self.__lastTitle = pltitle
683
683
684 setPlTitle(pltitle,"black")
684 setPlTitle(pltitle,"black")
685
685
686 setSubpages(self.ncol,self.nrow)
686 setSubpages(self.ncol,self.nrow)
687
687
688 def plot(self,subplot,x,y,z,subtitle):
688 def plot(self,subplot,x,y,z,subtitle):
689 # Spectra plot
689 # Spectra plot
690
690
691 name = "spc"
691 name = "spc"
692 key = name + "%d"%subplot
692 key = name + "%d"%subplot
693
693
694 # newx = [x[0],x[-1]]
694 # newx = [x[0],x[-1]]
695 pcolorObj = self.pcolorObjDic[key]
695 pcolorObj = self.pcolorObjDic[key]
696 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst")
696 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst")
697 pcolorObj.delLabels()
697 pcolorObj.delLabels()
698 pcolorObj.setLabels(title=subtitle)
698 pcolorObj.setLabels(title=subtitle)
699
699
700 deltax = None; deltay = None
700 deltax = None; deltay = None
701
701
702 pcolorObj.advPcolorPlot(z,
702 pcolorObj.advPcolorPlot(z,
703 x,
703 x,
704 y,
704 y,
705 xmin=pcolorObj.xrange[0],
705 xmin=pcolorObj.xrange[0],
706 xmax=pcolorObj.xrange[1],
706 xmax=pcolorObj.xrange[1],
707 ymin=pcolorObj.yrange[0],
707 ymin=pcolorObj.yrange[0],
708 ymax=pcolorObj.yrange[1],
708 ymax=pcolorObj.yrange[1],
709 zmin=pcolorObj.zrange[0],
709 zmin=pcolorObj.zrange[0],
710 zmax=pcolorObj.zrange[1],
710 zmax=pcolorObj.zrange[1],
711 deltax=deltax,
711 deltax=deltax,
712 deltay=deltay,
712 deltay=deltay,
713 getGrid=pcolorObj.getGrid)
713 getGrid=pcolorObj.getGrid)
714
714
715 pcolorObj.getGrid = False
715 pcolorObj.getGrid = False
716
716
717 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst")
717 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], "bcst", "bcst")
718
718
719 # Power Profile
719 # Power Profile
720 if self.showPowerProfile:
720 if self.showPowerProfile:
721 power = numpy.average(z, axis=0)
721 power = numpy.average(z, axis=0)
722 name = "pwprofile"
722 name = "pwprofile"
723 key = name + "%d"%subplot
723 key = name + "%d"%subplot
724 powObj = self.pwprofileObjDic[key]
724 powObj = self.pwprofileObjDic[key]
725
725
726 if powObj.setXYData() != None:
726 if powObj.setXYData() != None:
727 clearData(powObj)
727 clearData(powObj)
728 powObj.setLineStyle(2)
728 powObj.setLineStyle(2)
729 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
729 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
730 powObj.setLineStyle(1)
730 powObj.setLineStyle(1)
731 else:
731 else:
732 powObj.setXYData(power,y)
732 powObj.setXYData(power,y)
733
733
734 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
734 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
735 powObj.basicXYPlot(power,y)
735 powObj.basicXYPlot(power,y)
736 powObj.setXYData(power,y)
736 powObj.setXYData(power,y)
737
737
738 def savePlot(self,indexPlot,path):
738 def savePlot(self,indexPlot,path):
739
739
740 now = datetime.datetime.now().timetuple()
740 now = datetime.datetime.now().timetuple()
741 file = "spc_img%02d_%03d_%02d%02d%02d"%(indexPlot,now[7],now[3],now[4],now[5])
741 file = "spc_img%02d_%03d_%02d%02d%02d"%(indexPlot,now[7],now[3],now[4],now[5])
742 filename = os.path.join(path,file+".png")
742 filename = os.path.join(path,file+".png")
743 savePlplot(indexPlot,filename,self.ncol,self.nrow,self.width,self.height)
743 width = self.width*self.ncol
744 hei = self.height*self.nrow
745 savePlplot(filename,width,hei)
744
746
745
747
746
748
747 def refresh(self):
749 def refresh(self):
748 plFlush()
750 plFlush()
749
751
750 class RtiPlot:
752 class RtiPlot:
751
753
752 pcolorObjDic = {}
754 pcolorObjDic = {}
753 colorbarObjDic = {}
755 colorbarObjDic = {}
754 pwprofileObjDic = {}
756 pwprofileObjDic = {}
755 showColorbar = None
757 showColorbar = None
756 showPowerProfile = None
758 showPowerProfile = None
757 XAxisAsTime = None
759 XAxisAsTime = None
758 widht = None
760 widht = None
759 height = None
761 height = None
760 __rtixpos = None
762 __rtixpos = None
761 __rtiypos = None
763 __rtiypos = None
762 __cmapxpos = None
764 __cmapxpos = None
763 __cmapypos = None
765 __cmapypos = None
764 __profxpos = None
766 __profxpos = None
765 __profypos = None
767 __profypos = None
766
768
767 def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime):
769 def __init__(self,indexPlot,nsubplot,winTitle,colormap,showColorbar,showPowerProfile,XAxisAsTime):
768 self.width = 700
770 self.width = 700
769 self.height = 150
771 self.height = 150
770 self.showColorbar = showColorbar
772 self.showColorbar = showColorbar
771 self.showPowerProfile = showPowerProfile
773 self.showPowerProfile = showPowerProfile
772 self.XAxisAsTime = XAxisAsTime
774 self.XAxisAsTime = XAxisAsTime
773
775
774 ncol = 1
776 ncol = 1
775 nrow = nsubplot
777 nrow = nsubplot
776 initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height)
778 initPlplot(indexPlot,ncol,nrow,winTitle,self.width,self.height)
777 setColormap(colormap)
779 setColormap(colormap)
778
780
779 def setFigure(self,indexPlot):
781 def setFigure(self,indexPlot):
780 setStrm(indexPlot)
782 setStrm(indexPlot)
781
783
782 def setRtiScreenPos(self):
784 def setRtiScreenPos(self):
783
785
784 if self.showPowerProfile: xi = 0.07; xf = 0.65
786 if self.showPowerProfile: xi = 0.07; xf = 0.65
785 else: xi = 0.07; xf = 0.9
787 else: xi = 0.07; xf = 0.9
786 yi = 0.15; yf = 0.80
788 yi = 0.15; yf = 0.80
787
789
788 xpos = [xi,xf]
790 xpos = [xi,xf]
789 ypos = [yi,yf]
791 ypos = [yi,yf]
790
792
791 self.__rtixpos = xpos
793 self.__rtixpos = xpos
792 self.__rtiypos = ypos
794 self.__rtiypos = ypos
793
795
794 return xpos,ypos
796 return xpos,ypos
795
797
796 def setColorbarScreenPos(self):
798 def setColorbarScreenPos(self):
797
799
798 xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03
800 xi = self.__rtixpos[1] + 0.03; xf = xi + 0.03
799
801
800 yi = self.__rtiypos[0]; yf = self.__rtiypos[1]
802 yi = self.__rtiypos[0]; yf = self.__rtiypos[1]
801
803
802 xpos = [xi,xf]
804 xpos = [xi,xf]
803 ypos = [yi,yf]
805 ypos = [yi,yf]
804
806
805 self.__cmapxpos = xpos
807 self.__cmapxpos = xpos
806 self.__cmapypos = ypos
808 self.__cmapypos = ypos
807
809
808 return xpos,ypos
810 return xpos,ypos
809
811
810 def setPowerprofileScreenPos(self):
812 def setPowerprofileScreenPos(self):
811
813
812 xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20
814 xi = self.__cmapxpos[1] + 0.05; xf = xi + 0.20
813
815
814 yi = self.__rtiypos[0]; yf = self.__rtiypos[1]
816 yi = self.__rtiypos[0]; yf = self.__rtiypos[1]
815
817
816 xpos = [xi,xf]
818 xpos = [xi,xf]
817 ypos = [yi,yf]
819 ypos = [yi,yf]
818
820
819 self.__profxpos = [xi,xf]
821 self.__profxpos = [xi,xf]
820 self.__profypos = [yi,yf]
822 self.__profypos = [yi,yf]
821
823
822 return xpos,ypos
824 return xpos,ypos
823
825
824 def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone="lt",npoints=100):
826 def setup(self,subplot,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel,timedata,timezone="lt",npoints=100):
825 # Config Rti plot
827 # Config Rti plot
826 szchar = 1.10
828 szchar = 1.10
827 name = "rti"
829 name = "rti"
828 key = name + "%d"%subplot
830 key = name + "%d"%subplot
829
831
830 # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal]
832 # xmin, xmax --> minHour, max Hour : valores que definen el ejex x=[horaInicio,horaFinal]
831 thisDateTime = datetime.datetime.fromtimestamp(timedata)
833 thisDateTime = datetime.datetime.fromtimestamp(timedata)
832 startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0)
834 startDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmin,0,0)
833 endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59)
835 endDateTime = datetime.datetime(thisDateTime.year,thisDateTime.month,thisDateTime.day,xmax,59,59)
834 deltaTime = 0
836 deltaTime = 0
835 if timezone == "lt":
837 if timezone == "lt":
836 deltaTime = time.timezone
838 deltaTime = time.timezone
837 startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime
839 startTimeInSecs = time.mktime(startDateTime.timetuple()) - deltaTime
838 endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime
840 endTimeInSecs = time.mktime(endDateTime.timetuple()) - deltaTime
839
841
840 xrange = [startTimeInSecs,endTimeInSecs]
842 xrange = [startTimeInSecs,endTimeInSecs]
841 totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1.
843 totalTimeInXrange = endTimeInSecs - startTimeInSecs + 1.
842 deltax = totalTimeInXrange / npoints
844 deltax = totalTimeInXrange / npoints
843
845
844 yrange = [ymin,ymax]
846 yrange = [ymin,ymax]
845 zrange = [zmin,zmax]
847 zrange = [zmin,zmax]
846
848
847 xpos,ypos = self.setRtiScreenPos()
849 xpos,ypos = self.setRtiScreenPos()
848 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax)
850 pcolorObj = BaseGraph(name,subplot,xpos,ypos,xlabel,ylabel,title,szchar,xrange,yrange,zrange,deltax)
849 if self.XAxisAsTime:
851 if self.XAxisAsTime:
850 pcolorObj.setXAxisAsTime(self.XAxisAsTime)
852 pcolorObj.setXAxisAsTime(self.XAxisAsTime)
851 xopt = "bcnstd"
853 xopt = "bcnstd"
852 yopt = "bcnstv"
854 yopt = "bcnstv"
853 else:
855 else:
854 xopt = "bcnst"
856 xopt = "bcnst"
855 yopt = "bcnstv"
857 yopt = "bcnstv"
856
858
857 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt)
859 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt)
858 self.pcolorObjDic[key] = pcolorObj
860 self.pcolorObjDic[key] = pcolorObj
859
861
860
862
861 # Config Colorbar
863 # Config Colorbar
862 if self.showColorbar:
864 if self.showColorbar:
863 szchar = 0.9
865 szchar = 0.9
864 name = "colorbar"
866 name = "colorbar"
865 key = name + "%d"%subplot
867 key = name + "%d"%subplot
866
868
867 xpos,ypos = self.setColorbarScreenPos()
869 xpos,ypos = self.setColorbarScreenPos()
868 xrange = [0.,1.]
870 xrange = [0.,1.]
869 yrange = [zmin,zmax]
871 yrange = [zmin,zmax]
870 cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange)
872 cmapObj = BaseGraph(name,subplot,xpos,ypos,"","","dB",szchar,xrange,yrange)
871 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm")
873 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcm")
872 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
874 cmapObj.colorbarPlot(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1])
873 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv")
875 cmapObj.plotBox(cmapObj.xrange[0], cmapObj.xrange[1], cmapObj.yrange[0], cmapObj.yrange[1], "bc", "bcmtsv")
874 self.colorbarObjDic[key] = cmapObj
876 self.colorbarObjDic[key] = cmapObj
875
877
876
878
877 # Config Power profile
879 # Config Power profile
878 if self.showPowerProfile:
880 if self.showPowerProfile:
879 szchar = 0.8
881 szchar = 0.8
880 name = "pwprofile"
882 name = "pwprofile"
881 key = name + "%d"%subplot
883 key = name + "%d"%subplot
882
884
883 xpos,ypos = self.setPowerprofileScreenPos()
885 xpos,ypos = self.setPowerprofileScreenPos()
884 xrange = [zmin,zmax]
886 xrange = [zmin,zmax]
885 yrange = [ymin,ymax]
887 yrange = [ymin,ymax]
886 powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange)
888 powObj = BaseGraph(name,subplot,xpos,ypos,"dB","","Power Profile",szchar,xrange,yrange)
887 powObj.setLineStyle(2)
889 powObj.setLineStyle(2)
888 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
890 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
889 powObj.setLineStyle(1)
891 powObj.setLineStyle(1)
890 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
892 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
891 self.pwprofileObjDic[key] = powObj
893 self.pwprofileObjDic[key] = powObj
892
894
893
895
894 def plot(self,subplot,x,y,z):
896 def plot(self,subplot,x,y,z):
895 # RTI plot
897 # RTI plot
896 name = "rti"
898 name = "rti"
897 key = name + "%d"%subplot
899 key = name + "%d"%subplot
898
900
899 data = numpy.reshape(z, (1,-1))
901 data = numpy.reshape(z, (1,-1))
900 data = numpy.abs(data)
902 data = numpy.abs(data)
901 data = 10*numpy.log10(data)
903 data = 10*numpy.log10(data)
902 newx = [x,x+1]
904 newx = [x,x+1]
903
905
904 pcolorObj = self.pcolorObjDic[key]
906 pcolorObj = self.pcolorObjDic[key]
905
907
906 if pcolorObj.xaxisIsTime:
908 if pcolorObj.xaxisIsTime:
907 xopt = "bcstd"
909 xopt = "bcstd"
908 yopt = "bcst"
910 yopt = "bcst"
909 else:
911 else:
910 xopt = "bcst"
912 xopt = "bcst"
911 yopt = "bcst"
913 yopt = "bcst"
912
914
913 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt)
915 pcolorObj.plotBox(pcolorObj.xrange[0], pcolorObj.xrange[1], pcolorObj.yrange[0], pcolorObj.yrange[1], xopt, yopt)
914
916
915 deltax = pcolorObj.deltax
917 deltax = pcolorObj.deltax
916 deltay = None
918 deltay = None
917
919
918 if pcolorObj.xmin == None and pcolorObj.xmax == None:
920 if pcolorObj.xmin == None and pcolorObj.xmax == None:
919 pcolorObj.xmin = x
921 pcolorObj.xmin = x
920 pcolorObj.xmax = x
922 pcolorObj.xmax = x
921
923
922 if x >= pcolorObj.xmax:
924 if x >= pcolorObj.xmax:
923 xmin = x
925 xmin = x
924 xmax = x + deltax
926 xmax = x + deltax
925 x = [x]
927 x = [x]
926 pcolorObj.advPcolorPlot(data,
928 pcolorObj.advPcolorPlot(data,
927 x,
929 x,
928 y,
930 y,
929 xmin=xmin,
931 xmin=xmin,
930 xmax=xmax,
932 xmax=xmax,
931 ymin=pcolorObj.yrange[0],
933 ymin=pcolorObj.yrange[0],
932 ymax=pcolorObj.yrange[1],
934 ymax=pcolorObj.yrange[1],
933 zmin=pcolorObj.zrange[0],
935 zmin=pcolorObj.zrange[0],
934 zmax=pcolorObj.zrange[1],
936 zmax=pcolorObj.zrange[1],
935 deltax=deltax,
937 deltax=deltax,
936 deltay=deltay,
938 deltay=deltay,
937 getGrid=pcolorObj.getGrid)
939 getGrid=pcolorObj.getGrid)
938
940
939 pcolorObj.xmin = xmin
941 pcolorObj.xmin = xmin
940 pcolorObj.xmax = xmax
942 pcolorObj.xmax = xmax
941
943
942
944
943 # Power Profile
945 # Power Profile
944 if self.showPowerProfile:
946 if self.showPowerProfile:
945 data = numpy.reshape(data,(numpy.size(data)))
947 data = numpy.reshape(data,(numpy.size(data)))
946 name = "pwprofile"
948 name = "pwprofile"
947 key = name + "%d"%subplot
949 key = name + "%d"%subplot
948 powObj = self.pwprofileObjDic[key]
950 powObj = self.pwprofileObjDic[key]
949
951
950 if powObj.setXYData() != None:
952 if powObj.setXYData() != None:
951 clearData(powObj)
953 clearData(powObj)
952 powObj.setLineStyle(2)
954 powObj.setLineStyle(2)
953 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
955 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bcntg", "bc")
954 powObj.setLineStyle(1)
956 powObj.setLineStyle(1)
955 else:
957 else:
956 powObj.setXYData(data,y)
958 powObj.setXYData(data,y)
957
959
958 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
960 powObj.plotBox(powObj.xrange[0], powObj.xrange[1], powObj.yrange[0], powObj.yrange[1], "bc", "bc")
959 powObj.basicXYPlot(data,y)
961 powObj.basicXYPlot(data,y)
960 powObj.setXYData(data,y)
962 powObj.setXYData(data,y)
961
963
962 def refresh(self):
964 def refresh(self):
963 plFlush() No newline at end of file
965 plFlush()
@@ -1,213 +1,213
1 import numpy
1 import numpy
2 from Model.Spectra import Spectra
2 from Model.Spectra import Spectra
3
3
4 def hildebrand_sekhon(Data, navg):
4 def hildebrand_sekhon(Data, navg):
5 """
5 """
6 This method is for the objective determination of de noise level in Doppler spectra. This
6 This method is for the objective determination of de noise level in Doppler spectra. This
7 implementation technique is based on the fact that the standard deviation of the spectral
7 implementation technique is based on the fact that the standard deviation of the spectral
8 densities is equal to the mean spectral density for white Gaussian noise
8 densities is equal to the mean spectral density for white Gaussian noise
9
9
10 Inputs:
10 Inputs:
11 Data : heights
11 Data : heights
12 navg : numbers of averages
12 navg : numbers of averages
13
13
14 Return:
14 Return:
15 -1 : any error
15 -1 : any error
16 anoise : noise's level
16 anoise : noise's level
17 """
17 """
18
18
19 divisor = 8
19 divisor = 8
20 ratio = 7 / divisor
20 ratio = 7 / divisor
21 data = Data.reshape(-1)
21 data = Data.reshape(-1)
22 npts = data.size #numbers of points of the data
22 npts = data.size #numbers of points of the data
23
23
24 if npts < 32:
24 if npts < 32:
25 print "error in noise - requires at least 32 points"
25 print "error in noise - requires at least 32 points"
26 return -1.0
26 return -1.0
27
27
28 # data sorted in ascending order
28 # data sorted in ascending order
29 nmin = int(npts/divisor + ratio);
29 nmin = int(npts/divisor + ratio);
30 s = 0.0
30 s = 0.0
31 s2 = 0.0
31 s2 = 0.0
32 data2 = data[:npts]
32 data2 = data[:npts]
33 data2.sort()
33 data2.sort()
34
34
35 for i in range(nmin):
35 for i in range(nmin):
36 s += data2[i]
36 s += data2[i]
37 s2 += data2[i]**2;
37 s2 += data2[i]**2;
38
38
39 icount = nmin
39 icount = nmin
40 iflag = 0
40 iflag = 0
41
41
42 for i in range(nmin, npts):
42 for i in range(nmin, npts):
43 s += data2[i];
43 s += data2[i];
44 s2 += data2[i]**2
44 s2 += data2[i]**2
45 icount=icount+1;
45 icount=icount+1;
46 p = s / float(icount);
46 p = s / float(icount);
47 p2 = p**2;
47 p2 = p**2;
48 q = s2 / float(icount) - p2;
48 q = s2 / float(icount) - p2;
49 leftc = p2;
49 leftc = p2;
50 rightc = q * float(navg);
50 rightc = q * float(navg);
51
51
52 if leftc > rightc:
52 if leftc > rightc:
53 iflag = 1; #No weather signal
53 iflag = 1; #No weather signal
54 # Signal detect: R2 < 1 (R2 = leftc/rightc)
54 # Signal detect: R2 < 1 (R2 = leftc/rightc)
55 if(leftc < rightc):
55 if(leftc < rightc):
56 if iflag:
56 if iflag:
57 break
57 break
58
58
59 anoise = 0.0;
59 anoise = 0.0;
60 for j in range(i):
60 for j in range(i):
61 anoise += data2[j];
61 anoise += data2[j];
62
62
63 anoise = anoise / float(i);
63 anoise = anoise / float(i);
64
64
65 return anoise;
65 return anoise;
66
66
67 def sorting_bruce(Data, navg):
67 def sorting_bruce(Data, navg):
68 sortdata = numpy.sort(Data)
68 sortdata = numpy.sort(Data)
69 lenOfData = len(Data)
69 lenOfData = len(Data)
70 nums_min = lenOfData/10
70 nums_min = lenOfData/10
71
71
72 if (lenOfData/10) > 0:
72 if (lenOfData/10) > 0:
73 nums_min = lenOfData/10
73 nums_min = lenOfData/10
74 else:
74 else:
75 nums_min = 0
75 nums_min = 0
76
76
77 rtest = 1.0 + 1.0/navg
77 rtest = 1.0 + 1.0/navg
78
78
79 sum = 0.
79 sum = 0.
80
80
81 sumq = 0.
81 sumq = 0.
82
82
83 j = 0
83 j = 0
84
84
85 cont = 1
85 cont = 1
86
86
87 while((cont==1)and(j<lenOfData)):
87 while((cont==1)and(j<lenOfData)):
88
88
89 sum += sortdata[j]
89 sum += sortdata[j]
90
90
91 sumq += sortdata[j]**2
91 sumq += sortdata[j]**2
92
92
93 j += 1
93 j += 1
94
94
95 if j > nums_min:
95 if j > nums_min:
96 if ((sumq*j) <= (rtest*sum**2)):
96 if ((sumq*j) <= (rtest*sum**2)):
97 lnoise = sum / j
97 lnoise = sum / j
98 else:
98 else:
99 j = j - 1
99 j = j - 1
100 sum = sum - sordata[j]
100 sum = sum - sordata[j]
101 sumq = sumq - sordata[j]**2
101 sumq = sumq - sordata[j]**2
102 cont = 0
102 cont = 0
103
103
104 if j == nums_min:
104 if j == nums_min:
105 lnoise = sum /j
105 lnoise = sum /j
106
106
107 return lnoise
107 return lnoise
108
108
109 class Noise:
109 class Noise:
110 """
110 """
111 Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler
111 Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler
112 """
112 """
113 data = None
113 data = None
114 noise = None
114 noise = None
115 dim = None
115 dim = None
116
116
117 def __init__(self, data=None):
117 def __init__(self, data=None):
118 """
118 """
119 Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler.
119 Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler.
120
120
121 Inputs:
121 Inputs:
122 data: Numpy array de la forma nChan x nHeis x nProfiles
122 data: Numpy array de la forma nChan x nHeis x nProfiles
123
123
124 Affected:
124 Affected:
125 self.noise
125 self.noise
126
126
127 Return:
127 Return:
128 None
128 None
129 """
129 """
130
130
131 self.data = data
131 self.data = data
132 self.dim = None
132 self.dim = None
133 self.nChannels = None
133 self.nChannels = None
134 self.noise = None
134 self.noise = None
135
135
136 def setNoise(self, data):
136 def setNoise(self, data):
137 """
137 """
138 Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler.
138 Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler.
139
139
140 Inputs:
140 Inputs:
141 data: Numpy array de la forma nChan x nHeis x nProfiles
141 data: Numpy array de la forma nChan x nHeis x nProfiles
142
142
143 Affected:
143 Affected:
144 self.noise
144 self.noise
145
145
146 Return:
146 Return:
147 None
147 None
148 """
148 """
149
149
150 if data == None:
150 if data == None:
151 return 0
151 raise ValueError, "The data value is not defined"
152
152
153 shape = data.shape
153 shape = data.shape
154 self.dim = len(shape)
154 self.dim = len(shape)
155 if self.dim == 3:
155 if self.dim == 3:
156 nChan, nProfiles, nHeis = shape
156 nChan, nProfiles, nHeis = shape
157 elif self.dim == 2:
157 elif self.dim == 2:
158 nChan, nHeis = shape
158 nChan, nHeis = shape
159 else:
159 else:
160 raise ValueError, ""
160 raise ValueError, ""
161
161
162 self.nChannels = nChan
162 self.nChannels = nChan
163 self.data = data.copy()
163 self.data = data.copy()
164 self.noise = numpy.zeros(nChan)
164 self.noise = numpy.zeros(nChan)
165
165
166 return 1
166 return 1
167
167
168
168
169 def byHildebrand(self, navg=1):
169 def byHildebrand(self, navg=1):
170 """
170 """
171 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
171 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
172
172
173 Return:
173 Return:
174 noiselevel
174 noiselevel
175 """
175 """
176
176
177 daux = None
177 daux = None
178
178
179 for channel in range(self.nChannels):
179 for channel in range(self.nChannels):
180 daux = self.data[channel,:,:]
180 daux = self.data[channel,:,:]
181 self.noise[channel] = hildebrand_sekhon(daux, navg)
181 self.noise[channel] = hildebrand_sekhon(daux, navg)
182 return self.noise
182 return self.noise
183
183
184 def byWindow(self, heiIndexMin, heiIndexMax, freqIndexMin, freqIndexMax):
184 def byWindow(self, heiIndexMin, heiIndexMax, freqIndexMin, freqIndexMax):
185 """
185 """
186 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
186 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
187 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
187 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
188
188
189 Inputs:
189 Inputs:
190 heiIndexMin: Limite inferior del eje de alturas
190 heiIndexMin: Limite inferior del eje de alturas
191 heiIndexMax: Limite superior del eje de alturas
191 heiIndexMax: Limite superior del eje de alturas
192 freqIndexMin: Limite inferior del eje de frecuencia
192 freqIndexMin: Limite inferior del eje de frecuencia
193 freqIndexMax: Limite supoerior del eje de frecuencia
193 freqIndexMax: Limite supoerior del eje de frecuencia
194 """
194 """
195
195
196 data = self.data[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
196 data = self.data[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
197
197
198 for channel in range(self.nChannels):
198 for channel in range(self.nChannels):
199 daux = data[channel,:,:]
199 daux = data[channel,:,:]
200 self.noise[channel] = numpy.average(daux)
200 self.noise[channel] = numpy.average(daux)
201
201
202 return self.noise
202 return self.noise
203
203
204 def bySort(self,navg = 1):
204 def bySort(self,navg = 1):
205 daux = None
205 daux = None
206
206
207 for channel in range(self.nChannels):
207 for channel in range(self.nChannels):
208 daux = self.data[channel,:,:]
208 daux = self.data[channel,:,:]
209 self.noise[channel] = sorting_bruce(daux, navg)
209 self.noise[channel] = sorting_bruce(daux, navg)
210
210
211 return self.noise
211 return self.noise
212
212
213 No newline at end of file
213
@@ -1,689 +1,693
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7 import os, sys
7 import os, sys
8 import numpy
8 import numpy
9
9
10 path = os.path.split(os.getcwd())[0]
10 path = os.path.split(os.getcwd())[0]
11 sys.path.append(path)
11 sys.path.append(path)
12
12
13 from Model.Spectra import Spectra
13 from Model.Spectra import Spectra
14 from IO.SpectraIO import SpectraWriter
14 from IO.SpectraIO import SpectraWriter
15 from Graphics.SpectraPlot import Spectrum
15 from Graphics.SpectraPlot import Spectrum
16 from JRONoise import Noise
16 from JRONoise import Noise
17
17
18 class SpectraProcessor:
18 class SpectraProcessor:
19 '''
19 '''
20 classdocs
20 classdocs
21 '''
21 '''
22
22
23 dataInObj = None
23 dataInObj = None
24
24
25 dataOutObj = None
25 dataOutObj = None
26
26
27 noiseObj = None
27 noiseObj = None
28
28
29 integratorObjList = []
29 integratorObjList = []
30
30
31 decoderObjList = []
31 decoderObjList = []
32
32
33 writerObjList = []
33 writerObjList = []
34
34
35 plotterObjList = []
35 plotterObjList = []
36
36
37 integratorObjIndex = None
37 integratorObjIndex = None
38
38
39 decoderObjIndex = None
39 decoderObjIndex = None
40
40
41 writerObjIndex = None
41 writerObjIndex = None
42
42
43 plotterObjIndex = None
43 plotterObjIndex = None
44
44
45 buffer = None
45 buffer = None
46
46
47 profIndex = 0
47 profIndex = 0
48
48
49 nFFTPoints = None
49 nFFTPoints = None
50
50
51 nChannels = None
51 nChannels = None
52
52
53 nHeights = None
53 nHeights = None
54
54
55 nPairs = None
55 nPairs = None
56
56
57 pairList = None
57 pairList = None
58
58
59
59
60 def __init__(self):
60 def __init__(self):
61 '''
61 '''
62 Constructor
62 Constructor
63 '''
63 '''
64
64
65 self.integratorObjIndex = None
65 self.integratorObjIndex = None
66 self.decoderObjIndex = None
66 self.decoderObjIndex = None
67 self.writerObjIndex = None
67 self.writerObjIndex = None
68 self.plotterObjIndex = None
68 self.plotterObjIndex = None
69
69
70 self.integratorObjList = []
70 self.integratorObjList = []
71 self.decoderObjList = []
71 self.decoderObjList = []
72 self.writerObjList = []
72 self.writerObjList = []
73 self.plotterObjList = []
73 self.plotterObjList = []
74
74
75 self.noiseObj = Noise()
75 self.noiseObj = Noise()
76 self.buffer = None
76 self.buffer = None
77 self.profIndex = 0
77 self.profIndex = 0
78
78
79 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
79 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
80
80
81 if dataInObj == None:
81 if dataInObj == None:
82 raise ValueError, ""
82 raise ValueError, ""
83
83
84 if nFFTPoints == None:
84 if nFFTPoints == None:
85 raise ValueError, ""
85 raise ValueError, ""
86
86
87 self.dataInObj = dataInObj
87 self.dataInObj = dataInObj
88
88
89 if dataOutObj == None:
89 if dataOutObj == None:
90 dataOutObj = Spectra()
90 dataOutObj = Spectra()
91
91
92 self.dataOutObj = dataOutObj
92 self.dataOutObj = dataOutObj
93 self.noiseObj = Noise()
93 self.noiseObj = Noise()
94
94
95 ##########################################
95 ##########################################
96 self.nFFTPoints = nFFTPoints
96 self.nFFTPoints = nFFTPoints
97 self.nChannels = self.dataInObj.nChannels
97 self.nChannels = self.dataInObj.nChannels
98 self.nHeights = self.dataInObj.nHeights
98 self.nHeights = self.dataInObj.nHeights
99 self.pairList = pairList
99 self.pairList = pairList
100 if pairList != None:
100 if pairList != None:
101 self.nPairs = len(pairList)
101 self.nPairs = len(pairList)
102 else:
102 else:
103 self.nPairs = 0
103 self.nPairs = 0
104
104
105 self.dataOutObj.heightList = self.dataInObj.heightList
105 self.dataOutObj.heightList = self.dataInObj.heightList
106 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
106 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
107 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
107 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
108 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
108 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
109 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
109 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
110 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
110 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
111
111
112 self.dataOutObj.dataType = self.dataInObj.dataType
112 self.dataOutObj.dataType = self.dataInObj.dataType
113 self.dataOutObj.nPairs = self.nPairs
113 self.dataOutObj.nPairs = self.nPairs
114 self.dataOutObj.nChannels = self.nChannels
114 self.dataOutObj.nChannels = self.nChannels
115 self.dataOutObj.nProfiles = self.nFFTPoints
115 self.dataOutObj.nProfiles = self.nFFTPoints
116 self.dataOutObj.nHeights = self.nHeights
116 self.dataOutObj.nHeights = self.nHeights
117 self.dataOutObj.nFFTPoints = self.nFFTPoints
117 self.dataOutObj.nFFTPoints = self.nFFTPoints
118 #self.dataOutObj.data = None
118 #self.dataOutObj.data = None
119
119
120 self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
120 self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
121 self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
121 self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
122
122
123 self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
123 self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
124 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
124 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
125 self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
125 self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
126 self.dataOutObj.m_ProcessingHeader.shif_fft = True
126 self.dataOutObj.m_ProcessingHeader.shif_fft = True
127
127
128 spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
128 spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
129 k = 0
129 k = 0
130 for i in range( 0,self.nChannels*2,2 ):
130 for i in range( 0,self.nChannels*2,2 ):
131 spectraComb[i] = k
131 spectraComb[i] = k
132 spectraComb[i+1] = k
132 spectraComb[i+1] = k
133 k += 1
133 k += 1
134
134
135 k *= 2
135 k *= 2
136
136
137 if self.pairList != None:
137 if self.pairList != None:
138
138
139 for pair in self.pairList:
139 for pair in self.pairList:
140 spectraComb[k] = pair[0]
140 spectraComb[k] = pair[0]
141 spectraComb[k+1] = pair[1]
141 spectraComb[k+1] = pair[1]
142 k += 2
142 k += 2
143
143
144 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
144 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
145
145
146 return self.dataOutObj
146 return self.dataOutObj
147
147
148 def init(self):
148 def init(self):
149
149
150 self.integratorObjIndex = 0
150 self.integratorObjIndex = 0
151 self.decoderObjIndex = 0
151 self.decoderObjIndex = 0
152 self.writerObjIndex = 0
152 self.writerObjIndex = 0
153 self.plotterObjIndex = 0
153 self.plotterObjIndex = 0
154
154
155 if self.dataInObj.type == "Voltage":
155 if self.dataInObj.type == "Voltage":
156
156
157 if self.buffer == None:
157 if self.buffer == None:
158 self.buffer = numpy.zeros((self.nChannels,
158 self.buffer = numpy.zeros((self.nChannels,
159 self.nFFTPoints,
159 self.nFFTPoints,
160 self.nHeights),
160 self.nHeights),
161 dtype='complex')
161 dtype='complex')
162
162
163 self.buffer[:,self.profIndex,:] = self.dataInObj.data
163 self.buffer[:,self.profIndex,:] = self.dataInObj.data
164 self.profIndex += 1
164 self.profIndex += 1
165
165
166 if self.profIndex == self.nFFTPoints:
166 if self.profIndex == self.nFFTPoints:
167 self.__getFft()
167 self.__getFft()
168 self.dataOutObj.flagNoData = False
168 self.dataOutObj.flagNoData = False
169
169
170 self.buffer = None
170 self.buffer = None
171 self.profIndex = 0
171 self.profIndex = 0
172 return
172 return
173
173
174 self.dataOutObj.flagNoData = True
174 self.dataOutObj.flagNoData = True
175
175
176 return
176 return
177
177
178 #Other kind of data
178 #Other kind of data
179 if self.dataInObj.type == "Spectra":
179 if self.dataInObj.type == "Spectra":
180 self.dataOutObj.copy(self.dataInObj)
180 self.dataOutObj.copy(self.dataInObj)
181 self.dataOutObj.flagNoData = False
181 self.dataOutObj.flagNoData = False
182 return
182 return
183
183
184 raise ValueError, "The datatype is not valid"
184 raise ValueError, "The datatype is not valid"
185
185
186 def __getFft(self):
186 def __getFft(self):
187 """
187 """
188 Convierte valores de Voltaje a Spectra
188 Convierte valores de Voltaje a Spectra
189
189
190 Affected:
190 Affected:
191 self.dataOutObj.data_spc
191 self.dataOutObj.data_spc
192 self.dataOutObj.data_cspc
192 self.dataOutObj.data_cspc
193 self.dataOutObj.data_dc
193 self.dataOutObj.data_dc
194 self.dataOutObj.heightList
194 self.dataOutObj.heightList
195 self.dataOutObj.m_BasicHeader
195 self.dataOutObj.m_BasicHeader
196 self.dataOutObj.m_ProcessingHeader
196 self.dataOutObj.m_ProcessingHeader
197 self.dataOutObj.m_RadarControllerHeader
197 self.dataOutObj.m_RadarControllerHeader
198 self.dataOutObj.m_SystemHeader
198 self.dataOutObj.m_SystemHeader
199 self.profIndex
199 self.profIndex
200 self.buffer
200 self.buffer
201 self.dataOutObj.flagNoData
201 self.dataOutObj.flagNoData
202 self.dataOutObj.dataType
202 self.dataOutObj.dataType
203 self.dataOutObj.nPairs
203 self.dataOutObj.nPairs
204 self.dataOutObj.nChannels
204 self.dataOutObj.nChannels
205 self.dataOutObj.nProfiles
205 self.dataOutObj.nProfiles
206 self.dataOutObj.m_SystemHeader.numChannels
206 self.dataOutObj.m_SystemHeader.numChannels
207 self.dataOutObj.m_ProcessingHeader.totalSpectra
207 self.dataOutObj.m_ProcessingHeader.totalSpectra
208 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
208 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
209 self.dataOutObj.m_ProcessingHeader.numHeights
209 self.dataOutObj.m_ProcessingHeader.numHeights
210 self.dataOutObj.m_ProcessingHeader.spectraComb
210 self.dataOutObj.m_ProcessingHeader.spectraComb
211 self.dataOutObj.m_ProcessingHeader.shif_fft
211 self.dataOutObj.m_ProcessingHeader.shif_fft
212 """
212 """
213 if self.dataInObj.flagNoData:
213 if self.dataInObj.flagNoData:
214 return 0
214 return 0
215
215
216 fft_volt = numpy.fft.fft(self.buffer,axis=1)
216 fft_volt = numpy.fft.fft(self.buffer,axis=1)
217 dc = fft_volt[:,0,:]
217 dc = fft_volt[:,0,:]
218
218
219 #calculo de self-spectra
219 #calculo de self-spectra
220 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
220 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
221 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
221 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
222
222
223 blocksize = 0
223 blocksize = 0
224 blocksize += dc.size
224 blocksize += dc.size
225 blocksize += spc.size
225 blocksize += spc.size
226
226
227 cspc = None
227 cspc = None
228 pairIndex = 0
228 pairIndex = 0
229 if self.pairList != None:
229 if self.pairList != None:
230 #calculo de cross-spectra
230 #calculo de cross-spectra
231 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
231 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
232 for pair in self.pairList:
232 for pair in self.pairList:
233 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
233 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
234 pairIndex += 1
234 pairIndex += 1
235 blocksize += cspc.size
235 blocksize += cspc.size
236
236
237 self.dataOutObj.data_spc = spc
237 self.dataOutObj.data_spc = spc
238 self.dataOutObj.data_cspc = cspc
238 self.dataOutObj.data_cspc = cspc
239 self.dataOutObj.data_dc = dc
239 self.dataOutObj.data_dc = dc
240 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
240 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
241 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
241 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
242
242
243 self.getNoise()
243
244
244 def addWriter(self,wrpath):
245 def addWriter(self,wrpath):
245 objWriter = SpectraWriter(self.dataOutObj)
246 objWriter = SpectraWriter(self.dataOutObj)
246 objWriter.setup(wrpath)
247 objWriter.setup(wrpath)
247 self.writerObjList.append(objWriter)
248 self.writerObjList.append(objWriter)
248
249
249 def addPlotter(self,index=None):
250 def addPlotter(self,index=None):
250 if index==None:
251 if index==None:
251 index = self.plotterObjIndex
252 index = self.plotterObjIndex
252
253
253 plotObj = Spectrum(self.dataOutObj, index)
254 plotObj = Spectrum(self.dataOutObj, index)
254 self.plotterObjList.append(plotObj)
255 self.plotterObjList.append(plotObj)
255
256
256 def addIntegrator(self,N,timeInterval):
257 def addIntegrator(self,N,timeInterval):
257
258
258 objIncohInt = IncoherentIntegration(N,timeInterval)
259 objIncohInt = IncoherentIntegration(N,timeInterval)
259 self.integratorObjList.append(objIncohInt)
260 self.integratorObjList.append(objIncohInt)
260
261
261 def writeData(self, wrpath):
262 def writeData(self, wrpath):
262 if self.dataOutObj.flagNoData:
263 if self.dataOutObj.flagNoData:
263 return 0
264 return 0
264
265
265 if len(self.writerObjList) <= self.writerObjIndex:
266 if len(self.writerObjList) <= self.writerObjIndex:
266 self.addWriter(wrpath)
267 self.addWriter(wrpath)
267
268
268 self.writerObjList[self.writerObjIndex].putData()
269 self.writerObjList[self.writerObjIndex].putData()
269
270
270 self.writerObjIndex += 1
271 self.writerObjIndex += 1
271
272
272 def plotData(self,
273 def plotData(self,
273 xmin=None,
274 xmin=None,
274 xmax=None,
275 xmax=None,
275 ymin=None,
276 ymin=None,
276 ymax=None,
277 ymax=None,
277 zmin=None,
278 zmin=None,
278 zmax=None,
279 zmax=None,
279 titleList=None,
280 titleList=None,
280 xlabelList=None,
281 xlabelList=None,
281 ylabelList=None,
282 ylabelList=None,
282 winTitle='',
283 winTitle='',
283 colormap="br_green",
284 colormap="br_green",
284 showColorbar=False,
285 showColorbar=False,
285 showPowerProfile=False,
286 showPowerProfile=False,
286 XAxisAsTime=False,
287 XAxisAsTime=False,
287 save=False,
288 save=False,
288 index=None):
289 index=None):
289
290
290 if self.dataOutObj.flagNoData:
291 if self.dataOutObj.flagNoData:
291 return 0
292 return 0
292
293
293 if len(self.plotterObjList) <= self.plotterObjIndex:
294 if len(self.plotterObjList) <= self.plotterObjIndex:
294 self.addPlotter(index)
295 self.addPlotter(index)
295
296
296 self.plotterObjList[self.plotterObjIndex].plotData(xmin,
297 self.plotterObjList[self.plotterObjIndex].plotData(xmin,
297 xmax,
298 xmax,
298 ymin,
299 ymin,
299 ymax,
300 ymax,
300 zmin,
301 zmin,
301 zmax,
302 zmax,
302 titleList,
303 titleList,
303 xlabelList,
304 xlabelList,
304 ylabelList,
305 ylabelList,
305 winTitle,
306 winTitle,
306 colormap,
307 colormap,
307 showColorbar,
308 showColorbar,
308 showPowerProfile,
309 showPowerProfile,
309 XAxisAsTime,
310 XAxisAsTime,
310 save)
311 save)
311
312
312 self.plotterObjIndex += 1
313 self.plotterObjIndex += 1
313
314
314 def integrator(self, N=None, timeInterval=None):
315 def integrator(self, N=None, timeInterval=None):
315
316
316 if self.dataOutObj.flagNoData:
317 if self.dataOutObj.flagNoData:
317 return 0
318 return 0
318
319
319 if len(self.integratorObjList) <= self.integratorObjIndex:
320 if len(self.integratorObjList) <= self.integratorObjIndex:
320 self.addIntegrator(N,timeInterval)
321 self.addIntegrator(N,timeInterval)
321
322
322 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
323 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
323 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
324 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
324
325
325 if myIncohIntObj.isReady:
326 if myIncohIntObj.isReady:
326 self.dataOutObj.data_spc = myIncohIntObj.data
327 self.dataOutObj.data_spc = myIncohIntObj.data
327 self.dataOutObj.nAvg = myIncohIntObj.navg
328 self.dataOutObj.nAvg = myIncohIntObj.navg
328 self.dataOutObj.m_ProcessingHeader.incoherentInt *= myIncohIntObj.navg
329 self.dataOutObj.m_ProcessingHeader.incoherentInt *= myIncohIntObj.navg
329 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
330 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
330 self.dataOutObj.flagNoData = False
331 self.dataOutObj.flagNoData = False
331
332
332 self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
333 self.getNoise(type="hildebrand")
333 # self.getNoise(type="sort", parm=16)
334 # self.getNoise(type="sort", parm=16)
334
335
335 else:
336 else:
336 self.dataOutObj.flagNoData = True
337 self.dataOutObj.flagNoData = True
337
338
338 self.integratorObjIndex += 1
339 self.integratorObjIndex += 1
339
340
340 """Calcular el ruido"""
341 """Calcular el ruido"""
341 # self.getNoise(type="hildebrand", parm=1)
342 # self.getNoise(type="hildebrand", parm=1)
342
343
343 def removeDC(self, type):
344 def removeDC(self, type):
344
345
345 if self.dataOutObj.flagNoData:
346 if self.dataOutObj.flagNoData:
346 return 0
347 return 0
347
348
348 def removeInterference(self):
349 def removeInterference(self):
349
350
350 if self.dataOutObj.flagNoData:
351 if self.dataOutObj.flagNoData:
351 return 0
352 return 0
352
353
353 def removeSatellites(self):
354 def removeSatellites(self):
354
355
355 if self.dataOutObj.flagNoData:
356 if self.dataOutObj.flagNoData:
356 return 0
357 return 0
357
358
358 def getNoise(self, type="hildebrand", parm=None):
359 def getNoise(self, type="hildebrand", parm=None):
359
360
361 if parm == None:
362 parm =self.dataOutObj.m_ProcessingHeader.incoherentInt
363
360 self.noiseObj.setNoise(self.dataOutObj.data_spc)
364 self.noiseObj.setNoise(self.dataOutObj.data_spc)
361
365
362 if type == "hildebrand":
366 if type == "hildebrand":
363 noise = self.noiseObj.byHildebrand(parm)
367 noise = self.noiseObj.byHildebrand(parm)
364
368
365 if type == "window":
369 if type == "window":
366 noise = self.noiseObj.byWindow(parm)
370 noise = self.noiseObj.byWindow(parm)
367
371
368 if type == "sort":
372 if type == "sort":
369 noise = self.noiseObj.bySort(parm)
373 noise = self.noiseObj.bySort(parm)
370
374
371 self.dataOutObj.noise = noise
375 self.dataOutObj.noise = noise
372 # print 10*numpy.log10(noise)
376 # print 10*numpy.log10(noise)
373
377
374 def selectChannels(self, channelList, pairList=[]):
378 def selectChannels(self, channelList, pairList=[]):
375
379
376 channelIndexList = []
380 channelIndexList = []
377
381
378 for channel in channelList:
382 for channel in channelList:
379 if channel in self.dataOutObj.channelList:
383 if channel in self.dataOutObj.channelList:
380 index = self.dataOutObj.channelList.index(channel)
384 index = self.dataOutObj.channelList.index(channel)
381 channelIndexList.append(index)
385 channelIndexList.append(index)
382
386
383 pairIndexList = []
387 pairIndexList = []
384
388
385 for pair in pairList:
389 for pair in pairList:
386 if pair in self.dataOutObj.pairList:
390 if pair in self.dataOutObj.pairList:
387 index = self.dataOutObj.pairList.index(pair)
391 index = self.dataOutObj.pairList.index(pair)
388 pairIndexList.append(index)
392 pairIndexList.append(index)
389
393
390 self.selectChannelsByIndex(channelIndexList, pairIndexList)
394 self.selectChannelsByIndex(channelIndexList, pairIndexList)
391
395
392 def selectChannelsByIndex(self, channelIndexList, pairIndexList=[]):
396 def selectChannelsByIndex(self, channelIndexList, pairIndexList=[]):
393 """
397 """
394 Selecciona un bloque de datos en base a canales y pares segun el
398 Selecciona un bloque de datos en base a canales y pares segun el
395 channelIndexList y el pairIndexList
399 channelIndexList y el pairIndexList
396
400
397 Input:
401 Input:
398 channelIndexList : lista de indices de los canales a seleccionar por ej.
402 channelIndexList : lista de indices de los canales a seleccionar por ej.
399
403
400 Si tenemos los canales
404 Si tenemos los canales
401
405
402 self.channelList = (2,3,5,7)
406 self.channelList = (2,3,5,7)
403
407
404 y deseamos escoger los canales (3,7)
408 y deseamos escoger los canales (3,7)
405 entonces colocaremos el parametro
409 entonces colocaremos el parametro
406
410
407 channelndexList = (1,3)
411 channelndexList = (1,3)
408
412
409 pairIndexList : tupla de indice depares que se desea selecionar por ej.
413 pairIndexList : tupla de indice depares que se desea selecionar por ej.
410
414
411 Si tenemos los pares :
415 Si tenemos los pares :
412
416
413 ( (0,1), (0,2), (1,3), (2,5) )
417 ( (0,1), (0,2), (1,3), (2,5) )
414
418
415 y deseamos seleccionar los pares ((0,2), (2,5))
419 y deseamos seleccionar los pares ((0,2), (2,5))
416 entonces colocaremos el parametro
420 entonces colocaremos el parametro
417
421
418 pairIndexList = (1,3)
422 pairIndexList = (1,3)
419
423
420 Affected:
424 Affected:
421 self.dataOutObj.data_spc
425 self.dataOutObj.data_spc
422 self.dataOutObj.data_cspc
426 self.dataOutObj.data_cspc
423 self.dataOutObj.data_dc
427 self.dataOutObj.data_dc
424 self.dataOutObj.nChannels
428 self.dataOutObj.nChannels
425 self.dataOutObj.nPairs
429 self.dataOutObj.nPairs
426 self.dataOutObj.m_ProcessingHeader.spectraComb
430 self.dataOutObj.m_ProcessingHeader.spectraComb
427 self.dataOutObj.m_SystemHeader.numChannels
431 self.dataOutObj.m_SystemHeader.numChannels
428
432
429 self.dataOutObj.noise
433 self.dataOutObj.noise
430 Return:
434 Return:
431 None
435 None
432 """
436 """
433
437
434 if self.dataOutObj.flagNoData:
438 if self.dataOutObj.flagNoData:
435 return 0
439 return 0
436
440
437 if pairIndexList == []:
441 if pairIndexList == []:
438 pairIndexList = numpy.arange(len(self.dataOutObj.pairList))
442 pairIndexList = numpy.arange(len(self.dataOutObj.pairList))
439
443
440 nChannels = len(channelIndexList)
444 nChannels = len(channelIndexList)
441 nPairs = len(pairIndexList)
445 nPairs = len(pairIndexList)
442
446
443 blocksize = 0
447 blocksize = 0
444 #self spectra
448 #self spectra
445 spc = self.dataOutObj.data_spc[channelIndexList,:,:]
449 spc = self.dataOutObj.data_spc[channelIndexList,:,:]
446 blocksize += spc.size
450 blocksize += spc.size
447
451
448 cspc = None
452 cspc = None
449 if pairIndexList != []:
453 if pairIndexList != []:
450 cspc = self.dataOutObj.data_cspc[pairIndexList,:,:]
454 cspc = self.dataOutObj.data_cspc[pairIndexList,:,:]
451 blocksize += cspc.size
455 blocksize += cspc.size
452
456
453 #DC channel
457 #DC channel
454 dc = None
458 dc = None
455 if self.dataOutObj.m_ProcessingHeader.flag_dc:
459 if self.dataOutObj.m_ProcessingHeader.flag_dc:
456 dc = self.dataOutObj.data_dc[channelIndexList,:]
460 dc = self.dataOutObj.data_dc[channelIndexList,:]
457 blocksize += dc.size
461 blocksize += dc.size
458
462
459 #Almacenar las combinaciones de canales y cros espectros
463 #Almacenar las combinaciones de canales y cros espectros
460
464
461 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
465 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
462 i = 0
466 i = 0
463 for spcChannel in channelIndexList:
467 for spcChannel in channelIndexList:
464 spectraComb[i] = spcChannel
468 spectraComb[i] = spcChannel
465 spectraComb[i+1] = spcChannel
469 spectraComb[i+1] = spcChannel
466 i += 2
470 i += 2
467
471
468 if pairList != None:
472 if pairList != None:
469 for pair in pairList:
473 for pair in pairList:
470 spectraComb[i] = pair[0]
474 spectraComb[i] = pair[0]
471 spectraComb[i+1] = pair[1]
475 spectraComb[i+1] = pair[1]
472 i += 2
476 i += 2
473
477
474 #######
478 #######
475
479
476 self.dataOutObj.data_spc = spc
480 self.dataOutObj.data_spc = spc
477 self.dataOutObj.data_cspc = cspc
481 self.dataOutObj.data_cspc = cspc
478 self.dataOutObj.data_dc = dc
482 self.dataOutObj.data_dc = dc
479 self.dataOutObj.nChannels = nChannels
483 self.dataOutObj.nChannels = nChannels
480 self.dataOutObj.nPairs = nPairs
484 self.dataOutObj.nPairs = nPairs
481
485
482 self.dataOutObj.channelIndexList = channelIndexList
486 self.dataOutObj.channelIndexList = channelIndexList
483
487
484 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
488 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
485 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
489 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
486 self.dataOutObj.m_SystemHeader.numChannels = nChannels
490 self.dataOutObj.m_SystemHeader.numChannels = nChannels
487 self.dataOutObj.nChannels = nChannels
491 self.dataOutObj.nChannels = nChannels
488 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
492 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
489
493
490 if cspc == None:
494 if cspc == None:
491 self.dataOutObj.m_ProcessingHeader.flag_dc = False
495 self.dataOutObj.m_ProcessingHeader.flag_dc = False
492 if dc == None:
496 if dc == None:
493 self.dataOutObj.m_ProcessingHeader.flag_cpsc = False
497 self.dataOutObj.m_ProcessingHeader.flag_cpsc = False
494
498
495 def selectHeightsByValue(self, minHei, maxHei):
499 def selectHeightsByValue(self, minHei, maxHei):
496 """
500 """
497 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
501 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
498 minHei <= height <= maxHei
502 minHei <= height <= maxHei
499
503
500 Input:
504 Input:
501 minHei : valor minimo de altura a considerar
505 minHei : valor minimo de altura a considerar
502 maxHei : valor maximo de altura a considerar
506 maxHei : valor maximo de altura a considerar
503
507
504 Affected:
508 Affected:
505 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
509 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
506
510
507 Return:
511 Return:
508 None
512 None
509 """
513 """
510
514
511 if self.dataOutObj.flagNoData:
515 if self.dataOutObj.flagNoData:
512 return 0
516 return 0
513
517
514 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
518 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
515 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
519 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
516
520
517 if (maxHei > self.dataOutObj.heightList[-1]):
521 if (maxHei > self.dataOutObj.heightList[-1]):
518 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
522 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
519
523
520 minIndex = 0
524 minIndex = 0
521 maxIndex = 0
525 maxIndex = 0
522 data = self.dataOutObj.heightList
526 data = self.dataOutObj.heightList
523
527
524 for i,val in enumerate(data):
528 for i,val in enumerate(data):
525 if val < minHei:
529 if val < minHei:
526 continue
530 continue
527 else:
531 else:
528 minIndex = i;
532 minIndex = i;
529 break
533 break
530
534
531 for i,val in enumerate(data):
535 for i,val in enumerate(data):
532 if val <= maxHei:
536 if val <= maxHei:
533 maxIndex = i;
537 maxIndex = i;
534 else:
538 else:
535 break
539 break
536
540
537 self.selectHeightsByIndex(minIndex, maxIndex)
541 self.selectHeightsByIndex(minIndex, maxIndex)
538
542
539 def selectHeightsByIndex(self, minIndex, maxIndex):
543 def selectHeightsByIndex(self, minIndex, maxIndex):
540 """
544 """
541 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
545 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
542 minIndex <= index <= maxIndex
546 minIndex <= index <= maxIndex
543
547
544 Input:
548 Input:
545 minIndex : valor minimo de altura a considerar
549 minIndex : valor minimo de altura a considerar
546 maxIndex : valor maximo de altura a considerar
550 maxIndex : valor maximo de altura a considerar
547
551
548 Affected:
552 Affected:
549 self.dataOutObj.data_spc
553 self.dataOutObj.data_spc
550 self.dataOutObj.data_cspc
554 self.dataOutObj.data_cspc
551 self.dataOutObj.data_dc
555 self.dataOutObj.data_dc
552 self.dataOutObj.heightList
556 self.dataOutObj.heightList
553 self.dataOutObj.nHeights
557 self.dataOutObj.nHeights
554 self.dataOutObj.m_ProcessingHeader.numHeights
558 self.dataOutObj.m_ProcessingHeader.numHeights
555 self.dataOutObj.m_ProcessingHeader.blockSize
559 self.dataOutObj.m_ProcessingHeader.blockSize
556 self.dataOutObj.m_ProcessingHeader.firstHeight
560 self.dataOutObj.m_ProcessingHeader.firstHeight
557 self.dataOutObj.m_RadarControllerHeader.numHeights
561 self.dataOutObj.m_RadarControllerHeader.numHeights
558
562
559 Return:
563 Return:
560 None
564 None
561 """
565 """
562
566
563 if self.dataOutObj.flagNoData:
567 if self.dataOutObj.flagNoData:
564 return 0
568 return 0
565
569
566 if (minIndex < 0) or (minIndex > maxIndex):
570 if (minIndex < 0) or (minIndex > maxIndex):
567 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
571 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
568
572
569 if (maxIndex >= self.dataOutObj.nHeights):
573 if (maxIndex >= self.dataOutObj.nHeights):
570 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
574 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
571
575
572 nChannels = self.dataOutObj.nChannels
576 nChannels = self.dataOutObj.nChannels
573 nPairs = self.dataOutObj.nPairs
577 nPairs = self.dataOutObj.nPairs
574 nProfiles = self.dataOutObj.nProfiles
578 nProfiles = self.dataOutObj.nProfiles
575 dataType = self.dataOutObj.dataType
579 dataType = self.dataOutObj.dataType
576 nHeights = maxIndex - minIndex + 1
580 nHeights = maxIndex - minIndex + 1
577 blockSize = 0
581 blockSize = 0
578
582
579 #self spectra
583 #self spectra
580 spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1]
584 spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1]
581 blockSize += spc.size
585 blockSize += spc.size
582
586
583 #cross spectra
587 #cross spectra
584 cspc = None
588 cspc = None
585 if self.dataOutObj.data_cspc != None:
589 if self.dataOutObj.data_cspc != None:
586 cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1]
590 cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1]
587 blockSize += cspc.size
591 blockSize += cspc.size
588
592
589 #DC channel
593 #DC channel
590 dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1]
594 dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1]
591 blockSize += dc.size
595 blockSize += dc.size
592
596
593 self.dataOutObj.data_spc = spc
597 self.dataOutObj.data_spc = spc
594 if cspc != None:
598 if cspc != None:
595 self.dataOutObj.data_cspc = cspc
599 self.dataOutObj.data_cspc = cspc
596 self.dataOutObj.data_dc = dc
600 self.dataOutObj.data_dc = dc
597
601
598 firstHeight = self.dataOutObj.heightList[minIndex]
602 firstHeight = self.dataOutObj.heightList[minIndex]
599
603
600 self.dataOutObj.nHeights = nHeights
604 self.dataOutObj.nHeights = nHeights
601 self.dataOutObj.m_ProcessingHeader.blockSize = blockSize
605 self.dataOutObj.m_ProcessingHeader.blockSize = blockSize
602 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
606 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
603 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
607 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
604 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
608 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
605
609
606 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
610 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
607
611
608
612
609 class IncoherentIntegration:
613 class IncoherentIntegration:
610
614
611 integ_counter = None
615 integ_counter = None
612 data = None
616 data = None
613 navg = None
617 navg = None
614 buffer = None
618 buffer = None
615 nIncohInt = None
619 nIncohInt = None
616
620
617 def __init__(self, N = None, timeInterval = None):
621 def __init__(self, N = None, timeInterval = None):
618 """
622 """
619 N
623 N
620 timeInterval - interval time [min], integer value
624 timeInterval - interval time [min], integer value
621 """
625 """
622
626
623 self.data = None
627 self.data = None
624 self.navg = None
628 self.navg = None
625 self.buffer = None
629 self.buffer = None
626 self.timeOut = None
630 self.timeOut = None
627 self.exitCondition = False
631 self.exitCondition = False
628 self.isReady = False
632 self.isReady = False
629 self.nIncohInt = N
633 self.nIncohInt = N
630 self.integ_counter = 0
634 self.integ_counter = 0
631 if timeInterval!=None:
635 if timeInterval!=None:
632 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
636 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
633
637
634 if ((timeInterval==None) and (N==None)):
638 if ((timeInterval==None) and (N==None)):
635 print 'N = None ; timeInterval = None'
639 print 'N = None ; timeInterval = None'
636 sys.exit(0)
640 sys.exit(0)
637 elif timeInterval == None:
641 elif timeInterval == None:
638 self.timeFlag = False
642 self.timeFlag = False
639 else:
643 else:
640 self.timeFlag = True
644 self.timeFlag = True
641
645
642
646
643 def exe(self,data,timeOfData):
647 def exe(self,data,timeOfData):
644 """
648 """
645 data
649 data
646
650
647 timeOfData [seconds]
651 timeOfData [seconds]
648 """
652 """
649
653
650 if self.timeFlag:
654 if self.timeFlag:
651 if self.timeOut == None:
655 if self.timeOut == None:
652 self.timeOut = timeOfData + self.timeIntervalInSeconds
656 self.timeOut = timeOfData + self.timeIntervalInSeconds
653
657
654 if timeOfData < self.timeOut:
658 if timeOfData < self.timeOut:
655 if self.buffer == None:
659 if self.buffer == None:
656 self.buffer = data
660 self.buffer = data
657 else:
661 else:
658 self.buffer = self.buffer + data
662 self.buffer = self.buffer + data
659 self.integ_counter += 1
663 self.integ_counter += 1
660 else:
664 else:
661 self.exitCondition = True
665 self.exitCondition = True
662
666
663 else:
667 else:
664 if self.integ_counter < self.nIncohInt:
668 if self.integ_counter < self.nIncohInt:
665 if self.buffer == None:
669 if self.buffer == None:
666 self.buffer = data
670 self.buffer = data
667 else:
671 else:
668 self.buffer = self.buffer + data
672 self.buffer = self.buffer + data
669
673
670 self.integ_counter += 1
674 self.integ_counter += 1
671
675
672 if self.integ_counter == self.nIncohInt:
676 if self.integ_counter == self.nIncohInt:
673 self.exitCondition = True
677 self.exitCondition = True
674
678
675 if self.exitCondition:
679 if self.exitCondition:
676 self.data = self.buffer
680 self.data = self.buffer
677 self.navg = self.integ_counter
681 self.navg = self.integ_counter
678 self.isReady = True
682 self.isReady = True
679 self.buffer = None
683 self.buffer = None
680 self.timeOut = None
684 self.timeOut = None
681 self.integ_counter = 0
685 self.integ_counter = 0
682 self.exitCondition = False
686 self.exitCondition = False
683
687
684 if self.timeFlag:
688 if self.timeFlag:
685 self.buffer = data
689 self.buffer = data
686 self.timeOut = timeOfData + self.timeIntervalInSeconds
690 self.timeOut = timeOfData + self.timeIntervalInSeconds
687 else:
691 else:
688 self.isReady = False
692 self.isReady = False
689 No newline at end of file
693
General Comments 0
You need to be logged in to leave comments. Login now