@@ -1,305 +1,305 | |||||
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]) |
|
|||
49 | ax.set_ylim([ymin,ymax]) |
|
|||
50 | ax.set_xlabel(xlabel, size=8) |
|
|||
51 | ax.set_ylabel(ylabel, size=8) |
|
|||
52 | ax.set_title(title, size=10) |
|
|||
53 | matplotlib.pyplot.tight_layout() |
|
|||
54 | else: |
|
|||
55 | ax.lines[0].set_data(x,y) |
|
|||
56 |
|
||||
57 | def draw(idfigure): |
|
|||
58 |
|
||||
59 | fig = matplotlib.pyplot.figure(idfigure) |
|
|||
60 | fig.canvas.draw() |
|
|||
61 |
|
||||
62 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): |
|
|||
63 |
|
||||
64 | if firsttime: |
|
|||
65 | divider = make_axes_locatable(ax) |
|
|||
66 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) |
|
|||
67 | fig1 = ax.get_figure() |
|
|||
68 | fig1.add_axes(ax_cb) |
|
|||
69 |
|
||||
70 | ax.set_xlim([xmin,xmax]) |
|
|||
71 | ax.set_ylim([ymin,ymax]) |
|
|||
72 | ax.set_xlabel(xlabel) |
|
|||
73 | ax.set_ylabel(ylabel) |
|
|||
74 | ax.set_title(title) |
|
|||
75 | print x |
|
|||
76 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
|||
77 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
|||
78 | ax_cb.yaxis.tick_right() |
|
|||
79 | for tl in ax_cb.get_yticklabels(): |
|
|||
80 | tl.set_visible(True) |
|
|||
81 | ax_cb.yaxis.tick_right() |
|
|||
82 | matplotlib.pyplot.tight_layout() |
|
|||
83 | return imesh |
|
|||
84 | else: |
|
|||
85 | # ax.set_xlim([xmin,xmax]) |
|
48 | # ax.set_xlim([xmin,xmax]) | |
86 | # ax.set_ylim([ymin,ymax]) |
|
49 | # ax.set_ylim([ymin,ymax]) | |
87 | ax.set_xlabel(xlabel) |
|
50 | # ax.set_xlabel(xlabel, size=8) | |
88 | ax.set_ylabel(ylabel) |
|
51 | # ax.set_ylabel(ylabel, size=8) | |
89 | ax.set_title(title) |
|
52 | # ax.set_title(title, size=10) | |
90 |
|
53 | # matplotlib.pyplot.tight_layout() | ||
91 | z = z.T |
|
54 | # else: | |
92 | # z = z[0:-1,0:-1] |
|
55 | # ax.lines[0].set_data(x,y) | |
93 | mesh.set_array(z.ravel()) |
|
56 | # | |
94 |
|
57 | #def draw(idfigure): | ||
95 | return mesh |
|
58 | # | |
|
59 | # fig = matplotlib.pyplot.figure(idfigure) | |||
|
60 | # fig.canvas.draw() | |||
|
61 | # | |||
|
62 | #def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): | |||
|
63 | # | |||
|
64 | # if firsttime: | |||
|
65 | # divider = make_axes_locatable(ax) | |||
|
66 | # ax_cb = divider.new_horizontal(size="4%", pad=0.05) | |||
|
67 | # fig1 = ax.get_figure() | |||
|
68 | # fig1.add_axes(ax_cb) | |||
|
69 | # | |||
|
70 | # ax.set_xlim([xmin,xmax]) | |||
|
71 | # ax.set_ylim([ymin,ymax]) | |||
|
72 | # ax.set_xlabel(xlabel) | |||
|
73 | # ax.set_ylabel(ylabel) | |||
|
74 | # ax.set_title(title) | |||
|
75 | # print x | |||
|
76 | # imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |||
|
77 | # matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |||
|
78 | # ax_cb.yaxis.tick_right() | |||
|
79 | # for tl in ax_cb.get_yticklabels(): | |||
|
80 | # tl.set_visible(True) | |||
|
81 | # ax_cb.yaxis.tick_right() | |||
|
82 | # matplotlib.pyplot.tight_layout() | |||
|
83 | # return imesh | |||
|
84 | # else: | |||
|
85 | ## ax.set_xlim([xmin,xmax]) | |||
|
86 | ## ax.set_ylim([ymin,ymax]) | |||
|
87 | # ax.set_xlabel(xlabel) | |||
|
88 | # ax.set_ylabel(ylabel) | |||
|
89 | # ax.set_title(title) | |||
|
90 | # | |||
|
91 | # z = z.T | |||
|
92 | ## z = z[0:-1,0:-1] | |||
|
93 | # mesh.set_array(z.ravel()) | |||
|
94 | # | |||
|
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 | iplot = ax.lines[-1] |
|
187 | iplot = ax.lines[-1] | |
188 |
|
188 | |||
189 | ###################################################### |
|
189 | ###################################################### | |
190 | if '0.' in matplotlib.__version__[0:2]: |
|
190 | if '0.' in matplotlib.__version__[0:2]: | |
191 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
191 | print "The matplotlib version has to be updated to 1.1 or newer" | |
192 | return iplot |
|
192 | return iplot | |
193 |
|
193 | |||
194 | if '1.0.' in matplotlib.__version__[0:4]: |
|
194 | if '1.0.' in matplotlib.__version__[0:4]: | |
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 iplot |
|
196 | return iplot | |
197 |
|
197 | |||
198 | if grid != None: |
|
198 | if grid != None: | |
199 | ax.grid(b=True, which='major', axis=grid) |
|
199 | ax.grid(b=True, which='major', axis=grid) | |
200 |
|
200 | |||
201 | matplotlib.pyplot.tight_layout() |
|
201 | matplotlib.pyplot.tight_layout() | |
202 |
|
202 | |||
203 | return iplot |
|
203 | return iplot | |
204 |
|
204 | |||
205 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
205 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
206 |
|
206 | |||
207 | ax = iplot.get_axes() |
|
207 | ax = iplot.get_axes() | |
208 |
|
208 | |||
209 | printLabels(ax, xlabel, ylabel, title) |
|
209 | printLabels(ax, xlabel, ylabel, title) | |
210 |
|
210 | |||
211 | iplot.set_data(x, y) |
|
211 | iplot.set_data(x, y) | |
212 |
|
212 | |||
213 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
213 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |
214 | xlabel='', ylabel='', title='', ticksize = 9, |
|
214 | xlabel='', ylabel='', title='', ticksize = 9, | |
215 | cblabel='', cbsize="5%", |
|
215 | cblabel='', cbsize="5%", | |
216 | XAxisAsTime=False): |
|
216 | XAxisAsTime=False): | |
217 |
|
217 | |||
218 | divider = make_axes_locatable(ax) |
|
218 | divider = make_axes_locatable(ax) | |
219 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
219 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) | |
220 | fig = ax.get_figure() |
|
220 | fig = ax.get_figure() | |
221 | fig.add_axes(ax_cb) |
|
221 | fig.add_axes(ax_cb) | |
222 |
|
222 | |||
223 | ax.set_xlim([xmin,xmax]) |
|
223 | ax.set_xlim([xmin,xmax]) | |
224 | ax.set_ylim([ymin,ymax]) |
|
224 | ax.set_ylim([ymin,ymax]) | |
225 |
|
225 | |||
226 | printLabels(ax, xlabel, ylabel, title) |
|
226 | printLabels(ax, xlabel, ylabel, title) | |
227 |
|
227 | |||
228 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
228 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
229 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
229 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
230 | cb.set_label(cblabel) |
|
230 | cb.set_label(cblabel) | |
231 |
|
231 | |||
232 | # for tl in ax_cb.get_yticklabels(): |
|
232 | # for tl in ax_cb.get_yticklabels(): | |
233 | # tl.set_visible(True) |
|
233 | # tl.set_visible(True) | |
234 |
|
234 | |||
235 | for tick in ax.yaxis.get_major_ticks(): |
|
235 | for tick in ax.yaxis.get_major_ticks(): | |
236 | tick.label.set_fontsize(ticksize) |
|
236 | tick.label.set_fontsize(ticksize) | |
237 |
|
237 | |||
238 | for tick in ax.xaxis.get_major_ticks(): |
|
238 | for tick in ax.xaxis.get_major_ticks(): | |
239 | tick.label.set_fontsize(ticksize) |
|
239 | tick.label.set_fontsize(ticksize) | |
240 |
|
240 | |||
241 | for tick in cb.ax.get_yticklabels(): |
|
241 | for tick in cb.ax.get_yticklabels(): | |
242 | tick.set_fontsize(ticksize) |
|
242 | tick.set_fontsize(ticksize) | |
243 |
|
243 | |||
244 | ax_cb.yaxis.tick_right() |
|
244 | ax_cb.yaxis.tick_right() | |
245 |
|
245 | |||
246 | if '0.' in matplotlib.__version__[0:2]: |
|
246 | if '0.' in matplotlib.__version__[0:2]: | |
247 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
247 | print "The matplotlib version has to be updated to 1.1 or newer" | |
248 | return imesh |
|
248 | return imesh | |
249 |
|
249 | |||
250 | if '1.0.' in matplotlib.__version__[0:4]: |
|
250 | if '1.0.' in matplotlib.__version__[0:4]: | |
251 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
251 | print "The matplotlib version has to be updated to 1.1 or newer" | |
252 | return imesh |
|
252 | return imesh | |
253 |
|
253 | |||
254 | matplotlib.pyplot.tight_layout() |
|
254 | matplotlib.pyplot.tight_layout() | |
255 |
|
255 | |||
256 | if XAxisAsTime: |
|
256 | if XAxisAsTime: | |
257 |
|
257 | |||
258 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime("%H:%M:%S")) |
|
258 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime("%H:%M:%S")) | |
259 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
259 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
260 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
260 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
261 |
|
261 | |||
262 | # seconds = numpy.array([xmin, xmax]) |
|
262 | # seconds = numpy.array([xmin, xmax]) | |
263 | # datesList = map(datetime.datetime.fromtimestamp, seconds) |
|
263 | # datesList = map(datetime.datetime.fromtimestamp, seconds) | |
264 | # ax.set_xlim([datesList[0],datesList[-1]]) |
|
264 | # ax.set_xlim([datesList[0],datesList[-1]]) | |
265 | # ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10))) |
|
265 | # ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10))) | |
266 | # ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60))) |
|
266 | # ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60))) | |
267 | # ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S")) |
|
267 | # ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S")) | |
268 | # xdateList = map(datetime.datetime.fromtimestamp, x) |
|
268 | # xdateList = map(datetime.datetime.fromtimestamp, x) | |
269 | # xdate = matplotlib.dates.date2num(xdateList) |
|
269 | # xdate = matplotlib.dates.date2num(xdateList) | |
270 | # x = xdate |
|
270 | # x = xdate | |
271 |
|
271 | |||
272 | # labels = [] |
|
272 | # labels = [] | |
273 | # for item in ax.xaxis.get_ticklabels(): |
|
273 | # for item in ax.xaxis.get_ticklabels(): | |
274 | # stri = item.get_text() |
|
274 | # stri = item.get_text() | |
275 | # text = datetime.datetime.fromtimestamp(float(stri)) |
|
275 | # text = datetime.datetime.fromtimestamp(float(stri)) | |
276 | # labels.append(text) |
|
276 | # labels.append(text) | |
277 | # |
|
277 | # | |
278 | # ax.xaxis.set_ticklabels(labels) |
|
278 | # ax.xaxis.set_ticklabels(labels) | |
279 | return imesh |
|
279 | return imesh | |
280 |
|
280 | |||
281 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
281 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
282 |
|
282 | |||
283 | z = z.T |
|
283 | z = z.T | |
284 |
|
284 | |||
285 | ax = imesh.get_axes() |
|
285 | ax = imesh.get_axes() | |
286 |
|
286 | |||
287 | printLabels(ax, xlabel, ylabel, title) |
|
287 | printLabels(ax, xlabel, ylabel, title) | |
288 |
|
288 | |||
289 | imesh.set_array(z.ravel()) |
|
289 | imesh.set_array(z.ravel()) | |
290 |
|
290 | |||
291 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title=''): |
|
291 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title=''): | |
292 |
|
292 | |||
293 | # xdateList = map(datetime.datetime.fromtimestamp, x) |
|
293 | # xdateList = map(datetime.datetime.fromtimestamp, x) | |
294 | # xdate = matplotlib.dates.date2num(xdateList) |
|
294 | # xdate = matplotlib.dates.date2num(xdateList) | |
295 |
|
295 | |||
296 | printLabels(ax, xlabel, ylabel, title) |
|
296 | printLabels(ax, xlabel, ylabel, title) | |
297 |
|
297 | |||
298 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
298 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
299 |
|
299 | |||
300 | def draw(fig): |
|
300 | def draw(fig): | |
301 |
|
301 | |||
302 | if type(fig) == 'int': |
|
302 | if type(fig) == 'int': | |
303 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
303 | raise ValueError, "This parameter should be of tpye matplotlib figure" | |
304 |
|
304 | |||
305 | fig.canvas.draw() No newline at end of file |
|
305 | fig.canvas.draw() |
@@ -1,494 +1,506 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import copy |
|
8 | import copy | |
9 | import numpy |
|
9 | import numpy | |
10 |
|
10 | |||
11 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
11 | from jroheaderIO import SystemHeader, RadarControllerHeader | |
12 |
|
12 | |||
13 | def hildebrand_sekhon(data, navg): |
|
13 | def hildebrand_sekhon(data, navg): | |
14 | """ |
|
14 | """ | |
15 | This method is for the objective determination of de noise level in Doppler spectra. This |
|
15 | This method is for the objective determination of de noise level in Doppler spectra. This | |
16 | implementation technique is based on the fact that the standard deviation of the spectral |
|
16 | implementation technique is based on the fact that the standard deviation of the spectral | |
17 | densities is equal to the mean spectral density for white Gaussian noise |
|
17 | densities is equal to the mean spectral density for white Gaussian noise | |
18 |
|
18 | |||
19 | Inputs: |
|
19 | Inputs: | |
20 | Data : heights |
|
20 | Data : heights | |
21 | navg : numbers of averages |
|
21 | navg : numbers of averages | |
22 |
|
22 | |||
23 | Return: |
|
23 | Return: | |
24 | -1 : any error |
|
24 | -1 : any error | |
25 | anoise : noise's level |
|
25 | anoise : noise's level | |
26 | """ |
|
26 | """ | |
27 |
|
27 | |||
28 | dataflat = data.copy().reshape(-1) |
|
28 | dataflat = data.copy().reshape(-1) | |
29 | dataflat.sort() |
|
29 | dataflat.sort() | |
30 | npts = dataflat.size #numbers of points of the data |
|
30 | npts = dataflat.size #numbers of points of the data | |
31 |
|
31 | |||
32 | if npts < 32: |
|
32 | if npts < 32: | |
33 | print "error in noise - requires at least 32 points" |
|
33 | print "error in noise - requires at least 32 points" | |
34 | return -1.0 |
|
34 | return -1.0 | |
35 |
|
35 | |||
36 | dataflat2 = numpy.power(dataflat,2) |
|
36 | dataflat2 = numpy.power(dataflat,2) | |
37 |
|
37 | |||
38 | cs = numpy.cumsum(dataflat) |
|
38 | cs = numpy.cumsum(dataflat) | |
39 | cs2 = numpy.cumsum(dataflat2) |
|
39 | cs2 = numpy.cumsum(dataflat2) | |
40 |
|
40 | |||
41 | # data sorted in ascending order |
|
41 | # data sorted in ascending order | |
42 | nmin = int((npts + 7.)/8) |
|
42 | nmin = int((npts + 7.)/8) | |
43 |
|
43 | |||
44 | for i in range(nmin, npts): |
|
44 | for i in range(nmin, npts): | |
45 | s = cs[i] |
|
45 | s = cs[i] | |
46 | s2 = cs2[i] |
|
46 | s2 = cs2[i] | |
47 | p = s / float(i); |
|
47 | p = s / float(i); | |
48 | p2 = p**2; |
|
48 | p2 = p**2; | |
49 | q = s2 / float(i) - p2; |
|
49 | q = s2 / float(i) - p2; | |
50 | leftc = p2; |
|
50 | leftc = p2; | |
51 | rightc = q * float(navg); |
|
51 | rightc = q * float(navg); | |
52 | R2 = leftc/rightc |
|
52 | R2 = leftc/rightc | |
53 |
|
53 | |||
54 | # Signal detect: R2 < 1 (R2 = leftc/rightc) |
|
54 | # Signal detect: R2 < 1 (R2 = leftc/rightc) | |
55 | if R2 < 1: |
|
55 | if R2 < 1: | |
56 | npts_noise = i |
|
56 | npts_noise = i | |
57 | break |
|
57 | break | |
58 |
|
58 | |||
59 |
|
59 | |||
60 | anoise = numpy.average(dataflat[0:npts_noise]) |
|
60 | anoise = numpy.average(dataflat[0:npts_noise]) | |
61 |
|
61 | |||
62 | return anoise; |
|
62 | return anoise; | |
63 |
|
63 | |||
64 | def sorting_bruce(data, navg): |
|
64 | def sorting_bruce(data, navg): | |
65 |
|
65 | |||
66 | data = data.copy() |
|
66 | data = data.copy() | |
67 |
|
67 | |||
68 | sortdata = numpy.sort(data) |
|
68 | sortdata = numpy.sort(data) | |
69 | lenOfData = len(data) |
|
69 | lenOfData = len(data) | |
70 | nums_min = lenOfData/10 |
|
70 | nums_min = lenOfData/10 | |
71 |
|
71 | |||
72 | if (lenOfData/10) > 0: |
|
72 | if (lenOfData/10) > 0: | |
73 | nums_min = lenOfData/10 |
|
73 | nums_min = lenOfData/10 | |
74 | else: |
|
74 | else: | |
75 | nums_min = 0 |
|
75 | nums_min = 0 | |
76 |
|
76 | |||
77 | rtest = 1.0 + 1.0/navg |
|
77 | rtest = 1.0 + 1.0/navg | |
78 |
|
78 | |||
79 | sum = 0. |
|
79 | sum = 0. | |
80 |
|
80 | |||
81 | sumq = 0. |
|
81 | sumq = 0. | |
82 |
|
82 | |||
83 | j = 0 |
|
83 | j = 0 | |
84 |
|
84 | |||
85 | cont = 1 |
|
85 | cont = 1 | |
86 |
|
86 | |||
87 | while((cont==1)and(j<lenOfData)): |
|
87 | while((cont==1)and(j<lenOfData)): | |
88 |
|
88 | |||
89 | sum += sortdata[j] |
|
89 | sum += sortdata[j] | |
90 |
|
90 | |||
91 | sumq += sortdata[j]**2 |
|
91 | sumq += sortdata[j]**2 | |
92 |
|
92 | |||
93 | j += 1 |
|
93 | j += 1 | |
94 |
|
94 | |||
95 | if j > nums_min: |
|
95 | if j > nums_min: | |
96 | if ((sumq*j) <= (rtest*sum**2)): |
|
96 | if ((sumq*j) <= (rtest*sum**2)): | |
97 | lnoise = sum / j |
|
97 | lnoise = sum / j | |
98 | else: |
|
98 | else: | |
99 | j = j - 1 |
|
99 | j = j - 1 | |
100 | sum = sum - sordata[j] |
|
100 | sum = sum - sordata[j] | |
101 | sumq = sumq - sordata[j]**2 |
|
101 | sumq = sumq - sordata[j]**2 | |
102 | cont = 0 |
|
102 | cont = 0 | |
103 |
|
103 | |||
104 | if j == nums_min: |
|
104 | if j == nums_min: | |
105 | lnoise = sum /j |
|
105 | lnoise = sum /j | |
106 |
|
106 | |||
107 | return lnoise |
|
107 | return lnoise | |
108 |
|
108 | |||
109 | class JROData: |
|
109 | class JROData: | |
110 |
|
110 | |||
111 | # m_BasicHeader = BasicHeader() |
|
111 | # m_BasicHeader = BasicHeader() | |
112 | # m_ProcessingHeader = ProcessingHeader() |
|
112 | # m_ProcessingHeader = ProcessingHeader() | |
113 |
|
113 | |||
114 | systemHeaderObj = SystemHeader() |
|
114 | systemHeaderObj = SystemHeader() | |
115 |
|
115 | |||
116 | radarControllerHeaderObj = RadarControllerHeader() |
|
116 | radarControllerHeaderObj = RadarControllerHeader() | |
117 |
|
117 | |||
118 | # data = None |
|
118 | # data = None | |
119 |
|
119 | |||
120 | type = None |
|
120 | type = None | |
121 |
|
121 | |||
122 | dtype = None |
|
122 | dtype = None | |
123 |
|
123 | |||
124 | # nChannels = None |
|
124 | # nChannels = None | |
125 |
|
125 | |||
126 | # nHeights = None |
|
126 | # nHeights = None | |
127 |
|
127 | |||
128 | nProfiles = None |
|
128 | nProfiles = None | |
129 |
|
129 | |||
130 | heightList = None |
|
130 | heightList = None | |
131 |
|
131 | |||
132 | channelList = None |
|
132 | channelList = None | |
133 |
|
133 | |||
134 | flagNoData = True |
|
134 | flagNoData = True | |
135 |
|
135 | |||
136 | flagTimeBlock = False |
|
136 | flagTimeBlock = False | |
137 |
|
137 | |||
138 | utctime = None |
|
138 | utctime = None | |
139 |
|
139 | |||
140 | blocksize = None |
|
140 | blocksize = None | |
141 |
|
141 | |||
142 | nCode = None |
|
142 | nCode = None | |
143 |
|
143 | |||
144 | nBaud = None |
|
144 | nBaud = None | |
145 |
|
145 | |||
146 | code = None |
|
146 | code = None | |
147 |
|
147 | |||
148 | flagDecodeData = True #asumo q la data esta decodificada |
|
148 | flagDecodeData = True #asumo q la data esta decodificada | |
149 |
|
149 | |||
150 | flagDeflipData = True #asumo q la data esta sin flip |
|
150 | flagDeflipData = True #asumo q la data esta sin flip | |
151 |
|
151 | |||
152 | flagShiftFFT = False |
|
152 | flagShiftFFT = False | |
153 |
|
153 | |||
154 | ippSeconds = None |
|
154 | ippSeconds = None | |
155 |
|
155 | |||
156 | timeInterval = None |
|
156 | timeInterval = None | |
157 |
|
157 | |||
158 | nCohInt = None |
|
158 | nCohInt = None | |
159 |
|
159 | |||
160 | noise = None |
|
160 | noise = None | |
161 |
|
161 | |||
162 | #Speed of ligth |
|
162 | #Speed of ligth | |
163 | C = 3e8 |
|
163 | C = 3e8 | |
164 |
|
164 | |||
165 | frequency = 49.92e6 |
|
165 | frequency = 49.92e6 | |
166 |
|
166 | |||
167 | def __init__(self): |
|
167 | def __init__(self): | |
168 |
|
168 | |||
169 | raise ValueError, "This class has not been implemented" |
|
169 | raise ValueError, "This class has not been implemented" | |
170 |
|
170 | |||
171 | def copy(self, inputObj=None): |
|
171 | def copy(self, inputObj=None): | |
172 |
|
172 | |||
173 | if inputObj == None: |
|
173 | if inputObj == None: | |
174 | return copy.deepcopy(self) |
|
174 | return copy.deepcopy(self) | |
175 |
|
175 | |||
176 | for key in inputObj.__dict__.keys(): |
|
176 | for key in inputObj.__dict__.keys(): | |
177 | self.__dict__[key] = inputObj.__dict__[key] |
|
177 | self.__dict__[key] = inputObj.__dict__[key] | |
178 |
|
178 | |||
179 | def deepcopy(self): |
|
179 | def deepcopy(self): | |
180 |
|
180 | |||
181 | return copy.deepcopy(self) |
|
181 | return copy.deepcopy(self) | |
182 |
|
182 | |||
183 | def isEmpty(self): |
|
183 | def isEmpty(self): | |
184 |
|
184 | |||
185 | return self.flagNoData |
|
185 | return self.flagNoData | |
186 |
|
186 | |||
187 | def getNoise(self): |
|
187 | def getNoise(self): | |
188 |
|
188 | |||
189 | raise ValueError, "Not implemented" |
|
189 | raise ValueError, "Not implemented" | |
190 |
|
190 | |||
191 | def getNChannels(self): |
|
191 | def getNChannels(self): | |
192 |
|
192 | |||
193 | return len(self.channelList) |
|
193 | return len(self.channelList) | |
194 |
|
194 | |||
195 | def getChannelIndexList(self): |
|
195 | def getChannelIndexList(self): | |
196 |
|
196 | |||
197 | return range(self.nChannels) |
|
197 | return range(self.nChannels) | |
198 |
|
198 | |||
199 | def getNHeights(self): |
|
199 | def getNHeights(self): | |
200 |
|
200 | |||
201 | return len(self.heightList) |
|
201 | return len(self.heightList) | |
202 |
|
202 | |||
203 | def getHeiRange(self, extrapoints=0): |
|
203 | def getHeiRange(self, extrapoints=0): | |
204 |
|
204 | |||
205 | heis = self.heightList |
|
205 | heis = self.heightList | |
206 | # deltah = self.heightList[1] - self.heightList[0] |
|
206 | # deltah = self.heightList[1] - self.heightList[0] | |
207 | # |
|
207 | # | |
208 | # heis.append(self.heightList[-1]) |
|
208 | # heis.append(self.heightList[-1]) | |
209 |
|
209 | |||
210 | return heis |
|
210 | return heis | |
211 |
|
211 | |||
212 | def getDatatime(self): |
|
212 | def getDatatime(self): | |
213 |
|
213 | |||
214 | datatime = [] |
|
214 | datatime = [] | |
215 |
|
215 | |||
216 | datatime.append(self.utctime) |
|
216 | datatime.append(self.utctime) | |
217 | datatime.append(self.utctime + 2*self.timeInterval) |
|
217 | datatime.append(self.utctime + 2*self.timeInterval) | |
218 |
|
218 | |||
219 | datatime = numpy.array(datatime) |
|
219 | datatime = numpy.array(datatime) | |
220 |
|
220 | |||
221 | return datatime |
|
221 | return datatime | |
222 |
|
222 | |||
223 | def getFmax(self): |
|
223 | def getFmax(self): | |
224 |
|
224 | |||
225 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
225 | PRF = 1./(self.ippSeconds * self.nCohInt) | |
226 |
|
226 | |||
227 | fmax = PRF/2. |
|
227 | fmax = PRF/2. | |
228 |
|
228 | |||
229 | return fmax |
|
229 | return fmax | |
230 |
|
230 | |||
231 | def getVmax(self): |
|
231 | def getVmax(self): | |
232 |
|
232 | |||
233 | _lambda = self.C/self.frequency |
|
233 | _lambda = self.C/self.frequency | |
234 |
|
234 | |||
235 | vmax = self.getFmax() * _lambda / 2. |
|
235 | vmax = self.getFmax() * _lambda / 2. | |
236 |
|
236 | |||
237 | return vmax |
|
237 | return vmax | |
238 |
|
238 | |||
239 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
239 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
240 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
240 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
241 |
|
241 | |||
242 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
242 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
243 |
|
243 | |||
244 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
244 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
245 |
|
245 | |||
246 | class Voltage(JROData): |
|
246 | class Voltage(JROData): | |
247 |
|
247 | |||
248 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
248 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
249 | data = None |
|
249 | data = None | |
250 |
|
250 | |||
251 | def __init__(self): |
|
251 | def __init__(self): | |
252 | ''' |
|
252 | ''' | |
253 | Constructor |
|
253 | Constructor | |
254 | ''' |
|
254 | ''' | |
255 |
|
255 | |||
256 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
256 | self.radarControllerHeaderObj = RadarControllerHeader() | |
257 |
|
257 | |||
258 | self.systemHeaderObj = SystemHeader() |
|
258 | self.systemHeaderObj = SystemHeader() | |
259 |
|
259 | |||
260 | self.type = "Voltage" |
|
260 | self.type = "Voltage" | |
261 |
|
261 | |||
262 | self.data = None |
|
262 | self.data = None | |
263 |
|
263 | |||
264 | self.dtype = None |
|
264 | self.dtype = None | |
265 |
|
265 | |||
266 | # self.nChannels = 0 |
|
266 | # self.nChannels = 0 | |
267 |
|
267 | |||
268 | # self.nHeights = 0 |
|
268 | # self.nHeights = 0 | |
269 |
|
269 | |||
270 | self.nProfiles = None |
|
270 | self.nProfiles = None | |
271 |
|
271 | |||
272 | self.heightList = None |
|
272 | self.heightList = None | |
273 |
|
273 | |||
274 | self.channelList = None |
|
274 | self.channelList = None | |
275 |
|
275 | |||
276 | # self.channelIndexList = None |
|
276 | # self.channelIndexList = None | |
277 |
|
277 | |||
278 | self.flagNoData = True |
|
278 | self.flagNoData = True | |
279 |
|
279 | |||
280 | self.flagTimeBlock = False |
|
280 | self.flagTimeBlock = False | |
281 |
|
281 | |||
282 | self.utctime = None |
|
282 | self.utctime = None | |
283 |
|
283 | |||
284 | self.nCohInt = None |
|
284 | self.nCohInt = None | |
285 |
|
285 | |||
286 | self.blocksize = None |
|
286 | self.blocksize = None | |
287 |
|
287 | |||
288 | def getNoisebyHildebrand(self): |
|
288 | def getNoisebyHildebrand(self): | |
289 | """ |
|
289 | """ | |
290 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
290 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
291 |
|
291 | |||
292 | Return: |
|
292 | Return: | |
293 | noiselevel |
|
293 | noiselevel | |
294 | """ |
|
294 | """ | |
295 |
|
295 | |||
296 | for channel in range(self.nChannels): |
|
296 | for channel in range(self.nChannels): | |
297 | daux = self.data_spc[channel,:,:] |
|
297 | daux = self.data_spc[channel,:,:] | |
298 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) |
|
298 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) | |
299 |
|
299 | |||
300 | return self.noise |
|
300 | return self.noise | |
301 |
|
301 | |||
302 | def getNoise(self, type = 1): |
|
302 | def getNoise(self, type = 1): | |
303 |
|
303 | |||
304 | self.noise = numpy.zeros(self.nChannels) |
|
304 | self.noise = numpy.zeros(self.nChannels) | |
305 |
|
305 | |||
306 | if type == 1: |
|
306 | if type == 1: | |
307 | noise = self.getNoisebyHildebrand() |
|
307 | noise = self.getNoisebyHildebrand() | |
308 |
|
308 | |||
309 | return 10*numpy.log10(noise) |
|
309 | return 10*numpy.log10(noise) | |
310 |
|
310 | |||
311 | class Spectra(JROData): |
|
311 | class Spectra(JROData): | |
312 |
|
312 | |||
313 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
313 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
314 | data_spc = None |
|
314 | data_spc = None | |
315 |
|
315 | |||
316 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
316 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) | |
317 | data_cspc = None |
|
317 | data_cspc = None | |
318 |
|
318 | |||
319 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
319 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
320 | data_dc = None |
|
320 | data_dc = None | |
321 |
|
321 | |||
322 | nFFTPoints = None |
|
322 | nFFTPoints = None | |
323 |
|
323 | |||
324 | nPairs = None |
|
324 | nPairs = None | |
325 |
|
325 | |||
326 | pairsList = None |
|
326 | pairsList = None | |
327 |
|
327 | |||
328 | nIncohInt = None |
|
328 | nIncohInt = None | |
329 |
|
329 | |||
330 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
330 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia | |
331 |
|
331 | |||
332 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
332 | nCohInt = None #se requiere para determinar el valor de timeInterval | |
333 |
|
333 | |||
334 | def __init__(self): |
|
334 | def __init__(self): | |
335 | ''' |
|
335 | ''' | |
336 | Constructor |
|
336 | Constructor | |
337 | ''' |
|
337 | ''' | |
338 |
|
338 | |||
339 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
339 | self.radarControllerHeaderObj = RadarControllerHeader() | |
340 |
|
340 | |||
341 | self.systemHeaderObj = SystemHeader() |
|
341 | self.systemHeaderObj = SystemHeader() | |
342 |
|
342 | |||
343 | self.type = "Spectra" |
|
343 | self.type = "Spectra" | |
344 |
|
344 | |||
345 | # self.data = None |
|
345 | # self.data = None | |
346 |
|
346 | |||
347 | self.dtype = None |
|
347 | self.dtype = None | |
348 |
|
348 | |||
349 | # self.nChannels = 0 |
|
349 | # self.nChannels = 0 | |
350 |
|
350 | |||
351 | # self.nHeights = 0 |
|
351 | # self.nHeights = 0 | |
352 |
|
352 | |||
353 | self.nProfiles = None |
|
353 | self.nProfiles = None | |
354 |
|
354 | |||
355 | self.heightList = None |
|
355 | self.heightList = None | |
356 |
|
356 | |||
357 | self.channelList = None |
|
357 | self.channelList = None | |
358 |
|
358 | |||
359 | # self.channelIndexList = None |
|
359 | # self.channelIndexList = None | |
360 |
|
360 | |||
361 | self.flagNoData = True |
|
361 | self.flagNoData = True | |
362 |
|
362 | |||
363 | self.flagTimeBlock = False |
|
363 | self.flagTimeBlock = False | |
364 |
|
364 | |||
365 | self.utctime = None |
|
365 | self.utctime = None | |
366 |
|
366 | |||
367 | self.nCohInt = None |
|
367 | self.nCohInt = None | |
368 |
|
368 | |||
369 | self.nIncohInt = None |
|
369 | self.nIncohInt = None | |
370 |
|
370 | |||
371 | self.blocksize = None |
|
371 | self.blocksize = None | |
372 |
|
372 | |||
373 | self.nFFTPoints = None |
|
373 | self.nFFTPoints = None | |
374 |
|
374 | |||
375 | self.wavelength = None |
|
375 | self.wavelength = None | |
376 |
|
||||
377 | def getFreqRange(self, extrapoints=0): |
|
|||
378 |
|
||||
379 | delfreq = 2 * self.getFmax() / self.nFFTPoints |
|
|||
380 | freqrange = deltafreqs*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
|||
381 |
|
||||
382 | return freqrange |
|
|||
383 |
|
||||
384 | def getVelRange(self, extrapoints=0): |
|
|||
385 |
|
||||
386 | deltav = 2 * self.getVmax() / self.nFFTPoints |
|
|||
387 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 |
|
|||
388 |
|
||||
389 | return velrange |
|
|||
390 |
|
376 | |||
391 | def getNoisebyHildebrand(self): |
|
377 | def getNoisebyHildebrand(self): | |
392 | """ |
|
378 | """ | |
393 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
379 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
394 |
|
380 | |||
395 | Return: |
|
381 | Return: | |
396 | noiselevel |
|
382 | noiselevel | |
397 | """ |
|
383 | """ | |
398 |
|
384 | |||
399 | for channel in range(self.nChannels): |
|
385 | for channel in range(self.nChannels): | |
400 | daux = self.data_spc[channel,:,:] |
|
386 | daux = self.data_spc[channel,:,:] | |
401 | self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
387 | self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
402 |
|
388 | |||
403 | return self.noise |
|
389 | return self.noise | |
404 |
|
390 | |||
405 | def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1): |
|
391 | def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1): | |
406 | """ |
|
392 | """ | |
407 | Determina el ruido del canal utilizando la ventana indicada con las coordenadas: |
|
393 | Determina el ruido del canal utilizando la ventana indicada con las coordenadas: | |
408 | (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx) |
|
394 | (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx) | |
409 |
|
395 | |||
410 | Inputs: |
|
396 | Inputs: | |
411 | heiIndexMin: Limite inferior del eje de alturas |
|
397 | heiIndexMin: Limite inferior del eje de alturas | |
412 | heiIndexMax: Limite superior del eje de alturas |
|
398 | heiIndexMax: Limite superior del eje de alturas | |
413 | freqIndexMin: Limite inferior del eje de frecuencia |
|
399 | freqIndexMin: Limite inferior del eje de frecuencia | |
414 | freqIndexMax: Limite supoerior del eje de frecuencia |
|
400 | freqIndexMax: Limite supoerior del eje de frecuencia | |
415 | """ |
|
401 | """ | |
416 |
|
402 | |||
417 | data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax] |
|
403 | data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax] | |
418 |
|
404 | |||
419 | for channel in range(self.nChannels): |
|
405 | for channel in range(self.nChannels): | |
420 | daux = data[channel,:,:] |
|
406 | daux = data[channel,:,:] | |
421 | self.noise[channel] = numpy.average(daux) |
|
407 | self.noise[channel] = numpy.average(daux) | |
422 |
|
408 | |||
423 | return self.noise |
|
409 | return self.noise | |
424 |
|
410 | |||
425 | def getNoisebySort(self): |
|
411 | def getNoisebySort(self): | |
426 |
|
412 | |||
427 | for channel in range(self.nChannels): |
|
413 | for channel in range(self.nChannels): | |
428 | daux = self.data_spc[channel,:,:] |
|
414 | daux = self.data_spc[channel,:,:] | |
429 | self.noise[channel] = sorting_bruce(daux, self.nIncohInt) |
|
415 | self.noise[channel] = sorting_bruce(daux, self.nIncohInt) | |
430 |
|
416 | |||
431 | return self.noise |
|
417 | return self.noise | |
432 |
|
418 | |||
433 | def getNoise(self, type = 1): |
|
419 | def getNoise(self, type = 1): | |
434 |
|
420 | |||
435 | self.noise = numpy.zeros(self.nChannels) |
|
421 | self.noise = numpy.zeros(self.nChannels) | |
436 |
|
422 | |||
437 | if type == 1: |
|
423 | if type == 1: | |
438 | noise = self.getNoisebyHildebrand() |
|
424 | noise = self.getNoisebyHildebrand() | |
439 |
|
425 | |||
440 | if type == 2: |
|
426 | if type == 2: | |
441 | noise = self.getNoisebySort() |
|
427 | noise = self.getNoisebySort() | |
442 |
|
428 | |||
443 | if type == 3: |
|
429 | if type == 3: | |
444 | noise = self.getNoisebyWindow() |
|
430 | noise = self.getNoisebyWindow() | |
445 |
|
431 | |||
446 | return 10*numpy.log10(noise) |
|
432 | return 10*numpy.log10(noise) | |
|
433 | ||||
|
434 | ||||
|
435 | def getFreqRange(self, extrapoints=0): | |||
|
436 | ||||
|
437 | delfreq = 2 * self.getFmax() / self.nFFTPoints | |||
|
438 | freqrange = deltafreqs*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |||
|
439 | ||||
|
440 | return freqrange | |||
|
441 | ||||
|
442 | def getVelRange(self, extrapoints=0): | |||
|
443 | ||||
|
444 | deltav = 2 * self.getVmax() / self.nFFTPoints | |||
|
445 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 | |||
|
446 | ||||
|
447 | return velrange | |||
|
448 | ||||
|
449 | def getNPairs(self): | |||
|
450 | ||||
|
451 | return len(self.pairsList) | |||
|
452 | ||||
|
453 | def getPairsIndexList(self): | |||
|
454 | ||||
|
455 | return range(self.nPairs) | |||
|
456 | ||||
|
457 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") | |||
|
458 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") | |||
447 |
|
459 | |||
448 | class SpectraHeis(JROData): |
|
460 | class SpectraHeis(JROData): | |
449 |
|
461 | |||
450 | data_spc = None |
|
462 | data_spc = None | |
451 |
|
463 | |||
452 | data_cspc = None |
|
464 | data_cspc = None | |
453 |
|
465 | |||
454 | data_dc = None |
|
466 | data_dc = None | |
455 |
|
467 | |||
456 | nFFTPoints = None |
|
468 | nFFTPoints = None | |
457 |
|
469 | |||
458 | nPairs = None |
|
470 | nPairs = None | |
459 |
|
471 | |||
460 | pairsList = None |
|
472 | pairsList = None | |
461 |
|
473 | |||
462 | nIncohInt = None |
|
474 | nIncohInt = None | |
463 |
|
475 | |||
464 | def __init__(self): |
|
476 | def __init__(self): | |
465 |
|
477 | |||
466 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
478 | self.radarControllerHeaderObj = RadarControllerHeader() | |
467 |
|
479 | |||
468 | self.systemHeaderObj = SystemHeader() |
|
480 | self.systemHeaderObj = SystemHeader() | |
469 |
|
481 | |||
470 | self.type = "SpectraHeis" |
|
482 | self.type = "SpectraHeis" | |
471 |
|
483 | |||
472 | self.dtype = None |
|
484 | self.dtype = None | |
473 |
|
485 | |||
474 | # self.nChannels = 0 |
|
486 | # self.nChannels = 0 | |
475 |
|
487 | |||
476 | # self.nHeights = 0 |
|
488 | # self.nHeights = 0 | |
477 |
|
489 | |||
478 | self.nProfiles = None |
|
490 | self.nProfiles = None | |
479 |
|
491 | |||
480 | self.heightList = None |
|
492 | self.heightList = None | |
481 |
|
493 | |||
482 | self.channelList = None |
|
494 | self.channelList = None | |
483 |
|
495 | |||
484 | # self.channelIndexList = None |
|
496 | # self.channelIndexList = None | |
485 |
|
497 | |||
486 | self.flagNoData = True |
|
498 | self.flagNoData = True | |
487 |
|
499 | |||
488 | self.flagTimeBlock = False |
|
500 | self.flagTimeBlock = False | |
489 |
|
501 | |||
490 | self.nPairs = 0 |
|
502 | self.nPairs = 0 | |
491 |
|
503 | |||
492 | self.utctime = None |
|
504 | self.utctime = None | |
493 |
|
505 | |||
494 | self.blocksize = None |
|
506 | self.blocksize = None |
@@ -1,427 +1,586 | |||||
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): | |||
|
6 | ||||
|
7 | __isConfig = None | |||
|
8 | __nsubplots = None | |||
|
9 | ||||
|
10 | WIDTHPROF = None | |||
|
11 | HEIGHTPROF = None | |||
|
12 | PREFIX = 'spc' | |||
|
13 | ||||
|
14 | def __init__(self): | |||
|
15 | ||||
|
16 | self.__isConfig = False | |||
|
17 | self.__nsubplots = 4 | |||
|
18 | ||||
|
19 | self.WIDTH = 300 | |||
|
20 | self.HEIGHT = 400 | |||
|
21 | self.WIDTHPROF = 0 | |||
|
22 | self.HEIGHTPROF = 0 | |||
|
23 | ||||
|
24 | def getSubplots(self): | |||
|
25 | ||||
|
26 | ncol = 4 | |||
|
27 | nrow = self.nplots | |||
|
28 | ||||
|
29 | return nrow, ncol | |||
|
30 | ||||
|
31 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |||
|
32 | ||||
|
33 | self.__showprofile = showprofile | |||
|
34 | self.nplots = nplots | |||
|
35 | ||||
|
36 | ncolspan = 1 | |||
|
37 | colspan = 1 | |||
|
38 | ||||
|
39 | self.createFigure(idfigure = idfigure, | |||
|
40 | wintitle = wintitle, | |||
|
41 | widthplot = self.WIDTH + self.WIDTHPROF, | |||
|
42 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |||
|
43 | ||||
|
44 | nrow, ncol = self.getSubplots() | |||
|
45 | ||||
|
46 | counter = 0 | |||
|
47 | for y in range(nrow): | |||
|
48 | for x in range(ncol): | |||
|
49 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |||
|
50 | ||||
|
51 | counter += 1 | |||
|
52 | ||||
|
53 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', | |||
|
54 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |||
|
55 | save=False, figpath='./', figfile=None): | |||
|
56 | ||||
|
57 | """ | |||
|
58 | ||||
|
59 | Input: | |||
|
60 | dataOut : | |||
|
61 | idfigure : | |||
|
62 | wintitle : | |||
|
63 | channelList : | |||
|
64 | showProfile : | |||
|
65 | xmin : None, | |||
|
66 | xmax : None, | |||
|
67 | ymin : None, | |||
|
68 | ymax : None, | |||
|
69 | zmin : None, | |||
|
70 | zmax : None | |||
|
71 | """ | |||
|
72 | ||||
|
73 | if pairsList == None: | |||
|
74 | pairsIndexList = dataOut.pairsIndexList | |||
|
75 | else: | |||
|
76 | pairsIndexList = [] | |||
|
77 | for pair in pairsList: | |||
|
78 | if pair not in dataOut.pairsList: | |||
|
79 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |||
|
80 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |||
|
81 | ||||
|
82 | x = dataOut.getVelRange(1) | |||
|
83 | y = dataOut.getHeiRange() | |||
|
84 | z = 10.*numpy.log10(dataOut.data_spc[:,:,:]) | |||
|
85 | avg = numpy.average(numpy.abs(z), axis=1) | |||
|
86 | ||||
|
87 | noise = dataOut.getNoise() | |||
|
88 | ||||
|
89 | if not self.__isConfig: | |||
|
90 | ||||
|
91 | nplots = len(pairsIndexList) | |||
|
92 | ||||
|
93 | self.setup(idfigure=idfigure, | |||
|
94 | nplots=nplots, | |||
|
95 | wintitle=wintitle, | |||
|
96 | showprofile=showprofile) | |||
|
97 | ||||
|
98 | if xmin == None: xmin = numpy.nanmin(x) | |||
|
99 | if xmax == None: xmax = numpy.nanmax(x) | |||
|
100 | if ymin == None: ymin = numpy.nanmin(y) | |||
|
101 | if ymax == None: ymax = numpy.nanmax(y) | |||
|
102 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |||
|
103 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |||
|
104 | ||||
|
105 | self.__isConfig = True | |||
|
106 | ||||
|
107 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |||
|
108 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |||
|
109 | xlabel = "Velocity (m/s)" | |||
|
110 | ylabel = "Range (Km)" | |||
|
111 | ||||
|
112 | self.setWinTitle(title) | |||
|
113 | ||||
|
114 | for i in range(self.nplots): | |||
|
115 | pair = dataOut.pairsList[pairsIndexList[i]] | |||
|
116 | ||||
|
117 | title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]]) | |||
|
118 | z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) | |||
|
119 | axes0 = self.axesList[i*self.__nsubplots] | |||
|
120 | axes0.pcolor(x, y, z, | |||
|
121 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |||
|
122 | xlabel=xlabel, ylabel=ylabel, title=title, | |||
|
123 | ticksize=9, cblabel='') | |||
|
124 | ||||
|
125 | title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]]) | |||
|
126 | z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) | |||
|
127 | axes0 = self.axesList[i*self.__nsubplots+1] | |||
|
128 | axes0.pcolor(x, y, z, | |||
|
129 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |||
|
130 | xlabel=xlabel, ylabel=ylabel, title=title, | |||
|
131 | ticksize=9, cblabel='') | |||
|
132 | ||||
|
133 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |||
|
134 | coherence = numpy.abs(coherenceComplex) | |||
|
135 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |||
|
136 | ||||
|
137 | ||||
|
138 | title = "Coherence %d%d" %(pair[0], pair[1]) | |||
|
139 | axes0 = self.axesList[i*self.__nsubplots+2] | |||
|
140 | axes0.pcolor(x, y, coherence, | |||
|
141 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-1, zmax=1, | |||
|
142 | xlabel=xlabel, ylabel=ylabel, title=title, | |||
|
143 | ticksize=9, cblabel='') | |||
|
144 | ||||
|
145 | title = "Phase %d%d" %(pair[0], pair[1]) | |||
|
146 | axes0 = self.axesList[i*self.__nsubplots+3] | |||
|
147 | axes0.pcolor(x, y, phase, | |||
|
148 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |||
|
149 | xlabel=xlabel, ylabel=ylabel, title=title, | |||
|
150 | ticksize=9, cblabel='') | |||
|
151 | ||||
|
152 | ||||
|
153 | ||||
|
154 | self.draw() | |||
|
155 | ||||
|
156 | if save: | |||
|
157 | date = thisDatetime.strftime("%Y%m%d") | |||
|
158 | if figfile == None: | |||
|
159 | figfile = self.getFilename(name = date) | |||
|
160 | ||||
|
161 | self.saveFigure(figpath, figfile) | |||
|
162 | ||||
|
163 | ||||
5 | class RTIPlot(Figure): |
|
164 | class RTIPlot(Figure): | |
6 |
|
165 | |||
7 | __isConfig = None |
|
166 | __isConfig = None | |
8 | __nsubplots = None |
|
167 | __nsubplots = None | |
9 |
|
168 | |||
10 | WIDTHPROF = None |
|
169 | WIDTHPROF = None | |
11 | HEIGHTPROF = None |
|
170 | HEIGHTPROF = None | |
12 | PREFIX = 'rti' |
|
171 | PREFIX = 'rti' | |
13 |
|
172 | |||
14 | def __init__(self): |
|
173 | def __init__(self): | |
15 |
|
174 | |||
16 | self.__timerange = 24*60*60 |
|
175 | self.__timerange = 24*60*60 | |
17 | self.__isConfig = False |
|
176 | self.__isConfig = False | |
18 | self.__nsubplots = 1 |
|
177 | self.__nsubplots = 1 | |
19 |
|
178 | |||
20 | self.WIDTH = 800 |
|
179 | self.WIDTH = 800 | |
21 | self.HEIGHT = 200 |
|
180 | self.HEIGHT = 200 | |
22 | self.WIDTHPROF = 120 |
|
181 | self.WIDTHPROF = 120 | |
23 | self.HEIGHTPROF = 0 |
|
182 | self.HEIGHTPROF = 0 | |
24 |
|
183 | |||
25 | def getSubplots(self): |
|
184 | def getSubplots(self): | |
26 |
|
185 | |||
27 | ncol = 1 |
|
186 | ncol = 1 | |
28 | nrow = self.nplots |
|
187 | nrow = self.nplots | |
29 |
|
188 | |||
30 | return nrow, ncol |
|
189 | return nrow, ncol | |
31 |
|
190 | |||
32 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
191 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
33 |
|
192 | |||
34 | self.__showprofile = showprofile |
|
193 | self.__showprofile = showprofile | |
35 | self.nplots = nplots |
|
194 | self.nplots = nplots | |
36 |
|
195 | |||
37 | ncolspan = 1 |
|
196 | ncolspan = 1 | |
38 | colspan = 1 |
|
197 | colspan = 1 | |
39 | if showprofile: |
|
198 | if showprofile: | |
40 | ncolspan = 7 |
|
199 | ncolspan = 7 | |
41 | colspan = 6 |
|
200 | colspan = 6 | |
42 | self.__nsubplots = 2 |
|
201 | self.__nsubplots = 2 | |
43 |
|
202 | |||
44 | self.createFigure(idfigure = idfigure, |
|
203 | self.createFigure(idfigure = idfigure, | |
45 | wintitle = wintitle, |
|
204 | wintitle = wintitle, | |
46 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
205 | widthplot = self.WIDTH + self.WIDTHPROF, | |
47 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
206 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
48 |
|
207 | |||
49 | nrow, ncol = self.getSubplots() |
|
208 | nrow, ncol = self.getSubplots() | |
50 |
|
209 | |||
51 | counter = 0 |
|
210 | counter = 0 | |
52 | for y in range(nrow): |
|
211 | for y in range(nrow): | |
53 | for x in range(ncol): |
|
212 | for x in range(ncol): | |
54 |
|
213 | |||
55 | if counter >= self.nplots: |
|
214 | if counter >= self.nplots: | |
56 | break |
|
215 | break | |
57 |
|
216 | |||
58 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
217 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
59 |
|
218 | |||
60 | if showprofile: |
|
219 | if showprofile: | |
61 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
220 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
62 |
|
221 | |||
63 | counter += 1 |
|
222 | counter += 1 | |
64 |
|
223 | |||
65 | def __getTimeLim(self, x, xmin, xmax): |
|
224 | def __getTimeLim(self, x, xmin, xmax): | |
66 |
|
225 | |||
67 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) |
|
226 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) | |
68 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
227 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |
69 |
|
228 | |||
70 | #################################################### |
|
229 | #################################################### | |
71 | #If the x is out of xrange |
|
230 | #If the x is out of xrange | |
72 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
231 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): | |
73 | xmin = None |
|
232 | xmin = None | |
74 | xmax = None |
|
233 | xmax = None | |
75 |
|
234 | |||
76 | if xmin == None: |
|
235 | if xmin == None: | |
77 | td = thisdatetime - thisdate |
|
236 | td = thisdatetime - thisdate | |
78 | xmin = td.seconds/(60*60.) |
|
237 | xmin = td.seconds/(60*60.) | |
79 |
|
238 | |||
80 | if xmax == None: |
|
239 | if xmax == None: | |
81 | xmax = xmin + self.__timerange/(60*60.) |
|
240 | xmax = xmin + self.__timerange/(60*60.) | |
82 |
|
241 | |||
83 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) |
|
242 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) | |
84 | tmin = time.mktime(mindt.timetuple()) |
|
243 | tmin = time.mktime(mindt.timetuple()) | |
85 |
|
244 | |||
86 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) |
|
245 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) | |
87 | tmax = time.mktime(maxdt.timetuple()) |
|
246 | tmax = time.mktime(maxdt.timetuple()) | |
88 |
|
247 | |||
89 | self.__timerange = tmax - tmin |
|
248 | self.__timerange = tmax - tmin | |
90 |
|
249 | |||
91 | return tmin, tmax |
|
250 | return tmin, tmax | |
92 |
|
251 | |||
93 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
252 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
94 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
253 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
95 | timerange=None, |
|
254 | timerange=None, | |
96 | save=False, figpath='./', figfile=None): |
|
255 | save=False, figpath='./', figfile=None): | |
97 |
|
256 | |||
98 | """ |
|
257 | """ | |
99 |
|
258 | |||
100 | Input: |
|
259 | Input: | |
101 | dataOut : |
|
260 | dataOut : | |
102 | idfigure : |
|
261 | idfigure : | |
103 | wintitle : |
|
262 | wintitle : | |
104 | channelList : |
|
263 | channelList : | |
105 | showProfile : |
|
264 | showProfile : | |
106 | xmin : None, |
|
265 | xmin : None, | |
107 | xmax : None, |
|
266 | xmax : None, | |
108 | ymin : None, |
|
267 | ymin : None, | |
109 | ymax : None, |
|
268 | ymax : None, | |
110 | zmin : None, |
|
269 | zmin : None, | |
111 | zmax : None |
|
270 | zmax : None | |
112 | """ |
|
271 | """ | |
113 |
|
272 | |||
114 | if channelList == None: |
|
273 | if channelList == None: | |
115 | channelIndexList = dataOut.channelIndexList |
|
274 | channelIndexList = dataOut.channelIndexList | |
116 | else: |
|
275 | else: | |
117 | channelIndexList = [] |
|
276 | channelIndexList = [] | |
118 | for channel in channelList: |
|
277 | for channel in channelList: | |
119 | if channel not in dataOut.channelList: |
|
278 | if channel not in dataOut.channelList: | |
120 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
279 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
121 |
channelIndexList.append(dataOut.channelList.index( |
|
280 | channelIndexList.append(dataOut.channelList.index(channel)) | |
122 |
|
281 | |||
123 | if timerange != None: |
|
282 | if timerange != None: | |
124 | self.__timerange = timerange |
|
283 | self.__timerange = timerange | |
125 |
|
284 | |||
126 | tmin = None |
|
285 | tmin = None | |
127 | tmax = None |
|
286 | tmax = None | |
128 | x = dataOut.getDatatime() |
|
287 | x = dataOut.getDatatime() | |
129 | y = dataOut.getHeiRange() |
|
288 | y = dataOut.getHeiRange() | |
130 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
289 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) | |
131 | avg = numpy.average(z, axis=1) |
|
290 | avg = numpy.average(z, axis=1) | |
132 |
|
291 | |||
133 | noise = dataOut.getNoise() |
|
292 | noise = dataOut.getNoise() | |
134 |
|
293 | |||
135 | if not self.__isConfig: |
|
294 | if not self.__isConfig: | |
136 |
|
295 | |||
137 | nplots = len(channelIndexList) |
|
296 | nplots = len(channelIndexList) | |
138 |
|
297 | |||
139 | self.setup(idfigure=idfigure, |
|
298 | self.setup(idfigure=idfigure, | |
140 | nplots=nplots, |
|
299 | nplots=nplots, | |
141 | wintitle=wintitle, |
|
300 | wintitle=wintitle, | |
142 | showprofile=showprofile) |
|
301 | showprofile=showprofile) | |
143 |
|
302 | |||
144 | tmin, tmax = self.__getTimeLim(x, xmin, xmax) |
|
303 | tmin, tmax = self.__getTimeLim(x, xmin, xmax) | |
145 | if ymin == None: ymin = numpy.nanmin(y) |
|
304 | if ymin == None: ymin = numpy.nanmin(y) | |
146 | if ymax == None: ymax = numpy.nanmax(y) |
|
305 | if ymax == None: ymax = numpy.nanmax(y) | |
147 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
306 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |
148 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
307 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |
149 |
|
308 | |||
150 | self.__isConfig = True |
|
309 | self.__isConfig = True | |
151 |
|
310 | |||
152 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
311 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
153 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
312 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
154 | xlabel = "Velocity (m/s)" |
|
313 | xlabel = "Velocity (m/s)" | |
155 | ylabel = "Range (Km)" |
|
314 | ylabel = "Range (Km)" | |
156 |
|
315 | |||
157 | self.setWinTitle(title) |
|
316 | self.setWinTitle(title) | |
158 |
|
317 | |||
159 | for i in range(self.nplots): |
|
318 | for i in range(self.nplots): | |
160 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
319 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
161 | axes = self.axesList[i*self.__nsubplots] |
|
320 | axes = self.axesList[i*self.__nsubplots] | |
162 | z = avg[i].reshape((1,-1)) |
|
321 | z = avg[i].reshape((1,-1)) | |
163 | axes.pcolor(x, y, z, |
|
322 | axes.pcolor(x, y, z, | |
164 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
323 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
165 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
324 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
166 | ticksize=9, cblabel='', cbsize="1%") |
|
325 | ticksize=9, cblabel='', cbsize="1%") | |
167 |
|
326 | |||
168 | if self.__showprofile: |
|
327 | if self.__showprofile: | |
169 | axes = self.axesList[i*self.__nsubplots +1] |
|
328 | axes = self.axesList[i*self.__nsubplots +1] | |
170 | axes.pline(avg[i], y, |
|
329 | axes.pline(avg[i], y, | |
171 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
330 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
172 | xlabel='dB', ylabel='', title='', |
|
331 | xlabel='dB', ylabel='', title='', | |
173 | ytick_visible=False, |
|
332 | ytick_visible=False, | |
174 | grid='x') |
|
333 | grid='x') | |
175 |
|
334 | |||
176 | self.draw() |
|
335 | self.draw() | |
177 |
|
336 | |||
178 | if save: |
|
337 | if save: | |
179 | date = thisDatetime.strftime("%Y%m%d") |
|
338 | date = thisDatetime.strftime("%Y%m%d") | |
180 | if figfile == None: |
|
339 | if figfile == None: | |
181 | figfile = self.getFilename(name = date) |
|
340 | figfile = self.getFilename(name = date) | |
182 |
|
341 | |||
183 | self.saveFigure(figpath, figfile) |
|
342 | self.saveFigure(figpath, figfile) | |
184 |
|
343 | |||
185 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
344 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
186 | self.__isConfig = False |
|
345 | self.__isConfig = False | |
187 |
|
346 | |||
188 | class SpectraPlot(Figure): |
|
347 | class SpectraPlot(Figure): | |
189 |
|
348 | |||
190 | __isConfig = None |
|
349 | __isConfig = None | |
191 | __nsubplots = None |
|
350 | __nsubplots = None | |
192 |
|
351 | |||
193 | WIDTHPROF = None |
|
352 | WIDTHPROF = None | |
194 | HEIGHTPROF = None |
|
353 | HEIGHTPROF = None | |
195 | PREFIX = 'spc' |
|
354 | PREFIX = 'spc' | |
196 |
|
355 | |||
197 | def __init__(self): |
|
356 | def __init__(self): | |
198 |
|
357 | |||
199 | self.__isConfig = False |
|
358 | self.__isConfig = False | |
200 | self.__nsubplots = 1 |
|
359 | self.__nsubplots = 1 | |
201 |
|
360 | |||
202 | self.WIDTH = 300 |
|
361 | self.WIDTH = 300 | |
203 | self.HEIGHT = 400 |
|
362 | self.HEIGHT = 400 | |
204 | self.WIDTHPROF = 120 |
|
363 | self.WIDTHPROF = 120 | |
205 | self.HEIGHTPROF = 0 |
|
364 | self.HEIGHTPROF = 0 | |
206 |
|
365 | |||
207 | def getSubplots(self): |
|
366 | def getSubplots(self): | |
208 |
|
367 | |||
209 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
368 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
210 | nrow = int(self.nplots*1./ncol + 0.9) |
|
369 | nrow = int(self.nplots*1./ncol + 0.9) | |
211 |
|
370 | |||
212 | return nrow, ncol |
|
371 | return nrow, ncol | |
213 |
|
372 | |||
214 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
373 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
215 |
|
374 | |||
216 | self.__showprofile = showprofile |
|
375 | self.__showprofile = showprofile | |
217 | self.nplots = nplots |
|
376 | self.nplots = nplots | |
218 |
|
377 | |||
219 | ncolspan = 1 |
|
378 | ncolspan = 1 | |
220 | colspan = 1 |
|
379 | colspan = 1 | |
221 | if showprofile: |
|
380 | if showprofile: | |
222 | ncolspan = 3 |
|
381 | ncolspan = 3 | |
223 | colspan = 2 |
|
382 | colspan = 2 | |
224 | self.__nsubplots = 2 |
|
383 | self.__nsubplots = 2 | |
225 |
|
384 | |||
226 | self.createFigure(idfigure = idfigure, |
|
385 | self.createFigure(idfigure = idfigure, | |
227 | wintitle = wintitle, |
|
386 | wintitle = wintitle, | |
228 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
387 | widthplot = self.WIDTH + self.WIDTHPROF, | |
229 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
388 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
230 |
|
389 | |||
231 | nrow, ncol = self.getSubplots() |
|
390 | nrow, ncol = self.getSubplots() | |
232 |
|
391 | |||
233 | counter = 0 |
|
392 | counter = 0 | |
234 | for y in range(nrow): |
|
393 | for y in range(nrow): | |
235 | for x in range(ncol): |
|
394 | for x in range(ncol): | |
236 |
|
395 | |||
237 | if counter >= self.nplots: |
|
396 | if counter >= self.nplots: | |
238 | break |
|
397 | break | |
239 |
|
398 | |||
240 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
399 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
241 |
|
400 | |||
242 | if showprofile: |
|
401 | if showprofile: | |
243 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
402 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
244 |
|
403 | |||
245 | counter += 1 |
|
404 | counter += 1 | |
246 |
|
405 | |||
247 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
406 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
248 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
407 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
249 | save=False, figpath='./', figfile=None): |
|
408 | save=False, figpath='./', figfile=None): | |
250 |
|
409 | |||
251 | """ |
|
410 | """ | |
252 |
|
411 | |||
253 | Input: |
|
412 | Input: | |
254 | dataOut : |
|
413 | dataOut : | |
255 | idfigure : |
|
414 | idfigure : | |
256 | wintitle : |
|
415 | wintitle : | |
257 | channelList : |
|
416 | channelList : | |
258 | showProfile : |
|
417 | showProfile : | |
259 | xmin : None, |
|
418 | xmin : None, | |
260 | xmax : None, |
|
419 | xmax : None, | |
261 | ymin : None, |
|
420 | ymin : None, | |
262 | ymax : None, |
|
421 | ymax : None, | |
263 | zmin : None, |
|
422 | zmin : None, | |
264 | zmax : None |
|
423 | zmax : None | |
265 | """ |
|
424 | """ | |
266 |
|
425 | |||
267 | if channelList == None: |
|
426 | if channelList == None: | |
268 | channelIndexList = dataOut.channelIndexList |
|
427 | channelIndexList = dataOut.channelIndexList | |
269 | else: |
|
428 | else: | |
270 | channelIndexList = [] |
|
429 | channelIndexList = [] | |
271 | for channel in channelList: |
|
430 | for channel in channelList: | |
272 | if channel not in dataOut.channelList: |
|
431 | if channel not in dataOut.channelList: | |
273 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
432 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
274 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
433 | channelIndexList.append(dataOut.channelList.index(channel)) | |
275 |
|
434 | |||
276 | x = dataOut.getVelRange(1) |
|
435 | x = dataOut.getVelRange(1) | |
277 | y = dataOut.getHeiRange() |
|
436 | y = dataOut.getHeiRange() | |
278 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
437 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) | |
279 | avg = numpy.average(z, axis=1) |
|
438 | avg = numpy.average(z, axis=1) | |
280 |
|
439 | |||
281 | noise = dataOut.getNoise() |
|
440 | noise = dataOut.getNoise() | |
282 |
|
441 | |||
283 | if not self.__isConfig: |
|
442 | if not self.__isConfig: | |
284 |
|
443 | |||
285 | nplots = len(channelIndexList) |
|
444 | nplots = len(channelIndexList) | |
286 |
|
445 | |||
287 | self.setup(idfigure=idfigure, |
|
446 | self.setup(idfigure=idfigure, | |
288 | nplots=nplots, |
|
447 | nplots=nplots, | |
289 | wintitle=wintitle, |
|
448 | wintitle=wintitle, | |
290 | showprofile=showprofile) |
|
449 | showprofile=showprofile) | |
291 |
|
450 | |||
292 | if xmin == None: xmin = numpy.nanmin(x) |
|
451 | if xmin == None: xmin = numpy.nanmin(x) | |
293 | if xmax == None: xmax = numpy.nanmax(x) |
|
452 | if xmax == None: xmax = numpy.nanmax(x) | |
294 | if ymin == None: ymin = numpy.nanmin(y) |
|
453 | if ymin == None: ymin = numpy.nanmin(y) | |
295 | if ymax == None: ymax = numpy.nanmax(y) |
|
454 | if ymax == None: ymax = numpy.nanmax(y) | |
296 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
455 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 | |
297 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
456 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 | |
298 |
|
457 | |||
299 | self.__isConfig = True |
|
458 | self.__isConfig = True | |
300 |
|
459 | |||
301 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
460 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
302 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
461 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
303 | xlabel = "Velocity (m/s)" |
|
462 | xlabel = "Velocity (m/s)" | |
304 | ylabel = "Range (Km)" |
|
463 | ylabel = "Range (Km)" | |
305 |
|
464 | |||
306 | self.setWinTitle(title) |
|
465 | self.setWinTitle(title) | |
307 |
|
466 | |||
308 | for i in range(self.nplots): |
|
467 | for i in range(self.nplots): | |
309 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) |
|
468 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) | |
310 | axes = self.axesList[i*self.__nsubplots] |
|
469 | axes = self.axesList[i*self.__nsubplots] | |
311 | axes.pcolor(x, y, z[i,:,:], |
|
470 | axes.pcolor(x, y, z[i,:,:], | |
312 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
471 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
313 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
472 | xlabel=xlabel, ylabel=ylabel, title=title, | |
314 | ticksize=9, cblabel='') |
|
473 | ticksize=9, cblabel='') | |
315 |
|
474 | |||
316 | if self.__showprofile: |
|
475 | if self.__showprofile: | |
317 | axes = self.axesList[i*self.__nsubplots +1] |
|
476 | axes = self.axesList[i*self.__nsubplots +1] | |
318 | axes.pline(avg[i], y, |
|
477 | axes.pline(avg[i], y, | |
319 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
478 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
320 | xlabel='dB', ylabel='', title='', |
|
479 | xlabel='dB', ylabel='', title='', | |
321 | ytick_visible=False, |
|
480 | ytick_visible=False, | |
322 | grid='x') |
|
481 | grid='x') | |
323 |
|
482 | |||
324 | self.draw() |
|
483 | self.draw() | |
325 |
|
484 | |||
326 | if save: |
|
485 | if save: | |
327 | date = thisDatetime.strftime("%Y%m%d") |
|
486 | date = thisDatetime.strftime("%Y%m%d") | |
328 | if figfile == None: |
|
487 | if figfile == None: | |
329 | figfile = self.getFilename(name = date) |
|
488 | figfile = self.getFilename(name = date) | |
330 |
|
489 | |||
331 | self.saveFigure(figpath, figfile) |
|
490 | self.saveFigure(figpath, figfile) | |
332 |
|
491 | |||
333 | class Scope(Figure): |
|
492 | class Scope(Figure): | |
334 |
|
493 | |||
335 | __isConfig = None |
|
494 | __isConfig = None | |
336 |
|
495 | |||
337 | def __init__(self): |
|
496 | def __init__(self): | |
338 |
|
497 | |||
339 | self.__isConfig = False |
|
498 | self.__isConfig = False | |
340 | self.WIDTH = 600 |
|
499 | self.WIDTH = 600 | |
341 | self.HEIGHT = 200 |
|
500 | self.HEIGHT = 200 | |
342 |
|
501 | |||
343 | def getSubplots(self): |
|
502 | def getSubplots(self): | |
344 |
|
503 | |||
345 | nrow = self.nplots |
|
504 | nrow = self.nplots | |
346 | ncol = 3 |
|
505 | ncol = 3 | |
347 | return nrow, ncol |
|
506 | return nrow, ncol | |
348 |
|
507 | |||
349 | def setup(self, idfigure, nplots, wintitle): |
|
508 | def setup(self, idfigure, nplots, wintitle): | |
350 |
|
509 | |||
351 | self.createFigure(idfigure, wintitle) |
|
510 | self.createFigure(idfigure, wintitle) | |
352 |
|
511 | |||
353 | nrow,ncol = self.getSubplots() |
|
512 | nrow,ncol = self.getSubplots() | |
354 | colspan = 3 |
|
513 | colspan = 3 | |
355 | rowspan = 1 |
|
514 | rowspan = 1 | |
356 |
|
515 | |||
357 | for i in range(nplots): |
|
516 | for i in range(nplots): | |
358 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
517 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
359 |
|
518 | |||
360 | self.nplots = nplots |
|
519 | self.nplots = nplots | |
361 |
|
520 | |||
362 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
521 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
363 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None): |
|
522 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None): | |
364 |
|
523 | |||
365 | """ |
|
524 | """ | |
366 |
|
525 | |||
367 | Input: |
|
526 | Input: | |
368 | dataOut : |
|
527 | dataOut : | |
369 | idfigure : |
|
528 | idfigure : | |
370 | wintitle : |
|
529 | wintitle : | |
371 | channelList : |
|
530 | channelList : | |
372 | xmin : None, |
|
531 | xmin : None, | |
373 | xmax : None, |
|
532 | xmax : None, | |
374 | ymin : None, |
|
533 | ymin : None, | |
375 | ymax : None, |
|
534 | ymax : None, | |
376 | """ |
|
535 | """ | |
377 |
|
536 | |||
378 | if channelList == None: |
|
537 | if channelList == None: | |
379 | channelIndexList = dataOut.channelIndexList |
|
538 | channelIndexList = dataOut.channelIndexList | |
380 | else: |
|
539 | else: | |
381 | channelIndexList = [] |
|
540 | channelIndexList = [] | |
382 | for channel in channelList: |
|
541 | for channel in channelList: | |
383 | if channel not in dataOut.channelList: |
|
542 | if channel not in dataOut.channelList: | |
384 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
543 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
385 |
channelIndexList.append(dataOut.channelList.index( |
|
544 | channelIndexList.append(dataOut.channelList.index(channel)) | |
386 |
|
545 | |||
387 | x = dataOut.heightList |
|
546 | x = dataOut.heightList | |
388 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) |
|
547 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) | |
389 | y = y.real |
|
548 | y = y.real | |
390 |
|
549 | |||
391 | noise = dataOut.getNoise() |
|
550 | noise = dataOut.getNoise() | |
392 |
|
551 | |||
393 | if not self.__isConfig: |
|
552 | if not self.__isConfig: | |
394 | nplots = len(channelList) |
|
553 | nplots = len(channelList) | |
395 |
|
554 | |||
396 | self.setup(idfigure=idfigure, |
|
555 | self.setup(idfigure=idfigure, | |
397 | nplots=nplots, |
|
556 | nplots=nplots, | |
398 | wintitle=wintitle) |
|
557 | wintitle=wintitle) | |
399 |
|
558 | |||
400 | if xmin == None: xmin = numpy.nanmin(x) |
|
559 | if xmin == None: xmin = numpy.nanmin(x) | |
401 | if xmax == None: xmax = numpy.nanmax(x) |
|
560 | if xmax == None: xmax = numpy.nanmax(x) | |
402 | if ymin == None: ymin = numpy.nanmin(y) |
|
561 | if ymin == None: ymin = numpy.nanmin(y) | |
403 | if ymax == None: ymax = numpy.nanmax(y) |
|
562 | if ymax == None: ymax = numpy.nanmax(y) | |
404 |
|
563 | |||
405 | self.__isConfig = True |
|
564 | self.__isConfig = True | |
406 |
|
565 | |||
407 |
|
566 | |||
408 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
567 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
409 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
568 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
410 | xlabel = "Range (Km)" |
|
569 | xlabel = "Range (Km)" | |
411 | ylabel = "Intensity" |
|
570 | ylabel = "Intensity" | |
412 |
|
571 | |||
413 | self.setWinTitle(title) |
|
572 | self.setWinTitle(title) | |
414 |
|
573 | |||
415 | for i in range(len(self.axesList)): |
|
574 | for i in range(len(self.axesList)): | |
416 | title = "Channel %d: %4.2fdB" %(i, noise[i]) |
|
575 | title = "Channel %d: %4.2fdB" %(i, noise[i]) | |
417 | axes = self.axesList[i] |
|
576 | axes = self.axesList[i] | |
418 | ychannel = y[i,:] |
|
577 | ychannel = y[i,:] | |
419 | axes.pline(x, ychannel, |
|
578 | axes.pline(x, ychannel, | |
420 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
579 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
421 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
580 | xlabel=xlabel, ylabel=ylabel, title=title) | |
422 |
|
581 | |||
423 | self.draw() |
|
582 | self.draw() | |
424 |
|
583 | |||
425 | if save: |
|
584 | if save: | |
426 | self.saveFigure(filename) |
|
585 | self.saveFigure(filename) | |
427 | No newline at end of file |
|
586 |
General Comments 0
You need to be logged in to leave comments.
Login now