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