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