##// END OF EJS Templates
size of spectra plots = 250 again
jespinoza -
r1136:11af635bee3e
parent child
Show More
@@ -1,1542 +1,1542
1 1 '''
2 2 Created on Jul 9, 2014
3 3
4 4 @author: roj-idl71
5 5 '''
6 6 import os
7 7 import datetime
8 8 import numpy
9 9
10 10 from figure import Figure, isRealtime, isTimeInHourRange
11 11 from plotting_codes import *
12 12
13 13
14 14 class SpectraPlot(Figure):
15 15
16 16 isConfig = None
17 17 __nsubplots = None
18 18
19 19 WIDTHPROF = None
20 20 HEIGHTPROF = None
21 21 PREFIX = 'spc'
22 22
23 23 def __init__(self, **kwargs):
24 24 Figure.__init__(self, **kwargs)
25 25 self.isConfig = False
26 26 self.__nsubplots = 1
27 27
28 self.WIDTH = 300
29 self.HEIGHT = 300
28 self.WIDTH = 250
29 self.HEIGHT = 250
30 30 self.WIDTHPROF = 120
31 31 self.HEIGHTPROF = 0
32 32 self.counter_imagwr = 0
33 33
34 34 self.PLOT_CODE = SPEC_CODE
35 35
36 36 self.FTP_WEI = None
37 37 self.EXP_CODE = None
38 38 self.SUB_EXP_CODE = None
39 39 self.PLOT_POS = None
40 40
41 41 self.__xfilter_ena = False
42 42 self.__yfilter_ena = False
43 43
44 44 def getSubplots(self):
45 45
46 46 ncol = int(numpy.sqrt(self.nplots)+0.9)
47 47 nrow = int(self.nplots*1./ncol + 0.9)
48 48
49 49 return nrow, ncol
50 50
51 51 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
52 52
53 53 self.__showprofile = showprofile
54 54 self.nplots = nplots
55 55
56 56 ncolspan = 1
57 57 colspan = 1
58 58 if showprofile:
59 59 ncolspan = 3
60 60 colspan = 2
61 61 self.__nsubplots = 2
62 62
63 63 self.createFigure(id = id,
64 64 wintitle = wintitle,
65 65 widthplot = self.WIDTH + self.WIDTHPROF,
66 66 heightplot = self.HEIGHT + self.HEIGHTPROF,
67 67 show=show)
68 68
69 69 nrow, ncol = self.getSubplots()
70 70
71 71 counter = 0
72 72 for y in range(nrow):
73 73 for x in range(ncol):
74 74
75 75 if counter >= self.nplots:
76 76 break
77 77
78 78 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
79 79
80 80 if showprofile:
81 81 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
82 82
83 83 counter += 1
84 84
85 85 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
86 86 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
87 87 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
88 88 server=None, folder=None, username=None, password=None,
89 89 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
90 90 xaxis="frequency", colormap='jet', normFactor=None):
91 91
92 92 """
93 93
94 94 Input:
95 95 dataOut :
96 96 id :
97 97 wintitle :
98 98 channelList :
99 99 showProfile :
100 100 xmin : None,
101 101 xmax : None,
102 102 ymin : None,
103 103 ymax : None,
104 104 zmin : None,
105 105 zmax : None
106 106 """
107 107 if realtime:
108 108 if not(isRealtime(utcdatatime = dataOut.utctime)):
109 109 print 'Skipping this plot function'
110 110 return
111 111
112 112 if channelList == None:
113 113 channelIndexList = dataOut.channelIndexList
114 114 else:
115 115 channelIndexList = []
116 116 for channel in channelList:
117 117 if channel not in dataOut.channelList:
118 118 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
119 119 channelIndexList.append(dataOut.channelList.index(channel))
120 120
121 121 if normFactor is None:
122 122 factor = dataOut.normFactor
123 123 else:
124 124 factor = normFactor
125 125 if xaxis == "frequency":
126 126 x = dataOut.getFreqRange(1)/1000.
127 127 xlabel = "Frequency (kHz)"
128 128
129 129 elif xaxis == "time":
130 130 x = dataOut.getAcfRange(1)
131 131 xlabel = "Time (ms)"
132 132
133 133 else:
134 134 x = dataOut.getVelRange(1)
135 135 xlabel = "Velocity (m/s)"
136 136
137 137 ylabel = "Range (Km)"
138 138
139 139 y = dataOut.getHeiRange()
140 140
141 141 z = dataOut.data_spc/factor
142 142 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
143 143 zdB = 10*numpy.log10(z)
144 144
145 145 avg = numpy.average(z, axis=1)
146 146 avgdB = 10*numpy.log10(avg)
147 147
148 148 noise = dataOut.getNoise()/factor
149 149 noisedB = 10*numpy.log10(noise)
150 150
151 151 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
152 152 title = wintitle + " Spectra"
153 153 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
154 154 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
155 155
156 156 if not self.isConfig:
157 157
158 158 nplots = len(channelIndexList)
159 159
160 160 self.setup(id=id,
161 161 nplots=nplots,
162 162 wintitle=wintitle,
163 163 showprofile=showprofile,
164 164 show=show)
165 165
166 166 if xmin == None: xmin = numpy.nanmin(x)
167 167 if xmax == None: xmax = numpy.nanmax(x)
168 168 if ymin == None: ymin = numpy.nanmin(y)
169 169 if ymax == None: ymax = numpy.nanmax(y)
170 170 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
171 171 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
172 172
173 173 self.FTP_WEI = ftp_wei
174 174 self.EXP_CODE = exp_code
175 175 self.SUB_EXP_CODE = sub_exp_code
176 176 self.PLOT_POS = plot_pos
177 177
178 178 self.isConfig = True
179 179
180 180 self.setWinTitle(title)
181 181
182 182 for i in range(self.nplots):
183 183 index = channelIndexList[i]
184 184 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
185 185 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
186 186 if len(dataOut.beam.codeList) != 0:
187 187 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
188 188
189 189 axes = self.axesList[i*self.__nsubplots]
190 190 axes.pcolor(x, y, zdB[index,:,:],
191 191 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
192 192 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
193 193 ticksize=9, cblabel='')
194 194
195 195 if self.__showprofile:
196 196 axes = self.axesList[i*self.__nsubplots +1]
197 197 axes.pline(avgdB[index,:], y,
198 198 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
199 199 xlabel='dB', ylabel='', title='',
200 200 ytick_visible=False,
201 201 grid='x')
202 202
203 203 noiseline = numpy.repeat(noisedB[index], len(y))
204 204 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
205 205
206 206 self.draw()
207 207
208 208 if figfile == None:
209 209 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
210 210 name = str_datetime
211 211 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
212 212 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
213 213 figfile = self.getFilename(name)
214 214
215 215 self.save(figpath=figpath,
216 216 figfile=figfile,
217 217 save=save,
218 218 ftp=ftp,
219 219 wr_period=wr_period,
220 220 thisDatetime=thisDatetime)
221 221
222 222 class CrossSpectraPlot(Figure):
223 223
224 224 isConfig = None
225 225 __nsubplots = None
226 226
227 227 WIDTH = None
228 228 HEIGHT = None
229 229 WIDTHPROF = None
230 230 HEIGHTPROF = None
231 231 PREFIX = 'cspc'
232 232
233 233 def __init__(self, **kwargs):
234 234 Figure.__init__(self, **kwargs)
235 235 self.isConfig = False
236 236 self.__nsubplots = 4
237 237 self.counter_imagwr = 0
238 238 self.WIDTH = 250
239 239 self.HEIGHT = 250
240 240 self.WIDTHPROF = 0
241 241 self.HEIGHTPROF = 0
242 242
243 243 self.PLOT_CODE = CROSS_CODE
244 244 self.FTP_WEI = None
245 245 self.EXP_CODE = None
246 246 self.SUB_EXP_CODE = None
247 247 self.PLOT_POS = None
248 248
249 249 def getSubplots(self):
250 250
251 251 ncol = 4
252 252 nrow = self.nplots
253 253
254 254 return nrow, ncol
255 255
256 256 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
257 257
258 258 self.__showprofile = showprofile
259 259 self.nplots = nplots
260 260
261 261 ncolspan = 1
262 262 colspan = 1
263 263
264 264 self.createFigure(id = id,
265 265 wintitle = wintitle,
266 266 widthplot = self.WIDTH + self.WIDTHPROF,
267 267 heightplot = self.HEIGHT + self.HEIGHTPROF,
268 268 show=True)
269 269
270 270 nrow, ncol = self.getSubplots()
271 271
272 272 counter = 0
273 273 for y in range(nrow):
274 274 for x in range(ncol):
275 275 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
276 276
277 277 counter += 1
278 278
279 279 def run(self, dataOut, id, wintitle="", pairsList=None,
280 280 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
281 281 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
282 282 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
283 283 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
284 284 server=None, folder=None, username=None, password=None,
285 285 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
286 286 xaxis='frequency'):
287 287
288 288 """
289 289
290 290 Input:
291 291 dataOut :
292 292 id :
293 293 wintitle :
294 294 channelList :
295 295 showProfile :
296 296 xmin : None,
297 297 xmax : None,
298 298 ymin : None,
299 299 ymax : None,
300 300 zmin : None,
301 301 zmax : None
302 302 """
303 303
304 304 if pairsList == None:
305 305 pairsIndexList = dataOut.pairsIndexList
306 306 else:
307 307 pairsIndexList = []
308 308 for pair in pairsList:
309 309 if pair not in dataOut.pairsList:
310 310 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
311 311 pairsIndexList.append(dataOut.pairsList.index(pair))
312 312
313 313 if not pairsIndexList:
314 314 return
315 315
316 316 if len(pairsIndexList) > 4:
317 317 pairsIndexList = pairsIndexList[0:4]
318 318
319 319 if normFactor is None:
320 320 factor = dataOut.normFactor
321 321 else:
322 322 factor = normFactor
323 323 x = dataOut.getVelRange(1)
324 324 y = dataOut.getHeiRange()
325 325 z = dataOut.data_spc[:,:,:]/factor
326 326 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
327 327
328 328 noise = dataOut.noise/factor
329 329
330 330 zdB = 10*numpy.log10(z)
331 331 noisedB = 10*numpy.log10(noise)
332 332
333 333 if coh_min == None:
334 334 coh_min = 0.0
335 335 if coh_max == None:
336 336 coh_max = 1.0
337 337
338 338 if phase_min == None:
339 339 phase_min = -180
340 340 if phase_max == None:
341 341 phase_max = 180
342 342
343 343 #thisDatetime = dataOut.datatime
344 344 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
345 345 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
346 346 # xlabel = "Velocity (m/s)"
347 347 ylabel = "Range (Km)"
348 348
349 349 if xaxis == "frequency":
350 350 x = dataOut.getFreqRange(1)/1000.
351 351 xlabel = "Frequency (kHz)"
352 352
353 353 elif xaxis == "time":
354 354 x = dataOut.getAcfRange(1)
355 355 xlabel = "Time (ms)"
356 356
357 357 else:
358 358 x = dataOut.getVelRange(1)
359 359 xlabel = "Velocity (m/s)"
360 360
361 361 if not self.isConfig:
362 362
363 363 nplots = len(pairsIndexList)
364 364
365 365 self.setup(id=id,
366 366 nplots=nplots,
367 367 wintitle=wintitle,
368 368 showprofile=False,
369 369 show=show)
370 370
371 371 avg = numpy.abs(numpy.average(z, axis=1))
372 372 avgdB = 10*numpy.log10(avg)
373 373
374 374 if xmin == None: xmin = numpy.nanmin(x)
375 375 if xmax == None: xmax = numpy.nanmax(x)
376 376 if ymin == None: ymin = numpy.nanmin(y)
377 377 if ymax == None: ymax = numpy.nanmax(y)
378 378 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
379 379 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
380 380
381 381 self.FTP_WEI = ftp_wei
382 382 self.EXP_CODE = exp_code
383 383 self.SUB_EXP_CODE = sub_exp_code
384 384 self.PLOT_POS = plot_pos
385 385
386 386 self.isConfig = True
387 387
388 388 self.setWinTitle(title)
389 389
390 390 for i in range(self.nplots):
391 391 pair = dataOut.pairsList[pairsIndexList[i]]
392 392
393 393 chan_index0 = dataOut.channelList.index(pair[0])
394 394 chan_index1 = dataOut.channelList.index(pair[1])
395 395
396 396 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
397 397 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
398 398 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
399 399 axes0 = self.axesList[i*self.__nsubplots]
400 400 axes0.pcolor(x, y, zdB,
401 401 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
402 402 xlabel=xlabel, ylabel=ylabel, title=title,
403 403 ticksize=9, colormap=power_cmap, cblabel='')
404 404
405 405 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
406 406 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
407 407 axes0 = self.axesList[i*self.__nsubplots+1]
408 408 axes0.pcolor(x, y, zdB,
409 409 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
410 410 xlabel=xlabel, ylabel=ylabel, title=title,
411 411 ticksize=9, colormap=power_cmap, cblabel='')
412 412
413 413 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
414 414 coherence = numpy.abs(coherenceComplex)
415 415 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
416 416 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
417 417
418 418 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
419 419 axes0 = self.axesList[i*self.__nsubplots+2]
420 420 axes0.pcolor(x, y, coherence,
421 421 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
422 422 xlabel=xlabel, ylabel=ylabel, title=title,
423 423 ticksize=9, colormap=coherence_cmap, cblabel='')
424 424
425 425 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
426 426 axes0 = self.axesList[i*self.__nsubplots+3]
427 427 axes0.pcolor(x, y, phase,
428 428 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
429 429 xlabel=xlabel, ylabel=ylabel, title=title,
430 430 ticksize=9, colormap=phase_cmap, cblabel='')
431 431
432 432
433 433
434 434 self.draw()
435 435
436 436 self.save(figpath=figpath,
437 437 figfile=figfile,
438 438 save=save,
439 439 ftp=ftp,
440 440 wr_period=wr_period,
441 441 thisDatetime=thisDatetime)
442 442
443 443
444 444 class RTIPlot(Figure):
445 445
446 446 __isConfig = None
447 447 __nsubplots = None
448 448
449 449 WIDTHPROF = None
450 450 HEIGHTPROF = None
451 451 PREFIX = 'rti'
452 452
453 453 def __init__(self, **kwargs):
454 454
455 455 Figure.__init__(self, **kwargs)
456 456 self.timerange = None
457 457 self.isConfig = False
458 458 self.__nsubplots = 1
459 459
460 460 self.WIDTH = 800
461 461 self.HEIGHT = 180
462 462 self.WIDTHPROF = 120
463 463 self.HEIGHTPROF = 0
464 464 self.counter_imagwr = 0
465 465
466 466 self.PLOT_CODE = RTI_CODE
467 467
468 468 self.FTP_WEI = None
469 469 self.EXP_CODE = None
470 470 self.SUB_EXP_CODE = None
471 471 self.PLOT_POS = None
472 472 self.tmin = None
473 473 self.tmax = None
474 474
475 475 self.xmin = None
476 476 self.xmax = None
477 477
478 478 self.figfile = None
479 479
480 480 def getSubplots(self):
481 481
482 482 ncol = 1
483 483 nrow = self.nplots
484 484
485 485 return nrow, ncol
486 486
487 487 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
488 488
489 489 self.__showprofile = showprofile
490 490 self.nplots = nplots
491 491
492 492 ncolspan = 1
493 493 colspan = 1
494 494 if showprofile:
495 495 ncolspan = 7
496 496 colspan = 6
497 497 self.__nsubplots = 2
498 498
499 499 self.createFigure(id = id,
500 500 wintitle = wintitle,
501 501 widthplot = self.WIDTH + self.WIDTHPROF,
502 502 heightplot = self.HEIGHT + self.HEIGHTPROF,
503 503 show=show)
504 504
505 505 nrow, ncol = self.getSubplots()
506 506
507 507 counter = 0
508 508 for y in range(nrow):
509 509 for x in range(ncol):
510 510
511 511 if counter >= self.nplots:
512 512 break
513 513
514 514 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
515 515
516 516 if showprofile:
517 517 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
518 518
519 519 counter += 1
520 520
521 521 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
522 522 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
523 523 timerange=None, colormap='jet',
524 524 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
525 525 server=None, folder=None, username=None, password=None,
526 526 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
527 527
528 528 """
529 529
530 530 Input:
531 531 dataOut :
532 532 id :
533 533 wintitle :
534 534 channelList :
535 535 showProfile :
536 536 xmin : None,
537 537 xmax : None,
538 538 ymin : None,
539 539 ymax : None,
540 540 zmin : None,
541 541 zmax : None
542 542 """
543 543
544 544 #colormap = kwargs.get('colormap', 'jet')
545 545 if HEIGHT is not None:
546 546 self.HEIGHT = HEIGHT
547 547
548 548 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
549 549 return
550 550
551 551 if channelList == None:
552 552 channelIndexList = dataOut.channelIndexList
553 553 else:
554 554 channelIndexList = []
555 555 for channel in channelList:
556 556 if channel not in dataOut.channelList:
557 557 raise ValueError, "Channel %d is not in dataOut.channelList"
558 558 channelIndexList.append(dataOut.channelList.index(channel))
559 559
560 560 if normFactor is None:
561 561 factor = dataOut.normFactor
562 562 else:
563 563 factor = normFactor
564 564
565 565 # factor = dataOut.normFactor
566 566 x = dataOut.getTimeRange()
567 567 y = dataOut.getHeiRange()
568 568
569 569 z = dataOut.data_spc/factor
570 570 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
571 571 avg = numpy.average(z, axis=1)
572 572 avgdB = 10.*numpy.log10(avg)
573 573 # avgdB = dataOut.getPower()
574 574
575 575
576 576 thisDatetime = dataOut.datatime
577 577 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
578 578 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
579 579 xlabel = ""
580 580 ylabel = "Range (Km)"
581 581
582 582 update_figfile = False
583 583
584 584 if dataOut.ltctime >= self.xmax:
585 585 self.counter_imagwr = wr_period
586 586 self.isConfig = False
587 587 update_figfile = True
588 588
589 589 if not self.isConfig:
590 590
591 591 nplots = len(channelIndexList)
592 592
593 593 self.setup(id=id,
594 594 nplots=nplots,
595 595 wintitle=wintitle,
596 596 showprofile=showprofile,
597 597 show=show)
598 598
599 599 if timerange != None:
600 600 self.timerange = timerange
601 601
602 602 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
603 603
604 604 noise = dataOut.noise/factor
605 605 noisedB = 10*numpy.log10(noise)
606 606
607 607 if ymin == None: ymin = numpy.nanmin(y)
608 608 if ymax == None: ymax = numpy.nanmax(y)
609 609 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
610 610 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
611 611
612 612 self.FTP_WEI = ftp_wei
613 613 self.EXP_CODE = exp_code
614 614 self.SUB_EXP_CODE = sub_exp_code
615 615 self.PLOT_POS = plot_pos
616 616
617 617 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
618 618 self.isConfig = True
619 619 self.figfile = figfile
620 620 update_figfile = True
621 621
622 622 self.setWinTitle(title)
623 623
624 624 for i in range(self.nplots):
625 625 index = channelIndexList[i]
626 626 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
627 627 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
628 628 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
629 629 axes = self.axesList[i*self.__nsubplots]
630 630 zdB = avgdB[index].reshape((1,-1))
631 631 axes.pcolorbuffer(x, y, zdB,
632 632 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
633 633 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
634 634 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
635 635
636 636 if self.__showprofile:
637 637 axes = self.axesList[i*self.__nsubplots +1]
638 638 axes.pline(avgdB[index], y,
639 639 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
640 640 xlabel='dB', ylabel='', title='',
641 641 ytick_visible=False,
642 642 grid='x')
643 643
644 644 self.draw()
645 645
646 646 self.save(figpath=figpath,
647 647 figfile=figfile,
648 648 save=save,
649 649 ftp=ftp,
650 650 wr_period=wr_period,
651 651 thisDatetime=thisDatetime,
652 652 update_figfile=update_figfile)
653 653
654 654 class CoherenceMap(Figure):
655 655 isConfig = None
656 656 __nsubplots = None
657 657
658 658 WIDTHPROF = None
659 659 HEIGHTPROF = None
660 660 PREFIX = 'cmap'
661 661
662 662 def __init__(self, **kwargs):
663 663 Figure.__init__(self, **kwargs)
664 664 self.timerange = 2*60*60
665 665 self.isConfig = False
666 666 self.__nsubplots = 1
667 667
668 668 self.WIDTH = 800
669 669 self.HEIGHT = 180
670 670 self.WIDTHPROF = 120
671 671 self.HEIGHTPROF = 0
672 672 self.counter_imagwr = 0
673 673
674 674 self.PLOT_CODE = COH_CODE
675 675
676 676 self.FTP_WEI = None
677 677 self.EXP_CODE = None
678 678 self.SUB_EXP_CODE = None
679 679 self.PLOT_POS = None
680 680 self.counter_imagwr = 0
681 681
682 682 self.xmin = None
683 683 self.xmax = None
684 684
685 685 def getSubplots(self):
686 686 ncol = 1
687 687 nrow = self.nplots*2
688 688
689 689 return nrow, ncol
690 690
691 691 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
692 692 self.__showprofile = showprofile
693 693 self.nplots = nplots
694 694
695 695 ncolspan = 1
696 696 colspan = 1
697 697 if showprofile:
698 698 ncolspan = 7
699 699 colspan = 6
700 700 self.__nsubplots = 2
701 701
702 702 self.createFigure(id = id,
703 703 wintitle = wintitle,
704 704 widthplot = self.WIDTH + self.WIDTHPROF,
705 705 heightplot = self.HEIGHT + self.HEIGHTPROF,
706 706 show=True)
707 707
708 708 nrow, ncol = self.getSubplots()
709 709
710 710 for y in range(nrow):
711 711 for x in range(ncol):
712 712
713 713 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
714 714
715 715 if showprofile:
716 716 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
717 717
718 718 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
719 719 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
720 720 timerange=None, phase_min=None, phase_max=None,
721 721 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
722 722 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
723 723 server=None, folder=None, username=None, password=None,
724 724 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
725 725
726 726 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
727 727 return
728 728
729 729 if pairsList == None:
730 730 pairsIndexList = dataOut.pairsIndexList
731 731 else:
732 732 pairsIndexList = []
733 733 for pair in pairsList:
734 734 if pair not in dataOut.pairsList:
735 735 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
736 736 pairsIndexList.append(dataOut.pairsList.index(pair))
737 737
738 738 if pairsIndexList == []:
739 739 return
740 740
741 741 if len(pairsIndexList) > 4:
742 742 pairsIndexList = pairsIndexList[0:4]
743 743
744 744 if phase_min == None:
745 745 phase_min = -180
746 746 if phase_max == None:
747 747 phase_max = 180
748 748
749 749 x = dataOut.getTimeRange()
750 750 y = dataOut.getHeiRange()
751 751
752 752 thisDatetime = dataOut.datatime
753 753
754 754 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
755 755 xlabel = ""
756 756 ylabel = "Range (Km)"
757 757 update_figfile = False
758 758
759 759 if not self.isConfig:
760 760 nplots = len(pairsIndexList)
761 761 self.setup(id=id,
762 762 nplots=nplots,
763 763 wintitle=wintitle,
764 764 showprofile=showprofile,
765 765 show=show)
766 766
767 767 if timerange != None:
768 768 self.timerange = timerange
769 769
770 770 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
771 771
772 772 if ymin == None: ymin = numpy.nanmin(y)
773 773 if ymax == None: ymax = numpy.nanmax(y)
774 774 if zmin == None: zmin = 0.
775 775 if zmax == None: zmax = 1.
776 776
777 777 self.FTP_WEI = ftp_wei
778 778 self.EXP_CODE = exp_code
779 779 self.SUB_EXP_CODE = sub_exp_code
780 780 self.PLOT_POS = plot_pos
781 781
782 782 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
783 783
784 784 self.isConfig = True
785 785 update_figfile = True
786 786
787 787 self.setWinTitle(title)
788 788
789 789 for i in range(self.nplots):
790 790
791 791 pair = dataOut.pairsList[pairsIndexList[i]]
792 792
793 793 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
794 794 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
795 795 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
796 796
797 797
798 798 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
799 799 coherence = numpy.abs(avgcoherenceComplex)
800 800
801 801 z = coherence.reshape((1,-1))
802 802
803 803 counter = 0
804 804
805 805 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
806 806 axes = self.axesList[i*self.__nsubplots*2]
807 807 axes.pcolorbuffer(x, y, z,
808 808 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
809 809 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
810 810 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
811 811
812 812 if self.__showprofile:
813 813 counter += 1
814 814 axes = self.axesList[i*self.__nsubplots*2 + counter]
815 815 axes.pline(coherence, y,
816 816 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
817 817 xlabel='', ylabel='', title='', ticksize=7,
818 818 ytick_visible=False, nxticks=5,
819 819 grid='x')
820 820
821 821 counter += 1
822 822
823 823 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
824 824
825 825 z = phase.reshape((1,-1))
826 826
827 827 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
828 828 axes = self.axesList[i*self.__nsubplots*2 + counter]
829 829 axes.pcolorbuffer(x, y, z,
830 830 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
831 831 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
832 832 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
833 833
834 834 if self.__showprofile:
835 835 counter += 1
836 836 axes = self.axesList[i*self.__nsubplots*2 + counter]
837 837 axes.pline(phase, y,
838 838 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
839 839 xlabel='', ylabel='', title='', ticksize=7,
840 840 ytick_visible=False, nxticks=4,
841 841 grid='x')
842 842
843 843 self.draw()
844 844
845 845 if dataOut.ltctime >= self.xmax:
846 846 self.counter_imagwr = wr_period
847 847 self.isConfig = False
848 848 update_figfile = True
849 849
850 850 self.save(figpath=figpath,
851 851 figfile=figfile,
852 852 save=save,
853 853 ftp=ftp,
854 854 wr_period=wr_period,
855 855 thisDatetime=thisDatetime,
856 856 update_figfile=update_figfile)
857 857
858 858 class PowerProfilePlot(Figure):
859 859
860 860 isConfig = None
861 861 __nsubplots = None
862 862
863 863 WIDTHPROF = None
864 864 HEIGHTPROF = None
865 865 PREFIX = 'spcprofile'
866 866
867 867 def __init__(self, **kwargs):
868 868 Figure.__init__(self, **kwargs)
869 869 self.isConfig = False
870 870 self.__nsubplots = 1
871 871
872 872 self.PLOT_CODE = POWER_CODE
873 873
874 874 self.WIDTH = 300
875 875 self.HEIGHT = 500
876 876 self.counter_imagwr = 0
877 877
878 878 def getSubplots(self):
879 879 ncol = 1
880 880 nrow = 1
881 881
882 882 return nrow, ncol
883 883
884 884 def setup(self, id, nplots, wintitle, show):
885 885
886 886 self.nplots = nplots
887 887
888 888 ncolspan = 1
889 889 colspan = 1
890 890
891 891 self.createFigure(id = id,
892 892 wintitle = wintitle,
893 893 widthplot = self.WIDTH,
894 894 heightplot = self.HEIGHT,
895 895 show=show)
896 896
897 897 nrow, ncol = self.getSubplots()
898 898
899 899 counter = 0
900 900 for y in range(nrow):
901 901 for x in range(ncol):
902 902 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
903 903
904 904 def run(self, dataOut, id, wintitle="", channelList=None,
905 905 xmin=None, xmax=None, ymin=None, ymax=None,
906 906 save=False, figpath='./', figfile=None, show=True,
907 907 ftp=False, wr_period=1, server=None,
908 908 folder=None, username=None, password=None):
909 909
910 910
911 911 if channelList == None:
912 912 channelIndexList = dataOut.channelIndexList
913 913 channelList = dataOut.channelList
914 914 else:
915 915 channelIndexList = []
916 916 for channel in channelList:
917 917 if channel not in dataOut.channelList:
918 918 raise ValueError, "Channel %d is not in dataOut.channelList"
919 919 channelIndexList.append(dataOut.channelList.index(channel))
920 920
921 921 factor = dataOut.normFactor
922 922
923 923 y = dataOut.getHeiRange()
924 924
925 925 #for voltage
926 926 if dataOut.type == 'Voltage':
927 927 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
928 928 x = x.real
929 929 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
930 930
931 931 #for spectra
932 932 if dataOut.type == 'Spectra':
933 933 x = dataOut.data_spc[channelIndexList,:,:]/factor
934 934 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
935 935 x = numpy.average(x, axis=1)
936 936
937 937
938 938 xdB = 10*numpy.log10(x)
939 939
940 940 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
941 941 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
942 942 xlabel = "dB"
943 943 ylabel = "Range (Km)"
944 944
945 945 if not self.isConfig:
946 946
947 947 nplots = 1
948 948
949 949 self.setup(id=id,
950 950 nplots=nplots,
951 951 wintitle=wintitle,
952 952 show=show)
953 953
954 954 if ymin == None: ymin = numpy.nanmin(y)
955 955 if ymax == None: ymax = numpy.nanmax(y)
956 956 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
957 957 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
958 958
959 959 self.isConfig = True
960 960
961 961 self.setWinTitle(title)
962 962
963 963 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
964 964 axes = self.axesList[0]
965 965
966 966 legendlabels = ["channel %d"%x for x in channelList]
967 967 axes.pmultiline(xdB, y,
968 968 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
969 969 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
970 970 ytick_visible=True, nxticks=5,
971 971 grid='x')
972 972
973 973 self.draw()
974 974
975 975 self.save(figpath=figpath,
976 976 figfile=figfile,
977 977 save=save,
978 978 ftp=ftp,
979 979 wr_period=wr_period,
980 980 thisDatetime=thisDatetime)
981 981
982 982 class SpectraCutPlot(Figure):
983 983
984 984 isConfig = None
985 985 __nsubplots = None
986 986
987 987 WIDTHPROF = None
988 988 HEIGHTPROF = None
989 989 PREFIX = 'spc_cut'
990 990
991 991 def __init__(self, **kwargs):
992 992 Figure.__init__(self, **kwargs)
993 993 self.isConfig = False
994 994 self.__nsubplots = 1
995 995
996 996 self.PLOT_CODE = POWER_CODE
997 997
998 998 self.WIDTH = 700
999 999 self.HEIGHT = 500
1000 1000 self.counter_imagwr = 0
1001 1001
1002 1002 def getSubplots(self):
1003 1003 ncol = 1
1004 1004 nrow = 1
1005 1005
1006 1006 return nrow, ncol
1007 1007
1008 1008 def setup(self, id, nplots, wintitle, show):
1009 1009
1010 1010 self.nplots = nplots
1011 1011
1012 1012 ncolspan = 1
1013 1013 colspan = 1
1014 1014
1015 1015 self.createFigure(id = id,
1016 1016 wintitle = wintitle,
1017 1017 widthplot = self.WIDTH,
1018 1018 heightplot = self.HEIGHT,
1019 1019 show=show)
1020 1020
1021 1021 nrow, ncol = self.getSubplots()
1022 1022
1023 1023 counter = 0
1024 1024 for y in range(nrow):
1025 1025 for x in range(ncol):
1026 1026 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1027 1027
1028 1028 def run(self, dataOut, id, wintitle="", channelList=None,
1029 1029 xmin=None, xmax=None, ymin=None, ymax=None,
1030 1030 save=False, figpath='./', figfile=None, show=True,
1031 1031 ftp=False, wr_period=1, server=None,
1032 1032 folder=None, username=None, password=None,
1033 1033 xaxis="frequency"):
1034 1034
1035 1035
1036 1036 if channelList == None:
1037 1037 channelIndexList = dataOut.channelIndexList
1038 1038 channelList = dataOut.channelList
1039 1039 else:
1040 1040 channelIndexList = []
1041 1041 for channel in channelList:
1042 1042 if channel not in dataOut.channelList:
1043 1043 raise ValueError, "Channel %d is not in dataOut.channelList"
1044 1044 channelIndexList.append(dataOut.channelList.index(channel))
1045 1045
1046 1046 factor = dataOut.normFactor
1047 1047
1048 1048 y = dataOut.getHeiRange()
1049 1049
1050 1050 z = dataOut.data_spc/factor
1051 1051 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1052 1052
1053 1053 hei_index = numpy.arange(25)*3 + 20
1054 1054
1055 1055 if xaxis == "frequency":
1056 1056 x = dataOut.getFreqRange()/1000.
1057 1057 zdB = 10*numpy.log10(z[0,:,hei_index])
1058 1058 xlabel = "Frequency (kHz)"
1059 1059 ylabel = "Power (dB)"
1060 1060
1061 1061 elif xaxis == "time":
1062 1062 x = dataOut.getAcfRange()
1063 1063 zdB = z[0,:,hei_index]
1064 1064 xlabel = "Time (ms)"
1065 1065 ylabel = "ACF"
1066 1066
1067 1067 else:
1068 1068 x = dataOut.getVelRange()
1069 1069 zdB = 10*numpy.log10(z[0,:,hei_index])
1070 1070 xlabel = "Velocity (m/s)"
1071 1071 ylabel = "Power (dB)"
1072 1072
1073 1073 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1074 1074 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1075 1075
1076 1076 if not self.isConfig:
1077 1077
1078 1078 nplots = 1
1079 1079
1080 1080 self.setup(id=id,
1081 1081 nplots=nplots,
1082 1082 wintitle=wintitle,
1083 1083 show=show)
1084 1084
1085 1085 if xmin == None: xmin = numpy.nanmin(x)*0.9
1086 1086 if xmax == None: xmax = numpy.nanmax(x)*1.1
1087 1087 if ymin == None: ymin = numpy.nanmin(zdB)
1088 1088 if ymax == None: ymax = numpy.nanmax(zdB)
1089 1089
1090 1090 self.isConfig = True
1091 1091
1092 1092 self.setWinTitle(title)
1093 1093
1094 1094 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1095 1095 axes = self.axesList[0]
1096 1096
1097 1097 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1098 1098
1099 1099 axes.pmultilineyaxis( x, zdB,
1100 1100 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1101 1101 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1102 1102 ytick_visible=True, nxticks=5,
1103 1103 grid='x')
1104 1104
1105 1105 self.draw()
1106 1106
1107 1107 self.save(figpath=figpath,
1108 1108 figfile=figfile,
1109 1109 save=save,
1110 1110 ftp=ftp,
1111 1111 wr_period=wr_period,
1112 1112 thisDatetime=thisDatetime)
1113 1113
1114 1114 class Noise(Figure):
1115 1115
1116 1116 isConfig = None
1117 1117 __nsubplots = None
1118 1118
1119 1119 PREFIX = 'noise'
1120 1120
1121 1121
1122 1122 def __init__(self, **kwargs):
1123 1123 Figure.__init__(self, **kwargs)
1124 1124 self.timerange = 24*60*60
1125 1125 self.isConfig = False
1126 1126 self.__nsubplots = 1
1127 1127 self.counter_imagwr = 0
1128 1128 self.WIDTH = 800
1129 1129 self.HEIGHT = 400
1130 1130 self.WIDTHPROF = 120
1131 1131 self.HEIGHTPROF = 0
1132 1132 self.xdata = None
1133 1133 self.ydata = None
1134 1134
1135 1135 self.PLOT_CODE = NOISE_CODE
1136 1136
1137 1137 self.FTP_WEI = None
1138 1138 self.EXP_CODE = None
1139 1139 self.SUB_EXP_CODE = None
1140 1140 self.PLOT_POS = None
1141 1141 self.figfile = None
1142 1142
1143 1143 self.xmin = None
1144 1144 self.xmax = None
1145 1145
1146 1146 def getSubplots(self):
1147 1147
1148 1148 ncol = 1
1149 1149 nrow = 1
1150 1150
1151 1151 return nrow, ncol
1152 1152
1153 1153 def openfile(self, filename):
1154 1154 dirname = os.path.dirname(filename)
1155 1155
1156 1156 if not os.path.exists(dirname):
1157 1157 os.mkdir(dirname)
1158 1158
1159 1159 f = open(filename,'w+')
1160 1160 f.write('\n\n')
1161 1161 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1162 1162 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1163 1163 f.close()
1164 1164
1165 1165 def save_data(self, filename_phase, data, data_datetime):
1166 1166
1167 1167 f=open(filename_phase,'a')
1168 1168
1169 1169 timetuple_data = data_datetime.timetuple()
1170 1170 day = str(timetuple_data.tm_mday)
1171 1171 month = str(timetuple_data.tm_mon)
1172 1172 year = str(timetuple_data.tm_year)
1173 1173 hour = str(timetuple_data.tm_hour)
1174 1174 minute = str(timetuple_data.tm_min)
1175 1175 second = str(timetuple_data.tm_sec)
1176 1176
1177 1177 data_msg = ''
1178 1178 for i in range(len(data)):
1179 1179 data_msg += str(data[i]) + ' '
1180 1180
1181 1181 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1182 1182 f.close()
1183 1183
1184 1184
1185 1185 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1186 1186
1187 1187 self.__showprofile = showprofile
1188 1188 self.nplots = nplots
1189 1189
1190 1190 ncolspan = 7
1191 1191 colspan = 6
1192 1192 self.__nsubplots = 2
1193 1193
1194 1194 self.createFigure(id = id,
1195 1195 wintitle = wintitle,
1196 1196 widthplot = self.WIDTH+self.WIDTHPROF,
1197 1197 heightplot = self.HEIGHT+self.HEIGHTPROF,
1198 1198 show=show)
1199 1199
1200 1200 nrow, ncol = self.getSubplots()
1201 1201
1202 1202 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1203 1203
1204 1204
1205 1205 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1206 1206 xmin=None, xmax=None, ymin=None, ymax=None,
1207 1207 timerange=None,
1208 1208 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1209 1209 server=None, folder=None, username=None, password=None,
1210 1210 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1211 1211
1212 1212 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1213 1213 return
1214 1214
1215 1215 if channelList == None:
1216 1216 channelIndexList = dataOut.channelIndexList
1217 1217 channelList = dataOut.channelList
1218 1218 else:
1219 1219 channelIndexList = []
1220 1220 for channel in channelList:
1221 1221 if channel not in dataOut.channelList:
1222 1222 raise ValueError, "Channel %d is not in dataOut.channelList"
1223 1223 channelIndexList.append(dataOut.channelList.index(channel))
1224 1224
1225 1225 x = dataOut.getTimeRange()
1226 1226 #y = dataOut.getHeiRange()
1227 1227 factor = dataOut.normFactor
1228 1228 noise = dataOut.noise[channelIndexList]/factor
1229 1229 noisedB = 10*numpy.log10(noise)
1230 1230
1231 1231 thisDatetime = dataOut.datatime
1232 1232
1233 1233 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1234 1234 xlabel = ""
1235 1235 ylabel = "Intensity (dB)"
1236 1236 update_figfile = False
1237 1237
1238 1238 if not self.isConfig:
1239 1239
1240 1240 nplots = 1
1241 1241
1242 1242 self.setup(id=id,
1243 1243 nplots=nplots,
1244 1244 wintitle=wintitle,
1245 1245 showprofile=showprofile,
1246 1246 show=show)
1247 1247
1248 1248 if timerange != None:
1249 1249 self.timerange = timerange
1250 1250
1251 1251 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1252 1252
1253 1253 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1254 1254 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1255 1255
1256 1256 self.FTP_WEI = ftp_wei
1257 1257 self.EXP_CODE = exp_code
1258 1258 self.SUB_EXP_CODE = sub_exp_code
1259 1259 self.PLOT_POS = plot_pos
1260 1260
1261 1261
1262 1262 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1263 1263 self.isConfig = True
1264 1264 self.figfile = figfile
1265 1265 self.xdata = numpy.array([])
1266 1266 self.ydata = numpy.array([])
1267 1267
1268 1268 update_figfile = True
1269 1269
1270 1270 #open file beacon phase
1271 1271 path = '%s%03d' %(self.PREFIX, self.id)
1272 1272 noise_file = os.path.join(path,'%s.txt'%self.name)
1273 1273 self.filename_noise = os.path.join(figpath,noise_file)
1274 1274
1275 1275 self.setWinTitle(title)
1276 1276
1277 1277 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1278 1278
1279 1279 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1280 1280 axes = self.axesList[0]
1281 1281
1282 1282 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1283 1283
1284 1284 if len(self.ydata)==0:
1285 1285 self.ydata = noisedB.reshape(-1,1)
1286 1286 else:
1287 1287 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1288 1288
1289 1289
1290 1290 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1291 1291 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1292 1292 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1293 1293 XAxisAsTime=True, grid='both'
1294 1294 )
1295 1295
1296 1296 self.draw()
1297 1297
1298 1298 if dataOut.ltctime >= self.xmax:
1299 1299 self.counter_imagwr = wr_period
1300 1300 self.isConfig = False
1301 1301 update_figfile = True
1302 1302
1303 1303 self.save(figpath=figpath,
1304 1304 figfile=figfile,
1305 1305 save=save,
1306 1306 ftp=ftp,
1307 1307 wr_period=wr_period,
1308 1308 thisDatetime=thisDatetime,
1309 1309 update_figfile=update_figfile)
1310 1310
1311 1311 #store data beacon phase
1312 1312 if save:
1313 1313 self.save_data(self.filename_noise, noisedB, thisDatetime)
1314 1314
1315 1315 class BeaconPhase(Figure):
1316 1316
1317 1317 __isConfig = None
1318 1318 __nsubplots = None
1319 1319
1320 1320 PREFIX = 'beacon_phase'
1321 1321
1322 1322 def __init__(self, **kwargs):
1323 1323 Figure.__init__(self, **kwargs)
1324 1324 self.timerange = 24*60*60
1325 1325 self.isConfig = False
1326 1326 self.__nsubplots = 1
1327 1327 self.counter_imagwr = 0
1328 1328 self.WIDTH = 800
1329 1329 self.HEIGHT = 400
1330 1330 self.WIDTHPROF = 120
1331 1331 self.HEIGHTPROF = 0
1332 1332 self.xdata = None
1333 1333 self.ydata = None
1334 1334
1335 1335 self.PLOT_CODE = BEACON_CODE
1336 1336
1337 1337 self.FTP_WEI = None
1338 1338 self.EXP_CODE = None
1339 1339 self.SUB_EXP_CODE = None
1340 1340 self.PLOT_POS = None
1341 1341
1342 1342 self.filename_phase = None
1343 1343
1344 1344 self.figfile = None
1345 1345
1346 1346 self.xmin = None
1347 1347 self.xmax = None
1348 1348
1349 1349 def getSubplots(self):
1350 1350
1351 1351 ncol = 1
1352 1352 nrow = 1
1353 1353
1354 1354 return nrow, ncol
1355 1355
1356 1356 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1357 1357
1358 1358 self.__showprofile = showprofile
1359 1359 self.nplots = nplots
1360 1360
1361 1361 ncolspan = 7
1362 1362 colspan = 6
1363 1363 self.__nsubplots = 2
1364 1364
1365 1365 self.createFigure(id = id,
1366 1366 wintitle = wintitle,
1367 1367 widthplot = self.WIDTH+self.WIDTHPROF,
1368 1368 heightplot = self.HEIGHT+self.HEIGHTPROF,
1369 1369 show=show)
1370 1370
1371 1371 nrow, ncol = self.getSubplots()
1372 1372
1373 1373 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1374 1374
1375 1375 def save_phase(self, filename_phase):
1376 1376 f = open(filename_phase,'w+')
1377 1377 f.write('\n\n')
1378 1378 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1379 1379 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1380 1380 f.close()
1381 1381
1382 1382 def save_data(self, filename_phase, data, data_datetime):
1383 1383 f=open(filename_phase,'a')
1384 1384 timetuple_data = data_datetime.timetuple()
1385 1385 day = str(timetuple_data.tm_mday)
1386 1386 month = str(timetuple_data.tm_mon)
1387 1387 year = str(timetuple_data.tm_year)
1388 1388 hour = str(timetuple_data.tm_hour)
1389 1389 minute = str(timetuple_data.tm_min)
1390 1390 second = str(timetuple_data.tm_sec)
1391 1391 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1392 1392 f.close()
1393 1393
1394 1394
1395 1395 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1396 1396 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1397 1397 timerange=None,
1398 1398 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1399 1399 server=None, folder=None, username=None, password=None,
1400 1400 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1401 1401
1402 1402 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1403 1403 return
1404 1404
1405 1405 if pairsList == None:
1406 1406 pairsIndexList = dataOut.pairsIndexList[:10]
1407 1407 else:
1408 1408 pairsIndexList = []
1409 1409 for pair in pairsList:
1410 1410 if pair not in dataOut.pairsList:
1411 1411 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1412 1412 pairsIndexList.append(dataOut.pairsList.index(pair))
1413 1413
1414 1414 if pairsIndexList == []:
1415 1415 return
1416 1416
1417 1417 # if len(pairsIndexList) > 4:
1418 1418 # pairsIndexList = pairsIndexList[0:4]
1419 1419
1420 1420 hmin_index = None
1421 1421 hmax_index = None
1422 1422
1423 1423 if hmin != None and hmax != None:
1424 1424 indexes = numpy.arange(dataOut.nHeights)
1425 1425 hmin_list = indexes[dataOut.heightList >= hmin]
1426 1426 hmax_list = indexes[dataOut.heightList <= hmax]
1427 1427
1428 1428 if hmin_list.any():
1429 1429 hmin_index = hmin_list[0]
1430 1430
1431 1431 if hmax_list.any():
1432 1432 hmax_index = hmax_list[-1]+1
1433 1433
1434 1434 x = dataOut.getTimeRange()
1435 1435 #y = dataOut.getHeiRange()
1436 1436
1437 1437
1438 1438 thisDatetime = dataOut.datatime
1439 1439
1440 1440 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1441 1441 xlabel = "Local Time"
1442 1442 ylabel = "Phase (degrees)"
1443 1443
1444 1444 update_figfile = False
1445 1445
1446 1446 nplots = len(pairsIndexList)
1447 1447 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1448 1448 phase_beacon = numpy.zeros(len(pairsIndexList))
1449 1449 for i in range(nplots):
1450 1450 pair = dataOut.pairsList[pairsIndexList[i]]
1451 1451 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1452 1452 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1453 1453 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1454 1454 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1455 1455 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1456 1456
1457 1457 #print "Phase %d%d" %(pair[0], pair[1])
1458 1458 #print phase[dataOut.beacon_heiIndexList]
1459 1459
1460 1460 if dataOut.beacon_heiIndexList:
1461 1461 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1462 1462 else:
1463 1463 phase_beacon[i] = numpy.average(phase)
1464 1464
1465 1465 if not self.isConfig:
1466 1466
1467 1467 nplots = len(pairsIndexList)
1468 1468
1469 1469 self.setup(id=id,
1470 1470 nplots=nplots,
1471 1471 wintitle=wintitle,
1472 1472 showprofile=showprofile,
1473 1473 show=show)
1474 1474
1475 1475 if timerange != None:
1476 1476 self.timerange = timerange
1477 1477
1478 1478 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1479 1479
1480 1480 if ymin == None: ymin = 0
1481 1481 if ymax == None: ymax = 360
1482 1482
1483 1483 self.FTP_WEI = ftp_wei
1484 1484 self.EXP_CODE = exp_code
1485 1485 self.SUB_EXP_CODE = sub_exp_code
1486 1486 self.PLOT_POS = plot_pos
1487 1487
1488 1488 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1489 1489 self.isConfig = True
1490 1490 self.figfile = figfile
1491 1491 self.xdata = numpy.array([])
1492 1492 self.ydata = numpy.array([])
1493 1493
1494 1494 update_figfile = True
1495 1495
1496 1496 #open file beacon phase
1497 1497 path = '%s%03d' %(self.PREFIX, self.id)
1498 1498 beacon_file = os.path.join(path,'%s.txt'%self.name)
1499 1499 self.filename_phase = os.path.join(figpath,beacon_file)
1500 1500 #self.save_phase(self.filename_phase)
1501 1501
1502 1502
1503 1503 #store data beacon phase
1504 1504 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1505 1505
1506 1506 self.setWinTitle(title)
1507 1507
1508 1508
1509 1509 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1510 1510
1511 1511 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1512 1512
1513 1513 axes = self.axesList[0]
1514 1514
1515 1515 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1516 1516
1517 1517 if len(self.ydata)==0:
1518 1518 self.ydata = phase_beacon.reshape(-1,1)
1519 1519 else:
1520 1520 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1521 1521
1522 1522
1523 1523 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1524 1524 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1525 1525 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1526 1526 XAxisAsTime=True, grid='both'
1527 1527 )
1528 1528
1529 1529 self.draw()
1530 1530
1531 1531 if dataOut.ltctime >= self.xmax:
1532 1532 self.counter_imagwr = wr_period
1533 1533 self.isConfig = False
1534 1534 update_figfile = True
1535 1535
1536 1536 self.save(figpath=figpath,
1537 1537 figfile=figfile,
1538 1538 save=save,
1539 1539 ftp=ftp,
1540 1540 wr_period=wr_period,
1541 1541 thisDatetime=thisDatetime,
1542 1542 update_figfile=update_figfile)
General Comments 0
You need to be logged in to leave comments. Login now