@@ -1,294 +1,323 | |||
|
1 | 1 | import os |
|
2 | 2 | import numpy |
|
3 | 3 | import mpldriver |
|
4 | 4 | |
|
5 | 5 | |
|
6 | 6 | class Figure: |
|
7 | 7 | |
|
8 | 8 | __driver = mpldriver |
|
9 | 9 | fig = None |
|
10 | 10 | |
|
11 | 11 | idfigure = None |
|
12 | 12 | wintitle = None |
|
13 | 13 | width = None |
|
14 | 14 | height = None |
|
15 | 15 | nplots = None |
|
16 | 16 | |
|
17 | 17 | axesObjList = [] |
|
18 | 18 | |
|
19 | 19 | WIDTH = None |
|
20 | 20 | HEIGHT = None |
|
21 | 21 | PREFIX = 'fig' |
|
22 | 22 | |
|
23 | 23 | def __init__(self): |
|
24 | 24 | |
|
25 | 25 | raise ValueError, "This method is not implemented" |
|
26 | 26 | |
|
27 | 27 | def __del__(self): |
|
28 | 28 | |
|
29 | 29 | self.__driver.closeFigure() |
|
30 | 30 | |
|
31 | 31 | def getFilename(self, name, ext='.png'): |
|
32 | 32 | |
|
33 | 33 | filename = '%s_%s%s' %(self.PREFIX, name, ext) |
|
34 | 34 | |
|
35 | 35 | return filename |
|
36 | 36 | |
|
37 | 37 | def getAxesObjList(self): |
|
38 | 38 | |
|
39 | 39 | return self.axesObjList |
|
40 | 40 | |
|
41 | 41 | def getSubplots(self): |
|
42 | 42 | |
|
43 | 43 | raise ValueError, "Abstract method: This method should be defined" |
|
44 | 44 | |
|
45 | 45 | def getScreenDim(self, widthplot, heightplot): |
|
46 | 46 | |
|
47 | 47 | nrow, ncol = self.getSubplots() |
|
48 | 48 | |
|
49 | 49 | widthscreen = widthplot*ncol |
|
50 | 50 | heightscreen = heightplot*nrow |
|
51 | 51 | |
|
52 | 52 | return widthscreen, heightscreen |
|
53 | 53 | |
|
54 | 54 | def init(self, idfigure, nplots, wintitle): |
|
55 | 55 | |
|
56 | 56 | raise ValueError, "This method has been replaced with createFigure" |
|
57 | 57 | |
|
58 | 58 | def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None): |
|
59 | 59 | |
|
60 | 60 | """ |
|
61 | 61 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
62 | 62 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
63 | 63 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
64 | 64 | |
|
65 | 65 | Input: |
|
66 | 66 | idfigure : Los parametros necesarios son |
|
67 | 67 | wintitle : |
|
68 | 68 | |
|
69 | 69 | """ |
|
70 | 70 | |
|
71 | 71 | if widthplot == None: |
|
72 | 72 | widthplot = self.WIDTH |
|
73 | 73 | |
|
74 | 74 | if heightplot == None: |
|
75 | 75 | heightplot = self.HEIGHT |
|
76 | 76 | |
|
77 | 77 | self.idfigure = idfigure |
|
78 | 78 | |
|
79 | 79 | self.wintitle = wintitle |
|
80 | 80 | |
|
81 | 81 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
82 | 82 | |
|
83 | 83 | self.fig = self.__driver.createFigure(self.idfigure, |
|
84 | 84 | self.wintitle, |
|
85 | 85 | self.widthscreen, |
|
86 | 86 | self.heightscreen) |
|
87 | 87 | |
|
88 | 88 | self.axesObjList = [] |
|
89 | 89 | |
|
90 | 90 | def setDriver(self, driver=mpldriver): |
|
91 | 91 | |
|
92 | 92 | self.__driver = driver |
|
93 | 93 | |
|
94 | 94 | def setTitle(self, title): |
|
95 | 95 | |
|
96 | 96 | self.__driver.setTitle(self.fig, title) |
|
97 | 97 | |
|
98 | 98 | def setWinTitle(self, title): |
|
99 | 99 | |
|
100 | 100 | self.__driver.setWinTitle(self.fig, title=title) |
|
101 | 101 | |
|
102 | 102 | def setTextFromAxes(self, text): |
|
103 | 103 | |
|
104 | 104 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
105 | 105 | |
|
106 | 106 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
107 | 107 | |
|
108 | 108 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
109 | 109 | |
|
110 | 110 | def addAxes(self, *args): |
|
111 | 111 | """ |
|
112 | 112 | |
|
113 | 113 | Input: |
|
114 | 114 | *args : Los parametros necesarios son |
|
115 | 115 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
116 | 116 | """ |
|
117 | 117 | |
|
118 | 118 | axesObj = Axes(self.fig, *args) |
|
119 | 119 | self.axesObjList.append(axesObj) |
|
120 | 120 | |
|
121 | 121 | def saveFigure(self, figpath, figfile, *args): |
|
122 | 122 | |
|
123 | 123 | filename = os.path.join(figpath, figfile) |
|
124 | 124 | self.__driver.saveFigure(self.fig, filename, *args) |
|
125 | 125 | |
|
126 | 126 | def draw(self): |
|
127 | 127 | |
|
128 | 128 | self.__driver.draw(self.fig) |
|
129 | 129 | |
|
130 | 130 | def run(self): |
|
131 | 131 | |
|
132 | 132 | raise ValueError, "This method is not implemented" |
|
133 | 133 | |
|
134 | 134 | axesList = property(getAxesObjList) |
|
135 | 135 | |
|
136 | 136 | |
|
137 | 137 | class Axes: |
|
138 | 138 | |
|
139 | 139 | __driver = mpldriver |
|
140 | 140 | fig = None |
|
141 | 141 | ax = None |
|
142 | 142 | plot = None |
|
143 | 143 | |
|
144 | 144 | __firsttime = None |
|
145 | 145 | |
|
146 | 146 | __showprofile = False |
|
147 | 147 | |
|
148 | 148 | xmin = None |
|
149 | 149 | xmax = None |
|
150 | 150 | ymin = None |
|
151 | 151 | ymax = None |
|
152 | 152 | zmin = None |
|
153 | 153 | zmax = None |
|
154 | 154 | |
|
155 | 155 | def __init__(self, *args): |
|
156 | 156 | |
|
157 | 157 | """ |
|
158 | 158 | |
|
159 | 159 | Input: |
|
160 | 160 | *args : Los parametros necesarios son |
|
161 | 161 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
162 | 162 | """ |
|
163 | 163 | |
|
164 | 164 | ax = self.__driver.createAxes(*args) |
|
165 | 165 | self.fig = args[0] |
|
166 | 166 | self.ax = ax |
|
167 | 167 | self.plot = None |
|
168 | 168 | |
|
169 | 169 | self.__firsttime = True |
|
170 | 170 | |
|
171 | 171 | def setText(self, text): |
|
172 | 172 | |
|
173 | 173 | self.__driver.setAxesText(self.ax, text) |
|
174 | 174 | |
|
175 | 175 | def setXAxisAsTime(self): |
|
176 | 176 | pass |
|
177 | 177 | |
|
178 | 178 | def pline(self, x, y, |
|
179 | 179 | xmin=None, xmax=None, |
|
180 | 180 | ymin=None, ymax=None, |
|
181 | 181 | xlabel='', ylabel='', |
|
182 | 182 | title='', |
|
183 | 183 | **kwargs): |
|
184 | 184 | |
|
185 | 185 | """ |
|
186 | 186 | |
|
187 | 187 | Input: |
|
188 | 188 | x : |
|
189 | 189 | y : |
|
190 | 190 | xmin : |
|
191 | 191 | xmax : |
|
192 | 192 | ymin : |
|
193 | 193 | ymax : |
|
194 | 194 | xlabel : |
|
195 | 195 | ylabel : |
|
196 | 196 | title : |
|
197 | 197 | **kwargs : Los parametros aceptados son |
|
198 | 198 | |
|
199 | 199 | ticksize |
|
200 | 200 | ytick_visible |
|
201 | 201 | """ |
|
202 | 202 | |
|
203 | 203 | if self.__firsttime: |
|
204 | 204 | |
|
205 | 205 | if xmin == None: xmin = numpy.nanmin(x) |
|
206 | 206 | if xmax == None: xmax = numpy.nanmax(x) |
|
207 | 207 | if ymin == None: ymin = numpy.nanmin(y) |
|
208 | 208 | if ymax == None: ymax = numpy.nanmax(y) |
|
209 | 209 | |
|
210 | 210 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
211 | 211 | xmin, xmax, |
|
212 | 212 | ymin, ymax, |
|
213 | 213 | xlabel=xlabel, |
|
214 | 214 | ylabel=ylabel, |
|
215 | 215 | title=title, |
|
216 | 216 | **kwargs) |
|
217 | 217 | self.__firsttime = False |
|
218 | 218 | return |
|
219 | 219 | |
|
220 | 220 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
221 | 221 | ylabel=ylabel, |
|
222 | 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 | 252 | def pcolor(self, x, y, z, |
|
226 | 253 | xmin=None, xmax=None, |
|
227 | 254 | ymin=None, ymax=None, |
|
228 | 255 | zmin=None, zmax=None, |
|
229 | 256 | xlabel='', ylabel='', |
|
230 | title='', rti = False, | |
|
257 | title='', rti = False, colormap='jet', | |
|
231 | 258 | **kwargs): |
|
232 | 259 | |
|
233 | 260 | """ |
|
234 | 261 | Input: |
|
235 | 262 | x : |
|
236 | 263 | y : |
|
237 | 264 | x : |
|
238 | 265 | xmin : |
|
239 | 266 | xmax : |
|
240 | 267 | ymin : |
|
241 | 268 | ymax : |
|
242 | 269 | zmin : |
|
243 | 270 | zmax : |
|
244 | 271 | xlabel : |
|
245 | 272 | ylabel : |
|
246 | 273 | title : |
|
247 | 274 | **kwargs : Los parametros aceptados son |
|
248 | 275 | ticksize=9, |
|
249 | 276 | cblabel='' |
|
250 | 277 | rti = True or False |
|
251 | 278 | """ |
|
252 | 279 | |
|
253 | 280 | if self.__firsttime: |
|
254 | 281 | |
|
255 | 282 | if xmin == None: xmin = numpy.nanmin(x) |
|
256 | 283 | if xmax == None: xmax = numpy.nanmax(x) |
|
257 | 284 | if ymin == None: ymin = numpy.nanmin(y) |
|
258 | 285 | if ymax == None: ymax = numpy.nanmax(y) |
|
259 | 286 | if zmin == None: zmin = numpy.nanmin(z) |
|
260 | 287 | if zmax == None: zmax = numpy.nanmax(z) |
|
261 | 288 | |
|
262 | 289 | |
|
263 | 290 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
264 | 291 | xmin, xmax, |
|
265 | 292 | ymin, ymax, |
|
266 | 293 | zmin, zmax, |
|
267 | 294 | xlabel=xlabel, |
|
268 | 295 | ylabel=ylabel, |
|
269 | 296 | title=title, |
|
297 | colormap=colormap, | |
|
270 | 298 | **kwargs) |
|
271 | 299 | |
|
272 | 300 | if self.xmin == None: self.xmin = xmin |
|
273 | 301 | if self.xmax == None: self.xmax = xmax |
|
274 | 302 | if self.ymin == None: self.ymin = ymin |
|
275 | 303 | if self.ymax == None: self.ymax = ymax |
|
276 | 304 | if self.zmin == None: self.zmin = zmin |
|
277 | 305 | if self.zmax == None: self.zmax = zmax |
|
278 | 306 | |
|
279 | 307 | self.__firsttime = False |
|
280 | 308 | return |
|
281 | 309 | |
|
282 | 310 | if rti: |
|
283 | 311 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, |
|
284 | 312 | xlabel=xlabel, |
|
285 | 313 | ylabel=ylabel, |
|
286 |
title=title |
|
|
314 | title=title, | |
|
315 | colormap=colormap) | |
|
287 | 316 | return |
|
288 | 317 | |
|
289 | 318 | self.__driver.pcolor(self.plot, z, |
|
290 | 319 | xlabel=xlabel, |
|
291 | 320 | ylabel=ylabel, |
|
292 | 321 | title=title) |
|
293 | 322 | |
|
294 | 323 | No newline at end of file |
@@ -1,202 +1,268 | |||
|
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 | 10 | from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter |
|
11 | 11 | from matplotlib.ticker import FuncFormatter |
|
12 | 12 | from matplotlib.ticker import * |
|
13 | 13 | |
|
14 | 14 | ########################################### |
|
15 | 15 | #Actualizacion de las funciones del driver |
|
16 | 16 | ########################################### |
|
17 | 17 | |
|
18 | 18 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): |
|
19 | 19 | |
|
20 | 20 | matplotlib.pyplot.ioff() |
|
21 | 21 | fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
22 | 22 | fig.canvas.manager.set_window_title(wintitle) |
|
23 | 23 | fig.canvas.manager.resize(width, height) |
|
24 | 24 | matplotlib.pyplot.ion() |
|
25 | 25 | |
|
26 | 26 | return fig |
|
27 | 27 | |
|
28 | 28 | def closeFigure(): |
|
29 | 29 | |
|
30 | 30 | matplotlib.pyplot.ioff() |
|
31 | 31 | matplotlib.pyplot.show() |
|
32 | 32 | |
|
33 | 33 | return |
|
34 | 34 | |
|
35 | 35 | def saveFigure(fig, filename): |
|
36 | 36 | fig.savefig(filename) |
|
37 | 37 | |
|
38 | 38 | def setWinTitle(fig, title): |
|
39 | 39 | |
|
40 | 40 | fig.canvas.manager.set_window_title(title) |
|
41 | 41 | |
|
42 | 42 | def setTitle(fig, title): |
|
43 | 43 | |
|
44 | 44 | fig.suptitle(title) |
|
45 | 45 | |
|
46 | 46 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
47 | 47 | |
|
48 | 48 | matplotlib.pyplot.figure(fig.number) |
|
49 | 49 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
50 | 50 | (xpos, ypos), |
|
51 | 51 | colspan=colspan, |
|
52 | 52 | rowspan=rowspan) |
|
53 | 53 | return axes |
|
54 | 54 | |
|
55 | 55 | def setAxesText(ax, text): |
|
56 | 56 | |
|
57 | 57 | ax.annotate(text, |
|
58 | 58 | xy = (.1, .99), |
|
59 | 59 | xycoords = 'figure fraction', |
|
60 | 60 | horizontalalignment = 'left', |
|
61 | 61 | verticalalignment = 'top', |
|
62 | 62 | fontsize = 10) |
|
63 | 63 | |
|
64 | 64 | def printLabels(ax, xlabel, ylabel, title): |
|
65 | 65 | |
|
66 | 66 | ax.set_xlabel(xlabel, size=11) |
|
67 | 67 | ax.set_ylabel(ylabel, size=11) |
|
68 | 68 | ax.set_title(title, size=12) |
|
69 | 69 | |
|
70 | 70 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
71 | 71 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
72 | 72 | nxticks=4, nyticks=10, |
|
73 | 73 | grid=None): |
|
74 | 74 | |
|
75 | 75 | """ |
|
76 | 76 | |
|
77 | 77 | Input: |
|
78 | 78 | grid : None, 'both', 'x', 'y' |
|
79 | 79 | """ |
|
80 | 80 | |
|
81 | 81 | ax.plot(x, y) |
|
82 | 82 | ax.set_xlim([xmin,xmax]) |
|
83 | 83 | ax.set_ylim([ymin,ymax]) |
|
84 | 84 | |
|
85 | 85 | printLabels(ax, xlabel, ylabel, title) |
|
86 | 86 | |
|
87 | 87 | ###################################################### |
|
88 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin) | |
|
89 | ax.set_xticks(xtickspos) | |
|
88 | if (xmax-xmin)<=1: | |
|
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 | 96 | for tick in ax.get_xticklabels(): |
|
92 | 97 | tick.set_visible(xtick_visible) |
|
93 | 98 | |
|
94 | 99 | for tick in ax.xaxis.get_major_ticks(): |
|
95 | 100 | tick.label.set_fontsize(ticksize) |
|
96 | 101 | |
|
97 | 102 | ###################################################### |
|
98 | 103 | for tick in ax.get_yticklabels(): |
|
99 | 104 | tick.set_visible(ytick_visible) |
|
100 | 105 | |
|
101 | 106 | for tick in ax.yaxis.get_major_ticks(): |
|
102 | 107 | tick.label.set_fontsize(ticksize) |
|
103 | 108 | |
|
104 | 109 | iplot = ax.lines[-1] |
|
105 | 110 | |
|
106 | 111 | ###################################################### |
|
107 | 112 | if '0.' in matplotlib.__version__[0:2]: |
|
108 | 113 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
109 | 114 | return iplot |
|
110 | 115 | |
|
111 | 116 | if '1.0.' in matplotlib.__version__[0:4]: |
|
112 | 117 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
113 | 118 | return iplot |
|
114 | 119 | |
|
115 | 120 | if grid != None: |
|
116 | 121 | ax.grid(b=True, which='major', axis=grid) |
|
117 | 122 | |
|
118 | 123 | matplotlib.pyplot.tight_layout() |
|
119 | 124 | |
|
120 | 125 | return iplot |
|
121 | 126 | |
|
122 | 127 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
123 | 128 | |
|
124 | 129 | ax = iplot.get_axes() |
|
125 | 130 | |
|
126 | 131 | printLabels(ax, xlabel, ylabel, title) |
|
127 | 132 | |
|
128 | 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 | 196 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
131 | 197 | xlabel='', ylabel='', title='', ticksize = 9, |
|
132 | 198 | colormap='jet',cblabel='', cbsize="5%", |
|
133 | 199 | XAxisAsTime=False): |
|
134 | 200 | |
|
135 | 201 | divider = make_axes_locatable(ax) |
|
136 | 202 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
137 | 203 | fig = ax.get_figure() |
|
138 | 204 | fig.add_axes(ax_cb) |
|
139 | 205 | |
|
140 | 206 | ax.set_xlim([xmin,xmax]) |
|
141 | 207 | ax.set_ylim([ymin,ymax]) |
|
142 | 208 | |
|
143 | 209 | printLabels(ax, xlabel, ylabel, title) |
|
144 | 210 | |
|
145 | 211 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
146 | 212 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
147 | 213 | cb.set_label(cblabel) |
|
148 | 214 | |
|
149 | 215 | # for tl in ax_cb.get_yticklabels(): |
|
150 | 216 | # tl.set_visible(True) |
|
151 | 217 | |
|
152 | 218 | for tick in ax.yaxis.get_major_ticks(): |
|
153 | 219 | tick.label.set_fontsize(ticksize) |
|
154 | 220 | |
|
155 | 221 | for tick in ax.xaxis.get_major_ticks(): |
|
156 | 222 | tick.label.set_fontsize(ticksize) |
|
157 | 223 | |
|
158 | 224 | for tick in cb.ax.get_yticklabels(): |
|
159 | 225 | tick.set_fontsize(ticksize) |
|
160 | 226 | |
|
161 | 227 | ax_cb.yaxis.tick_right() |
|
162 | 228 | |
|
163 | 229 | if '0.' in matplotlib.__version__[0:2]: |
|
164 | 230 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
165 | 231 | return imesh |
|
166 | 232 | |
|
167 | 233 | if '1.0.' in matplotlib.__version__[0:4]: |
|
168 | 234 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
169 | 235 | return imesh |
|
170 | 236 | |
|
171 | 237 | matplotlib.pyplot.tight_layout() |
|
172 | 238 | |
|
173 | 239 | if XAxisAsTime: |
|
174 | 240 | |
|
175 | 241 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
176 | 242 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
177 | 243 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
178 | 244 | |
|
179 | 245 | return imesh |
|
180 | 246 | |
|
181 | 247 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
182 | 248 | |
|
183 | 249 | z = z.T |
|
184 | 250 | |
|
185 | 251 | ax = imesh.get_axes() |
|
186 | 252 | |
|
187 | 253 | printLabels(ax, xlabel, ylabel, title) |
|
188 | 254 | |
|
189 | 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 | 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 | 263 | def draw(fig): |
|
198 | 264 | |
|
199 | 265 | if type(fig) == 'int': |
|
200 | 266 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
201 | 267 | |
|
202 | 268 | fig.canvas.draw() No newline at end of file |
@@ -1,592 +1,874 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import time, datetime |
|
3 | 3 | from graphics.figure import * |
|
4 | 4 | |
|
5 | 5 | class CrossSpectraPlot(Figure): |
|
6 | 6 | |
|
7 | 7 | __isConfig = None |
|
8 | 8 | __nsubplots = None |
|
9 | 9 | |
|
10 | 10 | WIDTHPROF = None |
|
11 | 11 | HEIGHTPROF = None |
|
12 | 12 | PREFIX = 'cspc' |
|
13 | 13 | |
|
14 | 14 | def __init__(self): |
|
15 | 15 | |
|
16 | 16 | self.__isConfig = False |
|
17 | 17 | self.__nsubplots = 4 |
|
18 | 18 | |
|
19 | 19 | self.WIDTH = 300 |
|
20 | 20 | self.HEIGHT = 400 |
|
21 | 21 | self.WIDTHPROF = 0 |
|
22 | 22 | self.HEIGHTPROF = 0 |
|
23 | 23 | |
|
24 | 24 | def getSubplots(self): |
|
25 | 25 | |
|
26 | 26 | ncol = 4 |
|
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 | |
|
39 | 39 | self.createFigure(idfigure = idfigure, |
|
40 | 40 | wintitle = wintitle, |
|
41 | 41 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
42 | 42 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
43 | 43 | |
|
44 | 44 | nrow, ncol = self.getSubplots() |
|
45 | 45 | |
|
46 | 46 | counter = 0 |
|
47 | 47 | for y in range(nrow): |
|
48 | 48 | for x in range(ncol): |
|
49 | 49 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
50 | 50 | |
|
51 | 51 | counter += 1 |
|
52 | 52 | |
|
53 | 53 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
54 | 54 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
55 | 55 | save=False, figpath='./', figfile=None): |
|
56 | 56 | |
|
57 | 57 | """ |
|
58 | 58 | |
|
59 | 59 | Input: |
|
60 | 60 | dataOut : |
|
61 | 61 | idfigure : |
|
62 | 62 | wintitle : |
|
63 | 63 | channelList : |
|
64 | 64 | showProfile : |
|
65 | 65 | xmin : None, |
|
66 | 66 | xmax : None, |
|
67 | 67 | ymin : None, |
|
68 | 68 | ymax : None, |
|
69 | 69 | zmin : None, |
|
70 | 70 | zmax : None |
|
71 | 71 | """ |
|
72 | 72 | |
|
73 | 73 | if pairsList == None: |
|
74 | 74 | pairsIndexList = dataOut.pairsIndexList |
|
75 | 75 | else: |
|
76 | 76 | pairsIndexList = [] |
|
77 | 77 | for pair in pairsList: |
|
78 | 78 | if pair not in dataOut.pairsList: |
|
79 | 79 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
80 | 80 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
81 | 81 | |
|
82 | 82 | if pairsIndexList == []: |
|
83 | 83 | return |
|
84 | 84 | |
|
85 | 85 | if len(pairsIndexList) > 4: |
|
86 | 86 | pairsIndexList = pairsIndexList[0:4] |
|
87 | 87 | |
|
88 | 88 | x = dataOut.getFreqRange(1) |
|
89 | 89 | y = dataOut.getHeiRange() |
|
90 | 90 | z = 10.*numpy.log10(dataOut.data_spc[:,:,:]) |
|
91 | 91 | avg = numpy.average(numpy.abs(z), axis=1) |
|
92 | 92 | |
|
93 | 93 | noise = dataOut.getNoise() |
|
94 | 94 | |
|
95 | 95 | if not self.__isConfig: |
|
96 | 96 | |
|
97 | 97 | nplots = len(pairsIndexList) |
|
98 | 98 | |
|
99 | 99 | self.setup(idfigure=idfigure, |
|
100 | 100 | nplots=nplots, |
|
101 | 101 | wintitle=wintitle, |
|
102 | 102 | showprofile=showprofile) |
|
103 | 103 | |
|
104 | 104 | if xmin == None: xmin = numpy.nanmin(x) |
|
105 | 105 | if xmax == None: xmax = numpy.nanmax(x) |
|
106 | 106 | if ymin == None: ymin = numpy.nanmin(y) |
|
107 | 107 | if ymax == None: ymax = numpy.nanmax(y) |
|
108 | 108 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
109 | 109 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
110 | 110 | |
|
111 | 111 | self.__isConfig = True |
|
112 | 112 | |
|
113 | 113 | thisDatetime = dataOut.datatime |
|
114 | 114 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
115 | 115 | xlabel = "Velocity (m/s)" |
|
116 | 116 | ylabel = "Range (Km)" |
|
117 | 117 | |
|
118 | 118 | self.setWinTitle(title) |
|
119 | 119 | |
|
120 | 120 | for i in range(self.nplots): |
|
121 | 121 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
122 | 122 | |
|
123 | 123 | title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]]) |
|
124 | 124 | z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) |
|
125 | 125 | axes0 = self.axesList[i*self.__nsubplots] |
|
126 | 126 | axes0.pcolor(x, y, z, |
|
127 | 127 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
128 | 128 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
129 | 129 | ticksize=9, cblabel='') |
|
130 | 130 | |
|
131 | 131 | title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]]) |
|
132 | 132 | z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) |
|
133 | 133 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
134 | 134 | axes0.pcolor(x, y, z, |
|
135 | 135 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
136 | 136 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
137 | 137 | ticksize=9, cblabel='') |
|
138 | 138 | |
|
139 | 139 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
140 | 140 | coherence = numpy.abs(coherenceComplex) |
|
141 | 141 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
142 | 142 | |
|
143 | 143 | |
|
144 | 144 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
145 | 145 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
146 | 146 | axes0.pcolor(x, y, coherence, |
|
147 | 147 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
148 | 148 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
149 | 149 | ticksize=9, cblabel='') |
|
150 | 150 | |
|
151 | 151 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
152 | 152 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
153 | 153 | axes0.pcolor(x, y, phase, |
|
154 | 154 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
155 | 155 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
156 | 156 | ticksize=9, cblabel='', colormap='RdBu') |
|
157 | 157 | |
|
158 | 158 | |
|
159 | 159 | |
|
160 | 160 | self.draw() |
|
161 | 161 | |
|
162 | 162 | if save: |
|
163 | 163 | date = thisDatetime.strftime("%Y%m%d") |
|
164 | 164 | if figfile == None: |
|
165 | 165 | figfile = self.getFilename(name = date) |
|
166 | 166 | |
|
167 | 167 | self.saveFigure(figpath, figfile) |
|
168 | 168 | |
|
169 | 169 | |
|
170 | 170 | class RTIPlot(Figure): |
|
171 | 171 | |
|
172 | 172 | __isConfig = None |
|
173 | 173 | __nsubplots = None |
|
174 | 174 | |
|
175 | 175 | WIDTHPROF = None |
|
176 | 176 | HEIGHTPROF = None |
|
177 | 177 | PREFIX = 'rti' |
|
178 | 178 | |
|
179 | 179 | def __init__(self): |
|
180 | 180 | |
|
181 | 181 | self.__timerange = 24*60*60 |
|
182 | 182 | self.__isConfig = False |
|
183 | 183 | self.__nsubplots = 1 |
|
184 | 184 | |
|
185 | 185 | self.WIDTH = 800 |
|
186 | 186 | self.HEIGHT = 200 |
|
187 | 187 | self.WIDTHPROF = 120 |
|
188 | 188 | self.HEIGHTPROF = 0 |
|
189 | 189 | |
|
190 | 190 | def getSubplots(self): |
|
191 | 191 | |
|
192 | 192 | ncol = 1 |
|
193 | 193 | nrow = self.nplots |
|
194 | 194 | |
|
195 | 195 | return nrow, ncol |
|
196 | 196 | |
|
197 | 197 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
198 | 198 | |
|
199 | 199 | self.__showprofile = showprofile |
|
200 | 200 | self.nplots = nplots |
|
201 | 201 | |
|
202 | 202 | ncolspan = 1 |
|
203 | 203 | colspan = 1 |
|
204 | 204 | if showprofile: |
|
205 | 205 | ncolspan = 7 |
|
206 | 206 | colspan = 6 |
|
207 | 207 | self.__nsubplots = 2 |
|
208 | 208 | |
|
209 | 209 | self.createFigure(idfigure = idfigure, |
|
210 | 210 | wintitle = wintitle, |
|
211 | 211 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
212 | 212 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
213 | 213 | |
|
214 | 214 | nrow, ncol = self.getSubplots() |
|
215 | 215 | |
|
216 | 216 | counter = 0 |
|
217 | 217 | for y in range(nrow): |
|
218 | 218 | for x in range(ncol): |
|
219 | 219 | |
|
220 | 220 | if counter >= self.nplots: |
|
221 | 221 | break |
|
222 | 222 | |
|
223 | 223 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
224 | 224 | |
|
225 | 225 | if showprofile: |
|
226 | 226 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
227 | 227 | |
|
228 | 228 | counter += 1 |
|
229 | 229 | |
|
230 | 230 | def __getTimeLim(self, x, xmin, xmax): |
|
231 | 231 | |
|
232 | 232 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) |
|
233 | 233 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
234 | 234 | |
|
235 | 235 | #################################################### |
|
236 | 236 | #If the x is out of xrange |
|
237 | 237 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
238 | 238 | xmin = None |
|
239 | 239 | xmax = None |
|
240 | 240 | |
|
241 | 241 | if xmin == None: |
|
242 | 242 | td = thisdatetime - thisdate |
|
243 | 243 | xmin = td.seconds/(60*60.) |
|
244 | 244 | |
|
245 | 245 | if xmax == None: |
|
246 | 246 | xmax = xmin + self.__timerange/(60*60.) |
|
247 | 247 | |
|
248 | 248 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) |
|
249 | 249 | tmin = time.mktime(mindt.timetuple()) |
|
250 | 250 | |
|
251 | 251 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) |
|
252 | 252 | tmax = time.mktime(maxdt.timetuple()) |
|
253 | 253 | |
|
254 | 254 | self.__timerange = tmax - tmin |
|
255 | 255 | |
|
256 | 256 | return tmin, tmax |
|
257 | 257 | |
|
258 | 258 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
259 | 259 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
260 | 260 | timerange=None, |
|
261 | 261 | save=False, figpath='./', figfile=None): |
|
262 | 262 | |
|
263 | 263 | """ |
|
264 | 264 | |
|
265 | 265 | Input: |
|
266 | 266 | dataOut : |
|
267 | 267 | idfigure : |
|
268 | 268 | wintitle : |
|
269 | 269 | channelList : |
|
270 | 270 | showProfile : |
|
271 | 271 | xmin : None, |
|
272 | 272 | xmax : None, |
|
273 | 273 | ymin : None, |
|
274 | 274 | ymax : None, |
|
275 | 275 | zmin : None, |
|
276 | 276 | zmax : None |
|
277 | 277 | """ |
|
278 | 278 | |
|
279 | 279 | if channelList == None: |
|
280 | 280 | channelIndexList = dataOut.channelIndexList |
|
281 | 281 | else: |
|
282 | 282 | channelIndexList = [] |
|
283 | 283 | for channel in channelList: |
|
284 | 284 | if channel not in dataOut.channelList: |
|
285 | 285 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
286 | 286 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
287 | 287 | |
|
288 | 288 | if timerange != None: |
|
289 | 289 | self.__timerange = timerange |
|
290 | 290 | |
|
291 | 291 | tmin = None |
|
292 | 292 | tmax = None |
|
293 | 293 | x = dataOut.getTimeRange() |
|
294 | 294 | y = dataOut.getHeiRange() |
|
295 | 295 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
296 | 296 | avg = numpy.average(z, axis=1) |
|
297 | 297 | |
|
298 | 298 | noise = dataOut.getNoise() |
|
299 | 299 | |
|
300 | 300 | if not self.__isConfig: |
|
301 | 301 | |
|
302 | 302 | nplots = len(channelIndexList) |
|
303 | 303 | |
|
304 | 304 | self.setup(idfigure=idfigure, |
|
305 | 305 | nplots=nplots, |
|
306 | 306 | wintitle=wintitle, |
|
307 | 307 | showprofile=showprofile) |
|
308 | 308 | |
|
309 | 309 | tmin, tmax = self.__getTimeLim(x, xmin, xmax) |
|
310 | 310 | if ymin == None: ymin = numpy.nanmin(y) |
|
311 | 311 | if ymax == None: ymax = numpy.nanmax(y) |
|
312 | 312 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
313 | 313 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
314 | 314 | |
|
315 | 315 | self.__isConfig = True |
|
316 | 316 | |
|
317 | 317 | thisDatetime = dataOut.datatime |
|
318 | 318 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
319 | 319 | xlabel = "Velocity (m/s)" |
|
320 | 320 | ylabel = "Range (Km)" |
|
321 | 321 | |
|
322 | 322 | self.setWinTitle(title) |
|
323 | 323 | |
|
324 | 324 | for i in range(self.nplots): |
|
325 | 325 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
326 | 326 | axes = self.axesList[i*self.__nsubplots] |
|
327 | 327 | z = avg[i].reshape((1,-1)) |
|
328 | 328 | axes.pcolor(x, y, z, |
|
329 | 329 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
330 | 330 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
331 | 331 | ticksize=9, cblabel='', cbsize="1%") |
|
332 | 332 | |
|
333 | 333 | if self.__showprofile: |
|
334 | 334 | axes = self.axesList[i*self.__nsubplots +1] |
|
335 | 335 | axes.pline(avg[i], y, |
|
336 | 336 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
337 | 337 | xlabel='dB', ylabel='', title='', |
|
338 | 338 | ytick_visible=False, |
|
339 | 339 | grid='x') |
|
340 | 340 | |
|
341 | 341 | self.draw() |
|
342 | 342 | |
|
343 | 343 | if save: |
|
344 | 344 | date = thisDatetime.strftime("%Y%m%d") |
|
345 | 345 | if figfile == None: |
|
346 | 346 | figfile = self.getFilename(name = date) |
|
347 | 347 | |
|
348 | 348 | self.saveFigure(figpath, figfile) |
|
349 | 349 | |
|
350 | 350 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
351 | 351 | self.__isConfig = False |
|
352 | 352 | |
|
353 | 353 | class SpectraPlot(Figure): |
|
354 | 354 | |
|
355 | 355 | __isConfig = None |
|
356 | 356 | __nsubplots = None |
|
357 | 357 | |
|
358 | 358 | WIDTHPROF = None |
|
359 | 359 | HEIGHTPROF = None |
|
360 | 360 | PREFIX = 'spc' |
|
361 | 361 | |
|
362 | 362 | def __init__(self): |
|
363 | 363 | |
|
364 | 364 | self.__isConfig = False |
|
365 | 365 | self.__nsubplots = 1 |
|
366 | 366 | |
|
367 | 367 | self.WIDTH = 300 |
|
368 | 368 | self.HEIGHT = 400 |
|
369 | 369 | self.WIDTHPROF = 120 |
|
370 | 370 | self.HEIGHTPROF = 0 |
|
371 | 371 | |
|
372 | 372 | def getSubplots(self): |
|
373 | 373 | |
|
374 | 374 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
375 | 375 | nrow = int(self.nplots*1./ncol + 0.9) |
|
376 | 376 | |
|
377 | 377 | return nrow, ncol |
|
378 | 378 | |
|
379 | 379 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
380 | 380 | |
|
381 | 381 | self.__showprofile = showprofile |
|
382 | 382 | self.nplots = nplots |
|
383 | 383 | |
|
384 | 384 | ncolspan = 1 |
|
385 | 385 | colspan = 1 |
|
386 | 386 | if showprofile: |
|
387 | 387 | ncolspan = 3 |
|
388 | 388 | colspan = 2 |
|
389 | 389 | self.__nsubplots = 2 |
|
390 | 390 | |
|
391 | 391 | self.createFigure(idfigure = idfigure, |
|
392 | 392 | wintitle = wintitle, |
|
393 | 393 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
394 | 394 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
395 | 395 | |
|
396 | 396 | nrow, ncol = self.getSubplots() |
|
397 | 397 | |
|
398 | 398 | counter = 0 |
|
399 | 399 | for y in range(nrow): |
|
400 | 400 | for x in range(ncol): |
|
401 | 401 | |
|
402 | 402 | if counter >= self.nplots: |
|
403 | 403 | break |
|
404 | 404 | |
|
405 | 405 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
406 | 406 | |
|
407 | 407 | if showprofile: |
|
408 | 408 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
409 | 409 | |
|
410 | 410 | counter += 1 |
|
411 | 411 | |
|
412 | 412 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
413 | 413 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
414 | 414 | save=False, figpath='./', figfile=None): |
|
415 | 415 | |
|
416 | 416 | """ |
|
417 | 417 | |
|
418 | 418 | Input: |
|
419 | 419 | dataOut : |
|
420 | 420 | idfigure : |
|
421 | 421 | wintitle : |
|
422 | 422 | channelList : |
|
423 | 423 | showProfile : |
|
424 | 424 | xmin : None, |
|
425 | 425 | xmax : None, |
|
426 | 426 | ymin : None, |
|
427 | 427 | ymax : None, |
|
428 | 428 | zmin : None, |
|
429 | 429 | zmax : None |
|
430 | 430 | """ |
|
431 | 431 | |
|
432 | 432 | if channelList == None: |
|
433 | 433 | channelIndexList = dataOut.channelIndexList |
|
434 | 434 | else: |
|
435 | 435 | channelIndexList = [] |
|
436 | 436 | for channel in channelList: |
|
437 | 437 | if channel not in dataOut.channelList: |
|
438 | 438 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
439 | 439 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
440 | 440 | |
|
441 | 441 | x = dataOut.getVelRange(1) |
|
442 | 442 | y = dataOut.getHeiRange() |
|
443 | 443 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
444 | 444 | avg = numpy.average(z, axis=1) |
|
445 | 445 | |
|
446 | 446 | noise = dataOut.getNoise() |
|
447 | 447 | |
|
448 | 448 | if not self.__isConfig: |
|
449 | 449 | |
|
450 | 450 | nplots = len(channelIndexList) |
|
451 | 451 | |
|
452 | 452 | self.setup(idfigure=idfigure, |
|
453 | 453 | nplots=nplots, |
|
454 | 454 | wintitle=wintitle, |
|
455 | 455 | showprofile=showprofile) |
|
456 | 456 | |
|
457 | 457 | if xmin == None: xmin = numpy.nanmin(x) |
|
458 | 458 | if xmax == None: xmax = numpy.nanmax(x) |
|
459 | 459 | if ymin == None: ymin = numpy.nanmin(y) |
|
460 | 460 | if ymax == None: ymax = numpy.nanmax(y) |
|
461 | 461 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
462 | 462 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
463 | 463 | |
|
464 | 464 | self.__isConfig = True |
|
465 | 465 | |
|
466 | 466 | thisDatetime = dataOut.datatime |
|
467 | 467 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
468 | 468 | xlabel = "Velocity (m/s)" |
|
469 | 469 | ylabel = "Range (Km)" |
|
470 | 470 | |
|
471 | 471 | self.setWinTitle(title) |
|
472 | 472 | |
|
473 | 473 | for i in range(self.nplots): |
|
474 | 474 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) |
|
475 | 475 | axes = self.axesList[i*self.__nsubplots] |
|
476 | 476 | axes.pcolor(x, y, z[i,:,:], |
|
477 | 477 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
478 | 478 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
479 | 479 | ticksize=9, cblabel='') |
|
480 | 480 | |
|
481 | 481 | if self.__showprofile: |
|
482 | 482 | axes = self.axesList[i*self.__nsubplots +1] |
|
483 | 483 | axes.pline(avg[i], y, |
|
484 | 484 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
485 | 485 | xlabel='dB', ylabel='', title='', |
|
486 | 486 | ytick_visible=False, |
|
487 | 487 | grid='x') |
|
488 | 488 | |
|
489 | 489 | self.draw() |
|
490 | 490 | |
|
491 | 491 | if save: |
|
492 | 492 | date = thisDatetime.strftime("%Y%m%d") |
|
493 | 493 | if figfile == None: |
|
494 | 494 | figfile = self.getFilename(name = date) |
|
495 | 495 | |
|
496 | 496 | self.saveFigure(figpath, figfile) |
|
497 | 497 | |
|
498 | 498 | class Scope(Figure): |
|
499 | 499 | |
|
500 | 500 | __isConfig = None |
|
501 | 501 | |
|
502 | 502 | def __init__(self): |
|
503 | 503 | |
|
504 | 504 | self.__isConfig = False |
|
505 | 505 | self.WIDTH = 600 |
|
506 | 506 | self.HEIGHT = 200 |
|
507 | 507 | |
|
508 | 508 | def getSubplots(self): |
|
509 | 509 | |
|
510 | 510 | nrow = self.nplots |
|
511 | 511 | ncol = 3 |
|
512 | 512 | return nrow, ncol |
|
513 | 513 | |
|
514 | 514 | def setup(self, idfigure, nplots, wintitle): |
|
515 | 515 | |
|
516 | 516 | self.createFigure(idfigure, wintitle) |
|
517 | 517 | |
|
518 | 518 | nrow,ncol = self.getSubplots() |
|
519 | 519 | colspan = 3 |
|
520 | 520 | rowspan = 1 |
|
521 | 521 | |
|
522 | 522 | for i in range(nplots): |
|
523 | 523 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
524 | 524 | |
|
525 | 525 | self.nplots = nplots |
|
526 | 526 | |
|
527 | 527 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
528 | 528 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None): |
|
529 | 529 | |
|
530 | 530 | """ |
|
531 | 531 | |
|
532 | 532 | Input: |
|
533 | 533 | dataOut : |
|
534 | 534 | idfigure : |
|
535 | 535 | wintitle : |
|
536 | 536 | channelList : |
|
537 | 537 | xmin : None, |
|
538 | 538 | xmax : None, |
|
539 | 539 | ymin : None, |
|
540 | 540 | ymax : None, |
|
541 | 541 | """ |
|
542 | 542 | |
|
543 | 543 | if channelList == None: |
|
544 | 544 | channelIndexList = dataOut.channelIndexList |
|
545 | 545 | else: |
|
546 | 546 | channelIndexList = [] |
|
547 | 547 | for channel in channelList: |
|
548 | 548 | if channel not in dataOut.channelList: |
|
549 | 549 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
550 | 550 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
551 | 551 | |
|
552 | 552 | x = dataOut.heightList |
|
553 | 553 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) |
|
554 | 554 | y = y.real |
|
555 | 555 | |
|
556 | 556 | noise = dataOut.getNoise() |
|
557 | 557 | |
|
558 | 558 | if not self.__isConfig: |
|
559 | 559 | nplots = len(channelList) |
|
560 | 560 | |
|
561 | 561 | self.setup(idfigure=idfigure, |
|
562 | 562 | nplots=nplots, |
|
563 | 563 | wintitle=wintitle) |
|
564 | 564 | |
|
565 | 565 | if xmin == None: xmin = numpy.nanmin(x) |
|
566 | 566 | if xmax == None: xmax = numpy.nanmax(x) |
|
567 | 567 | if ymin == None: ymin = numpy.nanmin(y) |
|
568 | 568 | if ymax == None: ymax = numpy.nanmax(y) |
|
569 | 569 | |
|
570 | 570 | self.__isConfig = True |
|
571 | 571 | |
|
572 | 572 | |
|
573 | 573 | thisDatetime = dataOut.datatime |
|
574 | 574 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
575 | 575 | xlabel = "Range (Km)" |
|
576 | 576 | ylabel = "Intensity" |
|
577 | 577 | |
|
578 | 578 | self.setWinTitle(title) |
|
579 | 579 | |
|
580 | 580 | for i in range(len(self.axesList)): |
|
581 | 581 | title = "Channel %d: %4.2fdB" %(i, noise[i]) |
|
582 | 582 | axes = self.axesList[i] |
|
583 | 583 | ychannel = y[i,:] |
|
584 | 584 | axes.pline(x, ychannel, |
|
585 | 585 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
586 | 586 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
587 | 587 | |
|
588 | 588 | self.draw() |
|
589 | 589 | |
|
590 | 590 | if save: |
|
591 | 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 | 874 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now