def _create_plot(self): plot_data = ArrayPlotData(image=self.image) plot = Plot(plot_data, width=500, height=500, resizable='hv', aspect_ratio=1.0, padding=8, padding_left=32, padding_bottom=32) plot.img_plot('image', colormap=RdBu_r, xbounds=(self.X[0],self.X[-1]), ybounds=(self.Y[0],self.Y[-1]), name='image') image = plot.plots['image'][0] image.x_mapper.domain_limits = (self.imager.get_x_range()[0],self.imager.get_x_range()[1]) image.y_mapper.domain_limits = (self.imager.get_y_range()[0],self.imager.get_y_range()[1]) zoom = AspectZoomTool(image, enable_wheel=False) cursor = CursorTool2D(image, drag_button='left', color='yellow', marker_size=1.0, line_width=1.0 ) image.overlays.append(cursor) image.overlays.append(zoom) colormap = image.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=16, height=320, padding=8, padding_left=32) container = HPlotContainer() container.add(plot) container.add(colorbar) z_label = PlotLabel(text='z=0.0', color='red', hjustify='left', vjustify='bottom', position=[10,10]) container.overlays.append(z_label) container.tools.append(SaveTool(container)) self.plot_data = plot_data self.scan_plot = image self.cursor = cursor self.zoom = zoom self.figure = plot self.figure_container = container self.sync_trait('z_label_text', z_label, 'text')
def _create_line_plot(self): line_data = ArrayPlotData(current=np.array(()), frequency=np.array(()),) plot = Plot(line_data, padding=8, padding_left=64, padding_bottom=36) plot.plot(('current','frequency'), color='blue', name='zeeman') plot.index_axis.title = 'current [mA]' plot.value_axis.title = 'frequency [MHz]' plot.tools.append(SaveTool(plot)) self.line_data = line_data self.line_plot = plot
def _create_line_plot(self): line_data = ArrayPlotData( index=np.array((0, 1)), spin_state=np.array((0, 0)), ) plot = Plot(line_data, padding=8, padding_left=64, padding_bottom=36) plot.plot(('index', 'spin_state'), color='blue', name='spin_state') plot.index_axis.title = 'time [micro s]' plot.value_axis.title = 'spin state' plot.tools.append(SaveTool(plot)) self.line_data = line_data self.line_plot = plot
def _figure_line_default(self): plot = Plot(self.plot_data_line, width=100, height=100, padding=8, padding_left=64, padding_bottom=32) plot.plot(('x', 'y'), color='blue') plot.plot(('x', 'fit'), color='red') plot.index_axis.title = 'z [micron]' plot.value_axis.title = 'Fluorescence [ counts / s ]' plot.tools.append(SaveTool(plot)) return plot
def _create_matrix_plot(self): matrix_data = ArrayPlotData(image=np.zeros((2, 2))) matrix_plot = Plot(matrix_data, padding=8, padding_left=64, padding_bottom=32) matrix_plot.index_axis.title = 'time bins' matrix_plot.value_axis.title = 'tau' matrix_plot.img_plot('image', xbounds=(self.tau[0], self.tau[-1]), ybounds=(0, self.n_lines), colormap=Spectral) matrix_plot.tools.append(SaveTool(matrix_plot)) self.matrix_data = matrix_data self.matrix_plot = matrix_plot
def _replot(self): self.TracePlot = Plot(self.plot_data, width=500, height=500, resizable='hv') self.TracePlot.legend.align = 'll' n=0 if self.c_enable0: self.TracePlot.plot(('t','y0'), type='line', color='blue', name='channel 0') n+=1 if self.c_enable1: self.TracePlot.plot(('t','y1'), type='line', color='red', name='channel 1') n+=1 if self.c_enable2: self.TracePlot.plot(('t','y2'), type='line', color='green', name='channel 2') n+=1 if self.c_enable3: self.TracePlot.plot(('t','y3'), type='line', color='black', name='channel 3') n+=1 if self.c_enable4: self.TracePlot.plot(('t','y4'), type='line', color='blue', name='channel 4') n+=1 if self.c_enable5: self.TracePlot.plot(('t','y5'), type='line', color='red', name='channel 5') n+=1 if self.c_enable6: self.TracePlot.plot(('t','y6'), type='line', color='green', name='channel 6') n+=1 if self.c_enable7: self.TracePlot.plot(('t','y7'), type='line', color='black', name='channel 7') if n > 1: self.TracePlot.legend.visible = True else: self.TracePlot.legend.visible = False
def _create_pulse_plot(self): pulse_data = ArrayPlotData(x=np.array((0., 100)), y=np.array((0, 1))) plot = Plot(pulse_data, padding=8, padding_left=64, padding_bottom=36) line = plot.plot(('x', 'y'), style='line', color='blue', name='data')[0] plot.index_axis.title = 'time bins' plot.value_axis.title = 'intensity' edge_marker = LinePlot( index=ArrayDataSource(np.array((0, 0))), value=ArrayDataSource(np.array((0, 1e9))), color='red', index_mapper=LinearMapper(range=plot.index_range), value_mapper=LinearMapper(range=plot.value_range), name='marker') plot.add(edge_marker) plot.tools.append(SaveTool(plot)) self.pulse_data = pulse_data self.pulse_plot = plot
def _create_line_plot(self): line_data = ArrayPlotData(index=np.array((0, 1)), spin_state=np.array((0, 0)), fit=np.array((0, 0))) plot = Plot(line_data, padding=8, padding_left=64, padding_bottom=36) plot.plot(('index', 'spin_state'), color='blue', name='spin_state') plot.plot(('index', 'fit'), color='red', name='fit') plot.index_axis.title = 'time [micro s]' plot.value_axis.title = 'spin state' plot.overlays.insert( 0, PlotLabel(text=self.label_text, hjustify='left', vjustify='bottom', position=[64, 32])) plot.tools.append(SaveTool(plot)) self.line_data = line_data self.line_plot = plot
def _create_matrix_plot(self): matrix_data = ArrayPlotData(image=np.zeros((2, 2))) plot = Plot(matrix_data, width=500, height=500, resizable='hv', padding=8, padding_left=48, padding_bottom=36) plot.index_axis.title = 'time [ns]' plot.value_axis.title = 'laser pulse #' plot.img_plot('image', xbounds=(0, 1), ybounds=(0, 1), colormap=Spectral)[0] plot.tools.append(SaveTool(plot)) self.matrix_data = matrix_data self.matrix_plot = plot
def _create_line_plot(self): line_data = ArrayPlotData(index=np.array((0, 1)), counts=np.array((0, 0)), pulse_indices=np.array((0, 0)), pulse_values=np.array((0, 0))) plot = Plot(line_data, padding=8, padding_left=64, padding_bottom=36) plot.plot(('index', 'counts'), color='blue', name='counts') plot.plot(('pulse_indices', 'pulse_values'), type='scatter', marker='circle', color='none', outline_color='red', line_width=1.0, name='pulses') plot.index_axis.title = 'time [ns]' plot.value_axis.title = 'spin state' #plot.overlays.insert(0, PlotLabel(text=self.label_text, hjustify='left', vjustify='bottom', position=[64,32]) ) self.line_data = line_data self.line_plot = plot
def _figure_image_default(self): plot = Plot(self.plot_data_image, width=100, height=100, padding=8, padding_left=48, padding_bottom=32) plot.img_plot('image', colormap=RdBu_r, name='image') plot.aspect_ratio = 1 plot.index_mapper.domain_limits = (self.imager.get_x_range()[0], self.imager.get_x_range()[1]) plot.value_mapper.domain_limits = (self.imager.get_y_range()[0], self.imager.get_y_range()[1]) plot_fit = Plot(self.plot_data_image, width=100, height=100, padding=8, padding_left=48, padding_bottom=32) plot_fit.img_plot('fit', colormap=RdBu_r, name='fit') plot_fit.aspect_ratio = 1 plot_fit.index_mapper.domain_limits = (self.imager.get_x_range()[0], self.imager.get_x_range()[1]) plot_fit.value_mapper.domain_limits = (self.imager.get_y_range()[0], self.imager.get_y_range()[1]) container = HPlotContainer() image = plot.plots['image'][0] colormap = image.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=16, height=320, padding=8, padding_left=32) container = HPlotContainer() container.add(plot) container.add(plot_fit) container.add(colorbar) container.overlays.append(self.image_label) container.tools.append(SaveTool(container)) return container
def _figure_drift_default(self): plot = Plot(self.plot_data_drift, width=100, height=100, padding=8, padding_left=64, padding_bottom=32) plot.plot(('t', 'x'), type='line', color='blue', name='x') plot.plot(('t', 'y'), type='line', color='red', name='y') plot.plot(('t', 'z'), type='line', color='green', name='z') bottom_axis = PlotAxis( plot, orientation="bottom", tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem())) plot.index_axis = bottom_axis plot.index_axis.title = 'time' plot.value_axis.title = 'drift [micron]' plot.legend.visible = True plot.tools.append(SaveTool(plot)) return plot
def _create_plot(self): plot_data = ArrayPlotData(image=self.image) plot = Plot(plot_data, width=500, height=500, resizable='hv', aspect_ratio=1.0, padding=8, padding_left=32, padding_bottom=32) plot.img_plot('image', colormap=jet, xbounds=(self.X[0], self.X[-1]), ybounds=(self.Y[0], self.Y[-1]), name='image') image = plot.plots['image'][0] bwplot_data = ArrayPlotData(bwimage=self.bwimage) bwplot = Plot(bwplot_data, width=500, height=500, resizable='hv', aspect_ratio=1.0, padding=8, padding_left=32, padding_bottom=32) bwplot.img_plot('bwimage', colormap=jet, xbounds=(self.X[0], self.X[-1]), ybounds=(self.Y[0], self.Y[-1]), name='bwimage') bwimage = bwplot.plots['bwimage'][0] image.x_mapper.domain_limits = (self.confocal.scanner.getXRange()[0], self.confocal.scanner.getXRange()[1]) image.y_mapper.domain_limits = (self.confocal.scanner.getYRange()[0], self.confocal.scanner.getYRange()[1]) bwimage.x_mapper.domain_limits = (self.confocal.scanner.getXRange()[0], self.confocal.scanner.getXRange()[1]) bwimage.y_mapper.domain_limits = (self.confocal.scanner.getYRange()[0], self.confocal.scanner.getYRange()[1]) colormap = image.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=16, height=320, padding=8, padding_left=32) container = HPlotContainer() container.add(plot) container.add(colorbar) container.add(bwplot) container.tools.append(SaveTool(container)) self.plot_data = plot_data self.scan_plot = image self.figure = plot self.bwplot_data = bwplot_data self.bwscan_plot = bwimage self.bwfigure = bwplot self.figure_container = container
def _create_plot(self): plot_data = ArrayPlotData(image=self.image) plot = Plot(plot_data, width=500, height=500, resizable='hv', aspect_ratio=1.0, padding=8, padding_left=32, padding_bottom=32) plot.img_plot('image', colormap=jet, xbounds=(self.X[0], self.X[-1]), ybounds=(self.Y[0], self.Y[-1]), name='image') image = plot.plots['image'][0] fitplot_data = ArrayPlotData(fitimage=self.fitimage) fitplot = Plot(fitplot_data, width=500, height=500, resizable='hv', aspect_ratio=1.0, padding=8, padding_left=32, padding_bottom=32) fitplot.img_plot('fitimage', colormap=jet, xbounds=(self.Xfit[0], self.Xfit[-1]), ybounds=(self.Yfit[0], self.Yfit[-1]), name='fitimage') fitplot.overlays.insert( 0, PlotLabel(text=self.label_text, hjustify='right', vjustify='bottom', position=[880, 590])) fitimage = fitplot.plots['fitimage'][0] image.x_mapper.domain_limits = (self.confocal.scanner.getXRange()[0], self.confocal.scanner.getXRange()[1]) image.y_mapper.domain_limits = (self.confocal.scanner.getYRange()[0], self.confocal.scanner.getYRange()[1]) fitimage.x_mapper.domain_limits = ( self.confocal.scanner.getXRange()[0], self.confocal.scanner.getXRange()[1]) fitimage.y_mapper.domain_limits = ( self.confocal.scanner.getYRange()[0], self.confocal.scanner.getYRange()[1]) colormap = image.color_mapper colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range), color_mapper=colormap, plot=plot, orientation='v', resizable='v', width=16, height=320, padding=8, padding_left=32) container = HPlotContainer() container.add(plot) container.add(colorbar) container.add(fitplot) container.tools.append(SaveTool(container)) self.plot_data = plot_data self.scan_plot = image self.figure = plot self.fitplot_data = fitplot_data self.fitscan_plot = fitimage self.fitfigure = fitplot self.figure_container = container
class TimeTrace(Job, GetSetItemsMixin): TraceLength = Range(low=10, high=10000, value=100, desc='Length of Count Trace', label='Trace Length') SecondsPerPoint = Range(low=0.001, high=1, value=0.1, desc='Seconds per point [s]', label='Seconds per point [s]') RefreshRate = Range(low=0.01, high=1, value=0.1, desc='Refresh rate [s]', label='Refresh rate [s]') # trace data value = Array() index = Array() c_enable0 = Bool(False, label='channel 0', desc='enable channel 0') c_enable1 = Bool(False, label='channel 1', desc='enable channel 1') c_enable2 = Bool(False, label='channel 2', desc='enable channel 2') c_enable3 = Bool(False, label='channel 3', desc='enable channel 3') c_enable4 = Bool(False, label='channel 4', desc='enable channel 4') c_enable5 = Bool(False, label='channel 5', desc='enable channel 5') c_enable6 = Bool(False, label='channel 6', desc='enable channel 6') c_enable7 = Bool(False, label='channel 7', desc='enable channel 7') TracePlot = Instance(Plot) plot_data = Instance(ArrayPlotData) def __init__(self, time_tagger, **kwargs): super(TimeTrace, self).__init__(**kwargs) self.time_tagger = time_tagger self._reset() #self.on_trait_change(self._index_changed, 'index', dispatch='ui') #self.on_trait_change(self._value_changed, 'value', dispatch='ui') #self._create_counter() def _channels_default(self): return list( np.arange(8)[np.array([ self.enable_0, self.enable_1, self.enable_2, self.enable_3, self.enable_4, self.enable_5, self.enable_6, self.enable_7 ])]) @on_trait_change( 'enable_0,enable_1,enable_2,enable_3,enable_4,enable_5,enable_6,enable_7' ) def _update_channels(self): self.channels = self._channels_default() @on_trait_change('channels,number_of_points,seconds_per_point') def _reset(self): if hasattr(self, '_timer'): self._timer.Stop() self._create_plot() self._counter = Counter(self.tagger, self.channels, int(self.seconds_per_point * 1e12), self.number_of_points) self.time = self._counter.getIndex() * 1e-12 self.count_rate = self._counter.getData() / self.seconds_per_point self._timer = Timer(200, self._refresh_data) self._timer.Start() def _refresh_data(self): self.count_rate = self._counter.getData() / self.seconds_per_point def _create_counter(self): channels = [] for i in range(8): if getattr(self, 'c_enable%i' % i): channels.append(i) self.counter = Counter(self.time_tagger, channels, int(self.SecondsPerPoint * 1e12), self.TraceLength) self.value = self.counter.getData() / self.seconds_per_point self.index = self.counter.getIndex() * 1e-12 self.channels = channels def _value_default(self): return numpy.zeros((self.TraceLength, )) def _index_default(self): return self.SecondsPerPoint * numpy.arange(self.TraceLength) def _index_changed(self): self.plot_data.set_data('t', self.index) def _value_changed(self, new): for i, line_i in enumerate(new): self.plot_data.set_data('y%i' % self.channels[i], line_i) def _TraceLength_changed(self): self._create_counter() def _SecondsPerPoint_changed(self): self._create_counter() def _plot_data_default(self): return ArrayPlotData(t=self.T, y0=self.C0, y1=self.C1, y2=self.C2, y3=self.C3, y4=self.C4, y5=self.C5, y6=self.C6, y7=self.C7, y8=self.C0C1) def _TracePlot_default(self): plot = Plot(self.plot_data, width=500, height=500, resizable='hv') plot.plot(('t', 'y0'), type='line', color='black') plot.tools.append(SaveTool(plot)) return plot @on_trait_change( 'c_enable0,c_enable1,c_enable2,c_enable3,c_enable4,c_enable5,c_enable6,c_enable7' ) def _replot(self): self.TracePlot = Plot(self.plot_data, width=500, height=500, resizable='hv') self.TracePlot.legend.align = 'll' n = 0 if self.c_enable0: self.TracePlot.plot(('t', 'y0'), type='line', color='blue', name='channel 0') n += 1 if self.c_enable1: self.TracePlot.plot(('t', 'y1'), type='line', color='red', name='channel 1') n += 1 if self.c_enable2: self.TracePlot.plot(('t', 'y2'), type='line', color='green', name='channel 2') n += 1 if self.c_enable3: self.TracePlot.plot(('t', 'y3'), type='line', color='black', name='channel 3') n += 1 if self.c_enable4: self.TracePlot.plot(('t', 'y4'), type='line', color='blue', name='channel 4') n += 1 if self.c_enable5: self.TracePlot.plot(('t', 'y5'), type='line', color='red', name='channel 5') n += 1 if self.c_enable6: self.TracePlot.plot(('t', 'y6'), type='line', color='green', name='channel 6') n += 1 if self.c_enable7: self.TracePlot.plot(('t', 'y7'), type='line', color='black', name='channel 7') if n > 1: self.TracePlot.legend.visible = True else: self.TracePlot.legend.visible = False def _run(self): """Acquire Count Trace""" while True: threading.current_thread().stop_request.wait(self.RefreshRate) if threading.current_thread().stop_request.isSet(): break self.value = self.counter.getData() / self.SecondsPerPoint traits_view = View( HGroup( Item('TracePlot', editor=ComponentEditor(), show_label=False), #VGroup(Item('c_enable0'),Item('c_enable1'),Item('c_enable2'),Item('c_enable3'),Item('c_enable4'),Item('c_enable5'),Item('c_enable6'),Item('c_enable7'),Item('sum_enable')) VGroup(Item('c_enable0'), Item('c_enable1'), Item('c_enable2'), Item('c_enable3'), Item('c_enable4'), Item('c_enable5'), Item('c_enable6'), Item('sum_enable'))), Item('TraceLength'), Item('SecondsPerPoint'), Item('RefreshRate'), title='Counter', width=800, height=600, buttons=[], resizable=True, handler=StartThreadHandler)
def _TracePlot_default(self): plot = Plot(self.plot_data, width=500, height=500, resizable='hv') plot.plot(('t', 'y0'), type='line', color='black') plot.tools.append(SaveTool(plot)) return plot