##// END OF EJS Templates
El nombre del archivo grafico esta compuesto por el titulo de la figura mas la fecha y tiempo de los datos.
Miguel Valdez -
r238:217177bd5024
parent child
Show More
@@ -1,353 +1,353
1 import os
1 import os
2 import numpy
2 import numpy
3 import time, datetime
3 import time, datetime
4 import mpldriver
4 import mpldriver
5
5
6
6
7 class Figure:
7 class Figure:
8
8
9 __driver = mpldriver
9 __driver = mpldriver
10 fig = None
10 fig = None
11
11
12 idfigure = None
12 idfigure = None
13 wintitle = None
13 wintitle = None
14 width = None
14 width = None
15 height = None
15 height = None
16 nplots = None
16 nplots = None
17 timerange = None
17 timerange = None
18
18
19 axesObjList = []
19 axesObjList = []
20
20
21 WIDTH = None
21 WIDTH = None
22 HEIGHT = None
22 HEIGHT = None
23 PREFIX = 'fig'
23 PREFIX = 'fig'
24
24
25 def __init__(self):
25 def __init__(self):
26
26
27 raise ValueError, "This method is not implemented"
27 raise ValueError, "This method is not implemented"
28
28
29 def __del__(self):
29 def __del__(self):
30
30
31 self.__driver.closeFigure()
31 self.__driver.closeFigure()
32
32
33 def getFilename(self, name, ext='.png'):
33 def getFilename(self, name, ext='.png'):
34
34
35 filename = '%s_%s%s' %(self.PREFIX, name, ext)
35 filename = '%s-%s_%s%s' %(self.wintitle[0:10], self.PREFIX, name, ext)
36
36
37 return filename
37 return filename
38
38
39 def getAxesObjList(self):
39 def getAxesObjList(self):
40
40
41 return self.axesObjList
41 return self.axesObjList
42
42
43 def getSubplots(self):
43 def getSubplots(self):
44
44
45 raise ValueError, "Abstract method: This method should be defined"
45 raise ValueError, "Abstract method: This method should be defined"
46
46
47 def getScreenDim(self, widthplot, heightplot):
47 def getScreenDim(self, widthplot, heightplot):
48
48
49 nrow, ncol = self.getSubplots()
49 nrow, ncol = self.getSubplots()
50
50
51 widthscreen = widthplot*ncol
51 widthscreen = widthplot*ncol
52 heightscreen = heightplot*nrow
52 heightscreen = heightplot*nrow
53
53
54 return widthscreen, heightscreen
54 return widthscreen, heightscreen
55
55
56 def getTimeLim(self, x, xmin, xmax):
56 def getTimeLim(self, x, xmin, xmax):
57
57
58 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
58 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
59 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
59 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
60
60
61 ####################################################
61 ####################################################
62 #If the x is out of xrange
62 #If the x is out of xrange
63 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
63 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
64 xmin = None
64 xmin = None
65 xmax = None
65 xmax = None
66
66
67 if xmin == None:
67 if xmin == None:
68 td = thisdatetime - thisdate
68 td = thisdatetime - thisdate
69 xmin = td.seconds/(60*60.)
69 xmin = td.seconds/(60*60.)
70
70
71 if xmax == None:
71 if xmax == None:
72 xmax = xmin + self.timerange/(60*60.)
72 xmax = xmin + self.timerange/(60*60.)
73
73
74 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
74 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
75 tmin = time.mktime(mindt.timetuple())
75 tmin = time.mktime(mindt.timetuple())
76
76
77 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
77 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
78 tmax = time.mktime(maxdt.timetuple())
78 tmax = time.mktime(maxdt.timetuple())
79
79
80 self.timerange = tmax - tmin
80 self.timerange = tmax - tmin
81
81
82 return tmin, tmax
82 return tmin, tmax
83
83
84 def init(self, idfigure, nplots, wintitle):
84 def init(self, idfigure, nplots, wintitle):
85
85
86 raise ValueError, "This method has been replaced with createFigure"
86 raise ValueError, "This method has been replaced with createFigure"
87
87
88 def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None):
88 def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None):
89
89
90 """
90 """
91 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
91 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
92 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
92 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
93 y self.HEIGHT y el numero de subplots (nrow, ncol)
93 y self.HEIGHT y el numero de subplots (nrow, ncol)
94
94
95 Input:
95 Input:
96 idfigure : Los parametros necesarios son
96 idfigure : Los parametros necesarios son
97 wintitle :
97 wintitle :
98
98
99 """
99 """
100
100
101 if widthplot == None:
101 if widthplot == None:
102 widthplot = self.WIDTH
102 widthplot = self.WIDTH
103
103
104 if heightplot == None:
104 if heightplot == None:
105 heightplot = self.HEIGHT
105 heightplot = self.HEIGHT
106
106
107 self.idfigure = idfigure
107 self.idfigure = idfigure
108
108
109 self.wintitle = wintitle
109 self.wintitle = wintitle
110
110
111 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
111 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
112
112
113 self.fig = self.__driver.createFigure(self.idfigure,
113 self.fig = self.__driver.createFigure(self.idfigure,
114 self.wintitle,
114 self.wintitle,
115 self.widthscreen,
115 self.widthscreen,
116 self.heightscreen)
116 self.heightscreen)
117
117
118 self.axesObjList = []
118 self.axesObjList = []
119
119
120 def setDriver(self, driver=mpldriver):
120 def setDriver(self, driver=mpldriver):
121
121
122 self.__driver = driver
122 self.__driver = driver
123
123
124 def setTitle(self, title):
124 def setTitle(self, title):
125
125
126 self.__driver.setTitle(self.fig, title)
126 self.__driver.setTitle(self.fig, title)
127
127
128 def setWinTitle(self, title):
128 def setWinTitle(self, title):
129
129
130 self.__driver.setWinTitle(self.fig, title=title)
130 self.__driver.setWinTitle(self.fig, title=title)
131
131
132 def setTextFromAxes(self, text):
132 def setTextFromAxes(self, text):
133
133
134 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
134 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
135
135
136 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
136 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
137
137
138 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
138 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
139
139
140 def addAxes(self, *args):
140 def addAxes(self, *args):
141 """
141 """
142
142
143 Input:
143 Input:
144 *args : Los parametros necesarios son
144 *args : Los parametros necesarios son
145 nrow, ncol, xpos, ypos, colspan, rowspan
145 nrow, ncol, xpos, ypos, colspan, rowspan
146 """
146 """
147
147
148 axesObj = Axes(self.fig, *args)
148 axesObj = Axes(self.fig, *args)
149 self.axesObjList.append(axesObj)
149 self.axesObjList.append(axesObj)
150
150
151 def saveFigure(self, figpath, figfile, *args):
151 def saveFigure(self, figpath, figfile, *args):
152
152
153 filename = os.path.join(figpath, figfile)
153 filename = os.path.join(figpath, figfile)
154 self.__driver.saveFigure(self.fig, filename, *args)
154 self.__driver.saveFigure(self.fig, filename, *args)
155
155
156 def draw(self):
156 def draw(self):
157
157
158 self.__driver.draw(self.fig)
158 self.__driver.draw(self.fig)
159
159
160 def run(self):
160 def run(self):
161
161
162 raise ValueError, "This method is not implemented"
162 raise ValueError, "This method is not implemented"
163
163
164 axesList = property(getAxesObjList)
164 axesList = property(getAxesObjList)
165
165
166
166
167 class Axes:
167 class Axes:
168
168
169 __driver = mpldriver
169 __driver = mpldriver
170 fig = None
170 fig = None
171 ax = None
171 ax = None
172 plot = None
172 plot = None
173
173
174 __firsttime = None
174 __firsttime = None
175
175
176 __showprofile = False
176 __showprofile = False
177
177
178 xmin = None
178 xmin = None
179 xmax = None
179 xmax = None
180 ymin = None
180 ymin = None
181 ymax = None
181 ymax = None
182 zmin = None
182 zmin = None
183 zmax = None
183 zmax = None
184
184
185 def __init__(self, *args):
185 def __init__(self, *args):
186
186
187 """
187 """
188
188
189 Input:
189 Input:
190 *args : Los parametros necesarios son
190 *args : Los parametros necesarios son
191 fig, nrow, ncol, xpos, ypos, colspan, rowspan
191 fig, nrow, ncol, xpos, ypos, colspan, rowspan
192 """
192 """
193
193
194 ax = self.__driver.createAxes(*args)
194 ax = self.__driver.createAxes(*args)
195 self.fig = args[0]
195 self.fig = args[0]
196 self.ax = ax
196 self.ax = ax
197 self.plot = None
197 self.plot = None
198
198
199 self.__firsttime = True
199 self.__firsttime = True
200
200
201 def setText(self, text):
201 def setText(self, text):
202
202
203 self.__driver.setAxesText(self.ax, text)
203 self.__driver.setAxesText(self.ax, text)
204
204
205 def setXAxisAsTime(self):
205 def setXAxisAsTime(self):
206 pass
206 pass
207
207
208 def pline(self, x, y,
208 def pline(self, x, y,
209 xmin=None, xmax=None,
209 xmin=None, xmax=None,
210 ymin=None, ymax=None,
210 ymin=None, ymax=None,
211 xlabel='', ylabel='',
211 xlabel='', ylabel='',
212 title='',
212 title='',
213 **kwargs):
213 **kwargs):
214
214
215 """
215 """
216
216
217 Input:
217 Input:
218 x :
218 x :
219 y :
219 y :
220 xmin :
220 xmin :
221 xmax :
221 xmax :
222 ymin :
222 ymin :
223 ymax :
223 ymax :
224 xlabel :
224 xlabel :
225 ylabel :
225 ylabel :
226 title :
226 title :
227 **kwargs : Los parametros aceptados son
227 **kwargs : Los parametros aceptados son
228
228
229 ticksize
229 ticksize
230 ytick_visible
230 ytick_visible
231 """
231 """
232
232
233 if self.__firsttime:
233 if self.__firsttime:
234
234
235 if xmin == None: xmin = numpy.nanmin(x)
235 if xmin == None: xmin = numpy.nanmin(x)
236 if xmax == None: xmax = numpy.nanmax(x)
236 if xmax == None: xmax = numpy.nanmax(x)
237 if ymin == None: ymin = numpy.nanmin(y)
237 if ymin == None: ymin = numpy.nanmin(y)
238 if ymax == None: ymax = numpy.nanmax(y)
238 if ymax == None: ymax = numpy.nanmax(y)
239
239
240 self.plot = self.__driver.createPline(self.ax, x, y,
240 self.plot = self.__driver.createPline(self.ax, x, y,
241 xmin, xmax,
241 xmin, xmax,
242 ymin, ymax,
242 ymin, ymax,
243 xlabel=xlabel,
243 xlabel=xlabel,
244 ylabel=ylabel,
244 ylabel=ylabel,
245 title=title,
245 title=title,
246 **kwargs)
246 **kwargs)
247 self.__firsttime = False
247 self.__firsttime = False
248 return
248 return
249
249
250 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
250 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
251 ylabel=ylabel,
251 ylabel=ylabel,
252 title=title)
252 title=title)
253
253
254 def pmultiline(self, x, y,
254 def pmultiline(self, x, y,
255 xmin=None, xmax=None,
255 xmin=None, xmax=None,
256 ymin=None, ymax=None,
256 ymin=None, ymax=None,
257 xlabel='', ylabel='',
257 xlabel='', ylabel='',
258 title='',
258 title='',
259 **kwargs):
259 **kwargs):
260
260
261 if self.__firsttime:
261 if self.__firsttime:
262
262
263 if xmin == None: xmin = numpy.nanmin(x)
263 if xmin == None: xmin = numpy.nanmin(x)
264 if xmax == None: xmax = numpy.nanmax(x)
264 if xmax == None: xmax = numpy.nanmax(x)
265 if ymin == None: ymin = numpy.nanmin(y)
265 if ymin == None: ymin = numpy.nanmin(y)
266 if ymax == None: ymax = numpy.nanmax(y)
266 if ymax == None: ymax = numpy.nanmax(y)
267
267
268 self.plot = self.__driver.createPmultiline(self.ax, x, y,
268 self.plot = self.__driver.createPmultiline(self.ax, x, y,
269 xmin, xmax,
269 xmin, xmax,
270 ymin, ymax,
270 ymin, ymax,
271 xlabel=xlabel,
271 xlabel=xlabel,
272 ylabel=ylabel,
272 ylabel=ylabel,
273 title=title,
273 title=title,
274 **kwargs)
274 **kwargs)
275 self.__firsttime = False
275 self.__firsttime = False
276 return
276 return
277
277
278 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
278 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
279 ylabel=ylabel,
279 ylabel=ylabel,
280 title=title)
280 title=title)
281
281
282 def pcolor(self, x, y, z,
282 def pcolor(self, x, y, z,
283 xmin=None, xmax=None,
283 xmin=None, xmax=None,
284 ymin=None, ymax=None,
284 ymin=None, ymax=None,
285 zmin=None, zmax=None,
285 zmin=None, zmax=None,
286 xlabel='', ylabel='',
286 xlabel='', ylabel='',
287 title='', rti = False, colormap='jet',
287 title='', rti = False, colormap='jet',
288 **kwargs):
288 **kwargs):
289
289
290 """
290 """
291 Input:
291 Input:
292 x :
292 x :
293 y :
293 y :
294 x :
294 x :
295 xmin :
295 xmin :
296 xmax :
296 xmax :
297 ymin :
297 ymin :
298 ymax :
298 ymax :
299 zmin :
299 zmin :
300 zmax :
300 zmax :
301 xlabel :
301 xlabel :
302 ylabel :
302 ylabel :
303 title :
303 title :
304 **kwargs : Los parametros aceptados son
304 **kwargs : Los parametros aceptados son
305 ticksize=9,
305 ticksize=9,
306 cblabel=''
306 cblabel=''
307 rti = True or False
307 rti = True or False
308 """
308 """
309
309
310 if self.__firsttime:
310 if self.__firsttime:
311
311
312 if xmin == None: xmin = numpy.nanmin(x)
312 if xmin == None: xmin = numpy.nanmin(x)
313 if xmax == None: xmax = numpy.nanmax(x)
313 if xmax == None: xmax = numpy.nanmax(x)
314 if ymin == None: ymin = numpy.nanmin(y)
314 if ymin == None: ymin = numpy.nanmin(y)
315 if ymax == None: ymax = numpy.nanmax(y)
315 if ymax == None: ymax = numpy.nanmax(y)
316 if zmin == None: zmin = numpy.nanmin(z)
316 if zmin == None: zmin = numpy.nanmin(z)
317 if zmax == None: zmax = numpy.nanmax(z)
317 if zmax == None: zmax = numpy.nanmax(z)
318
318
319
319
320 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
320 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
321 xmin, xmax,
321 xmin, xmax,
322 ymin, ymax,
322 ymin, ymax,
323 zmin, zmax,
323 zmin, zmax,
324 xlabel=xlabel,
324 xlabel=xlabel,
325 ylabel=ylabel,
325 ylabel=ylabel,
326 title=title,
326 title=title,
327 colormap=colormap,
327 colormap=colormap,
328 **kwargs)
328 **kwargs)
329
329
330 if self.xmin == None: self.xmin = xmin
330 if self.xmin == None: self.xmin = xmin
331 if self.xmax == None: self.xmax = xmax
331 if self.xmax == None: self.xmax = xmax
332 if self.ymin == None: self.ymin = ymin
332 if self.ymin == None: self.ymin = ymin
333 if self.ymax == None: self.ymax = ymax
333 if self.ymax == None: self.ymax = ymax
334 if self.zmin == None: self.zmin = zmin
334 if self.zmin == None: self.zmin = zmin
335 if self.zmax == None: self.zmax = zmax
335 if self.zmax == None: self.zmax = zmax
336
336
337 self.__firsttime = False
337 self.__firsttime = False
338 return
338 return
339
339
340 if rti:
340 if rti:
341 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
341 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
342 xlabel=xlabel,
342 xlabel=xlabel,
343 ylabel=ylabel,
343 ylabel=ylabel,
344 title=title,
344 title=title,
345 colormap=colormap)
345 colormap=colormap)
346 return
346 return
347
347
348 self.__driver.pcolor(self.plot, z,
348 self.__driver.pcolor(self.plot, z,
349 xlabel=xlabel,
349 xlabel=xlabel,
350 ylabel=ylabel,
350 ylabel=ylabel,
351 title=title)
351 title=title)
352
352
353 No newline at end of file
353
@@ -1,976 +1,983
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.getVelRange(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 thisDatetime = dataOut.datatime
99 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
100 xlabel = "Velocity (m/s)"
101 ylabel = "Range (Km)"
102
98 if not self.__isConfig:
103 if not self.__isConfig:
99
104
100 nplots = len(pairsIndexList)
105 nplots = len(pairsIndexList)
101
106
102 self.setup(idfigure=idfigure,
107 self.setup(idfigure=idfigure,
103 nplots=nplots,
108 nplots=nplots,
104 wintitle=wintitle,
109 wintitle=wintitle,
105 showprofile=showprofile)
110 showprofile=showprofile)
106
111
107 if xmin == None: xmin = numpy.nanmin(x)
112 if xmin == None: xmin = numpy.nanmin(x)
108 if xmax == None: xmax = numpy.nanmax(x)
113 if xmax == None: xmax = numpy.nanmax(x)
109 if ymin == None: ymin = numpy.nanmin(y)
114 if ymin == None: ymin = numpy.nanmin(y)
110 if ymax == None: ymax = numpy.nanmax(y)
115 if ymax == None: ymax = numpy.nanmax(y)
111 if zmin == None: zmin = numpy.nanmin(avg)*0.9
116 if zmin == None: zmin = numpy.nanmin(avg)*0.9
112 if zmax == None: zmax = numpy.nanmax(avg)*0.9
117 if zmax == None: zmax = numpy.nanmax(avg)*0.9
113
118
114 self.__isConfig = True
119 self.__isConfig = True
115
116 thisDatetime = dataOut.datatime
117 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
118 xlabel = "Velocity (m/s)"
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_r')
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_%H%M%S")
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 = 2*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 thisDatetime = dataOut.datatime
429 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
430 xlabel = "Velocity (m/s)"
431 ylabel = "Range (Km)"
432
428 if not self.__isConfig:
433 if not self.__isConfig:
429
434
430 nplots = len(channelIndexList)
435 nplots = len(channelIndexList)
431
436
432 self.setup(idfigure=idfigure,
437 self.setup(idfigure=idfigure,
433 nplots=nplots,
438 nplots=nplots,
434 wintitle=wintitle,
439 wintitle=wintitle,
435 showprofile=showprofile)
440 showprofile=showprofile)
436
441
437 if xmin == None: xmin = numpy.nanmin(x)
442 if xmin == None: xmin = numpy.nanmin(x)
438 if xmax == None: xmax = numpy.nanmax(x)
443 if xmax == None: xmax = numpy.nanmax(x)
439 if ymin == None: ymin = numpy.nanmin(y)
444 if ymin == None: ymin = numpy.nanmin(y)
440 if ymax == None: ymax = numpy.nanmax(y)
445 if ymax == None: ymax = numpy.nanmax(y)
441 if zmin == None: zmin = numpy.nanmin(avg)*0.9
446 if zmin == None: zmin = numpy.nanmin(avg)*0.9
442 if zmax == None: zmax = numpy.nanmax(avg)*0.9
447 if zmax == None: zmax = numpy.nanmax(avg)*0.9
443
448
444 self.__isConfig = True
449 self.__isConfig = True
445
446 thisDatetime = dataOut.datatime
447 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
448 xlabel = "Velocity (m/s)"
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_%H%M%S")
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,
511 figpath='./', figfile=None):
511
512
512 """
513 """
513
514
514 Input:
515 Input:
515 dataOut :
516 dataOut :
516 idfigure :
517 idfigure :
517 wintitle :
518 wintitle :
518 channelList :
519 channelList :
519 xmin : None,
520 xmin : None,
520 xmax : None,
521 xmax : None,
521 ymin : None,
522 ymin : None,
522 ymax : None,
523 ymax : None,
523 """
524 """
524
525
525 if channelList == None:
526 if channelList == None:
526 channelIndexList = dataOut.channelIndexList
527 channelIndexList = dataOut.channelIndexList
527 else:
528 else:
528 channelIndexList = []
529 channelIndexList = []
529 for channel in channelList:
530 for channel in channelList:
530 if channel not in dataOut.channelList:
531 if channel not in dataOut.channelList:
531 raise ValueError, "Channel %d is not in dataOut.channelList"
532 raise ValueError, "Channel %d is not in dataOut.channelList"
532 channelIndexList.append(dataOut.channelList.index(channel))
533 channelIndexList.append(dataOut.channelList.index(channel))
533
534
534 x = dataOut.heightList
535 x = dataOut.heightList
535 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
536 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
536 y = y.real
537 y = y.real
537
538
539 thisDatetime = dataOut.datatime
540 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
541 xlabel = "Range (Km)"
542 ylabel = "Intensity"
543
538 if not self.__isConfig:
544 if not self.__isConfig:
539 nplots = len(channelIndexList)
545 nplots = len(channelIndexList)
540
546
541 self.setup(idfigure=idfigure,
547 self.setup(idfigure=idfigure,
542 nplots=nplots,
548 nplots=nplots,
543 wintitle=wintitle)
549 wintitle=wintitle)
544
550
545 if xmin == None: xmin = numpy.nanmin(x)
551 if xmin == None: xmin = numpy.nanmin(x)
546 if xmax == None: xmax = numpy.nanmax(x)
552 if xmax == None: xmax = numpy.nanmax(x)
547 if ymin == None: ymin = numpy.nanmin(y)
553 if ymin == None: ymin = numpy.nanmin(y)
548 if ymax == None: ymax = numpy.nanmax(y)
554 if ymax == None: ymax = numpy.nanmax(y)
549
555
550 self.__isConfig = True
556 self.__isConfig = True
551
557
552
553 thisDatetime = dataOut.datatime
554 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
555 xlabel = "Range (Km)"
556 ylabel = "Intensity"
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 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
572 if figfile == None:
573 figfile = self.getFilename(name = date)
574
575 self.saveFigure(figpath, figfile)
572
576
573 class ProfilePlot(Figure):
577 class ProfilePlot(Figure):
574 __isConfig = None
578 __isConfig = None
575 __nsubplots = None
579 __nsubplots = None
576
580
577 WIDTHPROF = None
581 WIDTHPROF = None
578 HEIGHTPROF = None
582 HEIGHTPROF = None
579 PREFIX = 'spcprofile'
583 PREFIX = 'spcprofile'
580
584
581 def __init__(self):
585 def __init__(self):
582 self.__isConfig = False
586 self.__isConfig = False
583 self.__nsubplots = 1
587 self.__nsubplots = 1
584
588
585 self.WIDTH = 300
589 self.WIDTH = 300
586 self.HEIGHT = 500
590 self.HEIGHT = 500
587
591
588 def getSubplots(self):
592 def getSubplots(self):
589 ncol = 1
593 ncol = 1
590 nrow = 1
594 nrow = 1
591
595
592 return nrow, ncol
596 return nrow, ncol
593
597
594 def setup(self, idfigure, nplots, wintitle):
598 def setup(self, idfigure, nplots, wintitle):
595
599
596 self.nplots = nplots
600 self.nplots = nplots
597
601
598 ncolspan = 1
602 ncolspan = 1
599 colspan = 1
603 colspan = 1
600
604
601 self.createFigure(idfigure = idfigure,
605 self.createFigure(idfigure = idfigure,
602 wintitle = wintitle,
606 wintitle = wintitle,
603 widthplot = self.WIDTH,
607 widthplot = self.WIDTH,
604 heightplot = self.HEIGHT)
608 heightplot = self.HEIGHT)
605
609
606 nrow, ncol = self.getSubplots()
610 nrow, ncol = self.getSubplots()
607
611
608 counter = 0
612 counter = 0
609 for y in range(nrow):
613 for y in range(nrow):
610 for x in range(ncol):
614 for x in range(ncol):
611 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
615 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
612
616
613 def run(self, dataOut, idfigure, wintitle="", channelList=None,
617 def run(self, dataOut, idfigure, wintitle="", channelList=None,
614 xmin=None, xmax=None, ymin=None, ymax=None,
618 xmin=None, xmax=None, ymin=None, ymax=None,
615 save=False, figpath='./', figfile=None):
619 save=False, figpath='./', figfile=None):
616
620
617 if channelList == None:
621 if channelList == None:
618 channelIndexList = dataOut.channelIndexList
622 channelIndexList = dataOut.channelIndexList
619 channelList = dataOut.channelList
623 channelList = dataOut.channelList
620 else:
624 else:
621 channelIndexList = []
625 channelIndexList = []
622 for channel in channelList:
626 for channel in channelList:
623 if channel not in dataOut.channelList:
627 if channel not in dataOut.channelList:
624 raise ValueError, "Channel %d is not in dataOut.channelList"
628 raise ValueError, "Channel %d is not in dataOut.channelList"
625 channelIndexList.append(dataOut.channelList.index(channel))
629 channelIndexList.append(dataOut.channelList.index(channel))
626
630
627
631
628 y = dataOut.getHeiRange()
632 y = dataOut.getHeiRange()
629 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
633 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
630 avg = numpy.average(x, axis=1)
634 avg = numpy.average(x, axis=1)
631
635
636 thisDatetime = dataOut.datatime
637 title = "Power Profile"
638 xlabel = "dB"
639 ylabel = "Range (Km)"
632
640
633 if not self.__isConfig:
641 if not self.__isConfig:
634
642
635 nplots = 1
643 nplots = 1
636
644
637 self.setup(idfigure=idfigure,
645 self.setup(idfigure=idfigure,
638 nplots=nplots,
646 nplots=nplots,
639 wintitle=wintitle)
647 wintitle=wintitle)
640
648
641 if ymin == None: ymin = numpy.nanmin(y)
649 if ymin == None: ymin = numpy.nanmin(y)
642 if ymax == None: ymax = numpy.nanmax(y)
650 if ymax == None: ymax = numpy.nanmax(y)
643 if xmin == None: xmin = numpy.nanmin(avg)*0.9
651 if xmin == None: xmin = numpy.nanmin(avg)*0.9
644 if xmax == None: xmax = numpy.nanmax(avg)*0.9
652 if xmax == None: xmax = numpy.nanmax(avg)*0.9
645
653
646 self.__isConfig = True
654 self.__isConfig = True
647
648 thisDatetime = dataOut.datatime
649 title = "Power Profile"
650 xlabel = "dB"
651 ylabel = "Range (Km)"
652
655
653 self.setWinTitle(title)
656 self.setWinTitle(title)
654
657
655
658
656 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
659 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
657 axes = self.axesList[0]
660 axes = self.axesList[0]
658
661
659 legendlabels = ["channel %d"%x for x in channelList]
662 legendlabels = ["channel %d"%x for x in channelList]
660 axes.pmultiline(avg, y,
663 axes.pmultiline(avg, y,
661 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
664 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
662 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
665 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
663 ytick_visible=True, nxticks=5,
666 ytick_visible=True, nxticks=5,
664 grid='x')
667 grid='x')
665
668
666 self.draw()
669 self.draw()
667
670
668 if save:
671 if save:
669 date = thisDatetime.strftime("%Y%m%d")
672 date = thisDatetime.strftime("%Y%m%d")
670 if figfile == None:
673 if figfile == None:
671 figfile = self.getFilename(name = date)
674 figfile = self.getFilename(name = date)
672
675
673 self.saveFigure(figpath, figfile)
676 self.saveFigure(figpath, figfile)
674
677
675 class CoherenceMap(Figure):
678 class CoherenceMap(Figure):
676 __isConfig = None
679 __isConfig = None
677 __nsubplots = None
680 __nsubplots = None
678
681
679 WIDTHPROF = None
682 WIDTHPROF = None
680 HEIGHTPROF = None
683 HEIGHTPROF = None
681 PREFIX = 'coherencemap'
684 PREFIX = 'coherencemap'
682
685
683 def __init__(self):
686 def __init__(self):
684 self.timerange = 2*60*60
687 self.timerange = 2*60*60
685 self.__isConfig = False
688 self.__isConfig = False
686 self.__nsubplots = 1
689 self.__nsubplots = 1
687
690
688 self.WIDTH = 800
691 self.WIDTH = 800
689 self.HEIGHT = 200
692 self.HEIGHT = 200
690 self.WIDTHPROF = 120
693 self.WIDTHPROF = 120
691 self.HEIGHTPROF = 0
694 self.HEIGHTPROF = 0
692
695
693 def getSubplots(self):
696 def getSubplots(self):
694 ncol = 1
697 ncol = 1
695 nrow = self.nplots*2
698 nrow = self.nplots*2
696
699
697 return nrow, ncol
700 return nrow, ncol
698
701
699 def setup(self, idfigure, nplots, wintitle, showprofile=True):
702 def setup(self, idfigure, nplots, wintitle, showprofile=True):
700 self.__showprofile = showprofile
703 self.__showprofile = showprofile
701 self.nplots = nplots
704 self.nplots = nplots
702
705
703 ncolspan = 1
706 ncolspan = 1
704 colspan = 1
707 colspan = 1
705 if showprofile:
708 if showprofile:
706 ncolspan = 7
709 ncolspan = 7
707 colspan = 6
710 colspan = 6
708 self.__nsubplots = 2
711 self.__nsubplots = 2
709
712
710 self.createFigure(idfigure = idfigure,
713 self.createFigure(idfigure = idfigure,
711 wintitle = wintitle,
714 wintitle = wintitle,
712 widthplot = self.WIDTH + self.WIDTHPROF,
715 widthplot = self.WIDTH + self.WIDTHPROF,
713 heightplot = self.HEIGHT + self.HEIGHTPROF)
716 heightplot = self.HEIGHT + self.HEIGHTPROF)
714
717
715 nrow, ncol = self.getSubplots()
718 nrow, ncol = self.getSubplots()
716
719
717 for y in range(nrow):
720 for y in range(nrow):
718 for x in range(ncol):
721 for x in range(ncol):
719
722
720 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
723 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
721
724
722 if showprofile:
725 if showprofile:
723 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
726 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
724
727
725 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
728 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
726 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
729 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
727 timerange=None,
730 timerange=None,
728 save=False, figpath='./', figfile=None):
731 save=False, figpath='./', figfile=None):
729
732
730 if pairsList == None:
733 if pairsList == None:
731 pairsIndexList = dataOut.pairsIndexList
734 pairsIndexList = dataOut.pairsIndexList
732 else:
735 else:
733 pairsIndexList = []
736 pairsIndexList = []
734 for pair in pairsList:
737 for pair in pairsList:
735 if pair not in dataOut.pairsList:
738 if pair not in dataOut.pairsList:
736 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
739 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
737 pairsIndexList.append(dataOut.pairsList.index(pair))
740 pairsIndexList.append(dataOut.pairsList.index(pair))
738
741
739 if timerange != None:
742 if timerange != None:
740 self.timerange = timerange
743 self.timerange = timerange
741
744
742 if pairsIndexList == []:
745 if pairsIndexList == []:
743 return
746 return
744
747
745 if len(pairsIndexList) > 4:
748 if len(pairsIndexList) > 4:
746 pairsIndexList = pairsIndexList[0:4]
749 pairsIndexList = pairsIndexList[0:4]
747
750
748 tmin = None
751 tmin = None
749 tmax = None
752 tmax = None
750 x = dataOut.getTimeRange()
753 x = dataOut.getTimeRange()
751 y = dataOut.getHeiRange()
754 y = dataOut.getHeiRange()
752
755
756 thisDatetime = dataOut.datatime
757 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
758 xlabel = ""
759 ylabel = "Range (Km)"
760
753 if not self.__isConfig:
761 if not self.__isConfig:
754 nplots = len(pairsIndexList)
762 nplots = len(pairsIndexList)
755 self.setup(idfigure=idfigure,
763 self.setup(idfigure=idfigure,
756 nplots=nplots,
764 nplots=nplots,
757 wintitle=wintitle,
765 wintitle=wintitle,
758 showprofile=showprofile)
766 showprofile=showprofile)
759
767
760 tmin, tmax = self.getTimeLim(x, xmin, xmax)
768 tmin, tmax = self.getTimeLim(x, xmin, xmax)
761 if ymin == None: ymin = numpy.nanmin(y)
769 if ymin == None: ymin = numpy.nanmin(y)
762 if ymax == None: ymax = numpy.nanmax(y)
770 if ymax == None: ymax = numpy.nanmax(y)
763
771
772 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
773
764 self.__isConfig = True
774 self.__isConfig = True
765
775
766 thisDatetime = dataOut.datatime
767 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
768 xlabel = ""
769 ylabel = "Range (Km)"
770
771 self.setWinTitle(title)
776 self.setWinTitle(title)
772
777
773 for i in range(self.nplots):
778 for i in range(self.nplots):
774
779
775 pair = dataOut.pairsList[pairsIndexList[i]]
780 pair = dataOut.pairsList[pairsIndexList[i]]
776 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
781 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
777 coherence = numpy.abs(coherenceComplex)
782 coherence = numpy.abs(coherenceComplex)
778 avg = numpy.average(coherence, axis=0)
783 avg = numpy.average(coherence, axis=0)
779 z = avg.reshape((1,-1))
784 z = avg.reshape((1,-1))
780
785
781 counter = 0
786 counter = 0
782
787
783 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
788 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]
789 axes = self.axesList[i*self.__nsubplots*2]
785 axes.pcolor(x, y, z,
790 axes.pcolor(x, y, z,
786 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
791 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
787 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
792 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
788 ticksize=9, cblabel='', cbsize="1%")
793 ticksize=9, cblabel='', cbsize="1%")
789
794
790 if self.__showprofile:
795 if self.__showprofile:
791 counter += 1
796 counter += 1
792 axes = self.axesList[i*self.__nsubplots*2 + counter]
797 axes = self.axesList[i*self.__nsubplots*2 + counter]
793 axes.pline(avg, y,
798 axes.pline(avg, y,
794 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
799 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
795 xlabel='', ylabel='', title='', ticksize=7,
800 xlabel='', ylabel='', title='', ticksize=7,
796 ytick_visible=False, nxticks=5,
801 ytick_visible=False, nxticks=5,
797 grid='x')
802 grid='x')
798
803
799 counter += 1
804 counter += 1
800 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
805 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
801 avg = numpy.average(phase, axis=0)
806 avg = numpy.average(phase, axis=0)
802 z = avg.reshape((1,-1))
807 z = avg.reshape((1,-1))
803
808
804 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
809 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]
810 axes = self.axesList[i*self.__nsubplots*2 + counter]
806 axes.pcolor(x, y, z,
811 axes.pcolor(x, y, z,
807 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
812 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
808 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
813 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
809 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
814 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
810
815
811 if self.__showprofile:
816 if self.__showprofile:
812 counter += 1
817 counter += 1
813 axes = self.axesList[i*self.__nsubplots*2 + counter]
818 axes = self.axesList[i*self.__nsubplots*2 + counter]
814 axes.pline(avg, y,
819 axes.pline(avg, y,
815 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
820 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
816 xlabel='', ylabel='', title='', ticksize=7,
821 xlabel='', ylabel='', title='', ticksize=7,
817 ytick_visible=False, nxticks=4,
822 ytick_visible=False, nxticks=4,
818 grid='x')
823 grid='x')
819
824
820 self.draw()
825 self.draw()
821
826
822 if save:
827 if save:
823 date = thisDatetime.strftime("%Y%m%d")
828
824 if figfile == None:
829 if figfile == None:
825 figfile = self.getFilename(name = date)
830 figfile = self.getFilename(name = self.name)
826
831
827 self.saveFigure(figpath, figfile)
832 self.saveFigure(figpath, figfile)
828
833
829 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
834 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
830 self.__isConfig = False
835 self.__isConfig = False
831
836
832 class RTIfromNoise(Figure):
837 class RTIfromNoise(Figure):
833
838
834 __isConfig = None
839 __isConfig = None
835 __nsubplots = None
840 __nsubplots = None
836
841
837 WIDTHPROF = None
842 WIDTHPROF = None
838 HEIGHTPROF = None
843 HEIGHTPROF = None
839 PREFIX = 'rti'
844 PREFIX = 'rti'
840
845
841 def __init__(self):
846 def __init__(self):
842
847
843 self.__timerange = 24*60*60
848 self.__timerange = 24*60*60
844 self.__isConfig = False
849 self.__isConfig = False
845 self.__nsubplots = 1
850 self.__nsubplots = 1
846
851
847 self.WIDTH = 800
852 self.WIDTH = 800
848 self.HEIGHT = 200
853 self.HEIGHT = 200
849
854
850 def getSubplots(self):
855 def getSubplots(self):
851
856
852 ncol = 1
857 ncol = 1
853 nrow = self.nplots
858 nrow = self.nplots
854
859
855 return nrow, ncol
860 return nrow, ncol
856
861
857 def setup(self, idfigure, nplots, wintitle, showprofile=True):
862 def setup(self, idfigure, nplots, wintitle, showprofile=True):
858
863
859 self.__showprofile = showprofile
864 self.__showprofile = showprofile
860 self.nplots = nplots
865 self.nplots = nplots
861
866
862 ncolspan = 1
867 ncolspan = 1
863 colspan = 1
868 colspan = 1
864
869
865 self.createFigure(idfigure = idfigure,
870 self.createFigure(idfigure = idfigure,
866 wintitle = wintitle,
871 wintitle = wintitle,
867 widthplot = self.WIDTH + self.WIDTHPROF,
872 widthplot = self.WIDTH + self.WIDTHPROF,
868 heightplot = self.HEIGHT + self.HEIGHTPROF)
873 heightplot = self.HEIGHT + self.HEIGHTPROF)
869
874
870 nrow, ncol = self.getSubplots()
875 nrow, ncol = self.getSubplots()
871
876
872 self.addAxes(nrow, ncol, 0, 0, 1, 1)
877 self.addAxes(nrow, ncol, 0, 0, 1, 1)
873
878
874
879
875
880
876 def __getTimeLim(self, x, xmin, xmax):
881 def __getTimeLim(self, x, xmin, xmax):
877
882
878 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
883 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
879 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
884 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
880
885
881 ####################################################
886 ####################################################
882 #If the x is out of xrange
887 #If the x is out of xrange
883 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
888 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
884 xmin = None
889 xmin = None
885 xmax = None
890 xmax = None
886
891
887 if xmin == None:
892 if xmin == None:
888 td = thisdatetime - thisdate
893 td = thisdatetime - thisdate
889 xmin = td.seconds/(60*60.)
894 xmin = td.seconds/(60*60.)
890
895
891 if xmax == None:
896 if xmax == None:
892 xmax = xmin + self.__timerange/(60*60.)
897 xmax = xmin + self.__timerange/(60*60.)
893
898
894 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
899 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
895 tmin = time.mktime(mindt.timetuple())
900 tmin = time.mktime(mindt.timetuple())
896
901
897 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
902 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
898 tmax = time.mktime(maxdt.timetuple())
903 tmax = time.mktime(maxdt.timetuple())
899
904
900 self.__timerange = tmax - tmin
905 self.__timerange = tmax - tmin
901
906
902 return tmin, tmax
907 return tmin, tmax
903
908
904 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
909 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
905 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
910 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
906 timerange=None,
911 timerange=None,
907 save=False, figpath='./', figfile=None):
912 save=False, figpath='./', figfile=None):
908
913
909 if channelList == None:
914 if channelList == None:
910 channelIndexList = dataOut.channelIndexList
915 channelIndexList = dataOut.channelIndexList
911 else:
916 else:
912 channelIndexList = []
917 channelIndexList = []
913 for channel in channelList:
918 for channel in channelList:
914 if channel not in dataOut.channelList:
919 if channel not in dataOut.channelList:
915 raise ValueError, "Channel %d is not in dataOut.channelList"
920 raise ValueError, "Channel %d is not in dataOut.channelList"
916 channelIndexList.append(dataOut.channelList.index(channel))
921 channelIndexList.append(dataOut.channelList.index(channel))
917
922
918 if timerange != None:
923 if timerange != None:
919 self.__timerange = timerange
924 self.__timerange = timerange
920
925
921 tmin = None
926 tmin = None
922 tmax = None
927 tmax = None
923 x = dataOut.getTimeRange()
928 x = dataOut.getTimeRange()
924 y = dataOut.getHeiRange()
929 y = dataOut.getHeiRange()
925 x1 = dataOut.datatime
930 x1 = dataOut.datatime
926 # z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
931 # z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
927 # avg = numpy.average(z, axis=1)
932 # avg = numpy.average(z, axis=1)
928
933
929 noise = dataOut.getNoise()
934 noise = dataOut.getNoise()
930
935
936 thisDatetime = dataOut.datatime
937 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
938 xlabel = "Velocity (m/s)"
939 ylabel = "Range (Km)"
940
941
931 if not self.__isConfig:
942 if not self.__isConfig:
932
943
933 nplots = len(channelIndexList)
944 nplots = len(channelIndexList)
934
945
935 self.setup(idfigure=idfigure,
946 self.setup(idfigure=idfigure,
936 nplots=nplots,
947 nplots=nplots,
937 wintitle=wintitle,
948 wintitle=wintitle,
938 showprofile=showprofile)
949 showprofile=showprofile)
939
950
940 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
951 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
941 if ymin == None: ymin = numpy.nanmin(y)
952 if ymin == None: ymin = numpy.nanmin(y)
942 if ymax == None: ymax = numpy.nanmax(y)
953 if ymax == None: ymax = numpy.nanmax(y)
943 if zmin == None: zmin = numpy.nanmin(avg)*0.9
954 if zmin == None: zmin = numpy.nanmin(avg)*0.9
944 if zmax == None: zmax = numpy.nanmax(avg)*0.9
955 if zmax == None: zmax = numpy.nanmax(avg)*0.9
945
956
946 self.__isConfig = True
957 self.__isConfig = True
947
958
948 thisDatetime = dataOut.datatime
949 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
950 xlabel = "Velocity (m/s)"
951 ylabel = "Range (Km)"
952
959
953 self.setWinTitle(title)
960 self.setWinTitle(title)
954
961
955 for i in range(self.nplots):
962 for i in range(self.nplots):
956 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
963 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
957 axes = self.axesList[i*self.__nsubplots]
964 axes = self.axesList[i*self.__nsubplots]
958 z = avg[i].reshape((1,-1))
965 z = avg[i].reshape((1,-1))
959 axes.pcolor(x, y, z,
966 axes.pcolor(x, y, z,
960 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
967 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
961 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
968 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
962 ticksize=9, cblabel='', cbsize="1%")
969 ticksize=9, cblabel='', cbsize="1%")
963
970
964
971
965 self.draw()
972 self.draw()
966
973
967 if save:
974 if save:
968 date = thisDatetime.strftime("%Y%m%d")
975 date = thisDatetime.strftime("%Y%m%d")
969 if figfile == None:
976 if figfile == None:
970 figfile = self.getFilename(name = date)
977 figfile = self.getFilename(name = date)
971
978
972 self.saveFigure(figpath, figfile)
979 self.saveFigure(figpath, figfile)
973
980
974 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
981 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
975 self.__isConfig = False
982 self.__isConfig = False
976 No newline at end of file
983
General Comments 0
You need to be logged in to leave comments. Login now