##// END OF EJS Templates
Adicion de la clase ProfilePlot, CoherencePLot en el modulo jroplot.py...
Daniel Valdez -
r229:22aec8924dc0
parent child
Show More
@@ -1,294 +1,323
1 import os
1 import os
2 import numpy
2 import numpy
3 import mpldriver
3 import mpldriver
4
4
5
5
6 class Figure:
6 class Figure:
7
7
8 __driver = mpldriver
8 __driver = mpldriver
9 fig = None
9 fig = None
10
10
11 idfigure = None
11 idfigure = None
12 wintitle = None
12 wintitle = None
13 width = None
13 width = None
14 height = None
14 height = None
15 nplots = None
15 nplots = None
16
16
17 axesObjList = []
17 axesObjList = []
18
18
19 WIDTH = None
19 WIDTH = None
20 HEIGHT = None
20 HEIGHT = None
21 PREFIX = 'fig'
21 PREFIX = 'fig'
22
22
23 def __init__(self):
23 def __init__(self):
24
24
25 raise ValueError, "This method is not implemented"
25 raise ValueError, "This method is not implemented"
26
26
27 def __del__(self):
27 def __del__(self):
28
28
29 self.__driver.closeFigure()
29 self.__driver.closeFigure()
30
30
31 def getFilename(self, name, ext='.png'):
31 def getFilename(self, name, ext='.png'):
32
32
33 filename = '%s_%s%s' %(self.PREFIX, name, ext)
33 filename = '%s_%s%s' %(self.PREFIX, name, ext)
34
34
35 return filename
35 return filename
36
36
37 def getAxesObjList(self):
37 def getAxesObjList(self):
38
38
39 return self.axesObjList
39 return self.axesObjList
40
40
41 def getSubplots(self):
41 def getSubplots(self):
42
42
43 raise ValueError, "Abstract method: This method should be defined"
43 raise ValueError, "Abstract method: This method should be defined"
44
44
45 def getScreenDim(self, widthplot, heightplot):
45 def getScreenDim(self, widthplot, heightplot):
46
46
47 nrow, ncol = self.getSubplots()
47 nrow, ncol = self.getSubplots()
48
48
49 widthscreen = widthplot*ncol
49 widthscreen = widthplot*ncol
50 heightscreen = heightplot*nrow
50 heightscreen = heightplot*nrow
51
51
52 return widthscreen, heightscreen
52 return widthscreen, heightscreen
53
53
54 def init(self, idfigure, nplots, wintitle):
54 def init(self, idfigure, nplots, wintitle):
55
55
56 raise ValueError, "This method has been replaced with createFigure"
56 raise ValueError, "This method has been replaced with createFigure"
57
57
58 def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None):
58 def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None):
59
59
60 """
60 """
61 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
61 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
62 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
62 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
63 y self.HEIGHT y el numero de subplots (nrow, ncol)
63 y self.HEIGHT y el numero de subplots (nrow, ncol)
64
64
65 Input:
65 Input:
66 idfigure : Los parametros necesarios son
66 idfigure : Los parametros necesarios son
67 wintitle :
67 wintitle :
68
68
69 """
69 """
70
70
71 if widthplot == None:
71 if widthplot == None:
72 widthplot = self.WIDTH
72 widthplot = self.WIDTH
73
73
74 if heightplot == None:
74 if heightplot == None:
75 heightplot = self.HEIGHT
75 heightplot = self.HEIGHT
76
76
77 self.idfigure = idfigure
77 self.idfigure = idfigure
78
78
79 self.wintitle = wintitle
79 self.wintitle = wintitle
80
80
81 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
81 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
82
82
83 self.fig = self.__driver.createFigure(self.idfigure,
83 self.fig = self.__driver.createFigure(self.idfigure,
84 self.wintitle,
84 self.wintitle,
85 self.widthscreen,
85 self.widthscreen,
86 self.heightscreen)
86 self.heightscreen)
87
87
88 self.axesObjList = []
88 self.axesObjList = []
89
89
90 def setDriver(self, driver=mpldriver):
90 def setDriver(self, driver=mpldriver):
91
91
92 self.__driver = driver
92 self.__driver = driver
93
93
94 def setTitle(self, title):
94 def setTitle(self, title):
95
95
96 self.__driver.setTitle(self.fig, title)
96 self.__driver.setTitle(self.fig, title)
97
97
98 def setWinTitle(self, title):
98 def setWinTitle(self, title):
99
99
100 self.__driver.setWinTitle(self.fig, title=title)
100 self.__driver.setWinTitle(self.fig, title=title)
101
101
102 def setTextFromAxes(self, text):
102 def setTextFromAxes(self, text):
103
103
104 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
104 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
105
105
106 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
106 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
107
107
108 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
108 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
109
109
110 def addAxes(self, *args):
110 def addAxes(self, *args):
111 """
111 """
112
112
113 Input:
113 Input:
114 *args : Los parametros necesarios son
114 *args : Los parametros necesarios son
115 nrow, ncol, xpos, ypos, colspan, rowspan
115 nrow, ncol, xpos, ypos, colspan, rowspan
116 """
116 """
117
117
118 axesObj = Axes(self.fig, *args)
118 axesObj = Axes(self.fig, *args)
119 self.axesObjList.append(axesObj)
119 self.axesObjList.append(axesObj)
120
120
121 def saveFigure(self, figpath, figfile, *args):
121 def saveFigure(self, figpath, figfile, *args):
122
122
123 filename = os.path.join(figpath, figfile)
123 filename = os.path.join(figpath, figfile)
124 self.__driver.saveFigure(self.fig, filename, *args)
124 self.__driver.saveFigure(self.fig, filename, *args)
125
125
126 def draw(self):
126 def draw(self):
127
127
128 self.__driver.draw(self.fig)
128 self.__driver.draw(self.fig)
129
129
130 def run(self):
130 def run(self):
131
131
132 raise ValueError, "This method is not implemented"
132 raise ValueError, "This method is not implemented"
133
133
134 axesList = property(getAxesObjList)
134 axesList = property(getAxesObjList)
135
135
136
136
137 class Axes:
137 class Axes:
138
138
139 __driver = mpldriver
139 __driver = mpldriver
140 fig = None
140 fig = None
141 ax = None
141 ax = None
142 plot = None
142 plot = None
143
143
144 __firsttime = None
144 __firsttime = None
145
145
146 __showprofile = False
146 __showprofile = False
147
147
148 xmin = None
148 xmin = None
149 xmax = None
149 xmax = None
150 ymin = None
150 ymin = None
151 ymax = None
151 ymax = None
152 zmin = None
152 zmin = None
153 zmax = None
153 zmax = None
154
154
155 def __init__(self, *args):
155 def __init__(self, *args):
156
156
157 """
157 """
158
158
159 Input:
159 Input:
160 *args : Los parametros necesarios son
160 *args : Los parametros necesarios son
161 fig, nrow, ncol, xpos, ypos, colspan, rowspan
161 fig, nrow, ncol, xpos, ypos, colspan, rowspan
162 """
162 """
163
163
164 ax = self.__driver.createAxes(*args)
164 ax = self.__driver.createAxes(*args)
165 self.fig = args[0]
165 self.fig = args[0]
166 self.ax = ax
166 self.ax = ax
167 self.plot = None
167 self.plot = None
168
168
169 self.__firsttime = True
169 self.__firsttime = True
170
170
171 def setText(self, text):
171 def setText(self, text):
172
172
173 self.__driver.setAxesText(self.ax, text)
173 self.__driver.setAxesText(self.ax, text)
174
174
175 def setXAxisAsTime(self):
175 def setXAxisAsTime(self):
176 pass
176 pass
177
177
178 def pline(self, x, y,
178 def pline(self, x, y,
179 xmin=None, xmax=None,
179 xmin=None, xmax=None,
180 ymin=None, ymax=None,
180 ymin=None, ymax=None,
181 xlabel='', ylabel='',
181 xlabel='', ylabel='',
182 title='',
182 title='',
183 **kwargs):
183 **kwargs):
184
184
185 """
185 """
186
186
187 Input:
187 Input:
188 x :
188 x :
189 y :
189 y :
190 xmin :
190 xmin :
191 xmax :
191 xmax :
192 ymin :
192 ymin :
193 ymax :
193 ymax :
194 xlabel :
194 xlabel :
195 ylabel :
195 ylabel :
196 title :
196 title :
197 **kwargs : Los parametros aceptados son
197 **kwargs : Los parametros aceptados son
198
198
199 ticksize
199 ticksize
200 ytick_visible
200 ytick_visible
201 """
201 """
202
202
203 if self.__firsttime:
203 if self.__firsttime:
204
204
205 if xmin == None: xmin = numpy.nanmin(x)
205 if xmin == None: xmin = numpy.nanmin(x)
206 if xmax == None: xmax = numpy.nanmax(x)
206 if xmax == None: xmax = numpy.nanmax(x)
207 if ymin == None: ymin = numpy.nanmin(y)
207 if ymin == None: ymin = numpy.nanmin(y)
208 if ymax == None: ymax = numpy.nanmax(y)
208 if ymax == None: ymax = numpy.nanmax(y)
209
209
210 self.plot = self.__driver.createPline(self.ax, x, y,
210 self.plot = self.__driver.createPline(self.ax, x, y,
211 xmin, xmax,
211 xmin, xmax,
212 ymin, ymax,
212 ymin, ymax,
213 xlabel=xlabel,
213 xlabel=xlabel,
214 ylabel=ylabel,
214 ylabel=ylabel,
215 title=title,
215 title=title,
216 **kwargs)
216 **kwargs)
217 self.__firsttime = False
217 self.__firsttime = False
218 return
218 return
219
219
220 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
220 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
221 ylabel=ylabel,
221 ylabel=ylabel,
222 title=title)
222 title=title)
223
223
224 def pmultiline(self, x, y,
225 xmin=None, xmax=None,
226 ymin=None, ymax=None,
227 xlabel='', ylabel='',
228 title='',
229 **kwargs):
230
231 if self.__firsttime:
232
233 if xmin == None: xmin = numpy.nanmin(x)
234 if xmax == None: xmax = numpy.nanmax(x)
235 if ymin == None: ymin = numpy.nanmin(y)
236 if ymax == None: ymax = numpy.nanmax(y)
237
238 self.plot = self.__driver.createPmultiline(self.ax, x, y,
239 xmin, xmax,
240 ymin, ymax,
241 xlabel=xlabel,
242 ylabel=ylabel,
243 title=title,
244 **kwargs)
245 self.__firsttime = False
246 return
247
248 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
249 ylabel=ylabel,
250 title=title)
224
251
225 def pcolor(self, x, y, z,
252 def pcolor(self, x, y, z,
226 xmin=None, xmax=None,
253 xmin=None, xmax=None,
227 ymin=None, ymax=None,
254 ymin=None, ymax=None,
228 zmin=None, zmax=None,
255 zmin=None, zmax=None,
229 xlabel='', ylabel='',
256 xlabel='', ylabel='',
230 title='', rti = False,
257 title='', rti = False, colormap='jet',
231 **kwargs):
258 **kwargs):
232
259
233 """
260 """
234 Input:
261 Input:
235 x :
262 x :
236 y :
263 y :
237 x :
264 x :
238 xmin :
265 xmin :
239 xmax :
266 xmax :
240 ymin :
267 ymin :
241 ymax :
268 ymax :
242 zmin :
269 zmin :
243 zmax :
270 zmax :
244 xlabel :
271 xlabel :
245 ylabel :
272 ylabel :
246 title :
273 title :
247 **kwargs : Los parametros aceptados son
274 **kwargs : Los parametros aceptados son
248 ticksize=9,
275 ticksize=9,
249 cblabel=''
276 cblabel=''
250 rti = True or False
277 rti = True or False
251 """
278 """
252
279
253 if self.__firsttime:
280 if self.__firsttime:
254
281
255 if xmin == None: xmin = numpy.nanmin(x)
282 if xmin == None: xmin = numpy.nanmin(x)
256 if xmax == None: xmax = numpy.nanmax(x)
283 if xmax == None: xmax = numpy.nanmax(x)
257 if ymin == None: ymin = numpy.nanmin(y)
284 if ymin == None: ymin = numpy.nanmin(y)
258 if ymax == None: ymax = numpy.nanmax(y)
285 if ymax == None: ymax = numpy.nanmax(y)
259 if zmin == None: zmin = numpy.nanmin(z)
286 if zmin == None: zmin = numpy.nanmin(z)
260 if zmax == None: zmax = numpy.nanmax(z)
287 if zmax == None: zmax = numpy.nanmax(z)
261
288
262
289
263 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
290 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
264 xmin, xmax,
291 xmin, xmax,
265 ymin, ymax,
292 ymin, ymax,
266 zmin, zmax,
293 zmin, zmax,
267 xlabel=xlabel,
294 xlabel=xlabel,
268 ylabel=ylabel,
295 ylabel=ylabel,
269 title=title,
296 title=title,
297 colormap=colormap,
270 **kwargs)
298 **kwargs)
271
299
272 if self.xmin == None: self.xmin = xmin
300 if self.xmin == None: self.xmin = xmin
273 if self.xmax == None: self.xmax = xmax
301 if self.xmax == None: self.xmax = xmax
274 if self.ymin == None: self.ymin = ymin
302 if self.ymin == None: self.ymin = ymin
275 if self.ymax == None: self.ymax = ymax
303 if self.ymax == None: self.ymax = ymax
276 if self.zmin == None: self.zmin = zmin
304 if self.zmin == None: self.zmin = zmin
277 if self.zmax == None: self.zmax = zmax
305 if self.zmax == None: self.zmax = zmax
278
306
279 self.__firsttime = False
307 self.__firsttime = False
280 return
308 return
281
309
282 if rti:
310 if rti:
283 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
311 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
284 xlabel=xlabel,
312 xlabel=xlabel,
285 ylabel=ylabel,
313 ylabel=ylabel,
286 title=title)
314 title=title,
315 colormap=colormap)
287 return
316 return
288
317
289 self.__driver.pcolor(self.plot, z,
318 self.__driver.pcolor(self.plot, z,
290 xlabel=xlabel,
319 xlabel=xlabel,
291 ylabel=ylabel,
320 ylabel=ylabel,
292 title=title)
321 title=title)
293
322
294 No newline at end of file
323
@@ -1,202 +1,268
1 import numpy
1 import numpy
2 import datetime
2 import datetime
3 import matplotlib
3 import matplotlib
4 matplotlib.use("TKAgg")
4 matplotlib.use("TKAgg")
5 import matplotlib.pyplot
5 import matplotlib.pyplot
6 import matplotlib.dates
6 import matplotlib.dates
7 #import scitools.numpyutils
7 #import scitools.numpyutils
8 from mpl_toolkits.axes_grid1 import make_axes_locatable
8 from mpl_toolkits.axes_grid1 import make_axes_locatable
9
9
10 from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter
10 from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter
11 from matplotlib.ticker import FuncFormatter
11 from matplotlib.ticker import FuncFormatter
12 from matplotlib.ticker import *
12 from matplotlib.ticker import *
13
13
14 ###########################################
14 ###########################################
15 #Actualizacion de las funciones del driver
15 #Actualizacion de las funciones del driver
16 ###########################################
16 ###########################################
17
17
18 def createFigure(idfigure, wintitle, width, height, facecolor="w"):
18 def createFigure(idfigure, wintitle, width, height, facecolor="w"):
19
19
20 matplotlib.pyplot.ioff()
20 matplotlib.pyplot.ioff()
21 fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor)
21 fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor)
22 fig.canvas.manager.set_window_title(wintitle)
22 fig.canvas.manager.set_window_title(wintitle)
23 fig.canvas.manager.resize(width, height)
23 fig.canvas.manager.resize(width, height)
24 matplotlib.pyplot.ion()
24 matplotlib.pyplot.ion()
25
25
26 return fig
26 return fig
27
27
28 def closeFigure():
28 def closeFigure():
29
29
30 matplotlib.pyplot.ioff()
30 matplotlib.pyplot.ioff()
31 matplotlib.pyplot.show()
31 matplotlib.pyplot.show()
32
32
33 return
33 return
34
34
35 def saveFigure(fig, filename):
35 def saveFigure(fig, filename):
36 fig.savefig(filename)
36 fig.savefig(filename)
37
37
38 def setWinTitle(fig, title):
38 def setWinTitle(fig, title):
39
39
40 fig.canvas.manager.set_window_title(title)
40 fig.canvas.manager.set_window_title(title)
41
41
42 def setTitle(fig, title):
42 def setTitle(fig, title):
43
43
44 fig.suptitle(title)
44 fig.suptitle(title)
45
45
46 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan):
46 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan):
47
47
48 matplotlib.pyplot.figure(fig.number)
48 matplotlib.pyplot.figure(fig.number)
49 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
49 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
50 (xpos, ypos),
50 (xpos, ypos),
51 colspan=colspan,
51 colspan=colspan,
52 rowspan=rowspan)
52 rowspan=rowspan)
53 return axes
53 return axes
54
54
55 def setAxesText(ax, text):
55 def setAxesText(ax, text):
56
56
57 ax.annotate(text,
57 ax.annotate(text,
58 xy = (.1, .99),
58 xy = (.1, .99),
59 xycoords = 'figure fraction',
59 xycoords = 'figure fraction',
60 horizontalalignment = 'left',
60 horizontalalignment = 'left',
61 verticalalignment = 'top',
61 verticalalignment = 'top',
62 fontsize = 10)
62 fontsize = 10)
63
63
64 def printLabels(ax, xlabel, ylabel, title):
64 def printLabels(ax, xlabel, ylabel, title):
65
65
66 ax.set_xlabel(xlabel, size=11)
66 ax.set_xlabel(xlabel, size=11)
67 ax.set_ylabel(ylabel, size=11)
67 ax.set_ylabel(ylabel, size=11)
68 ax.set_title(title, size=12)
68 ax.set_title(title, size=12)
69
69
70 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
70 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
71 ticksize=9, xtick_visible=True, ytick_visible=True,
71 ticksize=9, xtick_visible=True, ytick_visible=True,
72 nxticks=4, nyticks=10,
72 nxticks=4, nyticks=10,
73 grid=None):
73 grid=None):
74
74
75 """
75 """
76
76
77 Input:
77 Input:
78 grid : None, 'both', 'x', 'y'
78 grid : None, 'both', 'x', 'y'
79 """
79 """
80
80
81 ax.plot(x, y)
81 ax.plot(x, y)
82 ax.set_xlim([xmin,xmax])
82 ax.set_xlim([xmin,xmax])
83 ax.set_ylim([ymin,ymax])
83 ax.set_ylim([ymin,ymax])
84
84
85 printLabels(ax, xlabel, ylabel, title)
85 printLabels(ax, xlabel, ylabel, title)
86
86
87 ######################################################
87 ######################################################
88 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin)
88 if (xmax-xmin)<=1:
89 ax.set_xticks(xtickspos)
89 xtickspos = numpy.linspace(xmin,xmax,nxticks)
90 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
91 ax.set_xticks(xtickspos)
92 else:
93 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
94 ax.set_xticks(xtickspos)
90
95
91 for tick in ax.get_xticklabels():
96 for tick in ax.get_xticklabels():
92 tick.set_visible(xtick_visible)
97 tick.set_visible(xtick_visible)
93
98
94 for tick in ax.xaxis.get_major_ticks():
99 for tick in ax.xaxis.get_major_ticks():
95 tick.label.set_fontsize(ticksize)
100 tick.label.set_fontsize(ticksize)
96
101
97 ######################################################
102 ######################################################
98 for tick in ax.get_yticklabels():
103 for tick in ax.get_yticklabels():
99 tick.set_visible(ytick_visible)
104 tick.set_visible(ytick_visible)
100
105
101 for tick in ax.yaxis.get_major_ticks():
106 for tick in ax.yaxis.get_major_ticks():
102 tick.label.set_fontsize(ticksize)
107 tick.label.set_fontsize(ticksize)
103
108
104 iplot = ax.lines[-1]
109 iplot = ax.lines[-1]
105
110
106 ######################################################
111 ######################################################
107 if '0.' in matplotlib.__version__[0:2]:
112 if '0.' in matplotlib.__version__[0:2]:
108 print "The matplotlib version has to be updated to 1.1 or newer"
113 print "The matplotlib version has to be updated to 1.1 or newer"
109 return iplot
114 return iplot
110
115
111 if '1.0.' in matplotlib.__version__[0:4]:
116 if '1.0.' in matplotlib.__version__[0:4]:
112 print "The matplotlib version has to be updated to 1.1 or newer"
117 print "The matplotlib version has to be updated to 1.1 or newer"
113 return iplot
118 return iplot
114
119
115 if grid != None:
120 if grid != None:
116 ax.grid(b=True, which='major', axis=grid)
121 ax.grid(b=True, which='major', axis=grid)
117
122
118 matplotlib.pyplot.tight_layout()
123 matplotlib.pyplot.tight_layout()
119
124
120 return iplot
125 return iplot
121
126
122 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
127 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
123
128
124 ax = iplot.get_axes()
129 ax = iplot.get_axes()
125
130
126 printLabels(ax, xlabel, ylabel, title)
131 printLabels(ax, xlabel, ylabel, title)
127
132
128 iplot.set_data(x, y)
133 iplot.set_data(x, y)
134
135 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
136 ticksize=9, xtick_visible=True, ytick_visible=True,
137 nxticks=4, nyticks=10,
138 grid=None):
139
140 """
141
142 Input:
143 grid : None, 'both', 'x', 'y'
144 """
145
146 lines = ax.plot(x.T, y)
147 leg = ax.legend(lines, legendlabels, loc='upper left')
148 leg.get_frame().set_alpha(0.5)
149 ax.set_xlim([xmin,xmax])
150 ax.set_ylim([ymin,ymax])
151 printLabels(ax, xlabel, ylabel, title)
152
153 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
154 ax.set_xticks(xtickspos)
155
156 for tick in ax.get_xticklabels():
157 tick.set_visible(xtick_visible)
158
159 for tick in ax.xaxis.get_major_ticks():
160 tick.label.set_fontsize(ticksize)
161
162 for tick in ax.get_yticklabels():
163 tick.set_visible(ytick_visible)
164
165 for tick in ax.yaxis.get_major_ticks():
166 tick.label.set_fontsize(ticksize)
167
168 iplot = ax.lines[-1]
169
170 if '0.' in matplotlib.__version__[0:2]:
171 print "The matplotlib version has to be updated to 1.1 or newer"
172 return iplot
173
174 if '1.0.' in matplotlib.__version__[0:4]:
175 print "The matplotlib version has to be updated to 1.1 or newer"
176 return iplot
177
178 if grid != None:
179 ax.grid(b=True, which='major', axis=grid)
180
181 matplotlib.pyplot.tight_layout()
182
183 return iplot
184
185
186 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
187
188 ax = iplot.get_axes()
189
190 printLabels(ax, xlabel, ylabel, title)
129
191
192 for i in range(len(ax.lines)):
193 line = ax.lines[i]
194 line.set_data(x[i,:],y)
195
130 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
196 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
131 xlabel='', ylabel='', title='', ticksize = 9,
197 xlabel='', ylabel='', title='', ticksize = 9,
132 colormap='jet',cblabel='', cbsize="5%",
198 colormap='jet',cblabel='', cbsize="5%",
133 XAxisAsTime=False):
199 XAxisAsTime=False):
134
200
135 divider = make_axes_locatable(ax)
201 divider = make_axes_locatable(ax)
136 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
202 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
137 fig = ax.get_figure()
203 fig = ax.get_figure()
138 fig.add_axes(ax_cb)
204 fig.add_axes(ax_cb)
139
205
140 ax.set_xlim([xmin,xmax])
206 ax.set_xlim([xmin,xmax])
141 ax.set_ylim([ymin,ymax])
207 ax.set_ylim([ymin,ymax])
142
208
143 printLabels(ax, xlabel, ylabel, title)
209 printLabels(ax, xlabel, ylabel, title)
144
210
145 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
211 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
146 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
212 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
147 cb.set_label(cblabel)
213 cb.set_label(cblabel)
148
214
149 # for tl in ax_cb.get_yticklabels():
215 # for tl in ax_cb.get_yticklabels():
150 # tl.set_visible(True)
216 # tl.set_visible(True)
151
217
152 for tick in ax.yaxis.get_major_ticks():
218 for tick in ax.yaxis.get_major_ticks():
153 tick.label.set_fontsize(ticksize)
219 tick.label.set_fontsize(ticksize)
154
220
155 for tick in ax.xaxis.get_major_ticks():
221 for tick in ax.xaxis.get_major_ticks():
156 tick.label.set_fontsize(ticksize)
222 tick.label.set_fontsize(ticksize)
157
223
158 for tick in cb.ax.get_yticklabels():
224 for tick in cb.ax.get_yticklabels():
159 tick.set_fontsize(ticksize)
225 tick.set_fontsize(ticksize)
160
226
161 ax_cb.yaxis.tick_right()
227 ax_cb.yaxis.tick_right()
162
228
163 if '0.' in matplotlib.__version__[0:2]:
229 if '0.' in matplotlib.__version__[0:2]:
164 print "The matplotlib version has to be updated to 1.1 or newer"
230 print "The matplotlib version has to be updated to 1.1 or newer"
165 return imesh
231 return imesh
166
232
167 if '1.0.' in matplotlib.__version__[0:4]:
233 if '1.0.' in matplotlib.__version__[0:4]:
168 print "The matplotlib version has to be updated to 1.1 or newer"
234 print "The matplotlib version has to be updated to 1.1 or newer"
169 return imesh
235 return imesh
170
236
171 matplotlib.pyplot.tight_layout()
237 matplotlib.pyplot.tight_layout()
172
238
173 if XAxisAsTime:
239 if XAxisAsTime:
174
240
175 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
241 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
176 ax.xaxis.set_major_formatter(FuncFormatter(func))
242 ax.xaxis.set_major_formatter(FuncFormatter(func))
177 ax.xaxis.set_major_locator(LinearLocator(7))
243 ax.xaxis.set_major_locator(LinearLocator(7))
178
244
179 return imesh
245 return imesh
180
246
181 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
247 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
182
248
183 z = z.T
249 z = z.T
184
250
185 ax = imesh.get_axes()
251 ax = imesh.get_axes()
186
252
187 printLabels(ax, xlabel, ylabel, title)
253 printLabels(ax, xlabel, ylabel, title)
188
254
189 imesh.set_array(z.ravel())
255 imesh.set_array(z.ravel())
190
256
191 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title=''):
257 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
192
258
193 printLabels(ax, xlabel, ylabel, title)
259 printLabels(ax, xlabel, ylabel, title)
194
260
195 imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax)
261 imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
196
262
197 def draw(fig):
263 def draw(fig):
198
264
199 if type(fig) == 'int':
265 if type(fig) == 'int':
200 raise ValueError, "This parameter should be of tpye matplotlib figure"
266 raise ValueError, "This parameter should be of tpye matplotlib figure"
201
267
202 fig.canvas.draw() No newline at end of file
268 fig.canvas.draw()
@@ -1,592 +1,874
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 = 'cspc'
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:
85 if len(pairsIndexList) > 4:
86 pairsIndexList = pairsIndexList[0:4]
86 pairsIndexList = pairsIndexList[0:4]
87
87
88 x = dataOut.getFreqRange(1)
88 x = dataOut.getFreqRange(1)
89 y = dataOut.getHeiRange()
89 y = dataOut.getHeiRange()
90 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
90 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
91 avg = numpy.average(numpy.abs(z), axis=1)
91 avg = numpy.average(numpy.abs(z), axis=1)
92
92
93 noise = dataOut.getNoise()
93 noise = dataOut.getNoise()
94
94
95 if not self.__isConfig:
95 if not self.__isConfig:
96
96
97 nplots = len(pairsIndexList)
97 nplots = len(pairsIndexList)
98
98
99 self.setup(idfigure=idfigure,
99 self.setup(idfigure=idfigure,
100 nplots=nplots,
100 nplots=nplots,
101 wintitle=wintitle,
101 wintitle=wintitle,
102 showprofile=showprofile)
102 showprofile=showprofile)
103
103
104 if xmin == None: xmin = numpy.nanmin(x)
104 if xmin == None: xmin = numpy.nanmin(x)
105 if xmax == None: xmax = numpy.nanmax(x)
105 if xmax == None: xmax = numpy.nanmax(x)
106 if ymin == None: ymin = numpy.nanmin(y)
106 if ymin == None: ymin = numpy.nanmin(y)
107 if ymax == None: ymax = numpy.nanmax(y)
107 if ymax == None: ymax = numpy.nanmax(y)
108 if zmin == None: zmin = numpy.nanmin(avg)*0.9
108 if zmin == None: zmin = numpy.nanmin(avg)*0.9
109 if zmax == None: zmax = numpy.nanmax(avg)*0.9
109 if zmax == None: zmax = numpy.nanmax(avg)*0.9
110
110
111 self.__isConfig = True
111 self.__isConfig = True
112
112
113 thisDatetime = dataOut.datatime
113 thisDatetime = dataOut.datatime
114 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
114 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
115 xlabel = "Velocity (m/s)"
115 xlabel = "Velocity (m/s)"
116 ylabel = "Range (Km)"
116 ylabel = "Range (Km)"
117
117
118 self.setWinTitle(title)
118 self.setWinTitle(title)
119
119
120 for i in range(self.nplots):
120 for i in range(self.nplots):
121 pair = dataOut.pairsList[pairsIndexList[i]]
121 pair = dataOut.pairsList[pairsIndexList[i]]
122
122
123 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
123 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
124 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
124 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
125 axes0 = self.axesList[i*self.__nsubplots]
125 axes0 = self.axesList[i*self.__nsubplots]
126 axes0.pcolor(x, y, z,
126 axes0.pcolor(x, y, z,
127 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,
128 xlabel=xlabel, ylabel=ylabel, title=title,
128 xlabel=xlabel, ylabel=ylabel, title=title,
129 ticksize=9, cblabel='')
129 ticksize=9, cblabel='')
130
130
131 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
131 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
132 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
132 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
133 axes0 = self.axesList[i*self.__nsubplots+1]
133 axes0 = self.axesList[i*self.__nsubplots+1]
134 axes0.pcolor(x, y, z,
134 axes0.pcolor(x, y, z,
135 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,
136 xlabel=xlabel, ylabel=ylabel, title=title,
136 xlabel=xlabel, ylabel=ylabel, title=title,
137 ticksize=9, cblabel='')
137 ticksize=9, cblabel='')
138
138
139 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],:,:])
140 coherence = numpy.abs(coherenceComplex)
140 coherence = numpy.abs(coherenceComplex)
141 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
141 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
142
142
143
143
144 title = "Coherence %d%d" %(pair[0], pair[1])
144 title = "Coherence %d%d" %(pair[0], pair[1])
145 axes0 = self.axesList[i*self.__nsubplots+2]
145 axes0 = self.axesList[i*self.__nsubplots+2]
146 axes0.pcolor(x, y, coherence,
146 axes0.pcolor(x, y, coherence,
147 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,
148 xlabel=xlabel, ylabel=ylabel, title=title,
148 xlabel=xlabel, ylabel=ylabel, title=title,
149 ticksize=9, cblabel='')
149 ticksize=9, cblabel='')
150
150
151 title = "Phase %d%d" %(pair[0], pair[1])
151 title = "Phase %d%d" %(pair[0], pair[1])
152 axes0 = self.axesList[i*self.__nsubplots+3]
152 axes0 = self.axesList[i*self.__nsubplots+3]
153 axes0.pcolor(x, y, phase,
153 axes0.pcolor(x, y, phase,
154 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,
155 xlabel=xlabel, ylabel=ylabel, title=title,
155 xlabel=xlabel, ylabel=ylabel, title=title,
156 ticksize=9, cblabel='', colormap='RdBu')
156 ticksize=9, cblabel='', colormap='RdBu')
157
157
158
158
159
159
160 self.draw()
160 self.draw()
161
161
162 if save:
162 if save:
163 date = thisDatetime.strftime("%Y%m%d")
163 date = thisDatetime.strftime("%Y%m%d")
164 if figfile == None:
164 if figfile == None:
165 figfile = self.getFilename(name = date)
165 figfile = self.getFilename(name = date)
166
166
167 self.saveFigure(figpath, figfile)
167 self.saveFigure(figpath, figfile)
168
168
169
169
170 class RTIPlot(Figure):
170 class RTIPlot(Figure):
171
171
172 __isConfig = None
172 __isConfig = None
173 __nsubplots = None
173 __nsubplots = None
174
174
175 WIDTHPROF = None
175 WIDTHPROF = None
176 HEIGHTPROF = None
176 HEIGHTPROF = None
177 PREFIX = 'rti'
177 PREFIX = 'rti'
178
178
179 def __init__(self):
179 def __init__(self):
180
180
181 self.__timerange = 24*60*60
181 self.__timerange = 24*60*60
182 self.__isConfig = False
182 self.__isConfig = False
183 self.__nsubplots = 1
183 self.__nsubplots = 1
184
184
185 self.WIDTH = 800
185 self.WIDTH = 800
186 self.HEIGHT = 200
186 self.HEIGHT = 200
187 self.WIDTHPROF = 120
187 self.WIDTHPROF = 120
188 self.HEIGHTPROF = 0
188 self.HEIGHTPROF = 0
189
189
190 def getSubplots(self):
190 def getSubplots(self):
191
191
192 ncol = 1
192 ncol = 1
193 nrow = self.nplots
193 nrow = self.nplots
194
194
195 return nrow, ncol
195 return nrow, ncol
196
196
197 def setup(self, idfigure, nplots, wintitle, showprofile=True):
197 def setup(self, idfigure, nplots, wintitle, showprofile=True):
198
198
199 self.__showprofile = showprofile
199 self.__showprofile = showprofile
200 self.nplots = nplots
200 self.nplots = nplots
201
201
202 ncolspan = 1
202 ncolspan = 1
203 colspan = 1
203 colspan = 1
204 if showprofile:
204 if showprofile:
205 ncolspan = 7
205 ncolspan = 7
206 colspan = 6
206 colspan = 6
207 self.__nsubplots = 2
207 self.__nsubplots = 2
208
208
209 self.createFigure(idfigure = idfigure,
209 self.createFigure(idfigure = idfigure,
210 wintitle = wintitle,
210 wintitle = wintitle,
211 widthplot = self.WIDTH + self.WIDTHPROF,
211 widthplot = self.WIDTH + self.WIDTHPROF,
212 heightplot = self.HEIGHT + self.HEIGHTPROF)
212 heightplot = self.HEIGHT + self.HEIGHTPROF)
213
213
214 nrow, ncol = self.getSubplots()
214 nrow, ncol = self.getSubplots()
215
215
216 counter = 0
216 counter = 0
217 for y in range(nrow):
217 for y in range(nrow):
218 for x in range(ncol):
218 for x in range(ncol):
219
219
220 if counter >= self.nplots:
220 if counter >= self.nplots:
221 break
221 break
222
222
223 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
223 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
224
224
225 if showprofile:
225 if showprofile:
226 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
226 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
227
227
228 counter += 1
228 counter += 1
229
229
230 def __getTimeLim(self, x, xmin, xmax):
230 def __getTimeLim(self, x, xmin, xmax):
231
231
232 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
232 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
233 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
233 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
234
234
235 ####################################################
235 ####################################################
236 #If the x is out of xrange
236 #If the x is out of xrange
237 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
237 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
238 xmin = None
238 xmin = None
239 xmax = None
239 xmax = None
240
240
241 if xmin == None:
241 if xmin == None:
242 td = thisdatetime - thisdate
242 td = thisdatetime - thisdate
243 xmin = td.seconds/(60*60.)
243 xmin = td.seconds/(60*60.)
244
244
245 if xmax == None:
245 if xmax == None:
246 xmax = xmin + self.__timerange/(60*60.)
246 xmax = xmin + self.__timerange/(60*60.)
247
247
248 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
248 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
249 tmin = time.mktime(mindt.timetuple())
249 tmin = time.mktime(mindt.timetuple())
250
250
251 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
251 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
252 tmax = time.mktime(maxdt.timetuple())
252 tmax = time.mktime(maxdt.timetuple())
253
253
254 self.__timerange = tmax - tmin
254 self.__timerange = tmax - tmin
255
255
256 return tmin, tmax
256 return tmin, tmax
257
257
258 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
258 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
259 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,
260 timerange=None,
260 timerange=None,
261 save=False, figpath='./', figfile=None):
261 save=False, figpath='./', figfile=None):
262
262
263 """
263 """
264
264
265 Input:
265 Input:
266 dataOut :
266 dataOut :
267 idfigure :
267 idfigure :
268 wintitle :
268 wintitle :
269 channelList :
269 channelList :
270 showProfile :
270 showProfile :
271 xmin : None,
271 xmin : None,
272 xmax : None,
272 xmax : None,
273 ymin : None,
273 ymin : None,
274 ymax : None,
274 ymax : None,
275 zmin : None,
275 zmin : None,
276 zmax : None
276 zmax : None
277 """
277 """
278
278
279 if channelList == None:
279 if channelList == None:
280 channelIndexList = dataOut.channelIndexList
280 channelIndexList = dataOut.channelIndexList
281 else:
281 else:
282 channelIndexList = []
282 channelIndexList = []
283 for channel in channelList:
283 for channel in channelList:
284 if channel not in dataOut.channelList:
284 if channel not in dataOut.channelList:
285 raise ValueError, "Channel %d is not in dataOut.channelList"
285 raise ValueError, "Channel %d is not in dataOut.channelList"
286 channelIndexList.append(dataOut.channelList.index(channel))
286 channelIndexList.append(dataOut.channelList.index(channel))
287
287
288 if timerange != None:
288 if timerange != None:
289 self.__timerange = timerange
289 self.__timerange = timerange
290
290
291 tmin = None
291 tmin = None
292 tmax = None
292 tmax = None
293 x = dataOut.getTimeRange()
293 x = dataOut.getTimeRange()
294 y = dataOut.getHeiRange()
294 y = dataOut.getHeiRange()
295 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
295 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
296 avg = numpy.average(z, axis=1)
296 avg = numpy.average(z, axis=1)
297
297
298 noise = dataOut.getNoise()
298 noise = dataOut.getNoise()
299
299
300 if not self.__isConfig:
300 if not self.__isConfig:
301
301
302 nplots = len(channelIndexList)
302 nplots = len(channelIndexList)
303
303
304 self.setup(idfigure=idfigure,
304 self.setup(idfigure=idfigure,
305 nplots=nplots,
305 nplots=nplots,
306 wintitle=wintitle,
306 wintitle=wintitle,
307 showprofile=showprofile)
307 showprofile=showprofile)
308
308
309 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
309 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
310 if ymin == None: ymin = numpy.nanmin(y)
310 if ymin == None: ymin = numpy.nanmin(y)
311 if ymax == None: ymax = numpy.nanmax(y)
311 if ymax == None: ymax = numpy.nanmax(y)
312 if zmin == None: zmin = numpy.nanmin(avg)*0.9
312 if zmin == None: zmin = numpy.nanmin(avg)*0.9
313 if zmax == None: zmax = numpy.nanmax(avg)*0.9
313 if zmax == None: zmax = numpy.nanmax(avg)*0.9
314
314
315 self.__isConfig = True
315 self.__isConfig = True
316
316
317 thisDatetime = dataOut.datatime
317 thisDatetime = dataOut.datatime
318 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
318 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
319 xlabel = "Velocity (m/s)"
319 xlabel = "Velocity (m/s)"
320 ylabel = "Range (Km)"
320 ylabel = "Range (Km)"
321
321
322 self.setWinTitle(title)
322 self.setWinTitle(title)
323
323
324 for i in range(self.nplots):
324 for i in range(self.nplots):
325 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"))
326 axes = self.axesList[i*self.__nsubplots]
326 axes = self.axesList[i*self.__nsubplots]
327 z = avg[i].reshape((1,-1))
327 z = avg[i].reshape((1,-1))
328 axes.pcolor(x, y, z,
328 axes.pcolor(x, y, z,
329 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,
330 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
330 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
331 ticksize=9, cblabel='', cbsize="1%")
331 ticksize=9, cblabel='', cbsize="1%")
332
332
333 if self.__showprofile:
333 if self.__showprofile:
334 axes = self.axesList[i*self.__nsubplots +1]
334 axes = self.axesList[i*self.__nsubplots +1]
335 axes.pline(avg[i], y,
335 axes.pline(avg[i], y,
336 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
336 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
337 xlabel='dB', ylabel='', title='',
337 xlabel='dB', ylabel='', title='',
338 ytick_visible=False,
338 ytick_visible=False,
339 grid='x')
339 grid='x')
340
340
341 self.draw()
341 self.draw()
342
342
343 if save:
343 if save:
344 date = thisDatetime.strftime("%Y%m%d")
344 date = thisDatetime.strftime("%Y%m%d")
345 if figfile == None:
345 if figfile == None:
346 figfile = self.getFilename(name = date)
346 figfile = self.getFilename(name = date)
347
347
348 self.saveFigure(figpath, figfile)
348 self.saveFigure(figpath, figfile)
349
349
350 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
350 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
351 self.__isConfig = False
351 self.__isConfig = False
352
352
353 class SpectraPlot(Figure):
353 class SpectraPlot(Figure):
354
354
355 __isConfig = None
355 __isConfig = None
356 __nsubplots = None
356 __nsubplots = None
357
357
358 WIDTHPROF = None
358 WIDTHPROF = None
359 HEIGHTPROF = None
359 HEIGHTPROF = None
360 PREFIX = 'spc'
360 PREFIX = 'spc'
361
361
362 def __init__(self):
362 def __init__(self):
363
363
364 self.__isConfig = False
364 self.__isConfig = False
365 self.__nsubplots = 1
365 self.__nsubplots = 1
366
366
367 self.WIDTH = 300
367 self.WIDTH = 300
368 self.HEIGHT = 400
368 self.HEIGHT = 400
369 self.WIDTHPROF = 120
369 self.WIDTHPROF = 120
370 self.HEIGHTPROF = 0
370 self.HEIGHTPROF = 0
371
371
372 def getSubplots(self):
372 def getSubplots(self):
373
373
374 ncol = int(numpy.sqrt(self.nplots)+0.9)
374 ncol = int(numpy.sqrt(self.nplots)+0.9)
375 nrow = int(self.nplots*1./ncol + 0.9)
375 nrow = int(self.nplots*1./ncol + 0.9)
376
376
377 return nrow, ncol
377 return nrow, ncol
378
378
379 def setup(self, idfigure, nplots, wintitle, showprofile=True):
379 def setup(self, idfigure, nplots, wintitle, showprofile=True):
380
380
381 self.__showprofile = showprofile
381 self.__showprofile = showprofile
382 self.nplots = nplots
382 self.nplots = nplots
383
383
384 ncolspan = 1
384 ncolspan = 1
385 colspan = 1
385 colspan = 1
386 if showprofile:
386 if showprofile:
387 ncolspan = 3
387 ncolspan = 3
388 colspan = 2
388 colspan = 2
389 self.__nsubplots = 2
389 self.__nsubplots = 2
390
390
391 self.createFigure(idfigure = idfigure,
391 self.createFigure(idfigure = idfigure,
392 wintitle = wintitle,
392 wintitle = wintitle,
393 widthplot = self.WIDTH + self.WIDTHPROF,
393 widthplot = self.WIDTH + self.WIDTHPROF,
394 heightplot = self.HEIGHT + self.HEIGHTPROF)
394 heightplot = self.HEIGHT + self.HEIGHTPROF)
395
395
396 nrow, ncol = self.getSubplots()
396 nrow, ncol = self.getSubplots()
397
397
398 counter = 0
398 counter = 0
399 for y in range(nrow):
399 for y in range(nrow):
400 for x in range(ncol):
400 for x in range(ncol):
401
401
402 if counter >= self.nplots:
402 if counter >= self.nplots:
403 break
403 break
404
404
405 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
405 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
406
406
407 if showprofile:
407 if showprofile:
408 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
408 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
409
409
410 counter += 1
410 counter += 1
411
411
412 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
412 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
413 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,
414 save=False, figpath='./', figfile=None):
414 save=False, figpath='./', figfile=None):
415
415
416 """
416 """
417
417
418 Input:
418 Input:
419 dataOut :
419 dataOut :
420 idfigure :
420 idfigure :
421 wintitle :
421 wintitle :
422 channelList :
422 channelList :
423 showProfile :
423 showProfile :
424 xmin : None,
424 xmin : None,
425 xmax : None,
425 xmax : None,
426 ymin : None,
426 ymin : None,
427 ymax : None,
427 ymax : None,
428 zmin : None,
428 zmin : None,
429 zmax : None
429 zmax : None
430 """
430 """
431
431
432 if channelList == None:
432 if channelList == None:
433 channelIndexList = dataOut.channelIndexList
433 channelIndexList = dataOut.channelIndexList
434 else:
434 else:
435 channelIndexList = []
435 channelIndexList = []
436 for channel in channelList:
436 for channel in channelList:
437 if channel not in dataOut.channelList:
437 if channel not in dataOut.channelList:
438 raise ValueError, "Channel %d is not in dataOut.channelList"
438 raise ValueError, "Channel %d is not in dataOut.channelList"
439 channelIndexList.append(dataOut.channelList.index(channel))
439 channelIndexList.append(dataOut.channelList.index(channel))
440
440
441 x = dataOut.getVelRange(1)
441 x = dataOut.getVelRange(1)
442 y = dataOut.getHeiRange()
442 y = dataOut.getHeiRange()
443 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
443 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
444 avg = numpy.average(z, axis=1)
444 avg = numpy.average(z, axis=1)
445
445
446 noise = dataOut.getNoise()
446 noise = dataOut.getNoise()
447
447
448 if not self.__isConfig:
448 if not self.__isConfig:
449
449
450 nplots = len(channelIndexList)
450 nplots = len(channelIndexList)
451
451
452 self.setup(idfigure=idfigure,
452 self.setup(idfigure=idfigure,
453 nplots=nplots,
453 nplots=nplots,
454 wintitle=wintitle,
454 wintitle=wintitle,
455 showprofile=showprofile)
455 showprofile=showprofile)
456
456
457 if xmin == None: xmin = numpy.nanmin(x)
457 if xmin == None: xmin = numpy.nanmin(x)
458 if xmax == None: xmax = numpy.nanmax(x)
458 if xmax == None: xmax = numpy.nanmax(x)
459 if ymin == None: ymin = numpy.nanmin(y)
459 if ymin == None: ymin = numpy.nanmin(y)
460 if ymax == None: ymax = numpy.nanmax(y)
460 if ymax == None: ymax = numpy.nanmax(y)
461 if zmin == None: zmin = numpy.nanmin(avg)*0.9
461 if zmin == None: zmin = numpy.nanmin(avg)*0.9
462 if zmax == None: zmax = numpy.nanmax(avg)*0.9
462 if zmax == None: zmax = numpy.nanmax(avg)*0.9
463
463
464 self.__isConfig = True
464 self.__isConfig = True
465
465
466 thisDatetime = dataOut.datatime
466 thisDatetime = dataOut.datatime
467 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
467 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
468 xlabel = "Velocity (m/s)"
468 xlabel = "Velocity (m/s)"
469 ylabel = "Range (Km)"
469 ylabel = "Range (Km)"
470
470
471 self.setWinTitle(title)
471 self.setWinTitle(title)
472
472
473 for i in range(self.nplots):
473 for i in range(self.nplots):
474 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
474 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
475 axes = self.axesList[i*self.__nsubplots]
475 axes = self.axesList[i*self.__nsubplots]
476 axes.pcolor(x, y, z[i,:,:],
476 axes.pcolor(x, y, z[i,:,:],
477 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,
478 xlabel=xlabel, ylabel=ylabel, title=title,
478 xlabel=xlabel, ylabel=ylabel, title=title,
479 ticksize=9, cblabel='')
479 ticksize=9, cblabel='')
480
480
481 if self.__showprofile:
481 if self.__showprofile:
482 axes = self.axesList[i*self.__nsubplots +1]
482 axes = self.axesList[i*self.__nsubplots +1]
483 axes.pline(avg[i], y,
483 axes.pline(avg[i], y,
484 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
484 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
485 xlabel='dB', ylabel='', title='',
485 xlabel='dB', ylabel='', title='',
486 ytick_visible=False,
486 ytick_visible=False,
487 grid='x')
487 grid='x')
488
488
489 self.draw()
489 self.draw()
490
490
491 if save:
491 if save:
492 date = thisDatetime.strftime("%Y%m%d")
492 date = thisDatetime.strftime("%Y%m%d")
493 if figfile == None:
493 if figfile == None:
494 figfile = self.getFilename(name = date)
494 figfile = self.getFilename(name = date)
495
495
496 self.saveFigure(figpath, figfile)
496 self.saveFigure(figpath, figfile)
497
497
498 class Scope(Figure):
498 class Scope(Figure):
499
499
500 __isConfig = None
500 __isConfig = None
501
501
502 def __init__(self):
502 def __init__(self):
503
503
504 self.__isConfig = False
504 self.__isConfig = False
505 self.WIDTH = 600
505 self.WIDTH = 600
506 self.HEIGHT = 200
506 self.HEIGHT = 200
507
507
508 def getSubplots(self):
508 def getSubplots(self):
509
509
510 nrow = self.nplots
510 nrow = self.nplots
511 ncol = 3
511 ncol = 3
512 return nrow, ncol
512 return nrow, ncol
513
513
514 def setup(self, idfigure, nplots, wintitle):
514 def setup(self, idfigure, nplots, wintitle):
515
515
516 self.createFigure(idfigure, wintitle)
516 self.createFigure(idfigure, wintitle)
517
517
518 nrow,ncol = self.getSubplots()
518 nrow,ncol = self.getSubplots()
519 colspan = 3
519 colspan = 3
520 rowspan = 1
520 rowspan = 1
521
521
522 for i in range(nplots):
522 for i in range(nplots):
523 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
523 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
524
524
525 self.nplots = nplots
525 self.nplots = nplots
526
526
527 def run(self, dataOut, idfigure, wintitle="", channelList=None,
527 def run(self, dataOut, idfigure, wintitle="", channelList=None,
528 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):
529
529
530 """
530 """
531
531
532 Input:
532 Input:
533 dataOut :
533 dataOut :
534 idfigure :
534 idfigure :
535 wintitle :
535 wintitle :
536 channelList :
536 channelList :
537 xmin : None,
537 xmin : None,
538 xmax : None,
538 xmax : None,
539 ymin : None,
539 ymin : None,
540 ymax : None,
540 ymax : None,
541 """
541 """
542
542
543 if channelList == None:
543 if channelList == None:
544 channelIndexList = dataOut.channelIndexList
544 channelIndexList = dataOut.channelIndexList
545 else:
545 else:
546 channelIndexList = []
546 channelIndexList = []
547 for channel in channelList:
547 for channel in channelList:
548 if channel not in dataOut.channelList:
548 if channel not in dataOut.channelList:
549 raise ValueError, "Channel %d is not in dataOut.channelList"
549 raise ValueError, "Channel %d is not in dataOut.channelList"
550 channelIndexList.append(dataOut.channelList.index(channel))
550 channelIndexList.append(dataOut.channelList.index(channel))
551
551
552 x = dataOut.heightList
552 x = dataOut.heightList
553 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
553 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
554 y = y.real
554 y = y.real
555
555
556 noise = dataOut.getNoise()
556 noise = dataOut.getNoise()
557
557
558 if not self.__isConfig:
558 if not self.__isConfig:
559 nplots = len(channelList)
559 nplots = len(channelList)
560
560
561 self.setup(idfigure=idfigure,
561 self.setup(idfigure=idfigure,
562 nplots=nplots,
562 nplots=nplots,
563 wintitle=wintitle)
563 wintitle=wintitle)
564
564
565 if xmin == None: xmin = numpy.nanmin(x)
565 if xmin == None: xmin = numpy.nanmin(x)
566 if xmax == None: xmax = numpy.nanmax(x)
566 if xmax == None: xmax = numpy.nanmax(x)
567 if ymin == None: ymin = numpy.nanmin(y)
567 if ymin == None: ymin = numpy.nanmin(y)
568 if ymax == None: ymax = numpy.nanmax(y)
568 if ymax == None: ymax = numpy.nanmax(y)
569
569
570 self.__isConfig = True
570 self.__isConfig = True
571
571
572
572
573 thisDatetime = dataOut.datatime
573 thisDatetime = dataOut.datatime
574 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
574 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
575 xlabel = "Range (Km)"
575 xlabel = "Range (Km)"
576 ylabel = "Intensity"
576 ylabel = "Intensity"
577
577
578 self.setWinTitle(title)
578 self.setWinTitle(title)
579
579
580 for i in range(len(self.axesList)):
580 for i in range(len(self.axesList)):
581 title = "Channel %d: %4.2fdB" %(i, noise[i])
581 title = "Channel %d: %4.2fdB" %(i, noise[i])
582 axes = self.axesList[i]
582 axes = self.axesList[i]
583 ychannel = y[i,:]
583 ychannel = y[i,:]
584 axes.pline(x, ychannel,
584 axes.pline(x, ychannel,
585 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
585 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
586 xlabel=xlabel, ylabel=ylabel, title=title)
586 xlabel=xlabel, ylabel=ylabel, title=title)
587
587
588 self.draw()
588 self.draw()
589
589
590 if save:
590 if save:
591 self.saveFigure(filename)
591 self.saveFigure(filename)
592
593 class ProfilePlot(Figure):
594 __isConfig = None
595 __nsubplots = None
596
597 WIDTHPROF = None
598 HEIGHTPROF = None
599 PREFIX = 'spcprofile'
600
601 def __init__(self):
602 self.__isConfig = False
603 self.__nsubplots = 1
604
605 self.WIDTH = 300
606 self.HEIGHT = 500
607
608 def getSubplots(self):
609 ncol = 1
610 nrow = 1
611
612 return nrow, ncol
613
614 def setup(self, idfigure, nplots, wintitle):
615
616 self.nplots = nplots
617
618 ncolspan = 1
619 colspan = 1
620
621 self.createFigure(idfigure = idfigure,
622 wintitle = wintitle,
623 widthplot = self.WIDTH,
624 heightplot = self.HEIGHT)
625
626 nrow, ncol = self.getSubplots()
627
628 counter = 0
629 for y in range(nrow):
630 for x in range(ncol):
631 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
632
633 def run(self, dataOut, idfigure, wintitle="", channelList=None,
634 xmin=None, xmax=None, ymin=None, ymax=None,
635 save=False, figpath='./', figfile=None):
636
637 if channelList == None:
638 channelIndexList = dataOut.channelIndexList
639 channelList = dataOut.channelList
640 else:
641 channelIndexList = []
642 for channel in channelList:
643 if channel not in dataOut.channelList:
644 raise ValueError, "Channel %d is not in dataOut.channelList"
645 channelIndexList.append(dataOut.channelList.index(channel))
646
647
648 y = dataOut.getHeiRange()
649 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
650 avg = numpy.average(x, axis=1)
651
652
653 if not self.__isConfig:
654
655 nplots = 1
656
657 self.setup(idfigure=idfigure,
658 nplots=nplots,
659 wintitle=wintitle)
660
661 if ymin == None: ymin = numpy.nanmin(y)
662 if ymax == None: ymax = numpy.nanmax(y)
663 if xmin == None: xmin = numpy.nanmin(avg)*0.9
664 if xmax == None: xmax = numpy.nanmax(avg)*0.9
665
666 self.__isConfig = True
667
668 thisDatetime = dataOut.datatime
669 title = "Power Profile"
670 xlabel = "dB"
671 ylabel = "Range (Km)"
672
673 self.setWinTitle(title)
674
675
676 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
677 axes = self.axesList[0]
678
679 legendlabels = ["channel %d"%x for x in channelList]
680 axes.pmultiline(avg, y,
681 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
682 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
683 ytick_visible=True, nxticks=5,
684 grid='x')
685
686 self.draw()
687
688 if save:
689 date = thisDatetime.strftime("%Y%m%d")
690 if figfile == None:
691 figfile = self.getFilename(name = date)
692
693 self.saveFigure(figpath, figfile)
694
695 class CoherencePlot(Figure):
696 __isConfig = None
697 __nsubplots = None
698
699 WIDTHPROF = None
700 HEIGHTPROF = None
701 PREFIX = 'coherencemap'
702
703 def __init__(self):
704 self.__timerange = 24*60*60
705 self.__isConfig = False
706 self.__nsubplots = 1
707
708 self.WIDTH = 800
709 self.HEIGHT = 200
710 self.WIDTHPROF = 120
711 self.HEIGHTPROF = 0
712
713 def getSubplots(self):
714 ncol = 1
715 nrow = self.nplots*2
716
717 return nrow, ncol
718
719 def setup(self, idfigure, nplots, wintitle, showprofile=True):
720 self.__showprofile = showprofile
721 self.nplots = nplots
722
723 ncolspan = 1
724 colspan = 1
725 if showprofile:
726 ncolspan = 7
727 colspan = 6
728 self.__nsubplots = 2
729
730 self.createFigure(idfigure = idfigure,
731 wintitle = wintitle,
732 widthplot = self.WIDTH + self.WIDTHPROF,
733 heightplot = self.HEIGHT + self.HEIGHTPROF)
734
735 nrow, ncol = self.getSubplots()
736
737 for y in range(nrow):
738 for x in range(ncol):
739
740 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
741
742 if showprofile:
743 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
744
745 def __getTimeLim(self, x, xmin, xmax):
746
747 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
748 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
749
750 ####################################################
751 #If the x is out of xrange
752 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
753 xmin = None
754 xmax = None
755
756 if xmin == None:
757 td = thisdatetime - thisdate
758 xmin = td.seconds/(60*60.)
759
760 if xmax == None:
761 xmax = xmin + self.__timerange/(60*60.)
762
763 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
764 tmin = time.mktime(mindt.timetuple())
765
766 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
767 tmax = time.mktime(maxdt.timetuple())
768
769 self.__timerange = tmax - tmin
770
771 return tmin, tmax
772
773 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
774 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
775 timerange=None,
776 save=False, figpath='./', figfile=None):
777
778 if pairsList == None:
779 pairsIndexList = dataOut.pairsIndexList
780 else:
781 pairsIndexList = []
782 for pair in pairsList:
783 if pair not in dataOut.pairsList:
784 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
785 pairsIndexList.append(dataOut.pairsList.index(pair))
786
787 if timerange != None:
788 self.__timerange = timerange
789
790 tmin = None
791 tmax = None
792 x = dataOut.getTimeRange()
793 y = dataOut.getHeiRange()
794
795 if not self.__isConfig:
796 nplots = len(pairsIndexList)
797 self.setup(idfigure=idfigure,
798 nplots=nplots,
799 wintitle=wintitle,
800 showprofile=showprofile)
801
802 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
803 if ymin == None: ymin = numpy.nanmin(y)
804 if ymax == None: ymax = numpy.nanmax(y)
805
806 self.__isConfig = True
807
808 thisDatetime = dataOut.datatime
809 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
810 xlabel = ""
811 ylabel = "Range (Km)"
812
813 self.setWinTitle(title)
814
815 for i in range(self.nplots):
816
817 pair = dataOut.pairsList[pairsIndexList[i]]
818 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
819 coherence = numpy.abs(coherenceComplex)
820 avg = numpy.average(coherence, axis=0)
821 z = avg.reshape((1,-1))
822
823 counter = 0
824
825 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
826 axes = self.axesList[i*self.__nsubplots*2]
827 axes.pcolor(x, y, z,
828 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
829 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
830 ticksize=9, cblabel='', cbsize="1%")
831
832 if self.__showprofile:
833 counter += 1
834 axes = self.axesList[i*self.__nsubplots*2 + counter]
835 axes.pline(avg, y,
836 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
837 xlabel='', ylabel='', title='', ticksize=7,
838 ytick_visible=False, nxticks=5,
839 grid='x')
840
841 counter += 1
842 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
843 avg = numpy.average(phase, axis=0)
844 z = avg.reshape((1,-1))
845
846 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
847 axes = self.axesList[i*self.__nsubplots*2 + counter]
848 axes.pcolor(x, y, z,
849 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
850 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
851 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
852
853 if self.__showprofile:
854 counter += 1
855 axes = self.axesList[i*self.__nsubplots*2 + counter]
856 axes.pline(avg, y,
857 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
858 xlabel='', ylabel='', title='', ticksize=7,
859 ytick_visible=False, nxticks=4,
860 grid='x')
861
862 self.draw()
863
864 if save:
865 date = thisDatetime.strftime("%Y%m%d")
866 if figfile == None:
867 figfile = self.getFilename(name = date)
868
869 self.saveFigure(figpath, figfile)
870
871 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
872 self.__isConfig = False
873
592 No newline at end of file
874
General Comments 0
You need to be logged in to leave comments. Login now