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