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