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