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