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