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