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