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