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