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