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