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