@@ -1,863 +1,902 | |||
|
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 | |
|
9 | 9 | import numpy |
|
10 | 10 | import plplot |
|
11 | 11 | |
|
12 | 12 | def cmap1_init(colormap="gray"): |
|
13 | 13 | |
|
14 | if colormap == None: | |
|
15 | return | |
|
16 | ||
|
14 | 17 | ncolor = None |
|
15 | 18 | rgb_lvl = None |
|
16 | 19 | |
|
17 | 20 | # Routine for defining a specific color map 1 in HLS space. |
|
18 | 21 | # if gray is true, use basic grayscale variation from half-dark to light. |
|
19 | 22 | # otherwise use false color variation from blue (240 deg) to red (360 deg). |
|
20 | 23 | |
|
21 | 24 | # Independent variable of control points. |
|
22 | 25 | i = numpy.array((0., 1.)) |
|
23 | 26 | if colormap=="gray": |
|
24 | 27 | ncolor = 256 |
|
25 | 28 | # Hue for control points. Doesn't matter since saturation is zero. |
|
26 | 29 | h = numpy.array((0., 0.)) |
|
27 | 30 | # Lightness ranging from half-dark (for interest) to light. |
|
28 | 31 | l = numpy.array((0.5, 1.)) |
|
29 | 32 | # Gray scale has zero saturation |
|
30 | 33 | s = numpy.array((0., 0.)) |
|
31 | 34 | |
|
32 | 35 | # number of cmap1 colours is 256 in this case. |
|
33 | 36 | plplot.plscmap1n(ncolor) |
|
34 | 37 | # Interpolate between control points to set up cmap1. |
|
35 | 38 | plplot.plscmap1l(0, i, h, l, s) |
|
36 | 39 | |
|
37 | 40 | return None |
|
38 | 41 | |
|
39 | 42 | if colormap=="br_green": |
|
40 | 43 | ncolor = 256 |
|
41 | 44 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
42 | 45 | h = numpy.array((240., 0.)) |
|
43 | 46 | # Lightness and saturation are constant (values taken from C example). |
|
44 | 47 | l = numpy.array((0.6, 0.6)) |
|
45 | 48 | s = numpy.array((0.8, 0.8)) |
|
46 | 49 | |
|
47 | 50 | # number of cmap1 colours is 256 in this case. |
|
48 | 51 | plplot.plscmap1n(ncolor) |
|
49 | 52 | # Interpolate between control points to set up cmap1. |
|
50 | 53 | plplot.plscmap1l(0, i, h, l, s) |
|
51 | 54 | |
|
52 | 55 | return None |
|
53 | 56 | |
|
54 | 57 | if colormap=="tricolor": |
|
55 | 58 | ncolor = 3 |
|
56 | 59 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
57 | 60 | h = numpy.array((240., 0.)) |
|
58 | 61 | # Lightness and saturation are constant (values taken from C example). |
|
59 | 62 | l = numpy.array((0.6, 0.6)) |
|
60 | 63 | s = numpy.array((0.8, 0.8)) |
|
61 | 64 | |
|
62 | 65 | # number of cmap1 colours is 256 in this case. |
|
63 | 66 | plplot.plscmap1n(ncolor) |
|
64 | 67 | # Interpolate between control points to set up cmap1. |
|
65 | 68 | plplot.plscmap1l(0, i, h, l, s) |
|
66 | 69 | |
|
67 | 70 | return None |
|
68 | 71 | |
|
69 | 72 | if colormap == 'rgb' or colormap == 'rgb666': |
|
70 | 73 | |
|
71 | 74 | color_sz = 6 |
|
72 | 75 | ncolor = color_sz*color_sz*color_sz |
|
73 | 76 | pos = numpy.zeros((ncolor)) |
|
74 | 77 | r = numpy.zeros((ncolor)) |
|
75 | 78 | g = numpy.zeros((ncolor)) |
|
76 | 79 | b = numpy.zeros((ncolor)) |
|
77 | 80 | ind = 0 |
|
78 | 81 | for ri in range(color_sz): |
|
79 | 82 | for gi in range(color_sz): |
|
80 | 83 | for bi in range(color_sz): |
|
81 | 84 | r[ind] = ri/(color_sz-1.0) |
|
82 | 85 | g[ind] = gi/(color_sz-1.0) |
|
83 | 86 | b[ind] = bi/(color_sz-1.0) |
|
84 | 87 | pos[ind] = ind/(ncolor-1.0) |
|
85 | 88 | ind += 1 |
|
86 | 89 | rgb_lvl = [6,6,6] #Levels for RGB colors |
|
87 | 90 | |
|
88 | 91 | if colormap == 'rgb676': |
|
89 | 92 | ncolor = 6*7*6 |
|
90 | 93 | pos = numpy.zeros((ncolor)) |
|
91 | 94 | r = numpy.zeros((ncolor)) |
|
92 | 95 | g = numpy.zeros((ncolor)) |
|
93 | 96 | b = numpy.zeros((ncolor)) |
|
94 | 97 | ind = 0 |
|
95 | 98 | for ri in range(8): |
|
96 | 99 | for gi in range(8): |
|
97 | 100 | for bi in range(4): |
|
98 | 101 | r[ind] = ri/(6-1.0) |
|
99 | 102 | g[ind] = gi/(7-1.0) |
|
100 | 103 | b[ind] = bi/(6-1.0) |
|
101 | 104 | pos[ind] = ind/(ncolor-1.0) |
|
102 | 105 | ind += 1 |
|
103 | 106 | rgb_lvl = [6,7,6] #Levels for RGB colors |
|
104 | 107 | |
|
105 | 108 | if colormap == 'rgb685': |
|
106 | 109 | ncolor = 6*8*5 |
|
107 | 110 | pos = numpy.zeros((ncolor)) |
|
108 | 111 | r = numpy.zeros((ncolor)) |
|
109 | 112 | g = numpy.zeros((ncolor)) |
|
110 | 113 | b = numpy.zeros((ncolor)) |
|
111 | 114 | ind = 0 |
|
112 | 115 | for ri in range(8): |
|
113 | 116 | for gi in range(8): |
|
114 | 117 | for bi in range(4): |
|
115 | 118 | r[ind] = ri/(6-1.0) |
|
116 | 119 | g[ind] = gi/(8-1.0) |
|
117 | 120 | b[ind] = bi/(5-1.0) |
|
118 | 121 | pos[ind] = ind/(ncolor-1.0) |
|
119 | 122 | ind += 1 |
|
120 | 123 | rgb_lvl = [6,8,5] #Levels for RGB colors |
|
121 | 124 | |
|
122 | 125 | if colormap == 'rgb884': |
|
123 | 126 | ncolor = 8*8*4 |
|
124 | 127 | pos = numpy.zeros((ncolor)) |
|
125 | 128 | r = numpy.zeros((ncolor)) |
|
126 | 129 | g = numpy.zeros((ncolor)) |
|
127 | 130 | b = numpy.zeros((ncolor)) |
|
128 | 131 | ind = 0 |
|
129 | 132 | for ri in range(8): |
|
130 | 133 | for gi in range(8): |
|
131 | 134 | for bi in range(4): |
|
132 | 135 | r[ind] = ri/(8-1.0) |
|
133 | 136 | g[ind] = gi/(8-1.0) |
|
134 | 137 | b[ind] = bi/(4-1.0) |
|
135 | 138 | pos[ind] = ind/(ncolor-1.0) |
|
136 | 139 | ind += 1 |
|
137 | 140 | rgb_lvl = [8,8,4] #Levels for RGB colors |
|
138 | 141 | |
|
139 | 142 | if ncolor == None: |
|
140 | 143 | raise ValueError, "The colormap selected is not valid" |
|
141 | 144 | |
|
142 | 145 | plplot.plscmap1n(ncolor) |
|
143 | 146 | plplot.plscmap1l(1, pos, r, g, b) |
|
144 | 147 | |
|
145 | 148 | return rgb_lvl |
|
146 | 149 | |
|
150 | def setColormap(colormap="br_green"): | |
|
151 | cmap1_init(colormap) | |
|
152 | ||
|
147 | 153 | class BaseGraph: |
|
148 | 154 | """ |
|
149 | 155 | |
|
150 | 156 | """ |
|
157 | hasNotRange = True | |
|
158 | ||
|
159 | xrange = None | |
|
160 | yrange = None | |
|
161 | zrange = None | |
|
151 | 162 | |
|
152 | ||
|
163 | xlabel = None | |
|
164 | ylabel = None | |
|
165 | title = None | |
|
166 | ||
|
167 | legends = None | |
|
168 | ||
|
169 | __name = None | |
|
170 | ||
|
171 | __colormap = None | |
|
172 | __colbox = None | |
|
173 | __colleg = None | |
|
174 | ||
|
175 | __xpos = None | |
|
176 | __ypos = None | |
|
177 | ||
|
178 | __xopt = None #"bcnst" | |
|
179 | __yopt = None #"bcnstv" | |
|
180 | ||
|
181 | __xlpos = None | |
|
182 | __ylpos = None | |
|
183 | ||
|
184 | __xrangeIsTime = False | |
|
185 | ||
|
186 | #Advanced | |
|
187 | __xg = None | |
|
188 | __yg = None | |
|
153 | 189 | |
|
154 | 190 | def __init__(self): |
|
155 | 191 | """ |
|
156 | 192 | |
|
157 | 193 | """ |
|
158 | 194 | self.hasNotRange = True |
|
159 | 195 | |
|
160 | 196 | self.xrange = None |
|
161 | 197 | self.yrange = None |
|
162 | 198 | self.zrange = None |
|
163 | 199 | |
|
164 | 200 | self.xlabel = None |
|
165 | 201 | self.ylabel = None |
|
166 | 202 | self.title = None |
|
167 | 203 | |
|
168 | 204 | self.legends = None |
|
169 | 205 | |
|
170 | 206 | self.__name = None |
|
171 | 207 | |
|
172 | 208 | self.__colormap = None |
|
173 | 209 | self.__colbox = None |
|
174 | 210 | self.__colleg = None |
|
175 | 211 | |
|
176 | 212 | self.__xpos = None |
|
177 | 213 | self.__ypos = None |
|
178 | 214 | |
|
179 | 215 | self.__xopt = None #"bcnst" |
|
180 | 216 | self.__yopt = None #"bcnstv" |
|
181 | 217 | |
|
182 | 218 | self.__xlpos = None |
|
183 | 219 | self.__ylpos = None |
|
184 | 220 | |
|
185 | 221 | self.__xrangeIsTime = False |
|
186 | 222 | |
|
187 | 223 | #Advanced |
|
188 | 224 | self.__xg = None |
|
189 | 225 | self.__yg = None |
|
190 | 226 | |
|
191 | 227 | def setName(self, name): |
|
192 | 228 | self.__name = name |
|
193 | 229 | |
|
194 | 230 | def setScreenPos(self, xpos, ypos): |
|
195 | 231 | self.__xpos = xpos |
|
196 | 232 | self.__ypos = ypos |
|
197 | 233 | |
|
198 | 234 | def setOpt(self, xopt, yopt): |
|
199 | 235 | self.__xopt = xopt |
|
200 | 236 | self.__yopt = yopt |
|
201 | 237 | |
|
202 | 238 | def setXAxisAsTime(self): |
|
203 | 239 | self.__xrangeIsTime = True |
|
204 | 240 | |
|
205 | 241 | |
|
206 | 242 | def setup(self, title=None, xlabel=None, ylabel=None, colormap=None): |
|
207 | 243 | """ |
|
208 | 244 | """ |
|
209 | 245 | self.title = title |
|
210 | 246 | self.xlabel = xlabel |
|
211 | 247 | self.ylabel = ylabel |
|
212 | 248 | self.__colormap = colormap |
|
213 | 249 | |
|
214 | 250 | def plotBox(self, xmin, xmax, ymin, ymax, xopt=None, yopt=None, nolabels=False): |
|
215 | 251 | """ |
|
216 | 252 | |
|
217 | 253 | """ |
|
218 | 254 | if self.__xrangeIsTime: |
|
219 | 255 | plplot.pltimefmt("%H:%M") |
|
220 | 256 | |
|
221 | 257 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) |
|
222 | 258 | plplot.plwind(float(xmin), |
|
223 | 259 | float(xmax), |
|
224 | 260 | float(ymin), |
|
225 | 261 | float(ymax) |
|
226 | 262 | ) |
|
227 | 263 | |
|
228 | 264 | if xopt == None: xopt = self.__xopt |
|
229 | 265 | if yopt == None: yopt = self.__yopt |
|
230 | 266 | |
|
231 | 267 | plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0) |
|
232 | 268 | |
|
233 | 269 | if not(nolabels): |
|
234 | 270 | plplot.pllab(self.xlabel, self.ylabel, self.title) |
|
235 | 271 | |
|
236 | 272 | |
|
237 | 273 | def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): |
|
238 | 274 | data = numpy.arange(256) |
|
239 | 275 | data = numpy.reshape(data, (1,-1)) |
|
240 | 276 | |
|
241 | 277 | plplot.plimage(data, |
|
242 | 278 | float(xmin), |
|
243 | 279 | float(xmax), |
|
244 | 280 | float(ymin), |
|
245 | 281 | float(ymax), |
|
246 | 282 | 0., |
|
247 | 283 | 255., |
|
248 | 284 | float(xmin), |
|
249 | 285 | float(xmax), |
|
250 | 286 | float(ymin), |
|
251 | 287 | float(ymax)) |
|
252 | 288 | |
|
253 | 289 | def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None): |
|
254 | 290 | |
|
255 | 291 | if xmin == None: xmin = x[0] |
|
256 | 292 | if xmax == None: xmax = x[-1] |
|
257 | 293 | if ymin == None: ymin = y[0] |
|
258 | 294 | if ymax == None: ymax = y[-1] |
|
259 | 295 | |
|
260 | 296 | plplot.plline(x, y) |
|
261 | 297 | |
|
262 | 298 | def basicXYwithErrorPlot(self): |
|
263 | 299 | pass |
|
264 | 300 | |
|
265 | 301 | def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): |
|
266 | 302 | |
|
267 | 303 | if xmin == None: xmin = x[0] |
|
268 | 304 | if xmax == None: xmax = x[-1] |
|
269 | 305 | if ymin == None: ymin = y[0] |
|
270 | 306 | if ymax == None: ymax = y[-1] |
|
271 | 307 | |
|
272 | 308 | plplot.plcol0(colline) |
|
273 | 309 | plplot.plline(x, y) |
|
274 | 310 | plplot.plcol0(1) |
|
275 | 311 | |
|
276 | 312 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
277 | 313 | """ |
|
278 | 314 | """ |
|
279 | 315 | if xmin == None: xmin = x[0] |
|
280 | 316 | if xmax == None: xmax = x[-1] |
|
281 | 317 | if ymin == None: ymin = y[0] |
|
282 | 318 | if ymax == None: ymax = y[-1] |
|
283 | 319 | if zmin == None: zmin = numpy.nanmin(data) |
|
284 | 320 | if zmax == None: zmax = numpy.nanmax(data) |
|
285 | 321 | |
|
286 | 322 | plplot.plimage(data, |
|
287 | 323 | float(x[0]), |
|
288 | 324 | float(x[-1]), |
|
289 | 325 | float(y[0]), |
|
290 | 326 | float(y[-1]), |
|
291 | 327 | float(zmin), |
|
292 | 328 | float(zmax), |
|
293 | 329 | float(xmin), |
|
294 | 330 | float(xmax), |
|
295 | 331 | float(ymin), |
|
296 | 332 | float(ymax) |
|
297 | 333 | ) |
|
298 | 334 | |
|
299 | 335 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): |
|
300 | 336 | |
|
301 | 337 | if not(len(x)>1 and len(y)>1): |
|
302 | 338 | raise ValueError, "x axis and y axis are empty" |
|
303 | 339 | |
|
304 | 340 | if deltax == None: deltax = x[-1] - x[-2] |
|
305 | 341 | if deltay == None: deltay = y[-1] - y[-2] |
|
306 | 342 | |
|
307 | 343 | x1 = numpy.append(x, x[-1] + deltax) |
|
308 | 344 | y1 = numpy.append(y, y[-1] + deltay) |
|
309 | 345 | |
|
310 | 346 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) |
|
311 | 347 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) |
|
312 | 348 | |
|
313 | 349 | self.__xg = xg |
|
314 | 350 | self.__yg = yg |
|
315 | 351 | |
|
316 | 352 | def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.): |
|
317 | 353 | """ |
|
318 | 354 | """ |
|
319 | 355 | |
|
320 | 356 | if self.__xg == None and self.__yg == None: |
|
321 | 357 | self.__getBoxpltr(x, y) |
|
322 | 358 | |
|
323 | 359 | plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg) |
|
324 | 360 | |
|
325 | 361 | |
|
326 |
class LinearPlot |
|
|
362 | class LinearPlot: | |
|
363 | ||
|
364 | linearGraphObj = BaseGraph() | |
|
327 | 365 | |
|
328 | 366 | __szchar = 1.0 |
|
367 | ||
|
329 | 368 | __xrange = None |
|
369 | ||
|
330 | 370 | __yrange = None |
|
331 | 371 | |
|
332 | m_BaseGraph = None | |
|
372 | __subpage = 0 | |
|
373 | m_BaseGraph= BaseGraph() | |
|
374 | ||
|
375 | ||
|
333 | 376 | |
|
334 | 377 | def __init__(self): |
|
335 | 378 | |
|
336 | 379 | |
|
337 | 380 | key = "linearplot" |
|
338 |
self. |
|
|
339 |
self. |
|
|
381 | self.linearGraphObj = BaseGraph() | |
|
382 | self.linearGraphObj.setName(key) | |
|
340 | 383 | |
|
341 | 384 | self.__subpage = 0 |
|
342 | 385 | |
|
343 | def setColormap(self, colormap="br_green"): | |
|
344 | ||
|
345 | if colormap == None: | |
|
346 | colormap = self.__colormap | |
|
347 | ||
|
348 | cmap1_init(colormap) | |
|
349 | ||
|
350 | def iniSubpage(self): | |
|
386 | def __iniSubpage(self): | |
|
351 | 387 | |
|
352 | 388 | if plplot.plgdev() == '': |
|
353 | 389 | raise ValueError, "Plot device has not been initialize" |
|
354 | 390 | |
|
355 | 391 | plplot.pladv(self.__subpage) |
|
356 | 392 | plplot.plschr(0.0, self.__szchar) |
|
357 | 393 | |
|
358 |
|
|
|
394 | setColormap() | |
|
359 | 395 | |
|
360 | 396 | def setScreenPos(self, width='small'): |
|
361 | 397 | |
|
362 | 398 | if width == 'small': |
|
363 | 399 | xi = 0.12; yi = 0.14; xw = 0.78; yw = 0.80 |
|
364 | 400 | |
|
365 | 401 | if width == 'medium': |
|
366 | 402 | xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60 |
|
367 | 403 | |
|
368 | 404 | xf = xi + xw |
|
369 | 405 | yf = yi + yw |
|
370 | 406 | |
|
371 |
self. |
|
|
407 | self.linearGraphObj.setScreenPos([xi, xf], [yi, yf]) | |
|
372 | 408 | |
|
373 | 409 | def setup(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): |
|
374 | 410 | """ |
|
375 | 411 | """ |
|
376 | 412 | |
|
377 |
self. |
|
|
378 |
self. |
|
|
413 | self.linearGraphObj.setOpt("bcnts","bcntsv") | |
|
414 | self.linearGraphObj.setup(title, | |
|
379 | 415 | xlabel, |
|
380 | 416 | ylabel |
|
381 | 417 | ) |
|
382 | 418 | |
|
383 | 419 | self.setScreenPos(width='medium') |
|
384 | 420 | |
|
385 | 421 | if XAxisAsTime: |
|
386 |
self. |
|
|
422 | self.linearGraphObj.setXAxisAsTime() | |
|
387 | 423 | |
|
388 | 424 | self.__subpage = subpage |
|
389 | 425 | # def setRanges(self, xrange, yrange, zrange): |
|
390 | 426 | # |
|
391 |
# self. |
|
|
427 | # self.linearGraphObj.setRanges(xrange, yrange, zrange) | |
|
392 | 428 | |
|
393 | 429 | def plotData(self, x, y=None, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): |
|
394 | 430 | """ |
|
395 | 431 | Inputs: |
|
396 | 432 | |
|
397 | 433 | x : Numpy array of dimension 1 |
|
398 | 434 | y : Numpy array of dimension 1 |
|
399 | 435 | |
|
400 | 436 | """ |
|
401 | 437 | |
|
402 | 438 | try: |
|
403 | 439 | nX = numpy.shape(x) |
|
404 | 440 | except: |
|
405 | 441 | raise ValueError, "x is not a numpy array" |
|
406 | 442 | |
|
407 | 443 | if y == None: y = numpy.arange(nX) |
|
408 | 444 | |
|
409 | 445 | if xmin == None: xmin = x[0] |
|
410 | 446 | if xmax == None: xmax = x[-1] |
|
411 | 447 | if ymin == None: ymin = y[0] |
|
412 | 448 | if ymax == None: ymax = y[-1] |
|
413 | 449 | |
|
414 | self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) | |
|
415 |
self. |
|
|
450 | self.__iniSubpage() | |
|
451 | self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax) | |
|
452 | self.linearGraphObj.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline) | |
|
416 | 453 | |
|
417 | 454 | def plotComplexData(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1, type='power'): |
|
418 | 455 | """ |
|
419 | 456 | Inputs: |
|
420 | 457 | |
|
421 | 458 | x : Numpy array of dimension 1 |
|
422 | 459 | y : Complex numpy array of dimension 1 |
|
423 | 460 | |
|
424 | 461 | """ |
|
425 | 462 | |
|
426 | 463 | try: |
|
427 | 464 | nX = numpy.shape(x) |
|
428 | 465 | except: |
|
429 | 466 | raise ValueError, "x is not a numpy array" |
|
430 | 467 | |
|
431 | 468 | try: |
|
432 | 469 | nY = numpy.shape(y) |
|
433 | 470 | except: |
|
434 | 471 | raise ValueError, "y is not a numpy array" |
|
435 | 472 | |
|
436 | 473 | if xmin == None: xmin = x[0] |
|
437 | 474 | if xmax == None: xmax = x[-1] |
|
438 | 475 | if ymin == None: ymin = y[0] |
|
439 | 476 | if ymax == None: ymax = y[-1] |
|
440 | 477 | |
|
441 | self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) | |
|
478 | self.__iniSubpage() | |
|
479 | self.linearGraphObj.plotBox(xmin, xmax, ymin, ymax) | |
|
442 | 480 | |
|
443 | 481 | if type.lower() == 'power': |
|
444 |
self. |
|
|
482 | self.linearGraphObj.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline) | |
|
445 | 483 | |
|
446 | 484 | if type.lower() == 'iq': |
|
447 | 485 | |
|
448 |
self. |
|
|
449 |
self. |
|
|
486 | self.linearGraphObj.basicLineTimePlot(x, y.real, xmin, xmax, ymin, ymax, colline) | |
|
487 | self.linearGraphObj.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1) | |
|
450 | 488 | |
|
451 |
class ColorPlot |
|
|
489 | class ColorPlot: | |
|
490 | ||
|
491 | colorGraphObj = BaseGraph() | |
|
492 | ||
|
493 | graphObjDict = {} | |
|
452 | 494 | |
|
495 | __subpage = 0 | |
|
496 | ||
|
497 | __showColorbar = False | |
|
498 | ||
|
499 | __showPowerProfile = True | |
|
500 | ||
|
501 | __szchar = 0.65 | |
|
502 | ||
|
503 | __xrange = None | |
|
504 | ||
|
505 | __yrange = None | |
|
506 | ||
|
507 | __zrange = None | |
|
508 | m_BaseGraph= BaseGraph() | |
|
509 | ||
|
510 | ||
|
511 | ||
|
453 | 512 | def __init__(self): |
|
454 | 513 | |
|
455 | 514 | self.graphObjDict = {} |
|
456 | 515 | |
|
457 | 516 | self.__subpage = 0 |
|
458 | 517 | self.__showColorbar = False |
|
459 | 518 | self.__showPowerProfile = True |
|
460 | 519 | |
|
461 | 520 | self.__szchar = 0.65 |
|
462 | 521 | self.__xrange = None |
|
463 | 522 | self.__yrange = None |
|
464 | 523 | self.__zrange = None |
|
465 | 524 | |
|
466 | 525 | key = "colorplot" |
|
467 |
self. |
|
|
468 |
self. |
|
|
526 | self.colorGraphObj = BaseGraph() | |
|
527 | self.colorGraphObj.setName(key) | |
|
469 | 528 | |
|
470 |
def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap=" |
|
|
529 | def setup(self, subpage, title="", xlabel="Frequency", ylabel="Range", colormap="br_green", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): | |
|
471 | 530 | """ |
|
472 | 531 | """ |
|
473 | 532 | |
|
474 |
self. |
|
|
475 |
self. |
|
|
533 | self.colorGraphObj.setOpt("bcnts","bcntsv") | |
|
534 | self.colorGraphObj.setup(title, | |
|
476 | 535 | xlabel, |
|
477 | 536 | ylabel |
|
478 | 537 | ) |
|
479 | 538 | |
|
480 | 539 | self.__subpage = subpage |
|
481 | 540 | self.__colormap = colormap |
|
482 | 541 | self.__showColorbar = showColorbar |
|
483 | 542 | self.__showPowerProfile = showPowerProfile |
|
484 | 543 | |
|
485 | 544 | if showColorbar: |
|
486 | 545 | key = "colorbar" |
|
487 | 546 | |
|
488 | 547 | cmapObj = BaseGraph() |
|
489 | 548 | cmapObj.setName(key) |
|
490 | 549 | cmapObj.setOpt("bc","bcmtv") |
|
491 | 550 | cmapObj.setup(title="dBs", |
|
492 | 551 | xlabel="", |
|
493 | 552 | ylabel="", |
|
494 | 553 | colormap=colormap) |
|
495 | 554 | |
|
496 | 555 | self.graphObjDict[key] = cmapObj |
|
497 | 556 | |
|
498 | 557 | |
|
499 | 558 | if showPowerProfile: |
|
500 | 559 | key = "powerprof" |
|
501 | 560 | |
|
502 | 561 | powObj = BaseGraph() |
|
503 | 562 | powObj.setName(key) |
|
504 | 563 | powObj.setOpt("bcntg","bc") |
|
505 | 564 | powObj.setup(title="Power Profile", |
|
506 | 565 | xlabel="dB", |
|
507 | 566 | ylabel="") |
|
508 | 567 | |
|
509 | 568 | self.graphObjDict[key] = powObj |
|
510 | 569 | |
|
511 | 570 | self.setScreenPos(width='small') |
|
512 | 571 | |
|
513 | 572 | if XAxisAsTime: |
|
514 |
self. |
|
|
573 | self.colorGraphObj.setXAxisAsTime() | |
|
515 | 574 | |
|
516 | ||
|
517 | ||
|
518 | def setColormap(self, colormap="br_green"): | |
|
519 | ||
|
520 | if colormap == None: | |
|
521 | colormap = self.__colormap | |
|
522 | ||
|
523 | cmap1_init(colormap) | |
|
524 | ||
|
525 | def iniSubpage(self): | |
|
575 | def __iniSubpage(self): | |
|
526 | 576 | |
|
527 | 577 | if plplot.plgdev() == '': |
|
528 | 578 | raise ValueError, "Plot device has not been initialize" |
|
529 | 579 | |
|
530 | 580 | plplot.pladv(self.__subpage) |
|
531 | 581 | plplot.plschr(0.0, self.__szchar) |
|
532 | 582 | |
|
533 |
self. |
|
|
583 | setColormap(self.__colormap) | |
|
534 | 584 | |
|
535 | 585 | def setScreenPos(self, width='small'): |
|
536 | 586 | |
|
537 | 587 | if width == 'small': |
|
538 | 588 | xi = 0.13; yi = 0.12; xw = 0.86; yw = 0.70; xcmapw = 0.04; xpoww = 0.25; deltaxcmap = 0.02; deltaxpow = 0.06 |
|
539 | 589 | |
|
540 | 590 | if width == 'medium': |
|
541 | 591 | xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60; xcmapw = 0.04; xpoww = 0.24; deltaxcmap = 0.02; deltaxpow = 0.06 |
|
542 | 592 | |
|
543 | 593 | if self.__showColorbar: |
|
544 | 594 | xw -= xcmapw + deltaxcmap |
|
545 | 595 | |
|
546 | 596 | if self.__showPowerProfile: |
|
547 | 597 | xw -= xpoww + deltaxpow |
|
548 | 598 | |
|
549 | 599 | xf = xi + xw |
|
550 | 600 | yf = yi + yw |
|
551 | 601 | xcmapf = xf |
|
552 | 602 | |
|
553 |
self. |
|
|
603 | self.colorGraphObj.setScreenPos([xi, xf], [yi, yf]) | |
|
554 | 604 | |
|
555 | 605 | if self.__showColorbar: |
|
556 | 606 | xcmapi = xf + deltaxcmap |
|
557 | 607 | xcmapf = xcmapi + xcmapw |
|
558 | 608 | |
|
559 | 609 | key = "colorbar" |
|
560 | 610 | cmapObj = self.graphObjDict[key] |
|
561 | 611 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) |
|
562 | 612 | |
|
563 | 613 | if self.__showPowerProfile: |
|
564 | 614 | |
|
565 | 615 | xpowi = xcmapf + deltaxpow |
|
566 | 616 | xpowf = xpowi + xpoww |
|
567 | 617 | |
|
568 | 618 | key = "powerprof" |
|
569 | 619 | powObj = self.graphObjDict[key] |
|
570 | 620 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) |
|
571 | 621 | |
|
572 | 622 | |
|
573 | 623 | |
|
574 | 624 | def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
575 | 625 | """ |
|
576 | 626 | Inputs: |
|
577 | 627 | |
|
578 | 628 | x : Numpy array of dimension 1 |
|
579 | 629 | y : Numpy array of dimension 1 |
|
580 | 630 | |
|
581 | 631 | """ |
|
582 | 632 | |
|
583 | 633 | try: |
|
584 | 634 | nX, nY = numpy.shape(data) |
|
585 | 635 | except: |
|
586 | 636 | raise ValueError, "data is not a numpy array" |
|
587 | 637 | |
|
588 | 638 | if x == None: x = numpy.arange(nX) |
|
589 | 639 | if y == None: y = numpy.arange(nY) |
|
590 | 640 | |
|
591 | 641 | if xmin == None: xmin = x[0] |
|
592 | 642 | if xmax == None: xmax = x[-1] |
|
593 | 643 | if ymin == None: ymin = y[0] |
|
594 | 644 | if ymax == None: ymax = y[-1] |
|
595 | 645 | if zmin == None: zmin = numpy.nanmin(data) |
|
596 | 646 | if zmax == None: zmax = numpy.nanmax(data) |
|
597 | 647 | |
|
598 | 648 | plplot.plschr(0.0, self.__szchar) |
|
599 | ||
|
600 |
self. |
|
|
601 |
self. |
|
|
649 | self.__iniSubpage() | |
|
650 | self.colorGraphObj.plotBox(xmin, xmax, ymin, ymax) | |
|
651 | self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, zmin, zmax) | |
|
602 | 652 | |
|
603 | 653 | if self.__showColorbar: |
|
604 | 654 | |
|
605 | 655 | |
|
606 | 656 | key = "colorbar" |
|
607 | 657 | cmapObj = self.graphObjDict[key] |
|
608 | 658 | |
|
609 | 659 | plplot.plschr(0.0, self.__szchar-0.05) |
|
610 | 660 | cmapObj.plotBox(0., 1., zmin, zmax) |
|
611 | 661 | cmapObj.colorbarPlot(0., 1., zmin, zmax) |
|
612 | 662 | |
|
613 | 663 | if self.__showPowerProfile: |
|
614 | 664 | power = numpy.max(data, axis=0) |
|
615 | 665 | |
|
616 | 666 | step = (ymax - ymin)/(nY-1) |
|
617 | 667 | heis = numpy.arange(ymin, ymax + step, step) |
|
618 | 668 | |
|
619 | 669 | key = "powerprof" |
|
620 | 670 | powObj = self.graphObjDict[key] |
|
621 | 671 | |
|
622 | 672 | plplot.pllsty(2) |
|
623 | 673 | plplot.plschr(0.0, self.__szchar-0.05) |
|
624 | 674 | powObj.plotBox(zmin, zmax, ymin, ymax, nolabels=True) |
|
625 | 675 | |
|
626 | 676 | plplot.pllsty(1) |
|
627 | 677 | plplot.plschr(0.0, self.__szchar) |
|
628 | 678 | powObj.plotBox(zmin, zmax, ymin, ymax, xopt='bc', yopt='bc') |
|
629 | 679 | |
|
630 | 680 | plplot.plcol0(9) |
|
631 | 681 | powObj.basicXYPlot(power, heis) |
|
632 | 682 | plplot.plcol0(1) |
|
633 | 683 | |
|
634 | 684 | |
|
635 |
class ColorPlotX |
|
|
685 | class ColorPlotX: | |
|
636 | 686 | |
|
637 | 687 | |
|
638 | 688 | graphObjDict = {} |
|
639 | 689 | showColorbar = False |
|
640 | 690 | showPowerProfile = True |
|
641 | 691 | |
|
642 | 692 | __szchar = 0.7 |
|
643 | 693 | __xrange = None |
|
644 | 694 | __yrange = None |
|
645 | 695 | __zrange = None |
|
646 | 696 | |
|
647 |
|
|
|
697 | colorGraphObj = BaseGraph() | |
|
648 | 698 | |
|
649 | 699 | def __init__(self): |
|
650 | 700 | |
|
651 | 701 | key = "colorplot" |
|
652 |
self. |
|
|
702 | self.colorGraphObj.setName(key) | |
|
653 | 703 | |
|
654 | 704 | self.__subpage = 0 |
|
655 | 705 | |
|
656 |
self.graphObjDict[key] = self. |
|
|
706 | self.graphObjDict[key] = self.colorGraphObj | |
|
657 | 707 | |
|
658 | def setColormap(self, colormap="br_green"): | |
|
659 | ||
|
660 | if colormap == None: | |
|
661 | colormap = self.__colormap | |
|
662 | ||
|
663 | cmap1_init(colormap) | |
|
664 | ||
|
665 | def iniSubpage(self): | |
|
708 | def __iniSubpage(self): | |
|
666 | 709 | |
|
667 | 710 | if plplot.plgdev() == '': |
|
668 | 711 | raise ValueError, "Plot device has not been initialize" |
|
669 | 712 | |
|
670 | 713 | plplot.pladv(self.__subpage) |
|
671 | 714 | plplot.plschr(0.0, self.__szchar) |
|
672 | 715 | |
|
673 |
self. |
|
|
716 | setColormap(self.__colormap) | |
|
717 | ||
|
718 | def setScreenPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06): | |
|
719 | ||
|
720 | if self.showColorbar: | |
|
721 | xw -= xcmapw + deltaxcmap | |
|
722 | ||
|
723 | if self.showPowerProfile: | |
|
724 | xw -= xpoww + deltaxpow | |
|
674 | 725 | |
|
726 | xf = xi + xw | |
|
727 | yf = yi + yw | |
|
728 | xcmapf = xf | |
|
729 | ||
|
730 | self.colorGraphObj.setScreenPos([xi, xf], [yi, yf]) | |
|
731 | ||
|
732 | if self.showColorbar: | |
|
733 | xcmapi = xf + deltaxcmap | |
|
734 | xcmapf = xcmapi + xcmapw | |
|
735 | ||
|
736 | key = "colorbar" | |
|
737 | cmapObj = self.graphObjDict[key] | |
|
738 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) | |
|
739 | ||
|
740 | if self.showPowerProfile: | |
|
741 | ||
|
742 | xpowi = xcmapf + deltaxpow | |
|
743 | xpowf = xpowi + xpoww | |
|
744 | ||
|
745 | key = "powerprof" | |
|
746 | powObj = self.graphObjDict[key] | |
|
747 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) | |
|
748 | ||
|
749 | def setRanges(self, xrange, yrange, zrange): | |
|
750 | ||
|
751 | self.colorGraphObj.setRanges(xrange, yrange, zrange) | |
|
752 | ||
|
753 | keyList = self.graphObjDict.keys() | |
|
754 | ||
|
755 | key = "colorbar" | |
|
756 | if key in keyList: | |
|
757 | cmapObj = self.graphObjDict[key] | |
|
758 | cmapObj.setRanges([0., 1.], zrange) | |
|
759 | ||
|
760 | key = "powerprof" | |
|
761 | if key in keyList: | |
|
762 | powObj = self.graphObjDict[key] | |
|
763 | powObj.setRanges(zrange, yrange) | |
|
764 | ||
|
675 | 765 | def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): |
|
676 | 766 | """ |
|
677 | 767 | """ |
|
678 | 768 | |
|
679 |
self. |
|
|
680 |
self. |
|
|
681 |
self. |
|
|
682 |
self. |
|
|
769 | self.colorGraphObj.setSubpage(subpage) | |
|
770 | self.colorGraphObj.setSzchar(self.__szchar) | |
|
771 | self.colorGraphObj.setOpt("bcnts","bcntsv") | |
|
772 | self.colorGraphObj.setup(title, | |
|
683 | 773 | xlabel, |
|
684 | 774 | ylabel, |
|
685 | 775 | colormap) |
|
686 | 776 | |
|
687 | 777 | if showColorbar: |
|
688 | 778 | key = "colorbar" |
|
689 | 779 | |
|
690 | 780 | cmapObj = BaseGraph() |
|
691 | 781 | cmapObj.setName(key) |
|
692 | 782 | cmapObj.setSubpage(subpage) |
|
693 | 783 | cmapObj.setSzchar(self.__szchar) |
|
694 | 784 | cmapObj.setOpt("bc","bcmt") |
|
695 | 785 | cmapObj.setup(title="dBs", |
|
696 | 786 | xlabel="", |
|
697 | 787 | ylabel="", |
|
698 | 788 | colormap=colormap) |
|
699 | 789 | |
|
700 | 790 | self.graphObjDict[key] = cmapObj |
|
701 | 791 | |
|
702 | 792 | |
|
703 | 793 | if showPowerProfile: |
|
704 | 794 | key = "powerprof" |
|
705 | 795 | |
|
706 | 796 | powObj = BaseGraph() |
|
707 | 797 | powObj.setName(key) |
|
708 | 798 | powObj.setSubpage(subpage) |
|
709 | 799 | powObj.setSzchar(self.__szchar) |
|
710 | 800 | plplot.pllsty(2) |
|
711 | 801 | powObj.setOpt("bcntg","bc") |
|
712 | 802 | plplot.pllsty(1) |
|
713 | 803 | powObj.setup(title="Power Profile", |
|
714 | 804 | xlabel="dBs", |
|
715 | 805 | ylabel="") |
|
716 | 806 | |
|
717 | 807 | self.graphObjDict[key] = powObj |
|
718 | 808 | |
|
719 | 809 | self.showColorbar = showColorbar |
|
720 | 810 | self.showPowerProfile = showPowerProfile |
|
721 | 811 | self.setScreenPos() |
|
722 | 812 | |
|
723 | 813 | if XAxisAsTime: |
|
724 |
self. |
|
|
814 | self.colorGraphObj.setXAxisAsTime() | |
|
725 | 815 | #self.setScreenPos(xi = 0.05, yi = 0.18, xw = 0.92, yw = 0.74, xcmapw = 0.015, xpoww = 0.14, deltaxcmap = 0.01, deltaxpow = 0.02) |
|
726 | 816 | |
|
727 | ||
|
728 | def setScreenPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06): | |
|
729 | ||
|
730 | if self.showColorbar: | |
|
731 | xw -= xcmapw + deltaxcmap | |
|
732 | ||
|
733 | if self.showPowerProfile: | |
|
734 | xw -= xpoww + deltaxpow | |
|
735 | ||
|
736 | xf = xi + xw | |
|
737 | yf = yi + yw | |
|
738 | xcmapf = xf | |
|
739 | ||
|
740 | self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) | |
|
741 | ||
|
742 | if self.showColorbar: | |
|
743 | xcmapi = xf + deltaxcmap | |
|
744 | xcmapf = xcmapi + xcmapw | |
|
745 | ||
|
746 | key = "colorbar" | |
|
747 | cmapObj = self.graphObjDict[key] | |
|
748 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) | |
|
749 | ||
|
750 | if self.showPowerProfile: | |
|
751 | ||
|
752 | xpowi = xcmapf + deltaxpow | |
|
753 | xpowf = xpowi + xpoww | |
|
754 | ||
|
755 | key = "powerprof" | |
|
756 | powObj = self.graphObjDict[key] | |
|
757 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) | |
|
758 | ||
|
759 | def setRanges(self, xrange, yrange, zrange): | |
|
760 | ||
|
761 | self.m_BaseGraph.setRanges(xrange, yrange, zrange) | |
|
762 | 817 | |
|
763 | keyList = self.graphObjDict.keys() | |
|
764 | ||
|
765 | key = "colorbar" | |
|
766 | if key in keyList: | |
|
767 | cmapObj = self.graphObjDict[key] | |
|
768 | cmapObj.setRanges([0., 1.], zrange) | |
|
769 | ||
|
770 | key = "powerprof" | |
|
771 | if key in keyList: | |
|
772 | powObj = self.graphObjDict[key] | |
|
773 | powObj.setRanges(zrange, yrange) | |
|
774 | ||
|
775 | 818 | def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
776 | 819 | """ |
|
777 | 820 | """ |
|
778 | 821 | |
|
779 | 822 | try: |
|
780 | 823 | nX, nY = numpy.shape(data) |
|
781 | 824 | except: |
|
782 | 825 | raise ValueError, "data is not a numpy array" |
|
783 | 826 | |
|
784 | 827 | if x == None: x = numpy.arange(nX) |
|
785 | 828 | if y == None: y = numpy.arange(nY) |
|
786 | 829 | |
|
787 | 830 | if xmin == None: xmin = x[0] |
|
788 | 831 | if xmax == None: xmax = x[-1] |
|
789 | 832 | if ymin == None: ymin = y[0] |
|
790 | 833 | if ymax == None: ymax = y[-1] |
|
791 | 834 | if zmin == None: zmin = numpy.nanmin(data) |
|
792 | 835 | if zmax == None: zmax = numpy.nanmax(data) |
|
793 | 836 | |
|
794 |
if self. |
|
|
837 | if self.colorGraphObj.hasNotRange: | |
|
795 | 838 | self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) |
|
796 | 839 | |
|
797 |
self. |
|
|
798 |
self. |
|
|
840 | self.colorGraphObj.initSubpage() | |
|
841 | self.colorGraphObj.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.colorGraphObj.zrange[0], self.colorGraphObj.zrange[1]) | |
|
799 | 842 | |
|
800 | 843 | if self.showColorbar: |
|
801 | 844 | key = "colorbar" |
|
802 | 845 | cmapObj = self.graphObjDict[key] |
|
803 | 846 | cmapObj.colorbarPlot() |
|
804 | 847 | |
|
805 | 848 | if self.showPowerProfile: |
|
806 | 849 | power = numpy.average(data, axis=1) |
|
807 | 850 | |
|
808 | 851 | step = (ymax - ymin)/(nY-1) |
|
809 | 852 | heis = numpy.arange(ymin, ymax + step, step) |
|
810 | 853 | |
|
811 | 854 | key = "powerprof" |
|
812 | 855 | powObj = self.graphObjDict[key] |
|
813 | 856 | powObj.basicXYPlot(power, heis) |
|
814 | 857 | |
|
815 | 858 | if __name__ == '__main__': |
|
816 | 859 | |
|
817 | 860 | import numpy |
|
818 | 861 | plplot.plsetopt("geometry", "%dx%d" %(350*2, 300*2)) |
|
819 | 862 | plplot.plsdev("xwin") |
|
820 | 863 | plplot.plscolbg(255,255,255) |
|
821 | 864 | plplot.plscol0(1,0,0,0) |
|
822 | 865 | plplot.plspause(False) |
|
823 | 866 | plplot.plinit() |
|
824 | 867 | plplot.plssub(2, 2) |
|
825 | 868 | |
|
826 | 869 | nx = 64 |
|
827 | 870 | ny = 100 |
|
828 | 871 | |
|
829 | 872 | data = numpy.random.uniform(-50,50,(nx,ny)) |
|
830 | 873 | |
|
831 | 874 | baseObj = ColorPlot() |
|
832 | 875 | specObj = ColorPlot() |
|
833 | 876 | baseObj1 = ColorPlot() |
|
834 | 877 | specObj1 = ColorPlot() |
|
835 | 878 | |
|
836 | 879 | baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", True, True) |
|
837 | 880 | specObj.setup(2, "Spectrum", "Frequency", "Range", "br_green", False, True) |
|
838 | 881 | |
|
839 | 882 | baseObj1.setup(3, "Spectrum", "Frequency", "Range", "br_green", False, True) |
|
840 | 883 | specObj1.setup(4, "Spectrum", "Frequency", "Range", "br_green", False, True) |
|
841 | 884 | |
|
842 | 885 | data = numpy.random.uniform(-50,50,(nx,ny)) |
|
843 | 886 | |
|
844 | 887 | plplot.plbop() |
|
845 | baseObj.iniSubpage() | |
|
846 | 888 | baseObj.plotData(data) |
|
847 | 889 | |
|
848 | specObj.iniSubpage() | |
|
849 | 890 | specObj.plotData(data) |
|
850 | 891 | |
|
851 | baseObj1.iniSubpage() | |
|
852 | 892 | baseObj1.plotData(data) |
|
853 | 893 | |
|
854 | specObj1.iniSubpage() | |
|
855 | 894 | specObj1.plotData(data) |
|
856 | 895 | |
|
857 | 896 | plplot.plflush() |
|
858 | 897 | |
|
859 | 898 | plplot.plspause(1) |
|
860 | 899 | plplot.plend() |
|
861 | 900 | exit(0) |
|
862 | 901 | |
|
863 | 902 |
@@ -1,178 +1,203 | |||
|
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 os, sys |
|
9 | 9 | import numpy |
|
10 | 10 | import datetime |
|
11 | 11 | import plplot |
|
12 | 12 | |
|
13 | 13 | path = os.path.split(os.getcwd())[0] |
|
14 | 14 | sys.path.append(path) |
|
15 | 15 | |
|
16 | 16 | from Graphics.BaseGraph import * |
|
17 | 17 | from Model.Spectra import Spectra |
|
18 | 18 | |
|
19 |
class Spectrum |
|
|
19 | class Spectrum: | |
|
20 | ||
|
21 | __isPlotConfig = False | |
|
22 | ||
|
23 | __isPlotIni = False | |
|
24 | ||
|
25 | __xrange = None | |
|
26 | ||
|
27 | __yrange = None | |
|
20 | 28 | |
|
29 | nGraphs = 0 | |
|
30 | ||
|
31 | indexPlot = None | |
|
32 | ||
|
33 | graphObjList = [] | |
|
34 | ||
|
35 | spectraObj = Spectra | |
|
36 | ||
|
37 | colorGraphObj = ColorPlot() | |
|
38 | m_Spectra= Spectra() | |
|
39 | ||
|
40 | ||
|
41 | m_ColorPlot= ColorPlot() | |
|
42 | ||
|
43 | ||
|
44 | ||
|
45 | ||
|
46 | ||
|
21 | 47 | def __init__(self, Spectra, index=0): |
|
22 | 48 | |
|
23 | 49 | """ |
|
24 | 50 | |
|
25 | 51 | Inputs: |
|
26 | 52 | |
|
27 | 53 | type: "power" ->> Potencia |
|
28 | 54 | "iq" ->> Real + Imaginario |
|
29 | 55 | """ |
|
30 | 56 | |
|
31 | 57 | self.__isPlotConfig = False |
|
32 | 58 | |
|
33 | 59 | self.__isPlotIni = False |
|
34 | 60 | |
|
35 | 61 | self.__xrange = None |
|
36 | 62 | |
|
37 | 63 | self.__yrange = None |
|
38 | 64 | |
|
39 | 65 | self.nGraphs = 0 |
|
40 | 66 | |
|
41 | 67 | self.indexPlot = index |
|
42 | 68 | |
|
43 | 69 | self.graphObjList = [] |
|
44 | 70 | |
|
45 |
self. |
|
|
71 | self.spectraObj = Spectra | |
|
46 | 72 | |
|
47 | 73 | |
|
48 | 74 | def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False): |
|
49 | 75 | |
|
50 | 76 | graphObj = ColorPlot() |
|
51 | 77 | graphObj.setup(subpage, |
|
52 | 78 | title, |
|
53 | 79 | xlabel, |
|
54 | 80 | ylabel, |
|
55 | 81 | showColorbar=showColorbar, |
|
56 | 82 | showPowerProfile=showPowerProfile, |
|
57 | 83 | XAxisAsTime=XAxisAsTime) |
|
58 | 84 | |
|
59 | 85 | self.graphObjList.append(graphObj) |
|
60 | 86 | |
|
61 | 87 | |
|
62 | 88 | def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False): |
|
63 | 89 | |
|
64 |
nChan = int(self. |
|
|
90 | nChan = int(self.spectraObj.m_SystemHeader.numChannels) | |
|
65 | 91 | channels = range(nChan) |
|
66 | 92 | |
|
67 | 93 | myXlabel = "Radial Velocity (m/s)" |
|
68 | 94 | myYlabel = "Range (km)" |
|
69 | 95 | |
|
70 | 96 | for i in channels: |
|
71 | 97 | if titleList != None: |
|
72 | 98 | myTitle = titleList[i] |
|
73 | 99 | myXlabel = xlabelList[i] |
|
74 | 100 | myYlabel = ylabelList[i] |
|
75 | 101 | |
|
76 |
# if self. |
|
|
77 |
# noise = '%4.2fdB' %(self. |
|
|
102 | # if self.spectraObj.m_NoiseObj != None: | |
|
103 | # noise = '%4.2fdB' %(self.spectraObj.m_NoiseObj[i]) | |
|
78 | 104 | # else: |
|
79 | 105 | noise = '--' |
|
80 | 106 | |
|
81 | 107 | myTitle = "Channel: %d - Noise: %s" %(i, noise) |
|
82 | 108 | |
|
83 | 109 | self.__addGraph(i+1, |
|
84 | 110 | title=myTitle, |
|
85 | 111 | xlabel=myXlabel, |
|
86 | 112 | ylabel=myYlabel, |
|
87 | 113 | showColorbar=showColorbar, |
|
88 | 114 | showPowerProfile=showPowerProfile, |
|
89 | 115 | XAxisAsTime=XAxisAsTime) |
|
90 | 116 | |
|
91 | 117 | self.nGraphs = nChan |
|
92 | 118 | self.__isPlotConfig = True |
|
93 | 119 | |
|
94 | 120 | def iniPlot(self, winTitle=""): |
|
95 | 121 | |
|
96 | 122 | nx = int(numpy.sqrt(self.nGraphs)+1) |
|
97 | 123 | #ny = int(self.nGraphs/nx) |
|
98 | 124 | |
|
99 | 125 | plplot.plsstrm(self.indexPlot) |
|
100 | 126 | plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) |
|
101 | 127 | plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx)) |
|
102 | 128 | plplot.plsdev("xwin") |
|
103 | 129 | plplot.plscolbg(255,255,255) |
|
104 | 130 | plplot.plscol0(1,0,0,0) |
|
105 | 131 | plplot.plinit() |
|
106 | 132 | plplot.plspause(False) |
|
107 | 133 | plplot.pladv(0) |
|
108 | 134 | plplot.plssub(nx, nx) |
|
109 | 135 | |
|
110 | 136 | self.__nx = nx |
|
111 | 137 | self.__ny = nx |
|
112 | 138 | self.__isPlotIni = True |
|
113 | 139 | |
|
114 | 140 | |
|
115 | 141 | def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False, winTitle="Spectra"): |
|
116 | 142 | |
|
117 | 143 | if not(self.__isPlotConfig): |
|
118 | 144 | self.setup(titleList, |
|
119 | 145 | xlabelList, |
|
120 | 146 | ylabelList, |
|
121 | 147 | showColorbar, |
|
122 | 148 | showPowerProfile, |
|
123 | 149 | XAxisAsTime) |
|
124 | 150 | |
|
125 | 151 | if not(self.__isPlotIni): |
|
126 | 152 | self.iniPlot(winTitle) |
|
127 | 153 | |
|
128 | 154 | plplot.plsstrm(self.indexPlot) |
|
129 | 155 | |
|
130 |
data = 10.*numpy.log10(self. |
|
|
156 | data = 10.*numpy.log10(self.spectraObj.data_spc) | |
|
131 | 157 | |
|
132 | 158 | #data.shape = Channels x Heights x Profiles |
|
133 | 159 | # data = numpy.transpose( data, (0,2,1) ) |
|
134 | 160 | #data.shape = Channels x Profiles x Heights |
|
135 | 161 | |
|
136 | 162 | nChan, nX, nY = numpy.shape(data) |
|
137 | 163 | |
|
138 | 164 | x = numpy.arange(nX) |
|
139 |
y = self. |
|
|
165 | y = self.spectraObj.heightList | |
|
140 | 166 | |
|
141 |
thisDatetime = datetime.datetime.fromtimestamp(self. |
|
|
167 | thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc) | |
|
142 | 168 | txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
143 | 169 | |
|
144 | 170 | if xmin == None: xmin = x[0] |
|
145 | 171 | if xmax == None: xmax = x[-1] |
|
146 | 172 | if ymin == None: ymin = y[0] |
|
147 | 173 | if ymax == None: ymax = y[-1] |
|
148 | 174 | if zmin == None: zmin = numpy.nanmin(abs(data)) |
|
149 | 175 | if zmax == None: zmax = numpy.nanmax(abs(data)) |
|
150 | 176 | |
|
151 | 177 | plplot.plbop() |
|
152 | 178 | |
|
153 | 179 | plplot.plssub(self.__nx, self.__ny) |
|
154 | 180 | for i in range(self.nGraphs): |
|
155 | self.graphObjList[i].iniSubpage() | |
|
156 | 181 | self.graphObjList[i].plotData(data[i,:,:], |
|
157 | 182 | x, |
|
158 | 183 | y, |
|
159 | 184 | xmin=xmin, |
|
160 | 185 | xmax=xmax, |
|
161 | 186 | ymin=ymin, |
|
162 | 187 | ymax=ymax, |
|
163 | 188 | zmin=zmin, |
|
164 | 189 | zmax=zmax) |
|
165 | 190 | |
|
166 | 191 | plplot.plssub(1,0) |
|
167 | 192 | plplot.pladv(0) |
|
168 | 193 | plplot.plvpor(0., 1., 0., 1.) |
|
169 | 194 | plplot.plmtex("t",-1., 0.5, 0.5, txtDate) |
|
170 | 195 | plplot.plflush() |
|
171 | 196 | plplot.pleop() |
|
172 | 197 | |
|
173 | 198 | def end(self): |
|
174 | 199 | plplot.plend() |
|
175 | ||
|
200 | ||
|
176 | 201 | |
|
177 | 202 | if __name__ == '__main__': |
|
178 | 203 | pass No newline at end of file |
@@ -1,182 +1,207 | |||
|
1 | ''' | |
|
2 | Created on Feb 7, 2012 | |
|
3 | ||
|
4 | @author $Author$ | |
|
5 | @version $Id$ | |
|
6 | ''' | |
|
7 | import os, sys | |
|
8 | import numpy | |
|
9 | import plplot | |
|
10 | ||
|
11 | path = os.path.split(os.getcwd())[0] | |
|
12 | sys.path.append(path) | |
|
13 | ||
|
14 | from Graphics.BaseGraph import * | |
|
15 | from Model.Voltage import Voltage | |
|
16 | ||
|
17 |
class Osciloscope |
|
|
18 | ||
|
19 | def __init__(self, Voltage, index=0): | |
|
20 |
|
|
|
21 | """ | |
|
22 |
|
|
|
23 | Inputs: | |
|
24 |
|
|
|
25 | type: "power" ->> Potencia | |
|
26 | "iq" ->> Real + Imaginario | |
|
27 | """ | |
|
28 |
|
|
|
29 | self.__isPlotConfig = False | |
|
30 |
|
|
|
31 | self.__isPlotIni = False | |
|
32 |
|
|
|
33 | self.__xrange = None | |
|
34 |
|
|
|
35 | self.__yrange = None | |
|
36 |
|
|
|
37 | self.m_Voltage = None | |
|
38 | ||
|
39 | self.nGraphs = 0 | |
|
40 | ||
|
41 | self.indexPlot = index | |
|
42 | ||
|
43 | self.graphObjList = [] | |
|
44 | ||
|
45 | self.m_Voltage = Voltage | |
|
46 |
|
|
|
47 | ||
|
48 | def __addGraph(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): | |
|
49 | ||
|
50 | graphObj = LinearPlot() | |
|
51 | graphObj.setup(subpage, title="", xlabel="", ylabel="", XAxisAsTime=False) | |
|
52 | #graphObj.setScreenPos() | |
|
53 | ||
|
54 | self.graphObjList.append(graphObj) | |
|
55 | ||
|
56 | del graphObj | |
|
57 | ||
|
58 | # def setXRange(self, xmin, xmax): | |
|
59 |
|
|
|
60 |
|
|
|
61 | # def setYRange(self, ymin, ymax): | |
|
62 | # self.__yrange = (ymin, ymax) | |
|
63 | ||
|
64 | ||
|
65 | def setup(self, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False): | |
|
66 | ||
|
67 | nChan = int(self.m_Voltage.m_SystemHeader.numChannels) | |
|
68 | ||
|
69 | myTitle = "" | |
|
70 | myXlabel = "" | |
|
71 | myYlabel = "" | |
|
72 | ||
|
73 | for chan in range(nChan): | |
|
74 | if titleList != None: | |
|
75 | myTitle = titleList[chan] | |
|
76 | myXlabel = xlabelList[chan] | |
|
77 | myYlabel = ylabelList[chan] | |
|
78 | ||
|
79 | self.__addGraph(chan+1, title=myTitle, xlabel=myXlabel, ylabel=myYlabel, XAxisAsTime=XAxisAsTime) | |
|
80 | ||
|
81 | self.nGraphs = nChan | |
|
82 | self.__isPlotConfig = True | |
|
83 | ||
|
84 | def iniPlot(self, winTitle=""): | |
|
85 | ||
|
86 | plplot.plsstrm(self.indexPlot) | |
|
87 | plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) | |
|
88 | plplot.plsetopt("geometry", "%dx%d" %(700, 115*self.nGraphs)) | |
|
89 | plplot.plsdev("xwin") | |
|
90 | plplot.plscolbg(255,255,255) | |
|
91 | plplot.plscol0(1,0,0,0) | |
|
92 | plplot.plinit() | |
|
93 | plplot.plspause(False) | |
|
94 | plplot.plssub(1, self.nGraphs) | |
|
95 | ||
|
96 | self.__isPlotIni = True | |
|
97 | ||
|
98 | def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, idProfile=None, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False, type='iq', winTitle="Voltage"): | |
|
99 | ||
|
100 | if idProfile != None and idProfile != self.m_Voltage.idProfile: | |
|
101 | return | |
|
102 | ||
|
103 | if not(self.__isPlotConfig): | |
|
104 | self.setup(titleList, xlabelList, ylabelList, XAxisAsTime) | |
|
105 | ||
|
106 | if not(self.__isPlotIni): | |
|
107 | self.iniPlot(winTitle) | |
|
108 | ||
|
109 | plplot.plsstrm(self.indexPlot) | |
|
110 | ||
|
111 | data = self.m_Voltage.data | |
|
112 | ||
|
113 | x = self.m_Voltage.heights | |
|
114 | ||
|
115 | if xmin == None: xmin = x[0] | |
|
116 | if xmax == None: xmax = x[-1] | |
|
117 | if ymin == None: ymin = numpy.nanmin(abs(data)) | |
|
118 | if ymax == None: ymax = numpy.nanmax(abs(data)) | |
|
119 | ||
|
120 |
plplot.plb |
|
|
121 | for chan in range(self.nGraphs): | |
|
122 | y = data[chan,:] | |
|
123 | ||
|
124 | self.graphObjList[chan].iniSubpage() | |
|
125 | self.graphObjList[chan].plotComplexData(x, y, xmin, xmax, ymin, ymax, 8, type) | |
|
126 | ||
|
127 | plplot.plflush() | |
|
128 | plplot.pleop() | |
|
129 | ||
|
130 | def end(self): | |
|
131 | plplot.plend() | |
|
132 | ||
|
133 | class VoltagePlot(object): | |
|
134 | ''' | |
|
135 | classdocs | |
|
136 | ''' | |
|
137 | ||
|
138 | __m_Voltage = None | |
|
139 | ||
|
140 | def __init__(self, m_Voltage): | |
|
141 | ''' | |
|
142 | Constructor | |
|
143 | ''' | |
|
144 | self.__m_Voltage = m_Voltage | |
|
145 | ||
|
146 | def setup(self): | |
|
147 | pass | |
|
148 | ||
|
149 | def addGraph(self, type, xrange=None, yrange=None, zrange=None): | |
|
150 | pass | |
|
151 | ||
|
152 | def plotData(self): | |
|
153 | pass | |
|
154 | ||
|
155 | if __name__ == '__main__': | |
|
156 | ||
|
157 | import numpy | |
|
158 | ||
|
159 | plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2)) | |
|
160 | plplot.plsdev("xcairo") | |
|
161 | plplot.plscolbg(255,255,255) | |
|
162 | plplot.plscol0(1,0,0,0) | |
|
163 | plplot.plinit() | |
|
164 | plplot.plssub(1, 2) | |
|
165 | ||
|
166 | nx = 64 | |
|
167 | ny = 100 | |
|
168 | ||
|
169 | data = numpy.random.uniform(-50,50,(nx,ny)) | |
|
170 | ||
|
171 | baseObj = RTI() | |
|
172 | baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False) | |
|
173 | baseObj.plotData(data) | |
|
174 | ||
|
175 | data = numpy.random.uniform(-50,50,(nx,ny)) | |
|
176 | ||
|
177 | base2Obj = RTI() | |
|
178 | base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True) | |
|
179 | base2Obj.plotData(data) | |
|
180 | ||
|
181 | plplot.plend() | |
|
1 | ''' | |
|
2 | Created on Feb 7, 2012 | |
|
3 | ||
|
4 | @author $Author$ | |
|
5 | @version $Id$ | |
|
6 | ''' | |
|
7 | import os, sys | |
|
8 | import numpy | |
|
9 | import plplot | |
|
10 | ||
|
11 | path = os.path.split(os.getcwd())[0] | |
|
12 | sys.path.append(path) | |
|
13 | ||
|
14 | from Graphics.BaseGraph import * | |
|
15 | from Model.Voltage import Voltage | |
|
16 | ||
|
17 | class Osciloscope: | |
|
18 | ||
|
19 | voltageObj = Voltage() | |
|
20 | ||
|
21 | linearGraphObj = LinearPlot() | |
|
22 | ||
|
23 | __isPlotConfig = False | |
|
24 | ||
|
25 | __isPlotIni = False | |
|
26 | ||
|
27 | __xrange = None | |
|
28 | ||
|
29 | __yrange = None | |
|
30 | ||
|
31 | voltageObj = Voltage() | |
|
32 | ||
|
33 | nGraphs = 0 | |
|
34 | ||
|
35 | indexPlot = None | |
|
36 | ||
|
37 | graphObjList = [] | |
|
38 | m_LinearPlot= LinearPlot() | |
|
39 | ||
|
40 | ||
|
41 | m_Voltage= Voltage() | |
|
42 | ||
|
43 | ||
|
44 | ||
|
45 | def __init__(self, Voltage, index=0): | |
|
46 | ||
|
47 | """ | |
|
48 | ||
|
49 | Inputs: | |
|
50 | ||
|
51 | type: "power" ->> Potencia | |
|
52 | "iq" ->> Real + Imaginario | |
|
53 | """ | |
|
54 | ||
|
55 | self.__isPlotConfig = False | |
|
56 | ||
|
57 | self.__isPlotIni = False | |
|
58 | ||
|
59 | self.__xrange = None | |
|
60 | ||
|
61 | self.__yrange = None | |
|
62 | ||
|
63 | self.voltageObj = None | |
|
64 | ||
|
65 | self.nGraphs = 0 | |
|
66 | ||
|
67 | self.indexPlot = index | |
|
68 | ||
|
69 | self.graphObjList = [] | |
|
70 | ||
|
71 | self.voltageObj = Voltage | |
|
72 | ||
|
73 | ||
|
74 | def __addGraph(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): | |
|
75 | ||
|
76 | graphObj = LinearPlot() | |
|
77 | graphObj.setup(subpage, title="", xlabel="", ylabel="", XAxisAsTime=False) | |
|
78 | #graphObj.setScreenPos() | |
|
79 | ||
|
80 | self.graphObjList.append(graphObj) | |
|
81 | ||
|
82 | del graphObj | |
|
83 | ||
|
84 | # def setXRange(self, xmin, xmax): | |
|
85 | # self.__xrange = (xmin, xmax) | |
|
86 | # | |
|
87 | # def setYRange(self, ymin, ymax): | |
|
88 | # self.__yrange = (ymin, ymax) | |
|
89 | ||
|
90 | ||
|
91 | def setup(self, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False): | |
|
92 | ||
|
93 | nChan = int(self.voltageObj.m_SystemHeader.numChannels) | |
|
94 | ||
|
95 | myTitle = "" | |
|
96 | myXlabel = "" | |
|
97 | myYlabel = "" | |
|
98 | ||
|
99 | for chan in range(nChan): | |
|
100 | if titleList != None: | |
|
101 | myTitle = titleList[chan] | |
|
102 | myXlabel = xlabelList[chan] | |
|
103 | myYlabel = ylabelList[chan] | |
|
104 | ||
|
105 | self.__addGraph(chan+1, title=myTitle, xlabel=myXlabel, ylabel=myYlabel, XAxisAsTime=XAxisAsTime) | |
|
106 | ||
|
107 | self.nGraphs = nChan | |
|
108 | self.__isPlotConfig = True | |
|
109 | ||
|
110 | def iniPlot(self, winTitle=""): | |
|
111 | ||
|
112 | plplot.plsstrm(self.indexPlot) | |
|
113 | plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL) | |
|
114 | plplot.plsetopt("geometry", "%dx%d" %(700, 115*self.nGraphs)) | |
|
115 | plplot.plsdev("xwin") | |
|
116 | plplot.plscolbg(255,255,255) | |
|
117 | plplot.plscol0(1,0,0,0) | |
|
118 | plplot.plinit() | |
|
119 | plplot.plspause(False) | |
|
120 | plplot.plssub(1, self.nGraphs) | |
|
121 | ||
|
122 | self.__isPlotIni = True | |
|
123 | ||
|
124 | def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, idProfile=None, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False, type='iq', winTitle="Voltage"): | |
|
125 | ||
|
126 | if idProfile != None and idProfile != self.voltageObj.idProfile: | |
|
127 | return | |
|
128 | ||
|
129 | if not(self.__isPlotConfig): | |
|
130 | self.setup(titleList, xlabelList, ylabelList, XAxisAsTime) | |
|
131 | ||
|
132 | if not(self.__isPlotIni): | |
|
133 | self.iniPlot(winTitle) | |
|
134 | ||
|
135 | plplot.plsstrm(self.indexPlot) | |
|
136 | ||
|
137 | data = self.voltageObj.data | |
|
138 | ||
|
139 | x = self.voltageObj.heights | |
|
140 | ||
|
141 | if xmin == None: xmin = x[0] | |
|
142 | if xmax == None: xmax = x[-1] | |
|
143 | if ymin == None: ymin = numpy.nanmin(abs(data)) | |
|
144 | if ymax == None: ymax = numpy.nanmax(abs(data)) | |
|
145 | ||
|
146 | plplot.plbop() | |
|
147 | for chan in range(self.nGraphs): | |
|
148 | y = data[chan,:] | |
|
149 | ||
|
150 | self.graphObjList[chan].plotComplexData(x, y, xmin, xmax, ymin, ymax, 8, type) | |
|
151 | ||
|
152 | plplot.plflush() | |
|
153 | plplot.pleop() | |
|
154 | ||
|
155 | def end(self): | |
|
156 | plplot.plend() | |
|
157 | ||
|
158 | class VoltagePlot(object): | |
|
159 | ''' | |
|
160 | classdocs | |
|
161 | ''' | |
|
162 | ||
|
163 | __m_Voltage = None | |
|
164 | ||
|
165 | def __init__(self, voltageObj): | |
|
166 | ''' | |
|
167 | Constructor | |
|
168 | ''' | |
|
169 | self.__m_Voltage = voltageObj | |
|
170 | ||
|
171 | def setup(self): | |
|
172 | pass | |
|
173 | ||
|
174 | def addGraph(self, type, xrange=None, yrange=None, zrange=None): | |
|
175 | pass | |
|
176 | ||
|
177 | def plotData(self): | |
|
178 | pass | |
|
179 | ||
|
180 | if __name__ == '__main__': | |
|
181 | ||
|
182 | import numpy | |
|
183 | ||
|
184 | plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2)) | |
|
185 | plplot.plsdev("xcairo") | |
|
186 | plplot.plscolbg(255,255,255) | |
|
187 | plplot.plscol0(1,0,0,0) | |
|
188 | plplot.plinit() | |
|
189 | plplot.plssub(1, 2) | |
|
190 | ||
|
191 | nx = 64 | |
|
192 | ny = 100 | |
|
193 | ||
|
194 | data = numpy.random.uniform(-50,50,(nx,ny)) | |
|
195 | ||
|
196 | baseObj = RTI() | |
|
197 | baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False) | |
|
198 | baseObj.plotData(data) | |
|
199 | ||
|
200 | data = numpy.random.uniform(-50,50,(nx,ny)) | |
|
201 | ||
|
202 | base2Obj = RTI() | |
|
203 | base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True) | |
|
204 | base2Obj.plotData(data) | |
|
205 | ||
|
206 | plplot.plend() | |
|
182 | 207 | exit(0) No newline at end of file |
@@ -1,18 +1,22 | |||
|
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 | class CorrelationProcessor: |
|
9 | 9 | ''' |
|
10 | 10 | classdocs |
|
11 | 11 | ''' |
|
12 | 12 | |
|
13 | 13 | |
|
14 | 14 | def __init__(self): |
|
15 | 15 | ''' |
|
16 | 16 | Constructor |
|
17 | 17 | ''' |
|
18 | pass No newline at end of file | |
|
18 | pass | |
|
19 | m_Correlation= Correlation() | |
|
20 | ||
|
21 | m_Voltage= Voltage() | |
|
22 |
@@ -1,112 +1,112 | |||
|
1 | import numpy | |
|
2 | from Model.Spectra import Spectra | |
|
3 | ||
|
4 | def hildebrand_sekhon(Data, navg=1): | |
|
5 | """ | |
|
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 | |
|
8 | densities is equal to the mean spectral density for white Gaussian noise | |
|
9 | ||
|
10 | Inputs: | |
|
11 | Data : heights | |
|
12 | navg : numbers of averages | |
|
13 | ||
|
14 | Return: | |
|
15 | -1 : any error | |
|
16 | anoise : noise's level | |
|
17 | """ | |
|
18 | divisor = 8 | |
|
19 | ratio = 7 / divisor | |
|
20 | data = Data.reshape(-1) | |
|
21 | npts = data.size #numbers of points of the data | |
|
22 | ||
|
23 | if npts < 32: | |
|
24 | print "error in noise - requires at least 32 points" | |
|
25 | return -1.0 | |
|
26 | ||
|
27 | # data sorted in ascending order | |
|
28 | nmin = int(npts/divisor + ratio); | |
|
29 | s = 0.0 | |
|
30 | s2 = 0.0 | |
|
31 | data2 = data[:npts] | |
|
32 | data2.sort() | |
|
33 | ||
|
34 | for i in range(nmin): | |
|
35 | s += data2[i] | |
|
36 | s2 += data2[i]**2; | |
|
37 | ||
|
38 | icount = nmin | |
|
39 | iflag = 0 | |
|
40 | ||
|
41 | for i in range(nmin, npts): | |
|
42 | s += data2[i]; | |
|
43 | s2 += data2[i]**2 | |
|
44 | icount=icount+1; | |
|
45 | p = s / float(icount); | |
|
46 | p2 = p**2; | |
|
47 | q = s2 / float(icount) - p2; | |
|
48 | leftc = p2; | |
|
49 | rightc = q * float(navg); | |
|
50 | ||
|
51 | if leftc > rightc: | |
|
52 | iflag = 1; #No weather signal | |
|
53 | # Signal detect: R2 < 1 (R2 = leftc/rightc) | |
|
54 | if(leftc < rightc): | |
|
55 | if iflag: | |
|
56 | break | |
|
57 | ||
|
58 | anoise = 0.0; | |
|
59 | for j in range(i): | |
|
60 | anoise += data2[j]; | |
|
61 | ||
|
62 | anoise = anoise / float(i); | |
|
63 | ||
|
64 | return anoise; | |
|
65 | ||
|
66 | ||
|
67 |
class Noise |
|
|
68 | """ | |
|
69 | Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler | |
|
70 | """ | |
|
71 | m_DataObj = None | |
|
72 | ||
|
73 | ||
|
74 | def __init__(self, m_Spectra=None): | |
|
75 | """ | |
|
76 | Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. | |
|
77 | ||
|
78 | Affected: | |
|
79 | self.m_DataObj | |
|
80 | ||
|
81 | Return: | |
|
82 | None | |
|
83 | """ | |
|
84 | if m_Spectra == None: | |
|
85 | m_Spectra = Spectra() | |
|
86 | ||
|
87 | if not(isinstance(m_Spectra, Spectra)): | |
|
88 | raise ValueError, "in Noise class, m_Spectra must be an Spectra class object" | |
|
89 | ||
|
90 | self.m_DataObj = m_Spectra | |
|
91 | ||
|
92 | ||
|
93 | def getNoiseLevelByHildebrandSekhon(self): | |
|
94 | """ | |
|
95 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
|
96 | ||
|
97 | Return: | |
|
98 | noise level | |
|
99 | """ | |
|
100 | data = self.m_DataObj.data_spc | |
|
101 | daux = None | |
|
102 | ||
|
103 | for channel in range(self.m_DataObj.nChannels): | |
|
104 | daux = data[channel,:,:] | |
|
105 | noiselevel = hildebrand_sekhon(daux) | |
|
106 | print noiselevel | |
|
107 | ||
|
108 | ||
|
109 | for pair in range(self.m_DataObj.nPairs): | |
|
110 | daux = data[pair,:,:] | |
|
111 | noiselevel = hildebrand_sekhon(daux) | |
|
112 | print noiselevel | |
|
1 | import numpy | |
|
2 | from Model.Spectra import Spectra | |
|
3 | ||
|
4 | def hildebrand_sekhon(Data, navg=1): | |
|
5 | """ | |
|
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 | |
|
8 | densities is equal to the mean spectral density for white Gaussian noise | |
|
9 | ||
|
10 | Inputs: | |
|
11 | Data : heights | |
|
12 | navg : numbers of averages | |
|
13 | ||
|
14 | Return: | |
|
15 | -1 : any error | |
|
16 | anoise : noise's level | |
|
17 | """ | |
|
18 | divisor = 8 | |
|
19 | ratio = 7 / divisor | |
|
20 | data = Data.reshape(-1) | |
|
21 | npts = data.size #numbers of points of the data | |
|
22 | ||
|
23 | if npts < 32: | |
|
24 | print "error in noise - requires at least 32 points" | |
|
25 | return -1.0 | |
|
26 | ||
|
27 | # data sorted in ascending order | |
|
28 | nmin = int(npts/divisor + ratio); | |
|
29 | s = 0.0 | |
|
30 | s2 = 0.0 | |
|
31 | data2 = data[:npts] | |
|
32 | data2.sort() | |
|
33 | ||
|
34 | for i in range(nmin): | |
|
35 | s += data2[i] | |
|
36 | s2 += data2[i]**2; | |
|
37 | ||
|
38 | icount = nmin | |
|
39 | iflag = 0 | |
|
40 | ||
|
41 | for i in range(nmin, npts): | |
|
42 | s += data2[i]; | |
|
43 | s2 += data2[i]**2 | |
|
44 | icount=icount+1; | |
|
45 | p = s / float(icount); | |
|
46 | p2 = p**2; | |
|
47 | q = s2 / float(icount) - p2; | |
|
48 | leftc = p2; | |
|
49 | rightc = q * float(navg); | |
|
50 | ||
|
51 | if leftc > rightc: | |
|
52 | iflag = 1; #No weather signal | |
|
53 | # Signal detect: R2 < 1 (R2 = leftc/rightc) | |
|
54 | if(leftc < rightc): | |
|
55 | if iflag: | |
|
56 | break | |
|
57 | ||
|
58 | anoise = 0.0; | |
|
59 | for j in range(i): | |
|
60 | anoise += data2[j]; | |
|
61 | ||
|
62 | anoise = anoise / float(i); | |
|
63 | ||
|
64 | return anoise; | |
|
65 | ||
|
66 | ||
|
67 | class Noise: | |
|
68 | """ | |
|
69 | Clase que implementa los metodos necesarios para deternimar el nivel de ruido en un Spectro Doppler | |
|
70 | """ | |
|
71 | m_DataObj = None | |
|
72 | ||
|
73 | ||
|
74 | def __init__(self, m_Spectra=None): | |
|
75 | """ | |
|
76 | Inicializador de la clase Noise para la la determinacion del nivel de ruido en un Spectro Doppler. | |
|
77 | ||
|
78 | Affected: | |
|
79 | self.m_DataObj | |
|
80 | ||
|
81 | Return: | |
|
82 | None | |
|
83 | """ | |
|
84 | if m_Spectra == None: | |
|
85 | m_Spectra = Spectra() | |
|
86 | ||
|
87 | if not(isinstance(m_Spectra, Spectra)): | |
|
88 | raise ValueError, "in Noise class, m_Spectra must be an Spectra class object" | |
|
89 | ||
|
90 | self.m_DataObj = m_Spectra | |
|
91 | ||
|
92 | ||
|
93 | def getNoiseLevelByHildebrandSekhon(self): | |
|
94 | """ | |
|
95 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
|
96 | ||
|
97 | Return: | |
|
98 | noise level | |
|
99 | """ | |
|
100 | data = self.m_DataObj.data_spc | |
|
101 | daux = None | |
|
102 | ||
|
103 | for channel in range(self.m_DataObj.nChannels): | |
|
104 | daux = data[channel,:,:] | |
|
105 | noiselevel = hildebrand_sekhon(daux) | |
|
106 | print noiselevel | |
|
107 | ||
|
108 | ||
|
109 | for pair in range(self.m_DataObj.nPairs): | |
|
110 | daux = data[pair,:,:] | |
|
111 | noiselevel = hildebrand_sekhon(daux) | |
|
112 | print noiselevel |
@@ -1,511 +1,553 | |||
|
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 | 9 | |
|
10 | 10 | path = os.path.split(os.getcwd())[0] |
|
11 | 11 | sys.path.append(path) |
|
12 | 12 | |
|
13 | 13 | from Model.Spectra import Spectra |
|
14 | 14 | from IO.SpectraIO import SpectraWriter |
|
15 | 15 | from Graphics.SpectraPlot import Spectrum |
|
16 | 16 | |
|
17 | 17 | |
|
18 | 18 | class SpectraProcessor: |
|
19 | 19 | ''' |
|
20 | 20 | classdocs |
|
21 | 21 | ''' |
|
22 | 22 | |
|
23 | dataInObj = None | |
|
24 | ||
|
25 | dataOutObj = None | |
|
26 | ||
|
27 | integratorObjIndex = None | |
|
28 | ||
|
29 | decoderObjIndex = None | |
|
30 | ||
|
31 | writerObjIndex = None | |
|
32 | ||
|
33 | plotterObjIndex = None | |
|
34 | ||
|
35 | integratorObjList = [] | |
|
36 | ||
|
37 | decoderObjList = [] | |
|
38 | ||
|
39 | writerObjList = [] | |
|
40 | ||
|
41 | plotterObjList = [] | |
|
42 | ||
|
43 | buffer = None | |
|
44 | ||
|
45 | ptsId = 0 | |
|
46 | ||
|
47 | nFFTPoints = None | |
|
48 | ||
|
49 | pairList = None | |
|
50 | m_Spectra= Spectra() | |
|
51 | ||
|
52 | m_Voltage= Voltage() | |
|
53 | ||
|
54 | m_IncoherentIntegration= IncoherentIntegration() | |
|
55 | ||
|
56 | ||
|
23 | 57 | def __init__(self, dataInObj, dataOutObj=None): |
|
24 | 58 | ''' |
|
25 | 59 | Constructor |
|
26 | 60 | ''' |
|
27 | 61 | self.dataInObj = dataInObj |
|
28 | 62 | |
|
29 | 63 | if dataOutObj == None: |
|
30 | 64 | self.dataOutObj = Spectra() |
|
31 | 65 | else: |
|
32 | 66 | self.dataOutObj = dataOutObj |
|
33 | 67 | |
|
34 | self.integratorIndex = None | |
|
35 | self.decoderIndex = None | |
|
36 | self.writerIndex = None | |
|
37 | self.plotterIndex = None | |
|
68 | self.integratorObjIndex = None | |
|
69 | self.decoderObjIndex = None | |
|
70 | self.writerObjIndex = None | |
|
71 | self.plotterObjIndex = None | |
|
38 | 72 | |
|
39 | self.integratorList = [] | |
|
40 | self.decoderList = [] | |
|
41 | self.writerList = [] | |
|
42 | self.plotterList = [] | |
|
73 | self.integratorObjList = [] | |
|
74 | self.decoderObjList = [] | |
|
75 | self.writerObjList = [] | |
|
76 | self.plotterObjList = [] | |
|
43 | 77 | |
|
44 | 78 | self.buffer = None |
|
45 | 79 | self.ptsId = 0 |
|
46 | 80 | |
|
47 | 81 | def init(self, nFFTPoints, pairList=None): |
|
48 | 82 | |
|
49 | self.integratorIndex = 0 | |
|
50 | self.decoderIndex = 0 | |
|
51 | self.writerIndex = 0 | |
|
52 | self.plotterIndex = 0 | |
|
83 | self.integratorObjIndex = 0 | |
|
84 | self.decoderObjIndex = 0 | |
|
85 | self.writerObjIndex = 0 | |
|
86 | self.plotterObjIndex = 0 | |
|
53 | 87 | |
|
54 | 88 | if nFFTPoints == None: |
|
55 | 89 | nFFTPoints = self.dataOutObj.nFFTPoints |
|
56 | 90 | |
|
57 | 91 | self.nFFTPoints = nFFTPoints |
|
58 | 92 | self.pairList = pairList |
|
59 | 93 | |
|
60 | 94 | if not( isinstance(self.dataInObj, Spectra) ): |
|
61 | 95 | self.__getFft() |
|
62 | 96 | else: |
|
63 | 97 | self.dataOutObj.copy(self.dataInObj) |
|
64 | 98 | |
|
65 | 99 | |
|
66 | 100 | def __getFft(self): |
|
67 | 101 | """ |
|
68 | 102 | Convierte valores de Voltaje a Spectra |
|
69 | 103 | |
|
70 | 104 | Affected: |
|
71 | 105 | self.dataOutObj.data_spc |
|
72 | 106 | self.dataOutObj.data_cspc |
|
73 | 107 | self.dataOutObj.data_dc |
|
74 | 108 | self.dataOutObj.heightList |
|
75 | 109 | self.dataOutObj.m_BasicHeader |
|
76 | 110 | self.dataOutObj.m_ProcessingHeader |
|
77 | 111 | self.dataOutObj.m_RadarControllerHeader |
|
78 | 112 | self.dataOutObj.m_SystemHeader |
|
79 | 113 | self.ptsId |
|
80 | 114 | self.buffer |
|
81 | 115 | self.dataOutObj.flagNoData |
|
82 | 116 | self.dataOutObj.dataType |
|
83 | 117 | self.dataOutObj.nPairs |
|
84 | 118 | self.dataOutObj.nChannels |
|
85 | 119 | self.dataOutObj.nProfiles |
|
86 | 120 | self.dataOutObj.m_SystemHeader.numChannels |
|
87 | 121 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
88 | 122 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock |
|
89 | 123 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
90 | 124 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
91 | 125 | self.dataOutObj.m_ProcessingHeader.shif_fft |
|
92 | 126 | """ |
|
93 | 127 | blocksize = 0 |
|
94 | 128 | nFFTPoints = self.nFFTPoints |
|
95 | 129 | nChannels, nheis = self.dataInObj.data.shape |
|
96 | 130 | |
|
97 | 131 | if self.buffer == None: |
|
98 | 132 | self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex') |
|
99 | 133 | |
|
100 | 134 | self.buffer[:,self.ptsId,:] = self.dataInObj.data |
|
101 | 135 | self.ptsId += 1 |
|
102 | 136 | |
|
103 | 137 | if self.ptsId < self.dataOutObj.nFFTPoints: |
|
104 | 138 | self.dataOutObj.flagNoData = True |
|
105 | 139 | return |
|
106 | 140 | |
|
107 | 141 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
108 | 142 | dc = fft_volt[:,0,:] |
|
109 | 143 | |
|
110 | 144 | #calculo de self-spectra |
|
111 | 145 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
112 | 146 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt)) |
|
113 | 147 | |
|
114 | 148 | blocksize += dc.size |
|
115 | 149 | blocksize += spc.size |
|
116 | 150 | |
|
117 | 151 | cspc = None |
|
118 | 152 | nPair = 0 |
|
119 | 153 | if self.pairList != None: |
|
120 | 154 | #calculo de cross-spectra |
|
121 | 155 | nPairs = len(self.pairList) |
|
122 | 156 | cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex') |
|
123 | 157 | for pair in self.pairList: |
|
124 | 158 | cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])) |
|
125 | 159 | nPair += 1 |
|
126 | 160 | blocksize += cspc.size |
|
127 | 161 | |
|
128 | 162 | self.dataOutObj.data_spc = spc |
|
129 | 163 | self.dataOutObj.data_cspc = cspc |
|
130 | 164 | self.dataOutObj.data_dc = dc |
|
131 | 165 | |
|
132 | 166 | self.ptsId = 0 |
|
133 | 167 | self.buffer = None |
|
134 | 168 | self.dataOutObj.flagNoData = False |
|
135 | 169 | |
|
136 | 170 | self.dataOutObj.heightList = self.dataInObj.heightList |
|
137 | 171 | self.dataOutObj.channelList = self.dataInObj.channelList |
|
138 | 172 | self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy() |
|
139 | 173 | self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy() |
|
140 | 174 | self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy() |
|
141 | 175 | self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy() |
|
142 | 176 | |
|
143 | 177 | self.dataOutObj.dataType = self.dataInObj.dataType |
|
144 | 178 | self.dataOutObj.nPairs = nPair |
|
145 | 179 | self.dataOutObj.nChannels = nChannels |
|
146 | 180 | self.dataOutObj.nProfiles = nFFTPoints |
|
147 | 181 | self.dataOutObj.nHeights = nheis |
|
148 | 182 | self.dataOutObj.nFFTPoints = nFFTPoints |
|
149 | 183 | #self.dataOutObj.data = None |
|
150 | 184 | |
|
151 | 185 | self.dataOutObj.m_SystemHeader.numChannels = nChannels |
|
152 | 186 | self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints |
|
153 | 187 | |
|
154 | 188 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
155 | 189 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair |
|
156 | 190 | self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints |
|
157 | 191 | self.dataOutObj.m_ProcessingHeader.numHeights = nheis |
|
158 | 192 | self.dataOutObj.m_ProcessingHeader.shif_fft = True |
|
159 | 193 | |
|
160 | 194 | spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1')) |
|
161 | 195 | k = 0 |
|
162 | 196 | for i in range( 0,nChannels*2,2 ): |
|
163 | 197 | spectraComb[i] = k |
|
164 | 198 | spectraComb[i+1] = k |
|
165 | 199 | k += 1 |
|
166 | 200 | |
|
167 | 201 | k *= 2 |
|
168 | 202 | |
|
169 | 203 | if self.pairList != None: |
|
170 | 204 | |
|
171 | 205 | for pair in self.pairList: |
|
172 | 206 | spectraComb[k] = pair[0] |
|
173 | 207 | spectraComb[k+1] = pair[1] |
|
174 | 208 | k += 2 |
|
175 | 209 | |
|
176 | 210 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
177 | 211 | |
|
178 | 212 | |
|
179 | 213 | def addWriter(self,wrpath): |
|
180 | 214 | objWriter = SpectraWriter(self.dataOutObj) |
|
181 | 215 | objWriter.setup(wrpath) |
|
182 | self.writerList.append(objWriter) | |
|
216 | self.writerObjList.append(objWriter) | |
|
183 | 217 | |
|
184 | 218 | |
|
185 | 219 | def addPlotter(self, index=None): |
|
186 | 220 | |
|
187 | 221 | if index==None: |
|
188 | index = self.plotterIndex | |
|
222 | index = self.plotterObjIndex | |
|
189 | 223 | |
|
190 | 224 | plotObj = Spectrum(self.dataOutObj, index) |
|
191 | self.plotterList.append(plotObj) | |
|
225 | self.plotterObjList.append(plotObj) | |
|
192 | 226 | |
|
193 | 227 | |
|
194 | 228 | def addIntegrator(self,N): |
|
195 | 229 | |
|
196 | 230 | objIncohInt = IncoherentIntegration(N) |
|
197 | self.integratorList.append(objIncohInt) | |
|
231 | self.integratorObjList.append(objIncohInt) | |
|
198 | 232 | |
|
199 | 233 | |
|
200 | 234 | def writeData(self, wrpath): |
|
201 | 235 | if self.dataOutObj.flagNoData: |
|
202 | 236 | return 0 |
|
203 | 237 | |
|
204 | if len(self.writerList) <= self.writerIndex: | |
|
238 | if len(self.writerObjList) <= self.writerObjIndex: | |
|
205 | 239 | self.addWriter(wrpath) |
|
206 | 240 | |
|
207 | self.writerList[self.writerIndex].putData() | |
|
241 | self.writerObjList[self.writerObjIndex].putData() | |
|
208 | 242 | |
|
209 | self.writerIndex += 1 | |
|
243 | self.writerObjIndex += 1 | |
|
210 | 244 | |
|
211 | 245 | def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None): |
|
212 | 246 | if self.dataOutObj.flagNoData: |
|
213 | 247 | return 0 |
|
214 | 248 | |
|
215 | if len(self.plotterList) <= self.plotterIndex: | |
|
249 | if len(self.plotterObjList) <= self.plotterObjIndex: | |
|
216 | 250 | self.addPlotter(index) |
|
217 | 251 | |
|
218 | self.plotterList[self.plotterIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) | |
|
252 | self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) | |
|
219 | 253 | |
|
220 | self.plotterIndex += 1 | |
|
254 | self.plotterObjIndex += 1 | |
|
221 | 255 | |
|
222 | 256 | def integrator(self, N): |
|
223 | 257 | if self.dataOutObj.flagNoData: |
|
224 | 258 | return 0 |
|
225 | 259 | |
|
226 | if len(self.integratorList) <= self.integratorIndex: | |
|
260 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
|
227 | 261 | self.addIntegrator(N) |
|
228 | 262 | |
|
229 | myCohIntObj = self.integratorList[self.integratorIndex] | |
|
263 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] | |
|
230 | 264 | myCohIntObj.exe(self.dataOutObj.data_spc) |
|
231 | 265 | |
|
232 | 266 | if myCohIntObj.flag: |
|
233 | 267 | self.dataOutObj.data_spc = myCohIntObj.data |
|
234 | 268 | self.dataOutObj.m_ProcessingHeader.incoherentInt *= N |
|
235 | 269 | self.dataOutObj.flagNoData = False |
|
236 | 270 | |
|
237 | 271 | else: |
|
238 | 272 | self.dataOutObj.flagNoData = True |
|
239 | 273 | |
|
240 | self.integratorIndex += 1 | |
|
274 | self.integratorObjIndex += 1 | |
|
241 | 275 | |
|
242 | 276 | def removeDC(self, type): |
|
243 | 277 | |
|
244 | 278 | if self.dataOutObj.flagNoData: |
|
245 | 279 | return 0 |
|
246 | 280 | pass |
|
247 | 281 | |
|
248 | 282 | def removeInterference(self): |
|
249 | 283 | |
|
250 | 284 | if self.dataOutObj.flagNoData: |
|
251 | 285 | return 0 |
|
252 | 286 | pass |
|
253 | 287 | |
|
254 | 288 | def removeSatellites(self): |
|
255 | 289 | |
|
256 | 290 | if self.dataOutObj.flagNoData: |
|
257 | 291 | return 0 |
|
258 | 292 | pass |
|
259 | 293 | |
|
260 | 294 | def selectChannels(self, channelList, pairList=None): |
|
261 | 295 | """ |
|
262 | 296 | Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList |
|
263 | 297 | |
|
264 | 298 | Input: |
|
265 | 299 | channelList : lista sencilla de canales a seleccionar por ej. (2,3,7) |
|
266 | 300 | pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) ) |
|
267 | 301 | |
|
268 | 302 | Affected: |
|
269 | 303 | self.dataOutObj.data_spc |
|
270 | 304 | self.dataOutObj.data_cspc |
|
271 | 305 | self.dataOutObj.data_dc |
|
272 | 306 | self.dataOutObj.nChannels |
|
273 | 307 | self.dataOutObj.nPairs |
|
274 | 308 | self.dataOutObj.m_ProcessingHeader.spectraComb |
|
275 | 309 | self.dataOutObj.m_SystemHeader.numChannels |
|
276 | 310 | |
|
277 | 311 | Return: |
|
278 | 312 | None |
|
279 | 313 | """ |
|
280 | 314 | |
|
281 | 315 | if self.dataOutObj.flagNoData: |
|
282 | 316 | return 0 |
|
283 | 317 | |
|
284 | 318 | channelIndexList = [] |
|
285 | 319 | for channel in channelList: |
|
286 | 320 | if channel in self.dataOutObj.channelList: |
|
287 | 321 | index = self.dataOutObj.channelList.index(channel) |
|
288 | 322 | channelIndexList.append(index) |
|
289 | 323 | continue |
|
290 | 324 | |
|
291 | 325 | raise ValueError, "The value %d in channelList is not valid" %channel |
|
292 | 326 | |
|
293 | 327 | nProfiles = self.dataOutObj.nProfiles |
|
294 | 328 | #dataType = self.dataOutObj.dataType |
|
295 | 329 | nHeights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights |
|
296 | 330 | blocksize = 0 |
|
297 | 331 | |
|
298 | 332 | #self spectra |
|
299 | 333 | nChannels = len(channelIndexList) |
|
300 | 334 | spc = numpy.zeros( (nChannels,nProfiles,nHeights), dtype='float' ) #dataType[0] ) |
|
301 | 335 | |
|
302 | 336 | for index, channel in enumerate(channelIndexList): |
|
303 | 337 | spc[index,:,:] = self.dataOutObj.data_spc[index,:,:] |
|
304 | 338 | |
|
305 | 339 | #DC channel |
|
306 | 340 | dc = numpy.zeros( (nChannels,nHeights), dtype='complex' ) |
|
307 | 341 | for index, channel in enumerate(channelIndexList): |
|
308 | 342 | dc[index,:] = self.dataOutObj.data_dc[channel,:] |
|
309 | 343 | |
|
310 | 344 | blocksize += dc.size |
|
311 | 345 | blocksize += spc.size |
|
312 | 346 | |
|
313 | 347 | nPairs = 0 |
|
314 | 348 | cspc = None |
|
315 | 349 | |
|
316 | 350 | if pairList == None: |
|
317 | 351 | pairList = self.pairList |
|
318 | 352 | |
|
319 | 353 | if (pairList != None) and (self.dataOutObj.data_cspc != None): |
|
320 | 354 | #cross spectra |
|
321 | 355 | nPairs = len(pairList) |
|
322 | 356 | cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' ) |
|
323 | 357 | |
|
324 | 358 | spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb |
|
325 | 359 | totalSpectra = len(spectraComb) |
|
326 | 360 | nchan = self.dataOutObj.nChannels |
|
327 | 361 | pairIndexList = [] |
|
328 | 362 | |
|
329 | 363 | for pair in pairList: #busco el par en la lista de pares del Spectra Combinations |
|
330 | 364 | for index in range(0,totalSpectra,2): |
|
331 | 365 | if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]: |
|
332 | 366 | pairIndexList.append( index/2 - nchan ) |
|
333 | 367 | |
|
334 | 368 | for index, pair in enumerate(pairIndexList): |
|
335 | 369 | cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:] |
|
336 | 370 | blocksize += cspc.size |
|
337 | 371 | |
|
338 | 372 | else: |
|
339 | 373 | pairList = self.pairList |
|
340 | 374 | cspc = self.dataOutObj.data_cspc |
|
341 | 375 | if cspc != None: |
|
342 | 376 | blocksize += cspc.size |
|
343 | 377 | |
|
344 | 378 | spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1')) |
|
345 | 379 | i = 0 |
|
346 | 380 | for val in channelList: |
|
347 | 381 | spectraComb[i] = val |
|
348 | 382 | spectraComb[i+1] = val |
|
349 | 383 | i += 2 |
|
350 | 384 | |
|
351 | 385 | if pairList != None: |
|
352 | 386 | for pair in pairList: |
|
353 | 387 | spectraComb[i] = pair[0] |
|
354 | 388 | spectraComb[i+1] = pair[1] |
|
355 | 389 | i += 2 |
|
356 | 390 | |
|
357 | 391 | self.dataOutObj.data_spc = spc |
|
358 | 392 | self.dataOutObj.data_cspc = cspc |
|
359 | 393 | self.dataOutObj.data_dc = dc |
|
360 | 394 | self.dataOutObj.nChannels = nChannels |
|
361 | 395 | self.dataOutObj.nPairs = nPairs |
|
362 | 396 | |
|
363 | 397 | self.dataOutObj.channelList = channelList |
|
364 | 398 | |
|
365 | 399 | self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb |
|
366 | 400 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs |
|
367 | 401 | self.dataOutObj.m_SystemHeader.numChannels = nChannels |
|
368 | 402 | self.dataOutObj.nChannels = nChannels |
|
369 | 403 | self.dataOutObj.m_ProcessingHeader.blockSize = blocksize |
|
370 | 404 | |
|
371 | 405 | |
|
372 | 406 | def selectHeightsByValue(self, minHei, maxHei): |
|
373 | 407 | """ |
|
374 | 408 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
375 | 409 | minHei <= height <= maxHei |
|
376 | 410 | |
|
377 | 411 | Input: |
|
378 | 412 | minHei : valor minimo de altura a considerar |
|
379 | 413 | maxHei : valor maximo de altura a considerar |
|
380 | 414 | |
|
381 | 415 | Affected: |
|
382 | 416 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
383 | 417 | |
|
384 | 418 | Return: |
|
385 | 419 | None |
|
386 | 420 | """ |
|
387 | 421 | |
|
388 | 422 | if self.dataOutObj.flagNoData: |
|
389 | 423 | return 0 |
|
390 | 424 | |
|
391 | 425 | if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei): |
|
392 | 426 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
393 | 427 | |
|
394 | 428 | if (maxHei > self.dataOutObj.heightList[-1]): |
|
395 | 429 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
396 | 430 | |
|
397 | 431 | minIndex = 0 |
|
398 | 432 | maxIndex = 0 |
|
399 | 433 | data = self.dataOutObj.heightList |
|
400 | 434 | |
|
401 | 435 | for i,val in enumerate(data): |
|
402 | 436 | if val < minHei: |
|
403 | 437 | continue |
|
404 | 438 | else: |
|
405 | 439 | minIndex = i; |
|
406 | 440 | break |
|
407 | 441 | |
|
408 | 442 | for i,val in enumerate(data): |
|
409 | 443 | if val <= maxHei: |
|
410 | 444 | maxIndex = i; |
|
411 | 445 | else: |
|
412 | 446 | break |
|
413 | 447 | |
|
414 | 448 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
415 | 449 | |
|
416 | 450 | |
|
417 | 451 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
418 | 452 | """ |
|
419 | 453 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
420 | 454 | minIndex <= index <= maxIndex |
|
421 | 455 | |
|
422 | 456 | Input: |
|
423 | 457 | minIndex : valor minimo de altura a considerar |
|
424 | 458 | maxIndex : valor maximo de altura a considerar |
|
425 | 459 | |
|
426 | 460 | Affected: |
|
427 | 461 | self.dataOutObj.data_spc |
|
428 | 462 | self.dataOutObj.data_cspc |
|
429 | 463 | self.dataOutObj.data_dc |
|
430 | 464 | self.dataOutObj.heightList |
|
431 | 465 | self.dataOutObj.nHeights |
|
432 | 466 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
433 | 467 | self.dataOutObj.m_ProcessingHeader.blockSize |
|
434 | 468 | self.dataOutObj.m_ProcessingHeader.firstHeight |
|
435 | 469 | self.dataOutObj.m_RadarControllerHeader.numHeights |
|
436 | 470 | |
|
437 | 471 | Return: |
|
438 | 472 | None |
|
439 | 473 | """ |
|
440 | 474 | |
|
441 | 475 | if self.dataOutObj.flagNoData: |
|
442 | 476 | return 0 |
|
443 | 477 | |
|
444 | 478 | if (minIndex < 0) or (minIndex > maxIndex): |
|
445 | 479 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
446 | 480 | |
|
447 | 481 | if (maxIndex >= self.dataOutObj.nHeights): |
|
448 | 482 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
449 | 483 | |
|
450 | 484 | nChannels = self.dataOutObj.nChannels |
|
451 | 485 | nPairs = self.dataOutObj.nPairs |
|
452 | 486 | nProfiles = self.dataOutObj.nProfiles |
|
453 | 487 | dataType = self.dataOutObj.dataType |
|
454 | 488 | nHeights = maxIndex - minIndex + 1 |
|
455 | 489 | blockSize = 0 |
|
456 | 490 | |
|
457 | 491 | #self spectra |
|
458 | 492 | spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1] |
|
459 | 493 | blockSize += spc.size |
|
460 | 494 | |
|
461 | 495 | #cross spectra |
|
462 | 496 | cspc = None |
|
463 | 497 | if self.dataOutObj.data_cspc != None: |
|
464 | 498 | cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1] |
|
465 | 499 | blockSize += cspc.size |
|
466 | 500 | |
|
467 | 501 | #DC channel |
|
468 | 502 | dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1] |
|
469 | 503 | blockSize += dc.size |
|
470 | 504 | |
|
471 | 505 | self.dataOutObj.data_spc = spc |
|
472 | 506 | if cspc != None: |
|
473 | 507 | self.dataOutObj.data_cspc = cspc |
|
474 | 508 | self.dataOutObj.data_dc = dc |
|
475 | 509 | |
|
476 | 510 | firstHeight = self.dataOutObj.heightList[minIndex] |
|
477 | 511 | |
|
478 | 512 | self.dataOutObj.nHeights = nHeights |
|
479 | 513 | self.dataOutObj.m_ProcessingHeader.blockSize = blockSize |
|
480 | 514 | self.dataOutObj.m_ProcessingHeader.numHeights = nHeights |
|
481 | 515 | self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight |
|
482 | 516 | self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights |
|
483 | 517 | |
|
484 | 518 | self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1] |
|
485 | 519 | |
|
486 | 520 | |
|
487 | 521 | class IncoherentIntegration: |
|
522 | ||
|
523 | profCounter = 1 | |
|
524 | data = None | |
|
525 | buffer = None | |
|
526 | flag = False | |
|
527 | nIncohInt = None | |
|
528 | ||
|
488 | 529 | def __init__(self, N): |
|
530 | ||
|
489 | 531 | self.profCounter = 1 |
|
490 | 532 | self.data = None |
|
491 | 533 | self.buffer = None |
|
492 | 534 | self.flag = False |
|
493 | 535 | self.nIncohInt = N |
|
494 | 536 | |
|
495 | 537 | def exe(self,data): |
|
496 | 538 | |
|
497 | 539 | if self.buffer == None: |
|
498 | 540 | self.buffer = data |
|
499 | 541 | else: |
|
500 | 542 | self.buffer = self.buffer + data |
|
501 | 543 | |
|
502 | 544 | if self.profCounter == self.nIncohInt: |
|
503 | 545 | self.data = self.buffer |
|
504 | 546 | self.buffer = None |
|
505 | 547 | self.profCounter = 0 |
|
506 | 548 | self.flag = True |
|
507 | 549 | else: |
|
508 | 550 | self.flag = False |
|
509 | 551 | |
|
510 | 552 | self.profCounter += 1 |
|
511 | 553 |
@@ -1,464 +1,503 | |||
|
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 os, sys |
|
9 | 9 | import numpy |
|
10 | 10 | |
|
11 | 11 | path = os.path.split(os.getcwd())[0] |
|
12 | 12 | sys.path.append(path) |
|
13 | 13 | |
|
14 | 14 | from Model.Voltage import Voltage |
|
15 | 15 | from IO.VoltageIO import VoltageWriter |
|
16 | 16 | from Graphics.VoltagePlot import Osciloscope |
|
17 | 17 | |
|
18 | 18 | class VoltageProcessor: |
|
19 | 19 | ''' |
|
20 | 20 | classdocs |
|
21 | 21 | ''' |
|
22 | ||
|
23 | dataInObj = None | |
|
24 | dataOutObj = None | |
|
25 | ||
|
26 | integratorObjIndex = None | |
|
27 | decoderObjIndex = None | |
|
28 | profSelectorObjIndex = None | |
|
29 | writerObjIndex = None | |
|
30 | plotterObjIndex = None | |
|
31 | ||
|
32 | integratorObjList = [] | |
|
33 | decoderObjList = [] | |
|
34 | profileSelectorObjList = [] | |
|
35 | writerObjList = [] | |
|
36 | plotterObjList = [] | |
|
37 | m_Voltage= Voltage() | |
|
38 | ||
|
39 | m_ProfileSelector= ProfileSelector() | |
|
22 | 40 | |
|
23 | def __init__(self, voltageInObj, voltageOutObj=None): | |
|
41 | m_Decoder= Decoder() | |
|
42 | ||
|
43 | m_CoherentIntegrator= CoherentIntegrator() | |
|
44 | ||
|
45 | ||
|
46 | def __init__(self, dataInObj, dataOutObj=None): | |
|
24 | 47 | ''' |
|
25 | 48 | Constructor |
|
26 | 49 | ''' |
|
27 | 50 | |
|
28 |
self. |
|
|
51 | self.dataInObj = dataInObj | |
|
29 | 52 | |
|
30 |
if |
|
|
31 |
self. |
|
|
53 | if dataOutObj == None: | |
|
54 | self.dataOutObj = Voltage() | |
|
32 | 55 | else: |
|
33 |
self. |
|
|
56 | self.dataOutObj = dataOutObj | |
|
34 | 57 | |
|
35 | self.integratorIndex = None | |
|
36 | self.decoderIndex = None | |
|
37 | self.profSelectorIndex = None | |
|
38 | self.writerIndex = None | |
|
39 | self.plotterIndex = None | |
|
40 | ||
|
41 | self.integratorList = [] | |
|
42 | self.decoderList = [] | |
|
43 | self.profileSelectorList = [] | |
|
44 | self.writerList = [] | |
|
45 | self.plotterList = [] | |
|
58 | self.integratorObjIndex = None | |
|
59 | self.decoderObjIndex = None | |
|
60 | self.profSelectorObjIndex = None | |
|
61 | self.writerObjIndex = None | |
|
62 | self.plotterObjIndex = None | |
|
63 | ||
|
64 | self.integratorObjList = [] | |
|
65 | self.decoderObjList = [] | |
|
66 | self.profileSelectorObjList = [] | |
|
67 | self.writerObjList = [] | |
|
68 | self.plotterObjList = [] | |
|
46 | 69 | |
|
47 | 70 | def init(self): |
|
48 | 71 | |
|
49 | self.integratorIndex = 0 | |
|
50 | self.decoderIndex = 0 | |
|
51 | self.profSelectorIndex = 0 | |
|
52 | self.writerIndex = 0 | |
|
53 | self.plotterIndex = 0 | |
|
54 |
self. |
|
|
72 | self.integratorObjIndex = 0 | |
|
73 | self.decoderObjIndex = 0 | |
|
74 | self.profSelectorObjIndex = 0 | |
|
75 | self.writerObjIndex = 0 | |
|
76 | self.plotterObjIndex = 0 | |
|
77 | self.dataOutObj.copy(self.dataInObj) | |
|
55 | 78 | |
|
56 | 79 | def addWriter(self, wrpath): |
|
57 |
objWriter = VoltageWriter(self. |
|
|
80 | objWriter = VoltageWriter(self.dataOutObj) | |
|
58 | 81 | objWriter.setup(wrpath) |
|
59 | self.writerList.append(objWriter) | |
|
82 | self.writerObjList.append(objWriter) | |
|
60 | 83 | |
|
61 | 84 | def addPlotter(self): |
|
62 | 85 | |
|
63 |
plotObj = Osciloscope(self. |
|
|
64 | self.plotterList.append(plotObj) | |
|
86 | plotObj = Osciloscope(self.dataOutObj,self.plotterObjIndex) | |
|
87 | self.plotterObjList.append(plotObj) | |
|
65 | 88 | |
|
66 | 89 | def addIntegrator(self, nCohInt): |
|
67 | 90 | |
|
68 | 91 | objCohInt = CoherentIntegrator(nCohInt) |
|
69 | self.integratorList.append(objCohInt) | |
|
92 | self.integratorObjList.append(objCohInt) | |
|
70 | 93 | |
|
71 | 94 | def addDecoder(self, code, ncode, nbaud): |
|
72 | 95 | |
|
73 | 96 | objDecoder = Decoder(code,ncode,nbaud) |
|
74 | self.decoderList.append(objDecoder) | |
|
97 | self.decoderObjList.append(objDecoder) | |
|
75 | 98 | |
|
76 | 99 | def addProfileSelector(self, nProfiles): |
|
77 | 100 | |
|
78 | 101 | objProfSelector = ProfileSelector(nProfiles) |
|
79 | self.profileSelectorList.append(objProfSelector) | |
|
102 | self.profileSelectorObjList.append(objProfSelector) | |
|
80 | 103 | |
|
81 | 104 | def writeData(self,wrpath): |
|
82 | 105 | |
|
83 |
if self. |
|
|
106 | if self.dataOutObj.flagNoData: | |
|
84 | 107 | return 0 |
|
85 | 108 | |
|
86 | if len(self.writerList) <= self.writerIndex: | |
|
109 | if len(self.writerObjList) <= self.writerObjIndex: | |
|
87 | 110 | self.addWriter(wrpath) |
|
88 | 111 | |
|
89 | self.writerList[self.writerIndex].putData() | |
|
112 | self.writerObjList[self.writerObjIndex].putData() | |
|
90 | 113 | |
|
91 | # myWrObj = self.writerList[self.writerIndex] | |
|
114 | # myWrObj = self.writerObjList[self.writerObjIndex] | |
|
92 | 115 | # myWrObj.putData() |
|
93 | 116 | |
|
94 | self.writerIndex += 1 | |
|
117 | self.writerObjIndex += 1 | |
|
95 | 118 | |
|
96 | 119 | def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''): |
|
97 |
if self. |
|
|
120 | if self.dataOutObj.flagNoData: | |
|
98 | 121 | return 0 |
|
99 | 122 | |
|
100 | if len(self.plotterList) <= self.plotterIndex: | |
|
123 | if len(self.plotterObjList) <= self.plotterObjIndex: | |
|
101 | 124 | self.addPlotter() |
|
102 | 125 | |
|
103 | self.plotterList[self.plotterIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) | |
|
126 | self.plotterObjList[self.plotterObjIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) | |
|
104 | 127 | |
|
105 | self.plotterIndex += 1 | |
|
128 | self.plotterObjIndex += 1 | |
|
106 | 129 | |
|
107 | 130 | def integrator(self, N): |
|
108 | 131 | |
|
109 |
if self. |
|
|
132 | if self.dataOutObj.flagNoData: | |
|
110 | 133 | return 0 |
|
111 | 134 | |
|
112 | if len(self.integratorList) <= self.integratorIndex: | |
|
135 | if len(self.integratorObjList) <= self.integratorObjIndex: | |
|
113 | 136 | self.addIntegrator(N) |
|
114 | 137 | |
|
115 | myCohIntObj = self.integratorList[self.integratorIndex] | |
|
116 |
myCohIntObj.exe(self. |
|
|
138 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] | |
|
139 | myCohIntObj.exe(self.dataOutObj.data) | |
|
117 | 140 | |
|
118 | 141 | if myCohIntObj.flag: |
|
119 |
self. |
|
|
120 |
self. |
|
|
121 |
self. |
|
|
142 | self.dataOutObj.data = myCohIntObj.data | |
|
143 | self.dataOutObj.m_ProcessingHeader.coherentInt *= N | |
|
144 | self.dataOutObj.flagNoData = False | |
|
122 | 145 | |
|
123 | 146 | else: |
|
124 |
self. |
|
|
147 | self.dataOutObj.flagNoData = True | |
|
125 | 148 | |
|
126 | self.integratorIndex += 1 | |
|
149 | self.integratorObjIndex += 1 | |
|
127 | 150 | |
|
128 | 151 | def decoder(self,code=None,type = 0): |
|
129 | 152 | |
|
130 |
if self. |
|
|
153 | if self.dataOutObj.flagNoData: | |
|
131 | 154 | return 0 |
|
132 | 155 | |
|
133 | 156 | if code == None: |
|
134 |
code = self. |
|
|
157 | code = self.dataOutObj.m_RadarControllerHeader.code | |
|
135 | 158 | ncode, nbaud = code.shape |
|
136 | 159 | |
|
137 | if len(self.decoderList) <= self.decoderIndex: | |
|
160 | if len(self.decoderObjList) <= self.decoderObjIndex: | |
|
138 | 161 | self.addDecoder(code,ncode,nbaud) |
|
139 | 162 | |
|
140 | myDecodObj = self.decoderList[self.decoderIndex] | |
|
141 |
myDecodObj.exe(data=self. |
|
|
163 | myDecodObj = self.decoderObjList[self.decoderObjIndex] | |
|
164 | myDecodObj.exe(data=self.dataOutObj.data,type=type) | |
|
142 | 165 | |
|
143 | 166 | if myDecodObj.flag: |
|
144 |
self. |
|
|
145 |
self. |
|
|
167 | self.dataOutObj.data = myDecodObj.data | |
|
168 | self.dataOutObj.flagNoData = False | |
|
146 | 169 | else: |
|
147 |
self. |
|
|
170 | self.dataOutObj.flagNoData = True | |
|
148 | 171 | |
|
149 | self.decoderIndex += 1 | |
|
172 | self.decoderObjIndex += 1 | |
|
150 | 173 | |
|
151 | 174 | |
|
152 | 175 | def filterByHei(self, window): |
|
153 | 176 | pass |
|
154 | 177 | |
|
155 | 178 | |
|
156 | 179 | def selectChannels(self, channelList): |
|
157 | 180 | """ |
|
158 | 181 | Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList |
|
159 | 182 | |
|
160 | 183 | Input: |
|
161 | 184 | channelList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
162 | 185 | |
|
163 | 186 | Affected: |
|
164 | 187 | self.dataOutObj.data |
|
165 |
self. |
|
|
188 | self.dataOutObj.channelList | |
|
166 | 189 | self.dataOutObj.nChannels |
|
167 |
self. |
|
|
190 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
|
168 | 191 | self.dataOutObj.m_SystemHeader.numChannels |
|
169 |
self. |
|
|
192 | self.dataOutObj.m_ProcessingHeader.blockSize | |
|
170 | 193 | |
|
171 | 194 | Return: |
|
172 | 195 | None |
|
173 | 196 | """ |
|
174 |
if self. |
|
|
197 | if self.dataOutObj.flagNoData: | |
|
175 | 198 | return 0 |
|
176 | 199 | |
|
177 | 200 | for channel in channelList: |
|
178 |
if channel not in self. |
|
|
201 | if channel not in self.dataOutObj.channelList: | |
|
179 | 202 | raise ValueError, "The value %d in channelList is not valid" %channel |
|
180 | 203 | |
|
181 | 204 | nchannels = len(channelList) |
|
182 |
profiles = self. |
|
|
183 |
heights = self. |
|
|
205 | profiles = self.dataOutObj.nProfiles | |
|
206 | heights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights | |
|
184 | 207 | |
|
185 | 208 | data = numpy.zeros( (nchannels,heights), dtype='complex' ) |
|
186 | 209 | for index,channel in enumerate(channelList): |
|
187 |
data[index,:] = self. |
|
|
210 | data[index,:] = self.dataOutObj.data[channel,:] | |
|
188 | 211 | |
|
189 |
self. |
|
|
190 |
self. |
|
|
191 |
self. |
|
|
192 |
self. |
|
|
193 |
self. |
|
|
194 |
self. |
|
|
212 | self.dataOutObj.data = data | |
|
213 | self.dataOutObj.channelList = channelList | |
|
214 | self.dataOutObj.nChannels = nchannels | |
|
215 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nchannels | |
|
216 | self.dataOutObj.m_SystemHeader.numChannels = nchannels | |
|
217 | self.dataOutObj.m_ProcessingHeader.blockSize = data.size | |
|
195 | 218 | return 1 |
|
196 | 219 | |
|
197 | 220 | |
|
198 | 221 | def selectHeightsByValue(self, minHei, maxHei): |
|
199 | 222 | """ |
|
200 | 223 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
201 | 224 | minHei <= height <= maxHei |
|
202 | 225 | |
|
203 | 226 | Input: |
|
204 | 227 | minHei : valor minimo de altura a considerar |
|
205 | 228 | maxHei : valor maximo de altura a considerar |
|
206 | 229 | |
|
207 | 230 | Affected: |
|
208 | 231 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
209 | 232 | |
|
210 | 233 | Return: |
|
211 | 234 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
212 | 235 | """ |
|
213 |
if self. |
|
|
236 | if self.dataOutObj.flagNoData: | |
|
214 | 237 | return 0 |
|
215 | 238 | |
|
216 |
if (minHei < self. |
|
|
239 | if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei): | |
|
217 | 240 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
218 | 241 | |
|
219 |
if (maxHei > self. |
|
|
242 | if (maxHei > self.dataOutObj.heightList[-1]): | |
|
220 | 243 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
221 | 244 | |
|
222 | 245 | minIndex = 0 |
|
223 | 246 | maxIndex = 0 |
|
224 |
data = self. |
|
|
247 | data = self.dataOutObj.heightList | |
|
225 | 248 | |
|
226 | 249 | for i,val in enumerate(data): |
|
227 | 250 | if val < minHei: |
|
228 | 251 | continue |
|
229 | 252 | else: |
|
230 | 253 | minIndex = i; |
|
231 | 254 | break |
|
232 | 255 | |
|
233 | 256 | for i,val in enumerate(data): |
|
234 | 257 | if val <= maxHei: |
|
235 | 258 | maxIndex = i; |
|
236 | 259 | else: |
|
237 | 260 | break |
|
238 | 261 | |
|
239 | 262 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
240 | 263 | return 1 |
|
241 | 264 | |
|
242 | 265 | |
|
243 | 266 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
244 | 267 | """ |
|
245 | 268 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
246 | 269 | minIndex <= index <= maxIndex |
|
247 | 270 | |
|
248 | 271 | Input: |
|
249 | 272 | minIndex : valor de indice minimo de altura a considerar |
|
250 | 273 | maxIndex : valor de indice maximo de altura a considerar |
|
251 | 274 | |
|
252 | 275 | Affected: |
|
253 |
self. |
|
|
254 |
self. |
|
|
255 |
self. |
|
|
256 |
self. |
|
|
257 |
self. |
|
|
258 |
self. |
|
|
259 |
self. |
|
|
276 | self.dataOutObj.data | |
|
277 | self.dataOutObj.heightList | |
|
278 | self.dataOutObj.nHeights | |
|
279 | self.dataOutObj.m_ProcessingHeader.blockSize | |
|
280 | self.dataOutObj.m_ProcessingHeader.numHeights | |
|
281 | self.dataOutObj.m_ProcessingHeader.firstHeight | |
|
282 | self.dataOutObj.m_RadarControllerHeader | |
|
260 | 283 | |
|
261 | 284 | Return: |
|
262 | 285 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
263 | 286 | """ |
|
264 |
if self. |
|
|
287 | if self.dataOutObj.flagNoData: | |
|
265 | 288 | return 0 |
|
266 | 289 | |
|
267 | 290 | if (minIndex < 0) or (minIndex > maxIndex): |
|
268 | 291 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
269 | 292 | |
|
270 |
if (maxIndex >= self. |
|
|
293 | if (maxIndex >= self.dataOutObj.nHeights): | |
|
271 | 294 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
272 | 295 | |
|
273 | 296 | nHeights = maxIndex - minIndex + 1 |
|
274 | 297 | firstHeight = 0 |
|
275 | 298 | |
|
276 | 299 | #voltage |
|
277 |
data = self. |
|
|
300 | data = self.dataOutObj.data[:,minIndex:maxIndex+1] | |
|
278 | 301 | |
|
279 |
firstHeight = self. |
|
|
302 | firstHeight = self.dataOutObj.heightList[minIndex] | |
|
280 | 303 | |
|
281 |
self. |
|
|
282 |
self. |
|
|
283 |
self. |
|
|
284 |
self. |
|
|
285 |
self. |
|
|
286 |
self. |
|
|
287 |
self. |
|
|
304 | self.dataOutObj.data = data | |
|
305 | self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1] | |
|
306 | self.dataOutObj.nHeights = nHeights | |
|
307 | self.dataOutObj.m_ProcessingHeader.blockSize = data.size | |
|
308 | self.dataOutObj.m_ProcessingHeader.numHeights = nHeights | |
|
309 | self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight | |
|
310 | self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights | |
|
288 | 311 | return 1 |
|
289 | 312 | |
|
290 | 313 | |
|
291 | 314 | def selectProfiles(self, minIndex, maxIndex, nProfiles): |
|
292 | 315 | """ |
|
293 | 316 | Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango |
|
294 | 317 | minIndex <= index <= maxIndex |
|
295 | 318 | |
|
296 | 319 | Input: |
|
297 | 320 | minIndex : valor de indice minimo de perfil a considerar |
|
298 | 321 | maxIndex : valor de indice maximo de perfil a considerar |
|
299 | 322 | nProfiles : numero de profiles |
|
300 | 323 | |
|
301 | 324 | Affected: |
|
302 |
self. |
|
|
303 | self.profSelectorIndex | |
|
325 | self.dataOutObj.flagNoData | |
|
326 | self.profSelectorObjIndex | |
|
304 | 327 | |
|
305 | 328 | Return: |
|
306 | 329 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
307 | 330 | """ |
|
308 | 331 | |
|
309 |
if self. |
|
|
332 | if self.dataOutObj.flagNoData: | |
|
310 | 333 | return 0 |
|
311 | 334 | |
|
312 | if self.profSelectorIndex >= len(self.profileSelectorList): | |
|
335 | if self.profSelectorObjIndex >= len(self.profileSelectorObjList): | |
|
313 | 336 | self.addProfileSelector(nProfiles) |
|
314 | 337 | |
|
315 | profileSelectorObj = self.profileSelectorList[self.profSelectorIndex] | |
|
338 | profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex] | |
|
316 | 339 | |
|
317 | 340 | if profileSelectorObj.isProfileInRange(minIndex, maxIndex): |
|
318 |
self. |
|
|
319 | self.profSelectorIndex += 1 | |
|
341 | self.dataOutObj.flagNoData = False | |
|
342 | self.profSelectorObjIndex += 1 | |
|
320 | 343 | return 1 |
|
321 | 344 | |
|
322 |
self. |
|
|
323 | self.profSelectorIndex += 1 | |
|
345 | self.dataOutObj.flagNoData = True | |
|
346 | self.profSelectorObjIndex += 1 | |
|
324 | 347 | |
|
325 | 348 | return 0 |
|
326 | 349 | |
|
327 | 350 | def selectNtxs(self, ntx): |
|
328 | 351 | pass |
|
329 | 352 | |
|
330 | 353 | |
|
331 | 354 | class Decoder: |
|
355 | ||
|
356 | data = None | |
|
357 | profCounter = 1 | |
|
358 | nCode = ncode | |
|
359 | nBaud = nbaud | |
|
360 | codeIndex = 0 | |
|
361 | code = code #this is a List | |
|
362 | fft_code = None | |
|
363 | flag = False | |
|
364 | setCodeFft = False | |
|
332 | 365 | |
|
333 | 366 | def __init__(self,code, ncode, nbaud): |
|
334 | 367 | |
|
335 |
self. |
|
|
368 | self.data = None | |
|
336 | 369 | self.profCounter = 1 |
|
337 | 370 | self.nCode = ncode |
|
338 | 371 | self.nBaud = nbaud |
|
339 | 372 | self.codeIndex = 0 |
|
340 | 373 | self.code = code #this is a List |
|
341 | 374 | self.fft_code = None |
|
342 | 375 | self.flag = False |
|
343 | 376 | self.setCodeFft = False |
|
344 | 377 | |
|
345 | 378 | def exe(self, data, ndata=None, type = 0): |
|
346 | 379 | |
|
347 | 380 | if ndata == None: ndata = data.shape[1] |
|
348 | 381 | |
|
349 | 382 | if type == 0: |
|
350 | 383 | self.convolutionInFreq(data,ndata) |
|
351 | 384 | |
|
352 | 385 | if type == 1: |
|
353 | 386 | self.convolutionInTime(data, ndata) |
|
354 | 387 | |
|
355 | 388 | def convolutionInFreq(self,data, ndata): |
|
356 | 389 | |
|
357 | 390 | newcode = numpy.zeros(ndata) |
|
358 | 391 | newcode[0:self.nBaud] = self.code[self.codeIndex] |
|
359 | 392 | |
|
360 | 393 | self.codeIndex += 1 |
|
361 | 394 | |
|
362 | 395 | fft_data = numpy.fft.fft(data, axis=1) |
|
363 | 396 | fft_code = numpy.conj(numpy.fft.fft(newcode)) |
|
364 | 397 | fft_code = fft_code.reshape(1,len(fft_code)) |
|
365 | 398 | |
|
366 | 399 | conv = fft_data.copy() |
|
367 | 400 | conv.fill(0) |
|
368 | 401 | |
|
369 | 402 | conv = fft_data*fft_code # This other way to calculate multiplication between bidimensional arrays |
|
370 | 403 | # for i in range(ndata): |
|
371 | 404 | # conv[i,:] = fft_data[i,:]*fft_code[i] |
|
372 | 405 | |
|
373 | 406 | self.data = numpy.fft.ifft(conv,axis=1) |
|
374 | 407 | self.flag = True |
|
375 | 408 | |
|
376 | 409 | if self.profCounter == self.nCode: |
|
377 | 410 | self.profCounter = 0 |
|
378 | 411 | self.codeIndex = 0 |
|
379 | 412 | |
|
380 | 413 | self.profCounter += 1 |
|
381 | 414 | |
|
382 | 415 | def convolutionInTime(self, data, ndata): |
|
383 | 416 | |
|
384 | 417 | nchannel = data.shape[1] |
|
385 | 418 | newcode = self.code[self.codeIndex] |
|
386 | 419 | self.codeIndex += 1 |
|
387 | 420 | conv = data.copy() |
|
388 | 421 | for i in range(nchannel): |
|
389 | 422 | conv[i,:] = numpy.correlate(data[i,:], newcode, 'same') |
|
390 | 423 | |
|
391 | 424 | self.data = conv |
|
392 | 425 | self.flag = True |
|
393 | 426 | |
|
394 | 427 | if self.profCounter == self.nCode: |
|
395 | 428 | self.profCounter = 0 |
|
396 | 429 | self.codeIndex = 0 |
|
397 | 430 | |
|
398 | 431 | self.profCounter += 1 |
|
399 | 432 | |
|
400 | 433 | |
|
401 | 434 | class CoherentIntegrator: |
|
402 | 435 | |
|
436 | profCounter = 1 | |
|
437 | data = None | |
|
438 | buffer = None | |
|
439 | flag = False | |
|
440 | nCohInt = N | |
|
441 | ||
|
403 | 442 | def __init__(self, N): |
|
404 | 443 | |
|
405 | 444 | self.profCounter = 1 |
|
406 | 445 | self.data = None |
|
407 | 446 | self.buffer = None |
|
408 | 447 | self.flag = False |
|
409 | 448 | self.nCohInt = N |
|
410 | 449 | |
|
411 | 450 | def exe(self, data): |
|
412 | 451 | |
|
413 | 452 | if self.buffer == None: |
|
414 | 453 | self.buffer = data |
|
415 | 454 | else: |
|
416 | 455 | self.buffer = self.buffer + data |
|
417 | 456 | |
|
418 | 457 | if self.profCounter == self.nCohInt: |
|
419 | 458 | self.data = self.buffer |
|
420 | 459 | self.buffer = None |
|
421 | 460 | self.profCounter = 0 |
|
422 | 461 | self.flag = True |
|
423 | 462 | else: |
|
424 | 463 | self.flag = False |
|
425 | 464 | |
|
426 | 465 | self.profCounter += 1 |
|
427 | 466 | |
|
428 |
class ProfileSelector |
|
|
467 | class ProfileSelector: | |
|
429 | 468 | |
|
430 | 469 | indexProfile = None |
|
431 | 470 | # Tamanho total de los perfiles |
|
432 | 471 | nProfiles = None |
|
433 | 472 | |
|
434 | 473 | def __init__(self, nProfiles): |
|
435 | 474 | |
|
436 | 475 | self.indexProfile = 0 |
|
437 | 476 | self.nProfiles = nProfiles |
|
438 | 477 | |
|
439 | 478 | def isProfileInRange(self, minIndex, maxIndex): |
|
440 | 479 | |
|
441 | 480 | if self.indexProfile < minIndex: |
|
442 | 481 | self.indexProfile += 1 |
|
443 | 482 | return False |
|
444 | 483 | |
|
445 | 484 | if self.indexProfile > maxIndex: |
|
446 | 485 | self.indexProfile += 1 |
|
447 | 486 | return False |
|
448 | 487 | |
|
449 | 488 | self.indexProfile += 1 |
|
450 | 489 | |
|
451 | 490 | return True |
|
452 | 491 | |
|
453 | 492 | def isProfileInList(self, profileList): |
|
454 | 493 | |
|
455 | 494 | if self.indexProfile not in profileList: |
|
456 | 495 | self.indexProfile += 1 |
|
457 | 496 | return False |
|
458 | 497 | |
|
459 | 498 | self.indexProfile += 1 |
|
460 | 499 | |
|
461 | 500 | return True |
|
462 | 501 | |
|
463 | 502 | |
|
464 | 503 | No newline at end of file |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now