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