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