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