##// END OF EJS Templates
bug fixed: store png file in workspace
Daniel Valdez -
r492:5ccb3e8f6781
parent child
Show More
@@ -1,1151 +1,1151
1 '''
1 '''
2 @author: Daniel Suarez
2 @author: Daniel Suarez
3 '''
3 '''
4 import os
4 import os
5 import datetime
5 import datetime
6 import numpy
6 import numpy
7
7
8 from figure import Figure, isRealtime
8 from figure import Figure, isRealtime
9
9
10 class SpectraPlot(Figure):
10 class SpectraPlot(Figure):
11
11
12 isConfig = None
12 isConfig = None
13 __nsubplots = None
13 __nsubplots = None
14
14
15 WIDTHPROF = None
15 WIDTHPROF = None
16 HEIGHTPROF = None
16 HEIGHTPROF = None
17 PREFIX = 'spc'
17 PREFIX = 'spc'
18
18
19 def __init__(self):
19 def __init__(self):
20
20
21 self.isConfig = False
21 self.isConfig = False
22 self.__nsubplots = 1
22 self.__nsubplots = 1
23
23
24 self.WIDTH = 280
24 self.WIDTH = 280
25 self.HEIGHT = 250
25 self.HEIGHT = 250
26 self.WIDTHPROF = 120
26 self.WIDTHPROF = 120
27 self.HEIGHTPROF = 0
27 self.HEIGHTPROF = 0
28 self.counter_imagwr = 0
28 self.counter_imagwr = 0
29
29
30 self.PLOT_CODE = 1
30 self.PLOT_CODE = 1
31 self.FTP_WEI = None
31 self.FTP_WEI = None
32 self.EXP_CODE = None
32 self.EXP_CODE = None
33 self.SUB_EXP_CODE = None
33 self.SUB_EXP_CODE = None
34 self.PLOT_POS = None
34 self.PLOT_POS = None
35
35
36 def getSubplots(self):
36 def getSubplots(self):
37
37
38 ncol = int(numpy.sqrt(self.nplots)+0.9)
38 ncol = int(numpy.sqrt(self.nplots)+0.9)
39 nrow = int(self.nplots*1./ncol + 0.9)
39 nrow = int(self.nplots*1./ncol + 0.9)
40
40
41 return nrow, ncol
41 return nrow, ncol
42
42
43 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
43 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
44
44
45 self.__showprofile = showprofile
45 self.__showprofile = showprofile
46 self.nplots = nplots
46 self.nplots = nplots
47
47
48 ncolspan = 1
48 ncolspan = 1
49 colspan = 1
49 colspan = 1
50 if showprofile:
50 if showprofile:
51 ncolspan = 3
51 ncolspan = 3
52 colspan = 2
52 colspan = 2
53 self.__nsubplots = 2
53 self.__nsubplots = 2
54
54
55 self.createFigure(id = id,
55 self.createFigure(id = id,
56 wintitle = wintitle,
56 wintitle = wintitle,
57 widthplot = self.WIDTH + self.WIDTHPROF,
57 widthplot = self.WIDTH + self.WIDTHPROF,
58 heightplot = self.HEIGHT + self.HEIGHTPROF,
58 heightplot = self.HEIGHT + self.HEIGHTPROF,
59 show=show)
59 show=show)
60
60
61 nrow, ncol = self.getSubplots()
61 nrow, ncol = self.getSubplots()
62
62
63 counter = 0
63 counter = 0
64 for y in range(nrow):
64 for y in range(nrow):
65 for x in range(ncol):
65 for x in range(ncol):
66
66
67 if counter >= self.nplots:
67 if counter >= self.nplots:
68 break
68 break
69
69
70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
71
71
72 if showprofile:
72 if showprofile:
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
74
74
75 counter += 1
75 counter += 1
76
76
77 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
77 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
78 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
78 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
79 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
79 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
80 server=None, folder=None, username=None, password=None,
80 server=None, folder=None, username=None, password=None,
81 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
81 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
82
82
83 """
83 """
84
84
85 Input:
85 Input:
86 dataOut :
86 dataOut :
87 id :
87 id :
88 wintitle :
88 wintitle :
89 channelList :
89 channelList :
90 showProfile :
90 showProfile :
91 xmin : None,
91 xmin : None,
92 xmax : None,
92 xmax : None,
93 ymin : None,
93 ymin : None,
94 ymax : None,
94 ymax : None,
95 zmin : None,
95 zmin : None,
96 zmax : None
96 zmax : None
97 """
97 """
98
98
99 if dataOut.flagNoData:
99 if dataOut.flagNoData:
100 return None
100 return None
101
101
102 if realtime:
102 if realtime:
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 print 'Skipping this plot function'
104 print 'Skipping this plot function'
105 return
105 return
106
106
107 if channelList == None:
107 if channelList == None:
108 channelIndexList = dataOut.channelIndexList
108 channelIndexList = dataOut.channelIndexList
109 else:
109 else:
110 channelIndexList = []
110 channelIndexList = []
111 for channel in channelList:
111 for channel in channelList:
112 if channel not in dataOut.channelList:
112 if channel not in dataOut.channelList:
113 raise ValueError, "Channel %d is not in dataOut.channelList"
113 raise ValueError, "Channel %d is not in dataOut.channelList"
114 channelIndexList.append(dataOut.channelList.index(channel))
114 channelIndexList.append(dataOut.channelList.index(channel))
115
115
116 factor = dataOut.normFactor
116 factor = dataOut.normFactor
117
117
118 x = dataOut.getVelRange(1)
118 x = dataOut.getVelRange(1)
119 y = dataOut.getHeiRange()
119 y = dataOut.getHeiRange()
120
120
121 z = dataOut.data_spc[channelIndexList,:,:]/factor
121 z = dataOut.data_spc[channelIndexList,:,:]/factor
122 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
122 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
123 avg = numpy.average(z, axis=1)
123 avg = numpy.average(z, axis=1)
124 avg = numpy.nanmean(z, axis=1)
124 avg = numpy.nanmean(z, axis=1)
125 noise = dataOut.noise/factor
125 noise = dataOut.noise/factor
126
126
127 zdB = 10*numpy.log10(z)
127 zdB = 10*numpy.log10(z)
128 avgdB = 10*numpy.log10(avg)
128 avgdB = 10*numpy.log10(avg)
129 noisedB = 10*numpy.log10(noise)
129 noisedB = 10*numpy.log10(noise)
130
130
131 #thisDatetime = dataOut.datatime
131 #thisDatetime = dataOut.datatime
132 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
132 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
133 title = wintitle + " Spectra"
133 title = wintitle + " Spectra"
134 xlabel = "Velocity (m/s)"
134 xlabel = "Velocity (m/s)"
135 ylabel = "Range (Km)"
135 ylabel = "Range (Km)"
136
136
137 if not self.isConfig:
137 if not self.isConfig:
138
138
139 nplots = len(channelIndexList)
139 nplots = len(channelIndexList)
140
140
141 self.setup(id=id,
141 self.setup(id=id,
142 nplots=nplots,
142 nplots=nplots,
143 wintitle=wintitle,
143 wintitle=wintitle,
144 showprofile=showprofile,
144 showprofile=showprofile,
145 show=show)
145 show=show)
146
146
147 if xmin == None: xmin = numpy.nanmin(x)
147 if xmin == None: xmin = numpy.nanmin(x)
148 if xmax == None: xmax = numpy.nanmax(x)
148 if xmax == None: xmax = numpy.nanmax(x)
149 if ymin == None: ymin = numpy.nanmin(y)
149 if ymin == None: ymin = numpy.nanmin(y)
150 if ymax == None: ymax = numpy.nanmax(y)
150 if ymax == None: ymax = numpy.nanmax(y)
151 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
151 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
152 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
152 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
153
153
154 self.FTP_WEI = ftp_wei
154 self.FTP_WEI = ftp_wei
155 self.EXP_CODE = exp_code
155 self.EXP_CODE = exp_code
156 self.SUB_EXP_CODE = sub_exp_code
156 self.SUB_EXP_CODE = sub_exp_code
157 self.PLOT_POS = plot_pos
157 self.PLOT_POS = plot_pos
158
158
159 self.isConfig = True
159 self.isConfig = True
160
160
161 self.setWinTitle(title)
161 self.setWinTitle(title)
162
162
163 for i in range(self.nplots):
163 for i in range(self.nplots):
164 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
164 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
165 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
165 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
166 axes = self.axesList[i*self.__nsubplots]
166 axes = self.axesList[i*self.__nsubplots]
167 axes.pcolor(x, y, zdB[i,:,:],
167 axes.pcolor(x, y, zdB[i,:,:],
168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
169 xlabel=xlabel, ylabel=ylabel, title=title,
169 xlabel=xlabel, ylabel=ylabel, title=title,
170 ticksize=9, cblabel='')
170 ticksize=9, cblabel='')
171
171
172 if self.__showprofile:
172 if self.__showprofile:
173 axes = self.axesList[i*self.__nsubplots +1]
173 axes = self.axesList[i*self.__nsubplots +1]
174 axes.pline(avgdB[i], y,
174 axes.pline(avgdB[i], y,
175 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
175 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
176 xlabel='dB', ylabel='', title='',
176 xlabel='dB', ylabel='', title='',
177 ytick_visible=False,
177 ytick_visible=False,
178 grid='x')
178 grid='x')
179
179
180 noiseline = numpy.repeat(noisedB[i], len(y))
180 noiseline = numpy.repeat(noisedB[i], len(y))
181 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
181 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
182
182
183 self.draw()
183 self.draw()
184
184
185 if figfile == None:
185 if figfile == None:
186 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
186 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
187 figfile = self.getFilename(name = str_datetime)
187 figfile = self.getFilename(name = str_datetime)
188
188
189 if figpath != '':
189 if figpath != '':
190 self.counter_imagwr += 1
190 self.counter_imagwr += 1
191 if (self.counter_imagwr>=wr_period):
191 if (self.counter_imagwr>=wr_period):
192 # store png plot to local folder
192 # store png plot to local folder
193 self.saveFigure(figpath, figfile)
193 self.saveFigure(figpath, figfile)
194 # store png plot to FTP server according to RT-Web format
194 # store png plot to FTP server according to RT-Web format
195 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
195 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
196 ftp_filename = os.path.join(figpath, name)
196 ftp_filename = os.path.join(figpath, name)
197 self.saveFigure(figpath, ftp_filename)
197 self.saveFigure(figpath, ftp_filename)
198 self.counter_imagwr = 0
198 self.counter_imagwr = 0
199
199
200
200
201 class CrossSpectraPlot(Figure):
201 class CrossSpectraPlot(Figure):
202
202
203 isConfig = None
203 isConfig = None
204 __nsubplots = None
204 __nsubplots = None
205
205
206 WIDTH = None
206 WIDTH = None
207 HEIGHT = None
207 HEIGHT = None
208 WIDTHPROF = None
208 WIDTHPROF = None
209 HEIGHTPROF = None
209 HEIGHTPROF = None
210 PREFIX = 'cspc'
210 PREFIX = 'cspc'
211
211
212 def __init__(self):
212 def __init__(self):
213
213
214 self.isConfig = False
214 self.isConfig = False
215 self.__nsubplots = 4
215 self.__nsubplots = 4
216 self.counter_imagwr = 0
216 self.counter_imagwr = 0
217 self.WIDTH = 250
217 self.WIDTH = 250
218 self.HEIGHT = 250
218 self.HEIGHT = 250
219 self.WIDTHPROF = 0
219 self.WIDTHPROF = 0
220 self.HEIGHTPROF = 0
220 self.HEIGHTPROF = 0
221
221
222 self.PLOT_CODE = 1
222 self.PLOT_CODE = 1
223 self.FTP_WEI = None
223 self.FTP_WEI = None
224 self.EXP_CODE = None
224 self.EXP_CODE = None
225 self.SUB_EXP_CODE = None
225 self.SUB_EXP_CODE = None
226 self.PLOT_POS = None
226 self.PLOT_POS = None
227
227
228 def getSubplots(self):
228 def getSubplots(self):
229
229
230 ncol = 4
230 ncol = 4
231 nrow = self.nplots
231 nrow = self.nplots
232
232
233 return nrow, ncol
233 return nrow, ncol
234
234
235 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
235 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
236
236
237 self.__showprofile = showprofile
237 self.__showprofile = showprofile
238 self.nplots = nplots
238 self.nplots = nplots
239
239
240 ncolspan = 1
240 ncolspan = 1
241 colspan = 1
241 colspan = 1
242
242
243 self.createFigure(id = id,
243 self.createFigure(id = id,
244 wintitle = wintitle,
244 wintitle = wintitle,
245 widthplot = self.WIDTH + self.WIDTHPROF,
245 widthplot = self.WIDTH + self.WIDTHPROF,
246 heightplot = self.HEIGHT + self.HEIGHTPROF,
246 heightplot = self.HEIGHT + self.HEIGHTPROF,
247 show=True)
247 show=True)
248
248
249 nrow, ncol = self.getSubplots()
249 nrow, ncol = self.getSubplots()
250
250
251 counter = 0
251 counter = 0
252 for y in range(nrow):
252 for y in range(nrow):
253 for x in range(ncol):
253 for x in range(ncol):
254 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
254 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
255
255
256 counter += 1
256 counter += 1
257
257
258 def run(self, dataOut, id, wintitle="", pairsList=None,
258 def run(self, dataOut, id, wintitle="", pairsList=None,
259 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
259 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
260 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
260 save=False, figpath='', figfile=None, ftp=False, wr_period=1,
261 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
261 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
262 server=None, folder=None, username=None, password=None,
262 server=None, folder=None, username=None, password=None,
263 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
263 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
264
264
265 """
265 """
266
266
267 Input:
267 Input:
268 dataOut :
268 dataOut :
269 id :
269 id :
270 wintitle :
270 wintitle :
271 channelList :
271 channelList :
272 showProfile :
272 showProfile :
273 xmin : None,
273 xmin : None,
274 xmax : None,
274 xmax : None,
275 ymin : None,
275 ymin : None,
276 ymax : None,
276 ymax : None,
277 zmin : None,
277 zmin : None,
278 zmax : None
278 zmax : None
279 """
279 """
280
280
281 if pairsList == None:
281 if pairsList == None:
282 pairsIndexList = dataOut.pairsIndexList
282 pairsIndexList = dataOut.pairsIndexList
283 else:
283 else:
284 pairsIndexList = []
284 pairsIndexList = []
285 for pair in pairsList:
285 for pair in pairsList:
286 if pair not in dataOut.pairsList:
286 if pair not in dataOut.pairsList:
287 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
287 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
288 pairsIndexList.append(dataOut.pairsList.index(pair))
288 pairsIndexList.append(dataOut.pairsList.index(pair))
289
289
290 if pairsIndexList == []:
290 if pairsIndexList == []:
291 return
291 return
292
292
293 if len(pairsIndexList) > 4:
293 if len(pairsIndexList) > 4:
294 pairsIndexList = pairsIndexList[0:4]
294 pairsIndexList = pairsIndexList[0:4]
295 factor = dataOut.normFactor
295 factor = dataOut.normFactor
296 x = dataOut.getVelRange(1)
296 x = dataOut.getVelRange(1)
297 y = dataOut.getHeiRange()
297 y = dataOut.getHeiRange()
298 z = dataOut.data_spc[:,:,:]/factor
298 z = dataOut.data_spc[:,:,:]/factor
299 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
299 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
300 avg = numpy.abs(numpy.average(z, axis=1))
300 avg = numpy.abs(numpy.average(z, axis=1))
301 noise = dataOut.noise()/factor
301 noise = dataOut.noise()/factor
302
302
303 zdB = 10*numpy.log10(z)
303 zdB = 10*numpy.log10(z)
304 avgdB = 10*numpy.log10(avg)
304 avgdB = 10*numpy.log10(avg)
305 noisedB = 10*numpy.log10(noise)
305 noisedB = 10*numpy.log10(noise)
306
306
307
307
308 #thisDatetime = dataOut.datatime
308 #thisDatetime = dataOut.datatime
309 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
309 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
310 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
310 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
311 xlabel = "Velocity (m/s)"
311 xlabel = "Velocity (m/s)"
312 ylabel = "Range (Km)"
312 ylabel = "Range (Km)"
313
313
314 if not self.isConfig:
314 if not self.isConfig:
315
315
316 nplots = len(pairsIndexList)
316 nplots = len(pairsIndexList)
317
317
318 self.setup(id=id,
318 self.setup(id=id,
319 nplots=nplots,
319 nplots=nplots,
320 wintitle=wintitle,
320 wintitle=wintitle,
321 showprofile=False,
321 showprofile=False,
322 show=show)
322 show=show)
323
323
324 if xmin == None: xmin = numpy.nanmin(x)
324 if xmin == None: xmin = numpy.nanmin(x)
325 if xmax == None: xmax = numpy.nanmax(x)
325 if xmax == None: xmax = numpy.nanmax(x)
326 if ymin == None: ymin = numpy.nanmin(y)
326 if ymin == None: ymin = numpy.nanmin(y)
327 if ymax == None: ymax = numpy.nanmax(y)
327 if ymax == None: ymax = numpy.nanmax(y)
328 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
328 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
329 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
329 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
330
330
331 self.FTP_WEI = ftp_wei
331 self.FTP_WEI = ftp_wei
332 self.EXP_CODE = exp_code
332 self.EXP_CODE = exp_code
333 self.SUB_EXP_CODE = sub_exp_code
333 self.SUB_EXP_CODE = sub_exp_code
334 self.PLOT_POS = plot_pos
334 self.PLOT_POS = plot_pos
335
335
336 self.isConfig = True
336 self.isConfig = True
337
337
338 self.setWinTitle(title)
338 self.setWinTitle(title)
339
339
340 for i in range(self.nplots):
340 for i in range(self.nplots):
341 pair = dataOut.pairsList[pairsIndexList[i]]
341 pair = dataOut.pairsList[pairsIndexList[i]]
342 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
342 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
343 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime)
343 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime)
344 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
344 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
345 axes0 = self.axesList[i*self.__nsubplots]
345 axes0 = self.axesList[i*self.__nsubplots]
346 axes0.pcolor(x, y, zdB,
346 axes0.pcolor(x, y, zdB,
347 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
347 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
348 xlabel=xlabel, ylabel=ylabel, title=title,
348 xlabel=xlabel, ylabel=ylabel, title=title,
349 ticksize=9, colormap=power_cmap, cblabel='')
349 ticksize=9, colormap=power_cmap, cblabel='')
350
350
351 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime)
351 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime)
352 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
352 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
353 axes0 = self.axesList[i*self.__nsubplots+1]
353 axes0 = self.axesList[i*self.__nsubplots+1]
354 axes0.pcolor(x, y, zdB,
354 axes0.pcolor(x, y, zdB,
355 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
355 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
356 xlabel=xlabel, ylabel=ylabel, title=title,
356 xlabel=xlabel, ylabel=ylabel, title=title,
357 ticksize=9, colormap=power_cmap, cblabel='')
357 ticksize=9, colormap=power_cmap, cblabel='')
358
358
359 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
359 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
360 coherence = numpy.abs(coherenceComplex)
360 coherence = numpy.abs(coherenceComplex)
361 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
361 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
362 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
362 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
363
363
364 title = "Coherence %d%d" %(pair[0], pair[1])
364 title = "Coherence %d%d" %(pair[0], pair[1])
365 axes0 = self.axesList[i*self.__nsubplots+2]
365 axes0 = self.axesList[i*self.__nsubplots+2]
366 axes0.pcolor(x, y, coherence,
366 axes0.pcolor(x, y, coherence,
367 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
367 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
368 xlabel=xlabel, ylabel=ylabel, title=title,
368 xlabel=xlabel, ylabel=ylabel, title=title,
369 ticksize=9, colormap=coherence_cmap, cblabel='')
369 ticksize=9, colormap=coherence_cmap, cblabel='')
370
370
371 title = "Phase %d%d" %(pair[0], pair[1])
371 title = "Phase %d%d" %(pair[0], pair[1])
372 axes0 = self.axesList[i*self.__nsubplots+3]
372 axes0 = self.axesList[i*self.__nsubplots+3]
373 axes0.pcolor(x, y, phase,
373 axes0.pcolor(x, y, phase,
374 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
374 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
375 xlabel=xlabel, ylabel=ylabel, title=title,
375 xlabel=xlabel, ylabel=ylabel, title=title,
376 ticksize=9, colormap=phase_cmap, cblabel='')
376 ticksize=9, colormap=phase_cmap, cblabel='')
377
377
378
378
379
379
380 self.draw()
380 self.draw()
381
381
382 if save:
382 if save:
383
383
384 self.counter_imagwr += 1
384 self.counter_imagwr += 1
385 if (self.counter_imagwr==wr_period):
385 if (self.counter_imagwr==wr_period):
386 if figfile == None:
386 if figfile == None:
387 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
387 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
388 figfile = self.getFilename(name = str_datetime)
388 figfile = self.getFilename(name = str_datetime)
389
389
390 self.saveFigure(figpath, figfile)
390 self.saveFigure(figpath, figfile)
391
391
392 if ftp:
392 if ftp:
393 #provisionalmente envia archivos en el formato de la web en tiempo real
393 #provisionalmente envia archivos en el formato de la web en tiempo real
394 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
394 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
395 path = '%s%03d' %(self.PREFIX, self.id)
395 path = '%s%03d' %(self.PREFIX, self.id)
396 ftp_file = os.path.join(path,'ftp','%s.png'%name)
396 ftp_file = os.path.join(path,'ftp','%s.png'%name)
397 self.saveFigure(figpath, ftp_file)
397 self.saveFigure(figpath, ftp_file)
398 ftp_filename = os.path.join(figpath,ftp_file)
398 ftp_filename = os.path.join(figpath,ftp_file)
399
399
400 try:
400 try:
401 self.sendByFTP(ftp_filename, server, folder, username, password)
401 self.sendByFTP(ftp_filename, server, folder, username, password)
402 except:
402 except:
403 self.counter_imagwr = 0
403 self.counter_imagwr = 0
404 print ValueError, 'Error FTP'
404 print ValueError, 'Error FTP'
405
405
406 self.counter_imagwr = 0
406 self.counter_imagwr = 0
407
407
408 class RTIPlot(Figure):
408 class RTIPlot(Figure):
409
409
410 isConfig = None
410 isConfig = None
411 __nsubplots = None
411 __nsubplots = None
412
412
413 WIDTHPROF = None
413 WIDTHPROF = None
414 HEIGHTPROF = None
414 HEIGHTPROF = None
415 PREFIX = 'rti'
415 PREFIX = 'rti'
416
416
417 def __init__(self):
417 def __init__(self):
418
418
419 self.timerange = 2*60*60
419 self.timerange = 2*60*60
420 self.isConfig = False
420 self.isConfig = False
421 self.__nsubplots = 1
421 self.__nsubplots = 1
422
422
423 self.WIDTH = 800
423 self.WIDTH = 800
424 self.HEIGHT = 150
424 self.HEIGHT = 150
425 self.WIDTHPROF = 120
425 self.WIDTHPROF = 120
426 self.HEIGHTPROF = 0
426 self.HEIGHTPROF = 0
427 self.counter_imagwr = 0
427 self.counter_imagwr = 0
428
428
429 self.PLOT_CODE = 0
429 self.PLOT_CODE = 0
430 self.FTP_WEI = None
430 self.FTP_WEI = None
431 self.EXP_CODE = None
431 self.EXP_CODE = None
432 self.SUB_EXP_CODE = None
432 self.SUB_EXP_CODE = None
433 self.PLOT_POS = None
433 self.PLOT_POS = None
434 self.tmin = None
434 self.tmin = None
435 self.tmax = None
435 self.tmax = None
436
436
437 self.xmin = None
437 self.xmin = None
438 self.xmax = None
438 self.xmax = None
439
439
440 self.figfile = None
440 self.figfile = None
441
441
442 def getSubplots(self):
442 def getSubplots(self):
443
443
444 ncol = 1
444 ncol = 1
445 nrow = self.nplots
445 nrow = self.nplots
446
446
447 return nrow, ncol
447 return nrow, ncol
448
448
449 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
449 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
450
450
451 self.__showprofile = showprofile
451 self.__showprofile = showprofile
452 self.nplots = nplots
452 self.nplots = nplots
453
453
454 ncolspan = 1
454 ncolspan = 1
455 colspan = 1
455 colspan = 1
456 if showprofile:
456 if showprofile:
457 ncolspan = 7
457 ncolspan = 7
458 colspan = 6
458 colspan = 6
459 self.__nsubplots = 2
459 self.__nsubplots = 2
460
460
461 self.createFigure(id = id,
461 self.createFigure(id = id,
462 wintitle = wintitle,
462 wintitle = wintitle,
463 widthplot = self.WIDTH + self.WIDTHPROF,
463 widthplot = self.WIDTH + self.WIDTHPROF,
464 heightplot = self.HEIGHT + self.HEIGHTPROF,
464 heightplot = self.HEIGHT + self.HEIGHTPROF,
465 show=show)
465 show=show)
466
466
467 nrow, ncol = self.getSubplots()
467 nrow, ncol = self.getSubplots()
468
468
469 counter = 0
469 counter = 0
470 for y in range(nrow):
470 for y in range(nrow):
471 for x in range(ncol):
471 for x in range(ncol):
472
472
473 if counter >= self.nplots:
473 if counter >= self.nplots:
474 break
474 break
475
475
476 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
476 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
477
477
478 if showprofile:
478 if showprofile:
479 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
479 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
480
480
481 counter += 1
481 counter += 1
482
482
483 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
483 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
484 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
484 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
485 timerange=None,
485 timerange=None,
486 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
486 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
487 server=None, folder=None, username=None, password=None,
487 server=None, folder=None, username=None, password=None,
488 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
488 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
489
489
490 """
490 """
491
491
492 Input:
492 Input:
493 dataOut :
493 dataOut :
494 id :
494 id :
495 wintitle :
495 wintitle :
496 channelList :
496 channelList :
497 showProfile :
497 showProfile :
498 xmin : None,
498 xmin : None,
499 xmax : None,
499 xmax : None,
500 ymin : None,
500 ymin : None,
501 ymax : None,
501 ymax : None,
502 zmin : None,
502 zmin : None,
503 zmax : None
503 zmax : None
504 """
504 """
505
505
506 if channelList == None:
506 if channelList == None:
507 channelIndexList = dataOut.channelIndexList
507 channelIndexList = dataOut.channelIndexList
508 else:
508 else:
509 channelIndexList = []
509 channelIndexList = []
510 for channel in channelList:
510 for channel in channelList:
511 if channel not in dataOut.channelList:
511 if channel not in dataOut.channelList:
512 raise ValueError, "Channel %d is not in dataOut.channelList"
512 raise ValueError, "Channel %d is not in dataOut.channelList"
513 channelIndexList.append(dataOut.channelList.index(channel))
513 channelIndexList.append(dataOut.channelList.index(channel))
514
514
515 if timerange != None:
515 if timerange != None:
516 self.timerange = timerange
516 self.timerange = timerange
517
517
518 #tmin = None
518 #tmin = None
519 #tmax = None
519 #tmax = None
520 factor = dataOut.normFactor
520 factor = dataOut.normFactor
521 x = dataOut.getTimeRange()
521 x = dataOut.getTimeRange()
522 y = dataOut.getHeiRange()
522 y = dataOut.getHeiRange()
523
523
524 z = dataOut.data_spc[channelIndexList,:,:]/factor
524 z = dataOut.data_spc[channelIndexList,:,:]/factor
525 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
525 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
526 avg = numpy.average(z, axis=1)
526 avg = numpy.average(z, axis=1)
527
527
528 avgdB = 10.*numpy.log10(avg)
528 avgdB = 10.*numpy.log10(avg)
529
529
530
530
531 # thisDatetime = dataOut.datatime
531 # thisDatetime = dataOut.datatime
532 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
532 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
533 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
533 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
534 xlabel = ""
534 xlabel = ""
535 ylabel = "Range (Km)"
535 ylabel = "Range (Km)"
536
536
537 if not self.isConfig:
537 if not self.isConfig:
538
538
539 nplots = len(channelIndexList)
539 nplots = len(channelIndexList)
540
540
541 self.setup(id=id,
541 self.setup(id=id,
542 nplots=nplots,
542 nplots=nplots,
543 wintitle=wintitle,
543 wintitle=wintitle,
544 showprofile=showprofile,
544 showprofile=showprofile,
545 show=show)
545 show=show)
546
546
547 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
547 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
548
548
549 # if timerange != None:
549 # if timerange != None:
550 # self.timerange = timerange
550 # self.timerange = timerange
551 # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange)
551 # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange)
552
552
553
553
554
554
555 if ymin == None: ymin = numpy.nanmin(y)
555 if ymin == None: ymin = numpy.nanmin(y)
556 if ymax == None: ymax = numpy.nanmax(y)
556 if ymax == None: ymax = numpy.nanmax(y)
557 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
557 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
558 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
558 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
559
559
560 self.FTP_WEI = ftp_wei
560 self.FTP_WEI = ftp_wei
561 self.EXP_CODE = exp_code
561 self.EXP_CODE = exp_code
562 self.SUB_EXP_CODE = sub_exp_code
562 self.SUB_EXP_CODE = sub_exp_code
563 self.PLOT_POS = plot_pos
563 self.PLOT_POS = plot_pos
564
564
565 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
565 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
566 self.isConfig = True
566 self.isConfig = True
567 self.figfile = figfile
567 self.figfile = figfile
568
568
569 self.setWinTitle(title)
569 self.setWinTitle(title)
570
570
571 if ((self.xmax - x[1]) < (x[1]-x[0])):
571 if ((self.xmax - x[1]) < (x[1]-x[0])):
572 x[1] = self.xmax
572 x[1] = self.xmax
573
573
574 for i in range(self.nplots):
574 for i in range(self.nplots):
575 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
575 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
576 axes = self.axesList[i*self.__nsubplots]
576 axes = self.axesList[i*self.__nsubplots]
577 zdB = avgdB[i].reshape((1,-1))
577 zdB = avgdB[i].reshape((1,-1))
578 axes.pcolorbuffer(x, y, zdB,
578 axes.pcolorbuffer(x, y, zdB,
579 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
579 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
580 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
580 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
581 ticksize=9, cblabel='', cbsize="1%")
581 ticksize=9, cblabel='', cbsize="1%")
582
582
583 if self.__showprofile:
583 if self.__showprofile:
584 axes = self.axesList[i*self.__nsubplots +1]
584 axes = self.axesList[i*self.__nsubplots +1]
585 axes.pline(avgdB[i], y,
585 axes.pline(avgdB[i], y,
586 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
586 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
587 xlabel='dB', ylabel='', title='',
587 xlabel='dB', ylabel='', title='',
588 ytick_visible=False,
588 ytick_visible=False,
589 grid='x')
589 grid='x')
590
590
591 self.draw()
591 self.draw()
592
592
593 if x[1] >= self.axesList[0].xmax:
593 if x[1] >= self.axesList[0].xmax:
594 self.counter_imagwr = wr_period
594 self.counter_imagwr = wr_period
595 self.__isConfig = False
595 self.__isConfig = False
596
596
597
597
598 if self.figfile == None:
598 if self.figfile == None:
599 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
599 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
600 self.figfile = self.getFilename(name = str_datetime)
600 self.figfile = self.getFilename(name = str_datetime)
601
601
602 if figpath != '':
602 if figpath != '':
603
603
604 self.counter_imagwr += 1
604 self.counter_imagwr += 1
605 if (self.counter_imagwr>=wr_period):
605 if (self.counter_imagwr>=wr_period):
606 # store png plot to local folder
606 # store png plot to local folder
607 self.saveFigure(figpath, self.figfile)
607 self.saveFigure(figpath, self.figfile)
608 # store png plot to FTP server according to RT-Web format
608 # store png plot to FTP server according to RT-Web format
609 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
609 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
610 ftp_filename = os.path.join(figpath, name)
610 ftp_filename = os.path.join(figpath, name)
611 self.saveFigure(figpath, ftp_filename)
611 self.saveFigure(figpath, ftp_filename)
612
612
613 self.counter_imagwr = 0
613 self.counter_imagwr = 0
614
614
615
615
616 class CoherenceMap(Figure):
616 class CoherenceMap(Figure):
617 isConfig = None
617 isConfig = None
618 __nsubplots = None
618 __nsubplots = None
619
619
620 WIDTHPROF = None
620 WIDTHPROF = None
621 HEIGHTPROF = None
621 HEIGHTPROF = None
622 PREFIX = 'cmap'
622 PREFIX = 'cmap'
623
623
624 def __init__(self):
624 def __init__(self):
625 self.timerange = 2*60*60
625 self.timerange = 2*60*60
626 self.isConfig = False
626 self.isConfig = False
627 self.__nsubplots = 1
627 self.__nsubplots = 1
628
628
629 self.WIDTH = 800
629 self.WIDTH = 800
630 self.HEIGHT = 150
630 self.HEIGHT = 150
631 self.WIDTHPROF = 120
631 self.WIDTHPROF = 120
632 self.HEIGHTPROF = 0
632 self.HEIGHTPROF = 0
633 self.counter_imagwr = 0
633 self.counter_imagwr = 0
634
634
635 self.PLOT_CODE = 3
635 self.PLOT_CODE = 3
636 self.FTP_WEI = None
636 self.FTP_WEI = None
637 self.EXP_CODE = None
637 self.EXP_CODE = None
638 self.SUB_EXP_CODE = None
638 self.SUB_EXP_CODE = None
639 self.PLOT_POS = None
639 self.PLOT_POS = None
640 self.counter_imagwr = 0
640 self.counter_imagwr = 0
641
641
642 self.xmin = None
642 self.xmin = None
643 self.xmax = None
643 self.xmax = None
644
644
645 def getSubplots(self):
645 def getSubplots(self):
646 ncol = 1
646 ncol = 1
647 nrow = self.nplots*2
647 nrow = self.nplots*2
648
648
649 return nrow, ncol
649 return nrow, ncol
650
650
651 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
651 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
652 self.__showprofile = showprofile
652 self.__showprofile = showprofile
653 self.nplots = nplots
653 self.nplots = nplots
654
654
655 ncolspan = 1
655 ncolspan = 1
656 colspan = 1
656 colspan = 1
657 if showprofile:
657 if showprofile:
658 ncolspan = 7
658 ncolspan = 7
659 colspan = 6
659 colspan = 6
660 self.__nsubplots = 2
660 self.__nsubplots = 2
661
661
662 self.createFigure(id = id,
662 self.createFigure(id = id,
663 wintitle = wintitle,
663 wintitle = wintitle,
664 widthplot = self.WIDTH + self.WIDTHPROF,
664 widthplot = self.WIDTH + self.WIDTHPROF,
665 heightplot = self.HEIGHT + self.HEIGHTPROF,
665 heightplot = self.HEIGHT + self.HEIGHTPROF,
666 show=True)
666 show=True)
667
667
668 nrow, ncol = self.getSubplots()
668 nrow, ncol = self.getSubplots()
669
669
670 for y in range(nrow):
670 for y in range(nrow):
671 for x in range(ncol):
671 for x in range(ncol):
672
672
673 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
673 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
674
674
675 if showprofile:
675 if showprofile:
676 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
676 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
677
677
678 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
678 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
679 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
679 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
680 timerange=None,
680 timerange=None,
681 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
681 save=False, figpath='', figfile=None, ftp=False, wr_period=1,
682 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
682 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
683 server=None, folder=None, username=None, password=None,
683 server=None, folder=None, username=None, password=None,
684 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
684 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
685
685
686 if pairsList == None:
686 if pairsList == None:
687 pairsIndexList = dataOut.pairsIndexList
687 pairsIndexList = dataOut.pairsIndexList
688 else:
688 else:
689 pairsIndexList = []
689 pairsIndexList = []
690 for pair in pairsList:
690 for pair in pairsList:
691 if pair not in dataOut.pairsList:
691 if pair not in dataOut.pairsList:
692 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
692 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
693 pairsIndexList.append(dataOut.pairsList.index(pair))
693 pairsIndexList.append(dataOut.pairsList.index(pair))
694
694
695 if timerange != None:
695 if timerange != None:
696 self.timerange = timerange
696 self.timerange = timerange
697
697
698 if pairsIndexList == []:
698 if pairsIndexList == []:
699 return
699 return
700
700
701 if len(pairsIndexList) > 4:
701 if len(pairsIndexList) > 4:
702 pairsIndexList = pairsIndexList[0:4]
702 pairsIndexList = pairsIndexList[0:4]
703
703
704 # tmin = None
704 # tmin = None
705 # tmax = None
705 # tmax = None
706 x = dataOut.getTimeRange()
706 x = dataOut.getTimeRange()
707 y = dataOut.getHeiRange()
707 y = dataOut.getHeiRange()
708
708
709 #thisDatetime = dataOut.datatime
709 #thisDatetime = dataOut.datatime
710 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
710 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
711 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
711 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
712 xlabel = ""
712 xlabel = ""
713 ylabel = "Range (Km)"
713 ylabel = "Range (Km)"
714
714
715 if not self.isConfig:
715 if not self.isConfig:
716 nplots = len(pairsIndexList)
716 nplots = len(pairsIndexList)
717 self.setup(id=id,
717 self.setup(id=id,
718 nplots=nplots,
718 nplots=nplots,
719 wintitle=wintitle,
719 wintitle=wintitle,
720 showprofile=showprofile,
720 showprofile=showprofile,
721 show=show)
721 show=show)
722
722
723 #tmin, tmax = self.getTimeLim(x, xmin, xmax)
723 #tmin, tmax = self.getTimeLim(x, xmin, xmax)
724
724
725 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
725 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
726
726
727 if ymin == None: ymin = numpy.nanmin(y)
727 if ymin == None: ymin = numpy.nanmin(y)
728 if ymax == None: ymax = numpy.nanmax(y)
728 if ymax == None: ymax = numpy.nanmax(y)
729 if zmin == None: zmin = 0.
729 if zmin == None: zmin = 0.
730 if zmax == None: zmax = 1.
730 if zmax == None: zmax = 1.
731
731
732 self.FTP_WEI = ftp_wei
732 self.FTP_WEI = ftp_wei
733 self.EXP_CODE = exp_code
733 self.EXP_CODE = exp_code
734 self.SUB_EXP_CODE = sub_exp_code
734 self.SUB_EXP_CODE = sub_exp_code
735 self.PLOT_POS = plot_pos
735 self.PLOT_POS = plot_pos
736
736
737 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
737 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
738
738
739 self.isConfig = True
739 self.isConfig = True
740
740
741 self.setWinTitle(title)
741 self.setWinTitle(title)
742
742
743 if ((self.xmax - x[1]) < (x[1]-x[0])):
743 if ((self.xmax - x[1]) < (x[1]-x[0])):
744 x[1] = self.xmax
744 x[1] = self.xmax
745
745
746 for i in range(self.nplots):
746 for i in range(self.nplots):
747
747
748 pair = dataOut.pairsList[pairsIndexList[i]]
748 pair = dataOut.pairsList[pairsIndexList[i]]
749
749
750 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
750 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
751 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
751 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
752 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
752 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
753
753
754
754
755 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
755 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
756 coherence = numpy.abs(avgcoherenceComplex)
756 coherence = numpy.abs(avgcoherenceComplex)
757
757
758 z = coherence.reshape((1,-1))
758 z = coherence.reshape((1,-1))
759
759
760 counter = 0
760 counter = 0
761
761
762 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
762 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
763 axes = self.axesList[i*self.__nsubplots*2]
763 axes = self.axesList[i*self.__nsubplots*2]
764 axes.pcolorbuffer(x, y, z,
764 axes.pcolorbuffer(x, y, z,
765 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
765 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
766 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
766 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
767 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
767 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
768
768
769 if self.__showprofile:
769 if self.__showprofile:
770 counter += 1
770 counter += 1
771 axes = self.axesList[i*self.__nsubplots*2 + counter]
771 axes = self.axesList[i*self.__nsubplots*2 + counter]
772 axes.pline(coherence, y,
772 axes.pline(coherence, y,
773 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
773 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
774 xlabel='', ylabel='', title='', ticksize=7,
774 xlabel='', ylabel='', title='', ticksize=7,
775 ytick_visible=False, nxticks=5,
775 ytick_visible=False, nxticks=5,
776 grid='x')
776 grid='x')
777
777
778 counter += 1
778 counter += 1
779
779
780 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
780 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
781
781
782 z = phase.reshape((1,-1))
782 z = phase.reshape((1,-1))
783
783
784 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
784 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
785 axes = self.axesList[i*self.__nsubplots*2 + counter]
785 axes = self.axesList[i*self.__nsubplots*2 + counter]
786 axes.pcolorbuffer(x, y, z,
786 axes.pcolorbuffer(x, y, z,
787 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
787 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
788 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
788 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
789 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
789 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
790
790
791 if self.__showprofile:
791 if self.__showprofile:
792 counter += 1
792 counter += 1
793 axes = self.axesList[i*self.__nsubplots*2 + counter]
793 axes = self.axesList[i*self.__nsubplots*2 + counter]
794 axes.pline(phase, y,
794 axes.pline(phase, y,
795 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
795 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
796 xlabel='', ylabel='', title='', ticksize=7,
796 xlabel='', ylabel='', title='', ticksize=7,
797 ytick_visible=False, nxticks=4,
797 ytick_visible=False, nxticks=4,
798 grid='x')
798 grid='x')
799
799
800 self.draw()
800 self.draw()
801
801
802 if x[1] >= self.axesList[0].xmax:
802 if x[1] >= self.axesList[0].xmax:
803 self.counter_imagwr = wr_period
803 self.counter_imagwr = wr_period
804 self.__isConfig = False
804 self.__isConfig = False
805
805
806 if figfile == None:
806 if figfile == None:
807 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
807 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
808 figfile = self.getFilename(name = str_datetime)
808 figfile = self.getFilename(name = str_datetime)
809
809
810 if figpath != '':
810 if figpath != '':
811
811
812 self.counter_imagwr += 1
812 self.counter_imagwr += 1
813 if (self.counter_imagwr>=wr_period):
813 if (self.counter_imagwr>=wr_period):
814 # store png plot to local folder
814 # store png plot to local folder
815 self.saveFigure(figpath, figfile)
815 self.saveFigure(figpath, figfile)
816 # store png plot to FTP server according to RT-Web format
816 # store png plot to FTP server according to RT-Web format
817 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
817 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
818 ftp_filename = os.path.join(figpath, name)
818 ftp_filename = os.path.join(figpath, name)
819 self.saveFigure(figpath, ftp_filename)
819 self.saveFigure(figpath, ftp_filename)
820
820
821 self.counter_imagwr = 0
821 self.counter_imagwr = 0
822
822
823 class PowerProfile(Figure):
823 class PowerProfile(Figure):
824 isConfig = None
824 isConfig = None
825 __nsubplots = None
825 __nsubplots = None
826
826
827 WIDTHPROF = None
827 WIDTHPROF = None
828 HEIGHTPROF = None
828 HEIGHTPROF = None
829 PREFIX = 'spcprofile'
829 PREFIX = 'spcprofile'
830
830
831 def __init__(self):
831 def __init__(self):
832 self.isConfig = False
832 self.isConfig = False
833 self.__nsubplots = 1
833 self.__nsubplots = 1
834
834
835 self.WIDTH = 300
835 self.WIDTH = 300
836 self.HEIGHT = 500
836 self.HEIGHT = 500
837 self.counter_imagwr = 0
837 self.counter_imagwr = 0
838
838
839 def getSubplots(self):
839 def getSubplots(self):
840 ncol = 1
840 ncol = 1
841 nrow = 1
841 nrow = 1
842
842
843 return nrow, ncol
843 return nrow, ncol
844
844
845 def setup(self, id, nplots, wintitle, show):
845 def setup(self, id, nplots, wintitle, show):
846
846
847 self.nplots = nplots
847 self.nplots = nplots
848
848
849 ncolspan = 1
849 ncolspan = 1
850 colspan = 1
850 colspan = 1
851
851
852 self.createFigure(id = id,
852 self.createFigure(id = id,
853 wintitle = wintitle,
853 wintitle = wintitle,
854 widthplot = self.WIDTH,
854 widthplot = self.WIDTH,
855 heightplot = self.HEIGHT,
855 heightplot = self.HEIGHT,
856 show=show)
856 show=show)
857
857
858 nrow, ncol = self.getSubplots()
858 nrow, ncol = self.getSubplots()
859
859
860 counter = 0
860 counter = 0
861 for y in range(nrow):
861 for y in range(nrow):
862 for x in range(ncol):
862 for x in range(ncol):
863 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
863 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
864
864
865 def run(self, dataOut, id, wintitle="", channelList=None,
865 def run(self, dataOut, id, wintitle="", channelList=None,
866 xmin=None, xmax=None, ymin=None, ymax=None,
866 xmin=None, xmax=None, ymin=None, ymax=None,
867 save=False, figpath='./', figfile=None, show=True, wr_period=1,
867 save=False, figpath='', figfile=None, show=True, wr_period=1,
868 server=None, folder=None, username=None, password=None,):
868 server=None, folder=None, username=None, password=None,):
869
869
870 if dataOut.flagNoData:
870 if dataOut.flagNoData:
871 return None
871 return None
872
872
873 if channelList == None:
873 if channelList == None:
874 channelIndexList = dataOut.channelIndexList
874 channelIndexList = dataOut.channelIndexList
875 channelList = dataOut.channelList
875 channelList = dataOut.channelList
876 else:
876 else:
877 channelIndexList = []
877 channelIndexList = []
878 for channel in channelList:
878 for channel in channelList:
879 if channel not in dataOut.channelList:
879 if channel not in dataOut.channelList:
880 raise ValueError, "Channel %d is not in dataOut.channelList"
880 raise ValueError, "Channel %d is not in dataOut.channelList"
881 channelIndexList.append(dataOut.channelList.index(channel))
881 channelIndexList.append(dataOut.channelList.index(channel))
882
882
883 try:
883 try:
884 factor = dataOut.normFactor
884 factor = dataOut.normFactor
885 except:
885 except:
886 factor = 1
886 factor = 1
887
887
888 y = dataOut.getHeiRange()
888 y = dataOut.getHeiRange()
889
889
890 #for voltage
890 #for voltage
891 if dataOut.type == 'Voltage':
891 if dataOut.type == 'Voltage':
892 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
892 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
893 x = x.real
893 x = x.real
894 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
894 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
895
895
896 #for spectra
896 #for spectra
897 if dataOut.type == 'Spectra':
897 if dataOut.type == 'Spectra':
898 x = dataOut.data_spc[channelIndexList,:,:]/factor
898 x = dataOut.data_spc[channelIndexList,:,:]/factor
899 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
899 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
900 x = numpy.average(x, axis=1)
900 x = numpy.average(x, axis=1)
901
901
902
902
903 xdB = 10*numpy.log10(x)
903 xdB = 10*numpy.log10(x)
904
904
905 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
905 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
906 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
906 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
907 xlabel = "dB"
907 xlabel = "dB"
908 ylabel = "Range (Km)"
908 ylabel = "Range (Km)"
909
909
910 if not self.isConfig:
910 if not self.isConfig:
911
911
912 nplots = 1
912 nplots = 1
913
913
914 self.setup(id=id,
914 self.setup(id=id,
915 nplots=nplots,
915 nplots=nplots,
916 wintitle=wintitle,
916 wintitle=wintitle,
917 show=show)
917 show=show)
918
918
919 if ymin == None: ymin = numpy.nanmin(y)
919 if ymin == None: ymin = numpy.nanmin(y)
920 if ymax == None: ymax = numpy.nanmax(y)
920 if ymax == None: ymax = numpy.nanmax(y)
921 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
921 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
922 if xmax == None: xmax = numpy.nanmax(xdB)*0.9
922 if xmax == None: xmax = numpy.nanmax(xdB)*0.9
923
923
924 self.__isConfig = True
924 self.__isConfig = True
925
925
926 self.setWinTitle(title)
926 self.setWinTitle(title)
927
927
928 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
928 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
929 axes = self.axesList[0]
929 axes = self.axesList[0]
930
930
931 legendlabels = ["channel %d"%x for x in channelList]
931 legendlabels = ["channel %d"%x for x in channelList]
932 axes.pmultiline(xdB, y,
932 axes.pmultiline(xdB, y,
933 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
933 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
934 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
934 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
935 ytick_visible=True, nxticks=5,
935 ytick_visible=True, nxticks=5,
936 grid='x')
936 grid='x')
937
937
938 self.draw()
938 self.draw()
939
939
940 if save:
940 if save:
941 date = thisDatetime.strftime("%Y%m%d")
941 date = thisDatetime.strftime("%Y%m%d")
942 if figfile == None:
942 if figfile == None:
943 figfile = self.getFilename(name = date)
943 figfile = self.getFilename(name = date)
944
944
945 self.saveFigure(figpath, figfile)
945 self.saveFigure(figpath, figfile)
946
946
947 self.counter_imagwr += 1
947 self.counter_imagwr += 1
948 if (ftp and (self.counter_imagwr==wr_period)):
948 if (ftp and (self.counter_imagwr==wr_period)):
949 ftp_filename = os.path.join(figpath,figfile)
949 ftp_filename = os.path.join(figpath,figfile)
950 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
950 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
951 self.counter_imagwr = 0
951 self.counter_imagwr = 0
952
952
953 class Noise(Figure):
953 class Noise(Figure):
954
954
955 isConfig = None
955 isConfig = None
956 __nsubplots = None
956 __nsubplots = None
957
957
958 PREFIX = 'noise'
958 PREFIX = 'noise'
959
959
960 def __init__(self):
960 def __init__(self):
961
961
962 self.timerange = 24*60*60
962 self.timerange = 24*60*60
963 self.isConfig = False
963 self.isConfig = False
964 self.__nsubplots = 1
964 self.__nsubplots = 1
965 self.counter_imagwr = 0
965 self.counter_imagwr = 0
966 self.WIDTH = 600
966 self.WIDTH = 600
967 self.HEIGHT = 300
967 self.HEIGHT = 300
968 self.WIDTHPROF = 120
968 self.WIDTHPROF = 120
969 self.HEIGHTPROF = 0
969 self.HEIGHTPROF = 0
970 self.xdata = None
970 self.xdata = None
971 self.ydata = None
971 self.ydata = None
972
972
973 self.PLOT_CODE = 77
973 self.PLOT_CODE = 77
974 self.FTP_WEI = None
974 self.FTP_WEI = None
975 self.EXP_CODE = None
975 self.EXP_CODE = None
976 self.SUB_EXP_CODE = None
976 self.SUB_EXP_CODE = None
977 self.PLOT_POS = None
977 self.PLOT_POS = None
978
978
979 def getSubplots(self):
979 def getSubplots(self):
980
980
981 ncol = 1
981 ncol = 1
982 nrow = 1
982 nrow = 1
983
983
984 return nrow, ncol
984 return nrow, ncol
985
985
986 def openfile(self, filename):
986 def openfile(self, filename):
987 f = open(filename,'w+')
987 f = open(filename,'w+')
988 f.write('\n\n')
988 f.write('\n\n')
989 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
989 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
990 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
990 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
991 f.close()
991 f.close()
992
992
993 def save_data(self, filename_phase, data, data_datetime):
993 def save_data(self, filename_phase, data, data_datetime):
994 f=open(filename_phase,'a')
994 f=open(filename_phase,'a')
995 timetuple_data = data_datetime.timetuple()
995 timetuple_data = data_datetime.timetuple()
996 day = str(timetuple_data.tm_mday)
996 day = str(timetuple_data.tm_mday)
997 month = str(timetuple_data.tm_mon)
997 month = str(timetuple_data.tm_mon)
998 year = str(timetuple_data.tm_year)
998 year = str(timetuple_data.tm_year)
999 hour = str(timetuple_data.tm_hour)
999 hour = str(timetuple_data.tm_hour)
1000 minute = str(timetuple_data.tm_min)
1000 minute = str(timetuple_data.tm_min)
1001 second = str(timetuple_data.tm_sec)
1001 second = str(timetuple_data.tm_sec)
1002 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1002 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1003 f.close()
1003 f.close()
1004
1004
1005
1005
1006 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1006 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1007
1007
1008 self.__showprofile = showprofile
1008 self.__showprofile = showprofile
1009 self.nplots = nplots
1009 self.nplots = nplots
1010
1010
1011 ncolspan = 7
1011 ncolspan = 7
1012 colspan = 6
1012 colspan = 6
1013 self.__nsubplots = 2
1013 self.__nsubplots = 2
1014
1014
1015 self.createFigure(id = id,
1015 self.createFigure(id = id,
1016 wintitle = wintitle,
1016 wintitle = wintitle,
1017 widthplot = self.WIDTH+self.WIDTHPROF,
1017 widthplot = self.WIDTH+self.WIDTHPROF,
1018 heightplot = self.HEIGHT+self.HEIGHTPROF,
1018 heightplot = self.HEIGHT+self.HEIGHTPROF,
1019 show=show)
1019 show=show)
1020
1020
1021 nrow, ncol = self.getSubplots()
1021 nrow, ncol = self.getSubplots()
1022
1022
1023 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1023 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1024
1024
1025
1025
1026 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1026 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1027 xmin=None, xmax=None, ymin=None, ymax=None,
1027 xmin=None, xmax=None, ymin=None, ymax=None,
1028 timerange=None,
1028 timerange=None,
1029 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1029 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1030 server=None, folder=None, username=None, password=None,
1030 server=None, folder=None, username=None, password=None,
1031 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1031 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1032
1032
1033 if channelList == None:
1033 if channelList == None:
1034 channelIndexList = dataOut.channelIndexList
1034 channelIndexList = dataOut.channelIndexList
1035 channelList = dataOut.channelList
1035 channelList = dataOut.channelList
1036 else:
1036 else:
1037 channelIndexList = []
1037 channelIndexList = []
1038 for channel in channelList:
1038 for channel in channelList:
1039 if channel not in dataOut.channelList:
1039 if channel not in dataOut.channelList:
1040 raise ValueError, "Channel %d is not in dataOut.channelList"
1040 raise ValueError, "Channel %d is not in dataOut.channelList"
1041 channelIndexList.append(dataOut.channelList.index(channel))
1041 channelIndexList.append(dataOut.channelList.index(channel))
1042
1042
1043 if timerange != None:
1043 if timerange != None:
1044 self.timerange = timerange
1044 self.timerange = timerange
1045
1045
1046 tmin = None
1046 tmin = None
1047 tmax = None
1047 tmax = None
1048 x = dataOut.getTimeRange()
1048 x = dataOut.getTimeRange()
1049 y = dataOut.getHeiRange()
1049 y = dataOut.getHeiRange()
1050 factor = dataOut.normFactor
1050 factor = dataOut.normFactor
1051 noise = dataOut.noise()/factor
1051 noise = dataOut.noise()/factor
1052 noisedB = 10*numpy.log10(noise)
1052 noisedB = 10*numpy.log10(noise)
1053
1053
1054 #thisDatetime = dataOut.datatime
1054 #thisDatetime = dataOut.datatime
1055 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1055 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1056 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1056 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1057 xlabel = ""
1057 xlabel = ""
1058 ylabel = "Intensity (dB)"
1058 ylabel = "Intensity (dB)"
1059
1059
1060 if not self.isConfig:
1060 if not self.isConfig:
1061
1061
1062 nplots = 1
1062 nplots = 1
1063
1063
1064 self.setup(id=id,
1064 self.setup(id=id,
1065 nplots=nplots,
1065 nplots=nplots,
1066 wintitle=wintitle,
1066 wintitle=wintitle,
1067 showprofile=showprofile,
1067 showprofile=showprofile,
1068 show=show)
1068 show=show)
1069
1069
1070 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1070 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1071 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1071 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1072 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1072 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1073
1073
1074 self.FTP_WEI = ftp_wei
1074 self.FTP_WEI = ftp_wei
1075 self.EXP_CODE = exp_code
1075 self.EXP_CODE = exp_code
1076 self.SUB_EXP_CODE = sub_exp_code
1076 self.SUB_EXP_CODE = sub_exp_code
1077 self.PLOT_POS = plot_pos
1077 self.PLOT_POS = plot_pos
1078
1078
1079
1079
1080 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1080 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1081 self.isConfig = True
1081 self.isConfig = True
1082
1082
1083 self.xdata = numpy.array([])
1083 self.xdata = numpy.array([])
1084 self.ydata = numpy.array([])
1084 self.ydata = numpy.array([])
1085
1085
1086 #open file beacon phase
1086 #open file beacon phase
1087 path = '%s%03d' %(self.PREFIX, self.id)
1087 path = '%s%03d' %(self.PREFIX, self.id)
1088 noise_file = os.path.join(path,'%s.txt'%self.name)
1088 noise_file = os.path.join(path,'%s.txt'%self.name)
1089 self.filename_noise = os.path.join(figpath,noise_file)
1089 self.filename_noise = os.path.join(figpath,noise_file)
1090 self.openfile(self.filename_noise)
1090 self.openfile(self.filename_noise)
1091
1091
1092
1092
1093 #store data beacon phase
1093 #store data beacon phase
1094 self.save_data(self.filename_noise, noisedB, thisDatetime)
1094 self.save_data(self.filename_noise, noisedB, thisDatetime)
1095
1095
1096
1096
1097 self.setWinTitle(title)
1097 self.setWinTitle(title)
1098
1098
1099
1099
1100 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1100 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1101
1101
1102 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1102 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1103 axes = self.axesList[0]
1103 axes = self.axesList[0]
1104
1104
1105 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1105 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1106
1106
1107 if len(self.ydata)==0:
1107 if len(self.ydata)==0:
1108 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1108 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1109 else:
1109 else:
1110 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1110 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1111
1111
1112
1112
1113 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1113 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1114 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1114 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1115 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1115 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1116 XAxisAsTime=True, grid='both'
1116 XAxisAsTime=True, grid='both'
1117 )
1117 )
1118
1118
1119 self.draw()
1119 self.draw()
1120
1120
1121 # if save:
1121 # if save:
1122 #
1122 #
1123 # if figfile == None:
1123 # if figfile == None:
1124 # figfile = self.getFilename(name = self.name)
1124 # figfile = self.getFilename(name = self.name)
1125 #
1125 #
1126 # self.saveFigure(figpath, figfile)
1126 # self.saveFigure(figpath, figfile)
1127
1127
1128 if save:
1128 if save:
1129
1129
1130 self.counter_imagwr += 1
1130 self.counter_imagwr += 1
1131 if (self.counter_imagwr==wr_period):
1131 if (self.counter_imagwr==wr_period):
1132 if figfile == None:
1132 if figfile == None:
1133 figfile = self.getFilename(name = self.name)
1133 figfile = self.getFilename(name = self.name)
1134 self.saveFigure(figpath, figfile)
1134 self.saveFigure(figpath, figfile)
1135
1135
1136 if ftp:
1136 if ftp:
1137 #provisionalmente envia archivos en el formato de la web en tiempo real
1137 #provisionalmente envia archivos en el formato de la web en tiempo real
1138 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1138 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1139 path = '%s%03d' %(self.PREFIX, self.id)
1139 path = '%s%03d' %(self.PREFIX, self.id)
1140 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1140 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1141 self.saveFigure(figpath, ftp_file)
1141 self.saveFigure(figpath, ftp_file)
1142 ftp_filename = os.path.join(figpath,ftp_file)
1142 ftp_filename = os.path.join(figpath,ftp_file)
1143 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1143 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1144 self.counter_imagwr = 0
1144 self.counter_imagwr = 0
1145
1145
1146 self.counter_imagwr = 0
1146 self.counter_imagwr = 0
1147
1147
1148 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1148 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1149 self.isConfig = False
1149 self.isConfig = False
1150 del self.xdata
1150 del self.xdata
1151 del self.ydata
1151 del self.ydata
General Comments 0
You need to be logged in to leave comments. Login now