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