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