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