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