##// END OF EJS Templates
Add localtime anf fix pause figs
Juan C. Espinoza -
r1089:d97088881fbc
parent child
Show More
@@ -20,10 +20,19 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15
20 20 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
21 21 matplotlib.pyplot.register_cmap(cmap=ncmap)
22 22
23 func = lambda x, pos: '{}'.format(datetime.datetime.utcfromtimestamp(x).strftime('%H:%M'))
24
25 23 CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'RdBu_r', 'seismic')]
26 24
25 def figpause(interval):
26 backend = plt.rcParams['backend']
27 if backend in matplotlib.rcsetup.interactive_bk:
28 figManager = matplotlib._pylab_helpers.Gcf.get_active()
29 if figManager is not None:
30 canvas = figManager.canvas
31 if canvas.figure.stale:
32 canvas.draw()
33 canvas.start_event_loop(interval)
34 return
35
27 36 class PlotData(Operation, Process):
28 37 '''
29 38 Base class for Schain plotting operations
@@ -77,6 +86,12 class PlotData(Operation, Process):
77 86 self.colorbar = kwargs.get('colorbar', True)
78 87 self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1])
79 88 self.titles = ['' for __ in range(16)]
89
90 def __fmtTime(self, x, pos):
91 '''
92 '''
93
94 return '{}'.format(self.getDateTime(x).strftime('%H:%M'))
80 95
81 96 def __setup(self):
82 97 '''
@@ -86,6 +101,10 class PlotData(Operation, Process):
86 101 self.setup()
87 102
88 103 self.time_label = 'LT' if self.localtime else 'UTC'
104 if self.data.localtime:
105 self.getDateTime = datetime.datetime.fromtimestamp
106 else:
107 self.getDateTime = datetime.datetime.utcfromtimestamp
89 108
90 109 if self.width is None:
91 110 self.width = 8
@@ -150,6 +169,8 class PlotData(Operation, Process):
150 169 fig.canvas.mpl_connect('button_press_event', self.onBtnPress)
151 170 fig.canvas.mpl_connect('motion_notify_event', self.onMotion)
152 171 fig.canvas.mpl_connect('button_release_event', self.onBtnRelease)
172 if self.show:
173 fig.show()
153 174
154 175 def OnKeyPress(self, event):
155 176 '''
@@ -165,11 +186,12 class PlotData(Operation, Process):
165 186 ax.index = len(CMAPS) - 1
166 187 elif ax.index == len(CMAPS):
167 188 ax.index = 0
168 cmap = CMAPS[ax.index]
189 cmap = CMAPS[ax.index]
169 190 ax.cbar.set_cmap(cmap)
170 191 ax.cbar.draw_all()
171 192 ax.plt.set_cmap(cmap)
172 193 ax.cbar.patch.figure.canvas.draw()
194 self.colormap = cmap.name
173 195
174 196 def OnBtnScroll(self, event):
175 197 '''
@@ -307,8 +329,10 class PlotData(Operation, Process):
307 329 xmin = self.min_time
308 330 else:
309 331 if self.xaxis is 'time':
310 dt = datetime.datetime.utcfromtimestamp(self.min_time)
332 dt = self.getDateTime(self.min_time)
311 333 xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) - datetime.datetime(1970, 1, 1)).total_seconds()
334 if self.data.localtime:
335 xmin += time.timezone
312 336 else:
313 337 xmin = self.xmin
314 338
@@ -316,8 +340,10 class PlotData(Operation, Process):
316 340 xmax = xmin+self.xrange*60*60
317 341 else:
318 342 if self.xaxis is 'time':
319 dt = datetime.datetime.utcfromtimestamp(self.min_time)
343 dt = self.getDateTime(self.max_time)
320 344 xmax = (dt.replace(hour=int(self.xmax), minute=0, second=0) - datetime.datetime(1970, 1, 1)).total_seconds()
345 if self.data.localtime:
346 xmax += time.timezone
321 347 else:
322 348 xmax = self.xmax
323 349
@@ -333,7 +359,7 class PlotData(Operation, Process):
333 359 ax.set_facecolor(self.bgcolor)
334 360 ax.yaxis.set_major_locator(MultipleLocator(ystep))
335 361 if self.xaxis is 'time':
336 ax.xaxis.set_major_formatter(FuncFormatter(func))
362 ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime))
337 363 ax.xaxis.set_major_locator(LinearLocator(9))
338 364 if self.xlabel is not None:
339 365 ax.set_xlabel(self.xlabel)
@@ -356,7 +382,7 class PlotData(Operation, Process):
356 382
357 383 ax.set_title('{} - {} {}'.format(
358 384 self.titles[n],
359 datetime.datetime.utcfromtimestamp(self.max_time).strftime('%H:%M:%S'),
385 self.getDateTime(self.max_time).strftime('%H:%M:%S'),
360 386 self.time_label),
361 387 size=8)
362 388 ax.set_xlim(xmin, xmax)
@@ -373,13 +399,11 class PlotData(Operation, Process):
373 399 for n, fig in enumerate(self.figures):
374 400 if self.nrows == 0 or self.nplots == 0:
375 401 log.warning('No data', self.name)
376 continue
377 if self.show:
378 fig.show()
402 continue
379 403
380 404 fig.tight_layout()
381 405 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
382 datetime.datetime.utcfromtimestamp(self.max_time).strftime('%Y/%m/%d')))
406 self.getDateTime(self.max_time).strftime('%Y/%m/%d')))
383 407 # fig.canvas.draw()
384 408
385 409 if self.save and self.data.ended:
@@ -393,7 +417,7 class PlotData(Operation, Process):
393 417 '{}{}_{}.png'.format(
394 418 self.CODE,
395 419 label,
396 datetime.datetime.utcfromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')
420 self.getDateTime(self.saveTime).strftime('%y%m%d_%H%M%S')
397 421 )
398 422 )
399 423 print 'Saving figure: {}'.format(figname)
@@ -421,12 +445,15 class PlotData(Operation, Process):
421 445 while True:
422 446 try:
423 447 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)
424
425 if self.localtime:
448 if self.data.localtime and self.localtime:
449 self.times = self.data.times
450 elif self.data.localtime and not self.localtime:
451 self.times = self.data.times + time.timezone
452 elif not self.data.localtime and self.localtime:
426 453 self.times = self.data.times - time.timezone
427 454 else:
428 455 self.times = self.data.times
429
456
430 457 self.min_time = self.times[0]
431 458 self.max_time = self.times[-1]
432 459
@@ -439,7 +466,7 class PlotData(Operation, Process):
439 466 except zmq.Again as e:
440 467 log.log('Waiting for data...')
441 468 if self.data:
442 plt.pause(self.data.throttle)
469 figpause(self.data.throttle)
443 470 else:
444 471 time.sleep(2)
445 472
@@ -814,8 +841,8 class PlotSkyMapData(PlotData):
814 841 self.ax.plot.set_data(x, y)
815 842
816 843
817 dt1 = datetime.datetime.utcfromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S')
818 dt2 = datetime.datetime.utcfromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')
844 dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S')
845 dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S')
819 846 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
820 847 dt2,
821 848 len(x))
@@ -81,7 +81,9 class Data(object):
81 81 self.plottypes = plottypes
82 82 self.throttle = throttle_value
83 83 self.ended = False
84 self.__times = []
84 self.localtime = False
85 self.__times = []
86 self.__heights = []
85 87
86 88 def __str__(self):
87 89 dum = ['{}{}'.format(key, self.shape(key)) for key in self.data]
@@ -141,6 +143,7 class Data(object):
141 143 self.pairs = dataOut.pairsList
142 144 self.channels = dataOut.channelList
143 145 self.interval = dataOut.getTimeInterval()
146 self.localtime = dataOut.useLocalTime
144 147 if 'spc' in self.plottypes or 'cspc' in self.plottypes:
145 148 self.xrange = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
146 149 self.__heights.append(dataOut.heightList)
@@ -396,8 +399,8 class PublishData(Operation):
396 399 if self.zeromq is 1:
397 400 if self.verbose:
398 401 log.log(
399 '{} - {}'.format(self.dataOut.type, self.dataOut.datatime),
400 'Sending'
402 'Sending {} - {}'.format(self.dataOut.type, self.dataOut.datatime),
403 self.name
401 404 )
402 405 self.zmq_socket.send_pyobj(self.dataOut)
403 406
@@ -486,6 +489,7 class PlotterReceiver(ProcessingUnit, Process):
486 489 self.plot_address = plot_address
487 490 self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')]
488 491 self.realtime = kwargs.get('realtime', False)
492 self.localtime = kwargs.get('localtime', True)
489 493 self.throttle_value = kwargs.get('throttle', 5)
490 494 self.sendData = self.initThrottle(self.throttle_value)
491 495 self.dates = []
@@ -560,7 +564,15 class PlotterReceiver(ProcessingUnit, Process):
560 564
561 565 while True:
562 566 dataOut = self.receiver.recv_pyobj()
563 dt = datetime.datetime.utcfromtimestamp(dataOut.utctime).date()
567 tm = dataOut.utctime
568 if dataOut.useLocalTime:
569 if not self.localtime:
570 tm += time.timezone
571 dt = datetime.datetime.fromtimestamp(tm).date()
572 else:
573 if self.localtime:
574 tm -= time.timezone
575 dt = datetime.datetime.utcfromtimestamp(tm).date()
564 576 sended = False
565 577 if dt not in self.dates:
566 578 if self.data:
@@ -604,4 +616,4 class PlotterReceiver(ProcessingUnit, Process):
604 616 if 'plot' in kwargs:
605 617 log.success('[Sending] Config data to web for {}'.format(kwargs['code'].upper()))
606 618 sender_web_config.send_string(json.dumps(kwargs))
607 self.isWebConfig = True No newline at end of file
619 self.isWebConfig = True
General Comments 0
You need to be logged in to leave comments. Login now