def OnInit(self): self.HARDWARE_DEBUG = HARDWARE_DEBUG self.frame = MCLStage3DFrame(None) self.nanodrive = MCLNanoDrive(debug=self.HARDWARE_DEBUG) try: self.frame.m_staticText_maxdim.SetLabel( "[ %g x %g x %g ]" % (self.nanodrive.cal_X, self.nanodrive.cal_Y, self.nanodrive.cal_Z)) except Exception as e: print e self.frame.m_staticText_maxdim.SetLabel("[ ? ? ? ]") y, x, z = self.nanodrive.get_pos() self.frame.m_scrollBar_x.SetScrollbar(100 * x / self.nanodrive.cal_Y, 1, 100, 1, refresh=True) self.frame.m_scrollBar_y.SetScrollbar(100 * y / self.nanodrive.cal_X, 1, 100, 1, refresh=True) self.frame.m_scrollBar_z.SetScrollbar(100 * z / self.nanodrive.cal_Z, 1, 100, 1, refresh=True) self.frame.m_textCtrl_x.SetValue("%02.3f" % x) self.frame.m_textCtrl_y.SetValue("%02.3f" % y) self.frame.m_textCtrl_z.SetValue("%02.3f" % z) self.frame.m_scrollBar_x.Bind(wx.EVT_SCROLL, self.on_scroll) self.frame.m_scrollBar_y.Bind(wx.EVT_SCROLL, self.on_scroll) self.frame.m_scrollBar_z.Bind(wx.EVT_SCROLL, self.on_scroll) self.frame.m_textCtrl_x.Bind(wx.EVT_TEXT_ENTER, self.on_change_text) self.frame.m_textCtrl_y.Bind(wx.EVT_TEXT_ENTER, self.on_change_text) self.frame.m_textCtrl_z.Bind(wx.EVT_TEXT_ENTER, self.on_change_text) # Figure self.wxfig = MPLFigureWithToolbarWX(self.frame.m_panel_plot) self.fig = self.wxfig.fig self.ax = self.fig.add_subplot(111) self.ax.set_xlim(0, self.nanodrive.cal_Y) self.ax.set_ylim(self.nanodrive.cal_X, 0) self.xypos_line, = self.ax.plot([x], [y], 'ro') self.frame.Show() return True
def OnInit(self): print "OnInit" self.HARDWARE_DEBUG = HARDWARE_DEBUG self.STORED_HISTCHAN = 5000 self.frame = ScanningTRPLControlFrame(None) # Logged Quantities self.x_position = LoggedQuantity( name='x_position', dtype=np.float, display_textctrl=self.frame.m_textCtrl_current_x, input_textctrl=self.frame.m_textCtrl_set_current_x) self.y_position = LoggedQuantity( name='x_position', dtype=np.float, display_textctrl=self.frame.m_textCtrl_current_y, input_textctrl=self.frame.m_textCtrl_set_current_y) # Figure self.wxfig = MPLFigureWithToolbarWX(self.frame.m_panel_plot) self.fig = self.wxfig.fig self.ax = self.fig.add_subplot(111) # Optimization Fig self.fig2 = pl.figure(2) self.ax2 = self.fig2.add_subplot(111) self.c0_hist_line, = self.ax2.plot(np.zeros(HIST_LEN, dtype=float)) self.c1_hist_line, = self.ax2.plot(np.zeros(HIST_LEN, dtype=float)) self.hist_vline = self.ax2.axvline(0) self.c0_hist = np.zeros(HIST_LEN, dtype=float) self.c1_hist = np.zeros(HIST_LEN, dtype=float) self.fig2.show() self.hist_i = 0 # hardware self.scanning = False self.nanodrive = MCLNanoDrive(debug=self.HARDWARE_DEBUG) try: self.frame.m_staticText_maxdim.SetLabel( "max: %g x %g um" % (self.nanodrive.cal_Y, self.nanodrive.cal_X)) except Exception as e: print e self.frame.m_staticText_maxdim.SetLabel("max: ? x ? um") #self.frame.m_staticText_maxdim.SetLabel("max: 75 x 75 um") #self.srslockin = SRSlockin(port="COM5", gpibaddr=8) #self.lockinstage = LockinStage(srs=self.srslockin, # POSMIN=0, POSMAX=75, channels={'x':1, 'y':2, 'z':3}) self.picoharp = PicoHarp300(devnum=0, debug=self.HARDWARE_DEBUG) self.read_from_hardware() #self.x_position.hardware_set_func = lambda x: self.lockinstage.setx(x) #self.y_position.hardware_set_func = lambda y: self.lockinstage.sety(y) self.x_position.hardware_set_func = lambda x: self.nanodrive.set_pos_ax( x, 2) self.y_position.hardware_set_func = lambda y: self.nanodrive.set_pos_ax( y, 1) # update figure self.ax.set_xlim(0, self.nanodrive.cal_Y) self.ax.set_ylim(0, self.nanodrive.cal_X) #self.ax.set_xlim(0, 75) #self.ax.set_ylim(0, 75) # events self.frame.Bind(wx.EVT_BUTTON, self.on_start_scan, self.frame.m_button_start) self.frame.Bind(wx.EVT_BUTTON, self.on_stop_scan, self.frame.m_button_stop) self.timer = wx.Timer(id=2001) self.timer.Bind(wx.EVT_TIMER, self.on_timer) self.timer.Start(2000) self.fast_timer = wx.Timer(id=2002) self.fast_timer.Bind(wx.EVT_TIMER, self.on_fast_timer) self.frame.m_checkBox_picoharp_fastreadout.Bind( wx.EVT_CHECKBOX, self.on_fast_timer_checkbox) self.update_display() self.frame.Show() return True
class ScanningTRPLHistMapApp(wx.App): def OnInit(self): print "OnInit" self.HARDWARE_DEBUG = HARDWARE_DEBUG self.STORED_HISTCHAN = 5000 self.frame = ScanningTRPLControlFrame(None) # Logged Quantities self.x_position = LoggedQuantity( name='x_position', dtype=np.float, display_textctrl=self.frame.m_textCtrl_current_x, input_textctrl=self.frame.m_textCtrl_set_current_x) self.y_position = LoggedQuantity( name='x_position', dtype=np.float, display_textctrl=self.frame.m_textCtrl_current_y, input_textctrl=self.frame.m_textCtrl_set_current_y) # Figure self.wxfig = MPLFigureWithToolbarWX(self.frame.m_panel_plot) self.fig = self.wxfig.fig self.ax = self.fig.add_subplot(111) # Optimization Fig self.fig2 = pl.figure(2) self.ax2 = self.fig2.add_subplot(111) self.c0_hist_line, = self.ax2.plot(np.zeros(HIST_LEN, dtype=float)) self.c1_hist_line, = self.ax2.plot(np.zeros(HIST_LEN, dtype=float)) self.hist_vline = self.ax2.axvline(0) self.c0_hist = np.zeros(HIST_LEN, dtype=float) self.c1_hist = np.zeros(HIST_LEN, dtype=float) self.fig2.show() self.hist_i = 0 # hardware self.scanning = False self.nanodrive = MCLNanoDrive(debug=self.HARDWARE_DEBUG) try: self.frame.m_staticText_maxdim.SetLabel( "max: %g x %g um" % (self.nanodrive.cal_Y, self.nanodrive.cal_X)) except Exception as e: print e self.frame.m_staticText_maxdim.SetLabel("max: ? x ? um") #self.frame.m_staticText_maxdim.SetLabel("max: 75 x 75 um") #self.srslockin = SRSlockin(port="COM5", gpibaddr=8) #self.lockinstage = LockinStage(srs=self.srslockin, # POSMIN=0, POSMAX=75, channels={'x':1, 'y':2, 'z':3}) self.picoharp = PicoHarp300(devnum=0, debug=self.HARDWARE_DEBUG) self.read_from_hardware() #self.x_position.hardware_set_func = lambda x: self.lockinstage.setx(x) #self.y_position.hardware_set_func = lambda y: self.lockinstage.sety(y) self.x_position.hardware_set_func = lambda x: self.nanodrive.set_pos_ax( x, 2) self.y_position.hardware_set_func = lambda y: self.nanodrive.set_pos_ax( y, 1) # update figure self.ax.set_xlim(0, self.nanodrive.cal_Y) self.ax.set_ylim(0, self.nanodrive.cal_X) #self.ax.set_xlim(0, 75) #self.ax.set_ylim(0, 75) # events self.frame.Bind(wx.EVT_BUTTON, self.on_start_scan, self.frame.m_button_start) self.frame.Bind(wx.EVT_BUTTON, self.on_stop_scan, self.frame.m_button_stop) self.timer = wx.Timer(id=2001) self.timer.Bind(wx.EVT_TIMER, self.on_timer) self.timer.Start(2000) self.fast_timer = wx.Timer(id=2002) self.fast_timer.Bind(wx.EVT_TIMER, self.on_fast_timer) self.frame.m_checkBox_picoharp_fastreadout.Bind( wx.EVT_CHECKBOX, self.on_fast_timer_checkbox) self.update_display() self.frame.Show() return True def on_timer(self, e): self.read_from_hardware() self.update_display() def on_fast_timer(self, e): self.picoharp.read_count_rates() self.frame.m_textCtrl_count0.SetValue(str(self.picoharp.Countrate0)) self.frame.m_textCtrl_count1.SetValue(str(self.picoharp.Countrate1)) self.c0_hist[self.hist_i] = self.picoharp.Countrate0 self.c1_hist[self.hist_i] = self.picoharp.Countrate1 #self.c0_hist_line.set_ydata(self.c0_hist) self.c1_hist_line.set_ydata(self.c1_hist) self.hist_vline.set_xdata([self.hist_i] * 2) self.hist_i += 1 self.hist_i %= HIST_LEN if (self.hist_i % 10) == 0: self.ax2.relim() self.ax2.autoscale_view(scalex=False, scaley=True) #self.ax2.autoscale() self.fig2.canvas.draw() def on_fast_timer_checkbox(self, e): fast_timer_enable = self.frame.m_checkBox_picoharp_fastreadout.GetValue( ) if fast_timer_enable: self.fast_timer.Start(100) else: self.fast_timer.Stop() def on_start_scan(self, e): print "start scan" self.scanning = True # get scan parameters: self.x0 = float(self.frame.m_textCtrl_x0.GetValue()) self.x1 = float(self.frame.m_textCtrl_x1.GetValue()) self.y0 = float(self.frame.m_textCtrl_y0.GetValue()) self.y1 = float(self.frame.m_textCtrl_y1.GetValue()) self.dx = float(self.frame.m_textCtrl_dx.GetValue()) / 1000. self.dy = float(self.frame.m_textCtrl_dy.GetValue()) / 1000. self.x_array = np.arange(self.x0, self.x1, self.dx, dtype=float) self.y_array = np.arange(self.y0, self.y1, self.dy, dtype=float) self.Nx = len(self.x_array) self.Ny = len(self.y_array) print "Nx, Ny", self.Nx, self.Ny self.tacq = int(float(self.frame.m_textCtrl_tacq.GetValue()) * 1000) self.phrange = int(self.frame.m_textCtrl_phrange.GetValue()) self.phoffset = int(self.frame.m_textCtrl_phoffset.GetValue()) self.syncdiv = int( self.frame.m_choice_syncdivider.GetString( self.frame.m_choice_syncdivider.GetSelection())) self.zerocross0 = int(self.frame.m_spinCtrl_zerocross0.GetValue()) self.zerocross1 = int(self.frame.m_spinCtrl_zerocross0.GetValue()) self.level0 = int(self.frame.m_textCtrl_level0.GetValue()) self.level1 = int(self.frame.m_textCtrl_level1.GetValue()) # create data arrays #self.integrated_count_map_c0 = np.zeros((self.Nx, self.Ny), dtype=int) self.integrated_count_map_c1 = np.zeros((self.Ny, self.Nx), dtype=int) self.time_trace_map = np.zeros( (self.Ny, self.Nx, self.STORED_HISTCHAN), dtype=int) print "shape:", self.integrated_count_map_c1.shape, self.time_trace_map.shape #update figure self.aximg = self.ax.imshow( self.integrated_count_map_c1, origin='lower', vmin=1e4, vmax=1e5, interpolation='nearest', extent=[self.x0, self.x1, self.y0, self.y1]) self.wxfig.redraw() # set up experiment self.picoharp.setup_experiment(Range=self.phrange, Offset=self.phoffset, Tacq=self.tacq, SyncDivider=self.syncdiv, CFDZeroCross0=self.zerocross0, CFDLevel0=self.level0, CFDZeroCross1=self.zerocross1, CFDLevel1=self.level1) line_time0 = time.time() for jj in range(self.Ny): #self.nanodrive.SetY(self.y_array[j]) if not self.scanning: break y = self.y_array[jj] #self.lockinstage.sety(y) #self.read_from_hardware() self.nanodrive.set_pos_ax(y, 1) self.read_from_hardware() y = self.ypos print "line time:", time.time() - line_time0 print "pixel time:", float(time.time() - line_time0) / len( self.x_array) line_time0 = time.time() """xdelta = self.x_array[0] - self.xpos if abs(xdelta) > 2.0: if xdelta > 0: step = +1.0 elif xdelta < 0: step = -1.0 for x in np.arange(self.xpos, self.x_array[0], step): self.nanodrive.set_pos_ax(x, 2) wx_yielded_sleep(0.1) """ if jj % 2: #odd lines x_line_indicies = range(self.Nx) else: #even lines -- traverse in opposite direction x_line_indicies = range(self.Nx)[::-1] for ii in x_line_indicies: if not self.scanning: break x = self.xpos = self.x_array[ii] #print ii,x wx.Yield() #self.nanodrive.SetX(self.x_array[i]) #self.nanodrive.set_pos(x, y) #print "nanodrive set_pos: ", x, y #self.lockinstage.setx(x) self.nanodrive.set_pos_ax(x, 2) #if self.HARDWARE_DEBUG: print "lockin stage moved to ", x, y ph = self.picoharp ph.start_histogram(Tacq=self.tacq) while not ph.check_done_scanning(): wx.Yield() ph.stop_histogram() hist_data = ph.read_histogram_data() self.time_trace_map[jj, ii, :] = hist_data[0:self.STORED_HISTCHAN] self.integrated_count_map_c1[jj, ii] = sum(hist_data) #x1, y1 = self.nanodrive.get_pos() #print "get pos: ", x1,y1 # update display try: self.update_display() except Exception, err: print "Failed to update_display", err if not (ii % 5): #self.update_figure() try: #print "updating figure" #self.read_from_hardware() self.aximg.set_data(self.integrated_count_map_c1) try: count_min = np.min( self.integrated_count_map_c1[np.nonzero( self.integrated_count_map_c1)]) except Exception as err: count_min = 0 count_max = np.max(self.integrated_count_map_c1) self.aximg.set_clim(count_min, count_max + 1) self.wxfig.redraw() except Exception, err: print "Failed to update figure:", err
class MCLStage3DApp(wx.App): def OnInit(self): self.HARDWARE_DEBUG = HARDWARE_DEBUG self.frame = MCLStage3DFrame(None) self.nanodrive = MCLNanoDrive(debug=self.HARDWARE_DEBUG) try: self.frame.m_staticText_maxdim.SetLabel( "[ %g x %g x %g ]" % (self.nanodrive.cal_X, self.nanodrive.cal_Y, self.nanodrive.cal_Z)) except Exception as e: print e self.frame.m_staticText_maxdim.SetLabel("[ ? ? ? ]") x, y, z = self.nanodrive.get_pos() self.frame.m_scrollBar_x.SetScrollbar(100 * x / self.nanodrive.cal_X, 1, 100, 1, refresh=True) self.frame.m_scrollBar_y.SetScrollbar(100 * y / self.nanodrive.cal_Y, 1, 100, 1, refresh=True) self.frame.m_scrollBar_z.SetScrollbar(100 * z / self.nanodrive.cal_Z, 1, 100, 1, refresh=True) self.frame.m_textCtrl_x.SetValue("%02.3f" % x) self.frame.m_textCtrl_y.SetValue("%02.3f" % y) self.frame.m_textCtrl_z.SetValue("%02.3f" % z) self.frame.m_scrollBar_x.Bind(wx.EVT_SCROLL, self.on_scroll) self.frame.m_scrollBar_y.Bind(wx.EVT_SCROLL, self.on_scroll) self.frame.m_scrollBar_z.Bind(wx.EVT_SCROLL, self.on_scroll) # Figure self.wxfig = MPLFigureWithToolbarWX(self.frame.m_panel_plot) self.fig = self.wxfig.fig self.ax = self.fig.add_subplot(111) self.ax.set_xlim(0, self.nanodrive.cal_X) self.ax.set_ylim(self.nanodrive.cal_Y, 0) self.xypos_line, = self.ax.plot([x], [y], 'ro') self.frame.Show() return True def on_scroll(self, evt): self.frame.m_scrollBar_x.Refresh() self.frame.m_scrollBar_y.Refresh() self.frame.m_scrollBar_z.Refresh() new_x = self.frame.m_scrollBar_x.GetThumbPosition( ) * 0.01 * self.nanodrive.cal_X new_y = self.frame.m_scrollBar_y.GetThumbPosition( ) * 0.01 * self.nanodrive.cal_Y new_z = self.frame.m_scrollBar_z.GetThumbPosition( ) * 0.01 * self.nanodrive.cal_Z self.nanodrive.set_pos(new_x, new_y, new_z) x, y, z = self.nanodrive.get_pos() #self.frame.m_scrollBar_x.SetScrollbar(100*x/self.nanodrive.cal_X, 1, 100, 1, refresh=True) #self.frame.m_scrollBar_y.SetScrollbar(100*y/self.nanodrive.cal_Y, 1, 100, 1, refresh=True) #self.frame.m_scrollBar_z.SetScrollbar(100*z/self.nanodrive.cal_Z, 1, 100, 1, refresh=True) self.frame.m_textCtrl_x.SetValue("%02.3f" % x) self.frame.m_textCtrl_y.SetValue("%02.3f" % y) self.frame.m_textCtrl_z.SetValue("%02.3f" % z) self.xypos_line.set_xdata([x]) self.xypos_line.set_ydata([y]) self.wxfig.redraw()
def OnInit(self): print "OnInit" self.HARDWARE_DEBUG = HARDWARE_DEBUG self.frame = ScanningSpectrumControlFrame(None) # Logged Quantities self.x_position = LoggedQuantity( name='x_position', dtype=np.float, display_textctrl=self.frame.m_textCtrl_current_x, input_textctrl=self.frame.m_textCtrl_set_current_x) self.y_position = LoggedQuantity( name='y_position', dtype=np.float, display_textctrl=self.frame.m_textCtrl_current_y, input_textctrl=self.frame.m_textCtrl_set_current_y) # Figure ############################################################### self.wxfig = MPLFigureWithToolbarWX(self.frame.m_panel_plot) self.fig = self.wxfig.fig self.ax = self.fig.add_subplot(111) # Spectrum Fig self.fig2 = pl.figure(2) self.ax_speclive = self.fig2.add_subplot(111) #self.c0_hist_line, = self.ax2.plot(np.zeros(HIST_LEN,dtype=float)) #self.c1_hist_line, = self.ax2.plot(np.zeros(HIST_LEN,dtype=float)) #self.hist_vline = self.ax2.axvline(0) #self.c0_hist = np.zeros(HIST_LEN,dtype=float) #self.c1_hist = np.zeros(HIST_LEN,dtype=float) self.fig2.show() #self.history_i = 0 self.spec_plotline, = self.ax_speclive.plot(range(0, 512), range(0, 512)) ##################### hardware ######################################### self.scanning = False ######## MCL NanoDrive Stage ########################################### self.nanodrive = MCLNanoDrive(debug=self.HARDWARE_DEBUG) try: self.frame.m_staticText_maxdim.SetLabel( "max: %g x %g um" % (self.nanodrive.cal[XAXIS_ID], self.nanodrive.cal[YAXIS_ID])) except Exception as e: print e self.frame.m_staticText_maxdim.SetLabel("max: ? x ? um") self.read_from_hardware() self.x_position.hardware_set_func = lambda x: self.nanodrive.set_pos_ax( x, XAXIS_ID) self.y_position.hardware_set_func = lambda y: self.nanodrive.set_pos_ax( y, YAXIS_ID) #Spectrometer ########################################################## self.spec = ActonSpectrometer(port=SPEC_COMM_PORT, debug=self.HARDWARE_DEBUG, dummy=False) print self.spec.read_grating_info() self.frame.m_choice_spec_grating.Clear() for gnum, gname in self.spec.gratings: self.frame.m_choice_spec_grating.Append("%i %s" % (gnum, gname)) print self.spec.gratings_dict self.spec.read_grating() self.frame.m_choice_spec_grating.SetSelection(self.spec.grating - 1) self.spec.read_wl() self.frame.m_textCtrl_current_spec_wl.SetValue("%f" % self.spec.wl) self.frame.m_textCtrl_set_spec_wl.Bind(wx.EVT_TEXT_ENTER, self.on_change_spec_wl) self.frame.m_choice_spec_grating.Bind(wx.EVT_CHOICE, self.on_change_spec_grating) #self.frame.m_button_spec_stop.Bind(wx.EVT_BUTTON, self.on_spec_stop_motion) ######################################################################## #Andor CCD############################################################## self.ccd = AndorCCD(debug=self.HARDWARE_DEBUG) print "Andor CCD" print "%g x %g" % (self.ccd.Nx, self.ccd.Ny) self.spectrum_length = self.ccd.Nx self.ccd.set_ro_image_mode() self.ccd.set_trigger_mode('internal') self.ccd.set_image_flip(ANDOR_HFLIP, ANDOR_VFLIP) print "flip", self.ccd.get_image_flip() self.ccd.set_ad_channel(ANDOR_AD_CHAN) self.ccd.set_exposure_time(1.0) self.ccd.set_EMCCD_gain(1) self.ccd.set_cooler_on() self.ccd.get_temperature() self.ccd.set_shutter_open() self.spec_fig = pl.figure(3) self.specimg_ax = self.spec_fig.add_subplot(111) self.spec_ax = self.spec_fig.add_subplot(611) self.spec_ax.set_xlim(0, 512) self.spec_fig.show() self.ccd_img = self.specimg_ax.imshow(np.zeros( (self.ccd.Nx, self.ccd.Ny), dtype=np.int32), origin='lower', interpolation='nearest') self.specimg_ax.axhline(ROW0, color='w') self.specimg_ax.axhline(ROW1, color='w') self.specimg_ax.axvline(256, color='w') self.spec_line, = self.spec_ax.plot( np.zeros(self.ccd.Nx, dtype=np.int32), 'k-') self.spec_line2, = self.spec_ax.plot( np.zeros(self.ccd.Nx, dtype=np.int32), 'g-') self.video_mode = False self.frame.m_button_video_mode_start.Bind(wx.EVT_BUTTON, self.on_start_video_mode) self.frame.m_button_video_mode_stop.Bind(wx.EVT_BUTTON, self.on_stop_video_mode) self.frame.m_textCtrl_andor_exposure.SetValue( str(ANDOR_DEFAULT_EXPOSURE)) self.frame.m_textCtrl_andor_em.SetValue(str(ANDOR_DEFAULT_EMGAIN)) # A/D rate choice_adc = self.frame.m_choice_andor_adc choice_adc.Clear() for speed in self.ccd.HSSpeeds[ANDOR_AD_CHAN]: choice_adc.Append("%g MHz" % (speed)) choice_adc.SetSelection(0) self.ccd.set_hs_speed(0) choice_adc.Bind(wx.EVT_CHOICE, self.on_change_andor_adc) ######################################################################## # update figure self.ax.set_xlim(0, self.nanodrive.cal[XAXIS_ID]) self.ax.set_ylim(0, self.nanodrive.cal[YAXIS_ID]) # events self.frame.Bind(wx.EVT_BUTTON, self.on_start_scan, self.frame.m_button_start) self.frame.Bind(wx.EVT_BUTTON, self.on_stop_scan, self.frame.m_button_stop) self.timer = wx.Timer(id=2001) self.timer.Bind(wx.EVT_TIMER, self.on_timer) self.timer.Start(2000) #self.fast_timer = wx.Timer(id=2002) #self.fast_timer.Bind(wx.EVT_TIMER, self.on_fast_timer) #self.frame.m_checkBox_picoharp_fastreadout.Bind( # wx.EVT_CHECKBOX, self.on_fast_timer_checkbox) self.update_display() self.frame.Show() return True
class ScanningTRPLHistMapApp(wx.App): def OnInit(self): print "OnInit" self.HARDWARE_DEBUG = HARDWARE_DEBUG self.frame = ScanningSpectrumControlFrame(None) # Logged Quantities self.x_position = LoggedQuantity( name='x_position', dtype=np.float, display_textctrl=self.frame.m_textCtrl_current_x, input_textctrl=self.frame.m_textCtrl_set_current_x) self.y_position = LoggedQuantity( name='y_position', dtype=np.float, display_textctrl=self.frame.m_textCtrl_current_y, input_textctrl=self.frame.m_textCtrl_set_current_y) # Figure ############################################################### self.wxfig = MPLFigureWithToolbarWX(self.frame.m_panel_plot) self.fig = self.wxfig.fig self.ax = self.fig.add_subplot(111) # Spectrum Fig self.fig2 = pl.figure(2) self.ax_speclive = self.fig2.add_subplot(111) #self.c0_hist_line, = self.ax2.plot(np.zeros(HIST_LEN,dtype=float)) #self.c1_hist_line, = self.ax2.plot(np.zeros(HIST_LEN,dtype=float)) #self.hist_vline = self.ax2.axvline(0) #self.c0_hist = np.zeros(HIST_LEN,dtype=float) #self.c1_hist = np.zeros(HIST_LEN,dtype=float) self.fig2.show() #self.history_i = 0 self.spec_plotline, = self.ax_speclive.plot(range(0, 512), range(0, 512)) ##################### hardware ######################################### self.scanning = False ######## MCL NanoDrive Stage ########################################### self.nanodrive = MCLNanoDrive(debug=self.HARDWARE_DEBUG) try: self.frame.m_staticText_maxdim.SetLabel( "max: %g x %g um" % (self.nanodrive.cal[XAXIS_ID], self.nanodrive.cal[YAXIS_ID])) except Exception as e: print e self.frame.m_staticText_maxdim.SetLabel("max: ? x ? um") self.read_from_hardware() self.x_position.hardware_set_func = lambda x: self.nanodrive.set_pos_ax( x, XAXIS_ID) self.y_position.hardware_set_func = lambda y: self.nanodrive.set_pos_ax( y, YAXIS_ID) #Spectrometer ########################################################## self.spec = ActonSpectrometer(port=SPEC_COMM_PORT, debug=self.HARDWARE_DEBUG, dummy=False) print self.spec.read_grating_info() self.frame.m_choice_spec_grating.Clear() for gnum, gname in self.spec.gratings: self.frame.m_choice_spec_grating.Append("%i %s" % (gnum, gname)) print self.spec.gratings_dict self.spec.read_grating() self.frame.m_choice_spec_grating.SetSelection(self.spec.grating - 1) self.spec.read_wl() self.frame.m_textCtrl_current_spec_wl.SetValue("%f" % self.spec.wl) self.frame.m_textCtrl_set_spec_wl.Bind(wx.EVT_TEXT_ENTER, self.on_change_spec_wl) self.frame.m_choice_spec_grating.Bind(wx.EVT_CHOICE, self.on_change_spec_grating) #self.frame.m_button_spec_stop.Bind(wx.EVT_BUTTON, self.on_spec_stop_motion) ######################################################################## #Andor CCD############################################################## self.ccd = AndorCCD(debug=self.HARDWARE_DEBUG) print "Andor CCD" print "%g x %g" % (self.ccd.Nx, self.ccd.Ny) self.spectrum_length = self.ccd.Nx self.ccd.set_ro_image_mode() self.ccd.set_trigger_mode('internal') self.ccd.set_image_flip(ANDOR_HFLIP, ANDOR_VFLIP) print "flip", self.ccd.get_image_flip() self.ccd.set_ad_channel(ANDOR_AD_CHAN) self.ccd.set_exposure_time(1.0) self.ccd.set_EMCCD_gain(1) self.ccd.set_cooler_on() self.ccd.get_temperature() self.ccd.set_shutter_open() self.spec_fig = pl.figure(3) self.specimg_ax = self.spec_fig.add_subplot(111) self.spec_ax = self.spec_fig.add_subplot(611) self.spec_ax.set_xlim(0, 512) self.spec_fig.show() self.ccd_img = self.specimg_ax.imshow(np.zeros( (self.ccd.Nx, self.ccd.Ny), dtype=np.int32), origin='lower', interpolation='nearest') self.specimg_ax.axhline(ROW0, color='w') self.specimg_ax.axhline(ROW1, color='w') self.specimg_ax.axvline(256, color='w') self.spec_line, = self.spec_ax.plot( np.zeros(self.ccd.Nx, dtype=np.int32), 'k-') self.spec_line2, = self.spec_ax.plot( np.zeros(self.ccd.Nx, dtype=np.int32), 'g-') self.video_mode = False self.frame.m_button_video_mode_start.Bind(wx.EVT_BUTTON, self.on_start_video_mode) self.frame.m_button_video_mode_stop.Bind(wx.EVT_BUTTON, self.on_stop_video_mode) self.frame.m_textCtrl_andor_exposure.SetValue( str(ANDOR_DEFAULT_EXPOSURE)) self.frame.m_textCtrl_andor_em.SetValue(str(ANDOR_DEFAULT_EMGAIN)) # A/D rate choice_adc = self.frame.m_choice_andor_adc choice_adc.Clear() for speed in self.ccd.HSSpeeds[ANDOR_AD_CHAN]: choice_adc.Append("%g MHz" % (speed)) choice_adc.SetSelection(0) self.ccd.set_hs_speed(0) choice_adc.Bind(wx.EVT_CHOICE, self.on_change_andor_adc) ######################################################################## # update figure self.ax.set_xlim(0, self.nanodrive.cal[XAXIS_ID]) self.ax.set_ylim(0, self.nanodrive.cal[YAXIS_ID]) # events self.frame.Bind(wx.EVT_BUTTON, self.on_start_scan, self.frame.m_button_start) self.frame.Bind(wx.EVT_BUTTON, self.on_stop_scan, self.frame.m_button_stop) self.timer = wx.Timer(id=2001) self.timer.Bind(wx.EVT_TIMER, self.on_timer) self.timer.Start(2000) #self.fast_timer = wx.Timer(id=2002) #self.fast_timer.Bind(wx.EVT_TIMER, self.on_fast_timer) #self.frame.m_checkBox_picoharp_fastreadout.Bind( # wx.EVT_CHECKBOX, self.on_fast_timer_checkbox) self.update_display() self.frame.Show() return True def on_timer(self, e): self.read_from_hardware() self.update_display() # def on_fast_timer(self,e): # self.picoharp.read_count_rates() # self.frame.m_textCtrl_count0.SetValue(str(self.picoharp.Countrate0)) # self.frame.m_textCtrl_count1.SetValue(str(self.picoharp.Countrate1)) # self.c0_hist[self.hist_i] = self.picoharp.Countrate0 # self.c1_hist[self.hist_i] = self.picoharp.Countrate1 # # #self.c0_hist_line.set_ydata(self.c0_hist) # self.c1_hist_line.set_ydata(self.c1_hist) # self.hist_vline.set_xdata([self.hist_i]*2) # # self.history_i += 1 # self.history_i %= HISTORY_LEN # # if (self.hist_i % 10) == 0: # self.ax2.relim() # self.ax2.autoscale_view(scalex=False, scaley=True) # #self.ax2.autoscale() # # self.fig2.canvas.draw() def on_fast_timer_checkbox(self, e): fast_timer_enable = self.frame.m_checkBox_picoharp_fastreadout.GetValue( ) if fast_timer_enable: self.fast_timer.Start(100) else: self.fast_timer.Stop() def on_start_scan(self, e): print "start scan" self.scanning = True # get scan parameters: self.x0 = float(self.frame.m_textCtrl_x0.GetValue()) self.x1 = float(self.frame.m_textCtrl_x1.GetValue()) self.y0 = float(self.frame.m_textCtrl_y0.GetValue()) self.y1 = float(self.frame.m_textCtrl_y1.GetValue()) self.dx = float(self.frame.m_textCtrl_dx.GetValue()) / 1000. self.dy = float(self.frame.m_textCtrl_dy.GetValue()) / 1000. self.x_array = np.arange(self.x0, self.x1, self.dx, dtype=float) self.y_array = np.arange(self.y0, self.y1, self.dy, dtype=float) self.Nx = len(self.x_array) self.Ny = len(self.y_array) print "Nx, Ny", self.Nx, self.Ny self.andor_exposure = float( self.frame.m_textCtrl_andor_exposure.GetValue()) self.andor_em_gain = int(self.frame.m_textCtrl_andor_em.GetValue()) ### create data arrays self.integrated_count_map = np.zeros((self.Ny, self.Nx), dtype=int) self.spectrum_map = np.zeros((self.Ny, self.Nx, self.spectrum_length), dtype=int) print "shape:", self.integrated_count_map.shape, self.spectrum_map.shape ### update figure self.aximg = self.ax.imshow( self.integrated_count_map, origin='lower', vmin=1e4, vmax=1e5, interpolation='nearest', extent=[self.x0, self.x1, self.y0, self.y1]) self.wxfig.redraw() # set up experiment self.ccd.set_exposure_time(self.andor_exposure) self.ccd.set_EMCCD_gain(self.andor_em_gain) # Scan! line_time0 = time.time() for jj in range(self.Ny): if not self.scanning: break y = self.y_array[jj] self.nanodrive.set_pos_ax(y, YAXIS_ID) self.read_from_hardware() y = self.ypos print "line time:", time.time() - line_time0 print "pixel time:", float(time.time() - line_time0) / len( self.x_array) line_time0 = time.time() if jj % 2: #odd lines x_line_indicies = range(self.Nx) else: #even lines -- traverse in opposite direction x_line_indicies = range(self.Nx)[::-1] for ii in x_line_indicies: if not self.scanning: break x = self.xpos = self.x_array[ii] wx.Yield() self.nanodrive.set_pos_ax(x, XAXIS_ID) self.ccd.start_acquisition() stat = "ACQUIRING" while stat != "IDLE": wx_yielded_sleep(self.ccd.exposure_time * 0.25) stati, stat = self.ccd.get_status() self.ccd.get_acquired_data() spectrum = np.sum(self.ccd.buffer[ROW0:ROW1], axis=0) self.spectrum_map[jj, ii, :] = spectrum self.integrated_count_map[jj, ii] = sum(spectrum) # update display try: self.update_display() except Exception, err: print "Failed to update_display", err try: self.spec_plotline.set_ydata(spectrum) self.ax_speclive.relim() self.ax_speclive.autoscale_view(tight=None, scalex=False, scaley=True) self.fig2.canvas.draw() except Exception as err: print "Failed to update spectrum plot", err if not (ii % 5): #self.update_figure() try: #print "updating figure" #self.read_from_hardware() self.aximg.set_data(self.integrated_count_map) try: count_min = np.min( self.integrated_count_map[np.nonzero( self.integrated_count_map)]) except Exception as err: count_min = 0 count_max = np.max(self.integrated_count_map) self.aximg.set_clim(count_min, count_max + 1) self.wxfig.redraw() except Exception, err: print "Failed to update figure:", err
def OnInit(self): print "OnInit" self.HARDWARE_DEBUG = HARDWARE_DEBUG self.frame = SpectrumCameraControlFrame(None) #self.frame.m_panel_scanarea.Disable() # Figure self.wxfig = MPLFigureWithToolbarWX(self.frame.m_panel_plot) self.fig = self.wxfig.fig self.ax = self.fig.add_subplot(111) self.ax2 = self.fig.add_subplot(611) self.ax2.set_xlim(0, 512) #Spectrometer ########################################################## self.spec = ActonSpectrometer(port="COM4", debug=self.HARDWARE_DEBUG) print self.spec.read_grating_info() self.frame.m_choice_spec_grating.Clear() for gnum, gname in self.spec.gratings: self.frame.m_choice_spec_grating.Append("%i %s" % (gnum, gname)) print self.spec.gratings_dict self.spec.read_grating() self.frame.m_choice_spec_grating.SetSelection(self.spec.grating - 1) self.spec.read_wl() self.frame.m_textCtrl_current_spec_wl.SetValue("%f" % self.spec.wl) self.frame.m_textCtrl_set_spec_wl.Bind(wx.EVT_TEXT_ENTER, self.on_change_spec_wl) self.frame.m_choice_spec_grating.Bind(wx.EVT_CHOICE, self.on_change_spec_grating) self.frame.m_button_spec_stop.Bind(wx.EVT_BUTTON, self.on_spec_stop_motion) ######################################################################## #Andor CCD############################################################## self.ccd = AndorCCD(debug=self.HARDWARE_DEBUG) print "Andor CCD" print "%g x %g" % (self.ccd.Nx, self.ccd.Ny) self.ccd.set_ro_image_mode() self.ccd.set_trigger_mode('internal') self.ccd.set_exposure_time(1.0) self.ccd.set_EMCCD_gain(1) self.ccd.set_shutter_open() self.ccd_img = self.ax.imshow(np.zeros((self.ccd.Nx, self.ccd.Ny), dtype=np.int32), origin='lower', interpolation='nearest') self.spec_line, = self.ax2.plot(np.zeros(self.ccd.Nx, dtype=np.int32), 'k-') self.spec_line2, = self.ax2.plot(np.zeros(self.ccd.Nx, dtype=np.int32), 'g-') self.video_mode = False self.frame.m_button_video_mode_start.Bind(wx.EVT_BUTTON, self.on_start_video_mode) self.frame.m_button_video_mode_stop.Bind(wx.EVT_BUTTON, self.on_stop_video_mode) # A/D rate choice_adc = self.frame.m_choice_andor_adc choice_adc.Clear() for speed in self.ccd.HSSpeeds[AD_CHAN]: choice_adc.Append("%g MHz" % (speed)) choice_adc.SetSelection(0) self.ccd.set_hs_speed(0) choice_adc.Bind(wx.EVT_CHOICE, self.on_change_andor_adc) ######################################################################## self.timer = wx.Timer(id=2001) self.timer.Bind(wx.EVT_TIMER, self.on_timer) self.timer.Start(2000) self.fast_timer = wx.Timer(id=2002) self.fast_timer.Bind(wx.EVT_TIMER, self.on_fast_timer) #self.frame.m_checkBox_picoharp_fastreadout.Bind( # wx.EVT_CHECKBOX, self.on_fast_timer_checkbox) #self.update_display() self.frame.Show() return True
class AndorCameraTestApp(wx.App): def OnInit(self): print "OnInit" self.HARDWARE_DEBUG = HARDWARE_DEBUG self.frame = SpectrumCameraControlFrame(None) #self.frame.m_panel_scanarea.Disable() # Figure self.wxfig = MPLFigureWithToolbarWX(self.frame.m_panel_plot) self.fig = self.wxfig.fig self.ax = self.fig.add_subplot(111) self.ax2 = self.fig.add_subplot(611) self.ax2.set_xlim(0, 512) #Spectrometer ########################################################## self.spec = ActonSpectrometer(port="COM4", debug=self.HARDWARE_DEBUG) print self.spec.read_grating_info() self.frame.m_choice_spec_grating.Clear() for gnum, gname in self.spec.gratings: self.frame.m_choice_spec_grating.Append("%i %s" % (gnum, gname)) print self.spec.gratings_dict self.spec.read_grating() self.frame.m_choice_spec_grating.SetSelection(self.spec.grating - 1) self.spec.read_wl() self.frame.m_textCtrl_current_spec_wl.SetValue("%f" % self.spec.wl) self.frame.m_textCtrl_set_spec_wl.Bind(wx.EVT_TEXT_ENTER, self.on_change_spec_wl) self.frame.m_choice_spec_grating.Bind(wx.EVT_CHOICE, self.on_change_spec_grating) self.frame.m_button_spec_stop.Bind(wx.EVT_BUTTON, self.on_spec_stop_motion) ######################################################################## #Andor CCD############################################################## self.ccd = AndorCCD(debug=self.HARDWARE_DEBUG) print "Andor CCD" print "%g x %g" % (self.ccd.Nx, self.ccd.Ny) self.ccd.set_ro_image_mode() self.ccd.set_trigger_mode('internal') self.ccd.set_exposure_time(1.0) self.ccd.set_EMCCD_gain(1) self.ccd.set_shutter_open() self.ccd_img = self.ax.imshow(np.zeros((self.ccd.Nx, self.ccd.Ny), dtype=np.int32), origin='lower', interpolation='nearest') self.spec_line, = self.ax2.plot(np.zeros(self.ccd.Nx, dtype=np.int32), 'k-') self.spec_line2, = self.ax2.plot(np.zeros(self.ccd.Nx, dtype=np.int32), 'g-') self.video_mode = False self.frame.m_button_video_mode_start.Bind(wx.EVT_BUTTON, self.on_start_video_mode) self.frame.m_button_video_mode_stop.Bind(wx.EVT_BUTTON, self.on_stop_video_mode) # A/D rate choice_adc = self.frame.m_choice_andor_adc choice_adc.Clear() for speed in self.ccd.HSSpeeds[AD_CHAN]: choice_adc.Append("%g MHz" % (speed)) choice_adc.SetSelection(0) self.ccd.set_hs_speed(0) choice_adc.Bind(wx.EVT_CHOICE, self.on_change_andor_adc) ######################################################################## self.timer = wx.Timer(id=2001) self.timer.Bind(wx.EVT_TIMER, self.on_timer) self.timer.Start(2000) self.fast_timer = wx.Timer(id=2002) self.fast_timer.Bind(wx.EVT_TIMER, self.on_fast_timer) #self.frame.m_checkBox_picoharp_fastreadout.Bind( # wx.EVT_CHECKBOX, self.on_fast_timer_checkbox) #self.update_display() self.frame.Show() return True def on_timer(self, e): try: temp = self.ccd.get_temperature() self.frame.m_textCtrl_andor_temp.SetValue(str(temp)) except: print "failed to get temperature" #self.read_from_hardware() #self.update_display() def on_fast_timer(self, e): self.picoharp.read_count_rates() self.frame.m_textCtrl_count0.SetValue(str(self.picoharp.Countrate0)) self.frame.m_textCtrl_count1.SetValue(str(self.picoharp.Countrate1)) self.c0_hist[self.hist_i] = self.picoharp.Countrate0 self.c1_hist[self.hist_i] = self.picoharp.Countrate1 #self.c0_hist_line.set_ydata(self.c0_hist) self.c1_hist_line.set_ydata(self.c1_hist) self.hist_vline.set_xdata([self.hist_i] * 2) self.hist_i += 1 self.hist_i %= HIST_LEN if (self.hist_i % 10) == 0: self.ax2.relim() self.ax2.autoscale_view(scalex=False, scaley=True) #self.ax2.autoscale() self.fig2.canvas.draw() def on_fast_timer_checkbox(self, e): fast_timer_enable = self.frame.m_checkBox_picoharp_fastreadout.GetValue( ) if fast_timer_enable: self.fast_timer.Start(100) else: self.fast_timer.Stop() def read_from_hardware(self): self.picoharp.read_count_rates() self.ypos, self.xpos, z = self.nanodrive.get_pos() #self.xpos = self.lockinstage.getx() #self.ypos = self.lockinstage.gety() return self.xpos, self.ypos def update_display(self): #self.x_position.update_value(self.nanodrive.x_pos) #self.y_position.update_value(self.nanodrive.y_pos) self.x_position.update_value(self.xpos) self.y_position.update_value(self.ypos) self.frame.m_textCtrl_count0.SetValue(str(self.picoharp.Countrate0)) self.frame.m_textCtrl_count1.SetValue(str(self.picoharp.Countrate1)) def on_change_spec_wl(self, evt): self.spec_wl = float(self.frame.m_textCtrl_set_spec_wl.GetValue()) self.frame.m_statusBar.SetStatusText( "Setting spectrometer wavelength to %f nm ..." % self.spec_wl) self.spec.write_wl_nonblock(self.spec_wl) wx.Yield() wx.Sleep(1) self.spec_done = False while not self.spec_done: self.spec_done = self.spec.read_done_status() self.spec_wl_current = self.spec.read_wl() self.frame.m_textCtrl_current_spec_wl.SetValue( "%f" % self.spec_wl_current) wx.Yield() wx.Sleep(1) self.frame.m_textCtrl_set_spec_wl.SetValue("") self.frame.m_statusBar.SetStatusText("Done setting Spectrometer") def on_change_spec_grating(self, evt): new_grating_index = self.frame.m_choice_spec_grating.GetSelection() gnum, gname = self.spec.gratings[new_grating_index] if self.HARDWARE_DEBUG: print "Moving spectrometer grating to %i %s (please wait until the move is complete)" % ( gnum, gname) self.spec.write_grating(gnum) def on_spec_stop_motion(self, evt): pass def on_start_video_mode(self, evt): self.andor_exposure = float( self.frame.m_textCtrl_andor_exposure.GetValue()) self.andor_em_gain = int(self.frame.m_textCtrl_andor_em.GetValue()) self.ccd.set_exposure_time(self.andor_exposure) self.ccd.set_EMCCD_gain(self.andor_em_gain) self.frame.m_button_video_mode_start.Disable() self.frame.m_button_video_mode_stop.Enable(1) self.video_mode = True while self.video_mode: self.ccd.start_acquisition() stat = "ACQUIRING" while stat != "IDLE": wx_yielded_sleep(0.1) stati, stat = self.ccd.get_status() self.ccd.get_acquired_data() self.ccd_img.set_data(self.ccd.buffer) count_min = np.min(self.ccd.buffer) count_max = np.max(self.ccd.buffer) self.ccd_img.set_clim(count_min, count_max) self.spectra_data = np.average(self.ccd.buffer, axis=0) self.spectra_data2 = np.average(self.ccd.buffer[200:350], axis=0) self.spec_line.set_ydata(self.spectra_data) self.spec_line2.set_ydata(self.spectra_data2) self.ax2.relim() self.ax2.autoscale_view(scalex=False, scaley=True) self.wxfig.redraw() def on_stop_video_mode(self, evt): self.video_mode = False self.frame.m_button_video_mode_start.Enable(1) self.frame.m_button_video_mode_stop.Disable() # Andor CCD Events def on_change_andor_adc(self, evt): new_hs_speed_i = self.frame.m_choice_andor_adc.GetSelection() self.ccd.set_hs_speed(new_hs_speed_i)
def OnInit(self): print "OnInit" self.HARDWARE_DEBUG = HARDWARE_DEBUG self.frame = ScanningTRPLControlFrame(None) # Logged Quantities self.x_position = LoggedQuantity( name='x_position', dtype=np.float, display_textctrl=self.frame.m_textCtrl_current_x, input_textctrl=self.frame.m_textCtrl_set_current_x) self.y_position = LoggedQuantity( name='x_position', dtype=np.float, display_textctrl=self.frame.m_textCtrl_current_y, input_textctrl=self.frame.m_textCtrl_set_current_y) # Figure self.wxfig = MPLFigureWithToolbarWX(self.frame.m_panel_plot) self.fig = self.wxfig.fig self.ax = self.fig.add_subplot(111) # hardware self.scanning = False """ #self.nanodrive = MCLNanoDrive(debug=self.HARDWARE_DEBUG) try: self.frame.m_staticText_maxdim.SetLabel("max: %g x %g um" % (self.nanodrive.cal_X, self.nanodrive.cal_Y) ) except Exception as e: print e self.frame.m_staticText_maxdim.SetLabel("max: ? x ? um") """ self.frame.m_staticText_maxdim.SetLabel("max: 75 x 75 um") self.srslockin = SRSlockin(port="COM5", gpibaddr=8) self.lockinstage = LockinStage(srs=self.srslockin, POSMIN=0, POSMAX=75, channels={ 'x': 1, 'y': 2, 'z': 3 }) self.picoharp = PicoHarp300(devnum=0, debug=self.HARDWARE_DEBUG) self.read_from_hardware() self.x_position.hardware_set_func = lambda x: self.lockinstage.setx(x) self.y_position.hardware_set_func = lambda y: self.lockinstage.sety(y) #self.x_position.hardware_set_func = lambda x: self.nanodrive.set_pos_ax(x, 1) #self.y_position.hardware_set_func = lambda y: self.nanodrive.set_pos_ax(y, 2) # update figure #self.ax.set_xlim(0, self.nanodrive.cal_X) #self.ax.set_ylim(0, self.nanodrive.cal_Y) self.ax.set_xlim(0, 75) self.ax.set_ylim(0, 75) # events self.frame.Bind(wx.EVT_BUTTON, self.on_start_scan, self.frame.m_button_start) self.frame.Bind(wx.EVT_BUTTON, self.on_stop_scan, self.frame.m_button_stop) self.timer = wx.Timer() self.timer.Bind(wx.EVT_TIMER, self.on_timer) self.timer.Start(2000) self.update_display() self.frame.Show() return True
class ScanningTRPLConfocalApp(wx.App): def OnInit(self): print "OnInit" self.HARDWARE_DEBUG = HARDWARE_DEBUG self.frame = ScanningTRPLControlFrame(None) # Logged Quantities self.x_position = LoggedQuantity( name='x_position', dtype=np.float, display_textctrl=self.frame.m_textCtrl_current_x, input_textctrl=self.frame.m_textCtrl_set_current_x) self.y_position = LoggedQuantity( name='x_position', dtype=np.float, display_textctrl=self.frame.m_textCtrl_current_y, input_textctrl=self.frame.m_textCtrl_set_current_y) # Figure self.wxfig = MPLFigureWithToolbarWX(self.frame.m_panel_plot) self.fig = self.wxfig.fig self.ax = self.fig.add_subplot(111) # hardware self.scanning = False """ #self.nanodrive = MCLNanoDrive(debug=self.HARDWARE_DEBUG) try: self.frame.m_staticText_maxdim.SetLabel("max: %g x %g um" % (self.nanodrive.cal_X, self.nanodrive.cal_Y) ) except Exception as e: print e self.frame.m_staticText_maxdim.SetLabel("max: ? x ? um") """ self.frame.m_staticText_maxdim.SetLabel("max: 75 x 75 um") self.srslockin = SRSlockin(port="COM5", gpibaddr=8) self.lockinstage = LockinStage(srs=self.srslockin, POSMIN=0, POSMAX=75, channels={ 'x': 1, 'y': 2, 'z': 3 }) self.picoharp = PicoHarp300(devnum=0, debug=self.HARDWARE_DEBUG) self.read_from_hardware() self.x_position.hardware_set_func = lambda x: self.lockinstage.setx(x) self.y_position.hardware_set_func = lambda y: self.lockinstage.sety(y) #self.x_position.hardware_set_func = lambda x: self.nanodrive.set_pos_ax(x, 1) #self.y_position.hardware_set_func = lambda y: self.nanodrive.set_pos_ax(y, 2) # update figure #self.ax.set_xlim(0, self.nanodrive.cal_X) #self.ax.set_ylim(0, self.nanodrive.cal_Y) self.ax.set_xlim(0, 75) self.ax.set_ylim(0, 75) # events self.frame.Bind(wx.EVT_BUTTON, self.on_start_scan, self.frame.m_button_start) self.frame.Bind(wx.EVT_BUTTON, self.on_stop_scan, self.frame.m_button_stop) self.timer = wx.Timer() self.timer.Bind(wx.EVT_TIMER, self.on_timer) self.timer.Start(2000) self.update_display() self.frame.Show() return True def on_timer(self, e): self.read_from_hardware() self.update_display() def on_start_scan(self, e): print "start scan" self.scanning = True # get scan parameters: self.x0 = float(self.frame.m_textCtrl_x0.GetValue()) self.x1 = float(self.frame.m_textCtrl_x1.GetValue()) self.y0 = float(self.frame.m_textCtrl_y0.GetValue()) self.y1 = float(self.frame.m_textCtrl_y1.GetValue()) self.dx = float(self.frame.m_textCtrl_dx.GetValue()) / 1000. self.dy = float(self.frame.m_textCtrl_dy.GetValue()) / 1000. self.x_array = np.arange(self.x0, self.x1, self.dx, dtype=float) self.y_array = np.arange(self.y0, self.y1, self.dy, dtype=float) self.Nx = len(self.x_array) self.Ny = len(self.y_array) self.waittime = float(self.frame.m_textCtrl_waittime.GetValue()) self.average_n = int(self.frame.m_textCtrl_average_n.GetValue()) # create data arrays self.integrated_count_map_c0 = np.zeros((self.Nx, self.Ny), dtype=int) self.integrated_count_map_c1 = np.zeros((self.Nx, self.Ny), dtype=int) #self.time_trace_map = np.zeros( (self.Nx, self.Ny, self.picoharp.HISTCHAN),dtype=int) #update figure self.aximg = self.ax.imshow( self.integrated_count_map_c1, origin='lower', vmin=5e4, vmax=2e5, interpolation='nearest', extent=[self.x0, self.x1, self.y0, self.y1]) self.wxfig.redraw() for j in range(self.Ny): #self.nanodrive.SetY(self.y_array[j]) if not self.scanning: continue y = self.y_array[j] self.lockinstage.sety(y) self.read_from_hardware() y = self.ypos for i in range(self.Nx): if not self.scanning: continue x = self.xpos = self.x_array[i] wx.Yield() #self.nanodrive.SetX(self.x_array[i]) #self.nanodrive.set_pos(x, y) #print "nanodrive set_pos: ", x, y self.lockinstage.setx(x) #if self.HARDWARE_DEBUG: print "lockin stage moved to ", x, y #ph.setup_experiment()#Range, Offset, Tacq, SyncDivider, CFDZeroCross0, CFDLevel0, CFDZeroCross1, CFDLevel1) #ph.start_histogram(Tacq=2300) c0avg = 0 c1avg = 0 for n in range(self.average_n): if self.waittime > 0.1: wx_yielded_sleep(self.waittime) else: time.sleep(self.waittime) c0, c1 = self.picoharp.read_count_rates() c0avg += c0 c1avg += c1 c0avg /= self.average_n c1avg /= self.average_n #print c0avg, c1avg self.integrated_count_map_c0[j, i] = c0avg self.integrated_count_map_c1[j, i] = c1avg #x1, y1 = self.nanodrive.get_pos() #print "get pos: ", x1,y1 # update display self.update_display() if not (i % 10): #self.update_figure() print "updating figure" self.read_from_hardware() self.aximg.set_data(self.integrated_count_map_c1) self.wxfig.redraw() # clean up after scan self.aximg.set_data(self.integrated_count_map_c1) self.wxfig.redraw() self.update_display() self.scanning = False print "scanning done" print "saving data" t0 = time.time() np.savetxt("%i_confocal_scan.csv" % t0, self.integrated_count_map_c1, delimiter=',') def read_from_hardware(self): self.picoharp.read_count_rates() self.xpos = self.lockinstage.getx() self.ypos = self.lockinstage.gety() return self.xpos, self.ypos def on_stop_scan(self, e): self.scanning = False #self.nanodrive.get_pos() self.update_display() def update_display(self): #self.x_position.update_value(self.nanodrive.x_pos) #self.y_position.update_value(self.nanodrive.y_pos) self.x_position.update_value(self.xpos) self.y_position.update_value(self.ypos) self.frame.m_textCtrl_count0.SetValue(str(self.picoharp.Countrate0)) self.frame.m_textCtrl_count1.SetValue(str(self.picoharp.Countrate1))