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