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