@@ -1,382 +1,382 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import datetime |
|
3 | 3 | import sys |
|
4 | 4 | import matplotlib |
|
5 | 5 | |
|
6 | 6 | if 'linux' in sys.platform: |
|
7 | 7 | matplotlib.use("TKAgg") |
|
8 | 8 | |
|
9 | 9 | if 'darwin' in sys.platform: |
|
10 | 10 | matplotlib.use("TKAgg") |
|
11 | 11 | |
|
12 | 12 | import matplotlib.pyplot |
|
13 | 13 | |
|
14 | 14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
15 | 15 | from matplotlib.ticker import * |
|
16 | 16 | |
|
17 | 17 | ########################################### |
|
18 | 18 | #Actualizacion de las funciones del driver |
|
19 | 19 | ########################################### |
|
20 | 20 | |
|
21 | 21 | def createFigure(idfigure, wintitle, width, height, facecolor="w", show=True): |
|
22 | 22 | |
|
23 | 23 | matplotlib.pyplot.ioff() |
|
24 | 24 | fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
25 | 25 | fig.canvas.manager.set_window_title(wintitle) |
|
26 | 26 | fig.canvas.manager.resize(width, height) |
|
27 | 27 | matplotlib.pyplot.ion() |
|
28 | 28 | if show: |
|
29 | 29 | matplotlib.pyplot.show() |
|
30 | 30 | |
|
31 | 31 | return fig |
|
32 | 32 | |
|
33 | 33 | def closeFigure(show=True): |
|
34 | 34 | |
|
35 | 35 | matplotlib.pyplot.ioff() |
|
36 | 36 | if show: |
|
37 | 37 | matplotlib.pyplot.show() |
|
38 | 38 | |
|
39 | 39 | return |
|
40 | 40 | |
|
41 | 41 | def saveFigure(fig, filename): |
|
42 | 42 | |
|
43 | 43 | matplotlib.pyplot.ioff() |
|
44 | 44 | fig.savefig(filename) |
|
45 | 45 | matplotlib.pyplot.ion() |
|
46 | 46 | |
|
47 | 47 | def setWinTitle(fig, title): |
|
48 | 48 | |
|
49 | 49 | fig.canvas.manager.set_window_title(title) |
|
50 | 50 | |
|
51 | 51 | def setTitle(fig, title): |
|
52 | 52 | |
|
53 | 53 | fig.suptitle(title) |
|
54 | 54 | |
|
55 | 55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
56 | 56 | |
|
57 | 57 | matplotlib.pyplot.ioff() |
|
58 | 58 | matplotlib.pyplot.figure(fig.number) |
|
59 | 59 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
60 | 60 | (xpos, ypos), |
|
61 | 61 | colspan=colspan, |
|
62 | 62 | rowspan=rowspan) |
|
63 | 63 | |
|
64 | 64 | matplotlib.pyplot.ion() |
|
65 | 65 | return axes |
|
66 | 66 | |
|
67 | 67 | def setAxesText(ax, text): |
|
68 | 68 | |
|
69 | 69 | ax.annotate(text, |
|
70 | 70 | xy = (.1, .99), |
|
71 | 71 | xycoords = 'figure fraction', |
|
72 | 72 | horizontalalignment = 'left', |
|
73 | 73 | verticalalignment = 'top', |
|
74 | 74 | fontsize = 10) |
|
75 | 75 | |
|
76 | 76 | def printLabels(ax, xlabel, ylabel, title): |
|
77 | 77 | |
|
78 | 78 | ax.set_xlabel(xlabel, size=11) |
|
79 | 79 | ax.set_ylabel(ylabel, size=11) |
|
80 | 80 | ax.set_title(title, size=12) |
|
81 | 81 | |
|
82 | 82 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
83 | 83 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
84 | 84 | nxticks=4, nyticks=10, |
|
85 | 85 | grid=None): |
|
86 | 86 | |
|
87 | 87 | """ |
|
88 | 88 | |
|
89 | 89 | Input: |
|
90 | 90 | grid : None, 'both', 'x', 'y' |
|
91 | 91 | """ |
|
92 | 92 | |
|
93 | 93 | matplotlib.pyplot.ioff() |
|
94 | 94 | |
|
95 | 95 | ax.set_xlim([xmin,xmax]) |
|
96 | 96 | ax.set_ylim([ymin,ymax]) |
|
97 | 97 | |
|
98 | 98 | printLabels(ax, xlabel, ylabel, title) |
|
99 | 99 | |
|
100 | 100 | ###################################################### |
|
101 | 101 | # if (xmax-xmin)<=1: |
|
102 | 102 | # xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
103 | 103 | # xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
104 | 104 | # ax.set_xticks(xtickspos) |
|
105 | 105 | # else: |
|
106 | 106 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
107 | 107 | # ax.set_xticks(xtickspos) |
|
108 | 108 | # |
|
109 | 109 | # for tick in ax.get_xticklabels(): |
|
110 | 110 | # tick.set_visible(xtick_visible) |
|
111 | 111 | # |
|
112 | 112 | # for tick in ax.xaxis.get_major_ticks(): |
|
113 | 113 | # tick.label.set_fontsize(ticksize) |
|
114 | 114 | |
|
115 | 115 | ###################################################### |
|
116 | 116 | for tick in ax.get_yticklabels(): |
|
117 | 117 | tick.set_visible(ytick_visible) |
|
118 | 118 | |
|
119 | 119 | for tick in ax.yaxis.get_major_ticks(): |
|
120 | 120 | tick.label.set_fontsize(ticksize) |
|
121 | 121 | |
|
122 | 122 | ax.plot(x, y) |
|
123 | 123 | iplot = ax.lines[-1] |
|
124 | 124 | |
|
125 | 125 | ###################################################### |
|
126 | 126 | if '0.' in matplotlib.__version__[0:2]: |
|
127 | 127 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
128 | 128 | return iplot |
|
129 | 129 | |
|
130 | 130 | if '1.0.' in matplotlib.__version__[0:4]: |
|
131 | 131 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
132 | 132 | return iplot |
|
133 | 133 | |
|
134 | 134 | if grid != None: |
|
135 | 135 | ax.grid(b=True, which='major', axis=grid) |
|
136 | 136 | |
|
137 | 137 | matplotlib.pyplot.tight_layout() |
|
138 | 138 | |
|
139 | 139 | matplotlib.pyplot.ion() |
|
140 | 140 | |
|
141 | 141 | return iplot |
|
142 | 142 | |
|
143 | 143 | def set_linedata(ax, x, y, idline): |
|
144 | 144 | |
|
145 | 145 | ax.lines[idline].set_data(x,y) |
|
146 | 146 | |
|
147 | 147 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
148 | 148 | |
|
149 | 149 | ax = iplot.get_axes() |
|
150 | 150 | |
|
151 | 151 | printLabels(ax, xlabel, ylabel, title) |
|
152 | 152 | |
|
153 | 153 | set_linedata(ax, x, y, idline=0) |
|
154 | 154 | |
|
155 | 155 | def addpline(ax, x, y, color, linestyle, lw): |
|
156 | 156 | |
|
157 | 157 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
158 | 158 | |
|
159 | 159 | |
|
160 | 160 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
161 | 161 | xlabel='', ylabel='', title='', ticksize = 9, |
|
162 | 162 | colormap='jet',cblabel='', cbsize="5%", |
|
163 | 163 | XAxisAsTime=False): |
|
164 | 164 | |
|
165 | 165 | matplotlib.pyplot.ioff() |
|
166 | 166 | |
|
167 | 167 | divider = make_axes_locatable(ax) |
|
168 | 168 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
169 | 169 | fig = ax.get_figure() |
|
170 | 170 | fig.add_axes(ax_cb) |
|
171 | 171 | |
|
172 | 172 | ax.set_xlim([xmin,xmax]) |
|
173 | 173 | ax.set_ylim([ymin,ymax]) |
|
174 | 174 | |
|
175 | 175 | printLabels(ax, xlabel, ylabel, title) |
|
176 | 176 | |
|
177 | 177 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
178 | 178 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
179 | 179 | cb.set_label(cblabel) |
|
180 | 180 | |
|
181 | 181 | # for tl in ax_cb.get_yticklabels(): |
|
182 | 182 | # tl.set_visible(True) |
|
183 | 183 | |
|
184 | 184 | for tick in ax.yaxis.get_major_ticks(): |
|
185 | 185 | tick.label.set_fontsize(ticksize) |
|
186 | 186 | |
|
187 | 187 | for tick in ax.xaxis.get_major_ticks(): |
|
188 | 188 | tick.label.set_fontsize(ticksize) |
|
189 | 189 | |
|
190 | 190 | for tick in cb.ax.get_yticklabels(): |
|
191 | 191 | tick.set_fontsize(ticksize) |
|
192 | 192 | |
|
193 | 193 | ax_cb.yaxis.tick_right() |
|
194 | 194 | |
|
195 | 195 | if '0.' in matplotlib.__version__[0:2]: |
|
196 | 196 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
197 | 197 | return imesh |
|
198 | 198 | |
|
199 | 199 | if '1.0.' in matplotlib.__version__[0:4]: |
|
200 | 200 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
201 | 201 | return imesh |
|
202 | 202 | |
|
203 | 203 | matplotlib.pyplot.tight_layout() |
|
204 | 204 | |
|
205 | 205 | if XAxisAsTime: |
|
206 | 206 | |
|
207 | 207 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
208 | 208 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
209 | 209 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
210 | 210 | |
|
211 | 211 | matplotlib.pyplot.ion() |
|
212 | 212 | return imesh |
|
213 | 213 | |
|
214 | 214 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
215 | 215 | |
|
216 | 216 | z = z.T |
|
217 | 217 | |
|
218 | 218 | ax = imesh.get_axes() |
|
219 | 219 | |
|
220 | 220 | printLabels(ax, xlabel, ylabel, title) |
|
221 | 221 | |
|
222 | 222 | imesh.set_array(z.ravel()) |
|
223 | 223 | |
|
224 | 224 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
225 | 225 | |
|
226 | 226 | printLabels(ax, xlabel, ylabel, title) |
|
227 | 227 | |
|
228 | 228 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
229 | 229 | |
|
230 | 230 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
231 | 231 | |
|
232 | 232 | printLabels(ax, xlabel, ylabel, title) |
|
233 | 233 | |
|
234 | 234 | ax.collections.remove(ax.collections[0]) |
|
235 | 235 | |
|
236 | 236 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
237 | 237 | |
|
238 | 238 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
239 | 239 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
240 | 240 | nxticks=4, nyticks=10, |
|
241 | 241 | grid=None): |
|
242 | 242 | |
|
243 | 243 | """ |
|
244 | 244 | |
|
245 | 245 | Input: |
|
246 | 246 | grid : None, 'both', 'x', 'y' |
|
247 | 247 | """ |
|
248 | 248 | |
|
249 | 249 | matplotlib.pyplot.ioff() |
|
250 | 250 | |
|
251 | 251 | lines = ax.plot(x.T, y) |
|
252 | 252 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
253 | 253 | leg.get_frame().set_alpha(0.5) |
|
254 | 254 | ax.set_xlim([xmin,xmax]) |
|
255 | 255 | ax.set_ylim([ymin,ymax]) |
|
256 | 256 | printLabels(ax, xlabel, ylabel, title) |
|
257 | 257 | |
|
258 | 258 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
259 | 259 | ax.set_xticks(xtickspos) |
|
260 | 260 | |
|
261 | 261 | for tick in ax.get_xticklabels(): |
|
262 | 262 | tick.set_visible(xtick_visible) |
|
263 | 263 | |
|
264 | 264 | for tick in ax.xaxis.get_major_ticks(): |
|
265 | 265 | tick.label.set_fontsize(ticksize) |
|
266 | 266 | |
|
267 | 267 | for tick in ax.get_yticklabels(): |
|
268 | 268 | tick.set_visible(ytick_visible) |
|
269 | 269 | |
|
270 | 270 | for tick in ax.yaxis.get_major_ticks(): |
|
271 | 271 | tick.label.set_fontsize(ticksize) |
|
272 | 272 | |
|
273 | 273 | iplot = ax.lines[-1] |
|
274 | 274 | |
|
275 | 275 | if '0.' in matplotlib.__version__[0:2]: |
|
276 | 276 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
277 | 277 | return iplot |
|
278 | 278 | |
|
279 | 279 | if '1.0.' in matplotlib.__version__[0:4]: |
|
280 | 280 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
281 | 281 | return iplot |
|
282 | 282 | |
|
283 | 283 | if grid != None: |
|
284 | 284 | ax.grid(b=True, which='major', axis=grid) |
|
285 | 285 | |
|
286 | 286 | matplotlib.pyplot.tight_layout() |
|
287 | 287 | |
|
288 | 288 | matplotlib.pyplot.ion() |
|
289 | 289 | |
|
290 | 290 | return iplot |
|
291 | 291 | |
|
292 | 292 | |
|
293 | 293 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
294 | 294 | |
|
295 | 295 | ax = iplot.get_axes() |
|
296 | 296 | |
|
297 | 297 | printLabels(ax, xlabel, ylabel, title) |
|
298 | 298 | |
|
299 | 299 | for i in range(len(ax.lines)): |
|
300 | 300 | line = ax.lines[i] |
|
301 | 301 | line.set_data(x[i,:],y) |
|
302 | 302 | |
|
303 | 303 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
304 | 304 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
305 |
nxticks=4, nyticks=10, marker=' |
|
|
305 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", | |
|
306 | 306 | grid=None, XAxisAsTime=False): |
|
307 | 307 | |
|
308 | 308 | """ |
|
309 | 309 | |
|
310 | 310 | Input: |
|
311 | 311 | grid : None, 'both', 'x', 'y' |
|
312 | 312 | """ |
|
313 | 313 | |
|
314 | 314 | matplotlib.pyplot.ioff() |
|
315 | 315 | |
|
316 | 316 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
317 |
lines = ax.plot(x, y.T, 'o', markersize= |
|
|
317 | lines = ax.plot(x, y.T, linestyle='None', marker='.', markersize=markersize) | |
|
318 | 318 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
319 | 319 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
320 | 320 | |
|
321 | 321 | for label in leg.get_texts(): label.set_fontsize(9) |
|
322 | 322 | |
|
323 | 323 | ax.set_xlim([xmin,xmax]) |
|
324 | 324 | ax.set_ylim([ymin,ymax]) |
|
325 | 325 | printLabels(ax, xlabel, ylabel, title) |
|
326 | 326 | |
|
327 | 327 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
328 | 328 | # ax.set_xticks(xtickspos) |
|
329 | 329 | |
|
330 | 330 | for tick in ax.get_xticklabels(): |
|
331 | 331 | tick.set_visible(xtick_visible) |
|
332 | 332 | |
|
333 | 333 | for tick in ax.xaxis.get_major_ticks(): |
|
334 | 334 | tick.label.set_fontsize(ticksize) |
|
335 | 335 | |
|
336 | 336 | for tick in ax.get_yticklabels(): |
|
337 | 337 | tick.set_visible(ytick_visible) |
|
338 | 338 | |
|
339 | 339 | for tick in ax.yaxis.get_major_ticks(): |
|
340 | 340 | tick.label.set_fontsize(ticksize) |
|
341 | 341 | |
|
342 | 342 | iplot = ax.lines[-1] |
|
343 | 343 | |
|
344 | 344 | if '0.' in matplotlib.__version__[0:2]: |
|
345 | 345 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
346 | 346 | return iplot |
|
347 | 347 | |
|
348 | 348 | if '1.0.' in matplotlib.__version__[0:4]: |
|
349 | 349 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
350 | 350 | return iplot |
|
351 | 351 | |
|
352 | 352 | if grid != None: |
|
353 | 353 | ax.grid(b=True, which='major', axis=grid) |
|
354 | 354 | |
|
355 | 355 | matplotlib.pyplot.tight_layout() |
|
356 | 356 | |
|
357 | 357 | if XAxisAsTime: |
|
358 | 358 | |
|
359 | 359 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
360 | 360 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
361 | 361 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
362 | 362 | |
|
363 | 363 | matplotlib.pyplot.ion() |
|
364 | 364 | |
|
365 | 365 | return iplot |
|
366 | 366 | |
|
367 | 367 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
368 | 368 | |
|
369 | 369 | ax = iplot.get_axes() |
|
370 | 370 | |
|
371 | 371 | printLabels(ax, xlabel, ylabel, title) |
|
372 | 372 | |
|
373 | 373 | for i in range(len(ax.lines)): |
|
374 | 374 | line = ax.lines[i] |
|
375 | 375 | line.set_data(x,y[i,:]) |
|
376 | 376 | |
|
377 | 377 | def draw(fig): |
|
378 | 378 | |
|
379 | 379 | if type(fig) == 'int': |
|
380 | 380 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
381 | 381 | |
|
382 | 382 | fig.canvas.draw() No newline at end of file |
@@ -1,1343 +1,1351 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import time, datetime, os |
|
3 | 3 | from graphics.figure import * |
|
4 | 4 | |
|
5 | 5 | class CrossSpectraPlot(Figure): |
|
6 | 6 | |
|
7 | 7 | __isConfig = None |
|
8 | 8 | __nsubplots = None |
|
9 | 9 | |
|
10 | 10 | WIDTH = None |
|
11 | 11 | HEIGHT = None |
|
12 | 12 | WIDTHPROF = None |
|
13 | 13 | HEIGHTPROF = None |
|
14 | 14 | PREFIX = 'cspc' |
|
15 | 15 | |
|
16 | 16 | def __init__(self): |
|
17 | 17 | |
|
18 | 18 | self.__isConfig = False |
|
19 | 19 | self.__nsubplots = 4 |
|
20 | 20 | |
|
21 | 21 | self.WIDTH = 250 |
|
22 | 22 | self.HEIGHT = 250 |
|
23 | 23 | self.WIDTHPROF = 0 |
|
24 | 24 | self.HEIGHTPROF = 0 |
|
25 | 25 | |
|
26 | 26 | def getSubplots(self): |
|
27 | 27 | |
|
28 | 28 | ncol = 4 |
|
29 | 29 | nrow = self.nplots |
|
30 | 30 | |
|
31 | 31 | return nrow, ncol |
|
32 | 32 | |
|
33 | 33 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): |
|
34 | 34 | |
|
35 | 35 | self.__showprofile = showprofile |
|
36 | 36 | self.nplots = nplots |
|
37 | 37 | |
|
38 | 38 | ncolspan = 1 |
|
39 | 39 | colspan = 1 |
|
40 | 40 | |
|
41 | 41 | self.createFigure(idfigure = idfigure, |
|
42 | 42 | wintitle = wintitle, |
|
43 | 43 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
44 | 44 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
45 | 45 | show=True) |
|
46 | 46 | |
|
47 | 47 | nrow, ncol = self.getSubplots() |
|
48 | 48 | |
|
49 | 49 | counter = 0 |
|
50 | 50 | for y in range(nrow): |
|
51 | 51 | for x in range(ncol): |
|
52 | 52 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
53 | 53 | |
|
54 | 54 | counter += 1 |
|
55 | 55 | |
|
56 | 56 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
57 | 57 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
58 | 58 | save=False, figpath='./', figfile=None, |
|
59 | 59 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True): |
|
60 | 60 | |
|
61 | 61 | """ |
|
62 | 62 | |
|
63 | 63 | Input: |
|
64 | 64 | dataOut : |
|
65 | 65 | idfigure : |
|
66 | 66 | wintitle : |
|
67 | 67 | channelList : |
|
68 | 68 | showProfile : |
|
69 | 69 | xmin : None, |
|
70 | 70 | xmax : None, |
|
71 | 71 | ymin : None, |
|
72 | 72 | ymax : None, |
|
73 | 73 | zmin : None, |
|
74 | 74 | zmax : None |
|
75 | 75 | """ |
|
76 | 76 | |
|
77 | 77 | if pairsList == None: |
|
78 | 78 | pairsIndexList = dataOut.pairsIndexList |
|
79 | 79 | else: |
|
80 | 80 | pairsIndexList = [] |
|
81 | 81 | for pair in pairsList: |
|
82 | 82 | if pair not in dataOut.pairsList: |
|
83 | 83 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
84 | 84 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
85 | 85 | |
|
86 | 86 | if pairsIndexList == []: |
|
87 | 87 | return |
|
88 | 88 | |
|
89 | 89 | if len(pairsIndexList) > 4: |
|
90 | 90 | pairsIndexList = pairsIndexList[0:4] |
|
91 | 91 | factor = dataOut.normFactor |
|
92 | 92 | x = dataOut.getVelRange(1) |
|
93 | 93 | y = dataOut.getHeiRange() |
|
94 | 94 | z = dataOut.data_spc[:,:,:]/factor |
|
95 | 95 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
96 | 96 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
97 | 97 | noise = dataOut.getNoise()/factor |
|
98 | 98 | |
|
99 | 99 | zdB = 10*numpy.log10(z) |
|
100 | 100 | avgdB = 10*numpy.log10(avg) |
|
101 | 101 | noisedB = 10*numpy.log10(noise) |
|
102 | 102 | |
|
103 | 103 | |
|
104 | 104 | thisDatetime = dataOut.datatime |
|
105 | 105 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
106 | 106 | xlabel = "Velocity (m/s)" |
|
107 | 107 | ylabel = "Range (Km)" |
|
108 | 108 | |
|
109 | 109 | if not self.__isConfig: |
|
110 | 110 | |
|
111 | 111 | nplots = len(pairsIndexList) |
|
112 | 112 | |
|
113 | 113 | self.setup(idfigure=idfigure, |
|
114 | 114 | nplots=nplots, |
|
115 | 115 | wintitle=wintitle, |
|
116 | 116 | showprofile=showprofile, |
|
117 | 117 | show=show) |
|
118 | 118 | |
|
119 | 119 | if xmin == None: xmin = numpy.nanmin(x) |
|
120 | 120 | if xmax == None: xmax = numpy.nanmax(x) |
|
121 | 121 | if ymin == None: ymin = numpy.nanmin(y) |
|
122 | 122 | if ymax == None: ymax = numpy.nanmax(y) |
|
123 | 123 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
124 | 124 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
125 | 125 | |
|
126 | 126 | self.__isConfig = True |
|
127 | 127 | |
|
128 | 128 | self.setWinTitle(title) |
|
129 | 129 | |
|
130 | 130 | for i in range(self.nplots): |
|
131 | 131 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
132 | 132 | |
|
133 | 133 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) |
|
134 | 134 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
135 | 135 | axes0 = self.axesList[i*self.__nsubplots] |
|
136 | 136 | axes0.pcolor(x, y, zdB, |
|
137 | 137 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
138 | 138 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
139 | 139 | ticksize=9, colormap=power_cmap, cblabel='') |
|
140 | 140 | |
|
141 | 141 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) |
|
142 | 142 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
143 | 143 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
144 | 144 | axes0.pcolor(x, y, zdB, |
|
145 | 145 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
146 | 146 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
147 | 147 | ticksize=9, colormap=power_cmap, cblabel='') |
|
148 | 148 | |
|
149 | 149 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
150 | 150 | coherence = numpy.abs(coherenceComplex) |
|
151 | 151 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
152 | 152 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
153 | 153 | |
|
154 | 154 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
155 | 155 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
156 | 156 | axes0.pcolor(x, y, coherence, |
|
157 | 157 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
158 | 158 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
159 | 159 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
160 | 160 | |
|
161 | 161 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
162 | 162 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
163 | 163 | axes0.pcolor(x, y, phase, |
|
164 | 164 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
165 | 165 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
166 | 166 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
167 | 167 | |
|
168 | 168 | |
|
169 | 169 | |
|
170 | 170 | self.draw() |
|
171 | 171 | |
|
172 | 172 | if save: |
|
173 | 173 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
174 | 174 | if figfile == None: |
|
175 | 175 | figfile = self.getFilename(name = date) |
|
176 | 176 | |
|
177 | 177 | self.saveFigure(figpath, figfile) |
|
178 | 178 | |
|
179 | 179 | |
|
180 | 180 | class RTIPlot(Figure): |
|
181 | 181 | |
|
182 | 182 | __isConfig = None |
|
183 | 183 | __nsubplots = None |
|
184 | 184 | |
|
185 | 185 | WIDTHPROF = None |
|
186 | 186 | HEIGHTPROF = None |
|
187 | 187 | PREFIX = 'rti' |
|
188 | 188 | |
|
189 | 189 | def __init__(self): |
|
190 | 190 | |
|
191 | 191 | self.timerange = 2*60*60 |
|
192 | 192 | self.__isConfig = False |
|
193 | 193 | self.__nsubplots = 1 |
|
194 | 194 | |
|
195 | 195 | self.WIDTH = 800 |
|
196 | 196 | self.HEIGHT = 150 |
|
197 | 197 | self.WIDTHPROF = 120 |
|
198 | 198 | self.HEIGHTPROF = 0 |
|
199 | 199 | self.counterftp = 0 |
|
200 | 200 | |
|
201 | 201 | def getSubplots(self): |
|
202 | 202 | |
|
203 | 203 | ncol = 1 |
|
204 | 204 | nrow = self.nplots |
|
205 | 205 | |
|
206 | 206 | return nrow, ncol |
|
207 | 207 | |
|
208 | 208 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): |
|
209 | 209 | |
|
210 | 210 | self.__showprofile = showprofile |
|
211 | 211 | self.nplots = nplots |
|
212 | 212 | |
|
213 | 213 | ncolspan = 1 |
|
214 | 214 | colspan = 1 |
|
215 | 215 | if showprofile: |
|
216 | 216 | ncolspan = 7 |
|
217 | 217 | colspan = 6 |
|
218 | 218 | self.__nsubplots = 2 |
|
219 | 219 | |
|
220 | 220 | self.createFigure(idfigure = idfigure, |
|
221 | 221 | wintitle = wintitle, |
|
222 | 222 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
223 | 223 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
224 | 224 | show=show) |
|
225 | 225 | |
|
226 | 226 | nrow, ncol = self.getSubplots() |
|
227 | 227 | |
|
228 | 228 | counter = 0 |
|
229 | 229 | for y in range(nrow): |
|
230 | 230 | for x in range(ncol): |
|
231 | 231 | |
|
232 | 232 | if counter >= self.nplots: |
|
233 | 233 | break |
|
234 | 234 | |
|
235 | 235 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
236 | 236 | |
|
237 | 237 | if showprofile: |
|
238 | 238 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
239 | 239 | |
|
240 | 240 | counter += 1 |
|
241 | 241 | |
|
242 | 242 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
243 | 243 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
244 | 244 | timerange=None, |
|
245 | 245 | save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True): |
|
246 | 246 | |
|
247 | 247 | """ |
|
248 | 248 | |
|
249 | 249 | Input: |
|
250 | 250 | dataOut : |
|
251 | 251 | idfigure : |
|
252 | 252 | wintitle : |
|
253 | 253 | channelList : |
|
254 | 254 | showProfile : |
|
255 | 255 | xmin : None, |
|
256 | 256 | xmax : None, |
|
257 | 257 | ymin : None, |
|
258 | 258 | ymax : None, |
|
259 | 259 | zmin : None, |
|
260 | 260 | zmax : None |
|
261 | 261 | """ |
|
262 | 262 | |
|
263 | 263 | if channelList == None: |
|
264 | 264 | channelIndexList = dataOut.channelIndexList |
|
265 | 265 | else: |
|
266 | 266 | channelIndexList = [] |
|
267 | 267 | for channel in channelList: |
|
268 | 268 | if channel not in dataOut.channelList: |
|
269 | 269 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
270 | 270 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
271 | 271 | |
|
272 | 272 | if timerange != None: |
|
273 | 273 | self.timerange = timerange |
|
274 | 274 | |
|
275 | 275 | tmin = None |
|
276 | 276 | tmax = None |
|
277 | 277 | factor = dataOut.normFactor |
|
278 | 278 | x = dataOut.getTimeRange() |
|
279 | 279 | y = dataOut.getHeiRange() |
|
280 | 280 | |
|
281 | 281 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
282 | 282 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
283 | 283 | avg = numpy.average(z, axis=1) |
|
284 | 284 | |
|
285 | 285 | avgdB = 10.*numpy.log10(avg) |
|
286 | 286 | |
|
287 | 287 | |
|
288 | 288 | thisDatetime = dataOut.datatime |
|
289 | 289 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
290 | 290 | xlabel = "" |
|
291 | 291 | ylabel = "Range (Km)" |
|
292 | 292 | |
|
293 | 293 | if not self.__isConfig: |
|
294 | 294 | |
|
295 | 295 | nplots = len(channelIndexList) |
|
296 | 296 | |
|
297 | 297 | self.setup(idfigure=idfigure, |
|
298 | 298 | nplots=nplots, |
|
299 | 299 | wintitle=wintitle, |
|
300 | 300 | showprofile=showprofile, |
|
301 | 301 | show=show) |
|
302 | 302 | |
|
303 | 303 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
304 | 304 | if ymin == None: ymin = numpy.nanmin(y) |
|
305 | 305 | if ymax == None: ymax = numpy.nanmax(y) |
|
306 | 306 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
307 | 307 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
308 | 308 | |
|
309 | 309 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
310 | 310 | self.__isConfig = True |
|
311 | 311 | |
|
312 | 312 | |
|
313 | 313 | self.setWinTitle(title) |
|
314 | 314 | |
|
315 | 315 | for i in range(self.nplots): |
|
316 | 316 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
317 | 317 | axes = self.axesList[i*self.__nsubplots] |
|
318 | 318 | zdB = avgdB[i].reshape((1,-1)) |
|
319 | 319 | axes.pcolorbuffer(x, y, zdB, |
|
320 | 320 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
321 | 321 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
322 | 322 | ticksize=9, cblabel='', cbsize="1%") |
|
323 | 323 | |
|
324 | 324 | if self.__showprofile: |
|
325 | 325 | axes = self.axesList[i*self.__nsubplots +1] |
|
326 | 326 | axes.pline(avgdB[i], y, |
|
327 | 327 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
328 | 328 | xlabel='dB', ylabel='', title='', |
|
329 | 329 | ytick_visible=False, |
|
330 | 330 | grid='x') |
|
331 | 331 | |
|
332 | 332 | self.draw() |
|
333 | 333 | |
|
334 | 334 | if save: |
|
335 | 335 | |
|
336 | 336 | if figfile == None: |
|
337 | 337 | figfile = self.getFilename(name = self.name) |
|
338 | 338 | |
|
339 | 339 | self.saveFigure(figpath, figfile) |
|
340 | 340 | |
|
341 | 341 | self.counterftp += 1 |
|
342 | 342 | if (ftp and (self.counterftp==ftpratio)): |
|
343 | 343 | figfilename = os.path.join(figpath,figfile) |
|
344 | 344 | self.sendByFTP(figfilename) |
|
345 | 345 | self.counterftp = 0 |
|
346 | 346 | |
|
347 | 347 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
348 | 348 | self.__isConfig = False |
|
349 | 349 | |
|
350 | 350 | class SpectraPlot(Figure): |
|
351 | 351 | |
|
352 | 352 | __isConfig = None |
|
353 | 353 | __nsubplots = None |
|
354 | 354 | |
|
355 | 355 | WIDTHPROF = None |
|
356 | 356 | HEIGHTPROF = None |
|
357 | 357 | PREFIX = 'spc' |
|
358 | 358 | |
|
359 | 359 | def __init__(self): |
|
360 | 360 | |
|
361 | 361 | self.__isConfig = False |
|
362 | 362 | self.__nsubplots = 1 |
|
363 | 363 | |
|
364 | 364 | self.WIDTH = 230 |
|
365 | 365 | self.HEIGHT = 250 |
|
366 | 366 | self.WIDTHPROF = 120 |
|
367 | 367 | self.HEIGHTPROF = 0 |
|
368 | 368 | |
|
369 | 369 | def getSubplots(self): |
|
370 | 370 | |
|
371 | 371 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
372 | 372 | nrow = int(self.nplots*1./ncol + 0.9) |
|
373 | 373 | |
|
374 | 374 | return nrow, ncol |
|
375 | 375 | |
|
376 | 376 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): |
|
377 | 377 | |
|
378 | 378 | self.__showprofile = showprofile |
|
379 | 379 | self.nplots = nplots |
|
380 | 380 | |
|
381 | 381 | ncolspan = 1 |
|
382 | 382 | colspan = 1 |
|
383 | 383 | if showprofile: |
|
384 | 384 | ncolspan = 3 |
|
385 | 385 | colspan = 2 |
|
386 | 386 | self.__nsubplots = 2 |
|
387 | 387 | |
|
388 | 388 | self.createFigure(idfigure = idfigure, |
|
389 | 389 | wintitle = wintitle, |
|
390 | 390 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
391 | 391 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
392 | 392 | show=show) |
|
393 | 393 | |
|
394 | 394 | nrow, ncol = self.getSubplots() |
|
395 | 395 | |
|
396 | 396 | counter = 0 |
|
397 | 397 | for y in range(nrow): |
|
398 | 398 | for x in range(ncol): |
|
399 | 399 | |
|
400 | 400 | if counter >= self.nplots: |
|
401 | 401 | break |
|
402 | 402 | |
|
403 | 403 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
404 | 404 | |
|
405 | 405 | if showprofile: |
|
406 | 406 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
407 | 407 | |
|
408 | 408 | counter += 1 |
|
409 | 409 | |
|
410 | 410 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
411 | 411 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
412 | 412 | save=False, figpath='./', figfile=None, show=True): |
|
413 | 413 | |
|
414 | 414 | """ |
|
415 | 415 | |
|
416 | 416 | Input: |
|
417 | 417 | dataOut : |
|
418 | 418 | idfigure : |
|
419 | 419 | wintitle : |
|
420 | 420 | channelList : |
|
421 | 421 | showProfile : |
|
422 | 422 | xmin : None, |
|
423 | 423 | xmax : None, |
|
424 | 424 | ymin : None, |
|
425 | 425 | ymax : None, |
|
426 | 426 | zmin : None, |
|
427 | 427 | zmax : None |
|
428 | 428 | """ |
|
429 | 429 | |
|
430 | 430 | if channelList == None: |
|
431 | 431 | channelIndexList = dataOut.channelIndexList |
|
432 | 432 | else: |
|
433 | 433 | channelIndexList = [] |
|
434 | 434 | for channel in channelList: |
|
435 | 435 | if channel not in dataOut.channelList: |
|
436 | 436 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
437 | 437 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
438 | 438 | factor = dataOut.normFactor |
|
439 | 439 | x = dataOut.getVelRange(1) |
|
440 | 440 | y = dataOut.getHeiRange() |
|
441 | 441 | |
|
442 | 442 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
443 | 443 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
444 | 444 | avg = numpy.average(z, axis=1) |
|
445 | 445 | noise = dataOut.getNoise()/factor |
|
446 | 446 | |
|
447 | 447 | zdB = 10*numpy.log10(z) |
|
448 | 448 | avgdB = 10*numpy.log10(avg) |
|
449 | 449 | noisedB = 10*numpy.log10(noise) |
|
450 | 450 | |
|
451 | 451 | thisDatetime = dataOut.datatime |
|
452 | 452 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
453 | 453 | xlabel = "Velocity (m/s)" |
|
454 | 454 | ylabel = "Range (Km)" |
|
455 | 455 | |
|
456 | 456 | if not self.__isConfig: |
|
457 | 457 | |
|
458 | 458 | nplots = len(channelIndexList) |
|
459 | 459 | |
|
460 | 460 | self.setup(idfigure=idfigure, |
|
461 | 461 | nplots=nplots, |
|
462 | 462 | wintitle=wintitle, |
|
463 | 463 | showprofile=showprofile, |
|
464 | 464 | show=show) |
|
465 | 465 | |
|
466 | 466 | if xmin == None: xmin = numpy.nanmin(x) |
|
467 | 467 | if xmax == None: xmax = numpy.nanmax(x) |
|
468 | 468 | if ymin == None: ymin = numpy.nanmin(y) |
|
469 | 469 | if ymax == None: ymax = numpy.nanmax(y) |
|
470 | 470 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
471 | 471 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
472 | 472 | |
|
473 | 473 | self.__isConfig = True |
|
474 | 474 | |
|
475 | 475 | self.setWinTitle(title) |
|
476 | 476 | |
|
477 | 477 | for i in range(self.nplots): |
|
478 | 478 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i]) |
|
479 | 479 | axes = self.axesList[i*self.__nsubplots] |
|
480 | 480 | axes.pcolor(x, y, zdB[i,:,:], |
|
481 | 481 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
482 | 482 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
483 | 483 | ticksize=9, cblabel='') |
|
484 | 484 | |
|
485 | 485 | if self.__showprofile: |
|
486 | 486 | axes = self.axesList[i*self.__nsubplots +1] |
|
487 | 487 | axes.pline(avgdB[i], y, |
|
488 | 488 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
489 | 489 | xlabel='dB', ylabel='', title='', |
|
490 | 490 | ytick_visible=False, |
|
491 | 491 | grid='x') |
|
492 | 492 | |
|
493 | 493 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
494 | 494 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
495 | 495 | |
|
496 | 496 | self.draw() |
|
497 | 497 | |
|
498 | 498 | if save: |
|
499 | 499 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
500 | 500 | if figfile == None: |
|
501 | 501 | figfile = self.getFilename(name = date) |
|
502 | 502 | |
|
503 | 503 | self.saveFigure(figpath, figfile) |
|
504 | 504 | |
|
505 | 505 | class Scope(Figure): |
|
506 | 506 | |
|
507 | 507 | __isConfig = None |
|
508 | 508 | |
|
509 | 509 | def __init__(self): |
|
510 | 510 | |
|
511 | 511 | self.__isConfig = False |
|
512 | 512 | self.WIDTH = 600 |
|
513 | 513 | self.HEIGHT = 200 |
|
514 | 514 | |
|
515 | 515 | def getSubplots(self): |
|
516 | 516 | |
|
517 | 517 | nrow = self.nplots |
|
518 | 518 | ncol = 3 |
|
519 | 519 | return nrow, ncol |
|
520 | 520 | |
|
521 | 521 | def setup(self, idfigure, nplots, wintitle, show): |
|
522 | 522 | |
|
523 | 523 | self.nplots = nplots |
|
524 | 524 | |
|
525 | 525 | self.createFigure(idfigure=idfigure, |
|
526 | 526 | wintitle=wintitle, |
|
527 | 527 | show=show) |
|
528 | 528 | |
|
529 | 529 | nrow,ncol = self.getSubplots() |
|
530 | 530 | colspan = 3 |
|
531 | 531 | rowspan = 1 |
|
532 | 532 | |
|
533 | 533 | for i in range(nplots): |
|
534 | 534 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
535 | 535 | |
|
536 | 536 | |
|
537 | 537 | |
|
538 | 538 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
539 | 539 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
540 | 540 | figpath='./', figfile=None, show=True): |
|
541 | 541 | |
|
542 | 542 | """ |
|
543 | 543 | |
|
544 | 544 | Input: |
|
545 | 545 | dataOut : |
|
546 | 546 | idfigure : |
|
547 | 547 | wintitle : |
|
548 | 548 | channelList : |
|
549 | 549 | xmin : None, |
|
550 | 550 | xmax : None, |
|
551 | 551 | ymin : None, |
|
552 | 552 | ymax : None, |
|
553 | 553 | """ |
|
554 | 554 | |
|
555 | 555 | if channelList == None: |
|
556 | 556 | channelIndexList = dataOut.channelIndexList |
|
557 | 557 | else: |
|
558 | 558 | channelIndexList = [] |
|
559 | 559 | for channel in channelList: |
|
560 | 560 | if channel not in dataOut.channelList: |
|
561 | 561 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
562 | 562 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
563 | 563 | |
|
564 | 564 | x = dataOut.heightList |
|
565 | 565 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
566 | 566 | y = y.real |
|
567 | 567 | |
|
568 | 568 | thisDatetime = dataOut.datatime |
|
569 | 569 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
570 | 570 | xlabel = "Range (Km)" |
|
571 | 571 | ylabel = "Intensity" |
|
572 | 572 | |
|
573 | 573 | if not self.__isConfig: |
|
574 | 574 | nplots = len(channelIndexList) |
|
575 | 575 | |
|
576 | 576 | self.setup(idfigure=idfigure, |
|
577 | 577 | nplots=nplots, |
|
578 | 578 | wintitle=wintitle, |
|
579 | 579 | show=show) |
|
580 | 580 | |
|
581 | 581 | if xmin == None: xmin = numpy.nanmin(x) |
|
582 | 582 | if xmax == None: xmax = numpy.nanmax(x) |
|
583 | 583 | if ymin == None: ymin = numpy.nanmin(y) |
|
584 | 584 | if ymax == None: ymax = numpy.nanmax(y) |
|
585 | 585 | |
|
586 | 586 | self.__isConfig = True |
|
587 | 587 | |
|
588 | 588 | self.setWinTitle(title) |
|
589 | 589 | |
|
590 | 590 | for i in range(len(self.axesList)): |
|
591 | 591 | title = "Channel %d" %(i) |
|
592 | 592 | axes = self.axesList[i] |
|
593 | 593 | ychannel = y[i,:] |
|
594 | 594 | axes.pline(x, ychannel, |
|
595 | 595 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
596 | 596 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
597 | 597 | |
|
598 | 598 | self.draw() |
|
599 | 599 | |
|
600 | 600 | if save: |
|
601 | 601 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
602 | 602 | if figfile == None: |
|
603 | 603 | figfile = self.getFilename(name = date) |
|
604 | 604 | |
|
605 | 605 | self.saveFigure(figpath, figfile) |
|
606 | 606 | |
|
607 | 607 | class ProfilePlot(Figure): |
|
608 | 608 | __isConfig = None |
|
609 | 609 | __nsubplots = None |
|
610 | 610 | |
|
611 | 611 | WIDTHPROF = None |
|
612 | 612 | HEIGHTPROF = None |
|
613 | 613 | PREFIX = 'spcprofile' |
|
614 | 614 | |
|
615 | 615 | def __init__(self): |
|
616 | 616 | self.__isConfig = False |
|
617 | 617 | self.__nsubplots = 1 |
|
618 | 618 | |
|
619 | 619 | self.WIDTH = 300 |
|
620 | 620 | self.HEIGHT = 500 |
|
621 | 621 | |
|
622 | 622 | def getSubplots(self): |
|
623 | 623 | ncol = 1 |
|
624 | 624 | nrow = 1 |
|
625 | 625 | |
|
626 | 626 | return nrow, ncol |
|
627 | 627 | |
|
628 | 628 | def setup(self, idfigure, nplots, wintitle, show): |
|
629 | 629 | |
|
630 | 630 | self.nplots = nplots |
|
631 | 631 | |
|
632 | 632 | ncolspan = 1 |
|
633 | 633 | colspan = 1 |
|
634 | 634 | |
|
635 | 635 | self.createFigure(idfigure = idfigure, |
|
636 | 636 | wintitle = wintitle, |
|
637 | 637 | widthplot = self.WIDTH, |
|
638 | 638 | heightplot = self.HEIGHT, |
|
639 | 639 | show=show) |
|
640 | 640 | |
|
641 | 641 | nrow, ncol = self.getSubplots() |
|
642 | 642 | |
|
643 | 643 | counter = 0 |
|
644 | 644 | for y in range(nrow): |
|
645 | 645 | for x in range(ncol): |
|
646 | 646 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
647 | 647 | |
|
648 | 648 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
649 | 649 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
650 | 650 | save=False, figpath='./', figfile=None, show=True): |
|
651 | 651 | |
|
652 | 652 | if channelList == None: |
|
653 | 653 | channelIndexList = dataOut.channelIndexList |
|
654 | 654 | channelList = dataOut.channelList |
|
655 | 655 | else: |
|
656 | 656 | channelIndexList = [] |
|
657 | 657 | for channel in channelList: |
|
658 | 658 | if channel not in dataOut.channelList: |
|
659 | 659 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
660 | 660 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
661 | 661 | |
|
662 | 662 | factor = dataOut.normFactor |
|
663 | 663 | y = dataOut.getHeiRange() |
|
664 | 664 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
665 | 665 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
666 | 666 | avg = numpy.average(x, axis=1) |
|
667 | 667 | |
|
668 | 668 | avgdB = 10*numpy.log10(avg) |
|
669 | 669 | |
|
670 | 670 | thisDatetime = dataOut.datatime |
|
671 | 671 | title = "Power Profile" |
|
672 | 672 | xlabel = "dB" |
|
673 | 673 | ylabel = "Range (Km)" |
|
674 | 674 | |
|
675 | 675 | if not self.__isConfig: |
|
676 | 676 | |
|
677 | 677 | nplots = 1 |
|
678 | 678 | |
|
679 | 679 | self.setup(idfigure=idfigure, |
|
680 | 680 | nplots=nplots, |
|
681 | 681 | wintitle=wintitle, |
|
682 | 682 | show=show) |
|
683 | 683 | |
|
684 | 684 | if ymin == None: ymin = numpy.nanmin(y) |
|
685 | 685 | if ymax == None: ymax = numpy.nanmax(y) |
|
686 | 686 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 |
|
687 | 687 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 |
|
688 | 688 | |
|
689 | 689 | self.__isConfig = True |
|
690 | 690 | |
|
691 | 691 | self.setWinTitle(title) |
|
692 | 692 | |
|
693 | 693 | |
|
694 | 694 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
695 | 695 | axes = self.axesList[0] |
|
696 | 696 | |
|
697 | 697 | legendlabels = ["channel %d"%x for x in channelList] |
|
698 | 698 | axes.pmultiline(avgdB, y, |
|
699 | 699 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
700 | 700 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
701 | 701 | ytick_visible=True, nxticks=5, |
|
702 | 702 | grid='x') |
|
703 | 703 | |
|
704 | 704 | self.draw() |
|
705 | 705 | |
|
706 | 706 | if save: |
|
707 | 707 | date = thisDatetime.strftime("%Y%m%d") |
|
708 | 708 | if figfile == None: |
|
709 | 709 | figfile = self.getFilename(name = date) |
|
710 | 710 | |
|
711 | 711 | self.saveFigure(figpath, figfile) |
|
712 | 712 | |
|
713 | 713 | class CoherenceMap(Figure): |
|
714 | 714 | __isConfig = None |
|
715 | 715 | __nsubplots = None |
|
716 | 716 | |
|
717 | 717 | WIDTHPROF = None |
|
718 | 718 | HEIGHTPROF = None |
|
719 | 719 | PREFIX = 'cmap' |
|
720 | 720 | |
|
721 | 721 | def __init__(self): |
|
722 | 722 | self.timerange = 2*60*60 |
|
723 | 723 | self.__isConfig = False |
|
724 | 724 | self.__nsubplots = 1 |
|
725 | 725 | |
|
726 | 726 | self.WIDTH = 800 |
|
727 | 727 | self.HEIGHT = 150 |
|
728 | 728 | self.WIDTHPROF = 120 |
|
729 | 729 | self.HEIGHTPROF = 0 |
|
730 | 730 | self.counterftp = 0 |
|
731 | 731 | |
|
732 | 732 | def getSubplots(self): |
|
733 | 733 | ncol = 1 |
|
734 | 734 | nrow = self.nplots*2 |
|
735 | 735 | |
|
736 | 736 | return nrow, ncol |
|
737 | 737 | |
|
738 | 738 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): |
|
739 | 739 | self.__showprofile = showprofile |
|
740 | 740 | self.nplots = nplots |
|
741 | 741 | |
|
742 | 742 | ncolspan = 1 |
|
743 | 743 | colspan = 1 |
|
744 | 744 | if showprofile: |
|
745 | 745 | ncolspan = 7 |
|
746 | 746 | colspan = 6 |
|
747 | 747 | self.__nsubplots = 2 |
|
748 | 748 | |
|
749 | 749 | self.createFigure(idfigure = idfigure, |
|
750 | 750 | wintitle = wintitle, |
|
751 | 751 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
752 | 752 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
753 | 753 | show=True) |
|
754 | 754 | |
|
755 | 755 | nrow, ncol = self.getSubplots() |
|
756 | 756 | |
|
757 | 757 | for y in range(nrow): |
|
758 | 758 | for x in range(ncol): |
|
759 | 759 | |
|
760 | 760 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
761 | 761 | |
|
762 | 762 | if showprofile: |
|
763 | 763 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
764 | 764 | |
|
765 | 765 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
766 | 766 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
767 | 767 | timerange=None, |
|
768 | 768 | save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, |
|
769 | 769 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True): |
|
770 | 770 | |
|
771 | 771 | if pairsList == None: |
|
772 | 772 | pairsIndexList = dataOut.pairsIndexList |
|
773 | 773 | else: |
|
774 | 774 | pairsIndexList = [] |
|
775 | 775 | for pair in pairsList: |
|
776 | 776 | if pair not in dataOut.pairsList: |
|
777 | 777 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
778 | 778 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
779 | 779 | |
|
780 | 780 | if timerange != None: |
|
781 | 781 | self.timerange = timerange |
|
782 | 782 | |
|
783 | 783 | if pairsIndexList == []: |
|
784 | 784 | return |
|
785 | 785 | |
|
786 | 786 | if len(pairsIndexList) > 4: |
|
787 | 787 | pairsIndexList = pairsIndexList[0:4] |
|
788 | 788 | |
|
789 | 789 | tmin = None |
|
790 | 790 | tmax = None |
|
791 | 791 | x = dataOut.getTimeRange() |
|
792 | 792 | y = dataOut.getHeiRange() |
|
793 | 793 | |
|
794 | 794 | thisDatetime = dataOut.datatime |
|
795 | 795 | title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
796 | 796 | xlabel = "" |
|
797 | 797 | ylabel = "Range (Km)" |
|
798 | 798 | |
|
799 | 799 | if not self.__isConfig: |
|
800 | 800 | nplots = len(pairsIndexList) |
|
801 | 801 | self.setup(idfigure=idfigure, |
|
802 | 802 | nplots=nplots, |
|
803 | 803 | wintitle=wintitle, |
|
804 | 804 | showprofile=showprofile, |
|
805 | 805 | show=show) |
|
806 | 806 | |
|
807 | 807 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
808 | 808 | if ymin == None: ymin = numpy.nanmin(y) |
|
809 | 809 | if ymax == None: ymax = numpy.nanmax(y) |
|
810 | 810 | |
|
811 | 811 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
812 | 812 | |
|
813 | 813 | self.__isConfig = True |
|
814 | 814 | |
|
815 | 815 | self.setWinTitle(title) |
|
816 | 816 | |
|
817 | 817 | for i in range(self.nplots): |
|
818 | 818 | |
|
819 | 819 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
820 | 820 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
821 | 821 | avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) |
|
822 | 822 | coherence = numpy.abs(avgcoherenceComplex) |
|
823 | 823 | # coherence = numpy.abs(coherenceComplex) |
|
824 | 824 | # avg = numpy.average(coherence, axis=0) |
|
825 | 825 | |
|
826 | 826 | z = coherence.reshape((1,-1)) |
|
827 | 827 | |
|
828 | 828 | counter = 0 |
|
829 | 829 | |
|
830 | 830 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
831 | 831 | axes = self.axesList[i*self.__nsubplots*2] |
|
832 | 832 | axes.pcolorbuffer(x, y, z, |
|
833 | 833 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
834 | 834 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
835 | 835 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
836 | 836 | |
|
837 | 837 | if self.__showprofile: |
|
838 | 838 | counter += 1 |
|
839 | 839 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
840 | 840 | axes.pline(coherence, y, |
|
841 | 841 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, |
|
842 | 842 | xlabel='', ylabel='', title='', ticksize=7, |
|
843 | 843 | ytick_visible=False, nxticks=5, |
|
844 | 844 | grid='x') |
|
845 | 845 | |
|
846 | 846 | counter += 1 |
|
847 | 847 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
848 | 848 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
849 | 849 | # avg = numpy.average(phase, axis=0) |
|
850 | 850 | z = phase.reshape((1,-1)) |
|
851 | 851 | |
|
852 | 852 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
853 | 853 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
854 | 854 | axes.pcolorbuffer(x, y, z, |
|
855 | 855 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
856 | 856 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
857 | 857 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
858 | 858 | |
|
859 | 859 | if self.__showprofile: |
|
860 | 860 | counter += 1 |
|
861 | 861 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
862 | 862 | axes.pline(phase, y, |
|
863 | 863 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
864 | 864 | xlabel='', ylabel='', title='', ticksize=7, |
|
865 | 865 | ytick_visible=False, nxticks=4, |
|
866 | 866 | grid='x') |
|
867 | 867 | |
|
868 | 868 | self.draw() |
|
869 | 869 | |
|
870 | 870 | if save: |
|
871 | 871 | |
|
872 | 872 | if figfile == None: |
|
873 | 873 | figfile = self.getFilename(name = self.name) |
|
874 | 874 | |
|
875 | 875 | self.saveFigure(figpath, figfile) |
|
876 | 876 | |
|
877 | 877 | self.counterftp += 1 |
|
878 | 878 | if (ftp and (self.counterftp==ftpratio)): |
|
879 | 879 | figfilename = os.path.join(figpath,figfile) |
|
880 | 880 | self.sendByFTP(figfilename) |
|
881 | 881 | self.counterftp = 0 |
|
882 | 882 | |
|
883 | 883 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
884 | 884 | self.__isConfig = False |
|
885 | 885 | |
|
886 | 886 | class RTIfromNoise(Figure): |
|
887 | 887 | |
|
888 | 888 | __isConfig = None |
|
889 | 889 | __nsubplots = None |
|
890 | 890 | |
|
891 | 891 | PREFIX = 'rtinoise' |
|
892 | 892 | |
|
893 | 893 | def __init__(self): |
|
894 | 894 | |
|
895 | 895 | self.timerange = 24*60*60 |
|
896 | 896 | self.__isConfig = False |
|
897 | 897 | self.__nsubplots = 1 |
|
898 | 898 | |
|
899 | 899 | self.WIDTH = 820 |
|
900 | 900 | self.HEIGHT = 200 |
|
901 | 901 | self.WIDTHPROF = 120 |
|
902 | 902 | self.HEIGHTPROF = 0 |
|
903 | 903 | self.xdata = None |
|
904 | 904 | self.ydata = None |
|
905 | 905 | |
|
906 | 906 | def getSubplots(self): |
|
907 | 907 | |
|
908 | 908 | ncol = 1 |
|
909 | 909 | nrow = 1 |
|
910 | 910 | |
|
911 | 911 | return nrow, ncol |
|
912 | 912 | |
|
913 | 913 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): |
|
914 | 914 | |
|
915 | 915 | self.__showprofile = showprofile |
|
916 | 916 | self.nplots = nplots |
|
917 | 917 | |
|
918 | 918 | ncolspan = 7 |
|
919 | 919 | colspan = 6 |
|
920 | 920 | self.__nsubplots = 2 |
|
921 | 921 | |
|
922 | 922 | self.createFigure(idfigure = idfigure, |
|
923 | 923 | wintitle = wintitle, |
|
924 | 924 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
925 | 925 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
926 | 926 | show=show) |
|
927 | 927 | |
|
928 | 928 | nrow, ncol = self.getSubplots() |
|
929 | 929 | |
|
930 | 930 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
931 | 931 | |
|
932 | 932 | |
|
933 | 933 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
934 | 934 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
935 | 935 | timerange=None, |
|
936 | 936 | save=False, figpath='./', figfile=None, show=True): |
|
937 | 937 | |
|
938 | 938 | if channelList == None: |
|
939 | 939 | channelIndexList = dataOut.channelIndexList |
|
940 | 940 | channelList = dataOut.channelList |
|
941 | 941 | else: |
|
942 | 942 | channelIndexList = [] |
|
943 | 943 | for channel in channelList: |
|
944 | 944 | if channel not in dataOut.channelList: |
|
945 | 945 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
946 | 946 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
947 | 947 | |
|
948 | 948 | if timerange != None: |
|
949 | 949 | self.timerange = timerange |
|
950 | 950 | |
|
951 | 951 | tmin = None |
|
952 | 952 | tmax = None |
|
953 | 953 | x = dataOut.getTimeRange() |
|
954 | 954 | y = dataOut.getHeiRange() |
|
955 | 955 | factor = dataOut.normFactor |
|
956 | 956 | noise = dataOut.getNoise()/factor |
|
957 | 957 | noisedB = 10*numpy.log10(noise) |
|
958 | 958 | |
|
959 | 959 | thisDatetime = dataOut.datatime |
|
960 | 960 | title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
961 | 961 | xlabel = "" |
|
962 | 962 | ylabel = "Range (Km)" |
|
963 | 963 | |
|
964 | 964 | if not self.__isConfig: |
|
965 | 965 | |
|
966 | 966 | nplots = 1 |
|
967 | 967 | |
|
968 | 968 | self.setup(idfigure=idfigure, |
|
969 | 969 | nplots=nplots, |
|
970 | 970 | wintitle=wintitle, |
|
971 | 971 | showprofile=showprofile, |
|
972 | 972 | show=show) |
|
973 | 973 | |
|
974 | 974 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
975 | 975 | if ymin == None: ymin = numpy.nanmin(noisedB) |
|
976 | 976 | if ymax == None: ymax = numpy.nanmax(noisedB) |
|
977 | 977 | |
|
978 | 978 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
979 | 979 | self.__isConfig = True |
|
980 | 980 | |
|
981 | 981 | self.xdata = numpy.array([]) |
|
982 | 982 | self.ydata = numpy.array([]) |
|
983 | 983 | |
|
984 | 984 | self.setWinTitle(title) |
|
985 | 985 | |
|
986 | 986 | |
|
987 | 987 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
988 | 988 | |
|
989 | 989 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
990 | 990 | axes = self.axesList[0] |
|
991 | 991 | |
|
992 | 992 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
993 | 993 | |
|
994 | 994 | if len(self.ydata)==0: |
|
995 | 995 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
996 | 996 | else: |
|
997 | 997 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
998 | 998 | |
|
999 | 999 | |
|
1000 | 1000 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1001 | 1001 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1002 | 1002 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1003 | 1003 | XAxisAsTime=True |
|
1004 | 1004 | ) |
|
1005 | 1005 | |
|
1006 | 1006 | self.draw() |
|
1007 | 1007 | |
|
1008 | 1008 | if save: |
|
1009 | 1009 | |
|
1010 | 1010 | if figfile == None: |
|
1011 | 1011 | figfile = self.getFilename(name = self.name) |
|
1012 | 1012 | |
|
1013 | 1013 | self.saveFigure(figpath, figfile) |
|
1014 | 1014 | |
|
1015 | 1015 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1016 | 1016 | self.__isConfig = False |
|
1017 | 1017 | del self.xdata |
|
1018 | 1018 | del self.ydata |
|
1019 | 1019 | |
|
1020 | 1020 | |
|
1021 | 1021 | class SpectraHeisScope(Figure): |
|
1022 | 1022 | |
|
1023 | 1023 | |
|
1024 | 1024 | __isConfig = None |
|
1025 | 1025 | __nsubplots = None |
|
1026 | 1026 | |
|
1027 | 1027 | WIDTHPROF = None |
|
1028 | 1028 | HEIGHTPROF = None |
|
1029 | 1029 | PREFIX = 'spc' |
|
1030 | 1030 | |
|
1031 | 1031 | def __init__(self): |
|
1032 | 1032 | |
|
1033 | 1033 | self.__isConfig = False |
|
1034 | 1034 | self.__nsubplots = 1 |
|
1035 | 1035 | |
|
1036 | 1036 | self.WIDTH = 230 |
|
1037 | 1037 | self.HEIGHT = 250 |
|
1038 | 1038 | self.WIDTHPROF = 120 |
|
1039 | 1039 | self.HEIGHTPROF = 0 |
|
1040 | 1040 | self.counterftp = 0 |
|
1041 | 1041 | |
|
1042 | 1042 | def getSubplots(self): |
|
1043 | 1043 | |
|
1044 | 1044 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1045 | 1045 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1046 | 1046 | |
|
1047 | 1047 | return nrow, ncol |
|
1048 | 1048 | |
|
1049 | 1049 | def setup(self, idfigure, nplots, wintitle, show): |
|
1050 | 1050 | |
|
1051 | 1051 | showprofile = False |
|
1052 | 1052 | self.__showprofile = showprofile |
|
1053 | 1053 | self.nplots = nplots |
|
1054 | 1054 | |
|
1055 | 1055 | ncolspan = 1 |
|
1056 | 1056 | colspan = 1 |
|
1057 | 1057 | if showprofile: |
|
1058 | 1058 | ncolspan = 3 |
|
1059 | 1059 | colspan = 2 |
|
1060 | 1060 | self.__nsubplots = 2 |
|
1061 | 1061 | |
|
1062 | 1062 | self.createFigure(idfigure = idfigure, |
|
1063 | 1063 | wintitle = wintitle, |
|
1064 | 1064 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1065 | 1065 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1066 | 1066 | show = show) |
|
1067 | 1067 | |
|
1068 | 1068 | nrow, ncol = self.getSubplots() |
|
1069 | 1069 | |
|
1070 | 1070 | counter = 0 |
|
1071 | 1071 | for y in range(nrow): |
|
1072 | 1072 | for x in range(ncol): |
|
1073 | 1073 | |
|
1074 | 1074 | if counter >= self.nplots: |
|
1075 | 1075 | break |
|
1076 | 1076 | |
|
1077 | 1077 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1078 | 1078 | |
|
1079 | 1079 | if showprofile: |
|
1080 | 1080 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1081 | 1081 | |
|
1082 | 1082 | counter += 1 |
|
1083 | 1083 | |
|
1084 | 1084 | # __isConfig = None |
|
1085 | 1085 | # def __init__(self): |
|
1086 | 1086 | # |
|
1087 | 1087 | # self.__isConfig = False |
|
1088 | 1088 | # self.WIDTH = 600 |
|
1089 | 1089 | # self.HEIGHT = 200 |
|
1090 | 1090 | # |
|
1091 | 1091 | # def getSubplots(self): |
|
1092 | 1092 | # |
|
1093 | 1093 | # nrow = self.nplots |
|
1094 | 1094 | # ncol = 3 |
|
1095 | 1095 | # return nrow, ncol |
|
1096 | 1096 | # |
|
1097 | 1097 | # def setup(self, idfigure, nplots, wintitle): |
|
1098 | 1098 | # |
|
1099 | 1099 | # self.nplots = nplots |
|
1100 | 1100 | # |
|
1101 | 1101 | # self.createFigure(idfigure, wintitle) |
|
1102 | 1102 | # |
|
1103 | 1103 | # nrow,ncol = self.getSubplots() |
|
1104 | 1104 | # colspan = 3 |
|
1105 | 1105 | # rowspan = 1 |
|
1106 | 1106 | # |
|
1107 | 1107 | # for i in range(nplots): |
|
1108 | 1108 | # self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
1109 | 1109 | |
|
1110 | 1110 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
1111 | 1111 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
1112 | 1112 | figpath='./', figfile=None, ftp=False, ftpratio=1, show=True): |
|
1113 | 1113 | |
|
1114 | 1114 | """ |
|
1115 | 1115 | |
|
1116 | 1116 | Input: |
|
1117 | 1117 | dataOut : |
|
1118 | 1118 | idfigure : |
|
1119 | 1119 | wintitle : |
|
1120 | 1120 | channelList : |
|
1121 | 1121 | xmin : None, |
|
1122 | 1122 | xmax : None, |
|
1123 | 1123 | ymin : None, |
|
1124 | 1124 | ymax : None, |
|
1125 | 1125 | """ |
|
1126 | 1126 | |
|
1127 | 1127 | if channelList == None: |
|
1128 | 1128 | channelIndexList = dataOut.channelIndexList |
|
1129 | 1129 | else: |
|
1130 | 1130 | channelIndexList = [] |
|
1131 | 1131 | for channel in channelList: |
|
1132 | 1132 | if channel not in dataOut.channelList: |
|
1133 | 1133 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1134 | 1134 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1135 | 1135 | |
|
1136 | 1136 | # x = dataOut.heightList |
|
1137 | 1137 | c = 3E8 |
|
1138 | 1138 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1139 | 1139 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
1140 | 1140 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
1141 | 1141 | x= x/(10000.0) |
|
1142 | 1142 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
1143 | 1143 | # y = y.real |
|
1144 | 1144 | datadB = 10.*numpy.log10(dataOut.data_spc) |
|
1145 | 1145 | y = datadB |
|
1146 | 1146 | |
|
1147 | 1147 | thisDatetime = dataOut.datatime |
|
1148 | 1148 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1149 | 1149 | xlabel = "Frequency x 10000" |
|
1150 | 1150 | ylabel = "Intensity (dB)" |
|
1151 | 1151 | |
|
1152 | 1152 | if not self.__isConfig: |
|
1153 | 1153 | nplots = len(channelIndexList) |
|
1154 | 1154 | |
|
1155 | 1155 | self.setup(idfigure=idfigure, |
|
1156 | 1156 | nplots=nplots, |
|
1157 | 1157 | wintitle=wintitle, |
|
1158 | 1158 | show=show) |
|
1159 | 1159 | |
|
1160 | 1160 | if xmin == None: xmin = numpy.nanmin(x) |
|
1161 | 1161 | if xmax == None: xmax = numpy.nanmax(x) |
|
1162 | 1162 | if ymin == None: ymin = numpy.nanmin(y) |
|
1163 | 1163 | if ymax == None: ymax = numpy.nanmax(y) |
|
1164 | 1164 | |
|
1165 | 1165 | self.__isConfig = True |
|
1166 | 1166 | |
|
1167 | 1167 | self.setWinTitle(title) |
|
1168 | 1168 | |
|
1169 | 1169 | for i in range(len(self.axesList)): |
|
1170 | 1170 | ychannel = y[i,:] |
|
1171 | 1171 | title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel)) |
|
1172 | 1172 | axes = self.axesList[i] |
|
1173 | 1173 | axes.pline(x, ychannel, |
|
1174 | 1174 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1175 | 1175 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
1176 | 1176 | |
|
1177 | 1177 | |
|
1178 | 1178 | self.draw() |
|
1179 | 1179 | |
|
1180 | 1180 | if save: |
|
1181 | 1181 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1182 | 1182 | if figfile == None: |
|
1183 | 1183 | figfile = self.getFilename(name = date) |
|
1184 | 1184 | |
|
1185 | 1185 | self.saveFigure(figpath, figfile) |
|
1186 | 1186 | |
|
1187 | 1187 | self.counterftp += 1 |
|
1188 | 1188 | if (ftp and (self.counterftp==ftpratio)): |
|
1189 | 1189 | figfilename = os.path.join(figpath,figfile) |
|
1190 | 1190 | self.sendByFTP(figfilename) |
|
1191 | 1191 | self.counterftp = 0 |
|
1192 | 1192 | |
|
1193 | 1193 | |
|
1194 | 1194 | class RTIfromSpectraHeis(Figure): |
|
1195 | 1195 | |
|
1196 | 1196 | __isConfig = None |
|
1197 | 1197 | __nsubplots = None |
|
1198 | 1198 | |
|
1199 | 1199 | PREFIX = 'rtinoise' |
|
1200 | 1200 | |
|
1201 | 1201 | def __init__(self): |
|
1202 | 1202 | |
|
1203 | 1203 | self.timerange = 24*60*60 |
|
1204 | 1204 | self.__isConfig = False |
|
1205 | 1205 | self.__nsubplots = 1 |
|
1206 | 1206 | |
|
1207 | 1207 | self.WIDTH = 820 |
|
1208 | 1208 | self.HEIGHT = 200 |
|
1209 | 1209 | self.WIDTHPROF = 120 |
|
1210 | 1210 | self.HEIGHTPROF = 0 |
|
1211 | 1211 | self.counterftp = 0 |
|
1212 | 1212 | self.xdata = None |
|
1213 | 1213 | self.ydata = None |
|
1214 | 1214 | |
|
1215 | 1215 | def getSubplots(self): |
|
1216 | 1216 | |
|
1217 | 1217 | ncol = 1 |
|
1218 | 1218 | nrow = 1 |
|
1219 | 1219 | |
|
1220 | 1220 | return nrow, ncol |
|
1221 | 1221 | |
|
1222 | 1222 | def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True): |
|
1223 | 1223 | |
|
1224 | 1224 | self.__showprofile = showprofile |
|
1225 | 1225 | self.nplots = nplots |
|
1226 | 1226 | |
|
1227 | 1227 | ncolspan = 7 |
|
1228 | 1228 | colspan = 6 |
|
1229 | 1229 | self.__nsubplots = 2 |
|
1230 | 1230 | |
|
1231 | 1231 | self.createFigure(idfigure = idfigure, |
|
1232 | 1232 | wintitle = wintitle, |
|
1233 | 1233 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1234 | 1234 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1235 | 1235 | show = show) |
|
1236 | 1236 | |
|
1237 | 1237 | nrow, ncol = self.getSubplots() |
|
1238 | 1238 | |
|
1239 | 1239 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1240 | 1240 | |
|
1241 | 1241 | |
|
1242 | 1242 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
1243 | 1243 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1244 | 1244 | timerange=None, |
|
1245 | save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True): | |
|
1245 | save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True, useLocalTime=False, timezone=0): | |
|
1246 | 1246 | |
|
1247 | 1247 | if channelList == None: |
|
1248 | 1248 | channelIndexList = dataOut.channelIndexList |
|
1249 | 1249 | channelList = dataOut.channelList |
|
1250 | 1250 | else: |
|
1251 | 1251 | channelIndexList = [] |
|
1252 | 1252 | for channel in channelList: |
|
1253 | 1253 | if channel not in dataOut.channelList: |
|
1254 | 1254 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1255 | 1255 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1256 | 1256 | |
|
1257 | 1257 | if timerange != None: |
|
1258 | 1258 | self.timerange = timerange |
|
1259 | 1259 | |
|
1260 | 1260 | tmin = None |
|
1261 | 1261 | tmax = None |
|
1262 | 1262 | x = dataOut.getTimeRange() |
|
1263 | 1263 | y = dataOut.getHeiRange() |
|
1264 | 1264 | |
|
1265 | 1265 | factor = 1 |
|
1266 | 1266 | data = dataOut.data_spc/factor |
|
1267 | 1267 | data = numpy.average(data,axis=1) |
|
1268 | 1268 | datadB = 10*numpy.log10(data) |
|
1269 | 1269 | |
|
1270 | 1270 | # factor = dataOut.normFactor |
|
1271 | 1271 | # noise = dataOut.getNoise()/factor |
|
1272 | 1272 | # noisedB = 10*numpy.log10(noise) |
|
1273 | 1273 | |
|
1274 | 1274 | thisDatetime = dataOut.datatime |
|
1275 | if useLocalTime: | |
|
1276 | first_timezone = dataOut.timeZone | |
|
1277 | first_useLocalTime = dataOut.useLocalTime | |
|
1278 | dataOut.timeZone = timezone | |
|
1279 | dataOut.useLocalTime = useLocalTime | |
|
1280 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) | |
|
1281 | ||
|
1275 | 1282 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1276 | 1283 | xlabel = "Local Time" |
|
1277 | 1284 | ylabel = "Intensity (dB)" |
|
1278 | 1285 | |
|
1279 | 1286 | if not self.__isConfig: |
|
1280 | 1287 | |
|
1281 | 1288 | nplots = 1 |
|
1282 | 1289 | |
|
1283 | 1290 | self.setup(idfigure=idfigure, |
|
1284 | 1291 | nplots=nplots, |
|
1285 | 1292 | wintitle=wintitle, |
|
1286 | 1293 | showprofile=showprofile, |
|
1287 | 1294 | show=show) |
|
1288 | 1295 | |
|
1289 | 1296 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1290 | 1297 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
1291 | 1298 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
1292 | 1299 | |
|
1293 | 1300 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1294 | 1301 | self.__isConfig = True |
|
1295 | 1302 | |
|
1296 | 1303 | self.xdata = numpy.array([]) |
|
1297 | 1304 | self.ydata = numpy.array([]) |
|
1298 | 1305 | |
|
1299 | 1306 | self.setWinTitle(title) |
|
1300 | 1307 | |
|
1301 | 1308 | |
|
1302 | 1309 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1303 | 1310 | title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1304 | 1311 | |
|
1305 | 1312 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
1306 | 1313 | axes = self.axesList[0] |
|
1307 | 1314 | |
|
1308 | 1315 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1309 | 1316 | |
|
1310 | 1317 | if len(self.ydata)==0: |
|
1311 | 1318 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
1312 | 1319 | else: |
|
1313 | 1320 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
1314 | 1321 | |
|
1315 | 1322 | |
|
1316 | 1323 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1317 | 1324 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1318 | 1325 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
1319 | 1326 | XAxisAsTime=True |
|
1320 | 1327 | ) |
|
1321 | 1328 | |
|
1322 | 1329 | self.draw() |
|
1323 | 1330 | |
|
1324 | 1331 | if save: |
|
1325 | 1332 | |
|
1326 | 1333 | if figfile == None: |
|
1327 | 1334 | figfile = self.getFilename(name = self.name) |
|
1328 | 1335 | |
|
1329 | 1336 | self.saveFigure(figpath, figfile) |
|
1330 | 1337 | |
|
1331 | 1338 | self.counterftp += 1 |
|
1332 | 1339 | if (ftp and (self.counterftp==ftpratio)): |
|
1333 | 1340 | figfilename = os.path.join(figpath,figfile) |
|
1334 | 1341 | self.sendByFTP(figfilename) |
|
1335 | 1342 | self.counterftp = 0 |
|
1336 | 1343 | |
|
1337 | 1344 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1338 | 1345 | self.__isConfig = False |
|
1339 | 1346 | del self.xdata |
|
1340 | 1347 | del self.ydata |
|
1341 | 1348 | |
|
1342 | ||
|
1349 | dataOut.timeZone = first_timezone | |
|
1350 | dataOut.useLocalTime = first_useLocalTime | |
|
1343 | 1351 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now