##// END OF EJS Templates
Se restrige el numero de pares a graficar en Cross-Spectra....
Miguel Valdez -
r228:1fb3505cb0b4
parent child
Show More
@@ -1,589 +1,592
1 1 import numpy
2 2 import time, datetime
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 WIDTHPROF = None
11 11 HEIGHTPROF = None
12 PREFIX = 'spc'
12 PREFIX = 'cspc'
13 13
14 14 def __init__(self):
15 15
16 16 self.__isConfig = False
17 17 self.__nsubplots = 4
18 18
19 19 self.WIDTH = 300
20 20 self.HEIGHT = 400
21 21 self.WIDTHPROF = 0
22 22 self.HEIGHTPROF = 0
23 23
24 24 def getSubplots(self):
25 25
26 26 ncol = 4
27 27 nrow = self.nplots
28 28
29 29 return nrow, ncol
30 30
31 31 def setup(self, idfigure, nplots, wintitle, showprofile=True):
32 32
33 33 self.__showprofile = showprofile
34 34 self.nplots = nplots
35 35
36 36 ncolspan = 1
37 37 colspan = 1
38 38
39 39 self.createFigure(idfigure = idfigure,
40 40 wintitle = wintitle,
41 41 widthplot = self.WIDTH + self.WIDTHPROF,
42 42 heightplot = self.HEIGHT + self.HEIGHTPROF)
43 43
44 44 nrow, ncol = self.getSubplots()
45 45
46 46 counter = 0
47 47 for y in range(nrow):
48 48 for x in range(ncol):
49 49 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
50 50
51 51 counter += 1
52 52
53 53 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
54 54 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
55 55 save=False, figpath='./', figfile=None):
56 56
57 57 """
58 58
59 59 Input:
60 60 dataOut :
61 61 idfigure :
62 62 wintitle :
63 63 channelList :
64 64 showProfile :
65 65 xmin : None,
66 66 xmax : None,
67 67 ymin : None,
68 68 ymax : None,
69 69 zmin : None,
70 70 zmax : None
71 71 """
72 72
73 73 if pairsList == None:
74 74 pairsIndexList = dataOut.pairsIndexList
75 75 else:
76 76 pairsIndexList = []
77 77 for pair in pairsList:
78 78 if pair not in dataOut.pairsList:
79 79 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
80 80 pairsIndexList.append(dataOut.pairsList.index(pair))
81 81
82 82 if pairsIndexList == []:
83 83 return
84 84
85 if len(pairsIndexList) > 4:
86 pairsIndexList = pairsIndexList[0:4]
87
85 88 x = dataOut.getFreqRange(1)
86 89 y = dataOut.getHeiRange()
87 90 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
88 91 avg = numpy.average(numpy.abs(z), axis=1)
89 92
90 93 noise = dataOut.getNoise()
91 94
92 95 if not self.__isConfig:
93 96
94 97 nplots = len(pairsIndexList)
95 98
96 99 self.setup(idfigure=idfigure,
97 100 nplots=nplots,
98 101 wintitle=wintitle,
99 102 showprofile=showprofile)
100 103
101 104 if xmin == None: xmin = numpy.nanmin(x)
102 105 if xmax == None: xmax = numpy.nanmax(x)
103 106 if ymin == None: ymin = numpy.nanmin(y)
104 107 if ymax == None: ymax = numpy.nanmax(y)
105 108 if zmin == None: zmin = numpy.nanmin(avg)*0.9
106 109 if zmax == None: zmax = numpy.nanmax(avg)*0.9
107 110
108 111 self.__isConfig = True
109 112
110 113 thisDatetime = dataOut.datatime
111 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
114 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
112 115 xlabel = "Velocity (m/s)"
113 116 ylabel = "Range (Km)"
114 117
115 118 self.setWinTitle(title)
116 119
117 120 for i in range(self.nplots):
118 121 pair = dataOut.pairsList[pairsIndexList[i]]
119 122
120 123 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
121 124 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
122 125 axes0 = self.axesList[i*self.__nsubplots]
123 126 axes0.pcolor(x, y, z,
124 127 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
125 128 xlabel=xlabel, ylabel=ylabel, title=title,
126 129 ticksize=9, cblabel='')
127 130
128 131 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
129 132 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
130 133 axes0 = self.axesList[i*self.__nsubplots+1]
131 134 axes0.pcolor(x, y, z,
132 135 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
133 136 xlabel=xlabel, ylabel=ylabel, title=title,
134 137 ticksize=9, cblabel='')
135 138
136 139 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
137 140 coherence = numpy.abs(coherenceComplex)
138 141 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
139 142
140 143
141 144 title = "Coherence %d%d" %(pair[0], pair[1])
142 145 axes0 = self.axesList[i*self.__nsubplots+2]
143 146 axes0.pcolor(x, y, coherence,
144 147 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
145 148 xlabel=xlabel, ylabel=ylabel, title=title,
146 149 ticksize=9, cblabel='')
147 150
148 151 title = "Phase %d%d" %(pair[0], pair[1])
149 152 axes0 = self.axesList[i*self.__nsubplots+3]
150 153 axes0.pcolor(x, y, phase,
151 154 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
152 155 xlabel=xlabel, ylabel=ylabel, title=title,
153 156 ticksize=9, cblabel='', colormap='RdBu')
154 157
155 158
156 159
157 160 self.draw()
158 161
159 162 if save:
160 163 date = thisDatetime.strftime("%Y%m%d")
161 164 if figfile == None:
162 165 figfile = self.getFilename(name = date)
163 166
164 167 self.saveFigure(figpath, figfile)
165 168
166 169
167 170 class RTIPlot(Figure):
168 171
169 172 __isConfig = None
170 173 __nsubplots = None
171 174
172 175 WIDTHPROF = None
173 176 HEIGHTPROF = None
174 177 PREFIX = 'rti'
175 178
176 179 def __init__(self):
177 180
178 181 self.__timerange = 24*60*60
179 182 self.__isConfig = False
180 183 self.__nsubplots = 1
181 184
182 185 self.WIDTH = 800
183 186 self.HEIGHT = 200
184 187 self.WIDTHPROF = 120
185 188 self.HEIGHTPROF = 0
186 189
187 190 def getSubplots(self):
188 191
189 192 ncol = 1
190 193 nrow = self.nplots
191 194
192 195 return nrow, ncol
193 196
194 197 def setup(self, idfigure, nplots, wintitle, showprofile=True):
195 198
196 199 self.__showprofile = showprofile
197 200 self.nplots = nplots
198 201
199 202 ncolspan = 1
200 203 colspan = 1
201 204 if showprofile:
202 205 ncolspan = 7
203 206 colspan = 6
204 207 self.__nsubplots = 2
205 208
206 209 self.createFigure(idfigure = idfigure,
207 210 wintitle = wintitle,
208 211 widthplot = self.WIDTH + self.WIDTHPROF,
209 212 heightplot = self.HEIGHT + self.HEIGHTPROF)
210 213
211 214 nrow, ncol = self.getSubplots()
212 215
213 216 counter = 0
214 217 for y in range(nrow):
215 218 for x in range(ncol):
216 219
217 220 if counter >= self.nplots:
218 221 break
219 222
220 223 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
221 224
222 225 if showprofile:
223 226 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
224 227
225 228 counter += 1
226 229
227 230 def __getTimeLim(self, x, xmin, xmax):
228 231
229 thisdatetime = datetime.datetime.utcfromtimestamp(numpy.min(x))
232 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
230 233 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
231 234
232 235 ####################################################
233 236 #If the x is out of xrange
234 237 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
235 238 xmin = None
236 239 xmax = None
237 240
238 241 if xmin == None:
239 242 td = thisdatetime - thisdate
240 243 xmin = td.seconds/(60*60.)
241 244
242 245 if xmax == None:
243 246 xmax = xmin + self.__timerange/(60*60.)
244 247
245 248 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
246 249 tmin = time.mktime(mindt.timetuple())
247 250
248 251 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
249 252 tmax = time.mktime(maxdt.timetuple())
250 253
251 254 self.__timerange = tmax - tmin
252 255
253 256 return tmin, tmax
254 257
255 258 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
256 259 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
257 260 timerange=None,
258 261 save=False, figpath='./', figfile=None):
259 262
260 263 """
261 264
262 265 Input:
263 266 dataOut :
264 267 idfigure :
265 268 wintitle :
266 269 channelList :
267 270 showProfile :
268 271 xmin : None,
269 272 xmax : None,
270 273 ymin : None,
271 274 ymax : None,
272 275 zmin : None,
273 276 zmax : None
274 277 """
275 278
276 279 if channelList == None:
277 280 channelIndexList = dataOut.channelIndexList
278 281 else:
279 282 channelIndexList = []
280 283 for channel in channelList:
281 284 if channel not in dataOut.channelList:
282 285 raise ValueError, "Channel %d is not in dataOut.channelList"
283 286 channelIndexList.append(dataOut.channelList.index(channel))
284 287
285 288 if timerange != None:
286 289 self.__timerange = timerange
287 290
288 291 tmin = None
289 292 tmax = None
290 293 x = dataOut.getTimeRange()
291 294 y = dataOut.getHeiRange()
292 295 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
293 296 avg = numpy.average(z, axis=1)
294 297
295 298 noise = dataOut.getNoise()
296 299
297 300 if not self.__isConfig:
298 301
299 302 nplots = len(channelIndexList)
300 303
301 304 self.setup(idfigure=idfigure,
302 305 nplots=nplots,
303 306 wintitle=wintitle,
304 307 showprofile=showprofile)
305 308
306 309 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
307 310 if ymin == None: ymin = numpy.nanmin(y)
308 311 if ymax == None: ymax = numpy.nanmax(y)
309 312 if zmin == None: zmin = numpy.nanmin(avg)*0.9
310 313 if zmax == None: zmax = numpy.nanmax(avg)*0.9
311 314
312 315 self.__isConfig = True
313 316
314 317 thisDatetime = dataOut.datatime
315 318 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
316 319 xlabel = "Velocity (m/s)"
317 320 ylabel = "Range (Km)"
318 321
319 322 self.setWinTitle(title)
320 323
321 324 for i in range(self.nplots):
322 325 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
323 326 axes = self.axesList[i*self.__nsubplots]
324 327 z = avg[i].reshape((1,-1))
325 328 axes.pcolor(x, y, z,
326 329 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
327 330 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
328 331 ticksize=9, cblabel='', cbsize="1%")
329 332
330 333 if self.__showprofile:
331 334 axes = self.axesList[i*self.__nsubplots +1]
332 335 axes.pline(avg[i], y,
333 336 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
334 337 xlabel='dB', ylabel='', title='',
335 338 ytick_visible=False,
336 339 grid='x')
337 340
338 341 self.draw()
339 342
340 343 if save:
341 344 date = thisDatetime.strftime("%Y%m%d")
342 345 if figfile == None:
343 346 figfile = self.getFilename(name = date)
344 347
345 348 self.saveFigure(figpath, figfile)
346 349
347 350 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
348 351 self.__isConfig = False
349 352
350 353 class SpectraPlot(Figure):
351 354
352 355 __isConfig = None
353 356 __nsubplots = None
354 357
355 358 WIDTHPROF = None
356 359 HEIGHTPROF = None
357 360 PREFIX = 'spc'
358 361
359 362 def __init__(self):
360 363
361 364 self.__isConfig = False
362 365 self.__nsubplots = 1
363 366
364 367 self.WIDTH = 300
365 368 self.HEIGHT = 400
366 369 self.WIDTHPROF = 120
367 370 self.HEIGHTPROF = 0
368 371
369 372 def getSubplots(self):
370 373
371 374 ncol = int(numpy.sqrt(self.nplots)+0.9)
372 375 nrow = int(self.nplots*1./ncol + 0.9)
373 376
374 377 return nrow, ncol
375 378
376 379 def setup(self, idfigure, nplots, wintitle, showprofile=True):
377 380
378 381 self.__showprofile = showprofile
379 382 self.nplots = nplots
380 383
381 384 ncolspan = 1
382 385 colspan = 1
383 386 if showprofile:
384 387 ncolspan = 3
385 388 colspan = 2
386 389 self.__nsubplots = 2
387 390
388 391 self.createFigure(idfigure = idfigure,
389 392 wintitle = wintitle,
390 393 widthplot = self.WIDTH + self.WIDTHPROF,
391 394 heightplot = self.HEIGHT + self.HEIGHTPROF)
392 395
393 396 nrow, ncol = self.getSubplots()
394 397
395 398 counter = 0
396 399 for y in range(nrow):
397 400 for x in range(ncol):
398 401
399 402 if counter >= self.nplots:
400 403 break
401 404
402 405 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
403 406
404 407 if showprofile:
405 408 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
406 409
407 410 counter += 1
408 411
409 412 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
410 413 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
411 414 save=False, figpath='./', figfile=None):
412 415
413 416 """
414 417
415 418 Input:
416 419 dataOut :
417 420 idfigure :
418 421 wintitle :
419 422 channelList :
420 423 showProfile :
421 424 xmin : None,
422 425 xmax : None,
423 426 ymin : None,
424 427 ymax : None,
425 428 zmin : None,
426 429 zmax : None
427 430 """
428 431
429 432 if channelList == None:
430 433 channelIndexList = dataOut.channelIndexList
431 434 else:
432 435 channelIndexList = []
433 436 for channel in channelList:
434 437 if channel not in dataOut.channelList:
435 438 raise ValueError, "Channel %d is not in dataOut.channelList"
436 439 channelIndexList.append(dataOut.channelList.index(channel))
437 440
438 441 x = dataOut.getVelRange(1)
439 442 y = dataOut.getHeiRange()
440 443 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
441 444 avg = numpy.average(z, axis=1)
442 445
443 446 noise = dataOut.getNoise()
444 447
445 448 if not self.__isConfig:
446 449
447 450 nplots = len(channelIndexList)
448 451
449 452 self.setup(idfigure=idfigure,
450 453 nplots=nplots,
451 454 wintitle=wintitle,
452 455 showprofile=showprofile)
453 456
454 457 if xmin == None: xmin = numpy.nanmin(x)
455 458 if xmax == None: xmax = numpy.nanmax(x)
456 459 if ymin == None: ymin = numpy.nanmin(y)
457 460 if ymax == None: ymax = numpy.nanmax(y)
458 461 if zmin == None: zmin = numpy.nanmin(avg)*0.9
459 462 if zmax == None: zmax = numpy.nanmax(avg)*0.9
460 463
461 464 self.__isConfig = True
462 465
463 466 thisDatetime = dataOut.datatime
464 467 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
465 468 xlabel = "Velocity (m/s)"
466 469 ylabel = "Range (Km)"
467 470
468 471 self.setWinTitle(title)
469 472
470 473 for i in range(self.nplots):
471 474 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
472 475 axes = self.axesList[i*self.__nsubplots]
473 476 axes.pcolor(x, y, z[i,:,:],
474 477 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
475 478 xlabel=xlabel, ylabel=ylabel, title=title,
476 479 ticksize=9, cblabel='')
477 480
478 481 if self.__showprofile:
479 482 axes = self.axesList[i*self.__nsubplots +1]
480 483 axes.pline(avg[i], y,
481 484 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
482 485 xlabel='dB', ylabel='', title='',
483 486 ytick_visible=False,
484 487 grid='x')
485 488
486 489 self.draw()
487 490
488 491 if save:
489 492 date = thisDatetime.strftime("%Y%m%d")
490 493 if figfile == None:
491 494 figfile = self.getFilename(name = date)
492 495
493 496 self.saveFigure(figpath, figfile)
494 497
495 498 class Scope(Figure):
496 499
497 500 __isConfig = None
498 501
499 502 def __init__(self):
500 503
501 504 self.__isConfig = False
502 505 self.WIDTH = 600
503 506 self.HEIGHT = 200
504 507
505 508 def getSubplots(self):
506 509
507 510 nrow = self.nplots
508 511 ncol = 3
509 512 return nrow, ncol
510 513
511 514 def setup(self, idfigure, nplots, wintitle):
512 515
513 516 self.createFigure(idfigure, wintitle)
514 517
515 518 nrow,ncol = self.getSubplots()
516 519 colspan = 3
517 520 rowspan = 1
518 521
519 522 for i in range(nplots):
520 523 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
521 524
522 525 self.nplots = nplots
523 526
524 527 def run(self, dataOut, idfigure, wintitle="", channelList=None,
525 528 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
526 529
527 530 """
528 531
529 532 Input:
530 533 dataOut :
531 534 idfigure :
532 535 wintitle :
533 536 channelList :
534 537 xmin : None,
535 538 xmax : None,
536 539 ymin : None,
537 540 ymax : None,
538 541 """
539 542
540 543 if channelList == None:
541 544 channelIndexList = dataOut.channelIndexList
542 545 else:
543 546 channelIndexList = []
544 547 for channel in channelList:
545 548 if channel not in dataOut.channelList:
546 549 raise ValueError, "Channel %d is not in dataOut.channelList"
547 550 channelIndexList.append(dataOut.channelList.index(channel))
548 551
549 552 x = dataOut.heightList
550 553 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
551 554 y = y.real
552 555
553 556 noise = dataOut.getNoise()
554 557
555 558 if not self.__isConfig:
556 559 nplots = len(channelList)
557 560
558 561 self.setup(idfigure=idfigure,
559 562 nplots=nplots,
560 563 wintitle=wintitle)
561 564
562 565 if xmin == None: xmin = numpy.nanmin(x)
563 566 if xmax == None: xmax = numpy.nanmax(x)
564 567 if ymin == None: ymin = numpy.nanmin(y)
565 568 if ymax == None: ymax = numpy.nanmax(y)
566 569
567 570 self.__isConfig = True
568 571
569 572
570 573 thisDatetime = dataOut.datatime
571 574 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
572 575 xlabel = "Range (Km)"
573 576 ylabel = "Intensity"
574 577
575 578 self.setWinTitle(title)
576 579
577 580 for i in range(len(self.axesList)):
578 581 title = "Channel %d: %4.2fdB" %(i, noise[i])
579 582 axes = self.axesList[i]
580 583 ychannel = y[i,:]
581 584 axes.pline(x, ychannel,
582 585 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
583 586 xlabel=xlabel, ylabel=ylabel, title=title)
584 587
585 588 self.draw()
586 589
587 590 if save:
588 591 self.saveFigure(filename)
589 592 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now