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