##// END OF EJS Templates
rti png filename is defined by self.figfile
Daniel Valdez -
r490:9dd98ddf6c74
parent child
Show More
@@ -1,1148 +1,1151
1 1 '''
2 2 @author: Daniel Suarez
3 3 '''
4 4 import os
5 5 import datetime
6 6 import numpy
7 7
8 8 from figure import Figure, isRealtime
9 9
10 10 class SpectraPlot(Figure):
11 11
12 12 isConfig = None
13 13 __nsubplots = None
14 14
15 15 WIDTHPROF = None
16 16 HEIGHTPROF = None
17 17 PREFIX = 'spc'
18 18
19 19 def __init__(self):
20 20
21 21 self.isConfig = False
22 22 self.__nsubplots = 1
23 23
24 24 self.WIDTH = 280
25 25 self.HEIGHT = 250
26 26 self.WIDTHPROF = 120
27 27 self.HEIGHTPROF = 0
28 28 self.counter_imagwr = 0
29 29
30 30 self.PLOT_CODE = 1
31 31 self.FTP_WEI = None
32 32 self.EXP_CODE = None
33 33 self.SUB_EXP_CODE = None
34 34 self.PLOT_POS = None
35 35
36 36 def getSubplots(self):
37 37
38 38 ncol = int(numpy.sqrt(self.nplots)+0.9)
39 39 nrow = int(self.nplots*1./ncol + 0.9)
40 40
41 41 return nrow, ncol
42 42
43 43 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
44 44
45 45 self.__showprofile = showprofile
46 46 self.nplots = nplots
47 47
48 48 ncolspan = 1
49 49 colspan = 1
50 50 if showprofile:
51 51 ncolspan = 3
52 52 colspan = 2
53 53 self.__nsubplots = 2
54 54
55 55 self.createFigure(id = id,
56 56 wintitle = wintitle,
57 57 widthplot = self.WIDTH + self.WIDTHPROF,
58 58 heightplot = self.HEIGHT + self.HEIGHTPROF,
59 59 show=show)
60 60
61 61 nrow, ncol = self.getSubplots()
62 62
63 63 counter = 0
64 64 for y in range(nrow):
65 65 for x in range(ncol):
66 66
67 67 if counter >= self.nplots:
68 68 break
69 69
70 70 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
71 71
72 72 if showprofile:
73 73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
74 74
75 75 counter += 1
76 76
77 77 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
78 78 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
79 79 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
80 80 server=None, folder=None, username=None, password=None,
81 81 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
82 82
83 83 """
84 84
85 85 Input:
86 86 dataOut :
87 87 id :
88 88 wintitle :
89 89 channelList :
90 90 showProfile :
91 91 xmin : None,
92 92 xmax : None,
93 93 ymin : None,
94 94 ymax : None,
95 95 zmin : None,
96 96 zmax : None
97 97 """
98 98
99 99 if dataOut.flagNoData:
100 100 return None
101 101
102 102 if realtime:
103 103 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 104 print 'Skipping this plot function'
105 105 return
106 106
107 107 if channelList == None:
108 108 channelIndexList = dataOut.channelIndexList
109 109 else:
110 110 channelIndexList = []
111 111 for channel in channelList:
112 112 if channel not in dataOut.channelList:
113 113 raise ValueError, "Channel %d is not in dataOut.channelList"
114 114 channelIndexList.append(dataOut.channelList.index(channel))
115 115
116 116 factor = dataOut.normFactor
117 117
118 118 x = dataOut.getVelRange(1)
119 119 y = dataOut.getHeiRange()
120 120
121 121 z = dataOut.data_spc[channelIndexList,:,:]/factor
122 122 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
123 123 avg = numpy.average(z, axis=1)
124 124 avg = numpy.nanmean(z, axis=1)
125 125 noise = dataOut.noise/factor
126 126
127 127 zdB = 10*numpy.log10(z)
128 128 avgdB = 10*numpy.log10(avg)
129 129 noisedB = 10*numpy.log10(noise)
130 130
131 131 #thisDatetime = dataOut.datatime
132 132 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
133 133 title = wintitle + " Spectra"
134 134 xlabel = "Velocity (m/s)"
135 135 ylabel = "Range (Km)"
136 136
137 137 if not self.isConfig:
138 138
139 139 nplots = len(channelIndexList)
140 140
141 141 self.setup(id=id,
142 142 nplots=nplots,
143 143 wintitle=wintitle,
144 144 showprofile=showprofile,
145 145 show=show)
146 146
147 147 if xmin == None: xmin = numpy.nanmin(x)
148 148 if xmax == None: xmax = numpy.nanmax(x)
149 149 if ymin == None: ymin = numpy.nanmin(y)
150 150 if ymax == None: ymax = numpy.nanmax(y)
151 151 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
152 152 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
153 153
154 154 self.FTP_WEI = ftp_wei
155 155 self.EXP_CODE = exp_code
156 156 self.SUB_EXP_CODE = sub_exp_code
157 157 self.PLOT_POS = plot_pos
158 158
159 159 self.isConfig = True
160 160
161 161 self.setWinTitle(title)
162 162
163 163 for i in range(self.nplots):
164 164 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
165 165 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
166 166 axes = self.axesList[i*self.__nsubplots]
167 167 axes.pcolor(x, y, zdB[i,:,:],
168 168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
169 169 xlabel=xlabel, ylabel=ylabel, title=title,
170 170 ticksize=9, cblabel='')
171 171
172 172 if self.__showprofile:
173 173 axes = self.axesList[i*self.__nsubplots +1]
174 174 axes.pline(avgdB[i], y,
175 175 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
176 176 xlabel='dB', ylabel='', title='',
177 177 ytick_visible=False,
178 178 grid='x')
179 179
180 180 noiseline = numpy.repeat(noisedB[i], len(y))
181 181 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
182 182
183 183 self.draw()
184 184
185 185 if figfile == None:
186 186 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
187 187 figfile = self.getFilename(name = str_datetime)
188 188
189 189 if figpath != '':
190 190 self.counter_imagwr += 1
191 191 if (self.counter_imagwr>=wr_period):
192 192 # store png plot to local folder
193 193 self.saveFigure(figpath, figfile)
194 194 # store png plot to FTP server according to RT-Web format
195 195 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
196 196 ftp_filename = os.path.join(figpath, name)
197 197 self.saveFigure(figpath, ftp_filename)
198 198 self.counter_imagwr = 0
199 199
200 200
201 201 class CrossSpectraPlot(Figure):
202 202
203 203 isConfig = None
204 204 __nsubplots = None
205 205
206 206 WIDTH = None
207 207 HEIGHT = None
208 208 WIDTHPROF = None
209 209 HEIGHTPROF = None
210 210 PREFIX = 'cspc'
211 211
212 212 def __init__(self):
213 213
214 214 self.isConfig = False
215 215 self.__nsubplots = 4
216 216 self.counter_imagwr = 0
217 217 self.WIDTH = 250
218 218 self.HEIGHT = 250
219 219 self.WIDTHPROF = 0
220 220 self.HEIGHTPROF = 0
221 221
222 222 self.PLOT_CODE = 1
223 223 self.FTP_WEI = None
224 224 self.EXP_CODE = None
225 225 self.SUB_EXP_CODE = None
226 226 self.PLOT_POS = None
227 227
228 228 def getSubplots(self):
229 229
230 230 ncol = 4
231 231 nrow = self.nplots
232 232
233 233 return nrow, ncol
234 234
235 235 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
236 236
237 237 self.__showprofile = showprofile
238 238 self.nplots = nplots
239 239
240 240 ncolspan = 1
241 241 colspan = 1
242 242
243 243 self.createFigure(id = id,
244 244 wintitle = wintitle,
245 245 widthplot = self.WIDTH + self.WIDTHPROF,
246 246 heightplot = self.HEIGHT + self.HEIGHTPROF,
247 247 show=True)
248 248
249 249 nrow, ncol = self.getSubplots()
250 250
251 251 counter = 0
252 252 for y in range(nrow):
253 253 for x in range(ncol):
254 254 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
255 255
256 256 counter += 1
257 257
258 258 def run(self, dataOut, id, wintitle="", pairsList=None,
259 259 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
260 260 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
261 261 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
262 262 server=None, folder=None, username=None, password=None,
263 263 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
264 264
265 265 """
266 266
267 267 Input:
268 268 dataOut :
269 269 id :
270 270 wintitle :
271 271 channelList :
272 272 showProfile :
273 273 xmin : None,
274 274 xmax : None,
275 275 ymin : None,
276 276 ymax : None,
277 277 zmin : None,
278 278 zmax : None
279 279 """
280 280
281 281 if pairsList == None:
282 282 pairsIndexList = dataOut.pairsIndexList
283 283 else:
284 284 pairsIndexList = []
285 285 for pair in pairsList:
286 286 if pair not in dataOut.pairsList:
287 287 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
288 288 pairsIndexList.append(dataOut.pairsList.index(pair))
289 289
290 290 if pairsIndexList == []:
291 291 return
292 292
293 293 if len(pairsIndexList) > 4:
294 294 pairsIndexList = pairsIndexList[0:4]
295 295 factor = dataOut.normFactor
296 296 x = dataOut.getVelRange(1)
297 297 y = dataOut.getHeiRange()
298 298 z = dataOut.data_spc[:,:,:]/factor
299 299 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
300 300 avg = numpy.abs(numpy.average(z, axis=1))
301 301 noise = dataOut.noise()/factor
302 302
303 303 zdB = 10*numpy.log10(z)
304 304 avgdB = 10*numpy.log10(avg)
305 305 noisedB = 10*numpy.log10(noise)
306 306
307 307
308 308 #thisDatetime = dataOut.datatime
309 309 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
310 310 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
311 311 xlabel = "Velocity (m/s)"
312 312 ylabel = "Range (Km)"
313 313
314 314 if not self.isConfig:
315 315
316 316 nplots = len(pairsIndexList)
317 317
318 318 self.setup(id=id,
319 319 nplots=nplots,
320 320 wintitle=wintitle,
321 321 showprofile=False,
322 322 show=show)
323 323
324 324 if xmin == None: xmin = numpy.nanmin(x)
325 325 if xmax == None: xmax = numpy.nanmax(x)
326 326 if ymin == None: ymin = numpy.nanmin(y)
327 327 if ymax == None: ymax = numpy.nanmax(y)
328 328 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
329 329 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
330 330
331 331 self.FTP_WEI = ftp_wei
332 332 self.EXP_CODE = exp_code
333 333 self.SUB_EXP_CODE = sub_exp_code
334 334 self.PLOT_POS = plot_pos
335 335
336 336 self.isConfig = True
337 337
338 338 self.setWinTitle(title)
339 339
340 340 for i in range(self.nplots):
341 341 pair = dataOut.pairsList[pairsIndexList[i]]
342 342 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
343 343 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime)
344 344 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
345 345 axes0 = self.axesList[i*self.__nsubplots]
346 346 axes0.pcolor(x, y, zdB,
347 347 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
348 348 xlabel=xlabel, ylabel=ylabel, title=title,
349 349 ticksize=9, colormap=power_cmap, cblabel='')
350 350
351 351 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime)
352 352 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
353 353 axes0 = self.axesList[i*self.__nsubplots+1]
354 354 axes0.pcolor(x, y, zdB,
355 355 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
356 356 xlabel=xlabel, ylabel=ylabel, title=title,
357 357 ticksize=9, colormap=power_cmap, cblabel='')
358 358
359 359 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
360 360 coherence = numpy.abs(coherenceComplex)
361 361 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
362 362 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
363 363
364 364 title = "Coherence %d%d" %(pair[0], pair[1])
365 365 axes0 = self.axesList[i*self.__nsubplots+2]
366 366 axes0.pcolor(x, y, coherence,
367 367 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
368 368 xlabel=xlabel, ylabel=ylabel, title=title,
369 369 ticksize=9, colormap=coherence_cmap, cblabel='')
370 370
371 371 title = "Phase %d%d" %(pair[0], pair[1])
372 372 axes0 = self.axesList[i*self.__nsubplots+3]
373 373 axes0.pcolor(x, y, phase,
374 374 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
375 375 xlabel=xlabel, ylabel=ylabel, title=title,
376 376 ticksize=9, colormap=phase_cmap, cblabel='')
377 377
378 378
379 379
380 380 self.draw()
381 381
382 382 if save:
383 383
384 384 self.counter_imagwr += 1
385 385 if (self.counter_imagwr==wr_period):
386 386 if figfile == None:
387 387 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
388 388 figfile = self.getFilename(name = str_datetime)
389 389
390 390 self.saveFigure(figpath, figfile)
391 391
392 392 if ftp:
393 393 #provisionalmente envia archivos en el formato de la web en tiempo real
394 394 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
395 395 path = '%s%03d' %(self.PREFIX, self.id)
396 396 ftp_file = os.path.join(path,'ftp','%s.png'%name)
397 397 self.saveFigure(figpath, ftp_file)
398 398 ftp_filename = os.path.join(figpath,ftp_file)
399 399
400 400 try:
401 401 self.sendByFTP(ftp_filename, server, folder, username, password)
402 402 except:
403 403 self.counter_imagwr = 0
404 404 print ValueError, 'Error FTP'
405 405
406 406 self.counter_imagwr = 0
407 407
408 408 class RTIPlot(Figure):
409 409
410 410 isConfig = None
411 411 __nsubplots = None
412 412
413 413 WIDTHPROF = None
414 414 HEIGHTPROF = None
415 415 PREFIX = 'rti'
416 416
417 417 def __init__(self):
418 418
419 419 self.timerange = 2*60*60
420 420 self.isConfig = False
421 421 self.__nsubplots = 1
422 422
423 423 self.WIDTH = 800
424 424 self.HEIGHT = 150
425 425 self.WIDTHPROF = 120
426 426 self.HEIGHTPROF = 0
427 427 self.counter_imagwr = 0
428 428
429 429 self.PLOT_CODE = 0
430 430 self.FTP_WEI = None
431 431 self.EXP_CODE = None
432 432 self.SUB_EXP_CODE = None
433 433 self.PLOT_POS = None
434 434 self.tmin = None
435 435 self.tmax = None
436 436
437 437 self.xmin = None
438 438 self.xmax = None
439 439
440 self.figfile = None
441
440 442 def getSubplots(self):
441 443
442 444 ncol = 1
443 445 nrow = self.nplots
444 446
445 447 return nrow, ncol
446 448
447 449 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
448 450
449 451 self.__showprofile = showprofile
450 452 self.nplots = nplots
451 453
452 454 ncolspan = 1
453 455 colspan = 1
454 456 if showprofile:
455 457 ncolspan = 7
456 458 colspan = 6
457 459 self.__nsubplots = 2
458 460
459 461 self.createFigure(id = id,
460 462 wintitle = wintitle,
461 463 widthplot = self.WIDTH + self.WIDTHPROF,
462 464 heightplot = self.HEIGHT + self.HEIGHTPROF,
463 465 show=show)
464 466
465 467 nrow, ncol = self.getSubplots()
466 468
467 469 counter = 0
468 470 for y in range(nrow):
469 471 for x in range(ncol):
470 472
471 473 if counter >= self.nplots:
472 474 break
473 475
474 476 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
475 477
476 478 if showprofile:
477 479 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
478 480
479 481 counter += 1
480 482
481 483 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
482 484 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
483 485 timerange=None,
484 486 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
485 487 server=None, folder=None, username=None, password=None,
486 488 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
487 489
488 490 """
489 491
490 492 Input:
491 493 dataOut :
492 494 id :
493 495 wintitle :
494 496 channelList :
495 497 showProfile :
496 498 xmin : None,
497 499 xmax : None,
498 500 ymin : None,
499 501 ymax : None,
500 502 zmin : None,
501 503 zmax : None
502 504 """
503 505
504 506 if channelList == None:
505 507 channelIndexList = dataOut.channelIndexList
506 508 else:
507 509 channelIndexList = []
508 510 for channel in channelList:
509 511 if channel not in dataOut.channelList:
510 512 raise ValueError, "Channel %d is not in dataOut.channelList"
511 513 channelIndexList.append(dataOut.channelList.index(channel))
512 514
513 515 if timerange != None:
514 516 self.timerange = timerange
515 517
516 518 #tmin = None
517 519 #tmax = None
518 520 factor = dataOut.normFactor
519 521 x = dataOut.getTimeRange()
520 522 y = dataOut.getHeiRange()
521 523
522 524 z = dataOut.data_spc[channelIndexList,:,:]/factor
523 525 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
524 526 avg = numpy.average(z, axis=1)
525 527
526 528 avgdB = 10.*numpy.log10(avg)
527 529
528 530
529 531 # thisDatetime = dataOut.datatime
530 532 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
531 533 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
532 534 xlabel = ""
533 535 ylabel = "Range (Km)"
534 536
535 537 if not self.isConfig:
536 538
537 539 nplots = len(channelIndexList)
538 540
539 541 self.setup(id=id,
540 542 nplots=nplots,
541 543 wintitle=wintitle,
542 544 showprofile=showprofile,
543 545 show=show)
544 546
545 547 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
546 548
547 549 # if timerange != None:
548 550 # self.timerange = timerange
549 551 # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange)
550 552
551 553
552 554
553 555 if ymin == None: ymin = numpy.nanmin(y)
554 556 if ymax == None: ymax = numpy.nanmax(y)
555 557 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
556 558 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
557 559
558 560 self.FTP_WEI = ftp_wei
559 561 self.EXP_CODE = exp_code
560 562 self.SUB_EXP_CODE = sub_exp_code
561 563 self.PLOT_POS = plot_pos
562 564
563 565 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
564 566 self.isConfig = True
565
567 self.figfile = figfile
566 568
567 569 self.setWinTitle(title)
568 570
569 571 if ((self.xmax - x[1]) < (x[1]-x[0])):
570 572 x[1] = self.xmax
571 573
572 574 for i in range(self.nplots):
573 575 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
574 576 axes = self.axesList[i*self.__nsubplots]
575 577 zdB = avgdB[i].reshape((1,-1))
576 578 axes.pcolorbuffer(x, y, zdB,
577 579 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
578 580 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
579 581 ticksize=9, cblabel='', cbsize="1%")
580 582
581 583 if self.__showprofile:
582 584 axes = self.axesList[i*self.__nsubplots +1]
583 585 axes.pline(avgdB[i], y,
584 586 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
585 587 xlabel='dB', ylabel='', title='',
586 588 ytick_visible=False,
587 589 grid='x')
588 590
589 591 self.draw()
590 592
591 593 if x[1] >= self.axesList[0].xmax:
592 594 self.counter_imagwr = wr_period
593 595 self.__isConfig = False
594 596
595 if figfile == None:
597
598 if self.figfile == None:
596 599 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
597 figfile = self.getFilename(name = str_datetime)
600 self.figfile = self.getFilename(name = str_datetime)
598 601
599 602 if figpath != '':
600 603
601 604 self.counter_imagwr += 1
602 605 if (self.counter_imagwr>=wr_period):
603 606 # store png plot to local folder
604 self.saveFigure(figpath, figfile)
607 self.saveFigure(figpath, self.figfile)
605 608 # store png plot to FTP server according to RT-Web format
606 609 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
607 610 ftp_filename = os.path.join(figpath, name)
608 611 self.saveFigure(figpath, ftp_filename)
609 612
610 613 self.counter_imagwr = 0
611 614
612 615
613 616 class CoherenceMap(Figure):
614 617 isConfig = None
615 618 __nsubplots = None
616 619
617 620 WIDTHPROF = None
618 621 HEIGHTPROF = None
619 622 PREFIX = 'cmap'
620 623
621 624 def __init__(self):
622 625 self.timerange = 2*60*60
623 626 self.isConfig = False
624 627 self.__nsubplots = 1
625 628
626 629 self.WIDTH = 800
627 630 self.HEIGHT = 150
628 631 self.WIDTHPROF = 120
629 632 self.HEIGHTPROF = 0
630 633 self.counter_imagwr = 0
631 634
632 635 self.PLOT_CODE = 3
633 636 self.FTP_WEI = None
634 637 self.EXP_CODE = None
635 638 self.SUB_EXP_CODE = None
636 639 self.PLOT_POS = None
637 640 self.counter_imagwr = 0
638 641
639 642 self.xmin = None
640 643 self.xmax = None
641 644
642 645 def getSubplots(self):
643 646 ncol = 1
644 647 nrow = self.nplots*2
645 648
646 649 return nrow, ncol
647 650
648 651 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
649 652 self.__showprofile = showprofile
650 653 self.nplots = nplots
651 654
652 655 ncolspan = 1
653 656 colspan = 1
654 657 if showprofile:
655 658 ncolspan = 7
656 659 colspan = 6
657 660 self.__nsubplots = 2
658 661
659 662 self.createFigure(id = id,
660 663 wintitle = wintitle,
661 664 widthplot = self.WIDTH + self.WIDTHPROF,
662 665 heightplot = self.HEIGHT + self.HEIGHTPROF,
663 666 show=True)
664 667
665 668 nrow, ncol = self.getSubplots()
666 669
667 670 for y in range(nrow):
668 671 for x in range(ncol):
669 672
670 673 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
671 674
672 675 if showprofile:
673 676 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
674 677
675 678 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
676 679 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
677 680 timerange=None,
678 681 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
679 682 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
680 683 server=None, folder=None, username=None, password=None,
681 684 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
682 685
683 686 if pairsList == None:
684 687 pairsIndexList = dataOut.pairsIndexList
685 688 else:
686 689 pairsIndexList = []
687 690 for pair in pairsList:
688 691 if pair not in dataOut.pairsList:
689 692 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
690 693 pairsIndexList.append(dataOut.pairsList.index(pair))
691 694
692 695 if timerange != None:
693 696 self.timerange = timerange
694 697
695 698 if pairsIndexList == []:
696 699 return
697 700
698 701 if len(pairsIndexList) > 4:
699 702 pairsIndexList = pairsIndexList[0:4]
700 703
701 704 # tmin = None
702 705 # tmax = None
703 706 x = dataOut.getTimeRange()
704 707 y = dataOut.getHeiRange()
705 708
706 709 #thisDatetime = dataOut.datatime
707 710 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
708 711 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
709 712 xlabel = ""
710 713 ylabel = "Range (Km)"
711 714
712 715 if not self.isConfig:
713 716 nplots = len(pairsIndexList)
714 717 self.setup(id=id,
715 718 nplots=nplots,
716 719 wintitle=wintitle,
717 720 showprofile=showprofile,
718 721 show=show)
719 722
720 723 #tmin, tmax = self.getTimeLim(x, xmin, xmax)
721 724
722 725 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
723 726
724 727 if ymin == None: ymin = numpy.nanmin(y)
725 728 if ymax == None: ymax = numpy.nanmax(y)
726 729 if zmin == None: zmin = 0.
727 730 if zmax == None: zmax = 1.
728 731
729 732 self.FTP_WEI = ftp_wei
730 733 self.EXP_CODE = exp_code
731 734 self.SUB_EXP_CODE = sub_exp_code
732 735 self.PLOT_POS = plot_pos
733 736
734 737 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
735 738
736 739 self.isConfig = True
737 740
738 741 self.setWinTitle(title)
739 742
740 743 if ((self.xmax - x[1]) < (x[1]-x[0])):
741 744 x[1] = self.xmax
742 745
743 746 for i in range(self.nplots):
744 747
745 748 pair = dataOut.pairsList[pairsIndexList[i]]
746 749
747 750 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
748 751 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
749 752 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
750 753
751 754
752 755 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
753 756 coherence = numpy.abs(avgcoherenceComplex)
754 757
755 758 z = coherence.reshape((1,-1))
756 759
757 760 counter = 0
758 761
759 762 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
760 763 axes = self.axesList[i*self.__nsubplots*2]
761 764 axes.pcolorbuffer(x, y, z,
762 765 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
763 766 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
764 767 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
765 768
766 769 if self.__showprofile:
767 770 counter += 1
768 771 axes = self.axesList[i*self.__nsubplots*2 + counter]
769 772 axes.pline(coherence, y,
770 773 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
771 774 xlabel='', ylabel='', title='', ticksize=7,
772 775 ytick_visible=False, nxticks=5,
773 776 grid='x')
774 777
775 778 counter += 1
776 779
777 780 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
778 781
779 782 z = phase.reshape((1,-1))
780 783
781 784 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
782 785 axes = self.axesList[i*self.__nsubplots*2 + counter]
783 786 axes.pcolorbuffer(x, y, z,
784 787 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
785 788 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
786 789 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
787 790
788 791 if self.__showprofile:
789 792 counter += 1
790 793 axes = self.axesList[i*self.__nsubplots*2 + counter]
791 794 axes.pline(phase, y,
792 795 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
793 796 xlabel='', ylabel='', title='', ticksize=7,
794 797 ytick_visible=False, nxticks=4,
795 798 grid='x')
796 799
797 800 self.draw()
798 801
799 802 if x[1] >= self.axesList[0].xmax:
800 803 self.counter_imagwr = wr_period
801 804 self.__isConfig = False
802 805
803 806 if figfile == None:
804 807 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
805 808 figfile = self.getFilename(name = str_datetime)
806 809
807 810 if figpath != '':
808 811
809 812 self.counter_imagwr += 1
810 813 if (self.counter_imagwr>=wr_period):
811 814 # store png plot to local folder
812 815 self.saveFigure(figpath, figfile)
813 816 # store png plot to FTP server according to RT-Web format
814 817 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
815 818 ftp_filename = os.path.join(figpath, name)
816 819 self.saveFigure(figpath, ftp_filename)
817 820
818 821 self.counter_imagwr = 0
819 822
820 823 class PowerProfile(Figure):
821 824 isConfig = None
822 825 __nsubplots = None
823 826
824 827 WIDTHPROF = None
825 828 HEIGHTPROF = None
826 829 PREFIX = 'spcprofile'
827 830
828 831 def __init__(self):
829 832 self.isConfig = False
830 833 self.__nsubplots = 1
831 834
832 835 self.WIDTH = 300
833 836 self.HEIGHT = 500
834 837 self.counter_imagwr = 0
835 838
836 839 def getSubplots(self):
837 840 ncol = 1
838 841 nrow = 1
839 842
840 843 return nrow, ncol
841 844
842 845 def setup(self, id, nplots, wintitle, show):
843 846
844 847 self.nplots = nplots
845 848
846 849 ncolspan = 1
847 850 colspan = 1
848 851
849 852 self.createFigure(id = id,
850 853 wintitle = wintitle,
851 854 widthplot = self.WIDTH,
852 855 heightplot = self.HEIGHT,
853 856 show=show)
854 857
855 858 nrow, ncol = self.getSubplots()
856 859
857 860 counter = 0
858 861 for y in range(nrow):
859 862 for x in range(ncol):
860 863 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
861 864
862 865 def run(self, dataOut, id, wintitle="", channelList=None,
863 866 xmin=None, xmax=None, ymin=None, ymax=None,
864 867 save=False, figpath='./', figfile=None, show=True, wr_period=1,
865 868 server=None, folder=None, username=None, password=None,):
866 869
867 870 if dataOut.flagNoData:
868 871 return None
869 872
870 873 if channelList == None:
871 874 channelIndexList = dataOut.channelIndexList
872 875 channelList = dataOut.channelList
873 876 else:
874 877 channelIndexList = []
875 878 for channel in channelList:
876 879 if channel not in dataOut.channelList:
877 880 raise ValueError, "Channel %d is not in dataOut.channelList"
878 881 channelIndexList.append(dataOut.channelList.index(channel))
879 882
880 883 try:
881 884 factor = dataOut.normFactor
882 885 except:
883 886 factor = 1
884 887
885 888 y = dataOut.getHeiRange()
886 889
887 890 #for voltage
888 891 if dataOut.type == 'Voltage':
889 892 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
890 893 x = x.real
891 894 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
892 895
893 896 #for spectra
894 897 if dataOut.type == 'Spectra':
895 898 x = dataOut.data_spc[channelIndexList,:,:]/factor
896 899 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
897 900 x = numpy.average(x, axis=1)
898 901
899 902
900 903 xdB = 10*numpy.log10(x)
901 904
902 905 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
903 906 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
904 907 xlabel = "dB"
905 908 ylabel = "Range (Km)"
906 909
907 910 if not self.isConfig:
908 911
909 912 nplots = 1
910 913
911 914 self.setup(id=id,
912 915 nplots=nplots,
913 916 wintitle=wintitle,
914 917 show=show)
915 918
916 919 if ymin == None: ymin = numpy.nanmin(y)
917 920 if ymax == None: ymax = numpy.nanmax(y)
918 921 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
919 922 if xmax == None: xmax = numpy.nanmax(xdB)*0.9
920 923
921 924 self.__isConfig = True
922 925
923 926 self.setWinTitle(title)
924 927
925 928 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
926 929 axes = self.axesList[0]
927 930
928 931 legendlabels = ["channel %d"%x for x in channelList]
929 932 axes.pmultiline(xdB, y,
930 933 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
931 934 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
932 935 ytick_visible=True, nxticks=5,
933 936 grid='x')
934 937
935 938 self.draw()
936 939
937 940 if save:
938 941 date = thisDatetime.strftime("%Y%m%d")
939 942 if figfile == None:
940 943 figfile = self.getFilename(name = date)
941 944
942 945 self.saveFigure(figpath, figfile)
943 946
944 947 self.counter_imagwr += 1
945 948 if (ftp and (self.counter_imagwr==wr_period)):
946 949 ftp_filename = os.path.join(figpath,figfile)
947 950 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
948 951 self.counter_imagwr = 0
949 952
950 953 class Noise(Figure):
951 954
952 955 isConfig = None
953 956 __nsubplots = None
954 957
955 958 PREFIX = 'noise'
956 959
957 960 def __init__(self):
958 961
959 962 self.timerange = 24*60*60
960 963 self.isConfig = False
961 964 self.__nsubplots = 1
962 965 self.counter_imagwr = 0
963 966 self.WIDTH = 600
964 967 self.HEIGHT = 300
965 968 self.WIDTHPROF = 120
966 969 self.HEIGHTPROF = 0
967 970 self.xdata = None
968 971 self.ydata = None
969 972
970 973 self.PLOT_CODE = 77
971 974 self.FTP_WEI = None
972 975 self.EXP_CODE = None
973 976 self.SUB_EXP_CODE = None
974 977 self.PLOT_POS = None
975 978
976 979 def getSubplots(self):
977 980
978 981 ncol = 1
979 982 nrow = 1
980 983
981 984 return nrow, ncol
982 985
983 986 def openfile(self, filename):
984 987 f = open(filename,'w+')
985 988 f.write('\n\n')
986 989 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
987 990 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
988 991 f.close()
989 992
990 993 def save_data(self, filename_phase, data, data_datetime):
991 994 f=open(filename_phase,'a')
992 995 timetuple_data = data_datetime.timetuple()
993 996 day = str(timetuple_data.tm_mday)
994 997 month = str(timetuple_data.tm_mon)
995 998 year = str(timetuple_data.tm_year)
996 999 hour = str(timetuple_data.tm_hour)
997 1000 minute = str(timetuple_data.tm_min)
998 1001 second = str(timetuple_data.tm_sec)
999 1002 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1000 1003 f.close()
1001 1004
1002 1005
1003 1006 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1004 1007
1005 1008 self.__showprofile = showprofile
1006 1009 self.nplots = nplots
1007 1010
1008 1011 ncolspan = 7
1009 1012 colspan = 6
1010 1013 self.__nsubplots = 2
1011 1014
1012 1015 self.createFigure(id = id,
1013 1016 wintitle = wintitle,
1014 1017 widthplot = self.WIDTH+self.WIDTHPROF,
1015 1018 heightplot = self.HEIGHT+self.HEIGHTPROF,
1016 1019 show=show)
1017 1020
1018 1021 nrow, ncol = self.getSubplots()
1019 1022
1020 1023 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1021 1024
1022 1025
1023 1026 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1024 1027 xmin=None, xmax=None, ymin=None, ymax=None,
1025 1028 timerange=None,
1026 1029 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1027 1030 server=None, folder=None, username=None, password=None,
1028 1031 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1029 1032
1030 1033 if channelList == None:
1031 1034 channelIndexList = dataOut.channelIndexList
1032 1035 channelList = dataOut.channelList
1033 1036 else:
1034 1037 channelIndexList = []
1035 1038 for channel in channelList:
1036 1039 if channel not in dataOut.channelList:
1037 1040 raise ValueError, "Channel %d is not in dataOut.channelList"
1038 1041 channelIndexList.append(dataOut.channelList.index(channel))
1039 1042
1040 1043 if timerange != None:
1041 1044 self.timerange = timerange
1042 1045
1043 1046 tmin = None
1044 1047 tmax = None
1045 1048 x = dataOut.getTimeRange()
1046 1049 y = dataOut.getHeiRange()
1047 1050 factor = dataOut.normFactor
1048 1051 noise = dataOut.noise()/factor
1049 1052 noisedB = 10*numpy.log10(noise)
1050 1053
1051 1054 #thisDatetime = dataOut.datatime
1052 1055 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1053 1056 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1054 1057 xlabel = ""
1055 1058 ylabel = "Intensity (dB)"
1056 1059
1057 1060 if not self.isConfig:
1058 1061
1059 1062 nplots = 1
1060 1063
1061 1064 self.setup(id=id,
1062 1065 nplots=nplots,
1063 1066 wintitle=wintitle,
1064 1067 showprofile=showprofile,
1065 1068 show=show)
1066 1069
1067 1070 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1068 1071 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1069 1072 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1070 1073
1071 1074 self.FTP_WEI = ftp_wei
1072 1075 self.EXP_CODE = exp_code
1073 1076 self.SUB_EXP_CODE = sub_exp_code
1074 1077 self.PLOT_POS = plot_pos
1075 1078
1076 1079
1077 1080 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1078 1081 self.isConfig = True
1079 1082
1080 1083 self.xdata = numpy.array([])
1081 1084 self.ydata = numpy.array([])
1082 1085
1083 1086 #open file beacon phase
1084 1087 path = '%s%03d' %(self.PREFIX, self.id)
1085 1088 noise_file = os.path.join(path,'%s.txt'%self.name)
1086 1089 self.filename_noise = os.path.join(figpath,noise_file)
1087 1090 self.openfile(self.filename_noise)
1088 1091
1089 1092
1090 1093 #store data beacon phase
1091 1094 self.save_data(self.filename_noise, noisedB, thisDatetime)
1092 1095
1093 1096
1094 1097 self.setWinTitle(title)
1095 1098
1096 1099
1097 1100 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1098 1101
1099 1102 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1100 1103 axes = self.axesList[0]
1101 1104
1102 1105 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1103 1106
1104 1107 if len(self.ydata)==0:
1105 1108 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1106 1109 else:
1107 1110 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1108 1111
1109 1112
1110 1113 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1111 1114 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1112 1115 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1113 1116 XAxisAsTime=True, grid='both'
1114 1117 )
1115 1118
1116 1119 self.draw()
1117 1120
1118 1121 # if save:
1119 1122 #
1120 1123 # if figfile == None:
1121 1124 # figfile = self.getFilename(name = self.name)
1122 1125 #
1123 1126 # self.saveFigure(figpath, figfile)
1124 1127
1125 1128 if save:
1126 1129
1127 1130 self.counter_imagwr += 1
1128 1131 if (self.counter_imagwr==wr_period):
1129 1132 if figfile == None:
1130 1133 figfile = self.getFilename(name = self.name)
1131 1134 self.saveFigure(figpath, figfile)
1132 1135
1133 1136 if ftp:
1134 1137 #provisionalmente envia archivos en el formato de la web en tiempo real
1135 1138 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1136 1139 path = '%s%03d' %(self.PREFIX, self.id)
1137 1140 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1138 1141 self.saveFigure(figpath, ftp_file)
1139 1142 ftp_filename = os.path.join(figpath,ftp_file)
1140 1143 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1141 1144 self.counter_imagwr = 0
1142 1145
1143 1146 self.counter_imagwr = 0
1144 1147
1145 1148 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1146 1149 self.isConfig = False
1147 1150 del self.xdata
1148 1151 del self.ydata
General Comments 0
You need to be logged in to leave comments. Login now