##// END OF EJS Templates
Nueva clase de ploteo SNRPlot
Daniel Valdez -
r469:b302bf20d2ac
parent child
Show More
@@ -1,1780 +1,2000
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 class SNRPlot(Figure):
216
217 __isConfig = None
218 __nsubplots = None
219
220 WIDTHPROF = None
221 HEIGHTPROF = None
222 PREFIX = 'snr'
223
224 def __init__(self):
225
226 self.timerange = 2*60*60
227 self.__isConfig = False
228 self.__nsubplots = 1
229
230 self.WIDTH = 800
231 self.HEIGHT = 150
232 self.WIDTHPROF = 120
233 self.HEIGHTPROF = 0
234 self.counter_imagwr = 0
235
236 self.PLOT_CODE = 0
237 self.FTP_WEI = None
238 self.EXP_CODE = None
239 self.SUB_EXP_CODE = None
240 self.PLOT_POS = None
241
242 def getSubplots(self):
243
244 ncol = 1
245 nrow = self.nplots
246
247 return nrow, ncol
248
249 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
250
251 self.__showprofile = showprofile
252 self.nplots = nplots
253
254 ncolspan = 1
255 colspan = 1
256 if showprofile:
257 ncolspan = 7
258 colspan = 6
259 self.__nsubplots = 2
260
261 self.createFigure(id = id,
262 wintitle = wintitle,
263 widthplot = self.WIDTH + self.WIDTHPROF,
264 heightplot = self.HEIGHT + self.HEIGHTPROF,
265 show=show)
266
267 nrow, ncol = self.getSubplots()
268
269 counter = 0
270 for y in range(nrow):
271 for x in range(ncol):
272
273 if counter >= self.nplots:
274 break
275
276 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
277
278 if showprofile:
279 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
280
281 counter += 1
282
283 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
284 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
285 timerange=None,
286 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
287 server=None, folder=None, username=None, password=None,
288 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
289
290 """
291
292 Input:
293 dataOut :
294 id :
295 wintitle :
296 channelList :
297 showProfile :
298 xmin : None,
299 xmax : None,
300 ymin : None,
301 ymax : None,
302 zmin : None,
303 zmax : None
304 """
305
306 if channelList == None:
307 channelIndexList = dataOut.channelIndexList
308 else:
309 channelIndexList = []
310 for channel in channelList:
311 if channel not in dataOut.channelList:
312 raise ValueError, "Channel %d is not in dataOut.channelList"
313 channelIndexList.append(dataOut.channelList.index(channel))
314
315 if timerange != None:
316 self.timerange = timerange
317
318 tmin = None
319 tmax = None
320 factor = dataOut.normFactor
321 x = dataOut.getTimeRange()
322 y = dataOut.getHeiRange()
323
324 z = dataOut.data_spc[channelIndexList,:,:]/factor
325 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
326 avg = numpy.average(z, axis=1)
327
328 avgdB = 10.*numpy.log10(avg)
329
330 noise = dataOut.getNoise()/factor
331 noisedB = 10.*numpy.log10(noise)
332
333 SNR = numpy.transpose(numpy.divide(avg.T,noise))
334
335 SNR_dB = 10.*numpy.log10(SNR)
336
337 #SNR_dB = numpy.transpose(numpy.subtract(avgdB.T, noisedB))
338
339 # thisDatetime = dataOut.datatime
340 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
341 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
342 xlabel = ""
343 ylabel = "Range (Km)"
344
345 if not self.__isConfig:
346
347 nplots = len(channelIndexList)
348
349 self.setup(id=id,
350 nplots=nplots,
351 wintitle=wintitle,
352 showprofile=showprofile,
353 show=show)
354
355 tmin, tmax = self.getTimeLim(x, xmin, xmax)
356 if ymin == None: ymin = numpy.nanmin(y)
357 if ymax == None: ymax = numpy.nanmax(y)
358 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
359 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
360
361 self.FTP_WEI = ftp_wei
362 self.EXP_CODE = exp_code
363 self.SUB_EXP_CODE = sub_exp_code
364 self.PLOT_POS = plot_pos
365
366 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
367 self.__isConfig = True
368
369
370 self.setWinTitle(title)
371
372 for i in range(self.nplots):
373 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
374 axes = self.axesList[i*self.__nsubplots]
375 zdB = SNR_dB[i].reshape((1,-1))
376 axes.pcolorbuffer(x, y, zdB,
377 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
378 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
379 ticksize=9, cblabel='', cbsize="1%")
380
381 # if self.__showprofile:
382 # axes = self.axesList[i*self.__nsubplots +1]
383 # axes.pline(avgdB[i], y,
384 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
385 # xlabel='dB', ylabel='', title='',
386 # ytick_visible=False,
387 # grid='x')
388 #
389 self.draw()
390
391 if lastone:
392 if dataOut.blocknow >= dataOut.last_block:
393 if figfile == None:
394 figfile = self.getFilename(name = self.name)
395 self.saveFigure(figpath, figfile)
396
397 if (save and not(lastone)):
398
399 self.counter_imagwr += 1
400 if (self.counter_imagwr==wr_period):
401 if figfile == None:
402 figfile = self.getFilename(name = self.name)
403 self.saveFigure(figpath, figfile)
404
405 if ftp:
406 #provisionalmente envia archivos en el formato de la web en tiempo real
407 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
408 path = '%s%03d' %(self.PREFIX, self.id)
409 ftp_file = os.path.join(path,'ftp','%s.png'%name)
410 self.saveFigure(figpath, ftp_file)
411 ftp_filename = os.path.join(figpath,ftp_file)
412 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
413 self.counter_imagwr = 0
414
415 self.counter_imagwr = 0
416
417 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
418
419 self.__isConfig = False
420
421 if lastone:
422 if figfile == None:
423 figfile = self.getFilename(name = self.name)
424 self.saveFigure(figpath, figfile)
425
426 if ftp:
427 #provisionalmente envia archivos en el formato de la web en tiempo real
428 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
429 path = '%s%03d' %(self.PREFIX, self.id)
430 ftp_file = os.path.join(path,'ftp','%s.png'%name)
431 self.saveFigure(figpath, ftp_file)
432 ftp_filename = os.path.join(figpath,ftp_file)
433 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
434
215 435
216 436 class RTIPlot(Figure):
217 437
218 438 __isConfig = None
219 439 __nsubplots = None
220 440
221 441 WIDTHPROF = None
222 442 HEIGHTPROF = None
223 443 PREFIX = 'rti'
224 444
225 445 def __init__(self):
226 446
227 447 self.timerange = 2*60*60
228 448 self.__isConfig = False
229 449 self.__nsubplots = 1
230 450
231 451 self.WIDTH = 800
232 452 self.HEIGHT = 150
233 453 self.WIDTHPROF = 120
234 454 self.HEIGHTPROF = 0
235 455 self.counter_imagwr = 0
236 456
237 457 self.PLOT_CODE = 0
238 458 self.FTP_WEI = None
239 459 self.EXP_CODE = None
240 460 self.SUB_EXP_CODE = None
241 461 self.PLOT_POS = None
242 462
243 463 def getSubplots(self):
244 464
245 465 ncol = 1
246 466 nrow = self.nplots
247 467
248 468 return nrow, ncol
249 469
250 470 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
251 471
252 472 self.__showprofile = showprofile
253 473 self.nplots = nplots
254 474
255 475 ncolspan = 1
256 476 colspan = 1
257 477 if showprofile:
258 478 ncolspan = 7
259 479 colspan = 6
260 480 self.__nsubplots = 2
261 481
262 482 self.createFigure(id = id,
263 483 wintitle = wintitle,
264 484 widthplot = self.WIDTH + self.WIDTHPROF,
265 485 heightplot = self.HEIGHT + self.HEIGHTPROF,
266 486 show=show)
267 487
268 488 nrow, ncol = self.getSubplots()
269 489
270 490 counter = 0
271 491 for y in range(nrow):
272 492 for x in range(ncol):
273 493
274 494 if counter >= self.nplots:
275 495 break
276 496
277 497 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
278 498
279 499 if showprofile:
280 500 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
281 501
282 502 counter += 1
283 503
284 504 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
285 505 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
286 506 timerange=None,
287 507 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
288 508 server=None, folder=None, username=None, password=None,
289 509 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
290 510
291 511 """
292 512
293 513 Input:
294 514 dataOut :
295 515 id :
296 516 wintitle :
297 517 channelList :
298 518 showProfile :
299 519 xmin : None,
300 520 xmax : None,
301 521 ymin : None,
302 522 ymax : None,
303 523 zmin : None,
304 524 zmax : None
305 525 """
306 526
307 527 if channelList == None:
308 528 channelIndexList = dataOut.channelIndexList
309 529 else:
310 530 channelIndexList = []
311 531 for channel in channelList:
312 532 if channel not in dataOut.channelList:
313 533 raise ValueError, "Channel %d is not in dataOut.channelList"
314 534 channelIndexList.append(dataOut.channelList.index(channel))
315 535
316 536 if timerange != None:
317 537 self.timerange = timerange
318 538
319 539 tmin = None
320 540 tmax = None
321 541 factor = dataOut.normFactor
322 542 x = dataOut.getTimeRange()
323 543 y = dataOut.getHeiRange()
324 544
325 545 z = dataOut.data_spc[channelIndexList,:,:]/factor
326 546 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
327 547 avg = numpy.average(z, axis=1)
328 548
329 549 avgdB = 10.*numpy.log10(avg)
330 550
331 551
332 552 # thisDatetime = dataOut.datatime
333 553 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
334 554 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
335 555 xlabel = ""
336 556 ylabel = "Range (Km)"
337 557
338 558 if not self.__isConfig:
339 559
340 560 nplots = len(channelIndexList)
341 561
342 562 self.setup(id=id,
343 563 nplots=nplots,
344 564 wintitle=wintitle,
345 565 showprofile=showprofile,
346 566 show=show)
347 567
348 568 tmin, tmax = self.getTimeLim(x, xmin, xmax)
349 569 if ymin == None: ymin = numpy.nanmin(y)
350 570 if ymax == None: ymax = numpy.nanmax(y)
351 571 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
352 572 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
353 573
354 574 self.FTP_WEI = ftp_wei
355 575 self.EXP_CODE = exp_code
356 576 self.SUB_EXP_CODE = sub_exp_code
357 577 self.PLOT_POS = plot_pos
358 578
359 579 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
360 580 self.__isConfig = True
361 581
362 582
363 583 self.setWinTitle(title)
364 584
365 585 for i in range(self.nplots):
366 586 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
367 587 axes = self.axesList[i*self.__nsubplots]
368 588 zdB = avgdB[i].reshape((1,-1))
369 589 axes.pcolorbuffer(x, y, zdB,
370 590 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
371 591 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
372 592 ticksize=9, cblabel='', cbsize="1%")
373 593
374 594 if self.__showprofile:
375 595 axes = self.axesList[i*self.__nsubplots +1]
376 596 axes.pline(avgdB[i], y,
377 597 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
378 598 xlabel='dB', ylabel='', title='',
379 599 ytick_visible=False,
380 600 grid='x')
381 601
382 602 self.draw()
383 603
384 604 if lastone:
385 605 if dataOut.blocknow >= dataOut.last_block:
386 606 if figfile == None:
387 607 figfile = self.getFilename(name = self.name)
388 608 self.saveFigure(figpath, figfile)
389 609
390 610 if (save and not(lastone)):
391 611
392 612 self.counter_imagwr += 1
393 613 if (self.counter_imagwr==wr_period):
394 614 if figfile == None:
395 615 figfile = self.getFilename(name = self.name)
396 616 self.saveFigure(figpath, figfile)
397 617
398 618 if ftp:
399 619 #provisionalmente envia archivos en el formato de la web en tiempo real
400 620 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
401 621 path = '%s%03d' %(self.PREFIX, self.id)
402 622 ftp_file = os.path.join(path,'ftp','%s.png'%name)
403 623 self.saveFigure(figpath, ftp_file)
404 624 ftp_filename = os.path.join(figpath,ftp_file)
405 625 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
406 626 self.counter_imagwr = 0
407 627
408 628 self.counter_imagwr = 0
409 629
410 630 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
411 631
412 632 self.__isConfig = False
413 633
414 634 if lastone:
415 635 if figfile == None:
416 636 figfile = self.getFilename(name = self.name)
417 637 self.saveFigure(figpath, figfile)
418 638
419 639 if ftp:
420 640 #provisionalmente envia archivos en el formato de la web en tiempo real
421 641 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
422 642 path = '%s%03d' %(self.PREFIX, self.id)
423 643 ftp_file = os.path.join(path,'ftp','%s.png'%name)
424 644 self.saveFigure(figpath, ftp_file)
425 645 ftp_filename = os.path.join(figpath,ftp_file)
426 646 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
427 647
428 648
429 649 class SpectraPlot(Figure):
430 650
431 651 __isConfig = None
432 652 __nsubplots = None
433 653
434 654 WIDTHPROF = None
435 655 HEIGHTPROF = None
436 656 PREFIX = 'spc'
437 657
438 658 def __init__(self):
439 659
440 660 self.__isConfig = False
441 661 self.__nsubplots = 1
442 662
443 663 self.WIDTH = 280
444 664 self.HEIGHT = 250
445 665 self.WIDTHPROF = 120
446 666 self.HEIGHTPROF = 0
447 667 self.counter_imagwr = 0
448 668
449 669 self.PLOT_CODE = 1
450 670 self.FTP_WEI = None
451 671 self.EXP_CODE = None
452 672 self.SUB_EXP_CODE = None
453 673 self.PLOT_POS = None
454 674
455 675 def getSubplots(self):
456 676
457 677 ncol = int(numpy.sqrt(self.nplots)+0.9)
458 678 nrow = int(self.nplots*1./ncol + 0.9)
459 679
460 680 return nrow, ncol
461 681
462 682 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
463 683
464 684 self.__showprofile = showprofile
465 685 self.nplots = nplots
466 686
467 687 ncolspan = 1
468 688 colspan = 1
469 689 if showprofile:
470 690 ncolspan = 3
471 691 colspan = 2
472 692 self.__nsubplots = 2
473 693
474 694 self.createFigure(id = id,
475 695 wintitle = wintitle,
476 696 widthplot = self.WIDTH + self.WIDTHPROF,
477 697 heightplot = self.HEIGHT + self.HEIGHTPROF,
478 698 show=show)
479 699
480 700 nrow, ncol = self.getSubplots()
481 701
482 702 counter = 0
483 703 for y in range(nrow):
484 704 for x in range(ncol):
485 705
486 706 if counter >= self.nplots:
487 707 break
488 708
489 709 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
490 710
491 711 if showprofile:
492 712 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
493 713
494 714 counter += 1
495 715
496 716 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
497 717 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
498 718 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
499 719 server=None, folder=None, username=None, password=None,
500 720 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
501 721
502 722 """
503 723
504 724 Input:
505 725 dataOut :
506 726 id :
507 727 wintitle :
508 728 channelList :
509 729 showProfile :
510 730 xmin : None,
511 731 xmax : None,
512 732 ymin : None,
513 733 ymax : None,
514 734 zmin : None,
515 735 zmax : None
516 736 """
517 737
518 738 if realtime:
519 739 if not(isRealtime(utcdatatime = dataOut.utctime)):
520 740 print 'Skipping this plot function'
521 741 return
522 742
523 743 if channelList == None:
524 744 channelIndexList = dataOut.channelIndexList
525 745 else:
526 746 channelIndexList = []
527 747 for channel in channelList:
528 748 if channel not in dataOut.channelList:
529 749 raise ValueError, "Channel %d is not in dataOut.channelList"
530 750 channelIndexList.append(dataOut.channelList.index(channel))
531 751 factor = dataOut.normFactor
532 752 x = dataOut.getVelRange(1)
533 753 y = dataOut.getHeiRange()
534 754
535 755 z = dataOut.data_spc[channelIndexList,:,:]/factor
536 756 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
537 757 avg = numpy.average(z, axis=1)
538 758 noise = dataOut.getNoise()/factor
539 759
540 760 zdB = 10*numpy.log10(z)
541 761 avgdB = 10*numpy.log10(avg)
542 762 noisedB = 10*numpy.log10(noise)
543 763
544 764 #thisDatetime = dataOut.datatime
545 765 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
546 766 title = wintitle + " Spectra"
547 767 xlabel = "Velocity (m/s)"
548 768 ylabel = "Range (Km)"
549 769
550 770 if not self.__isConfig:
551 771
552 772 nplots = len(channelIndexList)
553 773
554 774 self.setup(id=id,
555 775 nplots=nplots,
556 776 wintitle=wintitle,
557 777 showprofile=showprofile,
558 778 show=show)
559 779
560 780 if xmin == None: xmin = numpy.nanmin(x)
561 781 if xmax == None: xmax = numpy.nanmax(x)
562 782 if ymin == None: ymin = numpy.nanmin(y)
563 783 if ymax == None: ymax = numpy.nanmax(y)
564 784 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
565 785 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
566 786
567 787 self.FTP_WEI = ftp_wei
568 788 self.EXP_CODE = exp_code
569 789 self.SUB_EXP_CODE = sub_exp_code
570 790 self.PLOT_POS = plot_pos
571 791
572 792 self.__isConfig = True
573 793
574 794 self.setWinTitle(title)
575 795
576 796 for i in range(self.nplots):
577 797 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
578 798 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
579 799 axes = self.axesList[i*self.__nsubplots]
580 800 axes.pcolor(x, y, zdB[i,:,:],
581 801 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
582 802 xlabel=xlabel, ylabel=ylabel, title=title,
583 803 ticksize=9, cblabel='')
584 804
585 805 if self.__showprofile:
586 806 axes = self.axesList[i*self.__nsubplots +1]
587 807 axes.pline(avgdB[i], y,
588 808 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
589 809 xlabel='dB', ylabel='', title='',
590 810 ytick_visible=False,
591 811 grid='x')
592 812
593 813 noiseline = numpy.repeat(noisedB[i], len(y))
594 814 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
595 815
596 816 self.draw()
597 817
598 818 if save:
599 819
600 820 self.counter_imagwr += 1
601 821 if (self.counter_imagwr==wr_period):
602 822 if figfile == None:
603 823 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
604 824 figfile = self.getFilename(name = str_datetime)
605 825
606 826 self.saveFigure(figpath, figfile)
607 827
608 828 if ftp:
609 829 #provisionalmente envia archivos en el formato de la web en tiempo real
610 830 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
611 831 path = '%s%03d' %(self.PREFIX, self.id)
612 832 ftp_file = os.path.join(path,'ftp','%s.png'%name)
613 833 self.saveFigure(figpath, ftp_file)
614 834 ftp_filename = os.path.join(figpath,ftp_file)
615 835 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
616 836 self.counter_imagwr = 0
617 837
618 838
619 839 self.counter_imagwr = 0
620 840
621 841
622 842 class Scope(Figure):
623 843
624 844 __isConfig = None
625 845
626 846 def __init__(self):
627 847
628 848 self.__isConfig = False
629 849 self.WIDTH = 600
630 850 self.HEIGHT = 200
631 851 self.counter_imagwr = 0
632 852
633 853 def getSubplots(self):
634 854
635 855 nrow = self.nplots
636 856 ncol = 3
637 857 return nrow, ncol
638 858
639 859 def setup(self, id, nplots, wintitle, show):
640 860
641 861 self.nplots = nplots
642 862
643 863 self.createFigure(id=id,
644 864 wintitle=wintitle,
645 865 show=show)
646 866
647 867 nrow,ncol = self.getSubplots()
648 868 colspan = 3
649 869 rowspan = 1
650 870
651 871 for i in range(nplots):
652 872 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
653 873
654 874
655 875
656 876 def run(self, dataOut, id, wintitle="", channelList=None,
657 877 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
658 878 figpath='./', figfile=None, show=True, wr_period=1,
659 879 server=None, folder=None, username=None, password=None):
660 880
661 881 """
662 882
663 883 Input:
664 884 dataOut :
665 885 id :
666 886 wintitle :
667 887 channelList :
668 888 xmin : None,
669 889 xmax : None,
670 890 ymin : None,
671 891 ymax : None,
672 892 """
673 893
674 894 if channelList == None:
675 895 channelIndexList = dataOut.channelIndexList
676 896 else:
677 897 channelIndexList = []
678 898 for channel in channelList:
679 899 if channel not in dataOut.channelList:
680 900 raise ValueError, "Channel %d is not in dataOut.channelList"
681 901 channelIndexList.append(dataOut.channelList.index(channel))
682 902
683 903 x = dataOut.heightList
684 904 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
685 905 y = y.real
686 906
687 907 #thisDatetime = dataOut.datatime
688 908 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
689 909 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
690 910 xlabel = "Range (Km)"
691 911 ylabel = "Intensity"
692 912
693 913 if not self.__isConfig:
694 914 nplots = len(channelIndexList)
695 915
696 916 self.setup(id=id,
697 917 nplots=nplots,
698 918 wintitle=wintitle,
699 919 show=show)
700 920
701 921 if xmin == None: xmin = numpy.nanmin(x)
702 922 if xmax == None: xmax = numpy.nanmax(x)
703 923 if ymin == None: ymin = numpy.nanmin(y)
704 924 if ymax == None: ymax = numpy.nanmax(y)
705 925
706 926 self.__isConfig = True
707 927
708 928 self.setWinTitle(title)
709 929
710 930 for i in range(len(self.axesList)):
711 931 title = "Channel %d" %(i)
712 932 axes = self.axesList[i]
713 933 ychannel = y[i,:]
714 934 axes.pline(x, ychannel,
715 935 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
716 936 xlabel=xlabel, ylabel=ylabel, title=title)
717 937
718 938 self.draw()
719 939
720 940 if save:
721 941 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
722 942 if figfile == None:
723 943 figfile = self.getFilename(name = date)
724 944
725 945 self.saveFigure(figpath, figfile)
726 946
727 947 self.counter_imagwr += 1
728 948 if (ftp and (self.counter_imagwr==wr_period)):
729 949 ftp_filename = os.path.join(figpath,figfile)
730 950 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
731 951 self.counter_imagwr = 0
732 952
733 953 class PowerProfilePlot(Figure):
734 954 __isConfig = None
735 955 __nsubplots = None
736 956
737 957 WIDTHPROF = None
738 958 HEIGHTPROF = None
739 959 PREFIX = 'spcprofile'
740 960
741 961 def __init__(self):
742 962 self.__isConfig = False
743 963 self.__nsubplots = 1
744 964
745 965 self.WIDTH = 300
746 966 self.HEIGHT = 500
747 967 self.counter_imagwr = 0
748 968
749 969 def getSubplots(self):
750 970 ncol = 1
751 971 nrow = 1
752 972
753 973 return nrow, ncol
754 974
755 975 def setup(self, id, nplots, wintitle, show):
756 976
757 977 self.nplots = nplots
758 978
759 979 ncolspan = 1
760 980 colspan = 1
761 981
762 982 self.createFigure(id = id,
763 983 wintitle = wintitle,
764 984 widthplot = self.WIDTH,
765 985 heightplot = self.HEIGHT,
766 986 show=show)
767 987
768 988 nrow, ncol = self.getSubplots()
769 989
770 990 counter = 0
771 991 for y in range(nrow):
772 992 for x in range(ncol):
773 993 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
774 994
775 995 def run(self, dataOut, id, wintitle="", channelList=None,
776 996 xmin=None, xmax=None, ymin=None, ymax=None,
777 997 save=False, figpath='./', figfile=None, show=True, wr_period=1,
778 998 server=None, folder=None, username=None, password=None,):
779 999
780 1000 if channelList == None:
781 1001 channelIndexList = dataOut.channelIndexList
782 1002 channelList = dataOut.channelList
783 1003 else:
784 1004 channelIndexList = []
785 1005 for channel in channelList:
786 1006 if channel not in dataOut.channelList:
787 1007 raise ValueError, "Channel %d is not in dataOut.channelList"
788 1008 channelIndexList.append(dataOut.channelList.index(channel))
789 1009
790 1010 factor = dataOut.normFactor
791 1011 y = dataOut.getHeiRange()
792 1012 x = dataOut.data_spc[channelIndexList,:,:]/factor
793 1013 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
794 1014 avg = numpy.average(x, axis=1)
795 1015
796 1016 avgdB = 10*numpy.log10(avg)
797 1017
798 1018 #thisDatetime = dataOut.datatime
799 1019 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
800 1020 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
801 1021 xlabel = "dB"
802 1022 ylabel = "Range (Km)"
803 1023
804 1024 if not self.__isConfig:
805 1025
806 1026 nplots = 1
807 1027
808 1028 self.setup(id=id,
809 1029 nplots=nplots,
810 1030 wintitle=wintitle,
811 1031 show=show)
812 1032
813 1033 if ymin == None: ymin = numpy.nanmin(y)
814 1034 if ymax == None: ymax = numpy.nanmax(y)
815 1035 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
816 1036 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
817 1037
818 1038 self.__isConfig = True
819 1039
820 1040 self.setWinTitle(title)
821 1041
822 1042
823 1043 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
824 1044 axes = self.axesList[0]
825 1045
826 1046 legendlabels = ["channel %d"%x for x in channelList]
827 1047 axes.pmultiline(avgdB, y,
828 1048 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
829 1049 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
830 1050 ytick_visible=True, nxticks=5,
831 1051 grid='x')
832 1052
833 1053 self.draw()
834 1054
835 1055 if save:
836 1056 date = thisDatetime.strftime("%Y%m%d")
837 1057 if figfile == None:
838 1058 figfile = self.getFilename(name = date)
839 1059
840 1060 self.saveFigure(figpath, figfile)
841 1061
842 1062 self.counter_imagwr += 1
843 1063 if (ftp and (self.counter_imagwr==wr_period)):
844 1064 ftp_filename = os.path.join(figpath,figfile)
845 1065 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
846 1066 self.counter_imagwr = 0
847 1067
848 1068 class CoherenceMap(Figure):
849 1069 __isConfig = None
850 1070 __nsubplots = None
851 1071
852 1072 WIDTHPROF = None
853 1073 HEIGHTPROF = None
854 1074 PREFIX = 'cmap'
855 1075
856 1076 def __init__(self):
857 1077 self.timerange = 2*60*60
858 1078 self.__isConfig = False
859 1079 self.__nsubplots = 1
860 1080
861 1081 self.WIDTH = 800
862 1082 self.HEIGHT = 150
863 1083 self.WIDTHPROF = 120
864 1084 self.HEIGHTPROF = 0
865 1085 self.counter_imagwr = 0
866 1086
867 1087 self.PLOT_CODE = 3
868 1088 self.FTP_WEI = None
869 1089 self.EXP_CODE = None
870 1090 self.SUB_EXP_CODE = None
871 1091 self.PLOT_POS = None
872 1092 self.counter_imagwr = 0
873 1093
874 1094 def getSubplots(self):
875 1095 ncol = 1
876 1096 nrow = self.nplots*2
877 1097
878 1098 return nrow, ncol
879 1099
880 1100 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
881 1101 self.__showprofile = showprofile
882 1102 self.nplots = nplots
883 1103
884 1104 ncolspan = 1
885 1105 colspan = 1
886 1106 if showprofile:
887 1107 ncolspan = 7
888 1108 colspan = 6
889 1109 self.__nsubplots = 2
890 1110
891 1111 self.createFigure(id = id,
892 1112 wintitle = wintitle,
893 1113 widthplot = self.WIDTH + self.WIDTHPROF,
894 1114 heightplot = self.HEIGHT + self.HEIGHTPROF,
895 1115 show=True)
896 1116
897 1117 nrow, ncol = self.getSubplots()
898 1118
899 1119 for y in range(nrow):
900 1120 for x in range(ncol):
901 1121
902 1122 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
903 1123
904 1124 if showprofile:
905 1125 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
906 1126
907 1127 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
908 1128 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
909 1129 timerange=None,
910 1130 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
911 1131 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
912 1132 server=None, folder=None, username=None, password=None,
913 1133 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
914 1134
915 1135 if pairsList == None:
916 1136 pairsIndexList = dataOut.pairsIndexList
917 1137 else:
918 1138 pairsIndexList = []
919 1139 for pair in pairsList:
920 1140 if pair not in dataOut.pairsList:
921 1141 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
922 1142 pairsIndexList.append(dataOut.pairsList.index(pair))
923 1143
924 1144 if timerange != None:
925 1145 self.timerange = timerange
926 1146
927 1147 if pairsIndexList == []:
928 1148 return
929 1149
930 1150 if len(pairsIndexList) > 4:
931 1151 pairsIndexList = pairsIndexList[0:4]
932 1152
933 1153 tmin = None
934 1154 tmax = None
935 1155 x = dataOut.getTimeRange()
936 1156 y = dataOut.getHeiRange()
937 1157
938 1158 #thisDatetime = dataOut.datatime
939 1159 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
940 1160 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
941 1161 xlabel = ""
942 1162 ylabel = "Range (Km)"
943 1163
944 1164 if not self.__isConfig:
945 1165 nplots = len(pairsIndexList)
946 1166 self.setup(id=id,
947 1167 nplots=nplots,
948 1168 wintitle=wintitle,
949 1169 showprofile=showprofile,
950 1170 show=show)
951 1171
952 1172 tmin, tmax = self.getTimeLim(x, xmin, xmax)
953 1173 if ymin == None: ymin = numpy.nanmin(y)
954 1174 if ymax == None: ymax = numpy.nanmax(y)
955 1175 if zmin == None: zmin = 0.
956 1176 if zmax == None: zmax = 1.
957 1177
958 1178 self.FTP_WEI = ftp_wei
959 1179 self.EXP_CODE = exp_code
960 1180 self.SUB_EXP_CODE = sub_exp_code
961 1181 self.PLOT_POS = plot_pos
962 1182
963 1183 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
964 1184
965 1185 self.__isConfig = True
966 1186
967 1187 self.setWinTitle(title)
968 1188
969 1189 for i in range(self.nplots):
970 1190
971 1191 pair = dataOut.pairsList[pairsIndexList[i]]
972 1192 # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
973 1193 # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
974 1194 # coherence = numpy.abs(avgcoherenceComplex)
975 1195
976 1196 ## coherence = numpy.abs(coherenceComplex)
977 1197 ## avg = numpy.average(coherence, axis=0)
978 1198
979 1199 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
980 1200 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
981 1201 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
982 1202
983 1203
984 1204 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
985 1205 coherence = numpy.abs(avgcoherenceComplex)
986 1206
987 1207 z = coherence.reshape((1,-1))
988 1208
989 1209 counter = 0
990 1210
991 1211 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
992 1212 axes = self.axesList[i*self.__nsubplots*2]
993 1213 axes.pcolorbuffer(x, y, z,
994 1214 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
995 1215 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
996 1216 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
997 1217
998 1218 if self.__showprofile:
999 1219 counter += 1
1000 1220 axes = self.axesList[i*self.__nsubplots*2 + counter]
1001 1221 axes.pline(coherence, y,
1002 1222 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
1003 1223 xlabel='', ylabel='', title='', ticksize=7,
1004 1224 ytick_visible=False, nxticks=5,
1005 1225 grid='x')
1006 1226
1007 1227 counter += 1
1008 1228 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
1009 1229 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1010 1230 # avg = numpy.average(phase, axis=0)
1011 1231 z = phase.reshape((1,-1))
1012 1232
1013 1233 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1014 1234 axes = self.axesList[i*self.__nsubplots*2 + counter]
1015 1235 axes.pcolorbuffer(x, y, z,
1016 1236 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
1017 1237 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1018 1238 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
1019 1239
1020 1240 if self.__showprofile:
1021 1241 counter += 1
1022 1242 axes = self.axesList[i*self.__nsubplots*2 + counter]
1023 1243 axes.pline(phase, y,
1024 1244 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
1025 1245 xlabel='', ylabel='', title='', ticksize=7,
1026 1246 ytick_visible=False, nxticks=4,
1027 1247 grid='x')
1028 1248
1029 1249 self.draw()
1030 1250
1031 1251 if save:
1032 1252
1033 1253 self.counter_imagwr += 1
1034 1254 if (self.counter_imagwr==wr_period):
1035 1255 if figfile == None:
1036 1256 figfile = self.getFilename(name = self.name)
1037 1257 self.saveFigure(figpath, figfile)
1038 1258
1039 1259 if ftp:
1040 1260 #provisionalmente envia archivos en el formato de la web en tiempo real
1041 1261 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1042 1262 path = '%s%03d' %(self.PREFIX, self.id)
1043 1263 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1044 1264 self.saveFigure(figpath, ftp_file)
1045 1265 ftp_filename = os.path.join(figpath,ftp_file)
1046 1266 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1047 1267 self.counter_imagwr = 0
1048 1268
1049 1269 self.counter_imagwr = 0
1050 1270
1051 1271
1052 1272 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1053 1273 self.__isConfig = False
1054 1274
1055 1275 class BeaconPhase(Figure):
1056 1276
1057 1277 __isConfig = None
1058 1278 __nsubplots = None
1059 1279
1060 1280 PREFIX = 'beacon_phase'
1061 1281
1062 1282 def __init__(self):
1063 1283
1064 1284 self.timerange = 24*60*60
1065 1285 self.__isConfig = False
1066 1286 self.__nsubplots = 1
1067 1287 self.counter_imagwr = 0
1068 1288 self.WIDTH = 600
1069 1289 self.HEIGHT = 300
1070 1290 self.WIDTHPROF = 120
1071 1291 self.HEIGHTPROF = 0
1072 1292 self.xdata = None
1073 1293 self.ydata = None
1074 1294
1075 1295 self.PLOT_CODE = 18
1076 1296 self.FTP_WEI = None
1077 1297 self.EXP_CODE = None
1078 1298 self.SUB_EXP_CODE = None
1079 1299 self.PLOT_POS = None
1080 1300
1081 1301 self.filename_phase = None
1082 1302
1083 1303 def getSubplots(self):
1084 1304
1085 1305 ncol = 1
1086 1306 nrow = 1
1087 1307
1088 1308 return nrow, ncol
1089 1309
1090 1310 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1091 1311
1092 1312 self.__showprofile = showprofile
1093 1313 self.nplots = nplots
1094 1314
1095 1315 ncolspan = 7
1096 1316 colspan = 6
1097 1317 self.__nsubplots = 2
1098 1318
1099 1319 self.createFigure(id = id,
1100 1320 wintitle = wintitle,
1101 1321 widthplot = self.WIDTH+self.WIDTHPROF,
1102 1322 heightplot = self.HEIGHT+self.HEIGHTPROF,
1103 1323 show=show)
1104 1324
1105 1325 nrow, ncol = self.getSubplots()
1106 1326
1107 1327 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1108 1328
1109 1329 def save_phase(self, filename_phase):
1110 1330 f = open(filename_phase,'w+')
1111 1331 f.write('\n\n')
1112 1332 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1113 1333 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1114 1334 f.close()
1115 1335
1116 1336 def save_data(self, filename_phase, data, data_datetime):
1117 1337 f=open(filename_phase,'a')
1118 1338 timetuple_data = data_datetime.timetuple()
1119 1339 day = str(timetuple_data.tm_mday)
1120 1340 month = str(timetuple_data.tm_mon)
1121 1341 year = str(timetuple_data.tm_year)
1122 1342 hour = str(timetuple_data.tm_hour)
1123 1343 minute = str(timetuple_data.tm_min)
1124 1344 second = str(timetuple_data.tm_sec)
1125 1345 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1126 1346 f.close()
1127 1347
1128 1348
1129 1349 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1130 1350 xmin=None, xmax=None, ymin=None, ymax=None,
1131 1351 timerange=None,
1132 1352 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1133 1353 server=None, folder=None, username=None, password=None,
1134 1354 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1135 1355
1136 1356 if pairsList == None:
1137 1357 pairsIndexList = dataOut.pairsIndexList
1138 1358 else:
1139 1359 pairsIndexList = []
1140 1360 for pair in pairsList:
1141 1361 if pair not in dataOut.pairsList:
1142 1362 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1143 1363 pairsIndexList.append(dataOut.pairsList.index(pair))
1144 1364
1145 1365 if pairsIndexList == []:
1146 1366 return
1147 1367
1148 1368 # if len(pairsIndexList) > 4:
1149 1369 # pairsIndexList = pairsIndexList[0:4]
1150 1370
1151 1371 if timerange != None:
1152 1372 self.timerange = timerange
1153 1373
1154 1374 tmin = None
1155 1375 tmax = None
1156 1376 x = dataOut.getTimeRange()
1157 1377 y = dataOut.getHeiRange()
1158 1378
1159 1379
1160 1380 #thisDatetime = dataOut.datatime
1161 1381 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1162 1382 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1163 1383 xlabel = "Local Time"
1164 1384 ylabel = "Phase"
1165 1385
1166 1386 nplots = len(pairsIndexList)
1167 1387 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1168 1388 phase_beacon = numpy.zeros(len(pairsIndexList))
1169 1389 for i in range(nplots):
1170 1390 pair = dataOut.pairsList[pairsIndexList[i]]
1171 1391 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
1172 1392 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
1173 1393 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
1174 1394 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1175 1395 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1176 1396
1177 1397 #print "Phase %d%d" %(pair[0], pair[1])
1178 1398 #print phase[dataOut.beacon_heiIndexList]
1179 1399
1180 1400 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1181 1401
1182 1402 if not self.__isConfig:
1183 1403
1184 1404 nplots = len(pairsIndexList)
1185 1405
1186 1406 self.setup(id=id,
1187 1407 nplots=nplots,
1188 1408 wintitle=wintitle,
1189 1409 showprofile=showprofile,
1190 1410 show=show)
1191 1411
1192 1412 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1193 1413 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1194 1414 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1195 1415
1196 1416 self.FTP_WEI = ftp_wei
1197 1417 self.EXP_CODE = exp_code
1198 1418 self.SUB_EXP_CODE = sub_exp_code
1199 1419 self.PLOT_POS = plot_pos
1200 1420
1201 1421 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1202 1422 self.__isConfig = True
1203 1423
1204 1424 self.xdata = numpy.array([])
1205 1425 self.ydata = numpy.array([])
1206 1426
1207 1427 #open file beacon phase
1208 1428 path = '%s%03d' %(self.PREFIX, self.id)
1209 1429 beacon_file = os.path.join(path,'%s.txt'%self.name)
1210 1430 self.filename_phase = os.path.join(figpath,beacon_file)
1211 1431 self.save_phase(self.filename_phase)
1212 1432
1213 1433
1214 1434 #store data beacon phase
1215 1435 self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1216 1436
1217 1437 self.setWinTitle(title)
1218 1438
1219 1439
1220 1440 title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1221 1441
1222 1442 legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1223 1443
1224 1444 axes = self.axesList[0]
1225 1445
1226 1446 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1227 1447
1228 1448 if len(self.ydata)==0:
1229 1449 self.ydata = phase_beacon.reshape(-1,1)
1230 1450 else:
1231 1451 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1232 1452
1233 1453
1234 1454 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1235 1455 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1236 1456 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1237 1457 XAxisAsTime=True, grid='both'
1238 1458 )
1239 1459
1240 1460 self.draw()
1241 1461
1242 1462 if save:
1243 1463
1244 1464 self.counter_imagwr += 1
1245 1465 if (self.counter_imagwr==wr_period):
1246 1466 if figfile == None:
1247 1467 figfile = self.getFilename(name = self.name)
1248 1468 self.saveFigure(figpath, figfile)
1249 1469
1250 1470 if ftp:
1251 1471 #provisionalmente envia archivos en el formato de la web en tiempo real
1252 1472 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1253 1473 path = '%s%03d' %(self.PREFIX, self.id)
1254 1474 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1255 1475 self.saveFigure(figpath, ftp_file)
1256 1476 ftp_filename = os.path.join(figpath,ftp_file)
1257 1477 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1258 1478
1259 1479 self.counter_imagwr = 0
1260 1480
1261 1481 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1262 1482 self.__isConfig = False
1263 1483 del self.xdata
1264 1484 del self.ydata
1265 1485
1266 1486
1267 1487
1268 1488
1269 1489 class Noise(Figure):
1270 1490
1271 1491 __isConfig = None
1272 1492 __nsubplots = None
1273 1493
1274 1494 PREFIX = 'noise'
1275 1495
1276 1496 def __init__(self):
1277 1497
1278 1498 self.timerange = 24*60*60
1279 1499 self.__isConfig = False
1280 1500 self.__nsubplots = 1
1281 1501 self.counter_imagwr = 0
1282 1502 self.WIDTH = 600
1283 1503 self.HEIGHT = 300
1284 1504 self.WIDTHPROF = 120
1285 1505 self.HEIGHTPROF = 0
1286 1506 self.xdata = None
1287 1507 self.ydata = None
1288 1508
1289 1509 self.PLOT_CODE = 77
1290 1510 self.FTP_WEI = None
1291 1511 self.EXP_CODE = None
1292 1512 self.SUB_EXP_CODE = None
1293 1513 self.PLOT_POS = None
1294 1514
1295 1515 def getSubplots(self):
1296 1516
1297 1517 ncol = 1
1298 1518 nrow = 1
1299 1519
1300 1520 return nrow, ncol
1301 1521
1302 1522 def openfile(self, filename):
1303 1523 f = open(filename,'w+')
1304 1524 f.write('\n\n')
1305 1525 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1306 1526 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1307 1527 f.close()
1308 1528
1309 1529 def save_data(self, filename_phase, data, data_datetime):
1310 1530 f=open(filename_phase,'a')
1311 1531 timetuple_data = data_datetime.timetuple()
1312 1532 day = str(timetuple_data.tm_mday)
1313 1533 month = str(timetuple_data.tm_mon)
1314 1534 year = str(timetuple_data.tm_year)
1315 1535 hour = str(timetuple_data.tm_hour)
1316 1536 minute = str(timetuple_data.tm_min)
1317 1537 second = str(timetuple_data.tm_sec)
1318 1538 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1319 1539 f.close()
1320 1540
1321 1541
1322 1542 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1323 1543
1324 1544 self.__showprofile = showprofile
1325 1545 self.nplots = nplots
1326 1546
1327 1547 ncolspan = 7
1328 1548 colspan = 6
1329 1549 self.__nsubplots = 2
1330 1550
1331 1551 self.createFigure(id = id,
1332 1552 wintitle = wintitle,
1333 1553 widthplot = self.WIDTH+self.WIDTHPROF,
1334 1554 heightplot = self.HEIGHT+self.HEIGHTPROF,
1335 1555 show=show)
1336 1556
1337 1557 nrow, ncol = self.getSubplots()
1338 1558
1339 1559 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1340 1560
1341 1561
1342 1562 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1343 1563 xmin=None, xmax=None, ymin=None, ymax=None,
1344 1564 timerange=None,
1345 1565 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1346 1566 server=None, folder=None, username=None, password=None,
1347 1567 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1348 1568
1349 1569 if channelList == None:
1350 1570 channelIndexList = dataOut.channelIndexList
1351 1571 channelList = dataOut.channelList
1352 1572 else:
1353 1573 channelIndexList = []
1354 1574 for channel in channelList:
1355 1575 if channel not in dataOut.channelList:
1356 1576 raise ValueError, "Channel %d is not in dataOut.channelList"
1357 1577 channelIndexList.append(dataOut.channelList.index(channel))
1358 1578
1359 1579 if timerange != None:
1360 1580 self.timerange = timerange
1361 1581
1362 1582 tmin = None
1363 1583 tmax = None
1364 1584 x = dataOut.getTimeRange()
1365 1585 y = dataOut.getHeiRange()
1366 1586 factor = dataOut.normFactor
1367 1587 noise = dataOut.getNoise()/factor
1368 1588 noisedB = 10*numpy.log10(noise)
1369 1589
1370 1590 #thisDatetime = dataOut.datatime
1371 1591 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1372 1592 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1373 1593 xlabel = ""
1374 1594 ylabel = "Intensity (dB)"
1375 1595
1376 1596 if not self.__isConfig:
1377 1597
1378 1598 nplots = 1
1379 1599
1380 1600 self.setup(id=id,
1381 1601 nplots=nplots,
1382 1602 wintitle=wintitle,
1383 1603 showprofile=showprofile,
1384 1604 show=show)
1385 1605
1386 1606 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1387 1607 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1388 1608 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1389 1609
1390 1610 self.FTP_WEI = ftp_wei
1391 1611 self.EXP_CODE = exp_code
1392 1612 self.SUB_EXP_CODE = sub_exp_code
1393 1613 self.PLOT_POS = plot_pos
1394 1614
1395 1615
1396 1616 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1397 1617 self.__isConfig = True
1398 1618
1399 1619 self.xdata = numpy.array([])
1400 1620 self.ydata = numpy.array([])
1401 1621
1402 1622 #open file beacon phase
1403 1623 path = '%s%03d' %(self.PREFIX, self.id)
1404 1624 noise_file = os.path.join(path,'%s.txt'%self.name)
1405 1625 self.filename_noise = os.path.join(figpath,noise_file)
1406 1626 self.openfile(self.filename_noise)
1407 1627
1408 1628
1409 1629 #store data beacon phase
1410 1630 self.save_data(self.filename_noise, noisedB, thisDatetime)
1411 1631
1412 1632
1413 1633 self.setWinTitle(title)
1414 1634
1415 1635
1416 1636 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1417 1637
1418 1638 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1419 1639 axes = self.axesList[0]
1420 1640
1421 1641 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1422 1642
1423 1643 if len(self.ydata)==0:
1424 1644 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1425 1645 else:
1426 1646 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1427 1647
1428 1648
1429 1649 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1430 1650 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1431 1651 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1432 1652 XAxisAsTime=True, grid='both'
1433 1653 )
1434 1654
1435 1655 self.draw()
1436 1656
1437 1657 # if save:
1438 1658 #
1439 1659 # if figfile == None:
1440 1660 # figfile = self.getFilename(name = self.name)
1441 1661 #
1442 1662 # self.saveFigure(figpath, figfile)
1443 1663
1444 1664 if save:
1445 1665
1446 1666 self.counter_imagwr += 1
1447 1667 if (self.counter_imagwr==wr_period):
1448 1668 if figfile == None:
1449 1669 figfile = self.getFilename(name = self.name)
1450 1670 self.saveFigure(figpath, figfile)
1451 1671
1452 1672 if ftp:
1453 1673 #provisionalmente envia archivos en el formato de la web en tiempo real
1454 1674 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1455 1675 path = '%s%03d' %(self.PREFIX, self.id)
1456 1676 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1457 1677 self.saveFigure(figpath, ftp_file)
1458 1678 ftp_filename = os.path.join(figpath,ftp_file)
1459 1679 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1460 1680 self.counter_imagwr = 0
1461 1681
1462 1682 self.counter_imagwr = 0
1463 1683
1464 1684 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1465 1685 self.__isConfig = False
1466 1686 del self.xdata
1467 1687 del self.ydata
1468 1688
1469 1689
1470 1690 class SpectraHeisScope(Figure):
1471 1691
1472 1692
1473 1693 __isConfig = None
1474 1694 __nsubplots = None
1475 1695
1476 1696 WIDTHPROF = None
1477 1697 HEIGHTPROF = None
1478 1698 PREFIX = 'spc'
1479 1699
1480 1700 def __init__(self):
1481 1701
1482 1702 self.__isConfig = False
1483 1703 self.__nsubplots = 1
1484 1704
1485 1705 self.WIDTH = 230
1486 1706 self.HEIGHT = 250
1487 1707 self.WIDTHPROF = 120
1488 1708 self.HEIGHTPROF = 0
1489 1709 self.counter_imagwr = 0
1490 1710
1491 1711 def getSubplots(self):
1492 1712
1493 1713 ncol = int(numpy.sqrt(self.nplots)+0.9)
1494 1714 nrow = int(self.nplots*1./ncol + 0.9)
1495 1715
1496 1716 return nrow, ncol
1497 1717
1498 1718 def setup(self, id, nplots, wintitle, show):
1499 1719
1500 1720 showprofile = False
1501 1721 self.__showprofile = showprofile
1502 1722 self.nplots = nplots
1503 1723
1504 1724 ncolspan = 1
1505 1725 colspan = 1
1506 1726 if showprofile:
1507 1727 ncolspan = 3
1508 1728 colspan = 2
1509 1729 self.__nsubplots = 2
1510 1730
1511 1731 self.createFigure(id = id,
1512 1732 wintitle = wintitle,
1513 1733 widthplot = self.WIDTH + self.WIDTHPROF,
1514 1734 heightplot = self.HEIGHT + self.HEIGHTPROF,
1515 1735 show = show)
1516 1736
1517 1737 nrow, ncol = self.getSubplots()
1518 1738
1519 1739 counter = 0
1520 1740 for y in range(nrow):
1521 1741 for x in range(ncol):
1522 1742
1523 1743 if counter >= self.nplots:
1524 1744 break
1525 1745
1526 1746 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1527 1747
1528 1748 if showprofile:
1529 1749 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1530 1750
1531 1751 counter += 1
1532 1752
1533 1753
1534 1754 def run(self, dataOut, id, wintitle="", channelList=None,
1535 1755 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1536 1756 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
1537 1757 server=None, folder=None, username=None, password=None):
1538 1758
1539 1759 """
1540 1760
1541 1761 Input:
1542 1762 dataOut :
1543 1763 id :
1544 1764 wintitle :
1545 1765 channelList :
1546 1766 xmin : None,
1547 1767 xmax : None,
1548 1768 ymin : None,
1549 1769 ymax : None,
1550 1770 """
1551 1771
1552 1772 if dataOut.realtime:
1553 1773 if not(isRealtime(utcdatatime = dataOut.utctime)):
1554 1774 print 'Skipping this plot function'
1555 1775 return
1556 1776
1557 1777 if channelList == None:
1558 1778 channelIndexList = dataOut.channelIndexList
1559 1779 else:
1560 1780 channelIndexList = []
1561 1781 for channel in channelList:
1562 1782 if channel not in dataOut.channelList:
1563 1783 raise ValueError, "Channel %d is not in dataOut.channelList"
1564 1784 channelIndexList.append(dataOut.channelList.index(channel))
1565 1785
1566 1786 # x = dataOut.heightList
1567 1787 c = 3E8
1568 1788 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1569 1789 #deberia cambiar para el caso de 1Mhz y 100KHz
1570 1790 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1571 1791 #para 1Mhz descomentar la siguiente linea
1572 1792 #x= x/(10000.0)
1573 1793 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1574 1794 # y = y.real
1575 1795 datadB = 10.*numpy.log10(dataOut.data_spc)
1576 1796 y = datadB
1577 1797
1578 1798 #thisDatetime = dataOut.datatime
1579 1799 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1580 1800 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1581 1801 xlabel = ""
1582 1802 #para 1Mhz descomentar la siguiente linea
1583 1803 #xlabel = "Frequency x 10000"
1584 1804 ylabel = "Intensity (dB)"
1585 1805
1586 1806 if not self.__isConfig:
1587 1807 nplots = len(channelIndexList)
1588 1808
1589 1809 self.setup(id=id,
1590 1810 nplots=nplots,
1591 1811 wintitle=wintitle,
1592 1812 show=show)
1593 1813
1594 1814 if xmin == None: xmin = numpy.nanmin(x)
1595 1815 if xmax == None: xmax = numpy.nanmax(x)
1596 1816 if ymin == None: ymin = numpy.nanmin(y)
1597 1817 if ymax == None: ymax = numpy.nanmax(y)
1598 1818
1599 1819 self.__isConfig = True
1600 1820
1601 1821 self.setWinTitle(title)
1602 1822
1603 1823 for i in range(len(self.axesList)):
1604 1824 ychannel = y[i,:]
1605 1825 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1606 1826 title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime)
1607 1827 axes = self.axesList[i]
1608 1828 axes.pline(x, ychannel,
1609 1829 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1610 1830 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1611 1831
1612 1832
1613 1833 self.draw()
1614 1834
1615 1835 if save:
1616 1836 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1617 1837 if figfile == None:
1618 1838 figfile = self.getFilename(name = date)
1619 1839
1620 1840 self.saveFigure(figpath, figfile)
1621 1841
1622 1842 self.counter_imagwr += 1
1623 1843 if (ftp and (self.counter_imagwr==wr_period)):
1624 1844 ftp_filename = os.path.join(figpath,figfile)
1625 1845 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1626 1846 self.counter_imagwr = 0
1627 1847
1628 1848
1629 1849 class RTIfromSpectraHeis(Figure):
1630 1850
1631 1851 __isConfig = None
1632 1852 __nsubplots = None
1633 1853
1634 1854 PREFIX = 'rtinoise'
1635 1855
1636 1856 def __init__(self):
1637 1857
1638 1858 self.timerange = 24*60*60
1639 1859 self.__isConfig = False
1640 1860 self.__nsubplots = 1
1641 1861
1642 1862 self.WIDTH = 820
1643 1863 self.HEIGHT = 200
1644 1864 self.WIDTHPROF = 120
1645 1865 self.HEIGHTPROF = 0
1646 1866 self.counter_imagwr = 0
1647 1867 self.xdata = None
1648 1868 self.ydata = None
1649 1869
1650 1870 def getSubplots(self):
1651 1871
1652 1872 ncol = 1
1653 1873 nrow = 1
1654 1874
1655 1875 return nrow, ncol
1656 1876
1657 1877 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1658 1878
1659 1879 self.__showprofile = showprofile
1660 1880 self.nplots = nplots
1661 1881
1662 1882 ncolspan = 7
1663 1883 colspan = 6
1664 1884 self.__nsubplots = 2
1665 1885
1666 1886 self.createFigure(id = id,
1667 1887 wintitle = wintitle,
1668 1888 widthplot = self.WIDTH+self.WIDTHPROF,
1669 1889 heightplot = self.HEIGHT+self.HEIGHTPROF,
1670 1890 show = show)
1671 1891
1672 1892 nrow, ncol = self.getSubplots()
1673 1893
1674 1894 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1675 1895
1676 1896
1677 1897 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1678 1898 xmin=None, xmax=None, ymin=None, ymax=None,
1679 1899 timerange=None,
1680 1900 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
1681 1901 server=None, folder=None, username=None, password=None):
1682 1902
1683 1903 if channelList == None:
1684 1904 channelIndexList = dataOut.channelIndexList
1685 1905 channelList = dataOut.channelList
1686 1906 else:
1687 1907 channelIndexList = []
1688 1908 for channel in channelList:
1689 1909 if channel not in dataOut.channelList:
1690 1910 raise ValueError, "Channel %d is not in dataOut.channelList"
1691 1911 channelIndexList.append(dataOut.channelList.index(channel))
1692 1912
1693 1913 if timerange != None:
1694 1914 self.timerange = timerange
1695 1915
1696 1916 tmin = None
1697 1917 tmax = None
1698 1918 x = dataOut.getTimeRange()
1699 1919 y = dataOut.getHeiRange()
1700 1920
1701 1921 #factor = 1
1702 1922 data = dataOut.data_spc#/factor
1703 1923 data = numpy.average(data,axis=1)
1704 1924 datadB = 10*numpy.log10(data)
1705 1925
1706 1926 # factor = dataOut.normFactor
1707 1927 # noise = dataOut.getNoise()/factor
1708 1928 # noisedB = 10*numpy.log10(noise)
1709 1929
1710 1930 #thisDatetime = dataOut.datatime
1711 1931 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1712 1932 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1713 1933 xlabel = "Local Time"
1714 1934 ylabel = "Intensity (dB)"
1715 1935
1716 1936 if not self.__isConfig:
1717 1937
1718 1938 nplots = 1
1719 1939
1720 1940 self.setup(id=id,
1721 1941 nplots=nplots,
1722 1942 wintitle=wintitle,
1723 1943 showprofile=showprofile,
1724 1944 show=show)
1725 1945
1726 1946 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1727 1947 if ymin == None: ymin = numpy.nanmin(datadB)
1728 1948 if ymax == None: ymax = numpy.nanmax(datadB)
1729 1949
1730 1950 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1731 1951 self.__isConfig = True
1732 1952
1733 1953 self.xdata = numpy.array([])
1734 1954 self.ydata = numpy.array([])
1735 1955
1736 1956 self.setWinTitle(title)
1737 1957
1738 1958
1739 1959 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1740 1960 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1741 1961
1742 1962 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1743 1963 axes = self.axesList[0]
1744 1964
1745 1965 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1746 1966
1747 1967 if len(self.ydata)==0:
1748 1968 self.ydata = datadB[channelIndexList].reshape(-1,1)
1749 1969 else:
1750 1970 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1751 1971
1752 1972
1753 1973 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1754 1974 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1755 1975 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1756 1976 XAxisAsTime=True
1757 1977 )
1758 1978
1759 1979 self.draw()
1760 1980
1761 1981 if save:
1762 1982
1763 1983 if figfile == None:
1764 1984 figfile = self.getFilename(name = self.name)
1765 1985
1766 1986 self.saveFigure(figpath, figfile)
1767 1987
1768 1988 self.counter_imagwr += 1
1769 1989 if (ftp and (self.counter_imagwr==wr_period)):
1770 1990 ftp_filename = os.path.join(figpath,figfile)
1771 1991 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1772 1992 self.counter_imagwr = 0
1773 1993
1774 1994 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1775 1995 self.__isConfig = False
1776 1996 del self.xdata
1777 1997 del self.ydata
1778 1998
1779 1999
1780 2000 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now