##// END OF EJS Templates
Bug fixed plotting RTI, CoherenceMap, Noise and BeaconPhase: It were not working properly when xmin and xmax were defined and more than one day selected.
Miguel Valdez -
r760:4d4218b17f73
parent child
Show More
@@ -5,6 +5,28 import mpldriver
5 5
6 6 from schainpy.model.proc.jroproc_base import Operation
7 7
8 def isTimeInHourRange(datatime, xmin, xmax):
9
10 if xmin == None or xmax == None:
11 return 1
12 hour = datatime.hour + datatime.minute/60.0
13
14 if xmin < (xmax % 24):
15
16 if hour >= xmin and hour <= xmax:
17 return 1
18 else:
19 return 0
20
21 else:
22
23 if hour >= xmin or hour <= (xmax % 24):
24 return 1
25 else:
26 return 0
27
28 return 0
29
8 30 def isRealtime(utcdatatime):
9 31
10 32 utcnow = time.mktime(time.localtime())
@@ -38,6 +60,8 class Figure(Operation):
38 60
39 61 figfile = None
40 62
63 created = False
64
41 65 def __init__(self):
42 66
43 67 raise NotImplementedError
@@ -71,13 +95,13 class Figure(Operation):
71 95
72 96 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
73 97
74 if self.xmin != None and self.xmax != None:
75 if timerange == None:
76 timerange = self.xmax - self.xmin
77 xmin = self.xmin + timerange
78 xmax = self.xmax + timerange
79
80 return xmin, xmax
98 # if self.xmin != None and self.xmax != None:
99 # if timerange == None:
100 # timerange = self.xmax - self.xmin
101 # xmin = self.xmin + timerange
102 # xmax = self.xmax + timerange
103 #
104 # return xmin, xmax
81 105
82 106 if timerange == None and (xmin==None or xmax==None):
83 107 timerange = 14400 #seconds
@@ -131,15 +155,22 class Figure(Operation):
131 155
132 156 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
133 157
134 self.fig = self.__driver.createFigure(id=self.id,
135 wintitle=self.wintitle,
136 width=self.widthscreen,
137 height=self.heightscreen,
138 show=show)
158 # if self.created:
159 # self.__driver.closeFigure(self.fig)
160
161 if not self.created:
162 self.fig = self.__driver.createFigure(id=self.id,
163 wintitle=self.wintitle,
164 width=self.widthscreen,
165 height=self.heightscreen,
166 show=show)
167 else:
168 self.__driver.clearFigure(self.fig)
139 169
140 170 self.axesObjList = []
141 171 self.counter_imagwr = 0
142 172
173 self.created = True
143 174
144 175 def setDriver(self, driver=mpldriver):
145 176
@@ -7,7 +7,7 import os
7 7 import datetime
8 8 import numpy
9 9
10 from figure import Figure, isRealtime
10 from figure import Figure, isRealtime, isTimeInHourRange
11 11 from plotting_codes import *
12 12
13 13 class SpectraPlot(Figure):
@@ -382,14 +382,14 class CrossSpectraPlot(Figure):
382 382 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
383 383 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
384 384
385 title = "Coherence %d%d" %(pair[0], pair[1])
385 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
386 386 axes0 = self.axesList[i*self.__nsubplots+2]
387 387 axes0.pcolor(x, y, coherence,
388 388 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
389 389 xlabel=xlabel, ylabel=ylabel, title=title,
390 390 ticksize=9, colormap=coherence_cmap, cblabel='')
391 391
392 title = "Phase %d%d" %(pair[0], pair[1])
392 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
393 393 axes0 = self.axesList[i*self.__nsubplots+3]
394 394 axes0.pcolor(x, y, phase,
395 395 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
@@ -420,7 +420,7 class RTIPlot(Figure):
420 420 def __init__(self):
421 421
422 422 self.timerange = None
423 self.__isConfig = False
423 self.isConfig = False
424 424 self.__nsubplots = 1
425 425
426 426 self.WIDTH = 800
@@ -507,6 +507,9 class RTIPlot(Figure):
507 507 zmax : None
508 508 """
509 509
510 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
511 return
512
510 513 if channelList == None:
511 514 channelIndexList = dataOut.channelIndexList
512 515 else:
@@ -516,11 +519,6 class RTIPlot(Figure):
516 519 raise ValueError, "Channel %d is not in dataOut.channelList"
517 520 channelIndexList.append(dataOut.channelList.index(channel))
518 521
519 # if timerange != None:
520 # self.timerange = timerange
521
522 #tmin = None
523 #tmax = None
524 522 factor = dataOut.normFactor
525 523 x = dataOut.getTimeRange()
526 524 y = dataOut.getHeiRange()
@@ -530,15 +528,16 class RTIPlot(Figure):
530 528 avg = numpy.average(z, axis=1)
531 529
532 530 avgdB = 10.*numpy.log10(avg)
533
534 531
535 # thisDatetime = dataOut.datatime
536 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
532 thisDatetime = dataOut.datatime
533 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
537 534 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
538 535 xlabel = ""
539 536 ylabel = "Range (Km)"
540 537
541 if not self.__isConfig:
538 update_figfile = False
539
540 if not self.isConfig:
542 541
543 542 nplots = len(channelIndexList)
544 543
@@ -567,14 +566,12 class RTIPlot(Figure):
567 566 self.PLOT_POS = plot_pos
568 567
569 568 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
570 self.__isConfig = True
569 self.isConfig = True
571 570 self.figfile = figfile
572
571 update_figfile = True
572
573 573 self.setWinTitle(title)
574 574
575 if ((self.xmax - x[1]) < (x[1]-x[0])):
576 x[1] = self.xmax
577
578 575 for i in range(self.nplots):
579 576 index = channelIndexList[i]
580 577 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
@@ -595,12 +592,12 class RTIPlot(Figure):
595 592 ytick_visible=False,
596 593 grid='x')
597 594
598 self.draw()
599
600 if x[1] >= self.axesList[0].xmax:
595 self.draw()
596
597 if dataOut.ltctime >= self.xmax:
601 598 self.counter_imagwr = wr_period
602 self.__isConfig = False
603 self.figfile = None
599 self.isConfig = False
600 update_figfile = True
604 601
605 602 self.save(figpath=figpath,
606 603 figfile=figfile,
@@ -608,7 +605,7 class RTIPlot(Figure):
608 605 ftp=ftp,
609 606 wr_period=wr_period,
610 607 thisDatetime=thisDatetime,
611 update_figfile=False)
608 update_figfile=update_figfile)
612 609
613 610 class CoherenceMap(Figure):
614 611 isConfig = None
@@ -680,7 +677,10 class CoherenceMap(Figure):
680 677 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
681 678 server=None, folder=None, username=None, password=None,
682 679 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
683
680
681 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
682 return
683
684 684 if pairsList == None:
685 685 pairsIndexList = dataOut.pairsIndexList
686 686 else:
@@ -700,17 +700,16 class CoherenceMap(Figure):
700 700 phase_min = -180
701 701 if phase_max == None:
702 702 phase_max = 180
703
704 # tmin = None
705 # tmax = None
703
706 704 x = dataOut.getTimeRange()
707 705 y = dataOut.getHeiRange()
708 706
709 #thisDatetime = dataOut.datatime
710 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
707 thisDatetime = dataOut.datatime
708
711 709 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
712 710 xlabel = ""
713 711 ylabel = "Range (Km)"
712 update_figfile = False
714 713
715 714 if not self.isConfig:
716 715 nplots = len(pairsIndexList)
@@ -738,12 +737,10 class CoherenceMap(Figure):
738 737 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
739 738
740 739 self.isConfig = True
740 update_figfile = True
741 741
742 742 self.setWinTitle(title)
743 743
744 if ((self.xmax - x[1]) < (x[1]-x[0])):
745 x[1] = self.xmax
746
747 744 for i in range(self.nplots):
748 745
749 746 pair = dataOut.pairsList[pairsIndexList[i]]
@@ -760,7 +757,7 class CoherenceMap(Figure):
760 757
761 758 counter = 0
762 759
763 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
760 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
764 761 axes = self.axesList[i*self.__nsubplots*2]
765 762 axes.pcolorbuffer(x, y, z,
766 763 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
@@ -782,7 +779,7 class CoherenceMap(Figure):
782 779
783 780 z = phase.reshape((1,-1))
784 781
785 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
782 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
786 783 axes = self.axesList[i*self.__nsubplots*2 + counter]
787 784 axes.pcolorbuffer(x, y, z,
788 785 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
@@ -800,10 +797,10 class CoherenceMap(Figure):
800 797
801 798 self.draw()
802 799
803 if x[1] >= self.axesList[0].xmax:
800 if dataOut.ltctime >= self.xmax:
804 801 self.counter_imagwr = wr_period
805 self.__isConfig = False
806 self.figfile = None
802 self.isConfig = False
803 update_figfile = True
807 804
808 805 self.save(figpath=figpath,
809 806 figfile=figfile,
@@ -811,7 +808,7 class CoherenceMap(Figure):
811 808 ftp=ftp,
812 809 wr_period=wr_period,
813 810 thisDatetime=thisDatetime,
814 update_figfile=False)
811 update_figfile=update_figfile)
815 812
816 813 class PowerProfilePlot(Figure):
817 814
@@ -913,7 +910,7 class PowerProfilePlot(Figure):
913 910 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
914 911 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
915 912
916 self.__isConfig = True
913 self.isConfig = True
917 914
918 915 self.setWinTitle(title)
919 916
@@ -949,8 +946,8 class Noise(Figure):
949 946 self.isConfig = False
950 947 self.__nsubplots = 1
951 948 self.counter_imagwr = 0
952 self.WIDTH = 600
953 self.HEIGHT = 300
949 self.WIDTH = 800
950 self.HEIGHT = 400
954 951 self.WIDTHPROF = 120
955 952 self.HEIGHTPROF = 0
956 953 self.xdata = None
@@ -1033,6 +1030,9 class Noise(Figure):
1033 1030 server=None, folder=None, username=None, password=None,
1034 1031 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1035 1032
1033 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1034 return
1035
1036 1036 if channelList == None:
1037 1037 channelIndexList = dataOut.channelIndexList
1038 1038 channelList = dataOut.channelList
@@ -1049,11 +1049,12 class Noise(Figure):
1049 1049 noise = dataOut.noise[channelIndexList]/factor
1050 1050 noisedB = 10*numpy.log10(noise)
1051 1051
1052 #thisDatetime = dataOut.datatime
1053 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1052 thisDatetime = dataOut.datatime
1053
1054 1054 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1055 1055 xlabel = ""
1056 1056 ylabel = "Intensity (dB)"
1057 update_figfile = False
1057 1058
1058 1059 if not self.isConfig:
1059 1060
@@ -1085,13 +1086,14 class Noise(Figure):
1085 1086 self.xdata = numpy.array([])
1086 1087 self.ydata = numpy.array([])
1087 1088
1089 update_figfile = True
1090
1088 1091 #open file beacon phase
1089 1092 path = '%s%03d' %(self.PREFIX, self.id)
1090 1093 noise_file = os.path.join(path,'%s.txt'%self.name)
1091 1094 self.filename_noise = os.path.join(figpath,noise_file)
1092 1095
1093 1096 self.setWinTitle(title)
1094
1095 1097
1096 1098 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1097 1099
@@ -1114,12 +1116,10 class Noise(Figure):
1114 1116
1115 1117 self.draw()
1116 1118
1117 if x[1] >= self.axesList[0].xmax:
1119 if dataOut.ltctime >= self.xmax:
1118 1120 self.counter_imagwr = wr_period
1119 del self.xdata
1120 del self.ydata
1121 self.__isConfig = False
1122 self.figfile = None
1121 self.isConfig = False
1122 update_figfile = True
1123 1123
1124 1124 self.save(figpath=figpath,
1125 1125 figfile=figfile,
@@ -1127,7 +1127,7 class Noise(Figure):
1127 1127 ftp=ftp,
1128 1128 wr_period=wr_period,
1129 1129 thisDatetime=thisDatetime,
1130 update_figfile=False)
1130 update_figfile=update_figfile)
1131 1131
1132 1132 #store data beacon phase
1133 1133 if save:
@@ -1143,11 +1143,11 class BeaconPhase(Figure):
1143 1143 def __init__(self):
1144 1144
1145 1145 self.timerange = 24*60*60
1146 self.__isConfig = False
1146 self.isConfig = False
1147 1147 self.__nsubplots = 1
1148 1148 self.counter_imagwr = 0
1149 self.WIDTH = 600
1150 self.HEIGHT = 300
1149 self.WIDTH = 800
1150 self.HEIGHT = 400
1151 1151 self.WIDTHPROF = 120
1152 1152 self.HEIGHTPROF = 0
1153 1153 self.xdata = None
@@ -1214,14 +1214,17 class BeaconPhase(Figure):
1214 1214
1215 1215
1216 1216 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1217 xmin=None, xmax=None, ymin=None, ymax=None,
1217 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1218 1218 timerange=None,
1219 1219 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1220 1220 server=None, folder=None, username=None, password=None,
1221 1221 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1222 1222
1223 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1224 return
1225
1223 1226 if pairsList == None:
1224 pairsIndexList = dataOut.pairsIndexList
1227 pairsIndexList = dataOut.pairsIndexList[:10]
1225 1228 else:
1226 1229 pairsIndexList = []
1227 1230 for pair in pairsList:
@@ -1234,34 +1237,53 class BeaconPhase(Figure):
1234 1237
1235 1238 # if len(pairsIndexList) > 4:
1236 1239 # pairsIndexList = pairsIndexList[0:4]
1240
1241 hmin_index = None
1242 hmax_index = None
1237 1243
1244 if hmin != None and hmax != None:
1245 indexes = numpy.arange(dataOut.nHeights)
1246 hmin_list = indexes[dataOut.heightList >= hmin]
1247 hmax_list = indexes[dataOut.heightList <= hmax]
1248
1249 if hmin_list.any():
1250 hmin_index = hmin_list[0]
1251
1252 if hmax_list.any():
1253 hmax_index = hmax_list[-1]+1
1254
1238 1255 x = dataOut.getTimeRange()
1239 1256 #y = dataOut.getHeiRange()
1240 1257
1241 1258
1242 #thisDatetime = dataOut.datatime
1243 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1244 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1259 thisDatetime = dataOut.datatime
1260
1261 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1245 1262 xlabel = "Local Time"
1246 ylabel = "Phase"
1263 ylabel = "Phase (degrees)"
1264
1265 update_figfile = False
1247 1266
1248 1267 nplots = len(pairsIndexList)
1249 1268 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1250 1269 phase_beacon = numpy.zeros(len(pairsIndexList))
1251 1270 for i in range(nplots):
1252 1271 pair = dataOut.pairsList[pairsIndexList[i]]
1253 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
1254 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
1255 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
1272 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1273 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1274 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1256 1275 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1257 1276 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1258 1277
1259 1278 #print "Phase %d%d" %(pair[0], pair[1])
1260 1279 #print phase[dataOut.beacon_heiIndexList]
1261 1280
1262 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1281 if dataOut.beacon_heiIndexList:
1282 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1283 else:
1284 phase_beacon[i] = numpy.average(phase)
1263 1285
1264 if not self.__isConfig:
1286 if not self.isConfig:
1265 1287
1266 1288 nplots = len(pairsIndexList)
1267 1289
@@ -1276,8 +1298,8 class BeaconPhase(Figure):
1276 1298
1277 1299 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1278 1300
1279 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1280 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1301 if ymin == None: ymin = 0
1302 if ymax == None: ymax = 360
1281 1303
1282 1304 self.FTP_WEI = ftp_wei
1283 1305 self.EXP_CODE = exp_code
@@ -1285,11 +1307,13 class BeaconPhase(Figure):
1285 1307 self.PLOT_POS = plot_pos
1286 1308
1287 1309 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1288 self.__isConfig = True
1310 self.isConfig = True
1289 1311 self.figfile = figfile
1290 1312 self.xdata = numpy.array([])
1291 1313 self.ydata = numpy.array([])
1292 1314
1315 update_figfile = True
1316
1293 1317 #open file beacon phase
1294 1318 path = '%s%03d' %(self.PREFIX, self.id)
1295 1319 beacon_file = os.path.join(path,'%s.txt'%self.name)
@@ -1303,9 +1327,9 class BeaconPhase(Figure):
1303 1327 self.setWinTitle(title)
1304 1328
1305 1329
1306 title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1330 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1307 1331
1308 legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1332 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1309 1333
1310 1334 axes = self.axesList[0]
1311 1335
@@ -1325,12 +1349,10 class BeaconPhase(Figure):
1325 1349
1326 1350 self.draw()
1327 1351
1328 if x[1] >= self.axesList[0].xmax:
1352 if dataOut.ltctime >= self.xmax:
1329 1353 self.counter_imagwr = wr_period
1330 del self.xdata
1331 del self.ydata
1332 self.__isConfig = False
1333 self.figfile = None
1354 self.isConfig = False
1355 update_figfile = True
1334 1356
1335 1357 self.save(figpath=figpath,
1336 1358 figfile=figfile,
@@ -1338,4 +1360,4 class BeaconPhase(Figure):
1338 1360 ftp=ftp,
1339 1361 wr_period=wr_period,
1340 1362 thisDatetime=thisDatetime,
1341 update_figfile=False)
1363 update_figfile=update_figfile)
@@ -32,7 +32,7 def createFigure(id, wintitle, width, height, facecolor="w", show=True):
32 32
33 33 def closeFigure(show=False, fig=None):
34 34
35 matplotlib.pyplot.ioff()
35 # matplotlib.pyplot.ioff()
36 36 # matplotlib.pyplot.pause(0)
37 37
38 38 if show:
@@ -57,6 +57,10 def saveFigure(fig, filename):
57 57 fig.savefig(filename)
58 58 # matplotlib.pyplot.ion()
59 59
60 def clearFigure(fig):
61
62 fig.clf()
63
60 64 def setWinTitle(fig, title):
61 65
62 66 fig.canvas.manager.set_window_title(title)
General Comments 0
You need to be logged in to leave comments. Login now