##// END OF EJS Templates
Se corrigen bugs en el eje x de los graficos RTI y CoherenceMap, se reduce el numero de puntos o pixeles en X e Y....
Daniel Valdez -
r471:087ce30f3ac5
parent child
Show More
@@ -1,592 +1,629
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 import Queue
8 8 import threading
9 9
10 10 class FTP_Thread (threading.Thread):
11 11 def __init__(self):
12 12 threading.Thread.__init__(self)
13 13 self.exitFlag = 0
14 14 self.queueLock = threading.Lock()
15 15 self.workQueue = Queue.Queue()
16 16
17 17 def run(self):
18 18 self.send_data()
19 19
20 20 def fin(self):
21 21 self.exitFlag = 1
22 22
23 23 def put_data(self, data):
24 24 # Fill the queue
25 25 self.queueLock.acquire()
26 26 self.workQueue.put(data)
27 27 self.queueLock.release()
28 28
29 29 def send_data(self):
30 30 while not self.exitFlag:
31 31 if self.workQueue.qsize():
32 32
33 33 data = self.workQueue.get(True)
34 34
35 35 try:
36 36 ftpObj = Ftp(host=data['server'],
37 37 username=data['username'],
38 38 passw=data['password'],
39 39 remotefolder=data['folder'])
40 40
41 41 ftpObj.upload(data['figfilename'])
42 42 ftpObj.close()
43 43 except:
44 44 print ValueError, 'Error FTP'
45 45 print "don't worry still running the program"
46 46
47 47
48 48 class Figure:
49 49
50 50 __driver = mpldriver
51 51 __isConfigThread = False
52 52 fig = None
53 53
54 54 id = None
55 55 wintitle = None
56 56 width = None
57 57 height = None
58 58 nplots = None
59 59 timerange = None
60 60
61 61 axesObjList = []
62 62
63 63 WIDTH = None
64 64 HEIGHT = None
65 65 PREFIX = 'fig'
66 66
67 xmin = None
68 xmax = None
69
67 70 def __init__(self):
68 71
69 72 raise ValueError, "This method is not implemented"
70 73
71 74 def __del__(self):
72 75
73 76 self.__driver.closeFigure()
74 77
75 78 def getFilename(self, name, ext='.png'):
76 79
77 80 path = '%s%03d' %(self.PREFIX, self.id)
78 81 filename = '%s_%s%s' %(self.PREFIX, name, ext)
79 82 return os.path.join(path, filename)
80 83
81 84 def getAxesObjList(self):
82 85
83 86 return self.axesObjList
84 87
85 88 def getSubplots(self):
86 89
87 90 raise ValueError, "Abstract method: This method should be defined"
88 91
89 92 def getScreenDim(self, widthplot, heightplot):
90 93
91 94 nrow, ncol = self.getSubplots()
92 95
93 96 widthscreen = widthplot*ncol
94 97 heightscreen = heightplot*nrow
95 98
96 99 return widthscreen, heightscreen
97 100
98 def getTimeLim(self, x, xmin, xmax):
101 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None):
99 102
100 if self.timerange != None:
101 txmin = x[0] - x[0]%self.timerange
102 else:
103 txmin = numpy.min(x)
104
105 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
106 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
103 if self.xmin != None and self.xmax != None:
104 if timerange == None:
105 timerange = self.xmax - self.xmin
106 xmin = self.xmin + timerange
107 xmax = self.xmax + timerange
108
109 return xmin, xmax
107 110
108 ####################################################
109 #If the x is out of xrange
110 if xmax != None:
111 if xmax < (thisdatetime - thisdate).seconds/(60*60.):
112 xmin = None
113 xmax = None
114 111
115 if xmin == None:
116 td = thisdatetime - thisdate
117 xmin = td.seconds/(60*60.)
112 if timerange != None and self.xmin == None and self.xmax == None:
113 txmin = x[0] - x[0]%timerange
114 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
115 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
116 xmin = (thisdatetime - thisdate).seconds/(60*60.)
117 xmax = xmin + timerange/(60*60.)
118 118
119 if xmax == None:
120 xmax = xmin + self.timerange/(60*60.)
119
120 if timerange == None:
121 txmin = numpy.min(x)
122 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
123 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
121 124
122 125 mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
123 tmin = time.mktime(mindt.timetuple())
126 xmin_sec = time.mktime(mindt.timetuple())
124 127
125 128 maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
126 tmax = time.mktime(maxdt.timetuple())
127
128 self.timerange = tmax - tmin
129
130 return tmin, tmax
129 xmax_sec = time.mktime(maxdt.timetuple())
130
131 return xmin_sec, xmax_sec
132
133
134
135
136
137 # if timerange != None:
138 # txmin = x[0] - x[0]%timerange
139 # else:
140 # txmin = numpy.min(x)
141 #
142 # thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
143 # thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
144 #
145 # ####################################################
146 # #If the x is out of xrange
147 # if xmax != None:
148 # if xmax < (thisdatetime - thisdate).seconds/(60*60.):
149 # xmin = None
150 # xmax = None
151 #
152 # if xmin == None:
153 # td = thisdatetime - thisdate
154 # xmin = td.seconds/(60*60.)
155 #
156 # if xmax == None:
157 # xmax = xmin + self.timerange/(60*60.)
158 #
159 # mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
160 # tmin = time.mktime(mindt.timetuple())
161 #
162 # maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
163 # tmax = time.mktime(maxdt.timetuple())
164 #
165 # #self.timerange = tmax - tmin
166 #
167 # return tmin, tmax
131 168
132 169 def init(self, id, nplots, wintitle):
133 170
134 171 raise ValueError, "This method has been replaced with createFigure"
135 172
136 173 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
137 174
138 175 """
139 176 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
140 177 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
141 178 y self.HEIGHT y el numero de subplots (nrow, ncol)
142 179
143 180 Input:
144 181 id : Los parametros necesarios son
145 182 wintitle :
146 183
147 184 """
148 185
149 186 if widthplot == None:
150 187 widthplot = self.WIDTH
151 188
152 189 if heightplot == None:
153 190 heightplot = self.HEIGHT
154 191
155 192 self.id = id
156 193
157 194 self.wintitle = wintitle
158 195
159 196 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
160 197
161 198 self.fig = self.__driver.createFigure(id=self.id,
162 199 wintitle=self.wintitle,
163 200 width=self.widthscreen,
164 201 height=self.heightscreen,
165 202 show=show)
166 203
167 204 self.axesObjList = []
168 205
169 206
170 207 def setDriver(self, driver=mpldriver):
171 208
172 209 self.__driver = driver
173 210
174 211 def setTitle(self, title):
175 212
176 213 self.__driver.setTitle(self.fig, title)
177 214
178 215 def setWinTitle(self, title):
179 216
180 217 self.__driver.setWinTitle(self.fig, title=title)
181 218
182 219 def setTextFromAxes(self, text):
183 220
184 221 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
185 222
186 223 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
187 224
188 225 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
189 226
190 227 def addAxes(self, *args):
191 228 """
192 229
193 230 Input:
194 231 *args : Los parametros necesarios son
195 232 nrow, ncol, xpos, ypos, colspan, rowspan
196 233 """
197 234
198 235 axesObj = Axes(self.fig, *args)
199 236 self.axesObjList.append(axesObj)
200 237
201 238 def saveFigure(self, figpath, figfile, *args):
202 239
203 240 filename = os.path.join(figpath, figfile)
204 241
205 242 fullpath = os.path.split(filename)[0]
206 243
207 244 if not os.path.exists(fullpath):
208 245 subpath = os.path.split(fullpath)[0]
209 246
210 247 if not os.path.exists(subpath):
211 248 os.mkdir(subpath)
212 249
213 250 os.mkdir(fullpath)
214 251
215 252 self.__driver.saveFigure(self.fig, filename, *args)
216 253
217 254 def sendByFTP(self, figfilename, server, folder, username, password):
218 255 ftpObj = Ftp(host=server, username=username, passw=password, remotefolder=folder)
219 256 ftpObj.upload(figfilename)
220 257 ftpObj.close()
221 258
222 259 def sendByFTP_Thread(self, figfilename, server, folder, username, password):
223 260 data = {'figfilename':figfilename,'server':server,'folder':folder,'username':username,'password':password}
224 261
225 262 if not(self.__isConfigThread):
226 263
227 264 self.thread = FTP_Thread()
228 265 self.thread.start()
229 266 self.__isConfigThread = True
230 267
231 268 self.thread.put_data(data)
232 269 #print 'thread.isAlive()', self.thread.isAlive()
233 270
234 271
235 272 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
236 273 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
237 274 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
238 275 FTP_WEI = '%2.2d'%FTP_WEI
239 276 EXP_CODE = '%3.3d'%EXP_CODE
240 277 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
241 278 PLOT_CODE = '%2.2d'%PLOT_CODE
242 279 PLOT_POS = '%2.2d'%PLOT_POS
243 280 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
244 281 return name
245 282
246 283 def draw(self):
247 284
248 285 self.__driver.draw(self.fig)
249 286
250 287 def run(self):
251 288
252 289 raise ValueError, "This method is not implemented"
253 290
254 291 axesList = property(getAxesObjList)
255 292
256 293
257 294 class Axes:
258 295
259 296 __driver = mpldriver
260 297 fig = None
261 298 ax = None
262 299 plot = None
263 300 __missing = 1E30
264 301 __firsttime = None
265 302
266 303 __showprofile = False
267 304
268 305 xmin = None
269 306 xmax = None
270 307 ymin = None
271 308 ymax = None
272 309 zmin = None
273 310 zmax = None
274 311
275 312 x_buffer = None
276 313 z_buffer = None
277 314
278 315 decimationx = None
279 316 decimationy = None
280 317
281 __MAXNUMX = 1000
282 __MAXNUMY = 500
318 __MAXNUMX = 300
319 __MAXNUMY = 150
283 320
284 321 def __init__(self, *args):
285 322
286 323 """
287 324
288 325 Input:
289 326 *args : Los parametros necesarios son
290 327 fig, nrow, ncol, xpos, ypos, colspan, rowspan
291 328 """
292 329
293 330 ax = self.__driver.createAxes(*args)
294 331 self.fig = args[0]
295 332 self.ax = ax
296 333 self.plot = None
297 334
298 335 self.__firsttime = True
299 336 self.idlineList = []
300 337
301 338 self.x_buffer = numpy.array([])
302 339 self.z_buffer = numpy.array([])
303 340
304 341 def setText(self, text):
305 342
306 343 self.__driver.setAxesText(self.ax, text)
307 344
308 345 def setXAxisAsTime(self):
309 346 pass
310 347
311 348 def pline(self, x, y,
312 349 xmin=None, xmax=None,
313 350 ymin=None, ymax=None,
314 351 xlabel='', ylabel='',
315 352 title='',
316 353 **kwargs):
317 354
318 355 """
319 356
320 357 Input:
321 358 x :
322 359 y :
323 360 xmin :
324 361 xmax :
325 362 ymin :
326 363 ymax :
327 364 xlabel :
328 365 ylabel :
329 366 title :
330 367 **kwargs : Los parametros aceptados son
331 368
332 369 ticksize
333 370 ytick_visible
334 371 """
335 372
336 373 if self.__firsttime:
337 374
338 375 if xmin == None: xmin = numpy.nanmin(x)
339 376 if xmax == None: xmax = numpy.nanmax(x)
340 377 if ymin == None: ymin = numpy.nanmin(y)
341 378 if ymax == None: ymax = numpy.nanmax(y)
342 379
343 380 self.plot = self.__driver.createPline(self.ax, x, y,
344 381 xmin, xmax,
345 382 ymin, ymax,
346 383 xlabel=xlabel,
347 384 ylabel=ylabel,
348 385 title=title,
349 386 **kwargs)
350 387
351 388 self.idlineList.append(0)
352 389 self.__firsttime = False
353 390 return
354 391
355 392 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
356 393 ylabel=ylabel,
357 394 title=title)
358 395
359 396 def addpline(self, x, y, idline, **kwargs):
360 397 lines = self.ax.lines
361 398
362 399 if idline in self.idlineList:
363 400 self.__driver.set_linedata(self.ax, x, y, idline)
364 401
365 402 if idline not in(self.idlineList):
366 403 self.__driver.addpline(self.ax, x, y, **kwargs)
367 404 self.idlineList.append(idline)
368 405
369 406 return
370 407
371 408 def pmultiline(self, x, y,
372 409 xmin=None, xmax=None,
373 410 ymin=None, ymax=None,
374 411 xlabel='', ylabel='',
375 412 title='',
376 413 **kwargs):
377 414
378 415 if self.__firsttime:
379 416
380 417 if xmin == None: xmin = numpy.nanmin(x)
381 418 if xmax == None: xmax = numpy.nanmax(x)
382 419 if ymin == None: ymin = numpy.nanmin(y)
383 420 if ymax == None: ymax = numpy.nanmax(y)
384 421
385 422 self.plot = self.__driver.createPmultiline(self.ax, x, y,
386 423 xmin, xmax,
387 424 ymin, ymax,
388 425 xlabel=xlabel,
389 426 ylabel=ylabel,
390 427 title=title,
391 428 **kwargs)
392 429 self.__firsttime = False
393 430 return
394 431
395 432 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
396 433 ylabel=ylabel,
397 434 title=title)
398 435
399 436 def pmultilineyaxis(self, x, y,
400 437 xmin=None, xmax=None,
401 438 ymin=None, ymax=None,
402 439 xlabel='', ylabel='',
403 440 title='',
404 441 **kwargs):
405 442
406 443 if self.__firsttime:
407 444
408 445 if xmin == None: xmin = numpy.nanmin(x)
409 446 if xmax == None: xmax = numpy.nanmax(x)
410 447 if ymin == None: ymin = numpy.nanmin(y)
411 448 if ymax == None: ymax = numpy.nanmax(y)
412 449
413 450 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
414 451 xmin, xmax,
415 452 ymin, ymax,
416 453 xlabel=xlabel,
417 454 ylabel=ylabel,
418 455 title=title,
419 456 **kwargs)
420 457 if self.xmin == None: self.xmin = xmin
421 458 if self.xmax == None: self.xmax = xmax
422 459 if self.ymin == None: self.ymin = ymin
423 460 if self.ymax == None: self.ymax = ymax
424 461
425 462 self.__firsttime = False
426 463 return
427 464
428 465 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
429 466 ylabel=ylabel,
430 467 title=title)
431 468
432 469 def pcolor(self, x, y, z,
433 470 xmin=None, xmax=None,
434 471 ymin=None, ymax=None,
435 472 zmin=None, zmax=None,
436 473 xlabel='', ylabel='',
437 474 title='', rti = False, colormap='jet',
438 475 **kwargs):
439 476
440 477 """
441 478 Input:
442 479 x :
443 480 y :
444 481 x :
445 482 xmin :
446 483 xmax :
447 484 ymin :
448 485 ymax :
449 486 zmin :
450 487 zmax :
451 488 xlabel :
452 489 ylabel :
453 490 title :
454 491 **kwargs : Los parametros aceptados son
455 492 ticksize=9,
456 493 cblabel=''
457 494 rti = True or False
458 495 """
459 496
460 497 if self.__firsttime:
461 498
462 499 if xmin == None: xmin = numpy.nanmin(x)
463 500 if xmax == None: xmax = numpy.nanmax(x)
464 501 if ymin == None: ymin = numpy.nanmin(y)
465 502 if ymax == None: ymax = numpy.nanmax(y)
466 503 if zmin == None: zmin = numpy.nanmin(z)
467 504 if zmax == None: zmax = numpy.nanmax(z)
468 505
469 506
470 507 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
471 508 xmin, xmax,
472 509 ymin, ymax,
473 510 zmin, zmax,
474 511 xlabel=xlabel,
475 512 ylabel=ylabel,
476 513 title=title,
477 514 colormap=colormap,
478 515 **kwargs)
479 516
480 517 if self.xmin == None: self.xmin = xmin
481 518 if self.xmax == None: self.xmax = xmax
482 519 if self.ymin == None: self.ymin = ymin
483 520 if self.ymax == None: self.ymax = ymax
484 521 if self.zmin == None: self.zmin = zmin
485 522 if self.zmax == None: self.zmax = zmax
486 523
487 524 self.__firsttime = False
488 525 return
489 526
490 527 if rti:
491 528 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
492 529 xlabel=xlabel,
493 530 ylabel=ylabel,
494 531 title=title,
495 532 colormap=colormap)
496 533 return
497 534
498 535 self.__driver.pcolor(self.plot, z,
499 536 xlabel=xlabel,
500 537 ylabel=ylabel,
501 538 title=title)
502 539
503 540 def pcolorbuffer(self, x, y, z,
504 541 xmin=None, xmax=None,
505 542 ymin=None, ymax=None,
506 543 zmin=None, zmax=None,
507 544 xlabel='', ylabel='',
508 545 title='', rti = True, colormap='jet',
509 546 maxNumX = None, maxNumY = None,
510 547 **kwargs):
511 548
512 549 if maxNumX == None:
513 550 maxNumX = self.__MAXNUMX
514 551
515 552 if maxNumY == None:
516 553 maxNumY = self.__MAXNUMY
517 554
518 555 if self.__firsttime:
519 556 self.z_buffer = z
520 557 self.x_buffer = numpy.hstack((self.x_buffer, x))
521 558
522 559 if xmin == None: xmin = numpy.nanmin(x)
523 560 if xmax == None: xmax = numpy.nanmax(x)
524 561 if ymin == None: ymin = numpy.nanmin(y)
525 562 if ymax == None: ymax = numpy.nanmax(y)
526 563 if zmin == None: zmin = numpy.nanmin(z)
527 564 if zmax == None: zmax = numpy.nanmax(z)
528 565
529 566
530 567 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
531 568 xmin, xmax,
532 569 ymin, ymax,
533 570 zmin, zmax,
534 571 xlabel=xlabel,
535 572 ylabel=ylabel,
536 573 title=title,
537 574 colormap=colormap,
538 575 **kwargs)
539 576
540 577 if self.xmin == None: self.xmin = xmin
541 578 if self.xmax == None: self.xmax = xmax
542 579 if self.ymin == None: self.ymin = ymin
543 580 if self.ymax == None: self.ymax = ymax
544 581 if self.zmin == None: self.zmin = zmin
545 582 if self.zmax == None: self.zmax = zmax
546 583
547 584 self.__firsttime = False
548 585 return
549 586
550 587 self.x_buffer = numpy.hstack((self.x_buffer, x[-1]))
551 588 self.z_buffer = numpy.hstack((self.z_buffer, z))
552 589
553 590 if self.decimationx == None:
554 591 deltax = float(self.xmax - self.xmin)/maxNumX
555 592 deltay = float(self.ymax - self.ymin)/maxNumY
556 593
557 594 resolutionx = self.x_buffer[2]-self.x_buffer[0]
558 595 resolutiony = y[1]-y[0]
559 596
560 597 self.decimationx = numpy.ceil(deltax / resolutionx)
561 598 self.decimationy = numpy.ceil(deltay / resolutiony)
562 599
563 600 z_buffer = self.z_buffer.reshape(-1,len(y))
564 601
565 602 x_buffer = self.x_buffer[::self.decimationx]
566 603 y_buffer = y[::self.decimationy]
567 604 z_buffer = z_buffer[::self.decimationx, ::self.decimationy]
568 605 #===================================================
569 606
570 607 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
571 608
572 609 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
573 610 xlabel=xlabel,
574 611 ylabel=ylabel,
575 612 title=title,
576 613 colormap=colormap)
577 614 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
578 615
579 616 deltas = x_buffer[1:] - x_buffer[0:-1]
580 617 x_median = numpy.median(deltas)
581 618
582 619 index = numpy.where(deltas >= 2*x_median)
583 620
584 621 if len(index[0]) != 0:
585 622 z_buffer[index[0],::] = self.__missing
586 623 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
587 624
588 625 return x_buffer, y_buffer, z_buffer
589 626
590 627
591 628
592 629 No newline at end of file
@@ -1,2000 +1,2033
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],:,:])
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],:,:])
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 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
211 211 self.counter_imagwr = 0
212 212
213 213 self.counter_imagwr = 0
214 214
215 215 class SNRPlot(Figure):
216 216
217 217 __isConfig = None
218 218 __nsubplots = None
219 219
220 220 WIDTHPROF = None
221 221 HEIGHTPROF = None
222 222 PREFIX = 'snr'
223 223
224 224 def __init__(self):
225 225
226 226 self.timerange = 2*60*60
227 227 self.__isConfig = False
228 228 self.__nsubplots = 1
229 229
230 230 self.WIDTH = 800
231 231 self.HEIGHT = 150
232 232 self.WIDTHPROF = 120
233 233 self.HEIGHTPROF = 0
234 234 self.counter_imagwr = 0
235 235
236 236 self.PLOT_CODE = 0
237 237 self.FTP_WEI = None
238 238 self.EXP_CODE = None
239 239 self.SUB_EXP_CODE = None
240 240 self.PLOT_POS = None
241 241
242 242 def getSubplots(self):
243 243
244 244 ncol = 1
245 245 nrow = self.nplots
246 246
247 247 return nrow, ncol
248 248
249 249 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
250 250
251 251 self.__showprofile = showprofile
252 252 self.nplots = nplots
253 253
254 254 ncolspan = 1
255 255 colspan = 1
256 256 if showprofile:
257 257 ncolspan = 7
258 258 colspan = 6
259 259 self.__nsubplots = 2
260 260
261 261 self.createFigure(id = id,
262 262 wintitle = wintitle,
263 263 widthplot = self.WIDTH + self.WIDTHPROF,
264 264 heightplot = self.HEIGHT + self.HEIGHTPROF,
265 265 show=show)
266 266
267 267 nrow, ncol = self.getSubplots()
268 268
269 269 counter = 0
270 270 for y in range(nrow):
271 271 for x in range(ncol):
272 272
273 273 if counter >= self.nplots:
274 274 break
275 275
276 276 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
277 277
278 278 if showprofile:
279 279 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
280 280
281 281 counter += 1
282 282
283 283 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
284 284 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
285 285 timerange=None,
286 286 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
287 287 server=None, folder=None, username=None, password=None,
288 288 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
289 289
290 290 """
291 291
292 292 Input:
293 293 dataOut :
294 294 id :
295 295 wintitle :
296 296 channelList :
297 297 showProfile :
298 298 xmin : None,
299 299 xmax : None,
300 300 ymin : None,
301 301 ymax : None,
302 302 zmin : None,
303 303 zmax : None
304 304 """
305 305
306 306 if channelList == None:
307 307 channelIndexList = dataOut.channelIndexList
308 308 else:
309 309 channelIndexList = []
310 310 for channel in channelList:
311 311 if channel not in dataOut.channelList:
312 312 raise ValueError, "Channel %d is not in dataOut.channelList"
313 313 channelIndexList.append(dataOut.channelList.index(channel))
314 314
315 315 if timerange != None:
316 316 self.timerange = timerange
317 317
318 318 tmin = None
319 319 tmax = None
320 320 factor = dataOut.normFactor
321 321 x = dataOut.getTimeRange()
322 322 y = dataOut.getHeiRange()
323 323
324 324 z = dataOut.data_spc[channelIndexList,:,:]/factor
325 325 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
326 326 avg = numpy.average(z, axis=1)
327 327
328 328 avgdB = 10.*numpy.log10(avg)
329 329
330 330 noise = dataOut.getNoise()/factor
331 331 noisedB = 10.*numpy.log10(noise)
332 332
333 333 SNR = numpy.transpose(numpy.divide(avg.T,noise))
334 334
335 335 SNR_dB = 10.*numpy.log10(SNR)
336 336
337 337 #SNR_dB = numpy.transpose(numpy.subtract(avgdB.T, noisedB))
338 338
339 339 # thisDatetime = dataOut.datatime
340 340 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
341 341 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
342 342 xlabel = ""
343 343 ylabel = "Range (Km)"
344 344
345 345 if not self.__isConfig:
346 346
347 347 nplots = len(channelIndexList)
348 348
349 349 self.setup(id=id,
350 350 nplots=nplots,
351 351 wintitle=wintitle,
352 352 showprofile=showprofile,
353 353 show=show)
354 354
355 355 tmin, tmax = self.getTimeLim(x, xmin, xmax)
356 356 if ymin == None: ymin = numpy.nanmin(y)
357 357 if ymax == None: ymax = numpy.nanmax(y)
358 358 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
359 359 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
360 360
361 361 self.FTP_WEI = ftp_wei
362 362 self.EXP_CODE = exp_code
363 363 self.SUB_EXP_CODE = sub_exp_code
364 364 self.PLOT_POS = plot_pos
365 365
366 366 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
367 367 self.__isConfig = True
368 368
369 369
370 370 self.setWinTitle(title)
371 371
372 372 for i in range(self.nplots):
373 373 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
374 374 axes = self.axesList[i*self.__nsubplots]
375 375 zdB = SNR_dB[i].reshape((1,-1))
376 376 axes.pcolorbuffer(x, y, zdB,
377 377 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
378 378 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
379 379 ticksize=9, cblabel='', cbsize="1%")
380 380
381 381 # if self.__showprofile:
382 382 # axes = self.axesList[i*self.__nsubplots +1]
383 383 # axes.pline(avgdB[i], y,
384 384 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
385 385 # xlabel='dB', ylabel='', title='',
386 386 # ytick_visible=False,
387 387 # grid='x')
388 388 #
389 389 self.draw()
390 390
391 391 if lastone:
392 392 if dataOut.blocknow >= dataOut.last_block:
393 393 if figfile == None:
394 394 figfile = self.getFilename(name = self.name)
395 395 self.saveFigure(figpath, figfile)
396 396
397 397 if (save and not(lastone)):
398 398
399 399 self.counter_imagwr += 1
400 400 if (self.counter_imagwr==wr_period):
401 401 if figfile == None:
402 402 figfile = self.getFilename(name = self.name)
403 403 self.saveFigure(figpath, figfile)
404 404
405 405 if ftp:
406 406 #provisionalmente envia archivos en el formato de la web en tiempo real
407 407 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
408 408 path = '%s%03d' %(self.PREFIX, self.id)
409 409 ftp_file = os.path.join(path,'ftp','%s.png'%name)
410 410 self.saveFigure(figpath, ftp_file)
411 411 ftp_filename = os.path.join(figpath,ftp_file)
412 412 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
413 413 self.counter_imagwr = 0
414 414
415 415 self.counter_imagwr = 0
416 416
417 417 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
418 418
419 419 self.__isConfig = False
420 420
421 421 if lastone:
422 422 if figfile == None:
423 423 figfile = self.getFilename(name = self.name)
424 424 self.saveFigure(figpath, figfile)
425 425
426 426 if ftp:
427 427 #provisionalmente envia archivos en el formato de la web en tiempo real
428 428 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
429 429 path = '%s%03d' %(self.PREFIX, self.id)
430 430 ftp_file = os.path.join(path,'ftp','%s.png'%name)
431 431 self.saveFigure(figpath, ftp_file)
432 432 ftp_filename = os.path.join(figpath,ftp_file)
433 433 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
434 434
435 435
436 436 class RTIPlot(Figure):
437 437
438 438 __isConfig = None
439 439 __nsubplots = None
440 440
441 441 WIDTHPROF = None
442 442 HEIGHTPROF = None
443 443 PREFIX = 'rti'
444 444
445 445 def __init__(self):
446 446
447 447 self.timerange = 2*60*60
448 448 self.__isConfig = False
449 449 self.__nsubplots = 1
450 450
451 451 self.WIDTH = 800
452 452 self.HEIGHT = 150
453 453 self.WIDTHPROF = 120
454 454 self.HEIGHTPROF = 0
455 455 self.counter_imagwr = 0
456 456
457 457 self.PLOT_CODE = 0
458 458 self.FTP_WEI = None
459 459 self.EXP_CODE = None
460 460 self.SUB_EXP_CODE = None
461 461 self.PLOT_POS = None
462 self.tmin = None
463 self.tmax = None
464
465 self.xmin = None
466 self.xmax = None
462 467
463 468 def getSubplots(self):
464 469
465 470 ncol = 1
466 471 nrow = self.nplots
467 472
468 473 return nrow, ncol
469 474
470 475 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
471 476
472 477 self.__showprofile = showprofile
473 478 self.nplots = nplots
474 479
475 480 ncolspan = 1
476 481 colspan = 1
477 482 if showprofile:
478 483 ncolspan = 7
479 484 colspan = 6
480 485 self.__nsubplots = 2
481 486
482 487 self.createFigure(id = id,
483 488 wintitle = wintitle,
484 489 widthplot = self.WIDTH + self.WIDTHPROF,
485 490 heightplot = self.HEIGHT + self.HEIGHTPROF,
486 491 show=show)
487 492
488 493 nrow, ncol = self.getSubplots()
489 494
490 495 counter = 0
491 496 for y in range(nrow):
492 497 for x in range(ncol):
493 498
494 499 if counter >= self.nplots:
495 500 break
496 501
497 502 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
498 503
499 504 if showprofile:
500 505 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
501 506
502 507 counter += 1
503 508
504 509 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
505 510 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
506 511 timerange=None,
507 512 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
508 513 server=None, folder=None, username=None, password=None,
509 514 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
510 515
511 516 """
512 517
513 518 Input:
514 519 dataOut :
515 520 id :
516 521 wintitle :
517 522 channelList :
518 523 showProfile :
519 524 xmin : None,
520 525 xmax : None,
521 526 ymin : None,
522 527 ymax : None,
523 528 zmin : None,
524 529 zmax : None
525 530 """
526 531
527 532 if channelList == None:
528 533 channelIndexList = dataOut.channelIndexList
529 534 else:
530 535 channelIndexList = []
531 536 for channel in channelList:
532 537 if channel not in dataOut.channelList:
533 538 raise ValueError, "Channel %d is not in dataOut.channelList"
534 539 channelIndexList.append(dataOut.channelList.index(channel))
535 540
536 541 if timerange != None:
537 542 self.timerange = timerange
538 543
539 tmin = None
540 tmax = None
544 #tmin = None
545 #tmax = None
541 546 factor = dataOut.normFactor
542 547 x = dataOut.getTimeRange()
543 548 y = dataOut.getHeiRange()
544 549
545 550 z = dataOut.data_spc[channelIndexList,:,:]/factor
546 551 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
547 552 avg = numpy.average(z, axis=1)
548 553
549 554 avgdB = 10.*numpy.log10(avg)
550 555
551 556
552 557 # thisDatetime = dataOut.datatime
553 558 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
554 559 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
555 560 xlabel = ""
556 561 ylabel = "Range (Km)"
557 562
558 563 if not self.__isConfig:
559 564
560 565 nplots = len(channelIndexList)
561 566
562 567 self.setup(id=id,
563 568 nplots=nplots,
564 569 wintitle=wintitle,
565 570 showprofile=showprofile,
566 571 show=show)
567 572
568 tmin, tmax = self.getTimeLim(x, xmin, xmax)
573 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
574
575 # if timerange != None:
576 # self.timerange = timerange
577 # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange)
578
579
580
569 581 if ymin == None: ymin = numpy.nanmin(y)
570 582 if ymax == None: ymax = numpy.nanmax(y)
571 583 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
572 584 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
573 585
574 586 self.FTP_WEI = ftp_wei
575 587 self.EXP_CODE = exp_code
576 588 self.SUB_EXP_CODE = sub_exp_code
577 589 self.PLOT_POS = plot_pos
578 590
579 591 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
580 592 self.__isConfig = True
581 593
582 594
583 595 self.setWinTitle(title)
584
596
597 if ((self.xmax - x[1]) < (x[1]-x[0])):
598 x[1] = self.xmax
599
585 600 for i in range(self.nplots):
586 601 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
587 602 axes = self.axesList[i*self.__nsubplots]
588 603 zdB = avgdB[i].reshape((1,-1))
589 604 axes.pcolorbuffer(x, y, zdB,
590 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
605 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
591 606 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
592 607 ticksize=9, cblabel='', cbsize="1%")
593 608
594 609 if self.__showprofile:
595 610 axes = self.axesList[i*self.__nsubplots +1]
596 611 axes.pline(avgdB[i], y,
597 612 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
598 613 xlabel='dB', ylabel='', title='',
599 614 ytick_visible=False,
600 615 grid='x')
601 616
602 617 self.draw()
603 618
604 if lastone:
605 if dataOut.blocknow >= dataOut.last_block:
606 if figfile == None:
607 figfile = self.getFilename(name = self.name)
608 self.saveFigure(figpath, figfile)
609
610 if (save and not(lastone)):
611
612 self.counter_imagwr += 1
613 if (self.counter_imagwr==wr_period):
614 if figfile == None:
615 figfile = self.getFilename(name = self.name)
616 self.saveFigure(figpath, figfile)
617
618 if ftp:
619 #provisionalmente envia archivos en el formato de la web en tiempo real
620 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
621 path = '%s%03d' %(self.PREFIX, self.id)
622 ftp_file = os.path.join(path,'ftp','%s.png'%name)
623 self.saveFigure(figpath, ftp_file)
624 ftp_filename = os.path.join(figpath,ftp_file)
625 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
626 self.counter_imagwr = 0
619 # if lastone:
620 # if dataOut.blocknow >= dataOut.last_block:
621 # if figfile == None:
622 # figfile = self.getFilename(name = self.name)
623 # self.saveFigure(figpath, figfile)
624 #
625 # if (save and not(lastone)):
626 #
627 # self.counter_imagwr += 1
628 # if (self.counter_imagwr==wr_period):
629 # if figfile == None:
630 # figfile = self.getFilename(name = self.name)
631 # self.saveFigure(figpath, figfile)
632 #
633 # if ftp:
634 # #provisionalmente envia archivos en el formato de la web en tiempo real
635 # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
636 # path = '%s%03d' %(self.PREFIX, self.id)
637 # ftp_file = os.path.join(path,'ftp','%s.png'%name)
638 # self.saveFigure(figpath, ftp_file)
639 # ftp_filename = os.path.join(figpath,ftp_file)
640 # self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
641 # self.counter_imagwr = 0
642 #
643 # self.counter_imagwr = 0
627 644
628 self.counter_imagwr = 0
629
630 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
631
645 #if ((dataOut.utctime-time.timezone) >= self.axesList[0].xmax):
646 if x[1] >= self.axesList[0].xmax:
647 self.saveFigure(figpath, figfile)
632 648 self.__isConfig = False
633 649
634 if lastone:
635 if figfile == None:
636 figfile = self.getFilename(name = self.name)
637 self.saveFigure(figpath, figfile)
638
639 if ftp:
640 #provisionalmente envia archivos en el formato de la web en tiempo real
641 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
642 path = '%s%03d' %(self.PREFIX, self.id)
643 ftp_file = os.path.join(path,'ftp','%s.png'%name)
644 self.saveFigure(figpath, ftp_file)
645 ftp_filename = os.path.join(figpath,ftp_file)
646 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
650 # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
651 #
652 # self.__isConfig = False
653
654 # if lastone:
655 # if figfile == None:
656 # figfile = self.getFilename(name = self.name)
657 # self.saveFigure(figpath, figfile)
658 #
659 # if ftp:
660 # #provisionalmente envia archivos en el formato de la web en tiempo real
661 # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
662 # path = '%s%03d' %(self.PREFIX, self.id)
663 # ftp_file = os.path.join(path,'ftp','%s.png'%name)
664 # self.saveFigure(figpath, ftp_file)
665 # ftp_filename = os.path.join(figpath,ftp_file)
666 # self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
647 667
648 668
649 669 class SpectraPlot(Figure):
650 670
651 671 __isConfig = None
652 672 __nsubplots = None
653 673
654 674 WIDTHPROF = None
655 675 HEIGHTPROF = None
656 676 PREFIX = 'spc'
657 677
658 678 def __init__(self):
659 679
660 680 self.__isConfig = False
661 681 self.__nsubplots = 1
662 682
663 683 self.WIDTH = 280
664 684 self.HEIGHT = 250
665 685 self.WIDTHPROF = 120
666 686 self.HEIGHTPROF = 0
667 687 self.counter_imagwr = 0
668 688
669 689 self.PLOT_CODE = 1
670 690 self.FTP_WEI = None
671 691 self.EXP_CODE = None
672 692 self.SUB_EXP_CODE = None
673 693 self.PLOT_POS = None
674 694
675 695 def getSubplots(self):
676 696
677 697 ncol = int(numpy.sqrt(self.nplots)+0.9)
678 698 nrow = int(self.nplots*1./ncol + 0.9)
679 699
680 700 return nrow, ncol
681 701
682 702 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
683 703
684 704 self.__showprofile = showprofile
685 705 self.nplots = nplots
686 706
687 707 ncolspan = 1
688 708 colspan = 1
689 709 if showprofile:
690 710 ncolspan = 3
691 711 colspan = 2
692 712 self.__nsubplots = 2
693 713
694 714 self.createFigure(id = id,
695 715 wintitle = wintitle,
696 716 widthplot = self.WIDTH + self.WIDTHPROF,
697 717 heightplot = self.HEIGHT + self.HEIGHTPROF,
698 718 show=show)
699 719
700 720 nrow, ncol = self.getSubplots()
701 721
702 722 counter = 0
703 723 for y in range(nrow):
704 724 for x in range(ncol):
705 725
706 726 if counter >= self.nplots:
707 727 break
708 728
709 729 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
710 730
711 731 if showprofile:
712 732 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
713 733
714 734 counter += 1
715 735
716 736 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
717 737 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
718 738 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
719 739 server=None, folder=None, username=None, password=None,
720 740 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
721 741
722 742 """
723 743
724 744 Input:
725 745 dataOut :
726 746 id :
727 747 wintitle :
728 748 channelList :
729 749 showProfile :
730 750 xmin : None,
731 751 xmax : None,
732 752 ymin : None,
733 753 ymax : None,
734 754 zmin : None,
735 755 zmax : None
736 756 """
737 757
738 758 if realtime:
739 759 if not(isRealtime(utcdatatime = dataOut.utctime)):
740 760 print 'Skipping this plot function'
741 761 return
742 762
743 763 if channelList == None:
744 764 channelIndexList = dataOut.channelIndexList
745 765 else:
746 766 channelIndexList = []
747 767 for channel in channelList:
748 768 if channel not in dataOut.channelList:
749 769 raise ValueError, "Channel %d is not in dataOut.channelList"
750 770 channelIndexList.append(dataOut.channelList.index(channel))
751 771 factor = dataOut.normFactor
752 772 x = dataOut.getVelRange(1)
753 773 y = dataOut.getHeiRange()
754 774
755 775 z = dataOut.data_spc[channelIndexList,:,:]/factor
756 776 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
757 777 avg = numpy.average(z, axis=1)
758 778 noise = dataOut.getNoise()/factor
759 779
760 780 zdB = 10*numpy.log10(z)
761 781 avgdB = 10*numpy.log10(avg)
762 782 noisedB = 10*numpy.log10(noise)
763 783
764 784 #thisDatetime = dataOut.datatime
765 785 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
766 786 title = wintitle + " Spectra"
767 787 xlabel = "Velocity (m/s)"
768 788 ylabel = "Range (Km)"
769 789
770 790 if not self.__isConfig:
771 791
772 792 nplots = len(channelIndexList)
773 793
774 794 self.setup(id=id,
775 795 nplots=nplots,
776 796 wintitle=wintitle,
777 797 showprofile=showprofile,
778 798 show=show)
779 799
780 800 if xmin == None: xmin = numpy.nanmin(x)
781 801 if xmax == None: xmax = numpy.nanmax(x)
782 802 if ymin == None: ymin = numpy.nanmin(y)
783 803 if ymax == None: ymax = numpy.nanmax(y)
784 804 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
785 805 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
786 806
787 807 self.FTP_WEI = ftp_wei
788 808 self.EXP_CODE = exp_code
789 809 self.SUB_EXP_CODE = sub_exp_code
790 810 self.PLOT_POS = plot_pos
791 811
792 812 self.__isConfig = True
793 813
794 814 self.setWinTitle(title)
795 815
796 816 for i in range(self.nplots):
797 817 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
798 818 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
799 819 axes = self.axesList[i*self.__nsubplots]
800 820 axes.pcolor(x, y, zdB[i,:,:],
801 821 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
802 822 xlabel=xlabel, ylabel=ylabel, title=title,
803 823 ticksize=9, cblabel='')
804 824
805 825 if self.__showprofile:
806 826 axes = self.axesList[i*self.__nsubplots +1]
807 827 axes.pline(avgdB[i], y,
808 828 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
809 829 xlabel='dB', ylabel='', title='',
810 830 ytick_visible=False,
811 831 grid='x')
812 832
813 833 noiseline = numpy.repeat(noisedB[i], len(y))
814 834 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
815 835
816 836 self.draw()
817 837
818 838 if save:
819 839
820 840 self.counter_imagwr += 1
821 841 if (self.counter_imagwr==wr_period):
822 842 if figfile == None:
823 843 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
824 844 figfile = self.getFilename(name = str_datetime)
825 845
826 846 self.saveFigure(figpath, figfile)
827 847
828 848 if ftp:
829 849 #provisionalmente envia archivos en el formato de la web en tiempo real
830 850 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
831 851 path = '%s%03d' %(self.PREFIX, self.id)
832 852 ftp_file = os.path.join(path,'ftp','%s.png'%name)
833 853 self.saveFigure(figpath, ftp_file)
834 854 ftp_filename = os.path.join(figpath,ftp_file)
835 855 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
836 856 self.counter_imagwr = 0
837 857
838 858
839 859 self.counter_imagwr = 0
840 860
841 861
842 862 class Scope(Figure):
843 863
844 864 __isConfig = None
845 865
846 866 def __init__(self):
847 867
848 868 self.__isConfig = False
849 869 self.WIDTH = 600
850 870 self.HEIGHT = 200
851 871 self.counter_imagwr = 0
852 872
853 873 def getSubplots(self):
854 874
855 875 nrow = self.nplots
856 876 ncol = 3
857 877 return nrow, ncol
858 878
859 879 def setup(self, id, nplots, wintitle, show):
860 880
861 881 self.nplots = nplots
862 882
863 883 self.createFigure(id=id,
864 884 wintitle=wintitle,
865 885 show=show)
866 886
867 887 nrow,ncol = self.getSubplots()
868 888 colspan = 3
869 889 rowspan = 1
870 890
871 891 for i in range(nplots):
872 892 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
873 893
874 894
875 895
876 896 def run(self, dataOut, id, wintitle="", channelList=None,
877 897 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
878 898 figpath='./', figfile=None, show=True, wr_period=1,
879 899 server=None, folder=None, username=None, password=None):
880 900
881 901 """
882 902
883 903 Input:
884 904 dataOut :
885 905 id :
886 906 wintitle :
887 907 channelList :
888 908 xmin : None,
889 909 xmax : None,
890 910 ymin : None,
891 911 ymax : None,
892 912 """
893 913
894 914 if channelList == None:
895 915 channelIndexList = dataOut.channelIndexList
896 916 else:
897 917 channelIndexList = []
898 918 for channel in channelList:
899 919 if channel not in dataOut.channelList:
900 920 raise ValueError, "Channel %d is not in dataOut.channelList"
901 921 channelIndexList.append(dataOut.channelList.index(channel))
902 922
903 923 x = dataOut.heightList
904 924 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
905 925 y = y.real
906 926
907 927 #thisDatetime = dataOut.datatime
908 928 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
909 929 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
910 930 xlabel = "Range (Km)"
911 931 ylabel = "Intensity"
912 932
913 933 if not self.__isConfig:
914 934 nplots = len(channelIndexList)
915 935
916 936 self.setup(id=id,
917 937 nplots=nplots,
918 938 wintitle=wintitle,
919 939 show=show)
920 940
921 941 if xmin == None: xmin = numpy.nanmin(x)
922 942 if xmax == None: xmax = numpy.nanmax(x)
923 943 if ymin == None: ymin = numpy.nanmin(y)
924 944 if ymax == None: ymax = numpy.nanmax(y)
925 945
926 946 self.__isConfig = True
927 947
928 948 self.setWinTitle(title)
929 949
930 950 for i in range(len(self.axesList)):
931 951 title = "Channel %d" %(i)
932 952 axes = self.axesList[i]
933 953 ychannel = y[i,:]
934 954 axes.pline(x, ychannel,
935 955 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
936 956 xlabel=xlabel, ylabel=ylabel, title=title)
937 957
938 958 self.draw()
939 959
940 960 if save:
941 961 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
942 962 if figfile == None:
943 963 figfile = self.getFilename(name = date)
944 964
945 965 self.saveFigure(figpath, figfile)
946 966
947 967 self.counter_imagwr += 1
948 968 if (ftp and (self.counter_imagwr==wr_period)):
949 969 ftp_filename = os.path.join(figpath,figfile)
950 970 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
951 971 self.counter_imagwr = 0
952 972
953 973 class PowerProfilePlot(Figure):
954 974 __isConfig = None
955 975 __nsubplots = None
956 976
957 977 WIDTHPROF = None
958 978 HEIGHTPROF = None
959 979 PREFIX = 'spcprofile'
960 980
961 981 def __init__(self):
962 982 self.__isConfig = False
963 983 self.__nsubplots = 1
964 984
965 985 self.WIDTH = 300
966 986 self.HEIGHT = 500
967 987 self.counter_imagwr = 0
968 988
969 989 def getSubplots(self):
970 990 ncol = 1
971 991 nrow = 1
972 992
973 993 return nrow, ncol
974 994
975 995 def setup(self, id, nplots, wintitle, show):
976 996
977 997 self.nplots = nplots
978 998
979 999 ncolspan = 1
980 1000 colspan = 1
981 1001
982 1002 self.createFigure(id = id,
983 1003 wintitle = wintitle,
984 1004 widthplot = self.WIDTH,
985 1005 heightplot = self.HEIGHT,
986 1006 show=show)
987 1007
988 1008 nrow, ncol = self.getSubplots()
989 1009
990 1010 counter = 0
991 1011 for y in range(nrow):
992 1012 for x in range(ncol):
993 1013 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
994 1014
995 1015 def run(self, dataOut, id, wintitle="", channelList=None,
996 1016 xmin=None, xmax=None, ymin=None, ymax=None,
997 1017 save=False, figpath='./', figfile=None, show=True, wr_period=1,
998 1018 server=None, folder=None, username=None, password=None,):
999 1019
1000 1020 if channelList == None:
1001 1021 channelIndexList = dataOut.channelIndexList
1002 1022 channelList = dataOut.channelList
1003 1023 else:
1004 1024 channelIndexList = []
1005 1025 for channel in channelList:
1006 1026 if channel not in dataOut.channelList:
1007 1027 raise ValueError, "Channel %d is not in dataOut.channelList"
1008 1028 channelIndexList.append(dataOut.channelList.index(channel))
1009 1029
1010 1030 factor = dataOut.normFactor
1011 1031 y = dataOut.getHeiRange()
1012 1032 x = dataOut.data_spc[channelIndexList,:,:]/factor
1013 1033 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
1014 1034 avg = numpy.average(x, axis=1)
1015 1035
1016 1036 avgdB = 10*numpy.log10(avg)
1017 1037
1018 1038 #thisDatetime = dataOut.datatime
1019 1039 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1020 1040 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
1021 1041 xlabel = "dB"
1022 1042 ylabel = "Range (Km)"
1023 1043
1024 1044 if not self.__isConfig:
1025 1045
1026 1046 nplots = 1
1027 1047
1028 1048 self.setup(id=id,
1029 1049 nplots=nplots,
1030 1050 wintitle=wintitle,
1031 1051 show=show)
1032 1052
1033 1053 if ymin == None: ymin = numpy.nanmin(y)
1034 1054 if ymax == None: ymax = numpy.nanmax(y)
1035 1055 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
1036 1056 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
1037 1057
1038 1058 self.__isConfig = True
1039 1059
1040 1060 self.setWinTitle(title)
1041 1061
1042 1062
1043 1063 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1044 1064 axes = self.axesList[0]
1045 1065
1046 1066 legendlabels = ["channel %d"%x for x in channelList]
1047 1067 axes.pmultiline(avgdB, y,
1048 1068 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1049 1069 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1050 1070 ytick_visible=True, nxticks=5,
1051 1071 grid='x')
1052 1072
1053 1073 self.draw()
1054 1074
1055 1075 if save:
1056 1076 date = thisDatetime.strftime("%Y%m%d")
1057 1077 if figfile == None:
1058 1078 figfile = self.getFilename(name = date)
1059 1079
1060 1080 self.saveFigure(figpath, figfile)
1061 1081
1062 1082 self.counter_imagwr += 1
1063 1083 if (ftp and (self.counter_imagwr==wr_period)):
1064 1084 ftp_filename = os.path.join(figpath,figfile)
1065 1085 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1066 1086 self.counter_imagwr = 0
1067 1087
1068 1088 class CoherenceMap(Figure):
1069 1089 __isConfig = None
1070 1090 __nsubplots = None
1071 1091
1072 1092 WIDTHPROF = None
1073 1093 HEIGHTPROF = None
1074 1094 PREFIX = 'cmap'
1075 1095
1076 1096 def __init__(self):
1077 1097 self.timerange = 2*60*60
1078 1098 self.__isConfig = False
1079 1099 self.__nsubplots = 1
1080 1100
1081 1101 self.WIDTH = 800
1082 1102 self.HEIGHT = 150
1083 1103 self.WIDTHPROF = 120
1084 1104 self.HEIGHTPROF = 0
1085 1105 self.counter_imagwr = 0
1086 1106
1087 1107 self.PLOT_CODE = 3
1088 1108 self.FTP_WEI = None
1089 1109 self.EXP_CODE = None
1090 1110 self.SUB_EXP_CODE = None
1091 1111 self.PLOT_POS = None
1092 1112 self.counter_imagwr = 0
1113
1114 self.xmin = None
1115 self.xmax = None
1093 1116
1094 1117 def getSubplots(self):
1095 1118 ncol = 1
1096 1119 nrow = self.nplots*2
1097 1120
1098 1121 return nrow, ncol
1099 1122
1100 1123 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1101 1124 self.__showprofile = showprofile
1102 1125 self.nplots = nplots
1103 1126
1104 1127 ncolspan = 1
1105 1128 colspan = 1
1106 1129 if showprofile:
1107 1130 ncolspan = 7
1108 1131 colspan = 6
1109 1132 self.__nsubplots = 2
1110 1133
1111 1134 self.createFigure(id = id,
1112 1135 wintitle = wintitle,
1113 1136 widthplot = self.WIDTH + self.WIDTHPROF,
1114 1137 heightplot = self.HEIGHT + self.HEIGHTPROF,
1115 1138 show=True)
1116 1139
1117 1140 nrow, ncol = self.getSubplots()
1118 1141
1119 1142 for y in range(nrow):
1120 1143 for x in range(ncol):
1121 1144
1122 1145 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1123 1146
1124 1147 if showprofile:
1125 1148 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1126 1149
1127 1150 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1128 1151 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1129 1152 timerange=None,
1130 1153 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
1131 1154 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
1132 1155 server=None, folder=None, username=None, password=None,
1133 1156 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1134 1157
1135 1158 if pairsList == None:
1136 1159 pairsIndexList = dataOut.pairsIndexList
1137 1160 else:
1138 1161 pairsIndexList = []
1139 1162 for pair in pairsList:
1140 1163 if pair not in dataOut.pairsList:
1141 1164 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1142 1165 pairsIndexList.append(dataOut.pairsList.index(pair))
1143 1166
1144 1167 if timerange != None:
1145 1168 self.timerange = timerange
1146 1169
1147 1170 if pairsIndexList == []:
1148 1171 return
1149 1172
1150 1173 if len(pairsIndexList) > 4:
1151 1174 pairsIndexList = pairsIndexList[0:4]
1152 1175
1153 tmin = None
1154 tmax = None
1176 # tmin = None
1177 # tmax = None
1155 1178 x = dataOut.getTimeRange()
1156 1179 y = dataOut.getHeiRange()
1157 1180
1158 1181 #thisDatetime = dataOut.datatime
1159 1182 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1160 1183 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1161 1184 xlabel = ""
1162 1185 ylabel = "Range (Km)"
1163 1186
1164 1187 if not self.__isConfig:
1165 1188 nplots = len(pairsIndexList)
1166 1189 self.setup(id=id,
1167 1190 nplots=nplots,
1168 1191 wintitle=wintitle,
1169 1192 showprofile=showprofile,
1170 1193 show=show)
1171 1194
1172 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1195 #tmin, tmax = self.getTimeLim(x, xmin, xmax)
1196
1197 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1198
1173 1199 if ymin == None: ymin = numpy.nanmin(y)
1174 1200 if ymax == None: ymax = numpy.nanmax(y)
1175 1201 if zmin == None: zmin = 0.
1176 1202 if zmax == None: zmax = 1.
1177 1203
1178 1204 self.FTP_WEI = ftp_wei
1179 1205 self.EXP_CODE = exp_code
1180 1206 self.SUB_EXP_CODE = sub_exp_code
1181 1207 self.PLOT_POS = plot_pos
1182 1208
1183 1209 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1184 1210
1185 1211 self.__isConfig = True
1186 1212
1187 1213 self.setWinTitle(title)
1188 1214
1215 if ((self.xmax - x[1]) < (x[1]-x[0])):
1216 x[1] = self.xmax
1217
1189 1218 for i in range(self.nplots):
1190 1219
1191 1220 pair = dataOut.pairsList[pairsIndexList[i]]
1192 1221 # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
1193 1222 # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
1194 1223 # coherence = numpy.abs(avgcoherenceComplex)
1195 1224
1196 1225 ## coherence = numpy.abs(coherenceComplex)
1197 1226 ## avg = numpy.average(coherence, axis=0)
1198 1227
1199 1228 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
1200 1229 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
1201 1230 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
1202 1231
1203 1232
1204 1233 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1205 1234 coherence = numpy.abs(avgcoherenceComplex)
1206 1235
1207 1236 z = coherence.reshape((1,-1))
1208 1237
1209 1238 counter = 0
1210 1239
1211 1240 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1212 1241 axes = self.axesList[i*self.__nsubplots*2]
1213 1242 axes.pcolorbuffer(x, y, z,
1214 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1243 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1215 1244 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1216 1245 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
1217 1246
1218 1247 if self.__showprofile:
1219 1248 counter += 1
1220 1249 axes = self.axesList[i*self.__nsubplots*2 + counter]
1221 1250 axes.pline(coherence, y,
1222 1251 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
1223 1252 xlabel='', ylabel='', title='', ticksize=7,
1224 1253 ytick_visible=False, nxticks=5,
1225 1254 grid='x')
1226 1255
1227 1256 counter += 1
1228 1257 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
1229 1258 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1230 1259 # avg = numpy.average(phase, axis=0)
1231 1260 z = phase.reshape((1,-1))
1232 1261
1233 1262 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1234 1263 axes = self.axesList[i*self.__nsubplots*2 + counter]
1235 1264 axes.pcolorbuffer(x, y, z,
1236 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
1265 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
1237 1266 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1238 1267 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
1239 1268
1240 1269 if self.__showprofile:
1241 1270 counter += 1
1242 1271 axes = self.axesList[i*self.__nsubplots*2 + counter]
1243 1272 axes.pline(phase, y,
1244 1273 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
1245 1274 xlabel='', ylabel='', title='', ticksize=7,
1246 1275 ytick_visible=False, nxticks=4,
1247 1276 grid='x')
1248 1277
1249 1278 self.draw()
1250 1279
1251 if save:
1252
1253 self.counter_imagwr += 1
1254 if (self.counter_imagwr==wr_period):
1255 if figfile == None:
1256 figfile = self.getFilename(name = self.name)
1257 self.saveFigure(figpath, figfile)
1258
1259 if ftp:
1260 #provisionalmente envia archivos en el formato de la web en tiempo real
1261 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1262 path = '%s%03d' %(self.PREFIX, self.id)
1263 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1264 self.saveFigure(figpath, ftp_file)
1265 ftp_filename = os.path.join(figpath,ftp_file)
1266 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1267 self.counter_imagwr = 0
1268
1269 self.counter_imagwr = 0
1270
1271
1272 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1280 if x[1] >= self.axesList[0].xmax:
1281 self.saveFigure(figpath, figfile)
1273 1282 self.__isConfig = False
1283
1284 # if save:
1285 #
1286 # self.counter_imagwr += 1
1287 # if (self.counter_imagwr==wr_period):
1288 # if figfile == None:
1289 # figfile = self.getFilename(name = self.name)
1290 # self.saveFigure(figpath, figfile)
1291 #
1292 # if ftp:
1293 # #provisionalmente envia archivos en el formato de la web en tiempo real
1294 # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1295 # path = '%s%03d' %(self.PREFIX, self.id)
1296 # ftp_file = os.path.join(path,'ftp','%s.png'%name)
1297 # self.saveFigure(figpath, ftp_file)
1298 # ftp_filename = os.path.join(figpath,ftp_file)
1299 # self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1300 # self.counter_imagwr = 0
1301 #
1302 # self.counter_imagwr = 0
1303 #
1304 #
1305 # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1306 # self.__isConfig = False
1274 1307
1275 1308 class BeaconPhase(Figure):
1276 1309
1277 1310 __isConfig = None
1278 1311 __nsubplots = None
1279 1312
1280 1313 PREFIX = 'beacon_phase'
1281 1314
1282 1315 def __init__(self):
1283 1316
1284 1317 self.timerange = 24*60*60
1285 1318 self.__isConfig = False
1286 1319 self.__nsubplots = 1
1287 1320 self.counter_imagwr = 0
1288 1321 self.WIDTH = 600
1289 1322 self.HEIGHT = 300
1290 1323 self.WIDTHPROF = 120
1291 1324 self.HEIGHTPROF = 0
1292 1325 self.xdata = None
1293 1326 self.ydata = None
1294 1327
1295 1328 self.PLOT_CODE = 18
1296 1329 self.FTP_WEI = None
1297 1330 self.EXP_CODE = None
1298 1331 self.SUB_EXP_CODE = None
1299 1332 self.PLOT_POS = None
1300 1333
1301 1334 self.filename_phase = None
1302 1335
1303 1336 def getSubplots(self):
1304 1337
1305 1338 ncol = 1
1306 1339 nrow = 1
1307 1340
1308 1341 return nrow, ncol
1309 1342
1310 1343 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1311 1344
1312 1345 self.__showprofile = showprofile
1313 1346 self.nplots = nplots
1314 1347
1315 1348 ncolspan = 7
1316 1349 colspan = 6
1317 1350 self.__nsubplots = 2
1318 1351
1319 1352 self.createFigure(id = id,
1320 1353 wintitle = wintitle,
1321 1354 widthplot = self.WIDTH+self.WIDTHPROF,
1322 1355 heightplot = self.HEIGHT+self.HEIGHTPROF,
1323 1356 show=show)
1324 1357
1325 1358 nrow, ncol = self.getSubplots()
1326 1359
1327 1360 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1328 1361
1329 1362 def save_phase(self, filename_phase):
1330 1363 f = open(filename_phase,'w+')
1331 1364 f.write('\n\n')
1332 1365 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1333 1366 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1334 1367 f.close()
1335 1368
1336 1369 def save_data(self, filename_phase, data, data_datetime):
1337 1370 f=open(filename_phase,'a')
1338 1371 timetuple_data = data_datetime.timetuple()
1339 1372 day = str(timetuple_data.tm_mday)
1340 1373 month = str(timetuple_data.tm_mon)
1341 1374 year = str(timetuple_data.tm_year)
1342 1375 hour = str(timetuple_data.tm_hour)
1343 1376 minute = str(timetuple_data.tm_min)
1344 1377 second = str(timetuple_data.tm_sec)
1345 1378 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1346 1379 f.close()
1347 1380
1348 1381
1349 1382 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1350 1383 xmin=None, xmax=None, ymin=None, ymax=None,
1351 1384 timerange=None,
1352 1385 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1353 1386 server=None, folder=None, username=None, password=None,
1354 1387 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1355 1388
1356 1389 if pairsList == None:
1357 1390 pairsIndexList = dataOut.pairsIndexList
1358 1391 else:
1359 1392 pairsIndexList = []
1360 1393 for pair in pairsList:
1361 1394 if pair not in dataOut.pairsList:
1362 1395 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1363 1396 pairsIndexList.append(dataOut.pairsList.index(pair))
1364 1397
1365 1398 if pairsIndexList == []:
1366 1399 return
1367 1400
1368 1401 # if len(pairsIndexList) > 4:
1369 1402 # pairsIndexList = pairsIndexList[0:4]
1370 1403
1371 1404 if timerange != None:
1372 1405 self.timerange = timerange
1373 1406
1374 1407 tmin = None
1375 1408 tmax = None
1376 1409 x = dataOut.getTimeRange()
1377 1410 y = dataOut.getHeiRange()
1378 1411
1379 1412
1380 1413 #thisDatetime = dataOut.datatime
1381 1414 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1382 1415 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1383 1416 xlabel = "Local Time"
1384 1417 ylabel = "Phase"
1385 1418
1386 1419 nplots = len(pairsIndexList)
1387 1420 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1388 1421 phase_beacon = numpy.zeros(len(pairsIndexList))
1389 1422 for i in range(nplots):
1390 1423 pair = dataOut.pairsList[pairsIndexList[i]]
1391 1424 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
1392 1425 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
1393 1426 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
1394 1427 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1395 1428 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1396 1429
1397 1430 #print "Phase %d%d" %(pair[0], pair[1])
1398 1431 #print phase[dataOut.beacon_heiIndexList]
1399 1432
1400 1433 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1401 1434
1402 1435 if not self.__isConfig:
1403 1436
1404 1437 nplots = len(pairsIndexList)
1405 1438
1406 1439 self.setup(id=id,
1407 1440 nplots=nplots,
1408 1441 wintitle=wintitle,
1409 1442 showprofile=showprofile,
1410 1443 show=show)
1411 1444
1412 1445 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1413 1446 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1414 1447 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1415 1448
1416 1449 self.FTP_WEI = ftp_wei
1417 1450 self.EXP_CODE = exp_code
1418 1451 self.SUB_EXP_CODE = sub_exp_code
1419 1452 self.PLOT_POS = plot_pos
1420 1453
1421 1454 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1422 1455 self.__isConfig = True
1423 1456
1424 1457 self.xdata = numpy.array([])
1425 1458 self.ydata = numpy.array([])
1426 1459
1427 1460 #open file beacon phase
1428 1461 path = '%s%03d' %(self.PREFIX, self.id)
1429 1462 beacon_file = os.path.join(path,'%s.txt'%self.name)
1430 1463 self.filename_phase = os.path.join(figpath,beacon_file)
1431 self.save_phase(self.filename_phase)
1464 #self.save_phase(self.filename_phase)
1432 1465
1433 1466
1434 1467 #store data beacon phase
1435 self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1468 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1436 1469
1437 1470 self.setWinTitle(title)
1438 1471
1439 1472
1440 1473 title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1441 1474
1442 1475 legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1443 1476
1444 1477 axes = self.axesList[0]
1445 1478
1446 1479 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1447 1480
1448 1481 if len(self.ydata)==0:
1449 1482 self.ydata = phase_beacon.reshape(-1,1)
1450 1483 else:
1451 1484 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1452 1485
1453 1486
1454 1487 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1455 1488 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1456 1489 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1457 1490 XAxisAsTime=True, grid='both'
1458 1491 )
1459 1492
1460 1493 self.draw()
1461 1494
1462 1495 if save:
1463 1496
1464 1497 self.counter_imagwr += 1
1465 1498 if (self.counter_imagwr==wr_period):
1466 1499 if figfile == None:
1467 1500 figfile = self.getFilename(name = self.name)
1468 1501 self.saveFigure(figpath, figfile)
1469 1502
1470 1503 if ftp:
1471 1504 #provisionalmente envia archivos en el formato de la web en tiempo real
1472 1505 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1473 1506 path = '%s%03d' %(self.PREFIX, self.id)
1474 1507 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1475 1508 self.saveFigure(figpath, ftp_file)
1476 1509 ftp_filename = os.path.join(figpath,ftp_file)
1477 1510 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1478 1511
1479 1512 self.counter_imagwr = 0
1480 1513
1481 1514 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1482 1515 self.__isConfig = False
1483 1516 del self.xdata
1484 1517 del self.ydata
1485 1518
1486 1519
1487 1520
1488 1521
1489 1522 class Noise(Figure):
1490 1523
1491 1524 __isConfig = None
1492 1525 __nsubplots = None
1493 1526
1494 1527 PREFIX = 'noise'
1495 1528
1496 1529 def __init__(self):
1497 1530
1498 1531 self.timerange = 24*60*60
1499 1532 self.__isConfig = False
1500 1533 self.__nsubplots = 1
1501 1534 self.counter_imagwr = 0
1502 1535 self.WIDTH = 600
1503 1536 self.HEIGHT = 300
1504 1537 self.WIDTHPROF = 120
1505 1538 self.HEIGHTPROF = 0
1506 1539 self.xdata = None
1507 1540 self.ydata = None
1508 1541
1509 1542 self.PLOT_CODE = 77
1510 1543 self.FTP_WEI = None
1511 1544 self.EXP_CODE = None
1512 1545 self.SUB_EXP_CODE = None
1513 1546 self.PLOT_POS = None
1514 1547
1515 1548 def getSubplots(self):
1516 1549
1517 1550 ncol = 1
1518 1551 nrow = 1
1519 1552
1520 1553 return nrow, ncol
1521 1554
1522 1555 def openfile(self, filename):
1523 1556 f = open(filename,'w+')
1524 1557 f.write('\n\n')
1525 1558 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1526 1559 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1527 1560 f.close()
1528 1561
1529 1562 def save_data(self, filename_phase, data, data_datetime):
1530 1563 f=open(filename_phase,'a')
1531 1564 timetuple_data = data_datetime.timetuple()
1532 1565 day = str(timetuple_data.tm_mday)
1533 1566 month = str(timetuple_data.tm_mon)
1534 1567 year = str(timetuple_data.tm_year)
1535 1568 hour = str(timetuple_data.tm_hour)
1536 1569 minute = str(timetuple_data.tm_min)
1537 1570 second = str(timetuple_data.tm_sec)
1538 1571 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1539 1572 f.close()
1540 1573
1541 1574
1542 1575 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1543 1576
1544 1577 self.__showprofile = showprofile
1545 1578 self.nplots = nplots
1546 1579
1547 1580 ncolspan = 7
1548 1581 colspan = 6
1549 1582 self.__nsubplots = 2
1550 1583
1551 1584 self.createFigure(id = id,
1552 1585 wintitle = wintitle,
1553 1586 widthplot = self.WIDTH+self.WIDTHPROF,
1554 1587 heightplot = self.HEIGHT+self.HEIGHTPROF,
1555 1588 show=show)
1556 1589
1557 1590 nrow, ncol = self.getSubplots()
1558 1591
1559 1592 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1560 1593
1561 1594
1562 1595 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1563 1596 xmin=None, xmax=None, ymin=None, ymax=None,
1564 1597 timerange=None,
1565 1598 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1566 1599 server=None, folder=None, username=None, password=None,
1567 1600 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1568 1601
1569 1602 if channelList == None:
1570 1603 channelIndexList = dataOut.channelIndexList
1571 1604 channelList = dataOut.channelList
1572 1605 else:
1573 1606 channelIndexList = []
1574 1607 for channel in channelList:
1575 1608 if channel not in dataOut.channelList:
1576 1609 raise ValueError, "Channel %d is not in dataOut.channelList"
1577 1610 channelIndexList.append(dataOut.channelList.index(channel))
1578 1611
1579 1612 if timerange != None:
1580 1613 self.timerange = timerange
1581 1614
1582 1615 tmin = None
1583 1616 tmax = None
1584 1617 x = dataOut.getTimeRange()
1585 1618 y = dataOut.getHeiRange()
1586 1619 factor = dataOut.normFactor
1587 1620 noise = dataOut.getNoise()/factor
1588 1621 noisedB = 10*numpy.log10(noise)
1589 1622
1590 1623 #thisDatetime = dataOut.datatime
1591 1624 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1592 1625 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1593 1626 xlabel = ""
1594 1627 ylabel = "Intensity (dB)"
1595 1628
1596 1629 if not self.__isConfig:
1597 1630
1598 1631 nplots = 1
1599 1632
1600 1633 self.setup(id=id,
1601 1634 nplots=nplots,
1602 1635 wintitle=wintitle,
1603 1636 showprofile=showprofile,
1604 1637 show=show)
1605 1638
1606 1639 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1607 1640 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1608 1641 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1609 1642
1610 1643 self.FTP_WEI = ftp_wei
1611 1644 self.EXP_CODE = exp_code
1612 1645 self.SUB_EXP_CODE = sub_exp_code
1613 1646 self.PLOT_POS = plot_pos
1614 1647
1615 1648
1616 1649 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1617 1650 self.__isConfig = True
1618 1651
1619 1652 self.xdata = numpy.array([])
1620 1653 self.ydata = numpy.array([])
1621 1654
1622 1655 #open file beacon phase
1623 1656 path = '%s%03d' %(self.PREFIX, self.id)
1624 1657 noise_file = os.path.join(path,'%s.txt'%self.name)
1625 1658 self.filename_noise = os.path.join(figpath,noise_file)
1626 1659 self.openfile(self.filename_noise)
1627 1660
1628 1661
1629 1662 #store data beacon phase
1630 1663 self.save_data(self.filename_noise, noisedB, thisDatetime)
1631 1664
1632 1665
1633 1666 self.setWinTitle(title)
1634 1667
1635 1668
1636 1669 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1637 1670
1638 1671 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1639 1672 axes = self.axesList[0]
1640 1673
1641 1674 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1642 1675
1643 1676 if len(self.ydata)==0:
1644 1677 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1645 1678 else:
1646 1679 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1647 1680
1648 1681
1649 1682 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1650 1683 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1651 1684 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1652 1685 XAxisAsTime=True, grid='both'
1653 1686 )
1654 1687
1655 1688 self.draw()
1656 1689
1657 1690 # if save:
1658 1691 #
1659 1692 # if figfile == None:
1660 1693 # figfile = self.getFilename(name = self.name)
1661 1694 #
1662 1695 # self.saveFigure(figpath, figfile)
1663 1696
1664 1697 if save:
1665 1698
1666 1699 self.counter_imagwr += 1
1667 1700 if (self.counter_imagwr==wr_period):
1668 1701 if figfile == None:
1669 1702 figfile = self.getFilename(name = self.name)
1670 1703 self.saveFigure(figpath, figfile)
1671 1704
1672 1705 if ftp:
1673 1706 #provisionalmente envia archivos en el formato de la web en tiempo real
1674 1707 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1675 1708 path = '%s%03d' %(self.PREFIX, self.id)
1676 1709 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1677 1710 self.saveFigure(figpath, ftp_file)
1678 1711 ftp_filename = os.path.join(figpath,ftp_file)
1679 1712 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1680 1713 self.counter_imagwr = 0
1681 1714
1682 1715 self.counter_imagwr = 0
1683 1716
1684 1717 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1685 1718 self.__isConfig = False
1686 1719 del self.xdata
1687 1720 del self.ydata
1688 1721
1689 1722
1690 1723 class SpectraHeisScope(Figure):
1691 1724
1692 1725
1693 1726 __isConfig = None
1694 1727 __nsubplots = None
1695 1728
1696 1729 WIDTHPROF = None
1697 1730 HEIGHTPROF = None
1698 1731 PREFIX = 'spc'
1699 1732
1700 1733 def __init__(self):
1701 1734
1702 1735 self.__isConfig = False
1703 1736 self.__nsubplots = 1
1704 1737
1705 1738 self.WIDTH = 230
1706 1739 self.HEIGHT = 250
1707 1740 self.WIDTHPROF = 120
1708 1741 self.HEIGHTPROF = 0
1709 1742 self.counter_imagwr = 0
1710 1743
1711 1744 def getSubplots(self):
1712 1745
1713 1746 ncol = int(numpy.sqrt(self.nplots)+0.9)
1714 1747 nrow = int(self.nplots*1./ncol + 0.9)
1715 1748
1716 1749 return nrow, ncol
1717 1750
1718 1751 def setup(self, id, nplots, wintitle, show):
1719 1752
1720 1753 showprofile = False
1721 1754 self.__showprofile = showprofile
1722 1755 self.nplots = nplots
1723 1756
1724 1757 ncolspan = 1
1725 1758 colspan = 1
1726 1759 if showprofile:
1727 1760 ncolspan = 3
1728 1761 colspan = 2
1729 1762 self.__nsubplots = 2
1730 1763
1731 1764 self.createFigure(id = id,
1732 1765 wintitle = wintitle,
1733 1766 widthplot = self.WIDTH + self.WIDTHPROF,
1734 1767 heightplot = self.HEIGHT + self.HEIGHTPROF,
1735 1768 show = show)
1736 1769
1737 1770 nrow, ncol = self.getSubplots()
1738 1771
1739 1772 counter = 0
1740 1773 for y in range(nrow):
1741 1774 for x in range(ncol):
1742 1775
1743 1776 if counter >= self.nplots:
1744 1777 break
1745 1778
1746 1779 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1747 1780
1748 1781 if showprofile:
1749 1782 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1750 1783
1751 1784 counter += 1
1752 1785
1753 1786
1754 1787 def run(self, dataOut, id, wintitle="", channelList=None,
1755 1788 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1756 1789 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
1757 1790 server=None, folder=None, username=None, password=None):
1758 1791
1759 1792 """
1760 1793
1761 1794 Input:
1762 1795 dataOut :
1763 1796 id :
1764 1797 wintitle :
1765 1798 channelList :
1766 1799 xmin : None,
1767 1800 xmax : None,
1768 1801 ymin : None,
1769 1802 ymax : None,
1770 1803 """
1771 1804
1772 1805 if dataOut.realtime:
1773 1806 if not(isRealtime(utcdatatime = dataOut.utctime)):
1774 1807 print 'Skipping this plot function'
1775 1808 return
1776 1809
1777 1810 if channelList == None:
1778 1811 channelIndexList = dataOut.channelIndexList
1779 1812 else:
1780 1813 channelIndexList = []
1781 1814 for channel in channelList:
1782 1815 if channel not in dataOut.channelList:
1783 1816 raise ValueError, "Channel %d is not in dataOut.channelList"
1784 1817 channelIndexList.append(dataOut.channelList.index(channel))
1785 1818
1786 1819 # x = dataOut.heightList
1787 1820 c = 3E8
1788 1821 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1789 1822 #deberia cambiar para el caso de 1Mhz y 100KHz
1790 1823 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1791 1824 #para 1Mhz descomentar la siguiente linea
1792 1825 #x= x/(10000.0)
1793 1826 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1794 1827 # y = y.real
1795 1828 datadB = 10.*numpy.log10(dataOut.data_spc)
1796 1829 y = datadB
1797 1830
1798 1831 #thisDatetime = dataOut.datatime
1799 1832 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1800 1833 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1801 1834 xlabel = ""
1802 1835 #para 1Mhz descomentar la siguiente linea
1803 1836 #xlabel = "Frequency x 10000"
1804 1837 ylabel = "Intensity (dB)"
1805 1838
1806 1839 if not self.__isConfig:
1807 1840 nplots = len(channelIndexList)
1808 1841
1809 1842 self.setup(id=id,
1810 1843 nplots=nplots,
1811 1844 wintitle=wintitle,
1812 1845 show=show)
1813 1846
1814 1847 if xmin == None: xmin = numpy.nanmin(x)
1815 1848 if xmax == None: xmax = numpy.nanmax(x)
1816 1849 if ymin == None: ymin = numpy.nanmin(y)
1817 1850 if ymax == None: ymax = numpy.nanmax(y)
1818 1851
1819 1852 self.__isConfig = True
1820 1853
1821 1854 self.setWinTitle(title)
1822 1855
1823 1856 for i in range(len(self.axesList)):
1824 1857 ychannel = y[i,:]
1825 1858 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1826 1859 title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime)
1827 1860 axes = self.axesList[i]
1828 1861 axes.pline(x, ychannel,
1829 1862 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1830 1863 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1831 1864
1832 1865
1833 1866 self.draw()
1834 1867
1835 1868 if save:
1836 1869 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1837 1870 if figfile == None:
1838 1871 figfile = self.getFilename(name = date)
1839 1872
1840 1873 self.saveFigure(figpath, figfile)
1841 1874
1842 1875 self.counter_imagwr += 1
1843 1876 if (ftp and (self.counter_imagwr==wr_period)):
1844 1877 ftp_filename = os.path.join(figpath,figfile)
1845 1878 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1846 1879 self.counter_imagwr = 0
1847 1880
1848 1881
1849 1882 class RTIfromSpectraHeis(Figure):
1850 1883
1851 1884 __isConfig = None
1852 1885 __nsubplots = None
1853 1886
1854 1887 PREFIX = 'rtinoise'
1855 1888
1856 1889 def __init__(self):
1857 1890
1858 1891 self.timerange = 24*60*60
1859 1892 self.__isConfig = False
1860 1893 self.__nsubplots = 1
1861 1894
1862 1895 self.WIDTH = 820
1863 1896 self.HEIGHT = 200
1864 1897 self.WIDTHPROF = 120
1865 1898 self.HEIGHTPROF = 0
1866 1899 self.counter_imagwr = 0
1867 1900 self.xdata = None
1868 1901 self.ydata = None
1869 1902
1870 1903 def getSubplots(self):
1871 1904
1872 1905 ncol = 1
1873 1906 nrow = 1
1874 1907
1875 1908 return nrow, ncol
1876 1909
1877 1910 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1878 1911
1879 1912 self.__showprofile = showprofile
1880 1913 self.nplots = nplots
1881 1914
1882 1915 ncolspan = 7
1883 1916 colspan = 6
1884 1917 self.__nsubplots = 2
1885 1918
1886 1919 self.createFigure(id = id,
1887 1920 wintitle = wintitle,
1888 1921 widthplot = self.WIDTH+self.WIDTHPROF,
1889 1922 heightplot = self.HEIGHT+self.HEIGHTPROF,
1890 1923 show = show)
1891 1924
1892 1925 nrow, ncol = self.getSubplots()
1893 1926
1894 1927 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1895 1928
1896 1929
1897 1930 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1898 1931 xmin=None, xmax=None, ymin=None, ymax=None,
1899 1932 timerange=None,
1900 1933 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
1901 1934 server=None, folder=None, username=None, password=None):
1902 1935
1903 1936 if channelList == None:
1904 1937 channelIndexList = dataOut.channelIndexList
1905 1938 channelList = dataOut.channelList
1906 1939 else:
1907 1940 channelIndexList = []
1908 1941 for channel in channelList:
1909 1942 if channel not in dataOut.channelList:
1910 1943 raise ValueError, "Channel %d is not in dataOut.channelList"
1911 1944 channelIndexList.append(dataOut.channelList.index(channel))
1912 1945
1913 1946 if timerange != None:
1914 1947 self.timerange = timerange
1915 1948
1916 1949 tmin = None
1917 1950 tmax = None
1918 1951 x = dataOut.getTimeRange()
1919 1952 y = dataOut.getHeiRange()
1920 1953
1921 1954 #factor = 1
1922 1955 data = dataOut.data_spc#/factor
1923 1956 data = numpy.average(data,axis=1)
1924 1957 datadB = 10*numpy.log10(data)
1925 1958
1926 1959 # factor = dataOut.normFactor
1927 1960 # noise = dataOut.getNoise()/factor
1928 1961 # noisedB = 10*numpy.log10(noise)
1929 1962
1930 1963 #thisDatetime = dataOut.datatime
1931 1964 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1932 1965 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1933 1966 xlabel = "Local Time"
1934 1967 ylabel = "Intensity (dB)"
1935 1968
1936 1969 if not self.__isConfig:
1937 1970
1938 1971 nplots = 1
1939 1972
1940 1973 self.setup(id=id,
1941 1974 nplots=nplots,
1942 1975 wintitle=wintitle,
1943 1976 showprofile=showprofile,
1944 1977 show=show)
1945 1978
1946 1979 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1947 1980 if ymin == None: ymin = numpy.nanmin(datadB)
1948 1981 if ymax == None: ymax = numpy.nanmax(datadB)
1949 1982
1950 1983 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1951 1984 self.__isConfig = True
1952 1985
1953 1986 self.xdata = numpy.array([])
1954 1987 self.ydata = numpy.array([])
1955 1988
1956 1989 self.setWinTitle(title)
1957 1990
1958 1991
1959 1992 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1960 1993 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1961 1994
1962 1995 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1963 1996 axes = self.axesList[0]
1964 1997
1965 1998 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1966 1999
1967 2000 if len(self.ydata)==0:
1968 2001 self.ydata = datadB[channelIndexList].reshape(-1,1)
1969 2002 else:
1970 2003 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1971 2004
1972 2005
1973 2006 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1974 2007 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1975 2008 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1976 2009 XAxisAsTime=True
1977 2010 )
1978 2011
1979 2012 self.draw()
1980 2013
1981 2014 if save:
1982 2015
1983 2016 if figfile == None:
1984 2017 figfile = self.getFilename(name = self.name)
1985 2018
1986 2019 self.saveFigure(figpath, figfile)
1987 2020
1988 2021 self.counter_imagwr += 1
1989 2022 if (ftp and (self.counter_imagwr==wr_period)):
1990 2023 ftp_filename = os.path.join(figpath,figfile)
1991 2024 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1992 2025 self.counter_imagwr = 0
1993 2026
1994 2027 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1995 2028 self.__isConfig = False
1996 2029 del self.xdata
1997 2030 del self.ydata
1998 2031
1999 2032
2000 2033 No newline at end of file
@@ -1,2040 +1,2044
1 1 '''
2 2
3 3 $Author: dsuarez $
4 4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
5 5 '''
6 6 import os
7 7 import numpy
8 8 import datetime
9 9 import time
10 10 import math
11 11 from jrodata import *
12 12 from jrodataIO import *
13 13 from jroplot import *
14 14
15 15 try:
16 16 import cfunctions
17 17 except:
18 18 pass
19 19
20 20 class ProcessingUnit:
21 21
22 22 """
23 23 Esta es la clase base para el procesamiento de datos.
24 24
25 25 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
26 26 - Metodos internos (callMethod)
27 27 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
28 28 tienen que ser agreagados con el metodo "add".
29 29
30 30 """
31 31 # objeto de datos de entrada (Voltage, Spectra o Correlation)
32 32 dataIn = None
33 33
34 34 # objeto de datos de entrada (Voltage, Spectra o Correlation)
35 35 dataOut = None
36 36
37 37
38 38 objectDict = None
39 39
40 40 def __init__(self):
41 41
42 42 self.objectDict = {}
43 43
44 44 def init(self):
45 45
46 46 raise ValueError, "Not implemented"
47 47
48 48 def addOperation(self, object, objId):
49 49
50 50 """
51 51 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
52 52 identificador asociado a este objeto.
53 53
54 54 Input:
55 55
56 56 object : objeto de la clase "Operation"
57 57
58 58 Return:
59 59
60 60 objId : identificador del objeto, necesario para ejecutar la operacion
61 61 """
62 62
63 63 self.objectDict[objId] = object
64 64
65 65 return objId
66 66
67 67 def operation(self, **kwargs):
68 68
69 69 """
70 70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
71 71 atributos del objeto dataOut
72 72
73 73 Input:
74 74
75 75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
76 76 """
77 77
78 78 raise ValueError, "ImplementedError"
79 79
80 80 def callMethod(self, name, **kwargs):
81 81
82 82 """
83 83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
84 84
85 85 Input:
86 86 name : nombre del metodo a ejecutar
87 87
88 88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
89 89
90 90 """
91 91 if name != 'run':
92 92
93 93 if name == 'init' and self.dataIn.isEmpty():
94 94 self.dataOut.flagNoData = True
95 95 return False
96 96
97 97 if name != 'init' and self.dataOut.isEmpty():
98 98 return False
99 99
100 100 methodToCall = getattr(self, name)
101 101
102 102 methodToCall(**kwargs)
103 103
104 104 if name != 'run':
105 105 return True
106 106
107 107 if self.dataOut.isEmpty():
108 108 return False
109 109
110 110 return True
111 111
112 112 def callObject(self, objId, **kwargs):
113 113
114 114 """
115 115 Ejecuta la operacion asociada al identificador del objeto "objId"
116 116
117 117 Input:
118 118
119 119 objId : identificador del objeto a ejecutar
120 120
121 121 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
122 122
123 123 Return:
124 124
125 125 None
126 126 """
127 127
128 128 if self.dataOut.isEmpty():
129 129 return False
130 130
131 131 object = self.objectDict[objId]
132 132
133 133 object.run(self.dataOut, **kwargs)
134 134
135 135 return True
136 136
137 137 def call(self, operationConf, **kwargs):
138 138
139 139 """
140 140 Return True si ejecuta la operacion "operationConf.name" con los
141 141 argumentos "**kwargs". False si la operacion no se ha ejecutado.
142 142 La operacion puede ser de dos tipos:
143 143
144 144 1. Un metodo propio de esta clase:
145 145
146 146 operation.type = "self"
147 147
148 148 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
149 149 operation.type = "other".
150 150
151 151 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
152 152 "addOperation" e identificado con el operation.id
153 153
154 154
155 155 con el id de la operacion.
156 156
157 157 Input:
158 158
159 159 Operation : Objeto del tipo operacion con los atributos: name, type y id.
160 160
161 161 """
162 162
163 163 if operationConf.type == 'self':
164 164 sts = self.callMethod(operationConf.name, **kwargs)
165 165
166 166 if operationConf.type == 'other':
167 167 sts = self.callObject(operationConf.id, **kwargs)
168 168
169 169 return sts
170 170
171 171 def setInput(self, dataIn):
172 172
173 173 self.dataIn = dataIn
174 174
175 175 def getOutput(self):
176 176
177 177 return self.dataOut
178 178
179 179 class Operation():
180 180
181 181 """
182 182 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
183 183 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
184 184 acumulacion dentro de esta clase
185 185
186 186 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
187 187
188 188 """
189 189
190 190 __buffer = None
191 191 __isConfig = False
192 192
193 193 def __init__(self):
194 194
195 195 pass
196 196
197 197 def run(self, dataIn, **kwargs):
198 198
199 199 """
200 200 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
201 201
202 202 Input:
203 203
204 204 dataIn : objeto del tipo JROData
205 205
206 206 Return:
207 207
208 208 None
209 209
210 210 Affected:
211 211 __buffer : buffer de recepcion de datos.
212 212
213 213 """
214 214
215 215 raise ValueError, "ImplementedError"
216 216
217 217 class VoltageProc(ProcessingUnit):
218 218
219 219
220 220 def __init__(self):
221 221
222 222 self.objectDict = {}
223 223 self.dataOut = Voltage()
224 224 self.flip = 1
225 225
226 226 def init(self):
227 227
228 228 self.dataOut.copy(self.dataIn)
229 229 # No necesita copiar en cada init() los atributos de dataIn
230 230 # la copia deberia hacerse por cada nuevo bloque de datos
231 231
232 232 def selectChannels(self, channelList):
233 233
234 234 channelIndexList = []
235 235
236 236 for channel in channelList:
237 237 index = self.dataOut.channelList.index(channel)
238 238 channelIndexList.append(index)
239 239
240 240 self.selectChannelsByIndex(channelIndexList)
241 241
242 242 def selectChannelsByIndex(self, channelIndexList):
243 243 """
244 244 Selecciona un bloque de datos en base a canales segun el channelIndexList
245 245
246 246 Input:
247 247 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
248 248
249 249 Affected:
250 250 self.dataOut.data
251 251 self.dataOut.channelIndexList
252 252 self.dataOut.nChannels
253 253 self.dataOut.m_ProcessingHeader.totalSpectra
254 254 self.dataOut.systemHeaderObj.numChannels
255 255 self.dataOut.m_ProcessingHeader.blockSize
256 256
257 257 Return:
258 258 None
259 259 """
260 260
261 261 for channelIndex in channelIndexList:
262 262 if channelIndex not in self.dataOut.channelIndexList:
263 263 print channelIndexList
264 264 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
265 265
266 266 nChannels = len(channelIndexList)
267 267
268 268 data = self.dataOut.data[channelIndexList,:]
269 269
270 270 self.dataOut.data = data
271 271 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
272 272 # self.dataOut.nChannels = nChannels
273 273
274 274 return 1
275 275
276 276 def selectHeights(self, minHei=None, maxHei=None):
277 277 """
278 278 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
279 279 minHei <= height <= maxHei
280 280
281 281 Input:
282 282 minHei : valor minimo de altura a considerar
283 283 maxHei : valor maximo de altura a considerar
284 284
285 285 Affected:
286 286 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
287 287
288 288 Return:
289 289 1 si el metodo se ejecuto con exito caso contrario devuelve 0
290 290 """
291 291
292 292 if minHei == None:
293 293 minHei = self.dataOut.heightList[0]
294 294
295 295 if maxHei == None:
296 296 maxHei = self.dataOut.heightList[-1]
297 297
298 298 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
299 299 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
300 300
301 301
302 302 if (maxHei > self.dataOut.heightList[-1]):
303 303 maxHei = self.dataOut.heightList[-1]
304 304 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
305 305
306 306 minIndex = 0
307 307 maxIndex = 0
308 308 heights = self.dataOut.heightList
309 309
310 310 inda = numpy.where(heights >= minHei)
311 311 indb = numpy.where(heights <= maxHei)
312 312
313 313 try:
314 314 minIndex = inda[0][0]
315 315 except:
316 316 minIndex = 0
317 317
318 318 try:
319 319 maxIndex = indb[0][-1]
320 320 except:
321 321 maxIndex = len(heights)
322 322
323 323 self.selectHeightsByIndex(minIndex, maxIndex)
324 324
325 325 return 1
326 326
327 327
328 328 def selectHeightsByIndex(self, minIndex, maxIndex):
329 329 """
330 330 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
331 331 minIndex <= index <= maxIndex
332 332
333 333 Input:
334 334 minIndex : valor de indice minimo de altura a considerar
335 335 maxIndex : valor de indice maximo de altura a considerar
336 336
337 337 Affected:
338 338 self.dataOut.data
339 339 self.dataOut.heightList
340 340
341 341 Return:
342 342 1 si el metodo se ejecuto con exito caso contrario devuelve 0
343 343 """
344 344
345 345 if (minIndex < 0) or (minIndex > maxIndex):
346 346 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
347 347
348 348 if (maxIndex >= self.dataOut.nHeights):
349 349 maxIndex = self.dataOut.nHeights-1
350 350 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
351 351
352 352 nHeights = maxIndex - minIndex + 1
353 353
354 354 #voltage
355 355 data = self.dataOut.data[:,minIndex:maxIndex+1]
356 356
357 357 firstHeight = self.dataOut.heightList[minIndex]
358 358
359 359 self.dataOut.data = data
360 360 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
361 361
362 362 return 1
363 363
364 364
365 365 def filterByHeights(self, window):
366 366 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
367 367
368 368 if window == None:
369 369 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
370 370
371 371 newdelta = deltaHeight * window
372 372 r = self.dataOut.data.shape[1] % window
373 373 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
374 374 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
375 375 buffer = numpy.sum(buffer,2)
376 376 self.dataOut.data = buffer
377 377 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta)
378 378 self.dataOut.windowOfFilter = window
379 379
380 380 def deFlip(self):
381 381 self.dataOut.data *= self.flip
382 382 self.flip *= -1.
383 383
384 384 def setRadarFrequency(self, frequency=None):
385 385 if frequency != None:
386 386 self.dataOut.frequency = frequency
387 387
388 388 return 1
389 389
390 390 class CohInt(Operation):
391 391
392 392 __isConfig = False
393 393
394 394 __profIndex = 0
395 395 __withOverapping = False
396 396
397 397 __byTime = False
398 398 __initime = None
399 399 __lastdatatime = None
400 400 __integrationtime = None
401 401
402 402 __buffer = None
403 403
404 404 __dataReady = False
405 405
406 406 n = None
407 407
408 408
409 409 def __init__(self):
410 410
411 411 self.__isConfig = False
412 412
413 413 def setup(self, n=None, timeInterval=None, overlapping=False):
414 414 """
415 415 Set the parameters of the integration class.
416 416
417 417 Inputs:
418 418
419 419 n : Number of coherent integrations
420 420 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
421 421 overlapping :
422 422
423 423 """
424 424
425 425 self.__initime = None
426 426 self.__lastdatatime = 0
427 427 self.__buffer = None
428 428 self.__dataReady = False
429 429
430 430
431 431 if n == None and timeInterval == None:
432 432 raise ValueError, "n or timeInterval should be specified ..."
433 433
434 434 if n != None:
435 435 self.n = n
436 436 self.__byTime = False
437 437 else:
438 438 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
439 439 self.n = 9999
440 440 self.__byTime = True
441 441
442 442 if overlapping:
443 443 self.__withOverapping = True
444 444 self.__buffer = None
445 445 else:
446 446 self.__withOverapping = False
447 447 self.__buffer = 0
448 448
449 449 self.__profIndex = 0
450 450
451 451 def putData(self, data):
452 452
453 453 """
454 454 Add a profile to the __buffer and increase in one the __profileIndex
455 455
456 456 """
457 457
458 458 if not self.__withOverapping:
459 459 self.__buffer += data.copy()
460 460 self.__profIndex += 1
461 461 return
462 462
463 463 #Overlapping data
464 464 nChannels, nHeis = data.shape
465 465 data = numpy.reshape(data, (1, nChannels, nHeis))
466 466
467 467 #If the buffer is empty then it takes the data value
468 468 if self.__buffer == None:
469 469 self.__buffer = data
470 470 self.__profIndex += 1
471 471 return
472 472
473 473 #If the buffer length is lower than n then stakcing the data value
474 474 if self.__profIndex < self.n:
475 475 self.__buffer = numpy.vstack((self.__buffer, data))
476 476 self.__profIndex += 1
477 477 return
478 478
479 479 #If the buffer length is equal to n then replacing the last buffer value with the data value
480 480 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
481 481 self.__buffer[self.n-1] = data
482 482 self.__profIndex = self.n
483 483 return
484 484
485 485
486 486 def pushData(self):
487 487 """
488 488 Return the sum of the last profiles and the profiles used in the sum.
489 489
490 490 Affected:
491 491
492 492 self.__profileIndex
493 493
494 494 """
495 495
496 496 if not self.__withOverapping:
497 497 data = self.__buffer
498 498 n = self.__profIndex
499 499
500 500 self.__buffer = 0
501 501 self.__profIndex = 0
502 502
503 503 return data, n
504 504
505 505 #Integration with Overlapping
506 506 data = numpy.sum(self.__buffer, axis=0)
507 507 n = self.__profIndex
508 508
509 509 return data, n
510 510
511 511 def byProfiles(self, data):
512 512
513 513 self.__dataReady = False
514 514 avgdata = None
515 515 n = None
516 516
517 517 self.putData(data)
518 518
519 519 if self.__profIndex == self.n:
520 520
521 521 avgdata, n = self.pushData()
522 522 self.__dataReady = True
523 523
524 524 return avgdata
525 525
526 526 def byTime(self, data, datatime):
527 527
528 528 self.__dataReady = False
529 529 avgdata = None
530 530 n = None
531 531
532 532 self.putData(data)
533 533
534 534 if (datatime - self.__initime) >= self.__integrationtime:
535 535 avgdata, n = self.pushData()
536 536 self.n = n
537 537 self.__dataReady = True
538 538
539 539 return avgdata
540 540
541 541 def integrate(self, data, datatime=None):
542 542
543 543 if self.__initime == None:
544 544 self.__initime = datatime
545 545
546 546 if self.__byTime:
547 547 avgdata = self.byTime(data, datatime)
548 548 else:
549 549 avgdata = self.byProfiles(data)
550 550
551 551
552 552 self.__lastdatatime = datatime
553 553
554 554 if avgdata == None:
555 555 return None, None
556 556
557 557 avgdatatime = self.__initime
558 558
559 559 deltatime = datatime -self.__lastdatatime
560 560
561 561 if not self.__withOverapping:
562 562 self.__initime = datatime
563 563 else:
564 564 self.__initime += deltatime
565 565
566 566 return avgdata, avgdatatime
567 567
568 568 def run(self, dataOut, **kwargs):
569 569
570 570 if not self.__isConfig:
571 571 self.setup(**kwargs)
572 572 self.__isConfig = True
573 573
574 574 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
575 575
576 576 # dataOut.timeInterval *= n
577 577 dataOut.flagNoData = True
578 578
579 579 if self.__dataReady:
580 580 dataOut.data = avgdata
581 581 dataOut.nCohInt *= self.n
582 582 dataOut.utctime = avgdatatime
583 583 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
584 584 dataOut.flagNoData = False
585 585
586 586
587 587 class Decoder(Operation):
588 588
589 589 __isConfig = False
590 590 __profIndex = 0
591 591
592 592 code = None
593 593
594 594 nCode = None
595 595 nBaud = None
596 596
597 597 def __init__(self):
598 598
599 599 self.__isConfig = False
600 600
601 601 def setup(self, code, shape):
602 602
603 603 self.__profIndex = 0
604 604
605 605 self.code = code
606 606
607 607 self.nCode = len(code)
608 608 self.nBaud = len(code[0])
609 609
610 610 self.__nChannels, self.__nHeis = shape
611 611
612 612 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
613 613
614 614 __codeBuffer[:,0:self.nBaud] = self.code
615 615
616 616 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
617 617
618 618 self.ndatadec = self.__nHeis - self.nBaud + 1
619 619
620 620 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
621 621
622 622 def convolutionInFreq(self, data):
623 623
624 624 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
625 625
626 626 fft_data = numpy.fft.fft(data, axis=1)
627 627
628 628 conv = fft_data*fft_code
629 629
630 630 data = numpy.fft.ifft(conv,axis=1)
631 631
632 632 datadec = data[:,:-self.nBaud+1]
633 633
634 634 return datadec
635 635
636 636 def convolutionInFreqOpt(self, data):
637 637
638 638 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
639 639
640 640 data = cfunctions.decoder(fft_code, data)
641 641
642 642 datadec = data[:,:-self.nBaud+1]
643 643
644 644 return datadec
645 645
646 646 def convolutionInTime(self, data):
647 647
648 648 code = self.code[self.__profIndex]
649 649
650 650 for i in range(self.__nChannels):
651 651 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
652 652
653 653 return self.datadecTime
654 654
655 655 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
656 656
657 657 if code == None:
658 658 code = dataOut.code
659 659 else:
660 660 code = numpy.array(code).reshape(nCode,nBaud)
661 661 dataOut.code = code
662 662 dataOut.nCode = nCode
663 663 dataOut.nBaud = nBaud
664 664 dataOut.radarControllerHeaderObj.code = code
665 665 dataOut.radarControllerHeaderObj.nCode = nCode
666 666 dataOut.radarControllerHeaderObj.nBaud = nBaud
667 667
668 668
669 669 if not self.__isConfig:
670 670
671 671 self.setup(code, dataOut.data.shape)
672 672 self.__isConfig = True
673 673
674 674 if mode == 0:
675 675 datadec = self.convolutionInTime(dataOut.data)
676 676
677 677 if mode == 1:
678 678 datadec = self.convolutionInFreq(dataOut.data)
679 679
680 680 if mode == 2:
681 681 datadec = self.convolutionInFreqOpt(dataOut.data)
682 682
683 683 dataOut.data = datadec
684 684
685 685 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
686 686
687 687 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
688 688
689 689 if self.__profIndex == self.nCode-1:
690 690 self.__profIndex = 0
691 691 return 1
692 692
693 693 self.__profIndex += 1
694 694
695 695 return 1
696 696 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
697 697
698 698
699 699
700 700 class SpectraProc(ProcessingUnit):
701 701
702 702 def __init__(self):
703 703
704 704 self.objectDict = {}
705 705 self.buffer = None
706 706 self.firstdatatime = None
707 707 self.profIndex = 0
708 708 self.dataOut = Spectra()
709 709
710 710 def __updateObjFromInput(self):
711 711
712 712 self.dataOut.timeZone = self.dataIn.timeZone
713 713 self.dataOut.dstFlag = self.dataIn.dstFlag
714 714 self.dataOut.errorCount = self.dataIn.errorCount
715 715 self.dataOut.useLocalTime = self.dataIn.useLocalTime
716 716
717 717 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
718 718 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
719 719 self.dataOut.channelList = self.dataIn.channelList
720 720 self.dataOut.heightList = self.dataIn.heightList
721 721 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
722 722 # self.dataOut.nHeights = self.dataIn.nHeights
723 723 # self.dataOut.nChannels = self.dataIn.nChannels
724 724 self.dataOut.nBaud = self.dataIn.nBaud
725 725 self.dataOut.nCode = self.dataIn.nCode
726 726 self.dataOut.code = self.dataIn.code
727 727 self.dataOut.nProfiles = self.dataOut.nFFTPoints
728 728 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
729 729 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
730 730 self.dataOut.utctime = self.firstdatatime
731 731 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
732 732 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
733 733 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
734 734 self.dataOut.nCohInt = self.dataIn.nCohInt
735 735 self.dataOut.nIncohInt = 1
736 736 self.dataOut.ippSeconds = self.dataIn.ippSeconds
737 737 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
738 738
739 739 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
740 740 self.dataOut.frequency = self.dataIn.frequency
741 741 self.dataOut.realtime = self.dataIn.realtime
742 742
743 743 def __getFft(self):
744 744 """
745 745 Convierte valores de Voltaje a Spectra
746 746
747 747 Affected:
748 748 self.dataOut.data_spc
749 749 self.dataOut.data_cspc
750 750 self.dataOut.data_dc
751 751 self.dataOut.heightList
752 752 self.profIndex
753 753 self.buffer
754 754 self.dataOut.flagNoData
755 755 """
756 756 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
757 757 fft_volt = fft_volt.astype(numpy.dtype('complex'))
758 758 dc = fft_volt[:,0,:]
759 759
760 760 #calculo de self-spectra
761 761 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
762 762 spc = fft_volt * numpy.conjugate(fft_volt)
763 763 spc = spc.real
764 764
765 765 blocksize = 0
766 766 blocksize += dc.size
767 767 blocksize += spc.size
768 768
769 769 cspc = None
770 770 pairIndex = 0
771 771 if self.dataOut.pairsList != None:
772 772 #calculo de cross-spectra
773 773 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
774 774 for pair in self.dataOut.pairsList:
775 775 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
776 776 pairIndex += 1
777 777 blocksize += cspc.size
778 778
779 779 self.dataOut.data_spc = spc
780 780 self.dataOut.data_cspc = cspc
781 781 self.dataOut.data_dc = dc
782 782 self.dataOut.blockSize = blocksize
783 783 self.dataOut.flagShiftFFT = False
784 784
785 785 def init(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None):
786 786
787 787 self.dataOut.flagNoData = True
788 788
789 789 if self.dataIn.type == "Spectra":
790 790 self.dataOut.copy(self.dataIn)
791 791 return
792 792
793 793 if self.dataIn.type == "Voltage":
794 794
795 795 if nFFTPoints == None:
796 796 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
797 797
798 798 if pairsList == None:
799 799 nPairs = 0
800 800 else:
801 801 nPairs = len(pairsList)
802 802
803 803 if ippFactor == None:
804 804 ippFactor = 1
805 805 self.dataOut.ippFactor = ippFactor
806 806
807 807 self.dataOut.nFFTPoints = nFFTPoints
808 808 self.dataOut.pairsList = pairsList
809 809 self.dataOut.nPairs = nPairs
810 810
811 811 if self.buffer == None:
812 812 self.buffer = numpy.zeros((self.dataIn.nChannels,
813 813 nProfiles,
814 814 self.dataIn.nHeights),
815 815 dtype='complex')
816 816
817 817
818 818 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
819 819 self.profIndex += 1
820 820
821 821 if self.firstdatatime == None:
822 822 self.firstdatatime = self.dataIn.utctime
823 823
824 824 if self.profIndex == nProfiles:
825 825 self.__updateObjFromInput()
826 826 self.__getFft()
827 827
828 828 self.dataOut.flagNoData = False
829 829
830 830 self.buffer = None
831 831 self.firstdatatime = None
832 832 self.profIndex = 0
833 833
834 834 return
835 835
836 836 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
837 837
838 838 def selectChannels(self, channelList):
839 839
840 840 channelIndexList = []
841 841
842 842 for channel in channelList:
843 843 index = self.dataOut.channelList.index(channel)
844 844 channelIndexList.append(index)
845 845
846 846 self.selectChannelsByIndex(channelIndexList)
847 847
848 848 def selectChannelsByIndex(self, channelIndexList):
849 849 """
850 850 Selecciona un bloque de datos en base a canales segun el channelIndexList
851 851
852 852 Input:
853 853 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
854 854
855 855 Affected:
856 856 self.dataOut.data_spc
857 857 self.dataOut.channelIndexList
858 858 self.dataOut.nChannels
859 859
860 860 Return:
861 861 None
862 862 """
863 863
864 864 for channelIndex in channelIndexList:
865 865 if channelIndex not in self.dataOut.channelIndexList:
866 866 print channelIndexList
867 867 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
868 868
869 869 nChannels = len(channelIndexList)
870 870
871 871 data_spc = self.dataOut.data_spc[channelIndexList,:]
872 872
873 873 self.dataOut.data_spc = data_spc
874 874 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
875 875 # self.dataOut.nChannels = nChannels
876 876
877 877 return 1
878 878
879 879 def selectHeights(self, minHei, maxHei):
880 880 """
881 881 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
882 882 minHei <= height <= maxHei
883 883
884 884 Input:
885 885 minHei : valor minimo de altura a considerar
886 886 maxHei : valor maximo de altura a considerar
887 887
888 888 Affected:
889 889 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
890 890
891 891 Return:
892 892 1 si el metodo se ejecuto con exito caso contrario devuelve 0
893 893 """
894 894 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
895 895 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
896 896
897 897 if (maxHei > self.dataOut.heightList[-1]):
898 898 maxHei = self.dataOut.heightList[-1]
899 899 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
900 900
901 901 minIndex = 0
902 902 maxIndex = 0
903 903 heights = self.dataOut.heightList
904 904
905 905 inda = numpy.where(heights >= minHei)
906 906 indb = numpy.where(heights <= maxHei)
907 907
908 908 try:
909 909 minIndex = inda[0][0]
910 910 except:
911 911 minIndex = 0
912 912
913 913 try:
914 914 maxIndex = indb[0][-1]
915 915 except:
916 916 maxIndex = len(heights)
917 917
918 918 self.selectHeightsByIndex(minIndex, maxIndex)
919 919
920 920 return 1
921 921
922 def getBeaconSignal(self, tauindex = 0, channelindex = 0):
922 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
923 923 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
924
925 if hei_ref != None:
926 newheis = numpy.where(self.dataOut.heightList>hei_ref)
927
924 928 minIndex = min(newheis[0])
925 929 maxIndex = max(newheis[0])
926 930 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
927 931 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
928 932
929 933 # determina indices
930 934 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
931 935 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
932 936 beacon_dB = numpy.sort(avg_dB)[-nheis:]
933 937 beacon_heiIndexList = []
934 938 for val in avg_dB.tolist():
935 939 if val >= beacon_dB[0]:
936 940 beacon_heiIndexList.append(avg_dB.tolist().index(val))
937 941
938 942 #data_spc = data_spc[:,:,beacon_heiIndexList]
939 943 data_cspc = None
940 944 if self.dataOut.data_cspc != None:
941 945 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
942 946 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
943 947
944 948 data_dc = None
945 949 if self.dataOut.data_dc != None:
946 950 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
947 951 #data_dc = data_dc[:,beacon_heiIndexList]
948 952
949 953 self.dataOut.data_spc = data_spc
950 954 self.dataOut.data_cspc = data_cspc
951 955 self.dataOut.data_dc = data_dc
952 956 self.dataOut.heightList = heightList
953 957 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
954 958
955 959 return 1
956 960
957 961
958 962 def selectHeightsByIndex(self, minIndex, maxIndex):
959 963 """
960 964 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
961 965 minIndex <= index <= maxIndex
962 966
963 967 Input:
964 968 minIndex : valor de indice minimo de altura a considerar
965 969 maxIndex : valor de indice maximo de altura a considerar
966 970
967 971 Affected:
968 972 self.dataOut.data_spc
969 973 self.dataOut.data_cspc
970 974 self.dataOut.data_dc
971 975 self.dataOut.heightList
972 976
973 977 Return:
974 978 1 si el metodo se ejecuto con exito caso contrario devuelve 0
975 979 """
976 980
977 981 if (minIndex < 0) or (minIndex > maxIndex):
978 982 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
979 983
980 984 if (maxIndex >= self.dataOut.nHeights):
981 985 maxIndex = self.dataOut.nHeights-1
982 986 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
983 987
984 988 nHeights = maxIndex - minIndex + 1
985 989
986 990 #Spectra
987 991 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
988 992
989 993 data_cspc = None
990 994 if self.dataOut.data_cspc != None:
991 995 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
992 996
993 997 data_dc = None
994 998 if self.dataOut.data_dc != None:
995 999 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
996 1000
997 1001 self.dataOut.data_spc = data_spc
998 1002 self.dataOut.data_cspc = data_cspc
999 1003 self.dataOut.data_dc = data_dc
1000 1004
1001 1005 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
1002 1006
1003 1007 return 1
1004 1008
1005 1009 def removeDC(self, mode = 2):
1006 1010 jspectra = self.dataOut.data_spc
1007 1011 jcspectra = self.dataOut.data_cspc
1008 1012
1009 1013
1010 1014 num_chan = jspectra.shape[0]
1011 1015 num_hei = jspectra.shape[2]
1012 1016
1013 1017 if jcspectra != None:
1014 1018 jcspectraExist = True
1015 1019 num_pairs = jcspectra.shape[0]
1016 1020 else: jcspectraExist = False
1017 1021
1018 1022 freq_dc = jspectra.shape[1]/2
1019 1023 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1020 1024
1021 1025 if ind_vel[0]<0:
1022 1026 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1023 1027
1024 1028 if mode == 1:
1025 1029 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1026 1030
1027 1031 if jcspectraExist:
1028 1032 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
1029 1033
1030 1034 if mode == 2:
1031 1035
1032 1036 vel = numpy.array([-2,-1,1,2])
1033 1037 xx = numpy.zeros([4,4])
1034 1038
1035 1039 for fil in range(4):
1036 1040 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1037 1041
1038 1042 xx_inv = numpy.linalg.inv(xx)
1039 1043 xx_aux = xx_inv[0,:]
1040 1044
1041 1045 for ich in range(num_chan):
1042 1046 yy = jspectra[ich,ind_vel,:]
1043 1047 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1044 1048
1045 1049 junkid = jspectra[ich,freq_dc,:]<=0
1046 1050 cjunkid = sum(junkid)
1047 1051
1048 1052 if cjunkid.any():
1049 1053 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1050 1054
1051 1055 if jcspectraExist:
1052 1056 for ip in range(num_pairs):
1053 1057 yy = jcspectra[ip,ind_vel,:]
1054 1058 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
1055 1059
1056 1060
1057 1061 self.dataOut.data_spc = jspectra
1058 1062 self.dataOut.data_cspc = jcspectra
1059 1063
1060 1064 return 1
1061 1065
1062 1066 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
1063 1067
1064 1068 jspectra = self.dataOut.data_spc
1065 1069 jcspectra = self.dataOut.data_cspc
1066 1070 jnoise = self.dataOut.getNoise()
1067 1071 num_incoh = self.dataOut.nIncohInt
1068 1072
1069 1073 num_channel = jspectra.shape[0]
1070 1074 num_prof = jspectra.shape[1]
1071 1075 num_hei = jspectra.shape[2]
1072 1076
1073 1077 #hei_interf
1074 1078 if hei_interf == None:
1075 1079 count_hei = num_hei/2 #Como es entero no importa
1076 1080 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
1077 1081 hei_interf = numpy.asarray(hei_interf)[0]
1078 1082 #nhei_interf
1079 1083 if (nhei_interf == None):
1080 1084 nhei_interf = 5
1081 1085 if (nhei_interf < 1):
1082 1086 nhei_interf = 1
1083 1087 if (nhei_interf > count_hei):
1084 1088 nhei_interf = count_hei
1085 1089 if (offhei_interf == None):
1086 1090 offhei_interf = 0
1087 1091
1088 1092 ind_hei = range(num_hei)
1089 1093 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
1090 1094 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
1091 1095 mask_prof = numpy.asarray(range(num_prof))
1092 1096 num_mask_prof = mask_prof.size
1093 1097 comp_mask_prof = [0, num_prof/2]
1094 1098
1095 1099
1096 1100 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
1097 1101 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
1098 1102 jnoise = numpy.nan
1099 1103 noise_exist = jnoise[0] < numpy.Inf
1100 1104
1101 1105 #Subrutina de Remocion de la Interferencia
1102 1106 for ich in range(num_channel):
1103 1107 #Se ordena los espectros segun su potencia (menor a mayor)
1104 1108 power = jspectra[ich,mask_prof,:]
1105 1109 power = power[:,hei_interf]
1106 1110 power = power.sum(axis = 0)
1107 1111 psort = power.ravel().argsort()
1108 1112
1109 1113 #Se estima la interferencia promedio en los Espectros de Potencia empleando
1110 1114 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
1111 1115
1112 1116 if noise_exist:
1113 1117 # tmp_noise = jnoise[ich] / num_prof
1114 1118 tmp_noise = jnoise[ich]
1115 1119 junkspc_interf = junkspc_interf - tmp_noise
1116 1120 #junkspc_interf[:,comp_mask_prof] = 0
1117 1121
1118 1122 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
1119 1123 jspc_interf = jspc_interf.transpose()
1120 1124 #Calculando el espectro de interferencia promedio
1121 1125 noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh))
1122 1126 noiseid = noiseid[0]
1123 1127 cnoiseid = noiseid.size
1124 1128 interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh))
1125 1129 interfid = interfid[0]
1126 1130 cinterfid = interfid.size
1127 1131
1128 1132 if (cnoiseid > 0): jspc_interf[noiseid] = 0
1129 1133
1130 1134 #Expandiendo los perfiles a limpiar
1131 1135 if (cinterfid > 0):
1132 1136 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
1133 1137 new_interfid = numpy.asarray(new_interfid)
1134 1138 new_interfid = {x for x in new_interfid}
1135 1139 new_interfid = numpy.array(list(new_interfid))
1136 1140 new_cinterfid = new_interfid.size
1137 1141 else: new_cinterfid = 0
1138 1142
1139 1143 for ip in range(new_cinterfid):
1140 1144 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
1141 1145 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
1142 1146
1143 1147
1144 1148 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
1145 1149
1146 1150 #Removiendo la interferencia del punto de mayor interferencia
1147 1151 ListAux = jspc_interf[mask_prof].tolist()
1148 1152 maxid = ListAux.index(max(ListAux))
1149 1153
1150 1154
1151 1155 if cinterfid > 0:
1152 1156 for ip in range(cinterfid*(interf == 2) - 1):
1153 1157 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero()
1154 1158 cind = len(ind)
1155 1159
1156 1160 if (cind > 0):
1157 1161 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh))
1158 1162
1159 1163 ind = numpy.array([-2,-1,1,2])
1160 1164 xx = numpy.zeros([4,4])
1161 1165
1162 1166 for id1 in range(4):
1163 1167 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
1164 1168
1165 1169 xx_inv = numpy.linalg.inv(xx)
1166 1170 xx = xx_inv[:,0]
1167 1171 ind = (ind + maxid + num_mask_prof)%num_mask_prof
1168 1172 yy = jspectra[ich,mask_prof[ind],:]
1169 1173 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
1170 1174
1171 1175
1172 1176 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero()
1173 1177 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh))
1174 1178
1175 1179 #Remocion de Interferencia en el Cross Spectra
1176 1180 if jcspectra == None: return jspectra, jcspectra
1177 1181 num_pairs = jcspectra.size/(num_prof*num_hei)
1178 1182 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
1179 1183
1180 1184 for ip in range(num_pairs):
1181 1185
1182 1186 #-------------------------------------------
1183 1187
1184 1188 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
1185 1189 cspower = cspower[:,hei_interf]
1186 1190 cspower = cspower.sum(axis = 0)
1187 1191
1188 1192 cspsort = cspower.ravel().argsort()
1189 1193 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
1190 1194 junkcspc_interf = junkcspc_interf.transpose()
1191 1195 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
1192 1196
1193 1197 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
1194 1198
1195 1199 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
1196 1200 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
1197 1201 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
1198 1202
1199 1203 for iprof in range(num_prof):
1200 1204 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
1201 1205 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
1202 1206
1203 1207 #Removiendo la Interferencia
1204 1208 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
1205 1209
1206 1210 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
1207 1211 maxid = ListAux.index(max(ListAux))
1208 1212
1209 1213 ind = numpy.array([-2,-1,1,2])
1210 1214 xx = numpy.zeros([4,4])
1211 1215
1212 1216 for id1 in range(4):
1213 1217 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
1214 1218
1215 1219 xx_inv = numpy.linalg.inv(xx)
1216 1220 xx = xx_inv[:,0]
1217 1221
1218 1222 ind = (ind + maxid + num_mask_prof)%num_mask_prof
1219 1223 yy = jcspectra[ip,mask_prof[ind],:]
1220 1224 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
1221 1225
1222 1226 #Guardar Resultados
1223 1227 self.dataOut.data_spc = jspectra
1224 1228 self.dataOut.data_cspc = jcspectra
1225 1229
1226 1230 return 1
1227 1231
1228 1232 def setRadarFrequency(self, frequency=None):
1229 1233 if frequency != None:
1230 1234 self.dataOut.frequency = frequency
1231 1235
1232 1236 return 1
1233 1237
1234 1238 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
1235 1239 #validacion de rango
1236 1240 if minHei == None:
1237 1241 minHei = self.dataOut.heightList[0]
1238 1242
1239 1243 if maxHei == None:
1240 1244 maxHei = self.dataOut.heightList[-1]
1241 1245
1242 1246 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
1243 1247 print 'minHei: %.2f is out of the heights range'%(minHei)
1244 1248 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
1245 1249 minHei = self.dataOut.heightList[0]
1246 1250
1247 1251 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
1248 1252 print 'maxHei: %.2f is out of the heights range'%(maxHei)
1249 1253 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
1250 1254 maxHei = self.dataOut.heightList[-1]
1251 1255
1252 1256 # validacion de velocidades
1253 1257 velrange = self.dataOut.getVelRange(1)
1254 1258
1255 1259 if minVel == None:
1256 1260 minVel = velrange[0]
1257 1261
1258 1262 if maxVel == None:
1259 1263 maxVel = velrange[-1]
1260 1264
1261 1265 if (minVel < velrange[0]) or (minVel > maxVel):
1262 1266 print 'minVel: %.2f is out of the velocity range'%(minVel)
1263 1267 print 'minVel is setting to %.2f'%(velrange[0])
1264 1268 minVel = velrange[0]
1265 1269
1266 1270 if (maxVel > velrange[-1]) or (maxVel < minVel):
1267 1271 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
1268 1272 print 'maxVel is setting to %.2f'%(velrange[-1])
1269 1273 maxVel = velrange[-1]
1270 1274
1271 1275 # seleccion de indices para rango
1272 1276 minIndex = 0
1273 1277 maxIndex = 0
1274 1278 heights = self.dataOut.heightList
1275 1279
1276 1280 inda = numpy.where(heights >= minHei)
1277 1281 indb = numpy.where(heights <= maxHei)
1278 1282
1279 1283 try:
1280 1284 minIndex = inda[0][0]
1281 1285 except:
1282 1286 minIndex = 0
1283 1287
1284 1288 try:
1285 1289 maxIndex = indb[0][-1]
1286 1290 except:
1287 1291 maxIndex = len(heights)
1288 1292
1289 1293 if (minIndex < 0) or (minIndex > maxIndex):
1290 1294 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
1291 1295
1292 1296 if (maxIndex >= self.dataOut.nHeights):
1293 1297 maxIndex = self.dataOut.nHeights-1
1294 1298
1295 1299 # seleccion de indices para velocidades
1296 1300 indminvel = numpy.where(velrange >= minVel)
1297 1301 indmaxvel = numpy.where(velrange <= maxVel)
1298 1302 try:
1299 1303 minIndexVel = indminvel[0][0]
1300 1304 except:
1301 1305 minIndexVel = 0
1302 1306
1303 1307 try:
1304 1308 maxIndexVel = indmaxvel[0][-1]
1305 1309 except:
1306 1310 maxIndexVel = len(velrange)
1307 1311
1308 1312 #seleccion del espectro
1309 1313 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
1310 1314 #estimacion de ruido
1311 1315 noise = numpy.zeros(self.dataOut.nChannels)
1312 1316
1313 1317 for channel in range(self.dataOut.nChannels):
1314 1318 daux = data_spc[channel,:,:]
1315 1319 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
1316 1320
1317 1321 self.dataOut.noise = noise.copy()
1318 1322
1319 1323 return 1
1320 1324
1321 1325
1322 1326 class IncohInt(Operation):
1323 1327
1324 1328
1325 1329 __profIndex = 0
1326 1330 __withOverapping = False
1327 1331
1328 1332 __byTime = False
1329 1333 __initime = None
1330 1334 __lastdatatime = None
1331 1335 __integrationtime = None
1332 1336
1333 1337 __buffer_spc = None
1334 1338 __buffer_cspc = None
1335 1339 __buffer_dc = None
1336 1340
1337 1341 __dataReady = False
1338 1342
1339 1343 __timeInterval = None
1340 1344
1341 1345 n = None
1342 1346
1343 1347
1344 1348
1345 1349 def __init__(self):
1346 1350
1347 1351 self.__isConfig = False
1348 1352
1349 1353 def setup(self, n=None, timeInterval=None, overlapping=False):
1350 1354 """
1351 1355 Set the parameters of the integration class.
1352 1356
1353 1357 Inputs:
1354 1358
1355 1359 n : Number of coherent integrations
1356 1360 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1357 1361 overlapping :
1358 1362
1359 1363 """
1360 1364
1361 1365 self.__initime = None
1362 1366 self.__lastdatatime = 0
1363 1367 self.__buffer_spc = None
1364 1368 self.__buffer_cspc = None
1365 1369 self.__buffer_dc = None
1366 1370 self.__dataReady = False
1367 1371
1368 1372
1369 1373 if n == None and timeInterval == None:
1370 1374 raise ValueError, "n or timeInterval should be specified ..."
1371 1375
1372 1376 if n != None:
1373 1377 self.n = n
1374 1378 self.__byTime = False
1375 1379 else:
1376 1380 self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line
1377 1381 self.n = 9999
1378 1382 self.__byTime = True
1379 1383
1380 1384 if overlapping:
1381 1385 self.__withOverapping = True
1382 1386 else:
1383 1387 self.__withOverapping = False
1384 1388 self.__buffer_spc = 0
1385 1389 self.__buffer_cspc = 0
1386 1390 self.__buffer_dc = 0
1387 1391
1388 1392 self.__profIndex = 0
1389 1393
1390 1394 def putData(self, data_spc, data_cspc, data_dc):
1391 1395
1392 1396 """
1393 1397 Add a profile to the __buffer_spc and increase in one the __profileIndex
1394 1398
1395 1399 """
1396 1400
1397 1401 if not self.__withOverapping:
1398 1402 self.__buffer_spc += data_spc
1399 1403
1400 1404 if data_cspc == None:
1401 1405 self.__buffer_cspc = None
1402 1406 else:
1403 1407 self.__buffer_cspc += data_cspc
1404 1408
1405 1409 if data_dc == None:
1406 1410 self.__buffer_dc = None
1407 1411 else:
1408 1412 self.__buffer_dc += data_dc
1409 1413
1410 1414 self.__profIndex += 1
1411 1415 return
1412 1416
1413 1417 #Overlapping data
1414 1418 nChannels, nFFTPoints, nHeis = data_spc.shape
1415 1419 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1416 1420 if data_cspc != None:
1417 1421 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1418 1422 if data_dc != None:
1419 1423 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1420 1424
1421 1425 #If the buffer is empty then it takes the data value
1422 1426 if self.__buffer_spc == None:
1423 1427 self.__buffer_spc = data_spc
1424 1428
1425 1429 if data_cspc == None:
1426 1430 self.__buffer_cspc = None
1427 1431 else:
1428 1432 self.__buffer_cspc += data_cspc
1429 1433
1430 1434 if data_dc == None:
1431 1435 self.__buffer_dc = None
1432 1436 else:
1433 1437 self.__buffer_dc += data_dc
1434 1438
1435 1439 self.__profIndex += 1
1436 1440 return
1437 1441
1438 1442 #If the buffer length is lower than n then stakcing the data value
1439 1443 if self.__profIndex < self.n:
1440 1444 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1441 1445
1442 1446 if data_cspc != None:
1443 1447 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1444 1448
1445 1449 if data_dc != None:
1446 1450 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1447 1451
1448 1452 self.__profIndex += 1
1449 1453 return
1450 1454
1451 1455 #If the buffer length is equal to n then replacing the last buffer value with the data value
1452 1456 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1453 1457 self.__buffer_spc[self.n-1] = data_spc
1454 1458
1455 1459 if data_cspc != None:
1456 1460 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1457 1461 self.__buffer_cspc[self.n-1] = data_cspc
1458 1462
1459 1463 if data_dc != None:
1460 1464 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1461 1465 self.__buffer_dc[self.n-1] = data_dc
1462 1466
1463 1467 self.__profIndex = self.n
1464 1468 return
1465 1469
1466 1470
1467 1471 def pushData(self):
1468 1472 """
1469 1473 Return the sum of the last profiles and the profiles used in the sum.
1470 1474
1471 1475 Affected:
1472 1476
1473 1477 self.__profileIndex
1474 1478
1475 1479 """
1476 1480 data_spc = None
1477 1481 data_cspc = None
1478 1482 data_dc = None
1479 1483
1480 1484 if not self.__withOverapping:
1481 1485 data_spc = self.__buffer_spc
1482 1486 data_cspc = self.__buffer_cspc
1483 1487 data_dc = self.__buffer_dc
1484 1488
1485 1489 n = self.__profIndex
1486 1490
1487 1491 self.__buffer_spc = 0
1488 1492 self.__buffer_cspc = 0
1489 1493 self.__buffer_dc = 0
1490 1494 self.__profIndex = 0
1491 1495
1492 1496 return data_spc, data_cspc, data_dc, n
1493 1497
1494 1498 #Integration with Overlapping
1495 1499 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1496 1500
1497 1501 if self.__buffer_cspc != None:
1498 1502 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1499 1503
1500 1504 if self.__buffer_dc != None:
1501 1505 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1502 1506
1503 1507 n = self.__profIndex
1504 1508
1505 1509 return data_spc, data_cspc, data_dc, n
1506 1510
1507 1511 def byProfiles(self, *args):
1508 1512
1509 1513 self.__dataReady = False
1510 1514 avgdata_spc = None
1511 1515 avgdata_cspc = None
1512 1516 avgdata_dc = None
1513 1517 n = None
1514 1518
1515 1519 self.putData(*args)
1516 1520
1517 1521 if self.__profIndex == self.n:
1518 1522
1519 1523 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1520 1524 self.__dataReady = True
1521 1525
1522 1526 return avgdata_spc, avgdata_cspc, avgdata_dc
1523 1527
1524 1528 def byTime(self, datatime, *args):
1525 1529
1526 1530 self.__dataReady = False
1527 1531 avgdata_spc = None
1528 1532 avgdata_cspc = None
1529 1533 avgdata_dc = None
1530 1534 n = None
1531 1535
1532 1536 self.putData(*args)
1533 1537
1534 1538 if (datatime - self.__initime) >= self.__integrationtime:
1535 1539 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1536 1540 self.n = n
1537 1541 self.__dataReady = True
1538 1542
1539 1543 return avgdata_spc, avgdata_cspc, avgdata_dc
1540 1544
1541 1545 def integrate(self, datatime, *args):
1542 1546
1543 1547 if self.__initime == None:
1544 1548 self.__initime = datatime
1545 1549
1546 1550 if self.__byTime:
1547 1551 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1548 1552 else:
1549 1553 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1550 1554
1551 1555 self.__lastdatatime = datatime
1552 1556
1553 1557 if avgdata_spc == None:
1554 1558 return None, None, None, None
1555 1559
1556 1560 avgdatatime = self.__initime
1557 1561 try:
1558 1562 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1559 1563 except:
1560 1564 self.__timeInterval = self.__lastdatatime - self.__initime
1561 1565
1562 1566 deltatime = datatime -self.__lastdatatime
1563 1567
1564 1568 if not self.__withOverapping:
1565 1569 self.__initime = datatime
1566 1570 else:
1567 1571 self.__initime += deltatime
1568 1572
1569 1573 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1570 1574
1571 1575 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1572 1576
1573 1577 if n==1:
1574 1578 dataOut.flagNoData = False
1575 1579 return
1576 1580
1577 1581 if not self.__isConfig:
1578 1582 self.setup(n, timeInterval, overlapping)
1579 1583 self.__isConfig = True
1580 1584
1581 1585 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1582 1586 dataOut.data_spc,
1583 1587 dataOut.data_cspc,
1584 1588 dataOut.data_dc)
1585 1589
1586 1590 # dataOut.timeInterval *= n
1587 1591 dataOut.flagNoData = True
1588 1592
1589 1593 if self.__dataReady:
1590 1594
1591 1595 dataOut.data_spc = avgdata_spc
1592 1596 dataOut.data_cspc = avgdata_cspc
1593 1597 dataOut.data_dc = avgdata_dc
1594 1598
1595 1599 dataOut.nIncohInt *= self.n
1596 1600 dataOut.utctime = avgdatatime
1597 1601 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1598 1602 dataOut.timeInterval = self.__timeInterval*self.n
1599 1603 dataOut.flagNoData = False
1600 1604
1601 1605 class ProfileConcat(Operation):
1602 1606
1603 1607 __isConfig = False
1604 1608 buffer = None
1605 1609
1606 1610 def __init__(self):
1607 1611
1608 1612 self.profileIndex = 0
1609 1613
1610 1614 def reset(self):
1611 1615 self.buffer = numpy.zeros_like(self.buffer)
1612 1616 self.start_index = 0
1613 1617 self.times = 1
1614 1618
1615 1619 def setup(self, data, m, n=1):
1616 1620 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
1617 1621 self.profiles = data.shape[1]
1618 1622 self.start_index = 0
1619 1623 self.times = 1
1620 1624
1621 1625 def concat(self, data):
1622 1626
1623 1627 self.buffer[:,self.start_index:self.profiles*self.times] = data.copy()
1624 1628 self.start_index = self.start_index + self.profiles
1625 1629
1626 1630 def run(self, dataOut, m):
1627 1631
1628 1632 dataOut.flagNoData = True
1629 1633
1630 1634 if not self.__isConfig:
1631 1635 self.setup(dataOut.data, m, 1)
1632 1636 self.__isConfig = True
1633 1637
1634 1638 self.concat(dataOut.data)
1635 1639 self.times += 1
1636 1640 if self.times > m:
1637 1641 dataOut.data = self.buffer
1638 1642 self.reset()
1639 1643 dataOut.flagNoData = False
1640 1644 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
1641 1645 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1642 1646 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5
1643 1647 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
1644 1648
1645 1649
1646 1650
1647 1651 class ProfileSelector(Operation):
1648 1652
1649 1653 profileIndex = None
1650 1654 # Tamanho total de los perfiles
1651 1655 nProfiles = None
1652 1656
1653 1657 def __init__(self):
1654 1658
1655 1659 self.profileIndex = 0
1656 1660
1657 1661 def incIndex(self):
1658 1662 self.profileIndex += 1
1659 1663
1660 1664 if self.profileIndex >= self.nProfiles:
1661 1665 self.profileIndex = 0
1662 1666
1663 1667 def isProfileInRange(self, minIndex, maxIndex):
1664 1668
1665 1669 if self.profileIndex < minIndex:
1666 1670 return False
1667 1671
1668 1672 if self.profileIndex > maxIndex:
1669 1673 return False
1670 1674
1671 1675 return True
1672 1676
1673 1677 def isProfileInList(self, profileList):
1674 1678
1675 1679 if self.profileIndex not in profileList:
1676 1680 return False
1677 1681
1678 1682 return True
1679 1683
1680 1684 def run(self, dataOut, profileList=None, profileRangeList=None):
1681 1685
1682 1686 dataOut.flagNoData = True
1683 1687 self.nProfiles = dataOut.nProfiles
1684 1688
1685 1689 if profileList != None:
1686 1690 if self.isProfileInList(profileList):
1687 1691 dataOut.flagNoData = False
1688 1692
1689 1693 self.incIndex()
1690 1694 return 1
1691 1695
1692 1696
1693 1697 elif profileRangeList != None:
1694 1698 minIndex = profileRangeList[0]
1695 1699 maxIndex = profileRangeList[1]
1696 1700 if self.isProfileInRange(minIndex, maxIndex):
1697 1701 dataOut.flagNoData = False
1698 1702
1699 1703 self.incIndex()
1700 1704 return 1
1701 1705
1702 1706 else:
1703 1707 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1704 1708
1705 1709 return 0
1706 1710
1707 1711 class SpectraHeisProc(ProcessingUnit):
1708 1712 def __init__(self):
1709 1713 self.objectDict = {}
1710 1714 # self.buffer = None
1711 1715 # self.firstdatatime = None
1712 1716 # self.profIndex = 0
1713 1717 self.dataOut = SpectraHeis()
1714 1718
1715 1719 def __updateObjFromInput(self):
1716 1720 self.dataOut.timeZone = self.dataIn.timeZone
1717 1721 self.dataOut.dstFlag = self.dataIn.dstFlag
1718 1722 self.dataOut.errorCount = self.dataIn.errorCount
1719 1723 self.dataOut.useLocalTime = self.dataIn.useLocalTime
1720 1724
1721 1725 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
1722 1726 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
1723 1727 self.dataOut.channelList = self.dataIn.channelList
1724 1728 self.dataOut.heightList = self.dataIn.heightList
1725 1729 # self.dataOut.dtype = self.dataIn.dtype
1726 1730 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
1727 1731 # self.dataOut.nHeights = self.dataIn.nHeights
1728 1732 # self.dataOut.nChannels = self.dataIn.nChannels
1729 1733 self.dataOut.nBaud = self.dataIn.nBaud
1730 1734 self.dataOut.nCode = self.dataIn.nCode
1731 1735 self.dataOut.code = self.dataIn.code
1732 1736 # self.dataOut.nProfiles = 1
1733 1737 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
1734 1738 self.dataOut.nFFTPoints = self.dataIn.nHeights
1735 1739 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
1736 1740 # self.dataOut.flagNoData = self.dataIn.flagNoData
1737 1741 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
1738 1742 self.dataOut.utctime = self.dataIn.utctime
1739 1743 # self.dataOut.utctime = self.firstdatatime
1740 1744 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
1741 1745 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
1742 1746 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
1743 1747 self.dataOut.nCohInt = self.dataIn.nCohInt
1744 1748 self.dataOut.nIncohInt = 1
1745 1749 self.dataOut.ippSeconds= self.dataIn.ippSeconds
1746 1750 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
1747 1751
1748 1752 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
1749 1753 # self.dataOut.set=self.dataIn.set
1750 1754 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
1751 1755
1752 1756
1753 1757 def __updateObjFromFits(self):
1754 1758 self.dataOut.utctime = self.dataIn.utctime
1755 1759 self.dataOut.channelIndexList = self.dataIn.channelIndexList
1756 1760
1757 1761 self.dataOut.channelList = self.dataIn.channelList
1758 1762 self.dataOut.heightList = self.dataIn.heightList
1759 1763 self.dataOut.data_spc = self.dataIn.data
1760 1764 self.dataOut.timeInterval = self.dataIn.timeInterval
1761 1765 self.dataOut.timeZone = self.dataIn.timeZone
1762 1766 self.dataOut.useLocalTime = True
1763 1767 # self.dataOut.
1764 1768 # self.dataOut.
1765 1769
1766 1770 def __getFft(self):
1767 1771
1768 1772 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
1769 1773 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
1770 1774 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
1771 1775 self.dataOut.data_spc = spc
1772 1776
1773 1777 def init(self):
1774 1778
1775 1779 self.dataOut.flagNoData = True
1776 1780
1777 1781 if self.dataIn.type == "Fits":
1778 1782 self.__updateObjFromFits()
1779 1783 self.dataOut.flagNoData = False
1780 1784 return
1781 1785
1782 1786 if self.dataIn.type == "SpectraHeis":
1783 1787 self.dataOut.copy(self.dataIn)
1784 1788 return
1785 1789
1786 1790 if self.dataIn.type == "Voltage":
1787 1791 self.__updateObjFromInput()
1788 1792 self.__getFft()
1789 1793 self.dataOut.flagNoData = False
1790 1794
1791 1795 return
1792 1796
1793 1797 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
1794 1798
1795 1799
1796 1800 def selectChannels(self, channelList):
1797 1801
1798 1802 channelIndexList = []
1799 1803
1800 1804 for channel in channelList:
1801 1805 index = self.dataOut.channelList.index(channel)
1802 1806 channelIndexList.append(index)
1803 1807
1804 1808 self.selectChannelsByIndex(channelIndexList)
1805 1809
1806 1810 def selectChannelsByIndex(self, channelIndexList):
1807 1811 """
1808 1812 Selecciona un bloque de datos en base a canales segun el channelIndexList
1809 1813
1810 1814 Input:
1811 1815 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
1812 1816
1813 1817 Affected:
1814 1818 self.dataOut.data
1815 1819 self.dataOut.channelIndexList
1816 1820 self.dataOut.nChannels
1817 1821 self.dataOut.m_ProcessingHeader.totalSpectra
1818 1822 self.dataOut.systemHeaderObj.numChannels
1819 1823 self.dataOut.m_ProcessingHeader.blockSize
1820 1824
1821 1825 Return:
1822 1826 None
1823 1827 """
1824 1828
1825 1829 for channelIndex in channelIndexList:
1826 1830 if channelIndex not in self.dataOut.channelIndexList:
1827 1831 print channelIndexList
1828 1832 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
1829 1833
1830 1834 nChannels = len(channelIndexList)
1831 1835
1832 1836 data_spc = self.dataOut.data_spc[channelIndexList,:]
1833 1837
1834 1838 self.dataOut.data_spc = data_spc
1835 1839 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
1836 1840
1837 1841 return 1
1838 1842
1839 1843 class IncohInt4SpectraHeis(Operation):
1840 1844
1841 1845 __isConfig = False
1842 1846
1843 1847 __profIndex = 0
1844 1848 __withOverapping = False
1845 1849
1846 1850 __byTime = False
1847 1851 __initime = None
1848 1852 __lastdatatime = None
1849 1853 __integrationtime = None
1850 1854
1851 1855 __buffer = None
1852 1856
1853 1857 __dataReady = False
1854 1858
1855 1859 n = None
1856 1860
1857 1861
1858 1862 def __init__(self):
1859 1863
1860 1864 self.__isConfig = False
1861 1865
1862 1866 def setup(self, n=None, timeInterval=None, overlapping=False):
1863 1867 """
1864 1868 Set the parameters of the integration class.
1865 1869
1866 1870 Inputs:
1867 1871
1868 1872 n : Number of coherent integrations
1869 1873 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1870 1874 overlapping :
1871 1875
1872 1876 """
1873 1877
1874 1878 self.__initime = None
1875 1879 self.__lastdatatime = 0
1876 1880 self.__buffer = None
1877 1881 self.__dataReady = False
1878 1882
1879 1883
1880 1884 if n == None and timeInterval == None:
1881 1885 raise ValueError, "n or timeInterval should be specified ..."
1882 1886
1883 1887 if n != None:
1884 1888 self.n = n
1885 1889 self.__byTime = False
1886 1890 else:
1887 1891 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
1888 1892 self.n = 9999
1889 1893 self.__byTime = True
1890 1894
1891 1895 if overlapping:
1892 1896 self.__withOverapping = True
1893 1897 self.__buffer = None
1894 1898 else:
1895 1899 self.__withOverapping = False
1896 1900 self.__buffer = 0
1897 1901
1898 1902 self.__profIndex = 0
1899 1903
1900 1904 def putData(self, data):
1901 1905
1902 1906 """
1903 1907 Add a profile to the __buffer and increase in one the __profileIndex
1904 1908
1905 1909 """
1906 1910
1907 1911 if not self.__withOverapping:
1908 1912 self.__buffer += data.copy()
1909 1913 self.__profIndex += 1
1910 1914 return
1911 1915
1912 1916 #Overlapping data
1913 1917 nChannels, nHeis = data.shape
1914 1918 data = numpy.reshape(data, (1, nChannels, nHeis))
1915 1919
1916 1920 #If the buffer is empty then it takes the data value
1917 1921 if self.__buffer == None:
1918 1922 self.__buffer = data
1919 1923 self.__profIndex += 1
1920 1924 return
1921 1925
1922 1926 #If the buffer length is lower than n then stakcing the data value
1923 1927 if self.__profIndex < self.n:
1924 1928 self.__buffer = numpy.vstack((self.__buffer, data))
1925 1929 self.__profIndex += 1
1926 1930 return
1927 1931
1928 1932 #If the buffer length is equal to n then replacing the last buffer value with the data value
1929 1933 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
1930 1934 self.__buffer[self.n-1] = data
1931 1935 self.__profIndex = self.n
1932 1936 return
1933 1937
1934 1938
1935 1939 def pushData(self):
1936 1940 """
1937 1941 Return the sum of the last profiles and the profiles used in the sum.
1938 1942
1939 1943 Affected:
1940 1944
1941 1945 self.__profileIndex
1942 1946
1943 1947 """
1944 1948
1945 1949 if not self.__withOverapping:
1946 1950 data = self.__buffer
1947 1951 n = self.__profIndex
1948 1952
1949 1953 self.__buffer = 0
1950 1954 self.__profIndex = 0
1951 1955
1952 1956 return data, n
1953 1957
1954 1958 #Integration with Overlapping
1955 1959 data = numpy.sum(self.__buffer, axis=0)
1956 1960 n = self.__profIndex
1957 1961
1958 1962 return data, n
1959 1963
1960 1964 def byProfiles(self, data):
1961 1965
1962 1966 self.__dataReady = False
1963 1967 avgdata = None
1964 1968 n = None
1965 1969
1966 1970 self.putData(data)
1967 1971
1968 1972 if self.__profIndex == self.n:
1969 1973
1970 1974 avgdata, n = self.pushData()
1971 1975 self.__dataReady = True
1972 1976
1973 1977 return avgdata
1974 1978
1975 1979 def byTime(self, data, datatime):
1976 1980
1977 1981 self.__dataReady = False
1978 1982 avgdata = None
1979 1983 n = None
1980 1984
1981 1985 self.putData(data)
1982 1986
1983 1987 if (datatime - self.__initime) >= self.__integrationtime:
1984 1988 avgdata, n = self.pushData()
1985 1989 self.n = n
1986 1990 self.__dataReady = True
1987 1991
1988 1992 return avgdata
1989 1993
1990 1994 def integrate(self, data, datatime=None):
1991 1995
1992 1996 if self.__initime == None:
1993 1997 self.__initime = datatime
1994 1998
1995 1999 if self.__byTime:
1996 2000 avgdata = self.byTime(data, datatime)
1997 2001 else:
1998 2002 avgdata = self.byProfiles(data)
1999 2003
2000 2004
2001 2005 self.__lastdatatime = datatime
2002 2006
2003 2007 if avgdata == None:
2004 2008 return None, None
2005 2009
2006 2010 avgdatatime = self.__initime
2007 2011
2008 2012 deltatime = datatime -self.__lastdatatime
2009 2013
2010 2014 if not self.__withOverapping:
2011 2015 self.__initime = datatime
2012 2016 else:
2013 2017 self.__initime += deltatime
2014 2018
2015 2019 return avgdata, avgdatatime
2016 2020
2017 2021 def run(self, dataOut, **kwargs):
2018 2022
2019 2023 if not self.__isConfig:
2020 2024 self.setup(**kwargs)
2021 2025 self.__isConfig = True
2022 2026
2023 2027 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
2024 2028
2025 2029 # dataOut.timeInterval *= n
2026 2030 dataOut.flagNoData = True
2027 2031
2028 2032 if self.__dataReady:
2029 2033 dataOut.data_spc = avgdata
2030 2034 dataOut.nIncohInt *= self.n
2031 2035 # dataOut.nCohInt *= self.n
2032 2036 dataOut.utctime = avgdatatime
2033 2037 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
2034 2038 # dataOut.timeInterval = self.__timeInterval*self.n
2035 2039 dataOut.flagNoData = False
2036 2040
2037 2041
2038 2042
2039 2043
2040 2044 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now