##// END OF EJS Templates
-Se agrego la funcionalidad de replotear el grafico de RTI, ademas de los parametros timerange, xmin, xmax...
Miguel Valdez -
r210:dc8fe29c201e
parent child
Show More
@@ -1,262 +1,284
1 import numpy
1 import numpy
2 import mpldriver
2 import mpldriver
3
3
4
4
5 class Figure:
5 class Figure:
6
6
7 __driver = mpldriver
7 __driver = mpldriver
8 fig = None
8 fig = None
9
9
10 idfigure = None
10 idfigure = None
11 wintitle = None
11 wintitle = None
12 width = None
12 width = None
13 height = None
13 height = None
14 nplots = None
14 nplots = None
15
15
16 axesObjList = []
16 axesObjList = []
17
17
18 WIDTH = None
18 WIDTH = None
19 HEIGHT = None
19 HEIGHT = None
20
20
21 def __init__(self):
21 def __init__(self):
22
22
23 raise ValueError, "This method is not implemented"
23 raise ValueError, "This method is not implemented"
24
24
25 def __del__(self):
25 def __del__(self):
26
26
27 self.__driver.closeFigure()
27 self.__driver.closeFigure()
28
28
29 def getAxesObjList(self):
29 def getAxesObjList(self):
30
30
31 return self.axesObjList
31 return self.axesObjList
32
32
33 def getSubplots(self):
33 def getSubplots(self):
34
34
35 raise ValueError, "Abstract method: This method should be defined"
35 raise ValueError, "Abstract method: This method should be defined"
36
36
37 def getScreenDim(self):
37 def getScreenDim(self, widthplot, heightplot):
38
38
39 nrow, ncol = self.getSubplots()
39 nrow, ncol = self.getSubplots()
40
40
41 width = self.WIDTH*ncol
41 widthscreen = widthplot*ncol
42 height = self.HEIGHT*nrow
42 heightscreen = heightplot*nrow
43
43
44 return width, height
44 return widthscreen, heightscreen
45
45
46 def init(self, idfigure, nplots, wintitle):
46 def init(self, idfigure, nplots, wintitle):
47
47
48 raise ValueError, "This method has been replaced with createFigure"
48 raise ValueError, "This method has been replaced with createFigure"
49
49
50 def createFigure(self, idfigure, wintitle):
50 def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None):
51
51
52 """
52 """
53 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
53 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
54 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
54 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
55 y self.HEIGHT y el numero de subplots (nrow, ncol)
55 y self.HEIGHT y el numero de subplots (nrow, ncol)
56
56
57 Input:
57 Input:
58 idfigure : Los parametros necesarios son
58 idfigure : Los parametros necesarios son
59 wintitle :
59 wintitle :
60
60
61 """
61 """
62
62
63 if widthplot == None:
64 widthplot = self.WIDTH
65
66 if heightplot == None:
67 heightplot = self.HEIGHT
68
63 self.idfigure = idfigure
69 self.idfigure = idfigure
64
70
65 self.wintitle = wintitle
71 self.wintitle = wintitle
66
72
67 self.width, self.height = self.getScreenDim()
73 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
68
74
69 self.fig = self.__driver.createFigure(self.idfigure,
75 self.fig = self.__driver.createFigure(self.idfigure,
70 self.wintitle,
76 self.wintitle,
71 self.width,
77 self.widthscreen,
72 self.height)
78 self.heightscreen)
73
79
74 self.axesObjList = []
80 self.axesObjList = []
75
81
76 def setDriver(self, driver=mpldriver):
82 def setDriver(self, driver=mpldriver):
77
83
78 self.__driver = driver
84 self.__driver = driver
79
85
80 def setTitle(self, title):
86 def setTitle(self, title):
81
87
82 self.__driver.setTitle(self.fig, title)
88 self.__driver.setTitle(self.fig, title)
83
89
84 def setWinTitle(self, title):
90 def setWinTitle(self, title):
85
91
86 self.__driver.setWinTitle(self.fig, title=title)
92 self.__driver.setWinTitle(self.fig, title=title)
87
93
88 def setTextFromAxes(self, text):
94 def setTextFromAxes(self, text):
89
95
90 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
96 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
91
97
92 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
98 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
93
99
94 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
100 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
95
101
96 def addAxes(self, *args):
102 def addAxes(self, *args):
97 """
103 """
98
104
99 Input:
105 Input:
100 *args : Los parametros necesarios son
106 *args : Los parametros necesarios son
101 nrow, ncol, xpos, ypos, colspan, rowspan
107 nrow, ncol, xpos, ypos, colspan, rowspan
102 """
108 """
103
109
104 axesObj = Axes(self.fig, *args)
110 axesObj = Axes(self.fig, *args)
105 self.axesObjList.append(axesObj)
111 self.axesObjList.append(axesObj)
106
112
107 def saveFigure(self, *args):
113 def saveFigure(self, *args):
108 self.__driver.saveFigure(self.fig, *args)
114 self.__driver.saveFigure(self.fig, *args)
109
115
110 def draw(self):
116 def draw(self):
111
117
112 self.__driver.draw(self.fig)
118 self.__driver.draw(self.fig)
113
119
114 def run(self):
120 def run(self):
115
121
116 raise ValueError, "This method is not implemented"
122 raise ValueError, "This method is not implemented"
117
123
118 axesList = property(getAxesObjList)
124 axesList = property(getAxesObjList)
119
125
120
126
121 class Axes:
127 class Axes:
122
128
123 __driver = mpldriver
129 __driver = mpldriver
124 fig = None
130 fig = None
125 ax = None
131 ax = None
126 plot = None
132 plot = None
127
133
128 firsttime = None
134 __firsttime = None
129
135
130 __showprofile = False
136 __showprofile = False
131
137
132 __zmin = None
138 xmin = None
133 __zmax = None
139 xmax = None
140 ymin = None
141 ymax = None
142 zmin = None
143 zmax = None
134
144
135 def __init__(self, *args):
145 def __init__(self, *args):
136
146
137 """
147 """
138
148
139 Input:
149 Input:
140 *args : Los parametros necesarios son
150 *args : Los parametros necesarios son
141 fig, nrow, ncol, xpos, ypos, colspan, rowspan
151 fig, nrow, ncol, xpos, ypos, colspan, rowspan
142 """
152 """
143
153
144 ax = self.__driver.createAxes(*args)
154 ax = self.__driver.createAxes(*args)
145 self.fig = args[0]
155 self.fig = args[0]
146 self.ax = ax
156 self.ax = ax
147 self.plot = None
157 self.plot = None
148
158
149 self.firsttime = True
159 self.__firsttime = True
150
160
151 def setText(self, text):
161 def setText(self, text):
152
162
153 self.__driver.setAxesText(self.ax, text)
163 self.__driver.setAxesText(self.ax, text)
154
164
155 def setXAxisAsTime(self):
165 def setXAxisAsTime(self):
156 pass
166 pass
157
167
158 def pline(self, x, y,
168 def pline(self, x, y,
159 xmin=None, xmax=None,
169 xmin=None, xmax=None,
160 ymin=None, ymax=None,
170 ymin=None, ymax=None,
161 xlabel='', ylabel='',
171 xlabel='', ylabel='',
162 title='',
172 title='',
163 **kwargs):
173 **kwargs):
164
174
165 """
175 """
166
176
167 Input:
177 Input:
168 x :
178 x :
169 y :
179 y :
170 xmin :
180 xmin :
171 xmax :
181 xmax :
172 ymin :
182 ymin :
173 ymax :
183 ymax :
174 xlabel :
184 xlabel :
175 ylabel :
185 ylabel :
176 title :
186 title :
177 **kwargs : Los parametros aceptados son
187 **kwargs : Los parametros aceptados son
178
188
179 ticksize
189 ticksize
180 ytick_visible
190 ytick_visible
181 """
191 """
182
192
183 if self.firsttime:
193 if self.__firsttime:
184
194
185 if xmin == None: xmin = numpy.nanmin(x)
195 if xmin == None: xmin = numpy.nanmin(x)
186 if xmax == None: xmax = numpy.nanmax(x)
196 if xmax == None: xmax = numpy.nanmax(x)
187 if ymin == None: ymin = numpy.nanmin(y)
197 if ymin == None: ymin = numpy.nanmin(y)
188 if ymax == None: ymax = numpy.nanmax(y)
198 if ymax == None: ymax = numpy.nanmax(y)
189
199
190 self.plot = self.__driver.createPline(self.ax, x, y,
200 self.plot = self.__driver.createPline(self.ax, x, y,
191 xmin, xmax,
201 xmin, xmax,
192 ymin, ymax,
202 ymin, ymax,
193 xlabel=xlabel,
203 xlabel=xlabel,
194 ylabel=ylabel,
204 ylabel=ylabel,
195 title=title,
205 title=title,
196 **kwargs)
206 **kwargs)
197 self.firsttime = False
207 self.__firsttime = False
198 return
208 return
199
209
200 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
210 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
201 ylabel=ylabel,
211 ylabel=ylabel,
202 title=title)
212 title=title)
203
213
204
214
205 def pcolor(self, x, y, z,
215 def pcolor(self, x, y, z,
206 xmin=None, xmax=None,
216 xmin=None, xmax=None,
207 ymin=None, ymax=None,
217 ymin=None, ymax=None,
208 zmin=None, zmax=None,
218 zmin=None, zmax=None,
209 xlabel='', ylabel='',
219 xlabel='', ylabel='',
210 title='', rti = False,
220 title='', rti = False,
211 **kwargs):
221 **kwargs):
212
222
213 """
223 """
214 Input:
224 Input:
215 x :
225 x :
216 y :
226 y :
217 x :
227 x :
218 xmin :
228 xmin :
219 xmax :
229 xmax :
220 ymin :
230 ymin :
221 ymax :
231 ymax :
222 zmin :
232 zmin :
223 zmax :
233 zmax :
224 xlabel :
234 xlabel :
225 ylabel :
235 ylabel :
226 title :
236 title :
227 **kwargs : Los parametros aceptados son
237 **kwargs : Los parametros aceptados son
228 ticksize=9,
238 ticksize=9,
229 cblabel=''
239 cblabel=''
230 rti = True or False
240 rti = True or False
231 """
241 """
232
242
233 if self.firsttime:
243 if self.__firsttime:
234
244
235 if xmin == None: xmin = numpy.nanmin(x)
245 if xmin == None: xmin = numpy.nanmin(x)
236 if xmax == None: xmax = numpy.nanmax(x)
246 if xmax == None: xmax = numpy.nanmax(x)
237 if ymin == None: ymin = numpy.nanmin(y)
247 if ymin == None: ymin = numpy.nanmin(y)
238 if ymax == None: ymax = numpy.nanmax(y)
248 if ymax == None: ymax = numpy.nanmax(y)
239 if zmin == None: zmin = numpy.nanmin(z)
249 if zmin == None: zmin = numpy.nanmin(z)
240 if zmax == None: zmax = numpy.nanmax(z)
250 if zmax == None: zmax = numpy.nanmax(z)
241
251
242
252
243 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
253 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
244 xmin, xmax,
254 xmin, xmax,
245 ymin, ymax,
255 ymin, ymax,
246 zmin, zmax,
256 zmin, zmax,
247 xlabel=xlabel,
257 xlabel=xlabel,
248 ylabel=ylabel,
258 ylabel=ylabel,
249 title=title,
259 title=title,
250 **kwargs)
260 **kwargs)
251 self.firsttime = False
261
252 if self.__zmin == None: self.__zmin = zmin
262 if self.xmin == None: self.xmin = xmin
253 if self.__zmax == None: self.__zmax = zmax
263 if self.xmax == None: self.xmax = xmax
264 if self.ymin == None: self.ymin = ymin
265 if self.ymax == None: self.ymax = ymax
266 if self.zmin == None: self.zmin = zmin
267 if self.zmax == None: self.zmax = zmax
268
269 self.__firsttime = False
254 return
270 return
255
271
256 if rti:
272 if rti:
257 self.__driver.addpcolor(self.ax, x, y, z, self.__zmin, self.__zmax)
273 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
274 xlabel=xlabel,
275 ylabel=ylabel,
276 title=title)
258 return
277 return
259
278
260 self.__driver.pcolor(self.plot, z, xlabel=xlabel, ylabel=ylabel, title=title)
279 self.__driver.pcolor(self.plot, z,
280 xlabel=xlabel,
281 ylabel=ylabel,
282 title=title)
261
283
262 No newline at end of file
284
@@ -1,272 +1,289
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
12 from matplotlib.ticker import *
11
13
12 def init(idfigure, wintitle, width, height, facecolor="w"):
14 def init(idfigure, wintitle, width, height, facecolor="w"):
13
15
14 matplotlib.pyplot.ioff()
16 matplotlib.pyplot.ioff()
15 fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor)
17 fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor)
16 fig.canvas.manager.set_window_title(wintitle)
18 fig.canvas.manager.set_window_title(wintitle)
17 fig.canvas.manager.resize(width, height)
19 fig.canvas.manager.resize(width, height)
18 matplotlib.pyplot.ion()
20 matplotlib.pyplot.ion()
19
21
20 return fig
22 return fig
21
23
22 def setWinTitle(fig, title):
24 def setWinTitle(fig, title):
23
25
24 fig.canvas.manager.set_window_title(title)
26 fig.canvas.manager.set_window_title(title)
25
27
26 def setTitle(idfigure, title):
28 def setTitle(idfigure, title):
27 fig = matplotlib.pyplot.figure(idfigure)
29 fig = matplotlib.pyplot.figure(idfigure)
28 fig.suptitle(title)
30 fig.suptitle(title)
29
31
30 def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan):
32 def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan):
31 fig = matplotlib.pyplot.figure(idfigure)
33 fig = matplotlib.pyplot.figure(idfigure)
32 ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan)
34 ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan)
33 return ax
35 return ax
34
36
35 def setTextFromAxes(idfigure, ax, title):
37 def setTextFromAxes(idfigure, ax, title):
36 fig = matplotlib.pyplot.figure(idfigure)
38 fig = matplotlib.pyplot.figure(idfigure)
37 ax.annotate(title, xy=(.1, .99),
39 ax.annotate(title, xy=(.1, .99),
38 xycoords='figure fraction',
40 xycoords='figure fraction',
39 horizontalalignment='left', verticalalignment='top',
41 horizontalalignment='left', verticalalignment='top',
40 fontsize=10)
42 fontsize=10)
41
43
42 def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime):
44 def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime):
43
45
44 if firsttime:
46 if firsttime:
45 ax.plot(x, y)
47 ax.plot(x, y)
46 ax.set_xlim([xmin,xmax])
48 ax.set_xlim([xmin,xmax])
47 ax.set_ylim([ymin,ymax])
49 ax.set_ylim([ymin,ymax])
48 ax.set_xlabel(xlabel, size=8)
50 ax.set_xlabel(xlabel, size=8)
49 ax.set_ylabel(ylabel, size=8)
51 ax.set_ylabel(ylabel, size=8)
50 ax.set_title(title, size=10)
52 ax.set_title(title, size=10)
51 matplotlib.pyplot.tight_layout()
53 matplotlib.pyplot.tight_layout()
52 else:
54 else:
53 ax.lines[0].set_data(x,y)
55 ax.lines[0].set_data(x,y)
54
56
55 def draw(idfigure):
57 def draw(idfigure):
56
58
57 fig = matplotlib.pyplot.figure(idfigure)
59 fig = matplotlib.pyplot.figure(idfigure)
58 fig.canvas.draw()
60 fig.canvas.draw()
59
61
60 def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh):
62 def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh):
61
63
62 if firsttime:
64 if firsttime:
63 divider = make_axes_locatable(ax)
65 divider = make_axes_locatable(ax)
64 ax_cb = divider.new_horizontal(size="4%", pad=0.05)
66 ax_cb = divider.new_horizontal(size="4%", pad=0.05)
65 fig1 = ax.get_figure()
67 fig1 = ax.get_figure()
66 fig1.add_axes(ax_cb)
68 fig1.add_axes(ax_cb)
67
69
68 ax.set_xlim([xmin,xmax])
70 ax.set_xlim([xmin,xmax])
69 ax.set_ylim([ymin,ymax])
71 ax.set_ylim([ymin,ymax])
70 ax.set_xlabel(xlabel)
72 ax.set_xlabel(xlabel)
71 ax.set_ylabel(ylabel)
73 ax.set_ylabel(ylabel)
72 ax.set_title(title)
74 ax.set_title(title)
73 print x
75 print x
74 imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax)
76 imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax)
75 matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
77 matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
76 ax_cb.yaxis.tick_right()
78 ax_cb.yaxis.tick_right()
77 for tl in ax_cb.get_yticklabels():
79 for tl in ax_cb.get_yticklabels():
78 tl.set_visible(True)
80 tl.set_visible(True)
79 ax_cb.yaxis.tick_right()
81 ax_cb.yaxis.tick_right()
80 matplotlib.pyplot.tight_layout()
82 matplotlib.pyplot.tight_layout()
81 return imesh
83 return imesh
82 else:
84 else:
83 # ax.set_xlim([xmin,xmax])
85 # ax.set_xlim([xmin,xmax])
84 # ax.set_ylim([ymin,ymax])
86 # ax.set_ylim([ymin,ymax])
85 ax.set_xlabel(xlabel)
87 ax.set_xlabel(xlabel)
86 ax.set_ylabel(ylabel)
88 ax.set_ylabel(ylabel)
87 ax.set_title(title)
89 ax.set_title(title)
88
90
89 z = z.T
91 z = z.T
90 # z = z[0:-1,0:-1]
92 # z = z[0:-1,0:-1]
91 mesh.set_array(z.ravel())
93 mesh.set_array(z.ravel())
92
94
93 return mesh
95 return mesh
94
96
95 ###########################################
97 ###########################################
96 #Actualizacion de las funciones del driver
98 #Actualizacion de las funciones del driver
97 ###########################################
99 ###########################################
98
100
99 def createFigure(idfigure, wintitle, width, height, facecolor="w"):
101 def createFigure(idfigure, wintitle, width, height, facecolor="w"):
100
102
101 matplotlib.pyplot.ioff()
103 matplotlib.pyplot.ioff()
102 fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor)
104 fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor)
103 fig.canvas.manager.set_window_title(wintitle)
105 fig.canvas.manager.set_window_title(wintitle)
104 fig.canvas.manager.resize(width, height)
106 fig.canvas.manager.resize(width, height)
105 matplotlib.pyplot.ion()
107 matplotlib.pyplot.ion()
106
108
107 return fig
109 return fig
108
110
109 def closeFigure():
111 def closeFigure():
110
112
111 matplotlib.pyplot.ioff()
113 matplotlib.pyplot.ioff()
112 matplotlib.pyplot.show()
114 matplotlib.pyplot.show()
113
115
114 return
116 return
115
117
116 def saveFigure(fig, filename):
118 def saveFigure(fig, filename):
117 fig.savefig(filename)
119 fig.savefig(filename)
118
120
119 def setWinTitle(fig, title):
121 def setWinTitle(fig, title):
120
122
121 fig.canvas.manager.set_window_title(title)
123 fig.canvas.manager.set_window_title(title)
122
124
123 def setTitle(fig, title):
125 def setTitle(fig, title):
124
126
125 fig.suptitle(title)
127 fig.suptitle(title)
126
128
127 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan):
129 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan):
128
130
129 matplotlib.pyplot.figure(fig.number)
131 matplotlib.pyplot.figure(fig.number)
130 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
132 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
131 (xpos, ypos),
133 (xpos, ypos),
132 colspan=colspan,
134 colspan=colspan,
133 rowspan=rowspan)
135 rowspan=rowspan)
134 return axes
136 return axes
135
137
136 def setAxesText(ax, text):
138 def setAxesText(ax, text):
137
139
138 ax.annotate(text,
140 ax.annotate(text,
139 xy = (.1, .99),
141 xy = (.1, .99),
140 xycoords = 'figure fraction',
142 xycoords = 'figure fraction',
141 horizontalalignment = 'left',
143 horizontalalignment = 'left',
142 verticalalignment = 'top',
144 verticalalignment = 'top',
143 fontsize = 10)
145 fontsize = 10)
144
146
145 def printLabels(ax, xlabel, ylabel, title):
147 def printLabels(ax, xlabel, ylabel, title):
146
148
147 ax.set_xlabel(xlabel, size=11)
149 ax.set_xlabel(xlabel, size=11)
148 ax.set_ylabel(ylabel, size=11)
150 ax.set_ylabel(ylabel, size=11)
149 ax.set_title(title, size=12)
151 ax.set_title(title, size=12)
150
152
151 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
153 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
152 ticksize=9, xtick_visible=True, ytick_visible=True,
154 ticksize=9, xtick_visible=True, ytick_visible=True,
153 nxticks=4, nyticks=10,
155 nxticks=4, nyticks=10,
154 grid=None):
156 grid=None):
155
157
156 """
158 """
157
159
158 Input:
160 Input:
159 grid : None, 'both', 'x', 'y'
161 grid : None, 'both', 'x', 'y'
160 """
162 """
161
163
162 ax.plot(x, y)
164 ax.plot(x, y)
163 ax.set_xlim([xmin,xmax])
165 ax.set_xlim([xmin,xmax])
164 ax.set_ylim([ymin,ymax])
166 ax.set_ylim([ymin,ymax])
165
167
166 printLabels(ax, xlabel, ylabel, title)
168 printLabels(ax, xlabel, ylabel, title)
167
169
168 ######################################################
170 ######################################################
169 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin)
171 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin)
170 ax.set_xticks(xtickspos)
172 ax.set_xticks(xtickspos)
171
173
172 for tick in ax.get_xticklabels():
174 for tick in ax.get_xticklabels():
173 tick.set_visible(xtick_visible)
175 tick.set_visible(xtick_visible)
174
176
175 for tick in ax.xaxis.get_major_ticks():
177 for tick in ax.xaxis.get_major_ticks():
176 tick.label.set_fontsize(ticksize)
178 tick.label.set_fontsize(ticksize)
177
179
178 ######################################################
180 ######################################################
179 for tick in ax.get_yticklabels():
181 for tick in ax.get_yticklabels():
180 tick.set_visible(ytick_visible)
182 tick.set_visible(ytick_visible)
181
183
182 for tick in ax.yaxis.get_major_ticks():
184 for tick in ax.yaxis.get_major_ticks():
183 tick.label.set_fontsize(ticksize)
185 tick.label.set_fontsize(ticksize)
184
186
185 ######################################################
187 ######################################################
186 if grid != None:
188 if grid != None:
187 ax.grid(b=True, which='major', axis=grid)
189 ax.grid(b=True, which='major', axis=grid)
188
190
189 matplotlib.pyplot.tight_layout()
191 matplotlib.pyplot.tight_layout()
190
192
191 iplot = ax.lines[-1]
193 iplot = ax.lines[-1]
192
194
193 return iplot
195 return iplot
194
196
195 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
197 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
196
198
197 ax = iplot.get_axes()
199 ax = iplot.get_axes()
198
200
199 printLabels(ax, xlabel, ylabel, title)
201 printLabels(ax, xlabel, ylabel, title)
200
202
201 iplot.set_data(x, y)
203 iplot.set_data(x, y)
202
204
203 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel='',XAxisAsTime=False):
205 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
206 xlabel='', ylabel='', title='', ticksize = 9,
207 cblabel='',XAxisAsTime=False):
204
208
205 divider = make_axes_locatable(ax)
209 divider = make_axes_locatable(ax)
206 ax_cb = divider.new_horizontal(size="4%", pad=0.05)
210 ax_cb = divider.new_horizontal(size="4%", pad=0.05)
207 fig = ax.get_figure()
211 fig = ax.get_figure()
208 fig.add_axes(ax_cb)
212 fig.add_axes(ax_cb)
209
213
210 ax.set_xlim([xmin,xmax])
214 ax.set_xlim([xmin,xmax])
211
212 if XAxisAsTime:
213 seconds = numpy.array([xmin, xmax])
214 datesList = map(datetime.datetime.fromtimestamp, seconds)
215 ax.set_xlim([datesList[0],datesList[-1]])
216 ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10)))
217 ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60)))
218 ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S"))
219 xdateList = map(datetime.datetime.fromtimestamp, x)
220 xdate = matplotlib.dates.date2num(xdateList)
221 x = xdate
222
223
224 ax.set_ylim([ymin,ymax])
215 ax.set_ylim([ymin,ymax])
225
216
226 printLabels(ax, xlabel, ylabel, title)
217 printLabels(ax, xlabel, ylabel, title)
227
218
228 imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax)
219 imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax)
229 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
220 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
230 cb.set_label(cblabel)
221 cb.set_label(cblabel)
231
222
232 ax_cb.yaxis.tick_right()
223 ax_cb.yaxis.tick_right()
233
224
234 for tl in ax_cb.get_yticklabels():
225 # for tl in ax_cb.get_yticklabels():
235 tl.set_visible(True)
226 # tl.set_visible(True)
236
227
237 for tick in ax.yaxis.get_major_ticks():
228 for tick in ax.yaxis.get_major_ticks():
238 tick.label.set_fontsize(ticksize)
229 tick.label.set_fontsize(ticksize)
239
230
240 for tick in ax.xaxis.get_major_ticks():
231 for tick in ax.xaxis.get_major_ticks():
241 tick.label.set_fontsize(ticksize)
232 tick.label.set_fontsize(ticksize)
242
233
243 for tick in cb.ax.get_yticklabels():
234 for tick in cb.ax.get_yticklabels():
244 tick.set_fontsize(ticksize)
235 tick.set_fontsize(ticksize)
245
236
246 ax_cb.yaxis.tick_right()
237 ax_cb.yaxis.tick_right()
247 matplotlib.pyplot.tight_layout()
238 matplotlib.pyplot.tight_layout()
248
239
240 if XAxisAsTime:
241
242 func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime("%H:%M:%S"))
243 ax.xaxis.set_major_formatter(FuncFormatter(func))
244 ax.xaxis.set_major_locator(LinearLocator(7))
245
246 # seconds = numpy.array([xmin, xmax])
247 # datesList = map(datetime.datetime.fromtimestamp, seconds)
248 # ax.set_xlim([datesList[0],datesList[-1]])
249 # ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10)))
250 # ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60)))
251 # ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S"))
252 # xdateList = map(datetime.datetime.fromtimestamp, x)
253 # xdate = matplotlib.dates.date2num(xdateList)
254 # x = xdate
255
256 # labels = []
257 # for item in ax.xaxis.get_ticklabels():
258 # stri = item.get_text()
259 # text = datetime.datetime.fromtimestamp(float(stri))
260 # labels.append(text)
261 #
262 # ax.xaxis.set_ticklabels(labels)
249 return imesh
263 return imesh
250
264
251 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
265 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
252
266
253 z = z.T
267 z = z.T
254
268
255 ax = imesh.get_axes()
269 ax = imesh.get_axes()
256
270
257 printLabels(ax, xlabel, ylabel, title)
271 printLabels(ax, xlabel, ylabel, title)
258
272
259 imesh.set_array(z.ravel())
273 imesh.set_array(z.ravel())
260
274
261 def addpcolor(ax, x, y, z, zmin, zmax):
275 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title=''):
262 xdateList = map(datetime.datetime.fromtimestamp, x)
276
263 xdate = matplotlib.dates.date2num(xdateList)
277 # xdateList = map(datetime.datetime.fromtimestamp, x)
278 # xdate = matplotlib.dates.date2num(xdateList)
264
279
265 imesh = ax.pcolormesh(xdate,y,z.T,vmin=zmin,vmax=zmax)
280 printLabels(ax, xlabel, ylabel, title)
281
282 imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax)
266
283
267 def draw(fig):
284 def draw(fig):
268
285
269 if type(fig) == 'int':
286 if type(fig) == 'int':
270 raise ValueError, "This parameter should be of tpye matplotlib figure"
287 raise ValueError, "This parameter should be of tpye matplotlib figure"
271
288
272 fig.canvas.draw() No newline at end of file
289 fig.canvas.draw()
@@ -1,371 +1,410
1 import numpy
1 import numpy
2 import datetime
2 import time, datetime
3 from graphics.figure import *
3 from graphics.figure import *
4
4
5 class RTIPlot(Figure):
5 class RTIPlot(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
12
13 def __init__(self):
13 def __init__(self):
14
14
15 self.__timerange = 30*60
15 self.__timerange = 24*60*60
16 self.__isConfig = False
16 self.__isConfig = False
17 self.__nsubplots = 1
17 self.__nsubplots = 1
18
18
19 self.WIDTH = 800
19 self.WIDTH = 800
20 self.HEIGHT = 400
20 self.HEIGHT = 300
21 self.WIDTHPROF = 120
21 self.WIDTHPROF = 120
22 self.HEIGHTPROF = 0
22 self.HEIGHTPROF = 0
23
23
24 def getSubplots(self):
24 def getSubplots(self):
25
25
26 ncol = 1
26 ncol = 1
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 if showprofile:
38 if showprofile:
39 ncolspan = 7
39 ncolspan = 7
40 colspan = 6
40 colspan = 6
41 self.__nsubplots = 2
41 self.__nsubplots = 2
42 self.WIDTH += self.WIDTHPROF
43 self.HEIGHT += self.HEIGHTPROF
44
42
45 self.createFigure(idfigure, wintitle)
43 self.createFigure(idfigure = idfigure,
44 wintitle = wintitle,
45 widthplot = self.WIDTH + self.WIDTHPROF,
46 heightplot = self.HEIGHT + self.HEIGHTPROF)
46
47
47 nrow, ncol = self.getSubplots()
48 nrow, ncol = self.getSubplots()
48
49
49 counter = 0
50 counter = 0
50 for y in range(nrow):
51 for y in range(nrow):
51 for x in range(ncol):
52 for x in range(ncol):
52
53
53 if counter >= self.nplots:
54 if counter >= self.nplots:
54 break
55 break
55
56
56 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
57 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
57
58
58 if showprofile:
59 if showprofile:
59 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
60 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
60
61
61 counter += 1
62 counter += 1
62
63
64 def __getTimeLim(self, x, xmin, xmax):
65
66 thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x))
67 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
68
69 ####################################################
70 #If the x is out of xrange
71 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
72 xmin = None
73 xmax = None
74
75 if xmin == None:
76 td = thisdatetime - thisdate
77 xmin = td.seconds/(60*60.)
78
79 if xmax == None:
80 xmax = xmin + self.__timerange/(60*60.)
81
82 mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin)
83 tmin = time.mktime(mindt.timetuple())
84
85 maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax)
86 tmax = time.mktime(maxdt.timetuple())
87
88 self.__timerange = tmax - tmin
89
90 return tmin, tmax
91
63 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
92 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
64 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None):
93 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
94 timerange=None,
95 save=False, filename=None):
65
96
66 """
97 """
67
98
68 Input:
99 Input:
69 dataOut :
100 dataOut :
70 idfigure :
101 idfigure :
71 wintitle :
102 wintitle :
72 channelList :
103 channelList :
73 showProfile :
104 showProfile :
74 xmin : None,
105 xmin : None,
75 xmax : None,
106 xmax : None,
76 ymin : None,
107 ymin : None,
77 ymax : None,
108 ymax : None,
78 zmin : None,
109 zmin : None,
79 zmax : None
110 zmax : None
80 """
111 """
81
112
82 if channelList == None:
113 if channelList == None:
83 channelIndexList = dataOut.channelIndexList
114 channelIndexList = dataOut.channelIndexList
84 else:
115 else:
85 channelIndexList = []
116 channelIndexList = []
86 for channel in channelList:
117 for channel in channelList:
87 if channel not in dataOut.channelList:
118 if channel not in dataOut.channelList:
88 raise ValueError, "Channel %d is not in dataOut.channelList"
119 raise ValueError, "Channel %d is not in dataOut.channelList"
89 channelIndexList.append(channel)
120 channelIndexList.append(channel)
90
121
122 if timerange != None:
123 self.__timerange = timerange
124
125 tmin = None
126 tmax = None
91 x = dataOut.getDatatime()
127 x = dataOut.getDatatime()
92 y = dataOut.getHeiRange()
128 y = dataOut.getHeiRange()
93 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
129 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
94 avg = numpy.average(z, axis=1)
130 avg = numpy.average(z, axis=1)
95
131
96 noise = dataOut.getNoise()
132 noise = dataOut.getNoise()
97
133
98 if not self.__isConfig:
134 if not self.__isConfig:
99
135
100 nplots = len(channelIndexList)
136 nplots = len(channelIndexList)
101
137
102 self.setup(idfigure=idfigure,
138 self.setup(idfigure=idfigure,
103 nplots=nplots,
139 nplots=nplots,
104 wintitle=wintitle,
140 wintitle=wintitle,
105 showprofile=showprofile)
141 showprofile=showprofile)
106
142
107 if xmin == None: xmin = numpy.min(x)
143 tmin, tmax = self.__getTimeLim(x, xmin, xmax)
108 if xmax == None: xmax = xmin + self.__timerange
109 if ymin == None: ymin = numpy.nanmin(y)
144 if ymin == None: ymin = numpy.nanmin(y)
110 if ymax == None: ymax = numpy.nanmax(y)
145 if ymax == None: ymax = numpy.nanmax(y)
111 if zmin == None: zmin = numpy.nanmin(avg)*0.9
146 if zmin == None: zmin = numpy.nanmin(avg)*0.9
112 if zmax == None: zmax = numpy.nanmax(avg)*0.9
147 if zmax == None: zmax = numpy.nanmax(avg)*0.9
113
148
114 self.__isConfig = True
149 self.__isConfig = True
115
150
116 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
151 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
117 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
152 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
118 xlabel = "Velocity (m/s)"
153 xlabel = "Velocity (m/s)"
119 ylabel = "Range (Km)"
154 ylabel = "Range (Km)"
120
155
121 self.setWinTitle(title)
156 self.setWinTitle(title)
122
157
123 for i in range(self.nplots):
158 for i in range(self.nplots):
124 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
159 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
125 axes = self.axesList[i*self.__nsubplots]
160 axes = self.axesList[i*self.__nsubplots]
126 z = avg[i].reshape((1,-1))
161 z = avg[i].reshape((1,-1))
127 axes.pcolor(x, y, z,
162 axes.pcolor(x, y, z,
128 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
163 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
129 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
164 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
130 ticksize=9, cblabel='')
165 ticksize=9, cblabel='')
131
166
132 if self.__showprofile:
167 if self.__showprofile:
133 axes = self.axesList[i*self.__nsubplots +1]
168 axes = self.axesList[i*self.__nsubplots +1]
134 axes.pline(avg[i], y,
169 axes.pline(avg[i], y,
135 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
170 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
136 xlabel='dB', ylabel='', title='',
171 xlabel='dB', ylabel='', title='',
137 ytick_visible=False,
172 ytick_visible=False,
138 grid='x')
173 grid='x')
139
174
140 self.draw()
175 self.draw()
141
176
142 if save:
177 if save:
143 self.saveFigure(filename)
178 self.saveFigure(filename)
179
180 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
181 self.__isConfig = False
144
182
145 class SpectraPlot(Figure):
183 class SpectraPlot(Figure):
146
184
147 __isConfig = None
185 __isConfig = None
148 __nsubplots = None
186 __nsubplots = None
149
187
150 WIDTHPROF = None
188 WIDTHPROF = None
151 HEIGHTPROF = None
189 HEIGHTPROF = None
152
190
153 def __init__(self):
191 def __init__(self):
154
192
155 self.__isConfig = False
193 self.__isConfig = False
156 self.__nsubplots = 1
194 self.__nsubplots = 1
157
195
158 self.WIDTH = 300
196 self.WIDTH = 300
159 self.HEIGHT = 400
197 self.HEIGHT = 400
160 self.WIDTHPROF = 120
198 self.WIDTHPROF = 120
161 self.HEIGHTPROF = 0
199 self.HEIGHTPROF = 0
162
200
163 def getSubplots(self):
201 def getSubplots(self):
164
202
165 ncol = int(numpy.sqrt(self.nplots)+0.9)
203 ncol = int(numpy.sqrt(self.nplots)+0.9)
166 nrow = int(self.nplots*1./ncol + 0.9)
204 nrow = int(self.nplots*1./ncol + 0.9)
167
205
168 return nrow, ncol
206 return nrow, ncol
169
207
170 def setup(self, idfigure, nplots, wintitle, showprofile=True):
208 def setup(self, idfigure, nplots, wintitle, showprofile=True):
171
209
172 self.__showprofile = showprofile
210 self.__showprofile = showprofile
173 self.nplots = nplots
211 self.nplots = nplots
174
212
175 ncolspan = 1
213 ncolspan = 1
176 colspan = 1
214 colspan = 1
177 if showprofile:
215 if showprofile:
178 ncolspan = 3
216 ncolspan = 3
179 colspan = 2
217 colspan = 2
180 self.__nsubplots = 2
218 self.__nsubplots = 2
181 self.WIDTH += self.WIDTHPROF
219
182 self.HEIGHT += self.HEIGHTPROF
220 self.createFigure(idfigure = idfigure,
183
221 wintitle = wintitle,
184 self.createFigure(idfigure, wintitle)
222 widthplot = self.WIDTH + self.WIDTHPROF,
223 heightplot = self.HEIGHT + self.HEIGHTPROF)
185
224
186 nrow, ncol = self.getSubplots()
225 nrow, ncol = self.getSubplots()
187
226
188 counter = 0
227 counter = 0
189 for y in range(nrow):
228 for y in range(nrow):
190 for x in range(ncol):
229 for x in range(ncol):
191
230
192 if counter >= self.nplots:
231 if counter >= self.nplots:
193 break
232 break
194
233
195 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
234 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
196
235
197 if showprofile:
236 if showprofile:
198 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
237 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
199
238
200 counter += 1
239 counter += 1
201
240
202 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
241 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
203 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None):
242 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None):
204
243
205 """
244 """
206
245
207 Input:
246 Input:
208 dataOut :
247 dataOut :
209 idfigure :
248 idfigure :
210 wintitle :
249 wintitle :
211 channelList :
250 channelList :
212 showProfile :
251 showProfile :
213 xmin : None,
252 xmin : None,
214 xmax : None,
253 xmax : None,
215 ymin : None,
254 ymin : None,
216 ymax : None,
255 ymax : None,
217 zmin : None,
256 zmin : None,
218 zmax : None
257 zmax : None
219 """
258 """
220
259
221 if channelList == None:
260 if channelList == None:
222 channelIndexList = dataOut.channelIndexList
261 channelIndexList = dataOut.channelIndexList
223 else:
262 else:
224 channelIndexList = []
263 channelIndexList = []
225 for channel in channelList:
264 for channel in channelList:
226 if channel not in dataOut.channelList:
265 if channel not in dataOut.channelList:
227 raise ValueError, "Channel %d is not in dataOut.channelList"
266 raise ValueError, "Channel %d is not in dataOut.channelList"
228 channelIndexList.append(channel)
267 channelIndexList.append(channel)
229
268
230 x = dataOut.getVelRange(1)
269 x = dataOut.getVelRange(1)
231 y = dataOut.getHeiRange()
270 y = dataOut.getHeiRange()
232 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
271 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
233 avg = numpy.average(z, axis=1)
272 avg = numpy.average(z, axis=1)
234
273
235 noise = dataOut.getNoise()
274 noise = dataOut.getNoise()
236
275
237 if not self.__isConfig:
276 if not self.__isConfig:
238
277
239 nplots = len(channelIndexList)
278 nplots = len(channelIndexList)
240
279
241 self.setup(idfigure=idfigure,
280 self.setup(idfigure=idfigure,
242 nplots=nplots,
281 nplots=nplots,
243 wintitle=wintitle,
282 wintitle=wintitle,
244 showprofile=showprofile)
283 showprofile=showprofile)
245
284
246 if xmin == None: xmin = numpy.nanmin(x)
285 if xmin == None: xmin = numpy.nanmin(x)
247 if xmax == None: xmax = numpy.nanmax(x)
286 if xmax == None: xmax = numpy.nanmax(x)
248 if ymin == None: ymin = numpy.nanmin(y)
287 if ymin == None: ymin = numpy.nanmin(y)
249 if ymax == None: ymax = numpy.nanmax(y)
288 if ymax == None: ymax = numpy.nanmax(y)
250 if zmin == None: zmin = numpy.nanmin(avg)*0.9
289 if zmin == None: zmin = numpy.nanmin(avg)*0.9
251 if zmax == None: zmax = numpy.nanmax(avg)*0.9
290 if zmax == None: zmax = numpy.nanmax(avg)*0.9
252
291
253 self.__isConfig = True
292 self.__isConfig = True
254
293
255 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
294 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
256 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
295 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
257 xlabel = "Velocity (m/s)"
296 xlabel = "Velocity (m/s)"
258 ylabel = "Range (Km)"
297 ylabel = "Range (Km)"
259
298
260 self.setWinTitle(title)
299 self.setWinTitle(title)
261
300
262 for i in range(self.nplots):
301 for i in range(self.nplots):
263 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
302 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
264 axes = self.axesList[i*self.__nsubplots]
303 axes = self.axesList[i*self.__nsubplots]
265 axes.pcolor(x, y, z[i,:,:],
304 axes.pcolor(x, y, z[i,:,:],
266 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
305 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
267 xlabel=xlabel, ylabel=ylabel, title=title,
306 xlabel=xlabel, ylabel=ylabel, title=title,
268 ticksize=9, cblabel='')
307 ticksize=9, cblabel='')
269
308
270 if self.__showprofile:
309 if self.__showprofile:
271 axes = self.axesList[i*self.__nsubplots +1]
310 axes = self.axesList[i*self.__nsubplots +1]
272 axes.pline(avg[i], y,
311 axes.pline(avg[i], y,
273 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
312 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
274 xlabel='dB', ylabel='', title='',
313 xlabel='dB', ylabel='', title='',
275 ytick_visible=False,
314 ytick_visible=False,
276 grid='x')
315 grid='x')
277
316
278 self.draw()
317 self.draw()
279
318
280 if save:
319 if save:
281 self.saveFigure(filename)
320 self.saveFigure(filename)
282
321
283 class Scope(Figure):
322 class Scope(Figure):
284
323
285 __isConfig = None
324 __isConfig = None
286
325
287 def __init__(self):
326 def __init__(self):
288
327
289 self.__isConfig = False
328 self.__isConfig = False
290 self.WIDTH = 600
329 self.WIDTH = 600
291 self.HEIGHT = 200
330 self.HEIGHT = 200
292
331
293 def getSubplots(self):
332 def getSubplots(self):
294
333
295 nrow = self.nplots
334 nrow = self.nplots
296 ncol = 3
335 ncol = 3
297 return nrow, ncol
336 return nrow, ncol
298
337
299 def setup(self, idfigure, nplots, wintitle):
338 def setup(self, idfigure, nplots, wintitle):
300
339
301 self.createFigure(idfigure, wintitle)
340 self.createFigure(idfigure, wintitle)
302
341
303 nrow,ncol = self.getSubplots()
342 nrow,ncol = self.getSubplots()
304 colspan = 3
343 colspan = 3
305 rowspan = 1
344 rowspan = 1
306
345
307 for i in range(nplots):
346 for i in range(nplots):
308 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
347 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
309
348
310 self.nplots = nplots
349 self.nplots = nplots
311
350
312 def run(self, dataOut, idfigure, wintitle="", channelList=None,
351 def run(self, dataOut, idfigure, wintitle="", channelList=None,
313 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
352 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
314
353
315 """
354 """
316
355
317 Input:
356 Input:
318 dataOut :
357 dataOut :
319 idfigure :
358 idfigure :
320 wintitle :
359 wintitle :
321 channelList :
360 channelList :
322 xmin : None,
361 xmin : None,
323 xmax : None,
362 xmax : None,
324 ymin : None,
363 ymin : None,
325 ymax : None,
364 ymax : None,
326 """
365 """
327
366
328 if channelList == None:
367 if channelList == None:
329 channelList = dataOut.channelList
368 channelList = dataOut.channelList
330
369
331 x = dataOut.heightList
370 x = dataOut.heightList
332 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
371 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
333 y = y.real
372 y = y.real
334
373
335 noise = dataOut.getNoise()
374 noise = dataOut.getNoise()
336
375
337 if not self.__isConfig:
376 if not self.__isConfig:
338 nplots = len(channelList)
377 nplots = len(channelList)
339
378
340 self.setup(idfigure=idfigure,
379 self.setup(idfigure=idfigure,
341 nplots=nplots,
380 nplots=nplots,
342 wintitle=wintitle)
381 wintitle=wintitle)
343
382
344 if xmin == None: xmin = numpy.nanmin(x)
383 if xmin == None: xmin = numpy.nanmin(x)
345 if xmax == None: xmax = numpy.nanmax(x)
384 if xmax == None: xmax = numpy.nanmax(x)
346 if ymin == None: ymin = numpy.nanmin(y)
385 if ymin == None: ymin = numpy.nanmin(y)
347 if ymax == None: ymax = numpy.nanmax(y)
386 if ymax == None: ymax = numpy.nanmax(y)
348
387
349 self.__isConfig = True
388 self.__isConfig = True
350
389
351
390
352 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
391 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
353 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
392 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
354 xlabel = "Range (Km)"
393 xlabel = "Range (Km)"
355 ylabel = "Intensity"
394 ylabel = "Intensity"
356
395
357 self.setWinTitle(title)
396 self.setWinTitle(title)
358
397
359 for i in range(len(self.axesList)):
398 for i in range(len(self.axesList)):
360 title = "Channel %d: %4.2fdB" %(i, noise[i])
399 title = "Channel %d: %4.2fdB" %(i, noise[i])
361 axes = self.axesList[i]
400 axes = self.axesList[i]
362 ychannel = y[i,:]
401 ychannel = y[i,:]
363 axes.pline(x, ychannel,
402 axes.pline(x, ychannel,
364 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
403 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
365 xlabel=xlabel, ylabel=ylabel, title=title)
404 xlabel=xlabel, ylabel=ylabel, title=title)
366
405
367 self.draw()
406 self.draw()
368
407
369 if save:
408 if save:
370 self.saveFigure(filename)
409 self.saveFigure(filename)
371 No newline at end of file
410
General Comments 0
You need to be logged in to leave comments. Login now