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