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