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