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