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