@@ -1,496 +1,497 | |||
|
1 | 1 | import os |
|
2 | 2 | import numpy |
|
3 | 3 | import time, datetime |
|
4 | 4 | import mpldriver |
|
5 | 5 | from customftp import * |
|
6 | 6 | |
|
7 | 7 | class Figure: |
|
8 | 8 | |
|
9 | 9 | __driver = mpldriver |
|
10 | 10 | fig = None |
|
11 | 11 | |
|
12 | 12 | idfigure = None |
|
13 | 13 | wintitle = None |
|
14 | 14 | width = None |
|
15 | 15 | height = None |
|
16 | 16 | nplots = None |
|
17 | 17 | timerange = None |
|
18 | 18 | |
|
19 | 19 | axesObjList = [] |
|
20 | 20 | |
|
21 | 21 | WIDTH = None |
|
22 | 22 | HEIGHT = None |
|
23 | 23 | PREFIX = 'fig' |
|
24 | 24 | |
|
25 | 25 | def __init__(self): |
|
26 | 26 | |
|
27 | 27 | raise ValueError, "This method is not implemented" |
|
28 | 28 | |
|
29 | 29 | def __del__(self): |
|
30 | 30 | |
|
31 | 31 | self.__driver.closeFigure() |
|
32 | 32 | |
|
33 | 33 | def getFilename(self, name, ext='.png'): |
|
34 | 34 | |
|
35 | 35 | path = '%s%03d' %(self.PREFIX, self.idfigure) |
|
36 | 36 | filename = '%s_%s%s' %(self.PREFIX, name, ext) |
|
37 | 37 | |
|
38 | 38 | return os.path.join(path, filename) |
|
39 | 39 | |
|
40 | 40 | def getAxesObjList(self): |
|
41 | 41 | |
|
42 | 42 | return self.axesObjList |
|
43 | 43 | |
|
44 | 44 | def getSubplots(self): |
|
45 | 45 | |
|
46 | 46 | raise ValueError, "Abstract method: This method should be defined" |
|
47 | 47 | |
|
48 | 48 | def getScreenDim(self, widthplot, heightplot): |
|
49 | 49 | |
|
50 | 50 | nrow, ncol = self.getSubplots() |
|
51 | 51 | |
|
52 | 52 | widthscreen = widthplot*ncol |
|
53 | 53 | heightscreen = heightplot*nrow |
|
54 | 54 | |
|
55 | 55 | return widthscreen, heightscreen |
|
56 | 56 | |
|
57 | 57 | def getTimeLim(self, x, xmin, xmax): |
|
58 | 58 | |
|
59 | 59 | thisdatetime = datetime.datetime.utcfromtimestamp(numpy.min(x)) |
|
60 | 60 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
61 | 61 | |
|
62 | 62 | #################################################### |
|
63 | 63 | #If the x is out of xrange |
|
64 | 64 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
65 | 65 | xmin = None |
|
66 | 66 | xmax = None |
|
67 | 67 | |
|
68 | 68 | if xmin == None: |
|
69 | 69 | td = thisdatetime - thisdate |
|
70 | 70 | xmin = td.seconds/(60*60.) |
|
71 | 71 | |
|
72 | 72 | if xmax == None: |
|
73 | 73 | xmax = xmin + self.timerange/(60*60.) |
|
74 | 74 | |
|
75 | 75 | mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) |
|
76 | 76 | tmin = time.mktime(mindt.timetuple()) |
|
77 | 77 | |
|
78 | 78 | maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) |
|
79 | 79 | tmax = time.mktime(maxdt.timetuple()) |
|
80 | 80 | |
|
81 | 81 | self.timerange = tmax - tmin |
|
82 | 82 | |
|
83 | 83 | return tmin, tmax |
|
84 | 84 | |
|
85 | 85 | def init(self, idfigure, nplots, wintitle): |
|
86 | 86 | |
|
87 | 87 | raise ValueError, "This method has been replaced with createFigure" |
|
88 | 88 | |
|
89 | def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None): | |
|
89 | def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None, show=True): | |
|
90 | 90 | |
|
91 | 91 | """ |
|
92 | 92 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
93 | 93 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
94 | 94 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
95 | 95 | |
|
96 | 96 | Input: |
|
97 | 97 | idfigure : Los parametros necesarios son |
|
98 | 98 | wintitle : |
|
99 | 99 | |
|
100 | 100 | """ |
|
101 | 101 | |
|
102 | 102 | if widthplot == None: |
|
103 | 103 | widthplot = self.WIDTH |
|
104 | 104 | |
|
105 | 105 | if heightplot == None: |
|
106 | 106 | heightplot = self.HEIGHT |
|
107 | 107 | |
|
108 | 108 | self.idfigure = idfigure |
|
109 | 109 | |
|
110 | 110 | self.wintitle = wintitle |
|
111 | 111 | |
|
112 | 112 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
113 | 113 | |
|
114 | self.fig = self.__driver.createFigure(self.idfigure, | |
|
115 | self.wintitle, | |
|
116 | self.widthscreen, | |
|
117 |
self.heightscreen |
|
|
114 | self.fig = self.__driver.createFigure(idfigure=self.idfigure, | |
|
115 | wintitle=self.wintitle, | |
|
116 | width=self.widthscreen, | |
|
117 | height=self.heightscreen, | |
|
118 | show=show) | |
|
118 | 119 | |
|
119 | 120 | self.axesObjList = [] |
|
120 | 121 | |
|
121 | 122 | |
|
122 | 123 | def setDriver(self, driver=mpldriver): |
|
123 | 124 | |
|
124 | 125 | self.__driver = driver |
|
125 | 126 | |
|
126 | 127 | def setTitle(self, title): |
|
127 | 128 | |
|
128 | 129 | self.__driver.setTitle(self.fig, title) |
|
129 | 130 | |
|
130 | 131 | def setWinTitle(self, title): |
|
131 | 132 | |
|
132 | 133 | self.__driver.setWinTitle(self.fig, title=title) |
|
133 | 134 | |
|
134 | 135 | def setTextFromAxes(self, text): |
|
135 | 136 | |
|
136 | 137 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
137 | 138 | |
|
138 | 139 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
139 | 140 | |
|
140 | 141 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
141 | 142 | |
|
142 | 143 | def addAxes(self, *args): |
|
143 | 144 | """ |
|
144 | 145 | |
|
145 | 146 | Input: |
|
146 | 147 | *args : Los parametros necesarios son |
|
147 | 148 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
148 | 149 | """ |
|
149 | 150 | |
|
150 | 151 | axesObj = Axes(self.fig, *args) |
|
151 | 152 | self.axesObjList.append(axesObj) |
|
152 | 153 | |
|
153 | 154 | def saveFigure(self, figpath, figfile, *args): |
|
154 | 155 | |
|
155 | 156 | filename = os.path.join(figpath, figfile) |
|
156 | 157 | |
|
157 | 158 | fullpath = os.path.split(filename)[0] |
|
158 | 159 | |
|
159 | 160 | if not os.path.exists(fullpath): |
|
160 | 161 | subpath = os.path.split(fullpath)[0] |
|
161 | 162 | |
|
162 | 163 | if not os.path.exists(subpath): |
|
163 | 164 | os.mkdir(subpath) |
|
164 | 165 | |
|
165 | 166 | os.mkdir(fullpath) |
|
166 | 167 | |
|
167 | 168 | self.__driver.saveFigure(self.fig, filename, *args) |
|
168 | 169 | |
|
169 | 170 | def sendByFTP(self, figfilename): |
|
170 | 171 | ftpObj = Ftp() |
|
171 | 172 | ftpObj.upload(figfilename) |
|
172 | 173 | ftpObj.close() |
|
173 | 174 | |
|
174 | 175 | def draw(self): |
|
175 | 176 | |
|
176 | 177 | self.__driver.draw(self.fig) |
|
177 | 178 | |
|
178 | 179 | def run(self): |
|
179 | 180 | |
|
180 | 181 | raise ValueError, "This method is not implemented" |
|
181 | 182 | |
|
182 | 183 | axesList = property(getAxesObjList) |
|
183 | 184 | |
|
184 | 185 | |
|
185 | 186 | class Axes: |
|
186 | 187 | |
|
187 | 188 | __driver = mpldriver |
|
188 | 189 | fig = None |
|
189 | 190 | ax = None |
|
190 | 191 | plot = None |
|
191 | 192 | __missing = 1E30 |
|
192 | 193 | __firsttime = None |
|
193 | 194 | |
|
194 | 195 | __showprofile = False |
|
195 | 196 | |
|
196 | 197 | xmin = None |
|
197 | 198 | xmax = None |
|
198 | 199 | ymin = None |
|
199 | 200 | ymax = None |
|
200 | 201 | zmin = None |
|
201 | 202 | zmax = None |
|
202 | 203 | |
|
203 | 204 | x_buffer = None |
|
204 | 205 | z_buffer = None |
|
205 | 206 | |
|
206 | 207 | def __init__(self, *args): |
|
207 | 208 | |
|
208 | 209 | """ |
|
209 | 210 | |
|
210 | 211 | Input: |
|
211 | 212 | *args : Los parametros necesarios son |
|
212 | 213 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
213 | 214 | """ |
|
214 | 215 | |
|
215 | 216 | ax = self.__driver.createAxes(*args) |
|
216 | 217 | self.fig = args[0] |
|
217 | 218 | self.ax = ax |
|
218 | 219 | self.plot = None |
|
219 | 220 | |
|
220 | 221 | self.__firsttime = True |
|
221 | 222 | self.idlineList = [] |
|
222 | 223 | |
|
223 | 224 | self.x_buffer = numpy.array([]) |
|
224 | 225 | self.z_buffer = numpy.array([]) |
|
225 | 226 | |
|
226 | 227 | def setText(self, text): |
|
227 | 228 | |
|
228 | 229 | self.__driver.setAxesText(self.ax, text) |
|
229 | 230 | |
|
230 | 231 | def setXAxisAsTime(self): |
|
231 | 232 | pass |
|
232 | 233 | |
|
233 | 234 | def pline(self, x, y, |
|
234 | 235 | xmin=None, xmax=None, |
|
235 | 236 | ymin=None, ymax=None, |
|
236 | 237 | xlabel='', ylabel='', |
|
237 | 238 | title='', |
|
238 | 239 | **kwargs): |
|
239 | 240 | |
|
240 | 241 | """ |
|
241 | 242 | |
|
242 | 243 | Input: |
|
243 | 244 | x : |
|
244 | 245 | y : |
|
245 | 246 | xmin : |
|
246 | 247 | xmax : |
|
247 | 248 | ymin : |
|
248 | 249 | ymax : |
|
249 | 250 | xlabel : |
|
250 | 251 | ylabel : |
|
251 | 252 | title : |
|
252 | 253 | **kwargs : Los parametros aceptados son |
|
253 | 254 | |
|
254 | 255 | ticksize |
|
255 | 256 | ytick_visible |
|
256 | 257 | """ |
|
257 | 258 | |
|
258 | 259 | if self.__firsttime: |
|
259 | 260 | |
|
260 | 261 | if xmin == None: xmin = numpy.nanmin(x) |
|
261 | 262 | if xmax == None: xmax = numpy.nanmax(x) |
|
262 | 263 | if ymin == None: ymin = numpy.nanmin(y) |
|
263 | 264 | if ymax == None: ymax = numpy.nanmax(y) |
|
264 | 265 | |
|
265 | 266 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
266 | 267 | xmin, xmax, |
|
267 | 268 | ymin, ymax, |
|
268 | 269 | xlabel=xlabel, |
|
269 | 270 | ylabel=ylabel, |
|
270 | 271 | title=title, |
|
271 | 272 | **kwargs) |
|
272 | 273 | |
|
273 | 274 | self.idlineList.append(0) |
|
274 | 275 | self.__firsttime = False |
|
275 | 276 | return |
|
276 | 277 | |
|
277 | 278 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
278 | 279 | ylabel=ylabel, |
|
279 | 280 | title=title) |
|
280 | 281 | |
|
281 | 282 | def addpline(self, x, y, idline, **kwargs): |
|
282 | 283 | lines = self.ax.lines |
|
283 | 284 | |
|
284 | 285 | if idline in self.idlineList: |
|
285 | 286 | self.__driver.set_linedata(self.ax, x, y, idline) |
|
286 | 287 | |
|
287 | 288 | if idline not in(self.idlineList): |
|
288 | 289 | self.__driver.addpline(self.ax, x, y, **kwargs) |
|
289 | 290 | self.idlineList.append(idline) |
|
290 | 291 | |
|
291 | 292 | return |
|
292 | 293 | |
|
293 | 294 | def pmultiline(self, x, y, |
|
294 | 295 | xmin=None, xmax=None, |
|
295 | 296 | ymin=None, ymax=None, |
|
296 | 297 | xlabel='', ylabel='', |
|
297 | 298 | title='', |
|
298 | 299 | **kwargs): |
|
299 | 300 | |
|
300 | 301 | if self.__firsttime: |
|
301 | 302 | |
|
302 | 303 | if xmin == None: xmin = numpy.nanmin(x) |
|
303 | 304 | if xmax == None: xmax = numpy.nanmax(x) |
|
304 | 305 | if ymin == None: ymin = numpy.nanmin(y) |
|
305 | 306 | if ymax == None: ymax = numpy.nanmax(y) |
|
306 | 307 | |
|
307 | 308 | self.plot = self.__driver.createPmultiline(self.ax, x, y, |
|
308 | 309 | xmin, xmax, |
|
309 | 310 | ymin, ymax, |
|
310 | 311 | xlabel=xlabel, |
|
311 | 312 | ylabel=ylabel, |
|
312 | 313 | title=title, |
|
313 | 314 | **kwargs) |
|
314 | 315 | self.__firsttime = False |
|
315 | 316 | return |
|
316 | 317 | |
|
317 | 318 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, |
|
318 | 319 | ylabel=ylabel, |
|
319 | 320 | title=title) |
|
320 | 321 | |
|
321 | 322 | def pmultilineyaxis(self, x, y, |
|
322 | 323 | xmin=None, xmax=None, |
|
323 | 324 | ymin=None, ymax=None, |
|
324 | 325 | xlabel='', ylabel='', |
|
325 | 326 | title='', |
|
326 | 327 | **kwargs): |
|
327 | 328 | |
|
328 | 329 | if self.__firsttime: |
|
329 | 330 | |
|
330 | 331 | if xmin == None: xmin = numpy.nanmin(x) |
|
331 | 332 | if xmax == None: xmax = numpy.nanmax(x) |
|
332 | 333 | if ymin == None: ymin = numpy.nanmin(y) |
|
333 | 334 | if ymax == None: ymax = numpy.nanmax(y) |
|
334 | 335 | |
|
335 | 336 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, |
|
336 | 337 | xmin, xmax, |
|
337 | 338 | ymin, ymax, |
|
338 | 339 | xlabel=xlabel, |
|
339 | 340 | ylabel=ylabel, |
|
340 | 341 | title=title, |
|
341 | 342 | **kwargs) |
|
342 | 343 | if self.xmin == None: self.xmin = xmin |
|
343 | 344 | if self.xmax == None: self.xmax = xmax |
|
344 | 345 | if self.ymin == None: self.ymin = ymin |
|
345 | 346 | if self.ymax == None: self.ymax = ymax |
|
346 | 347 | |
|
347 | 348 | self.__firsttime = False |
|
348 | 349 | return |
|
349 | 350 | |
|
350 | 351 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, |
|
351 | 352 | ylabel=ylabel, |
|
352 | 353 | title=title) |
|
353 | 354 | |
|
354 | 355 | def pcolor(self, x, y, z, |
|
355 | 356 | xmin=None, xmax=None, |
|
356 | 357 | ymin=None, ymax=None, |
|
357 | 358 | zmin=None, zmax=None, |
|
358 | 359 | xlabel='', ylabel='', |
|
359 | 360 | title='', rti = False, colormap='jet', |
|
360 | 361 | **kwargs): |
|
361 | 362 | |
|
362 | 363 | """ |
|
363 | 364 | Input: |
|
364 | 365 | x : |
|
365 | 366 | y : |
|
366 | 367 | x : |
|
367 | 368 | xmin : |
|
368 | 369 | xmax : |
|
369 | 370 | ymin : |
|
370 | 371 | ymax : |
|
371 | 372 | zmin : |
|
372 | 373 | zmax : |
|
373 | 374 | xlabel : |
|
374 | 375 | ylabel : |
|
375 | 376 | title : |
|
376 | 377 | **kwargs : Los parametros aceptados son |
|
377 | 378 | ticksize=9, |
|
378 | 379 | cblabel='' |
|
379 | 380 | rti = True or False |
|
380 | 381 | """ |
|
381 | 382 | |
|
382 | 383 | if self.__firsttime: |
|
383 | 384 | |
|
384 | 385 | if xmin == None: xmin = numpy.nanmin(x) |
|
385 | 386 | if xmax == None: xmax = numpy.nanmax(x) |
|
386 | 387 | if ymin == None: ymin = numpy.nanmin(y) |
|
387 | 388 | if ymax == None: ymax = numpy.nanmax(y) |
|
388 | 389 | if zmin == None: zmin = numpy.nanmin(z) |
|
389 | 390 | if zmax == None: zmax = numpy.nanmax(z) |
|
390 | 391 | |
|
391 | 392 | |
|
392 | 393 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
393 | 394 | xmin, xmax, |
|
394 | 395 | ymin, ymax, |
|
395 | 396 | zmin, zmax, |
|
396 | 397 | xlabel=xlabel, |
|
397 | 398 | ylabel=ylabel, |
|
398 | 399 | title=title, |
|
399 | 400 | colormap=colormap, |
|
400 | 401 | **kwargs) |
|
401 | 402 | |
|
402 | 403 | if self.xmin == None: self.xmin = xmin |
|
403 | 404 | if self.xmax == None: self.xmax = xmax |
|
404 | 405 | if self.ymin == None: self.ymin = ymin |
|
405 | 406 | if self.ymax == None: self.ymax = ymax |
|
406 | 407 | if self.zmin == None: self.zmin = zmin |
|
407 | 408 | if self.zmax == None: self.zmax = zmax |
|
408 | 409 | |
|
409 | 410 | self.__firsttime = False |
|
410 | 411 | return |
|
411 | 412 | |
|
412 | 413 | if rti: |
|
413 | 414 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, |
|
414 | 415 | xlabel=xlabel, |
|
415 | 416 | ylabel=ylabel, |
|
416 | 417 | title=title, |
|
417 | 418 | colormap=colormap) |
|
418 | 419 | return |
|
419 | 420 | |
|
420 | 421 | self.__driver.pcolor(self.plot, z, |
|
421 | 422 | xlabel=xlabel, |
|
422 | 423 | ylabel=ylabel, |
|
423 | 424 | title=title) |
|
424 | 425 | |
|
425 | 426 | def pcolorbuffer(self, x, y, z, |
|
426 | 427 | xmin=None, xmax=None, |
|
427 | 428 | ymin=None, ymax=None, |
|
428 | 429 | zmin=None, zmax=None, |
|
429 | 430 | xlabel='', ylabel='', |
|
430 | 431 | title='', rti = False, colormap='jet', |
|
431 | 432 | **kwargs): |
|
432 | 433 | |
|
433 | 434 | |
|
434 | 435 | if self.__firsttime: |
|
435 | 436 | self.z_buffer = z |
|
436 | 437 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
437 | 438 | |
|
438 | 439 | if xmin == None: xmin = numpy.nanmin(x) |
|
439 | 440 | if xmax == None: xmax = numpy.nanmax(x) |
|
440 | 441 | if ymin == None: ymin = numpy.nanmin(y) |
|
441 | 442 | if ymax == None: ymax = numpy.nanmax(y) |
|
442 | 443 | if zmin == None: zmin = numpy.nanmin(z) |
|
443 | 444 | if zmax == None: zmax = numpy.nanmax(z) |
|
444 | 445 | |
|
445 | 446 | |
|
446 | 447 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, |
|
447 | 448 | xmin, xmax, |
|
448 | 449 | ymin, ymax, |
|
449 | 450 | zmin, zmax, |
|
450 | 451 | xlabel=xlabel, |
|
451 | 452 | ylabel=ylabel, |
|
452 | 453 | title=title, |
|
453 | 454 | colormap=colormap, |
|
454 | 455 | **kwargs) |
|
455 | 456 | |
|
456 | 457 | if self.xmin == None: self.xmin = xmin |
|
457 | 458 | if self.xmax == None: self.xmax = xmax |
|
458 | 459 | if self.ymin == None: self.ymin = ymin |
|
459 | 460 | if self.ymax == None: self.ymax = ymax |
|
460 | 461 | if self.zmin == None: self.zmin = zmin |
|
461 | 462 | if self.zmax == None: self.zmax = zmax |
|
462 | 463 | |
|
463 | 464 | self.__firsttime = False |
|
464 | 465 | return |
|
465 | 466 | |
|
466 | 467 | if rti: |
|
467 | 468 | if x[0]>self.x_buffer[-1]: |
|
468 | 469 | gap = z.copy() |
|
469 | 470 | gap[:] = self.__missing |
|
470 | 471 | self.z_buffer = numpy.hstack((self.z_buffer, gap)) |
|
471 | 472 | self.z_buffer = numpy.ma.masked_inside(self.z_buffer,0.99*self.__missing,1.01*self.__missing) |
|
472 | 473 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
473 | 474 | |
|
474 | 475 | else: |
|
475 | 476 | self.x_buffer = numpy.hstack((self.x_buffer, x[-1])) |
|
476 | 477 | |
|
477 | 478 | self.z_buffer = numpy.hstack((self.z_buffer, z)) |
|
478 | 479 | |
|
479 | 480 | newydim = len(y) |
|
480 | 481 | |
|
481 | 482 | # self.z_buffer = numpy.ma.masked_inside(self.z_buffer,0.99*self.__missing,1.01*self.__missing) |
|
482 | 483 | |
|
483 | 484 | z_buffer = self.z_buffer.reshape(-1,newydim) |
|
484 | 485 | |
|
485 | 486 | self.__driver.addpcolorbuffer(self.ax, self.x_buffer, y, z_buffer, self.zmin, self.zmax, |
|
486 | 487 | xlabel=xlabel, |
|
487 | 488 | ylabel=ylabel, |
|
488 | 489 | title=title, |
|
489 | 490 | colormap=colormap) |
|
490 | 491 | return |
|
491 | 492 | |
|
492 | 493 | self.__driver.pcolor(self.plot, z, |
|
493 | 494 | xlabel=xlabel, |
|
494 | 495 | ylabel=ylabel, |
|
495 | 496 | title=title) |
|
496 | 497 | No newline at end of file |
@@ -1,380 +1,382 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import datetime |
|
3 | 3 | import sys |
|
4 | 4 | import matplotlib |
|
5 | 5 | |
|
6 | 6 | if 'linux' in sys.platform: |
|
7 | 7 | matplotlib.use("TKAgg") |
|
8 | 8 | |
|
9 | 9 | if 'darwin' in sys.platform: |
|
10 | 10 | matplotlib.use("TKAgg") |
|
11 | 11 | |
|
12 | 12 | import matplotlib.pyplot |
|
13 | 13 | |
|
14 | 14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
15 | 15 | from matplotlib.ticker import * |
|
16 | 16 | |
|
17 | 17 | ########################################### |
|
18 | 18 | #Actualizacion de las funciones del driver |
|
19 | 19 | ########################################### |
|
20 | 20 | |
|
21 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): | |
|
21 | def createFigure(idfigure, wintitle, width, height, facecolor="w", show=True): | |
|
22 | 22 | |
|
23 | 23 | matplotlib.pyplot.ioff() |
|
24 | 24 | fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
25 | 25 | fig.canvas.manager.set_window_title(wintitle) |
|
26 | 26 | fig.canvas.manager.resize(width, height) |
|
27 | 27 | matplotlib.pyplot.ion() |
|
28 | if show: | |
|
28 | 29 | matplotlib.pyplot.show() |
|
29 | 30 | |
|
30 | 31 | return fig |
|
31 | 32 | |
|
32 | def closeFigure(): | |
|
33 | def closeFigure(show=True): | |
|
33 | 34 | |
|
34 | 35 | matplotlib.pyplot.ioff() |
|
36 | if show: | |
|
35 | 37 | matplotlib.pyplot.show() |
|
36 | 38 | |
|
37 | 39 | return |
|
38 | 40 | |
|
39 | 41 | def saveFigure(fig, filename): |
|
40 | 42 | |
|
41 | 43 | matplotlib.pyplot.ioff() |
|
42 | 44 | fig.savefig(filename) |
|
43 | 45 | matplotlib.pyplot.ion() |
|
44 | 46 | |
|
45 | 47 | def setWinTitle(fig, title): |
|
46 | 48 | |
|
47 | 49 | fig.canvas.manager.set_window_title(title) |
|
48 | 50 | |
|
49 | 51 | def setTitle(fig, title): |
|
50 | 52 | |
|
51 | 53 | fig.suptitle(title) |
|
52 | 54 | |
|
53 | 55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
54 | 56 | |
|
55 | 57 | matplotlib.pyplot.ioff() |
|
56 | 58 | matplotlib.pyplot.figure(fig.number) |
|
57 | 59 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
58 | 60 | (xpos, ypos), |
|
59 | 61 | colspan=colspan, |
|
60 | 62 | rowspan=rowspan) |
|
61 | 63 | |
|
62 | 64 | matplotlib.pyplot.ion() |
|
63 | 65 | return axes |
|
64 | 66 | |
|
65 | 67 | def setAxesText(ax, text): |
|
66 | 68 | |
|
67 | 69 | ax.annotate(text, |
|
68 | 70 | xy = (.1, .99), |
|
69 | 71 | xycoords = 'figure fraction', |
|
70 | 72 | horizontalalignment = 'left', |
|
71 | 73 | verticalalignment = 'top', |
|
72 | 74 | fontsize = 10) |
|
73 | 75 | |
|
74 | 76 | def printLabels(ax, xlabel, ylabel, title): |
|
75 | 77 | |
|
76 | 78 | ax.set_xlabel(xlabel, size=11) |
|
77 | 79 | ax.set_ylabel(ylabel, size=11) |
|
78 | 80 | ax.set_title(title, size=12) |
|
79 | 81 | |
|
80 | 82 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
81 | 83 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
82 | 84 | nxticks=4, nyticks=10, |
|
83 | 85 | grid=None): |
|
84 | 86 | |
|
85 | 87 | """ |
|
86 | 88 | |
|
87 | 89 | Input: |
|
88 | 90 | grid : None, 'both', 'x', 'y' |
|
89 | 91 | """ |
|
90 | 92 | |
|
91 | 93 | matplotlib.pyplot.ioff() |
|
92 | 94 | |
|
93 | 95 | ax.set_xlim([xmin,xmax]) |
|
94 | 96 | ax.set_ylim([ymin,ymax]) |
|
95 | 97 | |
|
96 | 98 | printLabels(ax, xlabel, ylabel, title) |
|
97 | 99 | |
|
98 | 100 | ###################################################### |
|
99 | 101 | # if (xmax-xmin)<=1: |
|
100 | 102 | # xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
101 | 103 | # xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
102 | 104 | # ax.set_xticks(xtickspos) |
|
103 | 105 | # else: |
|
104 | 106 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
105 | 107 | # ax.set_xticks(xtickspos) |
|
106 | 108 | # |
|
107 | 109 | # for tick in ax.get_xticklabels(): |
|
108 | 110 | # tick.set_visible(xtick_visible) |
|
109 | 111 | # |
|
110 | 112 | # for tick in ax.xaxis.get_major_ticks(): |
|
111 | 113 | # tick.label.set_fontsize(ticksize) |
|
112 | 114 | |
|
113 | 115 | ###################################################### |
|
114 | 116 | for tick in ax.get_yticklabels(): |
|
115 | 117 | tick.set_visible(ytick_visible) |
|
116 | 118 | |
|
117 | 119 | for tick in ax.yaxis.get_major_ticks(): |
|
118 | 120 | tick.label.set_fontsize(ticksize) |
|
119 | 121 | |
|
120 | 122 | ax.plot(x, y) |
|
121 | 123 | iplot = ax.lines[-1] |
|
122 | 124 | |
|
123 | 125 | ###################################################### |
|
124 | 126 | if '0.' in matplotlib.__version__[0:2]: |
|
125 | 127 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
126 | 128 | return iplot |
|
127 | 129 | |
|
128 | 130 | if '1.0.' in matplotlib.__version__[0:4]: |
|
129 | 131 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
130 | 132 | return iplot |
|
131 | 133 | |
|
132 | 134 | if grid != None: |
|
133 | 135 | ax.grid(b=True, which='major', axis=grid) |
|
134 | 136 | |
|
135 | 137 | matplotlib.pyplot.tight_layout() |
|
136 | 138 | |
|
137 | 139 | matplotlib.pyplot.ion() |
|
138 | 140 | |
|
139 | 141 | return iplot |
|
140 | 142 | |
|
141 | 143 | def set_linedata(ax, x, y, idline): |
|
142 | 144 | |
|
143 | 145 | ax.lines[idline].set_data(x,y) |
|
144 | 146 | |
|
145 | 147 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
146 | 148 | |
|
147 | 149 | ax = iplot.get_axes() |
|
148 | 150 | |
|
149 | 151 | printLabels(ax, xlabel, ylabel, title) |
|
150 | 152 | |
|
151 | 153 | set_linedata(ax, x, y, idline=0) |
|
152 | 154 | |
|
153 | 155 | def addpline(ax, x, y, color, linestyle, lw): |
|
154 | 156 | |
|
155 | 157 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
156 | 158 | |
|
157 | 159 | |
|
158 | 160 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
159 | 161 | xlabel='', ylabel='', title='', ticksize = 9, |
|
160 | 162 | colormap='jet',cblabel='', cbsize="5%", |
|
161 | 163 | XAxisAsTime=False): |
|
162 | 164 | |
|
163 | 165 | matplotlib.pyplot.ioff() |
|
164 | 166 | |
|
165 | 167 | divider = make_axes_locatable(ax) |
|
166 | 168 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
167 | 169 | fig = ax.get_figure() |
|
168 | 170 | fig.add_axes(ax_cb) |
|
169 | 171 | |
|
170 | 172 | ax.set_xlim([xmin,xmax]) |
|
171 | 173 | ax.set_ylim([ymin,ymax]) |
|
172 | 174 | |
|
173 | 175 | printLabels(ax, xlabel, ylabel, title) |
|
174 | 176 | |
|
175 | 177 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
176 | 178 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
177 | 179 | cb.set_label(cblabel) |
|
178 | 180 | |
|
179 | 181 | # for tl in ax_cb.get_yticklabels(): |
|
180 | 182 | # tl.set_visible(True) |
|
181 | 183 | |
|
182 | 184 | for tick in ax.yaxis.get_major_ticks(): |
|
183 | 185 | tick.label.set_fontsize(ticksize) |
|
184 | 186 | |
|
185 | 187 | for tick in ax.xaxis.get_major_ticks(): |
|
186 | 188 | tick.label.set_fontsize(ticksize) |
|
187 | 189 | |
|
188 | 190 | for tick in cb.ax.get_yticklabels(): |
|
189 | 191 | tick.set_fontsize(ticksize) |
|
190 | 192 | |
|
191 | 193 | ax_cb.yaxis.tick_right() |
|
192 | 194 | |
|
193 | 195 | if '0.' in matplotlib.__version__[0:2]: |
|
194 | 196 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
195 | 197 | return imesh |
|
196 | 198 | |
|
197 | 199 | if '1.0.' in matplotlib.__version__[0:4]: |
|
198 | 200 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
199 | 201 | return imesh |
|
200 | 202 | |
|
201 | 203 | matplotlib.pyplot.tight_layout() |
|
202 | 204 | |
|
203 | 205 | if XAxisAsTime: |
|
204 | 206 | |
|
205 | 207 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
206 | 208 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
207 | 209 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
208 | 210 | |
|
209 | 211 | matplotlib.pyplot.ion() |
|
210 | 212 | return imesh |
|
211 | 213 | |
|
212 | 214 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
213 | 215 | |
|
214 | 216 | z = z.T |
|
215 | 217 | |
|
216 | 218 | ax = imesh.get_axes() |
|
217 | 219 | |
|
218 | 220 | printLabels(ax, xlabel, ylabel, title) |
|
219 | 221 | |
|
220 | 222 | imesh.set_array(z.ravel()) |
|
221 | 223 | |
|
222 | 224 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
223 | 225 | |
|
224 | 226 | printLabels(ax, xlabel, ylabel, title) |
|
225 | 227 | |
|
226 | 228 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
227 | 229 | |
|
228 | 230 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
229 | 231 | |
|
230 | 232 | printLabels(ax, xlabel, ylabel, title) |
|
231 | 233 | |
|
232 | 234 | ax.collections.remove(ax.collections[0]) |
|
233 | 235 | |
|
234 | 236 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
235 | 237 | |
|
236 | 238 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
237 | 239 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
238 | 240 | nxticks=4, nyticks=10, |
|
239 | 241 | grid=None): |
|
240 | 242 | |
|
241 | 243 | """ |
|
242 | 244 | |
|
243 | 245 | Input: |
|
244 | 246 | grid : None, 'both', 'x', 'y' |
|
245 | 247 | """ |
|
246 | 248 | |
|
247 | 249 | matplotlib.pyplot.ioff() |
|
248 | 250 | |
|
249 | 251 | lines = ax.plot(x.T, y) |
|
250 | 252 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
251 | 253 | leg.get_frame().set_alpha(0.5) |
|
252 | 254 | ax.set_xlim([xmin,xmax]) |
|
253 | 255 | ax.set_ylim([ymin,ymax]) |
|
254 | 256 | printLabels(ax, xlabel, ylabel, title) |
|
255 | 257 | |
|
256 | 258 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
257 | 259 | ax.set_xticks(xtickspos) |
|
258 | 260 | |
|
259 | 261 | for tick in ax.get_xticklabels(): |
|
260 | 262 | tick.set_visible(xtick_visible) |
|
261 | 263 | |
|
262 | 264 | for tick in ax.xaxis.get_major_ticks(): |
|
263 | 265 | tick.label.set_fontsize(ticksize) |
|
264 | 266 | |
|
265 | 267 | for tick in ax.get_yticklabels(): |
|
266 | 268 | tick.set_visible(ytick_visible) |
|
267 | 269 | |
|
268 | 270 | for tick in ax.yaxis.get_major_ticks(): |
|
269 | 271 | tick.label.set_fontsize(ticksize) |
|
270 | 272 | |
|
271 | 273 | iplot = ax.lines[-1] |
|
272 | 274 | |
|
273 | 275 | if '0.' in matplotlib.__version__[0:2]: |
|
274 | 276 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
275 | 277 | return iplot |
|
276 | 278 | |
|
277 | 279 | if '1.0.' in matplotlib.__version__[0:4]: |
|
278 | 280 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
279 | 281 | return iplot |
|
280 | 282 | |
|
281 | 283 | if grid != None: |
|
282 | 284 | ax.grid(b=True, which='major', axis=grid) |
|
283 | 285 | |
|
284 | 286 | matplotlib.pyplot.tight_layout() |
|
285 | 287 | |
|
286 | 288 | matplotlib.pyplot.ion() |
|
287 | 289 | |
|
288 | 290 | return iplot |
|
289 | 291 | |
|
290 | 292 | |
|
291 | 293 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
292 | 294 | |
|
293 | 295 | ax = iplot.get_axes() |
|
294 | 296 | |
|
295 | 297 | printLabels(ax, xlabel, ylabel, title) |
|
296 | 298 | |
|
297 | 299 | for i in range(len(ax.lines)): |
|
298 | 300 | line = ax.lines[i] |
|
299 | 301 | line.set_data(x[i,:],y) |
|
300 | 302 | |
|
301 | 303 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
302 | 304 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
303 | 305 | nxticks=4, nyticks=10, marker='+', markersize=8, linestyle="solid", |
|
304 | 306 | grid=None, XAxisAsTime=False): |
|
305 | 307 | |
|
306 | 308 | """ |
|
307 | 309 | |
|
308 | 310 | Input: |
|
309 | 311 | grid : None, 'both', 'x', 'y' |
|
310 | 312 | """ |
|
311 | 313 | |
|
312 | 314 | matplotlib.pyplot.ioff() |
|
313 | 315 | |
|
314 | 316 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
315 | 317 | lines = ax.plot(x, y.T, 'o', markersize=5) |
|
316 | 318 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
317 | 319 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
318 | 320 | |
|
319 | 321 | for label in leg.get_texts(): label.set_fontsize(9) |
|
320 | 322 | |
|
321 | 323 | ax.set_xlim([xmin,xmax]) |
|
322 | 324 | ax.set_ylim([ymin,ymax]) |
|
323 | 325 | printLabels(ax, xlabel, ylabel, title) |
|
324 | 326 | |
|
325 | 327 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
326 | 328 | # ax.set_xticks(xtickspos) |
|
327 | 329 | |
|
328 | 330 | for tick in ax.get_xticklabels(): |
|
329 | 331 | tick.set_visible(xtick_visible) |
|
330 | 332 | |
|
331 | 333 | for tick in ax.xaxis.get_major_ticks(): |
|
332 | 334 | tick.label.set_fontsize(ticksize) |
|
333 | 335 | |
|
334 | 336 | for tick in ax.get_yticklabels(): |
|
335 | 337 | tick.set_visible(ytick_visible) |
|
336 | 338 | |
|
337 | 339 | for tick in ax.yaxis.get_major_ticks(): |
|
338 | 340 | tick.label.set_fontsize(ticksize) |
|
339 | 341 | |
|
340 | 342 | iplot = ax.lines[-1] |
|
341 | 343 | |
|
342 | 344 | if '0.' in matplotlib.__version__[0:2]: |
|
343 | 345 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
344 | 346 | return iplot |
|
345 | 347 | |
|
346 | 348 | if '1.0.' in matplotlib.__version__[0:4]: |
|
347 | 349 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
348 | 350 | return iplot |
|
349 | 351 | |
|
350 | 352 | if grid != None: |
|
351 | 353 | ax.grid(b=True, which='major', axis=grid) |
|
352 | 354 | |
|
353 | 355 | matplotlib.pyplot.tight_layout() |
|
354 | 356 | |
|
355 | 357 | if XAxisAsTime: |
|
356 | 358 | |
|
357 | 359 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
358 | 360 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
359 | 361 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
360 | 362 | |
|
361 | 363 | matplotlib.pyplot.ion() |
|
362 | 364 | |
|
363 | 365 | return iplot |
|
364 | 366 | |
|
365 | 367 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
366 | 368 | |
|
367 | 369 | ax = iplot.get_axes() |
|
368 | 370 | |
|
369 | 371 | printLabels(ax, xlabel, ylabel, title) |
|
370 | 372 | |
|
371 | 373 | for i in range(len(ax.lines)): |
|
372 | 374 | line = ax.lines[i] |
|
373 | 375 | line.set_data(x,y[i,:]) |
|
374 | 376 | |
|
375 | 377 | def draw(fig): |
|
376 | 378 | |
|
377 | 379 | if type(fig) == 'int': |
|
378 | 380 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
379 | 381 | |
|
380 | 382 | fig.canvas.draw() No newline at end of file |
@@ -1,1323 +1,1343 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import time, datetime, os |
|
3 | 3 | from graphics.figure import * |
|
4 | 4 | |
|
5 | 5 | class CrossSpectraPlot(Figure): |
|
6 | 6 | |
|
7 | 7 | __isConfig = None |
|
8 | 8 | __nsubplots = None |
|
9 | 9 | |
|
10 | 10 | WIDTH = None |
|
11 | 11 | HEIGHT = None |
|
12 | 12 | WIDTHPROF = None |
|
13 | 13 | HEIGHTPROF = None |
|
14 | 14 | PREFIX = 'cspc' |
|
15 | 15 | |
|
16 | 16 | def __init__(self): |
|
17 | 17 | |
|
18 | 18 | self.__isConfig = False |
|
19 | 19 | self.__nsubplots = 4 |
|
20 | 20 | |
|
21 | 21 | self.WIDTH = 250 |
|
22 | 22 | self.HEIGHT = 250 |
|
23 | 23 | self.WIDTHPROF = 0 |
|
24 | 24 | self.HEIGHTPROF = 0 |
|
25 | 25 | |
|
26 | 26 | def getSubplots(self): |
|
27 | 27 | |
|
28 | 28 | ncol = 4 |
|
29 | 29 | nrow = self.nplots |
|
30 | 30 | |
|
31 | 31 | return nrow, ncol |
|
32 | 32 | |
|
33 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
|
33 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): | |
|
34 | 34 | |
|
35 | 35 | self.__showprofile = showprofile |
|
36 | 36 | self.nplots = nplots |
|
37 | 37 | |
|
38 | 38 | ncolspan = 1 |
|
39 | 39 | colspan = 1 |
|
40 | 40 | |
|
41 | 41 | self.createFigure(idfigure = idfigure, |
|
42 | 42 | wintitle = wintitle, |
|
43 | 43 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
44 |
heightplot = self.HEIGHT + self.HEIGHTPROF |
|
|
44 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
|
45 | show=True) | |
|
45 | 46 | |
|
46 | 47 | nrow, ncol = self.getSubplots() |
|
47 | 48 | |
|
48 | 49 | counter = 0 |
|
49 | 50 | for y in range(nrow): |
|
50 | 51 | for x in range(ncol): |
|
51 | 52 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
52 | 53 | |
|
53 | 54 | counter += 1 |
|
54 | 55 | |
|
55 | 56 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
56 | 57 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
57 | 58 | save=False, figpath='./', figfile=None, |
|
58 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r'): | |
|
59 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True): | |
|
59 | 60 | |
|
60 | 61 | """ |
|
61 | 62 | |
|
62 | 63 | Input: |
|
63 | 64 | dataOut : |
|
64 | 65 | idfigure : |
|
65 | 66 | wintitle : |
|
66 | 67 | channelList : |
|
67 | 68 | showProfile : |
|
68 | 69 | xmin : None, |
|
69 | 70 | xmax : None, |
|
70 | 71 | ymin : None, |
|
71 | 72 | ymax : None, |
|
72 | 73 | zmin : None, |
|
73 | 74 | zmax : None |
|
74 | 75 | """ |
|
75 | 76 | |
|
76 | 77 | if pairsList == None: |
|
77 | 78 | pairsIndexList = dataOut.pairsIndexList |
|
78 | 79 | else: |
|
79 | 80 | pairsIndexList = [] |
|
80 | 81 | for pair in pairsList: |
|
81 | 82 | if pair not in dataOut.pairsList: |
|
82 | 83 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
83 | 84 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
84 | 85 | |
|
85 | 86 | if pairsIndexList == []: |
|
86 | 87 | return |
|
87 | 88 | |
|
88 | 89 | if len(pairsIndexList) > 4: |
|
89 | 90 | pairsIndexList = pairsIndexList[0:4] |
|
90 | 91 | factor = dataOut.normFactor |
|
91 | 92 | x = dataOut.getVelRange(1) |
|
92 | 93 | y = dataOut.getHeiRange() |
|
93 | 94 | z = dataOut.data_spc[:,:,:]/factor |
|
94 | 95 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
95 | 96 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
96 | 97 | noise = dataOut.getNoise()/factor |
|
97 | 98 | |
|
98 | 99 | zdB = 10*numpy.log10(z) |
|
99 | 100 | avgdB = 10*numpy.log10(avg) |
|
100 | 101 | noisedB = 10*numpy.log10(noise) |
|
101 | 102 | |
|
102 | 103 | |
|
103 | 104 | thisDatetime = dataOut.datatime |
|
104 | 105 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
105 | 106 | xlabel = "Velocity (m/s)" |
|
106 | 107 | ylabel = "Range (Km)" |
|
107 | 108 | |
|
108 | 109 | if not self.__isConfig: |
|
109 | 110 | |
|
110 | 111 | nplots = len(pairsIndexList) |
|
111 | 112 | |
|
112 | 113 | self.setup(idfigure=idfigure, |
|
113 | 114 | nplots=nplots, |
|
114 | 115 | wintitle=wintitle, |
|
115 |
showprofile=showprofile |
|
|
116 | showprofile=showprofile, | |
|
117 | show=show) | |
|
116 | 118 | |
|
117 | 119 | if xmin == None: xmin = numpy.nanmin(x) |
|
118 | 120 | if xmax == None: xmax = numpy.nanmax(x) |
|
119 | 121 | if ymin == None: ymin = numpy.nanmin(y) |
|
120 | 122 | if ymax == None: ymax = numpy.nanmax(y) |
|
121 | 123 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
122 | 124 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
123 | 125 | |
|
124 | 126 | self.__isConfig = True |
|
125 | 127 | |
|
126 | 128 | self.setWinTitle(title) |
|
127 | 129 | |
|
128 | 130 | for i in range(self.nplots): |
|
129 | 131 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
130 | 132 | |
|
131 | 133 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) |
|
132 | 134 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
133 | 135 | axes0 = self.axesList[i*self.__nsubplots] |
|
134 | 136 | axes0.pcolor(x, y, zdB, |
|
135 | 137 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
136 | 138 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
137 | 139 | ticksize=9, colormap=power_cmap, cblabel='') |
|
138 | 140 | |
|
139 | 141 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) |
|
140 | 142 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
141 | 143 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
142 | 144 | axes0.pcolor(x, y, zdB, |
|
143 | 145 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
144 | 146 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
145 | 147 | ticksize=9, colormap=power_cmap, cblabel='') |
|
146 | 148 | |
|
147 | 149 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
148 | 150 | coherence = numpy.abs(coherenceComplex) |
|
149 | 151 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
150 | 152 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
151 | 153 | |
|
152 | 154 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
153 | 155 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
154 | 156 | axes0.pcolor(x, y, coherence, |
|
155 | 157 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
156 | 158 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
157 | 159 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
158 | 160 | |
|
159 | 161 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
160 | 162 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
161 | 163 | axes0.pcolor(x, y, phase, |
|
162 | 164 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
163 | 165 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
164 | 166 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
165 | 167 | |
|
166 | 168 | |
|
167 | 169 | |
|
168 | 170 | self.draw() |
|
169 | 171 | |
|
170 | 172 | if save: |
|
171 | 173 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
172 | 174 | if figfile == None: |
|
173 | 175 | figfile = self.getFilename(name = date) |
|
174 | 176 | |
|
175 | 177 | self.saveFigure(figpath, figfile) |
|
176 | 178 | |
|
177 | 179 | |
|
178 | 180 | class RTIPlot(Figure): |
|
179 | 181 | |
|
180 | 182 | __isConfig = None |
|
181 | 183 | __nsubplots = None |
|
182 | 184 | |
|
183 | 185 | WIDTHPROF = None |
|
184 | 186 | HEIGHTPROF = None |
|
185 | 187 | PREFIX = 'rti' |
|
186 | 188 | |
|
187 | 189 | def __init__(self): |
|
188 | 190 | |
|
189 | 191 | self.timerange = 2*60*60 |
|
190 | 192 | self.__isConfig = False |
|
191 | 193 | self.__nsubplots = 1 |
|
192 | 194 | |
|
193 | 195 | self.WIDTH = 800 |
|
194 | 196 | self.HEIGHT = 150 |
|
195 | 197 | self.WIDTHPROF = 120 |
|
196 | 198 | self.HEIGHTPROF = 0 |
|
197 | 199 | self.counterftp = 0 |
|
198 | 200 | |
|
199 | 201 | def getSubplots(self): |
|
200 | 202 | |
|
201 | 203 | ncol = 1 |
|
202 | 204 | nrow = self.nplots |
|
203 | 205 | |
|
204 | 206 | return nrow, ncol |
|
205 | 207 | |
|
206 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
|
208 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): | |
|
207 | 209 | |
|
208 | 210 | self.__showprofile = showprofile |
|
209 | 211 | self.nplots = nplots |
|
210 | 212 | |
|
211 | 213 | ncolspan = 1 |
|
212 | 214 | colspan = 1 |
|
213 | 215 | if showprofile: |
|
214 | 216 | ncolspan = 7 |
|
215 | 217 | colspan = 6 |
|
216 | 218 | self.__nsubplots = 2 |
|
217 | 219 | |
|
218 | 220 | self.createFigure(idfigure = idfigure, |
|
219 | 221 | wintitle = wintitle, |
|
220 | 222 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
221 |
heightplot = self.HEIGHT + self.HEIGHTPROF |
|
|
223 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
|
224 | show=show) | |
|
222 | 225 | |
|
223 | 226 | nrow, ncol = self.getSubplots() |
|
224 | 227 | |
|
225 | 228 | counter = 0 |
|
226 | 229 | for y in range(nrow): |
|
227 | 230 | for x in range(ncol): |
|
228 | 231 | |
|
229 | 232 | if counter >= self.nplots: |
|
230 | 233 | break |
|
231 | 234 | |
|
232 | 235 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
233 | 236 | |
|
234 | 237 | if showprofile: |
|
235 | 238 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
236 | 239 | |
|
237 | 240 | counter += 1 |
|
238 | 241 | |
|
239 | 242 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
240 | 243 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
241 | 244 | timerange=None, |
|
242 | save=False, figpath='./', figfile=None, ftp=False, ftpratio=1): | |
|
245 | save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True): | |
|
243 | 246 | |
|
244 | 247 | """ |
|
245 | 248 | |
|
246 | 249 | Input: |
|
247 | 250 | dataOut : |
|
248 | 251 | idfigure : |
|
249 | 252 | wintitle : |
|
250 | 253 | channelList : |
|
251 | 254 | showProfile : |
|
252 | 255 | xmin : None, |
|
253 | 256 | xmax : None, |
|
254 | 257 | ymin : None, |
|
255 | 258 | ymax : None, |
|
256 | 259 | zmin : None, |
|
257 | 260 | zmax : None |
|
258 | 261 | """ |
|
259 | 262 | |
|
260 | 263 | if channelList == None: |
|
261 | 264 | channelIndexList = dataOut.channelIndexList |
|
262 | 265 | else: |
|
263 | 266 | channelIndexList = [] |
|
264 | 267 | for channel in channelList: |
|
265 | 268 | if channel not in dataOut.channelList: |
|
266 | 269 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
267 | 270 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
268 | 271 | |
|
269 | 272 | if timerange != None: |
|
270 | 273 | self.timerange = timerange |
|
271 | 274 | |
|
272 | 275 | tmin = None |
|
273 | 276 | tmax = None |
|
274 | 277 | factor = dataOut.normFactor |
|
275 | 278 | x = dataOut.getTimeRange() |
|
276 | 279 | y = dataOut.getHeiRange() |
|
277 | 280 | |
|
278 | 281 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
279 | 282 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
280 | 283 | avg = numpy.average(z, axis=1) |
|
281 | 284 | |
|
282 | 285 | avgdB = 10.*numpy.log10(avg) |
|
283 | 286 | |
|
284 | 287 | |
|
285 | 288 | thisDatetime = dataOut.datatime |
|
286 | 289 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
287 | 290 | xlabel = "" |
|
288 | 291 | ylabel = "Range (Km)" |
|
289 | 292 | |
|
290 | 293 | if not self.__isConfig: |
|
291 | 294 | |
|
292 | 295 | nplots = len(channelIndexList) |
|
293 | 296 | |
|
294 | 297 | self.setup(idfigure=idfigure, |
|
295 | 298 | nplots=nplots, |
|
296 | 299 | wintitle=wintitle, |
|
297 |
showprofile=showprofile |
|
|
300 | showprofile=showprofile, | |
|
301 | show=show) | |
|
298 | 302 | |
|
299 | 303 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
300 | 304 | if ymin == None: ymin = numpy.nanmin(y) |
|
301 | 305 | if ymax == None: ymax = numpy.nanmax(y) |
|
302 | 306 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
303 | 307 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
304 | 308 | |
|
305 | 309 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
306 | 310 | self.__isConfig = True |
|
307 | 311 | |
|
308 | 312 | |
|
309 | 313 | self.setWinTitle(title) |
|
310 | 314 | |
|
311 | 315 | for i in range(self.nplots): |
|
312 | 316 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
313 | 317 | axes = self.axesList[i*self.__nsubplots] |
|
314 | 318 | zdB = avgdB[i].reshape((1,-1)) |
|
315 | 319 | axes.pcolorbuffer(x, y, zdB, |
|
316 | 320 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
317 | 321 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
318 | 322 | ticksize=9, cblabel='', cbsize="1%") |
|
319 | 323 | |
|
320 | 324 | if self.__showprofile: |
|
321 | 325 | axes = self.axesList[i*self.__nsubplots +1] |
|
322 | 326 | axes.pline(avgdB[i], y, |
|
323 | 327 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
324 | 328 | xlabel='dB', ylabel='', title='', |
|
325 | 329 | ytick_visible=False, |
|
326 | 330 | grid='x') |
|
327 | 331 | |
|
328 | 332 | self.draw() |
|
329 | 333 | |
|
330 | 334 | if save: |
|
331 | 335 | |
|
332 | 336 | if figfile == None: |
|
333 | 337 | figfile = self.getFilename(name = self.name) |
|
334 | 338 | |
|
335 | 339 | self.saveFigure(figpath, figfile) |
|
336 | 340 | |
|
337 | 341 | self.counterftp += 1 |
|
338 | 342 | if (ftp and (self.counterftp==ftpratio)): |
|
339 | 343 | figfilename = os.path.join(figpath,figfile) |
|
340 | 344 | self.sendByFTP(figfilename) |
|
341 | 345 | self.counterftp = 0 |
|
342 | 346 | |
|
343 | 347 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
344 | 348 | self.__isConfig = False |
|
345 | 349 | |
|
346 | 350 | class SpectraPlot(Figure): |
|
347 | 351 | |
|
348 | 352 | __isConfig = None |
|
349 | 353 | __nsubplots = None |
|
350 | 354 | |
|
351 | 355 | WIDTHPROF = None |
|
352 | 356 | HEIGHTPROF = None |
|
353 | 357 | PREFIX = 'spc' |
|
354 | 358 | |
|
355 | 359 | def __init__(self): |
|
356 | 360 | |
|
357 | 361 | self.__isConfig = False |
|
358 | 362 | self.__nsubplots = 1 |
|
359 | 363 | |
|
360 | 364 | self.WIDTH = 230 |
|
361 | 365 | self.HEIGHT = 250 |
|
362 | 366 | self.WIDTHPROF = 120 |
|
363 | 367 | self.HEIGHTPROF = 0 |
|
364 | 368 | |
|
365 | 369 | def getSubplots(self): |
|
366 | 370 | |
|
367 | 371 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
368 | 372 | nrow = int(self.nplots*1./ncol + 0.9) |
|
369 | 373 | |
|
370 | 374 | return nrow, ncol |
|
371 | 375 | |
|
372 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
|
376 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): | |
|
373 | 377 | |
|
374 | 378 | self.__showprofile = showprofile |
|
375 | 379 | self.nplots = nplots |
|
376 | 380 | |
|
377 | 381 | ncolspan = 1 |
|
378 | 382 | colspan = 1 |
|
379 | 383 | if showprofile: |
|
380 | 384 | ncolspan = 3 |
|
381 | 385 | colspan = 2 |
|
382 | 386 | self.__nsubplots = 2 |
|
383 | 387 | |
|
384 | 388 | self.createFigure(idfigure = idfigure, |
|
385 | 389 | wintitle = wintitle, |
|
386 | 390 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
387 |
heightplot = self.HEIGHT + self.HEIGHTPROF |
|
|
391 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
|
392 | show=show) | |
|
388 | 393 | |
|
389 | 394 | nrow, ncol = self.getSubplots() |
|
390 | 395 | |
|
391 | 396 | counter = 0 |
|
392 | 397 | for y in range(nrow): |
|
393 | 398 | for x in range(ncol): |
|
394 | 399 | |
|
395 | 400 | if counter >= self.nplots: |
|
396 | 401 | break |
|
397 | 402 | |
|
398 | 403 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
399 | 404 | |
|
400 | 405 | if showprofile: |
|
401 | 406 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
402 | 407 | |
|
403 | 408 | counter += 1 |
|
404 | 409 | |
|
405 | 410 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
406 | 411 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
407 | save=False, figpath='./', figfile=None): | |
|
412 | save=False, figpath='./', figfile=None, show=True): | |
|
408 | 413 | |
|
409 | 414 | """ |
|
410 | 415 | |
|
411 | 416 | Input: |
|
412 | 417 | dataOut : |
|
413 | 418 | idfigure : |
|
414 | 419 | wintitle : |
|
415 | 420 | channelList : |
|
416 | 421 | showProfile : |
|
417 | 422 | xmin : None, |
|
418 | 423 | xmax : None, |
|
419 | 424 | ymin : None, |
|
420 | 425 | ymax : None, |
|
421 | 426 | zmin : None, |
|
422 | 427 | zmax : None |
|
423 | 428 | """ |
|
424 | 429 | |
|
425 | 430 | if channelList == None: |
|
426 | 431 | channelIndexList = dataOut.channelIndexList |
|
427 | 432 | else: |
|
428 | 433 | channelIndexList = [] |
|
429 | 434 | for channel in channelList: |
|
430 | 435 | if channel not in dataOut.channelList: |
|
431 | 436 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
432 | 437 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
433 | 438 | factor = dataOut.normFactor |
|
434 | 439 | x = dataOut.getVelRange(1) |
|
435 | 440 | y = dataOut.getHeiRange() |
|
436 | 441 | |
|
437 | 442 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
438 | 443 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
439 | 444 | avg = numpy.average(z, axis=1) |
|
440 | 445 | noise = dataOut.getNoise()/factor |
|
441 | 446 | |
|
442 | 447 | zdB = 10*numpy.log10(z) |
|
443 | 448 | avgdB = 10*numpy.log10(avg) |
|
444 | 449 | noisedB = 10*numpy.log10(noise) |
|
445 | 450 | |
|
446 | 451 | thisDatetime = dataOut.datatime |
|
447 | 452 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
448 | 453 | xlabel = "Velocity (m/s)" |
|
449 | 454 | ylabel = "Range (Km)" |
|
450 | 455 | |
|
451 | 456 | if not self.__isConfig: |
|
452 | 457 | |
|
453 | 458 | nplots = len(channelIndexList) |
|
454 | 459 | |
|
455 | 460 | self.setup(idfigure=idfigure, |
|
456 | 461 | nplots=nplots, |
|
457 | 462 | wintitle=wintitle, |
|
458 |
showprofile=showprofile |
|
|
463 | showprofile=showprofile, | |
|
464 | show=show) | |
|
459 | 465 | |
|
460 | 466 | if xmin == None: xmin = numpy.nanmin(x) |
|
461 | 467 | if xmax == None: xmax = numpy.nanmax(x) |
|
462 | 468 | if ymin == None: ymin = numpy.nanmin(y) |
|
463 | 469 | if ymax == None: ymax = numpy.nanmax(y) |
|
464 | 470 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
465 | 471 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
466 | 472 | |
|
467 | 473 | self.__isConfig = True |
|
468 | 474 | |
|
469 | 475 | self.setWinTitle(title) |
|
470 | 476 | |
|
471 | 477 | for i in range(self.nplots): |
|
472 | 478 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i]) |
|
473 | 479 | axes = self.axesList[i*self.__nsubplots] |
|
474 | 480 | axes.pcolor(x, y, zdB[i,:,:], |
|
475 | 481 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
476 | 482 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
477 | 483 | ticksize=9, cblabel='') |
|
478 | 484 | |
|
479 | 485 | if self.__showprofile: |
|
480 | 486 | axes = self.axesList[i*self.__nsubplots +1] |
|
481 | 487 | axes.pline(avgdB[i], y, |
|
482 | 488 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
483 | 489 | xlabel='dB', ylabel='', title='', |
|
484 | 490 | ytick_visible=False, |
|
485 | 491 | grid='x') |
|
486 | 492 | |
|
487 | 493 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
488 | 494 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
489 | 495 | |
|
490 | 496 | self.draw() |
|
491 | 497 | |
|
492 | 498 | if save: |
|
493 | 499 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
494 | 500 | if figfile == None: |
|
495 | 501 | figfile = self.getFilename(name = date) |
|
496 | 502 | |
|
497 | 503 | self.saveFigure(figpath, figfile) |
|
498 | 504 | |
|
499 | 505 | class Scope(Figure): |
|
500 | 506 | |
|
501 | 507 | __isConfig = None |
|
502 | 508 | |
|
503 | 509 | def __init__(self): |
|
504 | 510 | |
|
505 | 511 | self.__isConfig = False |
|
506 | 512 | self.WIDTH = 600 |
|
507 | 513 | self.HEIGHT = 200 |
|
508 | 514 | |
|
509 | 515 | def getSubplots(self): |
|
510 | 516 | |
|
511 | 517 | nrow = self.nplots |
|
512 | 518 | ncol = 3 |
|
513 | 519 | return nrow, ncol |
|
514 | 520 | |
|
515 | def setup(self, idfigure, nplots, wintitle): | |
|
521 | def setup(self, idfigure, nplots, wintitle, show): | |
|
516 | 522 | |
|
517 | 523 | self.nplots = nplots |
|
518 | 524 | |
|
519 |
self.createFigure(idfigure, |
|
|
525 | self.createFigure(idfigure=idfigure, | |
|
526 | wintitle=wintitle, | |
|
527 | show=show) | |
|
520 | 528 | |
|
521 | 529 | nrow,ncol = self.getSubplots() |
|
522 | 530 | colspan = 3 |
|
523 | 531 | rowspan = 1 |
|
524 | 532 | |
|
525 | 533 | for i in range(nplots): |
|
526 | 534 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
527 | 535 | |
|
528 | 536 | |
|
529 | 537 | |
|
530 | 538 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
531 | 539 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
532 | figpath='./', figfile=None): | |
|
540 | figpath='./', figfile=None, show=True): | |
|
533 | 541 | |
|
534 | 542 | """ |
|
535 | 543 | |
|
536 | 544 | Input: |
|
537 | 545 | dataOut : |
|
538 | 546 | idfigure : |
|
539 | 547 | wintitle : |
|
540 | 548 | channelList : |
|
541 | 549 | xmin : None, |
|
542 | 550 | xmax : None, |
|
543 | 551 | ymin : None, |
|
544 | 552 | ymax : None, |
|
545 | 553 | """ |
|
546 | 554 | |
|
547 | 555 | if channelList == None: |
|
548 | 556 | channelIndexList = dataOut.channelIndexList |
|
549 | 557 | else: |
|
550 | 558 | channelIndexList = [] |
|
551 | 559 | for channel in channelList: |
|
552 | 560 | if channel not in dataOut.channelList: |
|
553 | 561 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
554 | 562 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
555 | 563 | |
|
556 | 564 | x = dataOut.heightList |
|
557 | 565 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
558 | 566 | y = y.real |
|
559 | 567 | |
|
560 | 568 | thisDatetime = dataOut.datatime |
|
561 | 569 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
562 | 570 | xlabel = "Range (Km)" |
|
563 | 571 | ylabel = "Intensity" |
|
564 | 572 | |
|
565 | 573 | if not self.__isConfig: |
|
566 | 574 | nplots = len(channelIndexList) |
|
567 | 575 | |
|
568 | 576 | self.setup(idfigure=idfigure, |
|
569 | 577 | nplots=nplots, |
|
570 |
wintitle=wintitle |
|
|
578 | wintitle=wintitle, | |
|
579 | show=show) | |
|
571 | 580 | |
|
572 | 581 | if xmin == None: xmin = numpy.nanmin(x) |
|
573 | 582 | if xmax == None: xmax = numpy.nanmax(x) |
|
574 | 583 | if ymin == None: ymin = numpy.nanmin(y) |
|
575 | 584 | if ymax == None: ymax = numpy.nanmax(y) |
|
576 | 585 | |
|
577 | 586 | self.__isConfig = True |
|
578 | 587 | |
|
579 | 588 | self.setWinTitle(title) |
|
580 | 589 | |
|
581 | 590 | for i in range(len(self.axesList)): |
|
582 | 591 | title = "Channel %d" %(i) |
|
583 | 592 | axes = self.axesList[i] |
|
584 | 593 | ychannel = y[i,:] |
|
585 | 594 | axes.pline(x, ychannel, |
|
586 | 595 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
587 | 596 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
588 | 597 | |
|
589 | 598 | self.draw() |
|
590 | 599 | |
|
591 | 600 | if save: |
|
592 | 601 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
593 | 602 | if figfile == None: |
|
594 | 603 | figfile = self.getFilename(name = date) |
|
595 | 604 | |
|
596 | 605 | self.saveFigure(figpath, figfile) |
|
597 | 606 | |
|
598 | 607 | class ProfilePlot(Figure): |
|
599 | 608 | __isConfig = None |
|
600 | 609 | __nsubplots = None |
|
601 | 610 | |
|
602 | 611 | WIDTHPROF = None |
|
603 | 612 | HEIGHTPROF = None |
|
604 | 613 | PREFIX = 'spcprofile' |
|
605 | 614 | |
|
606 | 615 | def __init__(self): |
|
607 | 616 | self.__isConfig = False |
|
608 | 617 | self.__nsubplots = 1 |
|
609 | 618 | |
|
610 | 619 | self.WIDTH = 300 |
|
611 | 620 | self.HEIGHT = 500 |
|
612 | 621 | |
|
613 | 622 | def getSubplots(self): |
|
614 | 623 | ncol = 1 |
|
615 | 624 | nrow = 1 |
|
616 | 625 | |
|
617 | 626 | return nrow, ncol |
|
618 | 627 | |
|
619 | def setup(self, idfigure, nplots, wintitle): | |
|
628 | def setup(self, idfigure, nplots, wintitle, show): | |
|
620 | 629 | |
|
621 | 630 | self.nplots = nplots |
|
622 | 631 | |
|
623 | 632 | ncolspan = 1 |
|
624 | 633 | colspan = 1 |
|
625 | 634 | |
|
626 | 635 | self.createFigure(idfigure = idfigure, |
|
627 | 636 | wintitle = wintitle, |
|
628 | 637 | widthplot = self.WIDTH, |
|
629 |
heightplot = self.HEIGHT |
|
|
638 | heightplot = self.HEIGHT, | |
|
639 | show=show) | |
|
630 | 640 | |
|
631 | 641 | nrow, ncol = self.getSubplots() |
|
632 | 642 | |
|
633 | 643 | counter = 0 |
|
634 | 644 | for y in range(nrow): |
|
635 | 645 | for x in range(ncol): |
|
636 | 646 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
637 | 647 | |
|
638 | 648 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
639 | 649 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
640 | save=False, figpath='./', figfile=None): | |
|
650 | save=False, figpath='./', figfile=None, show=True): | |
|
641 | 651 | |
|
642 | 652 | if channelList == None: |
|
643 | 653 | channelIndexList = dataOut.channelIndexList |
|
644 | 654 | channelList = dataOut.channelList |
|
645 | 655 | else: |
|
646 | 656 | channelIndexList = [] |
|
647 | 657 | for channel in channelList: |
|
648 | 658 | if channel not in dataOut.channelList: |
|
649 | 659 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
650 | 660 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
651 | 661 | |
|
652 | 662 | factor = dataOut.normFactor |
|
653 | 663 | y = dataOut.getHeiRange() |
|
654 | 664 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
655 | 665 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
656 | 666 | avg = numpy.average(x, axis=1) |
|
657 | 667 | |
|
658 | 668 | avgdB = 10*numpy.log10(avg) |
|
659 | 669 | |
|
660 | 670 | thisDatetime = dataOut.datatime |
|
661 | 671 | title = "Power Profile" |
|
662 | 672 | xlabel = "dB" |
|
663 | 673 | ylabel = "Range (Km)" |
|
664 | 674 | |
|
665 | 675 | if not self.__isConfig: |
|
666 | 676 | |
|
667 | 677 | nplots = 1 |
|
668 | 678 | |
|
669 | 679 | self.setup(idfigure=idfigure, |
|
670 | 680 | nplots=nplots, |
|
671 |
wintitle=wintitle |
|
|
681 | wintitle=wintitle, | |
|
682 | show=show) | |
|
672 | 683 | |
|
673 | 684 | if ymin == None: ymin = numpy.nanmin(y) |
|
674 | 685 | if ymax == None: ymax = numpy.nanmax(y) |
|
675 | 686 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 |
|
676 | 687 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 |
|
677 | 688 | |
|
678 | 689 | self.__isConfig = True |
|
679 | 690 | |
|
680 | 691 | self.setWinTitle(title) |
|
681 | 692 | |
|
682 | 693 | |
|
683 | 694 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
684 | 695 | axes = self.axesList[0] |
|
685 | 696 | |
|
686 | 697 | legendlabels = ["channel %d"%x for x in channelList] |
|
687 | 698 | axes.pmultiline(avgdB, y, |
|
688 | 699 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
689 | 700 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
690 | 701 | ytick_visible=True, nxticks=5, |
|
691 | 702 | grid='x') |
|
692 | 703 | |
|
693 | 704 | self.draw() |
|
694 | 705 | |
|
695 | 706 | if save: |
|
696 | 707 | date = thisDatetime.strftime("%Y%m%d") |
|
697 | 708 | if figfile == None: |
|
698 | 709 | figfile = self.getFilename(name = date) |
|
699 | 710 | |
|
700 | 711 | self.saveFigure(figpath, figfile) |
|
701 | 712 | |
|
702 | 713 | class CoherenceMap(Figure): |
|
703 | 714 | __isConfig = None |
|
704 | 715 | __nsubplots = None |
|
705 | 716 | |
|
706 | 717 | WIDTHPROF = None |
|
707 | 718 | HEIGHTPROF = None |
|
708 | 719 | PREFIX = 'cmap' |
|
709 | 720 | |
|
710 | 721 | def __init__(self): |
|
711 | 722 | self.timerange = 2*60*60 |
|
712 | 723 | self.__isConfig = False |
|
713 | 724 | self.__nsubplots = 1 |
|
714 | 725 | |
|
715 | 726 | self.WIDTH = 800 |
|
716 | 727 | self.HEIGHT = 150 |
|
717 | 728 | self.WIDTHPROF = 120 |
|
718 | 729 | self.HEIGHTPROF = 0 |
|
719 | 730 | self.counterftp = 0 |
|
720 | 731 | |
|
721 | 732 | def getSubplots(self): |
|
722 | 733 | ncol = 1 |
|
723 | 734 | nrow = self.nplots*2 |
|
724 | 735 | |
|
725 | 736 | return nrow, ncol |
|
726 | 737 | |
|
727 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
|
738 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): | |
|
728 | 739 | self.__showprofile = showprofile |
|
729 | 740 | self.nplots = nplots |
|
730 | 741 | |
|
731 | 742 | ncolspan = 1 |
|
732 | 743 | colspan = 1 |
|
733 | 744 | if showprofile: |
|
734 | 745 | ncolspan = 7 |
|
735 | 746 | colspan = 6 |
|
736 | 747 | self.__nsubplots = 2 |
|
737 | 748 | |
|
738 | 749 | self.createFigure(idfigure = idfigure, |
|
739 | 750 | wintitle = wintitle, |
|
740 | 751 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
741 |
heightplot = self.HEIGHT + self.HEIGHTPROF |
|
|
752 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
|
753 | show=True) | |
|
742 | 754 | |
|
743 | 755 | nrow, ncol = self.getSubplots() |
|
744 | 756 | |
|
745 | 757 | for y in range(nrow): |
|
746 | 758 | for x in range(ncol): |
|
747 | 759 | |
|
748 | 760 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
749 | 761 | |
|
750 | 762 | if showprofile: |
|
751 | 763 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
752 | 764 | |
|
753 | 765 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
754 | 766 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
755 | 767 | timerange=None, |
|
756 | 768 | save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, |
|
757 | coherence_cmap='jet', phase_cmap='RdBu_r'): | |
|
769 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True): | |
|
758 | 770 | |
|
759 | 771 | if pairsList == None: |
|
760 | 772 | pairsIndexList = dataOut.pairsIndexList |
|
761 | 773 | else: |
|
762 | 774 | pairsIndexList = [] |
|
763 | 775 | for pair in pairsList: |
|
764 | 776 | if pair not in dataOut.pairsList: |
|
765 | 777 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
766 | 778 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
767 | 779 | |
|
768 | 780 | if timerange != None: |
|
769 | 781 | self.timerange = timerange |
|
770 | 782 | |
|
771 | 783 | if pairsIndexList == []: |
|
772 | 784 | return |
|
773 | 785 | |
|
774 | 786 | if len(pairsIndexList) > 4: |
|
775 | 787 | pairsIndexList = pairsIndexList[0:4] |
|
776 | 788 | |
|
777 | 789 | tmin = None |
|
778 | 790 | tmax = None |
|
779 | 791 | x = dataOut.getTimeRange() |
|
780 | 792 | y = dataOut.getHeiRange() |
|
781 | 793 | |
|
782 | 794 | thisDatetime = dataOut.datatime |
|
783 | 795 | title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
784 | 796 | xlabel = "" |
|
785 | 797 | ylabel = "Range (Km)" |
|
786 | 798 | |
|
787 | 799 | if not self.__isConfig: |
|
788 | 800 | nplots = len(pairsIndexList) |
|
789 | 801 | self.setup(idfigure=idfigure, |
|
790 | 802 | nplots=nplots, |
|
791 | 803 | wintitle=wintitle, |
|
792 |
showprofile=showprofile |
|
|
804 | showprofile=showprofile, | |
|
805 | show=show) | |
|
793 | 806 | |
|
794 | 807 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
795 | 808 | if ymin == None: ymin = numpy.nanmin(y) |
|
796 | 809 | if ymax == None: ymax = numpy.nanmax(y) |
|
797 | 810 | |
|
798 | 811 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
799 | 812 | |
|
800 | 813 | self.__isConfig = True |
|
801 | 814 | |
|
802 | 815 | self.setWinTitle(title) |
|
803 | 816 | |
|
804 | 817 | for i in range(self.nplots): |
|
805 | 818 | |
|
806 | 819 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
807 | 820 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
808 | 821 | avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) |
|
809 | 822 | coherence = numpy.abs(avgcoherenceComplex) |
|
810 | 823 | # coherence = numpy.abs(coherenceComplex) |
|
811 | 824 | # avg = numpy.average(coherence, axis=0) |
|
812 | 825 | |
|
813 | 826 | z = coherence.reshape((1,-1)) |
|
814 | 827 | |
|
815 | 828 | counter = 0 |
|
816 | 829 | |
|
817 | 830 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
818 | 831 | axes = self.axesList[i*self.__nsubplots*2] |
|
819 | 832 | axes.pcolorbuffer(x, y, z, |
|
820 | 833 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
821 | 834 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
822 | 835 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
823 | 836 | |
|
824 | 837 | if self.__showprofile: |
|
825 | 838 | counter += 1 |
|
826 | 839 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
827 | 840 | axes.pline(coherence, y, |
|
828 | 841 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, |
|
829 | 842 | xlabel='', ylabel='', title='', ticksize=7, |
|
830 | 843 | ytick_visible=False, nxticks=5, |
|
831 | 844 | grid='x') |
|
832 | 845 | |
|
833 | 846 | counter += 1 |
|
834 | 847 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
835 | 848 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
836 | 849 | # avg = numpy.average(phase, axis=0) |
|
837 | 850 | z = phase.reshape((1,-1)) |
|
838 | 851 | |
|
839 | 852 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
840 | 853 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
841 | 854 | axes.pcolorbuffer(x, y, z, |
|
842 | 855 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
843 | 856 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
844 | 857 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
845 | 858 | |
|
846 | 859 | if self.__showprofile: |
|
847 | 860 | counter += 1 |
|
848 | 861 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
849 | 862 | axes.pline(phase, y, |
|
850 | 863 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
851 | 864 | xlabel='', ylabel='', title='', ticksize=7, |
|
852 | 865 | ytick_visible=False, nxticks=4, |
|
853 | 866 | grid='x') |
|
854 | 867 | |
|
855 | 868 | self.draw() |
|
856 | 869 | |
|
857 | 870 | if save: |
|
858 | 871 | |
|
859 | 872 | if figfile == None: |
|
860 | 873 | figfile = self.getFilename(name = self.name) |
|
861 | 874 | |
|
862 | 875 | self.saveFigure(figpath, figfile) |
|
863 | 876 | |
|
864 | 877 | self.counterftp += 1 |
|
865 | 878 | if (ftp and (self.counterftp==ftpratio)): |
|
866 | 879 | figfilename = os.path.join(figpath,figfile) |
|
867 | 880 | self.sendByFTP(figfilename) |
|
868 | 881 | self.counterftp = 0 |
|
869 | 882 | |
|
870 | 883 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
871 | 884 | self.__isConfig = False |
|
872 | 885 | |
|
873 | 886 | class RTIfromNoise(Figure): |
|
874 | 887 | |
|
875 | 888 | __isConfig = None |
|
876 | 889 | __nsubplots = None |
|
877 | 890 | |
|
878 | 891 | PREFIX = 'rtinoise' |
|
879 | 892 | |
|
880 | 893 | def __init__(self): |
|
881 | 894 | |
|
882 | 895 | self.timerange = 24*60*60 |
|
883 | 896 | self.__isConfig = False |
|
884 | 897 | self.__nsubplots = 1 |
|
885 | 898 | |
|
886 | 899 | self.WIDTH = 820 |
|
887 | 900 | self.HEIGHT = 200 |
|
888 | 901 | self.WIDTHPROF = 120 |
|
889 | 902 | self.HEIGHTPROF = 0 |
|
890 | 903 | self.xdata = None |
|
891 | 904 | self.ydata = None |
|
892 | 905 | |
|
893 | 906 | def getSubplots(self): |
|
894 | 907 | |
|
895 | 908 | ncol = 1 |
|
896 | 909 | nrow = 1 |
|
897 | 910 | |
|
898 | 911 | return nrow, ncol |
|
899 | 912 | |
|
900 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
|
913 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): | |
|
901 | 914 | |
|
902 | 915 | self.__showprofile = showprofile |
|
903 | 916 | self.nplots = nplots |
|
904 | 917 | |
|
905 | 918 | ncolspan = 7 |
|
906 | 919 | colspan = 6 |
|
907 | 920 | self.__nsubplots = 2 |
|
908 | 921 | |
|
909 | 922 | self.createFigure(idfigure = idfigure, |
|
910 | 923 | wintitle = wintitle, |
|
911 | 924 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
912 |
heightplot = self.HEIGHT+self.HEIGHTPROF |
|
|
925 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
|
926 | show=show) | |
|
913 | 927 | |
|
914 | 928 | nrow, ncol = self.getSubplots() |
|
915 | 929 | |
|
916 | 930 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
917 | 931 | |
|
918 | 932 | |
|
919 | 933 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
920 | 934 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
921 | 935 | timerange=None, |
|
922 | save=False, figpath='./', figfile=None): | |
|
936 | save=False, figpath='./', figfile=None, show=True): | |
|
923 | 937 | |
|
924 | 938 | if channelList == None: |
|
925 | 939 | channelIndexList = dataOut.channelIndexList |
|
926 | 940 | channelList = dataOut.channelList |
|
927 | 941 | else: |
|
928 | 942 | channelIndexList = [] |
|
929 | 943 | for channel in channelList: |
|
930 | 944 | if channel not in dataOut.channelList: |
|
931 | 945 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
932 | 946 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
933 | 947 | |
|
934 | 948 | if timerange != None: |
|
935 | 949 | self.timerange = timerange |
|
936 | 950 | |
|
937 | 951 | tmin = None |
|
938 | 952 | tmax = None |
|
939 | 953 | x = dataOut.getTimeRange() |
|
940 | 954 | y = dataOut.getHeiRange() |
|
941 | 955 | factor = dataOut.normFactor |
|
942 | 956 | noise = dataOut.getNoise()/factor |
|
943 | 957 | noisedB = 10*numpy.log10(noise) |
|
944 | 958 | |
|
945 | 959 | thisDatetime = dataOut.datatime |
|
946 | 960 | title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
947 | 961 | xlabel = "" |
|
948 | 962 | ylabel = "Range (Km)" |
|
949 | 963 | |
|
950 | 964 | if not self.__isConfig: |
|
951 | 965 | |
|
952 | 966 | nplots = 1 |
|
953 | 967 | |
|
954 | 968 | self.setup(idfigure=idfigure, |
|
955 | 969 | nplots=nplots, |
|
956 | 970 | wintitle=wintitle, |
|
957 |
showprofile=showprofile |
|
|
971 | showprofile=showprofile, | |
|
972 | show=show) | |
|
958 | 973 | |
|
959 | 974 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
960 | 975 | if ymin == None: ymin = numpy.nanmin(noisedB) |
|
961 | 976 | if ymax == None: ymax = numpy.nanmax(noisedB) |
|
962 | 977 | |
|
963 | 978 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
964 | 979 | self.__isConfig = True |
|
965 | 980 | |
|
966 | 981 | self.xdata = numpy.array([]) |
|
967 | 982 | self.ydata = numpy.array([]) |
|
968 | 983 | |
|
969 | 984 | self.setWinTitle(title) |
|
970 | 985 | |
|
971 | 986 | |
|
972 | 987 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
973 | 988 | |
|
974 | 989 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
975 | 990 | axes = self.axesList[0] |
|
976 | 991 | |
|
977 | 992 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
978 | 993 | |
|
979 | 994 | if len(self.ydata)==0: |
|
980 | 995 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
981 | 996 | else: |
|
982 | 997 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
983 | 998 | |
|
984 | 999 | |
|
985 | 1000 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
986 | 1001 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
987 | 1002 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
988 | 1003 | XAxisAsTime=True |
|
989 | 1004 | ) |
|
990 | 1005 | |
|
991 | 1006 | self.draw() |
|
992 | 1007 | |
|
993 | 1008 | if save: |
|
994 | 1009 | |
|
995 | 1010 | if figfile == None: |
|
996 | 1011 | figfile = self.getFilename(name = self.name) |
|
997 | 1012 | |
|
998 | 1013 | self.saveFigure(figpath, figfile) |
|
999 | 1014 | |
|
1000 | 1015 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1001 | 1016 | self.__isConfig = False |
|
1002 | 1017 | del self.xdata |
|
1003 | 1018 | del self.ydata |
|
1004 | 1019 | |
|
1005 | 1020 | |
|
1006 | 1021 | class SpectraHeisScope(Figure): |
|
1007 | 1022 | |
|
1008 | 1023 | |
|
1009 | 1024 | __isConfig = None |
|
1010 | 1025 | __nsubplots = None |
|
1011 | 1026 | |
|
1012 | 1027 | WIDTHPROF = None |
|
1013 | 1028 | HEIGHTPROF = None |
|
1014 | 1029 | PREFIX = 'spc' |
|
1015 | 1030 | |
|
1016 | 1031 | def __init__(self): |
|
1017 | 1032 | |
|
1018 | 1033 | self.__isConfig = False |
|
1019 | 1034 | self.__nsubplots = 1 |
|
1020 | 1035 | |
|
1021 | 1036 | self.WIDTH = 230 |
|
1022 | 1037 | self.HEIGHT = 250 |
|
1023 | 1038 | self.WIDTHPROF = 120 |
|
1024 | 1039 | self.HEIGHTPROF = 0 |
|
1025 | 1040 | self.counterftp = 0 |
|
1026 | 1041 | |
|
1027 | 1042 | def getSubplots(self): |
|
1028 | 1043 | |
|
1029 | 1044 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1030 | 1045 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1031 | 1046 | |
|
1032 | 1047 | return nrow, ncol |
|
1033 | 1048 | |
|
1034 | def setup(self, idfigure, nplots, wintitle): | |
|
1049 | def setup(self, idfigure, nplots, wintitle, show): | |
|
1035 | 1050 | |
|
1036 | 1051 | showprofile = False |
|
1037 | 1052 | self.__showprofile = showprofile |
|
1038 | 1053 | self.nplots = nplots |
|
1039 | 1054 | |
|
1040 | 1055 | ncolspan = 1 |
|
1041 | 1056 | colspan = 1 |
|
1042 | 1057 | if showprofile: |
|
1043 | 1058 | ncolspan = 3 |
|
1044 | 1059 | colspan = 2 |
|
1045 | 1060 | self.__nsubplots = 2 |
|
1046 | 1061 | |
|
1047 | 1062 | self.createFigure(idfigure = idfigure, |
|
1048 | 1063 | wintitle = wintitle, |
|
1049 | 1064 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1050 |
heightplot = self.HEIGHT + self.HEIGHTPROF |
|
|
1065 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
|
1066 | show = show) | |
|
1051 | 1067 | |
|
1052 | 1068 | nrow, ncol = self.getSubplots() |
|
1053 | 1069 | |
|
1054 | 1070 | counter = 0 |
|
1055 | 1071 | for y in range(nrow): |
|
1056 | 1072 | for x in range(ncol): |
|
1057 | 1073 | |
|
1058 | 1074 | if counter >= self.nplots: |
|
1059 | 1075 | break |
|
1060 | 1076 | |
|
1061 | 1077 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1062 | 1078 | |
|
1063 | 1079 | if showprofile: |
|
1064 | 1080 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1065 | 1081 | |
|
1066 | 1082 | counter += 1 |
|
1067 | 1083 | |
|
1068 | 1084 | # __isConfig = None |
|
1069 | 1085 | # def __init__(self): |
|
1070 | 1086 | # |
|
1071 | 1087 | # self.__isConfig = False |
|
1072 | 1088 | # self.WIDTH = 600 |
|
1073 | 1089 | # self.HEIGHT = 200 |
|
1074 | 1090 | # |
|
1075 | 1091 | # def getSubplots(self): |
|
1076 | 1092 | # |
|
1077 | 1093 | # nrow = self.nplots |
|
1078 | 1094 | # ncol = 3 |
|
1079 | 1095 | # return nrow, ncol |
|
1080 | 1096 | # |
|
1081 | 1097 | # def setup(self, idfigure, nplots, wintitle): |
|
1082 | 1098 | # |
|
1083 | 1099 | # self.nplots = nplots |
|
1084 | 1100 | # |
|
1085 | 1101 | # self.createFigure(idfigure, wintitle) |
|
1086 | 1102 | # |
|
1087 | 1103 | # nrow,ncol = self.getSubplots() |
|
1088 | 1104 | # colspan = 3 |
|
1089 | 1105 | # rowspan = 1 |
|
1090 | 1106 | # |
|
1091 | 1107 | # for i in range(nplots): |
|
1092 | 1108 | # self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
1093 | 1109 | |
|
1094 | 1110 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
1095 | 1111 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
1096 | figpath='./', figfile=None, ftp=False, ftpratio=1): | |
|
1112 | figpath='./', figfile=None, ftp=False, ftpratio=1, show=True): | |
|
1097 | 1113 | |
|
1098 | 1114 | """ |
|
1099 | 1115 | |
|
1100 | 1116 | Input: |
|
1101 | 1117 | dataOut : |
|
1102 | 1118 | idfigure : |
|
1103 | 1119 | wintitle : |
|
1104 | 1120 | channelList : |
|
1105 | 1121 | xmin : None, |
|
1106 | 1122 | xmax : None, |
|
1107 | 1123 | ymin : None, |
|
1108 | 1124 | ymax : None, |
|
1109 | 1125 | """ |
|
1110 | 1126 | |
|
1111 | 1127 | if channelList == None: |
|
1112 | 1128 | channelIndexList = dataOut.channelIndexList |
|
1113 | 1129 | else: |
|
1114 | 1130 | channelIndexList = [] |
|
1115 | 1131 | for channel in channelList: |
|
1116 | 1132 | if channel not in dataOut.channelList: |
|
1117 | 1133 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1118 | 1134 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1119 | 1135 | |
|
1120 | 1136 | # x = dataOut.heightList |
|
1121 | 1137 | c = 3E8 |
|
1122 | 1138 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1123 | 1139 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
1124 | 1140 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
1125 | 1141 | x= x/(10000.0) |
|
1126 | 1142 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
1127 | 1143 | # y = y.real |
|
1128 | 1144 | datadB = 10.*numpy.log10(dataOut.data_spc) |
|
1129 | 1145 | y = datadB |
|
1130 | 1146 | |
|
1131 | 1147 | thisDatetime = dataOut.datatime |
|
1132 | 1148 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1133 | 1149 | xlabel = "Frequency x 10000" |
|
1134 | 1150 | ylabel = "Intensity (dB)" |
|
1135 | 1151 | |
|
1136 | 1152 | if not self.__isConfig: |
|
1137 | 1153 | nplots = len(channelIndexList) |
|
1138 | 1154 | |
|
1139 | 1155 | self.setup(idfigure=idfigure, |
|
1140 | 1156 | nplots=nplots, |
|
1141 |
wintitle=wintitle |
|
|
1157 | wintitle=wintitle, | |
|
1158 | show=show) | |
|
1142 | 1159 | |
|
1143 | 1160 | if xmin == None: xmin = numpy.nanmin(x) |
|
1144 | 1161 | if xmax == None: xmax = numpy.nanmax(x) |
|
1145 | 1162 | if ymin == None: ymin = numpy.nanmin(y) |
|
1146 | 1163 | if ymax == None: ymax = numpy.nanmax(y) |
|
1147 | 1164 | |
|
1148 | 1165 | self.__isConfig = True |
|
1149 | 1166 | |
|
1150 | 1167 | self.setWinTitle(title) |
|
1151 | 1168 | |
|
1152 | 1169 | for i in range(len(self.axesList)): |
|
1153 | 1170 | ychannel = y[i,:] |
|
1154 | 1171 | title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel)) |
|
1155 | 1172 | axes = self.axesList[i] |
|
1156 | 1173 | axes.pline(x, ychannel, |
|
1157 | 1174 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1158 | 1175 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
1159 | 1176 | |
|
1177 | ||
|
1160 | 1178 | self.draw() |
|
1161 | 1179 | |
|
1162 | 1180 | if save: |
|
1163 | 1181 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1164 | 1182 | if figfile == None: |
|
1165 | 1183 | figfile = self.getFilename(name = date) |
|
1166 | 1184 | |
|
1167 | 1185 | self.saveFigure(figpath, figfile) |
|
1168 | 1186 | |
|
1169 | 1187 | self.counterftp += 1 |
|
1170 | 1188 | if (ftp and (self.counterftp==ftpratio)): |
|
1171 | 1189 | figfilename = os.path.join(figpath,figfile) |
|
1172 | 1190 | self.sendByFTP(figfilename) |
|
1173 | 1191 | self.counterftp = 0 |
|
1174 | 1192 | |
|
1175 | 1193 | |
|
1176 | 1194 | class RTIfromSpectraHeis(Figure): |
|
1177 | 1195 | |
|
1178 | 1196 | __isConfig = None |
|
1179 | 1197 | __nsubplots = None |
|
1180 | 1198 | |
|
1181 | 1199 | PREFIX = 'rtinoise' |
|
1182 | 1200 | |
|
1183 | 1201 | def __init__(self): |
|
1184 | 1202 | |
|
1185 | 1203 | self.timerange = 24*60*60 |
|
1186 | 1204 | self.__isConfig = False |
|
1187 | 1205 | self.__nsubplots = 1 |
|
1188 | 1206 | |
|
1189 | 1207 | self.WIDTH = 820 |
|
1190 | 1208 | self.HEIGHT = 200 |
|
1191 | 1209 | self.WIDTHPROF = 120 |
|
1192 | 1210 | self.HEIGHTPROF = 0 |
|
1193 | 1211 | self.counterftp = 0 |
|
1194 | 1212 | self.xdata = None |
|
1195 | 1213 | self.ydata = None |
|
1196 | 1214 | |
|
1197 | 1215 | def getSubplots(self): |
|
1198 | 1216 | |
|
1199 | 1217 | ncol = 1 |
|
1200 | 1218 | nrow = 1 |
|
1201 | 1219 | |
|
1202 | 1220 | return nrow, ncol |
|
1203 | 1221 | |
|
1204 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
|
1222 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): | |
|
1205 | 1223 | |
|
1206 | 1224 | self.__showprofile = showprofile |
|
1207 | 1225 | self.nplots = nplots |
|
1208 | 1226 | |
|
1209 | 1227 | ncolspan = 7 |
|
1210 | 1228 | colspan = 6 |
|
1211 | 1229 | self.__nsubplots = 2 |
|
1212 | 1230 | |
|
1213 | 1231 | self.createFigure(idfigure = idfigure, |
|
1214 | 1232 | wintitle = wintitle, |
|
1215 | 1233 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1216 |
heightplot = self.HEIGHT+self.HEIGHTPROF |
|
|
1234 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
|
1235 | show = show) | |
|
1217 | 1236 | |
|
1218 | 1237 | nrow, ncol = self.getSubplots() |
|
1219 | 1238 | |
|
1220 | 1239 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1221 | 1240 | |
|
1222 | 1241 | |
|
1223 | 1242 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
1224 | 1243 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1225 | 1244 | timerange=None, |
|
1226 | save=False, figpath='./', figfile=None, ftp=False, ftpratio=1): | |
|
1245 | save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True): | |
|
1227 | 1246 | |
|
1228 | 1247 | if channelList == None: |
|
1229 | 1248 | channelIndexList = dataOut.channelIndexList |
|
1230 | 1249 | channelList = dataOut.channelList |
|
1231 | 1250 | else: |
|
1232 | 1251 | channelIndexList = [] |
|
1233 | 1252 | for channel in channelList: |
|
1234 | 1253 | if channel not in dataOut.channelList: |
|
1235 | 1254 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1236 | 1255 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1237 | 1256 | |
|
1238 | 1257 | if timerange != None: |
|
1239 | 1258 | self.timerange = timerange |
|
1240 | 1259 | |
|
1241 | 1260 | tmin = None |
|
1242 | 1261 | tmax = None |
|
1243 | 1262 | x = dataOut.getTimeRange() |
|
1244 | 1263 | y = dataOut.getHeiRange() |
|
1245 | 1264 | |
|
1246 | 1265 | factor = 1 |
|
1247 | 1266 | data = dataOut.data_spc/factor |
|
1248 | 1267 | data = numpy.average(data,axis=1) |
|
1249 | 1268 | datadB = 10*numpy.log10(data) |
|
1250 | 1269 | |
|
1251 | 1270 | # factor = dataOut.normFactor |
|
1252 | 1271 | # noise = dataOut.getNoise()/factor |
|
1253 | 1272 | # noisedB = 10*numpy.log10(noise) |
|
1254 | 1273 | |
|
1255 | 1274 | thisDatetime = dataOut.datatime |
|
1256 | 1275 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1257 | 1276 | xlabel = "Local Time" |
|
1258 | 1277 | ylabel = "Intensity (dB)" |
|
1259 | 1278 | |
|
1260 | 1279 | if not self.__isConfig: |
|
1261 | 1280 | |
|
1262 | 1281 | nplots = 1 |
|
1263 | 1282 | |
|
1264 | 1283 | self.setup(idfigure=idfigure, |
|
1265 | 1284 | nplots=nplots, |
|
1266 | 1285 | wintitle=wintitle, |
|
1267 |
showprofile=showprofile |
|
|
1286 | showprofile=showprofile, | |
|
1287 | show=show) | |
|
1268 | 1288 | |
|
1269 | 1289 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1270 | 1290 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
1271 | 1291 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
1272 | 1292 | |
|
1273 | 1293 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1274 | 1294 | self.__isConfig = True |
|
1275 | 1295 | |
|
1276 | 1296 | self.xdata = numpy.array([]) |
|
1277 | 1297 | self.ydata = numpy.array([]) |
|
1278 | 1298 | |
|
1279 | 1299 | self.setWinTitle(title) |
|
1280 | 1300 | |
|
1281 | 1301 | |
|
1282 | 1302 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1283 | 1303 | title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1284 | 1304 | |
|
1285 | 1305 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
1286 | 1306 | axes = self.axesList[0] |
|
1287 | 1307 | |
|
1288 | 1308 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1289 | 1309 | |
|
1290 | 1310 | if len(self.ydata)==0: |
|
1291 | 1311 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
1292 | 1312 | else: |
|
1293 | 1313 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
1294 | 1314 | |
|
1295 | 1315 | |
|
1296 | 1316 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1297 | 1317 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1298 | 1318 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
1299 | 1319 | XAxisAsTime=True |
|
1300 | 1320 | ) |
|
1301 | 1321 | |
|
1302 | 1322 | self.draw() |
|
1303 | 1323 | |
|
1304 | 1324 | if save: |
|
1305 | 1325 | |
|
1306 | 1326 | if figfile == None: |
|
1307 | 1327 | figfile = self.getFilename(name = self.name) |
|
1308 | 1328 | |
|
1309 | 1329 | self.saveFigure(figpath, figfile) |
|
1310 | 1330 | |
|
1311 | 1331 | self.counterftp += 1 |
|
1312 | 1332 | if (ftp and (self.counterftp==ftpratio)): |
|
1313 | 1333 | figfilename = os.path.join(figpath,figfile) |
|
1314 | 1334 | self.sendByFTP(figfilename) |
|
1315 | 1335 | self.counterftp = 0 |
|
1316 | 1336 | |
|
1317 | 1337 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1318 | 1338 | self.__isConfig = False |
|
1319 | 1339 | del self.xdata |
|
1320 | 1340 | del self.ydata |
|
1321 | 1341 | |
|
1322 | 1342 | |
|
1323 | 1343 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now