##// END OF EJS Templates
Se restrige el numero de pares a graficar en Cross-Spectra....
Miguel Valdez -
r228:1fb3505cb0b4
parent child
Show More
@@ -1,589 +1,592
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 WIDTHPROF = None
10 WIDTHPROF = None
11 HEIGHTPROF = None
11 HEIGHTPROF = None
12 PREFIX = 'spc'
12 PREFIX = 'cspc'
13
13
14 def __init__(self):
14 def __init__(self):
15
15
16 self.__isConfig = False
16 self.__isConfig = False
17 self.__nsubplots = 4
17 self.__nsubplots = 4
18
18
19 self.WIDTH = 300
19 self.WIDTH = 300
20 self.HEIGHT = 400
20 self.HEIGHT = 400
21 self.WIDTHPROF = 0
21 self.WIDTHPROF = 0
22 self.HEIGHTPROF = 0
22 self.HEIGHTPROF = 0
23
23
24 def getSubplots(self):
24 def getSubplots(self):
25
25
26 ncol = 4
26 ncol = 4
27 nrow = self.nplots
27 nrow = self.nplots
28
28
29 return nrow, ncol
29 return nrow, ncol
30
30
31 def setup(self, idfigure, nplots, wintitle, showprofile=True):
31 def setup(self, idfigure, nplots, wintitle, showprofile=True):
32
32
33 self.__showprofile = showprofile
33 self.__showprofile = showprofile
34 self.nplots = nplots
34 self.nplots = nplots
35
35
36 ncolspan = 1
36 ncolspan = 1
37 colspan = 1
37 colspan = 1
38
38
39 self.createFigure(idfigure = idfigure,
39 self.createFigure(idfigure = idfigure,
40 wintitle = wintitle,
40 wintitle = wintitle,
41 widthplot = self.WIDTH + self.WIDTHPROF,
41 widthplot = self.WIDTH + self.WIDTHPROF,
42 heightplot = self.HEIGHT + self.HEIGHTPROF)
42 heightplot = self.HEIGHT + self.HEIGHTPROF)
43
43
44 nrow, ncol = self.getSubplots()
44 nrow, ncol = self.getSubplots()
45
45
46 counter = 0
46 counter = 0
47 for y in range(nrow):
47 for y in range(nrow):
48 for x in range(ncol):
48 for x in range(ncol):
49 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
49 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
50
50
51 counter += 1
51 counter += 1
52
52
53 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
53 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
54 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
54 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
55 save=False, figpath='./', figfile=None):
55 save=False, figpath='./', figfile=None):
56
56
57 """
57 """
58
58
59 Input:
59 Input:
60 dataOut :
60 dataOut :
61 idfigure :
61 idfigure :
62 wintitle :
62 wintitle :
63 channelList :
63 channelList :
64 showProfile :
64 showProfile :
65 xmin : None,
65 xmin : None,
66 xmax : None,
66 xmax : None,
67 ymin : None,
67 ymin : None,
68 ymax : None,
68 ymax : None,
69 zmin : None,
69 zmin : None,
70 zmax : None
70 zmax : None
71 """
71 """
72
72
73 if pairsList == None:
73 if pairsList == None:
74 pairsIndexList = dataOut.pairsIndexList
74 pairsIndexList = dataOut.pairsIndexList
75 else:
75 else:
76 pairsIndexList = []
76 pairsIndexList = []
77 for pair in pairsList:
77 for pair in pairsList:
78 if pair not in dataOut.pairsList:
78 if pair not in dataOut.pairsList:
79 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
79 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
80 pairsIndexList.append(dataOut.pairsList.index(pair))
80 pairsIndexList.append(dataOut.pairsList.index(pair))
81
81
82 if pairsIndexList == []:
82 if pairsIndexList == []:
83 return
83 return
84
84
85 if len(pairsIndexList) > 4:
86 pairsIndexList = pairsIndexList[0:4]
87
85 x = dataOut.getFreqRange(1)
88 x = dataOut.getFreqRange(1)
86 y = dataOut.getHeiRange()
89 y = dataOut.getHeiRange()
87 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
90 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
88 avg = numpy.average(numpy.abs(z), axis=1)
91 avg = numpy.average(numpy.abs(z), axis=1)
89
92
90 noise = dataOut.getNoise()
93 noise = dataOut.getNoise()
91
94
92 if not self.__isConfig:
95 if not self.__isConfig:
93
96
94 nplots = len(pairsIndexList)
97 nplots = len(pairsIndexList)
95
98
96 self.setup(idfigure=idfigure,
99 self.setup(idfigure=idfigure,
97 nplots=nplots,
100 nplots=nplots,
98 wintitle=wintitle,
101 wintitle=wintitle,
99 showprofile=showprofile)
102 showprofile=showprofile)
100
103
101 if xmin == None: xmin = numpy.nanmin(x)
104 if xmin == None: xmin = numpy.nanmin(x)
102 if xmax == None: xmax = numpy.nanmax(x)
105 if xmax == None: xmax = numpy.nanmax(x)
103 if ymin == None: ymin = numpy.nanmin(y)
106 if ymin == None: ymin = numpy.nanmin(y)
104 if ymax == None: ymax = numpy.nanmax(y)
107 if ymax == None: ymax = numpy.nanmax(y)
105 if zmin == None: zmin = numpy.nanmin(avg)*0.9
108 if zmin == None: zmin = numpy.nanmin(avg)*0.9
106 if zmax == None: zmax = numpy.nanmax(avg)*0.9
109 if zmax == None: zmax = numpy.nanmax(avg)*0.9
107
110
108 self.__isConfig = True
111 self.__isConfig = True
109
112
110 thisDatetime = dataOut.datatime
113 thisDatetime = dataOut.datatime
111 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
114 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
112 xlabel = "Velocity (m/s)"
115 xlabel = "Velocity (m/s)"
113 ylabel = "Range (Km)"
116 ylabel = "Range (Km)"
114
117
115 self.setWinTitle(title)
118 self.setWinTitle(title)
116
119
117 for i in range(self.nplots):
120 for i in range(self.nplots):
118 pair = dataOut.pairsList[pairsIndexList[i]]
121 pair = dataOut.pairsList[pairsIndexList[i]]
119
122
120 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
123 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
121 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
124 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
122 axes0 = self.axesList[i*self.__nsubplots]
125 axes0 = self.axesList[i*self.__nsubplots]
123 axes0.pcolor(x, y, z,
126 axes0.pcolor(x, y, z,
124 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
127 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
125 xlabel=xlabel, ylabel=ylabel, title=title,
128 xlabel=xlabel, ylabel=ylabel, title=title,
126 ticksize=9, cblabel='')
129 ticksize=9, cblabel='')
127
130
128 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
131 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
129 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
132 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
130 axes0 = self.axesList[i*self.__nsubplots+1]
133 axes0 = self.axesList[i*self.__nsubplots+1]
131 axes0.pcolor(x, y, z,
134 axes0.pcolor(x, y, z,
132 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,
133 xlabel=xlabel, ylabel=ylabel, title=title,
136 xlabel=xlabel, ylabel=ylabel, title=title,
134 ticksize=9, cblabel='')
137 ticksize=9, cblabel='')
135
138
136 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
139 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
137 coherence = numpy.abs(coherenceComplex)
140 coherence = numpy.abs(coherenceComplex)
138 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
141 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
139
142
140
143
141 title = "Coherence %d%d" %(pair[0], pair[1])
144 title = "Coherence %d%d" %(pair[0], pair[1])
142 axes0 = self.axesList[i*self.__nsubplots+2]
145 axes0 = self.axesList[i*self.__nsubplots+2]
143 axes0.pcolor(x, y, coherence,
146 axes0.pcolor(x, y, coherence,
144 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
147 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
145 xlabel=xlabel, ylabel=ylabel, title=title,
148 xlabel=xlabel, ylabel=ylabel, title=title,
146 ticksize=9, cblabel='')
149 ticksize=9, cblabel='')
147
150
148 title = "Phase %d%d" %(pair[0], pair[1])
151 title = "Phase %d%d" %(pair[0], pair[1])
149 axes0 = self.axesList[i*self.__nsubplots+3]
152 axes0 = self.axesList[i*self.__nsubplots+3]
150 axes0.pcolor(x, y, phase,
153 axes0.pcolor(x, y, phase,
151 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
154 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
152 xlabel=xlabel, ylabel=ylabel, title=title,
155 xlabel=xlabel, ylabel=ylabel, title=title,
153 ticksize=9, cblabel='', colormap='RdBu')
156 ticksize=9, cblabel='', colormap='RdBu')
154
157
155
158
156
159
157 self.draw()
160 self.draw()
158
161
159 if save:
162 if save:
160 date = thisDatetime.strftime("%Y%m%d")
163 date = thisDatetime.strftime("%Y%m%d")
161 if figfile == None:
164 if figfile == None:
162 figfile = self.getFilename(name = date)
165 figfile = self.getFilename(name = date)
163
166
164 self.saveFigure(figpath, figfile)
167 self.saveFigure(figpath, figfile)
165
168
166
169
167 class RTIPlot(Figure):
170 class RTIPlot(Figure):
168
171
169 __isConfig = None
172 __isConfig = None
170 __nsubplots = None
173 __nsubplots = None
171
174
172 WIDTHPROF = None
175 WIDTHPROF = None
173 HEIGHTPROF = None
176 HEIGHTPROF = None
174 PREFIX = 'rti'
177 PREFIX = 'rti'
175
178
176 def __init__(self):
179 def __init__(self):
177
180
178 self.__timerange = 24*60*60
181 self.__timerange = 24*60*60
179 self.__isConfig = False
182 self.__isConfig = False
180 self.__nsubplots = 1
183 self.__nsubplots = 1
181
184
182 self.WIDTH = 800
185 self.WIDTH = 800
183 self.HEIGHT = 200
186 self.HEIGHT = 200
184 self.WIDTHPROF = 120
187 self.WIDTHPROF = 120
185 self.HEIGHTPROF = 0
188 self.HEIGHTPROF = 0
186
189
187 def getSubplots(self):
190 def getSubplots(self):
188
191
189 ncol = 1
192 ncol = 1
190 nrow = self.nplots
193 nrow = self.nplots
191
194
192 return nrow, ncol
195 return nrow, ncol
193
196
194 def setup(self, idfigure, nplots, wintitle, showprofile=True):
197 def setup(self, idfigure, nplots, wintitle, showprofile=True):
195
198
196 self.__showprofile = showprofile
199 self.__showprofile = showprofile
197 self.nplots = nplots
200 self.nplots = nplots
198
201
199 ncolspan = 1
202 ncolspan = 1
200 colspan = 1
203 colspan = 1
201 if showprofile:
204 if showprofile:
202 ncolspan = 7
205 ncolspan = 7
203 colspan = 6
206 colspan = 6
204 self.__nsubplots = 2
207 self.__nsubplots = 2
205
208
206 self.createFigure(idfigure = idfigure,
209 self.createFigure(idfigure = idfigure,
207 wintitle = wintitle,
210 wintitle = wintitle,
208 widthplot = self.WIDTH + self.WIDTHPROF,
211 widthplot = self.WIDTH + self.WIDTHPROF,
209 heightplot = self.HEIGHT + self.HEIGHTPROF)
212 heightplot = self.HEIGHT + self.HEIGHTPROF)
210
213
211 nrow, ncol = self.getSubplots()
214 nrow, ncol = self.getSubplots()
212
215
213 counter = 0
216 counter = 0
214 for y in range(nrow):
217 for y in range(nrow):
215 for x in range(ncol):
218 for x in range(ncol):
216
219
217 if counter >= self.nplots:
220 if counter >= self.nplots:
218 break
221 break
219
222
220 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
223 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
221
224
222 if showprofile:
225 if showprofile:
223 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
226 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
224
227
225 counter += 1
228 counter += 1
226
229
227 def __getTimeLim(self, x, xmin, xmax):
230 def __getTimeLim(self, x, xmin, xmax):
228
231
229 thisdatetime = datetime.datetime.utcfromtimestamp(numpy.min(x))
232 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
230 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
233 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
231
234
232 ####################################################
235 ####################################################
233 #If the x is out of xrange
236 #If the x is out of xrange
234 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
237 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
235 xmin = None
238 xmin = None
236 xmax = None
239 xmax = None
237
240
238 if xmin == None:
241 if xmin == None:
239 td = thisdatetime - thisdate
242 td = thisdatetime - thisdate
240 xmin = td.seconds/(60*60.)
243 xmin = td.seconds/(60*60.)
241
244
242 if xmax == None:
245 if xmax == None:
243 xmax = xmin + self.__timerange/(60*60.)
246 xmax = xmin + self.__timerange/(60*60.)
244
247
245 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
248 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
246 tmin = time.mktime(mindt.timetuple())
249 tmin = time.mktime(mindt.timetuple())
247
250
248 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
251 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
249 tmax = time.mktime(maxdt.timetuple())
252 tmax = time.mktime(maxdt.timetuple())
250
253
251 self.__timerange = tmax - tmin
254 self.__timerange = tmax - tmin
252
255
253 return tmin, tmax
256 return tmin, tmax
254
257
255 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
258 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
256 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
259 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
257 timerange=None,
260 timerange=None,
258 save=False, figpath='./', figfile=None):
261 save=False, figpath='./', figfile=None):
259
262
260 """
263 """
261
264
262 Input:
265 Input:
263 dataOut :
266 dataOut :
264 idfigure :
267 idfigure :
265 wintitle :
268 wintitle :
266 channelList :
269 channelList :
267 showProfile :
270 showProfile :
268 xmin : None,
271 xmin : None,
269 xmax : None,
272 xmax : None,
270 ymin : None,
273 ymin : None,
271 ymax : None,
274 ymax : None,
272 zmin : None,
275 zmin : None,
273 zmax : None
276 zmax : None
274 """
277 """
275
278
276 if channelList == None:
279 if channelList == None:
277 channelIndexList = dataOut.channelIndexList
280 channelIndexList = dataOut.channelIndexList
278 else:
281 else:
279 channelIndexList = []
282 channelIndexList = []
280 for channel in channelList:
283 for channel in channelList:
281 if channel not in dataOut.channelList:
284 if channel not in dataOut.channelList:
282 raise ValueError, "Channel %d is not in dataOut.channelList"
285 raise ValueError, "Channel %d is not in dataOut.channelList"
283 channelIndexList.append(dataOut.channelList.index(channel))
286 channelIndexList.append(dataOut.channelList.index(channel))
284
287
285 if timerange != None:
288 if timerange != None:
286 self.__timerange = timerange
289 self.__timerange = timerange
287
290
288 tmin = None
291 tmin = None
289 tmax = None
292 tmax = None
290 x = dataOut.getTimeRange()
293 x = dataOut.getTimeRange()
291 y = dataOut.getHeiRange()
294 y = dataOut.getHeiRange()
292 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
295 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
293 avg = numpy.average(z, axis=1)
296 avg = numpy.average(z, axis=1)
294
297
295 noise = dataOut.getNoise()
298 noise = dataOut.getNoise()
296
299
297 if not self.__isConfig:
300 if not self.__isConfig:
298
301
299 nplots = len(channelIndexList)
302 nplots = len(channelIndexList)
300
303
301 self.setup(idfigure=idfigure,
304 self.setup(idfigure=idfigure,
302 nplots=nplots,
305 nplots=nplots,
303 wintitle=wintitle,
306 wintitle=wintitle,
304 showprofile=showprofile)
307 showprofile=showprofile)
305
308
306 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
309 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
307 if ymin == None: ymin = numpy.nanmin(y)
310 if ymin == None: ymin = numpy.nanmin(y)
308 if ymax == None: ymax = numpy.nanmax(y)
311 if ymax == None: ymax = numpy.nanmax(y)
309 if zmin == None: zmin = numpy.nanmin(avg)*0.9
312 if zmin == None: zmin = numpy.nanmin(avg)*0.9
310 if zmax == None: zmax = numpy.nanmax(avg)*0.9
313 if zmax == None: zmax = numpy.nanmax(avg)*0.9
311
314
312 self.__isConfig = True
315 self.__isConfig = True
313
316
314 thisDatetime = dataOut.datatime
317 thisDatetime = dataOut.datatime
315 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
318 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
316 xlabel = "Velocity (m/s)"
319 xlabel = "Velocity (m/s)"
317 ylabel = "Range (Km)"
320 ylabel = "Range (Km)"
318
321
319 self.setWinTitle(title)
322 self.setWinTitle(title)
320
323
321 for i in range(self.nplots):
324 for i in range(self.nplots):
322 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
325 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
323 axes = self.axesList[i*self.__nsubplots]
326 axes = self.axesList[i*self.__nsubplots]
324 z = avg[i].reshape((1,-1))
327 z = avg[i].reshape((1,-1))
325 axes.pcolor(x, y, z,
328 axes.pcolor(x, y, z,
326 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
329 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
327 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
330 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
328 ticksize=9, cblabel='', cbsize="1%")
331 ticksize=9, cblabel='', cbsize="1%")
329
332
330 if self.__showprofile:
333 if self.__showprofile:
331 axes = self.axesList[i*self.__nsubplots +1]
334 axes = self.axesList[i*self.__nsubplots +1]
332 axes.pline(avg[i], y,
335 axes.pline(avg[i], y,
333 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
336 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
334 xlabel='dB', ylabel='', title='',
337 xlabel='dB', ylabel='', title='',
335 ytick_visible=False,
338 ytick_visible=False,
336 grid='x')
339 grid='x')
337
340
338 self.draw()
341 self.draw()
339
342
340 if save:
343 if save:
341 date = thisDatetime.strftime("%Y%m%d")
344 date = thisDatetime.strftime("%Y%m%d")
342 if figfile == None:
345 if figfile == None:
343 figfile = self.getFilename(name = date)
346 figfile = self.getFilename(name = date)
344
347
345 self.saveFigure(figpath, figfile)
348 self.saveFigure(figpath, figfile)
346
349
347 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
350 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
348 self.__isConfig = False
351 self.__isConfig = False
349
352
350 class SpectraPlot(Figure):
353 class SpectraPlot(Figure):
351
354
352 __isConfig = None
355 __isConfig = None
353 __nsubplots = None
356 __nsubplots = None
354
357
355 WIDTHPROF = None
358 WIDTHPROF = None
356 HEIGHTPROF = None
359 HEIGHTPROF = None
357 PREFIX = 'spc'
360 PREFIX = 'spc'
358
361
359 def __init__(self):
362 def __init__(self):
360
363
361 self.__isConfig = False
364 self.__isConfig = False
362 self.__nsubplots = 1
365 self.__nsubplots = 1
363
366
364 self.WIDTH = 300
367 self.WIDTH = 300
365 self.HEIGHT = 400
368 self.HEIGHT = 400
366 self.WIDTHPROF = 120
369 self.WIDTHPROF = 120
367 self.HEIGHTPROF = 0
370 self.HEIGHTPROF = 0
368
371
369 def getSubplots(self):
372 def getSubplots(self):
370
373
371 ncol = int(numpy.sqrt(self.nplots)+0.9)
374 ncol = int(numpy.sqrt(self.nplots)+0.9)
372 nrow = int(self.nplots*1./ncol + 0.9)
375 nrow = int(self.nplots*1./ncol + 0.9)
373
376
374 return nrow, ncol
377 return nrow, ncol
375
378
376 def setup(self, idfigure, nplots, wintitle, showprofile=True):
379 def setup(self, idfigure, nplots, wintitle, showprofile=True):
377
380
378 self.__showprofile = showprofile
381 self.__showprofile = showprofile
379 self.nplots = nplots
382 self.nplots = nplots
380
383
381 ncolspan = 1
384 ncolspan = 1
382 colspan = 1
385 colspan = 1
383 if showprofile:
386 if showprofile:
384 ncolspan = 3
387 ncolspan = 3
385 colspan = 2
388 colspan = 2
386 self.__nsubplots = 2
389 self.__nsubplots = 2
387
390
388 self.createFigure(idfigure = idfigure,
391 self.createFigure(idfigure = idfigure,
389 wintitle = wintitle,
392 wintitle = wintitle,
390 widthplot = self.WIDTH + self.WIDTHPROF,
393 widthplot = self.WIDTH + self.WIDTHPROF,
391 heightplot = self.HEIGHT + self.HEIGHTPROF)
394 heightplot = self.HEIGHT + self.HEIGHTPROF)
392
395
393 nrow, ncol = self.getSubplots()
396 nrow, ncol = self.getSubplots()
394
397
395 counter = 0
398 counter = 0
396 for y in range(nrow):
399 for y in range(nrow):
397 for x in range(ncol):
400 for x in range(ncol):
398
401
399 if counter >= self.nplots:
402 if counter >= self.nplots:
400 break
403 break
401
404
402 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
405 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
403
406
404 if showprofile:
407 if showprofile:
405 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
408 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
406
409
407 counter += 1
410 counter += 1
408
411
409 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
412 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
410 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
413 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
411 save=False, figpath='./', figfile=None):
414 save=False, figpath='./', figfile=None):
412
415
413 """
416 """
414
417
415 Input:
418 Input:
416 dataOut :
419 dataOut :
417 idfigure :
420 idfigure :
418 wintitle :
421 wintitle :
419 channelList :
422 channelList :
420 showProfile :
423 showProfile :
421 xmin : None,
424 xmin : None,
422 xmax : None,
425 xmax : None,
423 ymin : None,
426 ymin : None,
424 ymax : None,
427 ymax : None,
425 zmin : None,
428 zmin : None,
426 zmax : None
429 zmax : None
427 """
430 """
428
431
429 if channelList == None:
432 if channelList == None:
430 channelIndexList = dataOut.channelIndexList
433 channelIndexList = dataOut.channelIndexList
431 else:
434 else:
432 channelIndexList = []
435 channelIndexList = []
433 for channel in channelList:
436 for channel in channelList:
434 if channel not in dataOut.channelList:
437 if channel not in dataOut.channelList:
435 raise ValueError, "Channel %d is not in dataOut.channelList"
438 raise ValueError, "Channel %d is not in dataOut.channelList"
436 channelIndexList.append(dataOut.channelList.index(channel))
439 channelIndexList.append(dataOut.channelList.index(channel))
437
440
438 x = dataOut.getVelRange(1)
441 x = dataOut.getVelRange(1)
439 y = dataOut.getHeiRange()
442 y = dataOut.getHeiRange()
440 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
443 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
441 avg = numpy.average(z, axis=1)
444 avg = numpy.average(z, axis=1)
442
445
443 noise = dataOut.getNoise()
446 noise = dataOut.getNoise()
444
447
445 if not self.__isConfig:
448 if not self.__isConfig:
446
449
447 nplots = len(channelIndexList)
450 nplots = len(channelIndexList)
448
451
449 self.setup(idfigure=idfigure,
452 self.setup(idfigure=idfigure,
450 nplots=nplots,
453 nplots=nplots,
451 wintitle=wintitle,
454 wintitle=wintitle,
452 showprofile=showprofile)
455 showprofile=showprofile)
453
456
454 if xmin == None: xmin = numpy.nanmin(x)
457 if xmin == None: xmin = numpy.nanmin(x)
455 if xmax == None: xmax = numpy.nanmax(x)
458 if xmax == None: xmax = numpy.nanmax(x)
456 if ymin == None: ymin = numpy.nanmin(y)
459 if ymin == None: ymin = numpy.nanmin(y)
457 if ymax == None: ymax = numpy.nanmax(y)
460 if ymax == None: ymax = numpy.nanmax(y)
458 if zmin == None: zmin = numpy.nanmin(avg)*0.9
461 if zmin == None: zmin = numpy.nanmin(avg)*0.9
459 if zmax == None: zmax = numpy.nanmax(avg)*0.9
462 if zmax == None: zmax = numpy.nanmax(avg)*0.9
460
463
461 self.__isConfig = True
464 self.__isConfig = True
462
465
463 thisDatetime = dataOut.datatime
466 thisDatetime = dataOut.datatime
464 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
467 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
465 xlabel = "Velocity (m/s)"
468 xlabel = "Velocity (m/s)"
466 ylabel = "Range (Km)"
469 ylabel = "Range (Km)"
467
470
468 self.setWinTitle(title)
471 self.setWinTitle(title)
469
472
470 for i in range(self.nplots):
473 for i in range(self.nplots):
471 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
474 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
472 axes = self.axesList[i*self.__nsubplots]
475 axes = self.axesList[i*self.__nsubplots]
473 axes.pcolor(x, y, z[i,:,:],
476 axes.pcolor(x, y, z[i,:,:],
474 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
477 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
475 xlabel=xlabel, ylabel=ylabel, title=title,
478 xlabel=xlabel, ylabel=ylabel, title=title,
476 ticksize=9, cblabel='')
479 ticksize=9, cblabel='')
477
480
478 if self.__showprofile:
481 if self.__showprofile:
479 axes = self.axesList[i*self.__nsubplots +1]
482 axes = self.axesList[i*self.__nsubplots +1]
480 axes.pline(avg[i], y,
483 axes.pline(avg[i], y,
481 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
484 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
482 xlabel='dB', ylabel='', title='',
485 xlabel='dB', ylabel='', title='',
483 ytick_visible=False,
486 ytick_visible=False,
484 grid='x')
487 grid='x')
485
488
486 self.draw()
489 self.draw()
487
490
488 if save:
491 if save:
489 date = thisDatetime.strftime("%Y%m%d")
492 date = thisDatetime.strftime("%Y%m%d")
490 if figfile == None:
493 if figfile == None:
491 figfile = self.getFilename(name = date)
494 figfile = self.getFilename(name = date)
492
495
493 self.saveFigure(figpath, figfile)
496 self.saveFigure(figpath, figfile)
494
497
495 class Scope(Figure):
498 class Scope(Figure):
496
499
497 __isConfig = None
500 __isConfig = None
498
501
499 def __init__(self):
502 def __init__(self):
500
503
501 self.__isConfig = False
504 self.__isConfig = False
502 self.WIDTH = 600
505 self.WIDTH = 600
503 self.HEIGHT = 200
506 self.HEIGHT = 200
504
507
505 def getSubplots(self):
508 def getSubplots(self):
506
509
507 nrow = self.nplots
510 nrow = self.nplots
508 ncol = 3
511 ncol = 3
509 return nrow, ncol
512 return nrow, ncol
510
513
511 def setup(self, idfigure, nplots, wintitle):
514 def setup(self, idfigure, nplots, wintitle):
512
515
513 self.createFigure(idfigure, wintitle)
516 self.createFigure(idfigure, wintitle)
514
517
515 nrow,ncol = self.getSubplots()
518 nrow,ncol = self.getSubplots()
516 colspan = 3
519 colspan = 3
517 rowspan = 1
520 rowspan = 1
518
521
519 for i in range(nplots):
522 for i in range(nplots):
520 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
523 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
521
524
522 self.nplots = nplots
525 self.nplots = nplots
523
526
524 def run(self, dataOut, idfigure, wintitle="", channelList=None,
527 def run(self, dataOut, idfigure, wintitle="", channelList=None,
525 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
528 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
526
529
527 """
530 """
528
531
529 Input:
532 Input:
530 dataOut :
533 dataOut :
531 idfigure :
534 idfigure :
532 wintitle :
535 wintitle :
533 channelList :
536 channelList :
534 xmin : None,
537 xmin : None,
535 xmax : None,
538 xmax : None,
536 ymin : None,
539 ymin : None,
537 ymax : None,
540 ymax : None,
538 """
541 """
539
542
540 if channelList == None:
543 if channelList == None:
541 channelIndexList = dataOut.channelIndexList
544 channelIndexList = dataOut.channelIndexList
542 else:
545 else:
543 channelIndexList = []
546 channelIndexList = []
544 for channel in channelList:
547 for channel in channelList:
545 if channel not in dataOut.channelList:
548 if channel not in dataOut.channelList:
546 raise ValueError, "Channel %d is not in dataOut.channelList"
549 raise ValueError, "Channel %d is not in dataOut.channelList"
547 channelIndexList.append(dataOut.channelList.index(channel))
550 channelIndexList.append(dataOut.channelList.index(channel))
548
551
549 x = dataOut.heightList
552 x = dataOut.heightList
550 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
553 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
551 y = y.real
554 y = y.real
552
555
553 noise = dataOut.getNoise()
556 noise = dataOut.getNoise()
554
557
555 if not self.__isConfig:
558 if not self.__isConfig:
556 nplots = len(channelList)
559 nplots = len(channelList)
557
560
558 self.setup(idfigure=idfigure,
561 self.setup(idfigure=idfigure,
559 nplots=nplots,
562 nplots=nplots,
560 wintitle=wintitle)
563 wintitle=wintitle)
561
564
562 if xmin == None: xmin = numpy.nanmin(x)
565 if xmin == None: xmin = numpy.nanmin(x)
563 if xmax == None: xmax = numpy.nanmax(x)
566 if xmax == None: xmax = numpy.nanmax(x)
564 if ymin == None: ymin = numpy.nanmin(y)
567 if ymin == None: ymin = numpy.nanmin(y)
565 if ymax == None: ymax = numpy.nanmax(y)
568 if ymax == None: ymax = numpy.nanmax(y)
566
569
567 self.__isConfig = True
570 self.__isConfig = True
568
571
569
572
570 thisDatetime = dataOut.datatime
573 thisDatetime = dataOut.datatime
571 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
574 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
572 xlabel = "Range (Km)"
575 xlabel = "Range (Km)"
573 ylabel = "Intensity"
576 ylabel = "Intensity"
574
577
575 self.setWinTitle(title)
578 self.setWinTitle(title)
576
579
577 for i in range(len(self.axesList)):
580 for i in range(len(self.axesList)):
578 title = "Channel %d: %4.2fdB" %(i, noise[i])
581 title = "Channel %d: %4.2fdB" %(i, noise[i])
579 axes = self.axesList[i]
582 axes = self.axesList[i]
580 ychannel = y[i,:]
583 ychannel = y[i,:]
581 axes.pline(x, ychannel,
584 axes.pline(x, ychannel,
582 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
585 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
583 xlabel=xlabel, ylabel=ylabel, title=title)
586 xlabel=xlabel, ylabel=ylabel, title=title)
584
587
585 self.draw()
588 self.draw()
586
589
587 if save:
590 if save:
588 self.saveFigure(filename)
591 self.saveFigure(filename)
589 No newline at end of file
592
General Comments 0
You need to be logged in to leave comments. Login now