##// END OF EJS Templates
bug fixed: store png file in workspace
Daniel Valdez -
r492:5ccb3e8f6781
parent child
Show More
@@ -1,1151 +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 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
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 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
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 440 self.figfile = None
441 441
442 442 def getSubplots(self):
443 443
444 444 ncol = 1
445 445 nrow = self.nplots
446 446
447 447 return nrow, ncol
448 448
449 449 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
450 450
451 451 self.__showprofile = showprofile
452 452 self.nplots = nplots
453 453
454 454 ncolspan = 1
455 455 colspan = 1
456 456 if showprofile:
457 457 ncolspan = 7
458 458 colspan = 6
459 459 self.__nsubplots = 2
460 460
461 461 self.createFigure(id = id,
462 462 wintitle = wintitle,
463 463 widthplot = self.WIDTH + self.WIDTHPROF,
464 464 heightplot = self.HEIGHT + self.HEIGHTPROF,
465 465 show=show)
466 466
467 467 nrow, ncol = self.getSubplots()
468 468
469 469 counter = 0
470 470 for y in range(nrow):
471 471 for x in range(ncol):
472 472
473 473 if counter >= self.nplots:
474 474 break
475 475
476 476 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
477 477
478 478 if showprofile:
479 479 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
480 480
481 481 counter += 1
482 482
483 483 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
484 484 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
485 485 timerange=None,
486 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
486 save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
487 487 server=None, folder=None, username=None, password=None,
488 488 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
489 489
490 490 """
491 491
492 492 Input:
493 493 dataOut :
494 494 id :
495 495 wintitle :
496 496 channelList :
497 497 showProfile :
498 498 xmin : None,
499 499 xmax : None,
500 500 ymin : None,
501 501 ymax : None,
502 502 zmin : None,
503 503 zmax : None
504 504 """
505 505
506 506 if channelList == None:
507 507 channelIndexList = dataOut.channelIndexList
508 508 else:
509 509 channelIndexList = []
510 510 for channel in channelList:
511 511 if channel not in dataOut.channelList:
512 512 raise ValueError, "Channel %d is not in dataOut.channelList"
513 513 channelIndexList.append(dataOut.channelList.index(channel))
514 514
515 515 if timerange != None:
516 516 self.timerange = timerange
517 517
518 518 #tmin = None
519 519 #tmax = None
520 520 factor = dataOut.normFactor
521 521 x = dataOut.getTimeRange()
522 522 y = dataOut.getHeiRange()
523 523
524 524 z = dataOut.data_spc[channelIndexList,:,:]/factor
525 525 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
526 526 avg = numpy.average(z, axis=1)
527 527
528 528 avgdB = 10.*numpy.log10(avg)
529 529
530 530
531 531 # thisDatetime = dataOut.datatime
532 532 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
533 533 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
534 534 xlabel = ""
535 535 ylabel = "Range (Km)"
536 536
537 537 if not self.isConfig:
538 538
539 539 nplots = len(channelIndexList)
540 540
541 541 self.setup(id=id,
542 542 nplots=nplots,
543 543 wintitle=wintitle,
544 544 showprofile=showprofile,
545 545 show=show)
546 546
547 547 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
548 548
549 549 # if timerange != None:
550 550 # self.timerange = timerange
551 551 # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange)
552 552
553 553
554 554
555 555 if ymin == None: ymin = numpy.nanmin(y)
556 556 if ymax == None: ymax = numpy.nanmax(y)
557 557 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
558 558 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
559 559
560 560 self.FTP_WEI = ftp_wei
561 561 self.EXP_CODE = exp_code
562 562 self.SUB_EXP_CODE = sub_exp_code
563 563 self.PLOT_POS = plot_pos
564 564
565 565 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
566 566 self.isConfig = True
567 567 self.figfile = figfile
568 568
569 569 self.setWinTitle(title)
570 570
571 571 if ((self.xmax - x[1]) < (x[1]-x[0])):
572 572 x[1] = self.xmax
573 573
574 574 for i in range(self.nplots):
575 575 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
576 576 axes = self.axesList[i*self.__nsubplots]
577 577 zdB = avgdB[i].reshape((1,-1))
578 578 axes.pcolorbuffer(x, y, zdB,
579 579 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
580 580 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
581 581 ticksize=9, cblabel='', cbsize="1%")
582 582
583 583 if self.__showprofile:
584 584 axes = self.axesList[i*self.__nsubplots +1]
585 585 axes.pline(avgdB[i], y,
586 586 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
587 587 xlabel='dB', ylabel='', title='',
588 588 ytick_visible=False,
589 589 grid='x')
590 590
591 591 self.draw()
592 592
593 593 if x[1] >= self.axesList[0].xmax:
594 594 self.counter_imagwr = wr_period
595 595 self.__isConfig = False
596 596
597 597
598 598 if self.figfile == None:
599 599 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
600 600 self.figfile = self.getFilename(name = str_datetime)
601 601
602 602 if figpath != '':
603 603
604 604 self.counter_imagwr += 1
605 605 if (self.counter_imagwr>=wr_period):
606 606 # store png plot to local folder
607 607 self.saveFigure(figpath, self.figfile)
608 608 # store png plot to FTP server according to RT-Web format
609 609 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
610 610 ftp_filename = os.path.join(figpath, name)
611 611 self.saveFigure(figpath, ftp_filename)
612 612
613 613 self.counter_imagwr = 0
614 614
615 615
616 616 class CoherenceMap(Figure):
617 617 isConfig = None
618 618 __nsubplots = None
619 619
620 620 WIDTHPROF = None
621 621 HEIGHTPROF = None
622 622 PREFIX = 'cmap'
623 623
624 624 def __init__(self):
625 625 self.timerange = 2*60*60
626 626 self.isConfig = False
627 627 self.__nsubplots = 1
628 628
629 629 self.WIDTH = 800
630 630 self.HEIGHT = 150
631 631 self.WIDTHPROF = 120
632 632 self.HEIGHTPROF = 0
633 633 self.counter_imagwr = 0
634 634
635 635 self.PLOT_CODE = 3
636 636 self.FTP_WEI = None
637 637 self.EXP_CODE = None
638 638 self.SUB_EXP_CODE = None
639 639 self.PLOT_POS = None
640 640 self.counter_imagwr = 0
641 641
642 642 self.xmin = None
643 643 self.xmax = None
644 644
645 645 def getSubplots(self):
646 646 ncol = 1
647 647 nrow = self.nplots*2
648 648
649 649 return nrow, ncol
650 650
651 651 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
652 652 self.__showprofile = showprofile
653 653 self.nplots = nplots
654 654
655 655 ncolspan = 1
656 656 colspan = 1
657 657 if showprofile:
658 658 ncolspan = 7
659 659 colspan = 6
660 660 self.__nsubplots = 2
661 661
662 662 self.createFigure(id = id,
663 663 wintitle = wintitle,
664 664 widthplot = self.WIDTH + self.WIDTHPROF,
665 665 heightplot = self.HEIGHT + self.HEIGHTPROF,
666 666 show=True)
667 667
668 668 nrow, ncol = self.getSubplots()
669 669
670 670 for y in range(nrow):
671 671 for x in range(ncol):
672 672
673 673 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
674 674
675 675 if showprofile:
676 676 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
677 677
678 678 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
679 679 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
680 680 timerange=None,
681 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
681 save=False, figpath='', figfile=None, ftp=False, wr_period=1,
682 682 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
683 683 server=None, folder=None, username=None, password=None,
684 684 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
685 685
686 686 if pairsList == None:
687 687 pairsIndexList = dataOut.pairsIndexList
688 688 else:
689 689 pairsIndexList = []
690 690 for pair in pairsList:
691 691 if pair not in dataOut.pairsList:
692 692 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
693 693 pairsIndexList.append(dataOut.pairsList.index(pair))
694 694
695 695 if timerange != None:
696 696 self.timerange = timerange
697 697
698 698 if pairsIndexList == []:
699 699 return
700 700
701 701 if len(pairsIndexList) > 4:
702 702 pairsIndexList = pairsIndexList[0:4]
703 703
704 704 # tmin = None
705 705 # tmax = None
706 706 x = dataOut.getTimeRange()
707 707 y = dataOut.getHeiRange()
708 708
709 709 #thisDatetime = dataOut.datatime
710 710 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
711 711 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
712 712 xlabel = ""
713 713 ylabel = "Range (Km)"
714 714
715 715 if not self.isConfig:
716 716 nplots = len(pairsIndexList)
717 717 self.setup(id=id,
718 718 nplots=nplots,
719 719 wintitle=wintitle,
720 720 showprofile=showprofile,
721 721 show=show)
722 722
723 723 #tmin, tmax = self.getTimeLim(x, xmin, xmax)
724 724
725 725 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
726 726
727 727 if ymin == None: ymin = numpy.nanmin(y)
728 728 if ymax == None: ymax = numpy.nanmax(y)
729 729 if zmin == None: zmin = 0.
730 730 if zmax == None: zmax = 1.
731 731
732 732 self.FTP_WEI = ftp_wei
733 733 self.EXP_CODE = exp_code
734 734 self.SUB_EXP_CODE = sub_exp_code
735 735 self.PLOT_POS = plot_pos
736 736
737 737 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
738 738
739 739 self.isConfig = True
740 740
741 741 self.setWinTitle(title)
742 742
743 743 if ((self.xmax - x[1]) < (x[1]-x[0])):
744 744 x[1] = self.xmax
745 745
746 746 for i in range(self.nplots):
747 747
748 748 pair = dataOut.pairsList[pairsIndexList[i]]
749 749
750 750 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
751 751 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
752 752 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
753 753
754 754
755 755 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
756 756 coherence = numpy.abs(avgcoherenceComplex)
757 757
758 758 z = coherence.reshape((1,-1))
759 759
760 760 counter = 0
761 761
762 762 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
763 763 axes = self.axesList[i*self.__nsubplots*2]
764 764 axes.pcolorbuffer(x, y, z,
765 765 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
766 766 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
767 767 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
768 768
769 769 if self.__showprofile:
770 770 counter += 1
771 771 axes = self.axesList[i*self.__nsubplots*2 + counter]
772 772 axes.pline(coherence, y,
773 773 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
774 774 xlabel='', ylabel='', title='', ticksize=7,
775 775 ytick_visible=False, nxticks=5,
776 776 grid='x')
777 777
778 778 counter += 1
779 779
780 780 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
781 781
782 782 z = phase.reshape((1,-1))
783 783
784 784 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
785 785 axes = self.axesList[i*self.__nsubplots*2 + counter]
786 786 axes.pcolorbuffer(x, y, z,
787 787 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
788 788 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
789 789 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
790 790
791 791 if self.__showprofile:
792 792 counter += 1
793 793 axes = self.axesList[i*self.__nsubplots*2 + counter]
794 794 axes.pline(phase, y,
795 795 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
796 796 xlabel='', ylabel='', title='', ticksize=7,
797 797 ytick_visible=False, nxticks=4,
798 798 grid='x')
799 799
800 800 self.draw()
801 801
802 802 if x[1] >= self.axesList[0].xmax:
803 803 self.counter_imagwr = wr_period
804 804 self.__isConfig = False
805 805
806 806 if figfile == None:
807 807 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
808 808 figfile = self.getFilename(name = str_datetime)
809 809
810 810 if figpath != '':
811 811
812 812 self.counter_imagwr += 1
813 813 if (self.counter_imagwr>=wr_period):
814 814 # store png plot to local folder
815 815 self.saveFigure(figpath, figfile)
816 816 # store png plot to FTP server according to RT-Web format
817 817 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
818 818 ftp_filename = os.path.join(figpath, name)
819 819 self.saveFigure(figpath, ftp_filename)
820 820
821 821 self.counter_imagwr = 0
822 822
823 823 class PowerProfile(Figure):
824 824 isConfig = None
825 825 __nsubplots = None
826 826
827 827 WIDTHPROF = None
828 828 HEIGHTPROF = None
829 829 PREFIX = 'spcprofile'
830 830
831 831 def __init__(self):
832 832 self.isConfig = False
833 833 self.__nsubplots = 1
834 834
835 835 self.WIDTH = 300
836 836 self.HEIGHT = 500
837 837 self.counter_imagwr = 0
838 838
839 839 def getSubplots(self):
840 840 ncol = 1
841 841 nrow = 1
842 842
843 843 return nrow, ncol
844 844
845 845 def setup(self, id, nplots, wintitle, show):
846 846
847 847 self.nplots = nplots
848 848
849 849 ncolspan = 1
850 850 colspan = 1
851 851
852 852 self.createFigure(id = id,
853 853 wintitle = wintitle,
854 854 widthplot = self.WIDTH,
855 855 heightplot = self.HEIGHT,
856 856 show=show)
857 857
858 858 nrow, ncol = self.getSubplots()
859 859
860 860 counter = 0
861 861 for y in range(nrow):
862 862 for x in range(ncol):
863 863 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
864 864
865 865 def run(self, dataOut, id, wintitle="", channelList=None,
866 866 xmin=None, xmax=None, ymin=None, ymax=None,
867 save=False, figpath='./', figfile=None, show=True, wr_period=1,
867 save=False, figpath='', figfile=None, show=True, wr_period=1,
868 868 server=None, folder=None, username=None, password=None,):
869 869
870 870 if dataOut.flagNoData:
871 871 return None
872 872
873 873 if channelList == None:
874 874 channelIndexList = dataOut.channelIndexList
875 875 channelList = dataOut.channelList
876 876 else:
877 877 channelIndexList = []
878 878 for channel in channelList:
879 879 if channel not in dataOut.channelList:
880 880 raise ValueError, "Channel %d is not in dataOut.channelList"
881 881 channelIndexList.append(dataOut.channelList.index(channel))
882 882
883 883 try:
884 884 factor = dataOut.normFactor
885 885 except:
886 886 factor = 1
887 887
888 888 y = dataOut.getHeiRange()
889 889
890 890 #for voltage
891 891 if dataOut.type == 'Voltage':
892 892 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
893 893 x = x.real
894 894 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
895 895
896 896 #for spectra
897 897 if dataOut.type == 'Spectra':
898 898 x = dataOut.data_spc[channelIndexList,:,:]/factor
899 899 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
900 900 x = numpy.average(x, axis=1)
901 901
902 902
903 903 xdB = 10*numpy.log10(x)
904 904
905 905 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
906 906 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
907 907 xlabel = "dB"
908 908 ylabel = "Range (Km)"
909 909
910 910 if not self.isConfig:
911 911
912 912 nplots = 1
913 913
914 914 self.setup(id=id,
915 915 nplots=nplots,
916 916 wintitle=wintitle,
917 917 show=show)
918 918
919 919 if ymin == None: ymin = numpy.nanmin(y)
920 920 if ymax == None: ymax = numpy.nanmax(y)
921 921 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
922 922 if xmax == None: xmax = numpy.nanmax(xdB)*0.9
923 923
924 924 self.__isConfig = True
925 925
926 926 self.setWinTitle(title)
927 927
928 928 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
929 929 axes = self.axesList[0]
930 930
931 931 legendlabels = ["channel %d"%x for x in channelList]
932 932 axes.pmultiline(xdB, y,
933 933 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
934 934 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
935 935 ytick_visible=True, nxticks=5,
936 936 grid='x')
937 937
938 938 self.draw()
939 939
940 940 if save:
941 941 date = thisDatetime.strftime("%Y%m%d")
942 942 if figfile == None:
943 943 figfile = self.getFilename(name = date)
944 944
945 945 self.saveFigure(figpath, figfile)
946 946
947 947 self.counter_imagwr += 1
948 948 if (ftp and (self.counter_imagwr==wr_period)):
949 949 ftp_filename = os.path.join(figpath,figfile)
950 950 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
951 951 self.counter_imagwr = 0
952 952
953 953 class Noise(Figure):
954 954
955 955 isConfig = None
956 956 __nsubplots = None
957 957
958 958 PREFIX = 'noise'
959 959
960 960 def __init__(self):
961 961
962 962 self.timerange = 24*60*60
963 963 self.isConfig = False
964 964 self.__nsubplots = 1
965 965 self.counter_imagwr = 0
966 966 self.WIDTH = 600
967 967 self.HEIGHT = 300
968 968 self.WIDTHPROF = 120
969 969 self.HEIGHTPROF = 0
970 970 self.xdata = None
971 971 self.ydata = None
972 972
973 973 self.PLOT_CODE = 77
974 974 self.FTP_WEI = None
975 975 self.EXP_CODE = None
976 976 self.SUB_EXP_CODE = None
977 977 self.PLOT_POS = None
978 978
979 979 def getSubplots(self):
980 980
981 981 ncol = 1
982 982 nrow = 1
983 983
984 984 return nrow, ncol
985 985
986 986 def openfile(self, filename):
987 987 f = open(filename,'w+')
988 988 f.write('\n\n')
989 989 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
990 990 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
991 991 f.close()
992 992
993 993 def save_data(self, filename_phase, data, data_datetime):
994 994 f=open(filename_phase,'a')
995 995 timetuple_data = data_datetime.timetuple()
996 996 day = str(timetuple_data.tm_mday)
997 997 month = str(timetuple_data.tm_mon)
998 998 year = str(timetuple_data.tm_year)
999 999 hour = str(timetuple_data.tm_hour)
1000 1000 minute = str(timetuple_data.tm_min)
1001 1001 second = str(timetuple_data.tm_sec)
1002 1002 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1003 1003 f.close()
1004 1004
1005 1005
1006 1006 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1007 1007
1008 1008 self.__showprofile = showprofile
1009 1009 self.nplots = nplots
1010 1010
1011 1011 ncolspan = 7
1012 1012 colspan = 6
1013 1013 self.__nsubplots = 2
1014 1014
1015 1015 self.createFigure(id = id,
1016 1016 wintitle = wintitle,
1017 1017 widthplot = self.WIDTH+self.WIDTHPROF,
1018 1018 heightplot = self.HEIGHT+self.HEIGHTPROF,
1019 1019 show=show)
1020 1020
1021 1021 nrow, ncol = self.getSubplots()
1022 1022
1023 1023 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1024 1024
1025 1025
1026 1026 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1027 1027 xmin=None, xmax=None, ymin=None, ymax=None,
1028 1028 timerange=None,
1029 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1029 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1030 1030 server=None, folder=None, username=None, password=None,
1031 1031 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1032 1032
1033 1033 if channelList == None:
1034 1034 channelIndexList = dataOut.channelIndexList
1035 1035 channelList = dataOut.channelList
1036 1036 else:
1037 1037 channelIndexList = []
1038 1038 for channel in channelList:
1039 1039 if channel not in dataOut.channelList:
1040 1040 raise ValueError, "Channel %d is not in dataOut.channelList"
1041 1041 channelIndexList.append(dataOut.channelList.index(channel))
1042 1042
1043 1043 if timerange != None:
1044 1044 self.timerange = timerange
1045 1045
1046 1046 tmin = None
1047 1047 tmax = None
1048 1048 x = dataOut.getTimeRange()
1049 1049 y = dataOut.getHeiRange()
1050 1050 factor = dataOut.normFactor
1051 1051 noise = dataOut.noise()/factor
1052 1052 noisedB = 10*numpy.log10(noise)
1053 1053
1054 1054 #thisDatetime = dataOut.datatime
1055 1055 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1056 1056 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1057 1057 xlabel = ""
1058 1058 ylabel = "Intensity (dB)"
1059 1059
1060 1060 if not self.isConfig:
1061 1061
1062 1062 nplots = 1
1063 1063
1064 1064 self.setup(id=id,
1065 1065 nplots=nplots,
1066 1066 wintitle=wintitle,
1067 1067 showprofile=showprofile,
1068 1068 show=show)
1069 1069
1070 1070 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1071 1071 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1072 1072 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1073 1073
1074 1074 self.FTP_WEI = ftp_wei
1075 1075 self.EXP_CODE = exp_code
1076 1076 self.SUB_EXP_CODE = sub_exp_code
1077 1077 self.PLOT_POS = plot_pos
1078 1078
1079 1079
1080 1080 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1081 1081 self.isConfig = True
1082 1082
1083 1083 self.xdata = numpy.array([])
1084 1084 self.ydata = numpy.array([])
1085 1085
1086 1086 #open file beacon phase
1087 1087 path = '%s%03d' %(self.PREFIX, self.id)
1088 1088 noise_file = os.path.join(path,'%s.txt'%self.name)
1089 1089 self.filename_noise = os.path.join(figpath,noise_file)
1090 1090 self.openfile(self.filename_noise)
1091 1091
1092 1092
1093 1093 #store data beacon phase
1094 1094 self.save_data(self.filename_noise, noisedB, thisDatetime)
1095 1095
1096 1096
1097 1097 self.setWinTitle(title)
1098 1098
1099 1099
1100 1100 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1101 1101
1102 1102 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1103 1103 axes = self.axesList[0]
1104 1104
1105 1105 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1106 1106
1107 1107 if len(self.ydata)==0:
1108 1108 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1109 1109 else:
1110 1110 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1111 1111
1112 1112
1113 1113 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1114 1114 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1115 1115 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1116 1116 XAxisAsTime=True, grid='both'
1117 1117 )
1118 1118
1119 1119 self.draw()
1120 1120
1121 1121 # if save:
1122 1122 #
1123 1123 # if figfile == None:
1124 1124 # figfile = self.getFilename(name = self.name)
1125 1125 #
1126 1126 # self.saveFigure(figpath, figfile)
1127 1127
1128 1128 if save:
1129 1129
1130 1130 self.counter_imagwr += 1
1131 1131 if (self.counter_imagwr==wr_period):
1132 1132 if figfile == None:
1133 1133 figfile = self.getFilename(name = self.name)
1134 1134 self.saveFigure(figpath, figfile)
1135 1135
1136 1136 if ftp:
1137 1137 #provisionalmente envia archivos en el formato de la web en tiempo real
1138 1138 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1139 1139 path = '%s%03d' %(self.PREFIX, self.id)
1140 1140 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1141 1141 self.saveFigure(figpath, ftp_file)
1142 1142 ftp_filename = os.path.join(figpath,ftp_file)
1143 1143 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1144 1144 self.counter_imagwr = 0
1145 1145
1146 1146 self.counter_imagwr = 0
1147 1147
1148 1148 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1149 1149 self.isConfig = False
1150 1150 del self.xdata
1151 1151 del self.ydata
General Comments 0
You need to be logged in to leave comments. Login now