def task22(method = 'point_feature_matching'): video_path = 'travi.mp4' vCapture = cv2.VideoCapture(video_path) n_frames = int(vCapture.get(cv2.CAP_PROP_FRAME_COUNT)) w = int(vCapture.get(cv2.CAP_PROP_FRAME_WIDTH)) h = int(vCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)) if method == 'point_feature_matching': start_time = time.time() rad = 50 # define radius # Step 1 # Define the codec for output video fourcc = cv2.VideoWriter_fourcc(*'MJPG') # Set up output video fps = 30 outVideo = cv2.VideoWriter('video_out.mp4', fourcc, fps, (w, h)) #Step 2 _,prev= vCapture.read() prev_gray = cv2.cvtColor(prev,cv2.COLOR_BGR2GRAY) # Step 3 transformations = np.zeros(((n_frames-1),3)) for i in trange(n_frames-2): dx,dy,a,current_gray = opticalFlow.extractRotation_translation(prev_gray,vCapture) transformations[i] = [dx,dy,a] # Update frame prev_gray = current_gray # Calc smooth motion btw frames motion = np.cumsum(transformations,axis=0) smooth_motion = utils.smooth(motion,rad) diff = smooth_motion - motion transformations_smooth = transformations + diff # Apply smoothed camera motion to frames vCapture.set(cv2.CAP_PROP_POS_FRAMES, 0) for i in range(n_frames-2): available,f = vCapture.read() if not available: break stabilised_f,frame_out = opticalFlow.stabilise_frame(transformations_smooth, i, f, w, h) if True: if (frame_out.shape[1] >= 1920): frame_out = cv2.resize(frame_out, (frame_out.shape[1] / 2, frame_out.shape[0] / 2)) cv2.imshow('BEFORE & AFTER',frame_out) cv2.waitKey(10) outVideo.write(stabilised_f) end_time = time.time() print('Duration:',end_time-start_time) elif method == 'mesh': start_time = time.time() x_motion_meshes, y_motion_meshes, x_paths, y_paths = Stabilization.read_video(vCapture) sx_paths, sy_paths = Stabilization.stabilize(x_paths, y_paths) x_motion_meshes, y_motion_meshes, new_x_motion_meshes, new_y_motion_meshes = Stabilization.get_frame_warp(x_motion_meshes,y_motion_meshes,x_paths, y_paths,sx_paths, sy_paths) Stabilization.generate_stabilized_video(vCapture, x_motion_meshes, y_motion_meshes, new_x_motion_meshes, new_y_motion_meshes) end_time = time.time() print('Duration:',end_time-start_time)
def Scan674(filename,dirname,StartF,EndF,ScanPoints,ScanRepeat,us_RedTime,SCloops,BlueLockOn): # Import functions: reload(Stabilization) reload(CavityStabilization) plot = gui_exports['plot'] purgatory = gui_exports['purgatory'] OpenDDS = f_set['DDS_SETPROG'] RunDDS = f_set['DDS_RUNPROG'] ReadUnshelved = f_read['DDS_NBRIGHT'] ReadAvgBright = f_read['DDS_LASTAVG'] SetParameter = f_set['DDS_PARAM'] ReadParameter = f_read['DDS_PARAM'] ScanDone = f_set['AudioAlert_scandone'] Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME+'/scripts/StabilizationConstants') CavStab = CavityStabilization.CavityStabilization(f_set, f_read, gui_exports) const = CavStab.LoadConstants(DAQ_HOME+'/scripts/CavityStabilizationConstants') print "Checking power levels of 422 and 1092 MonoLaser." CavStab.MonoLaserLockCheck('421') CavStab.MonoLaserLockCheck('1091') CavStab.MonoLaserLockCheck('674') #### Locking ####### if BlueLockOn==1: bluelockrv, BlueCav = Stab.BlueLock() # Set up plotting: try: purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.TWODPLOT) purgatory(plot.set_labels, 'DDS0 FREQ [MHz]', 'Shelving rate','<empty>') except Exception,e: print time.strftime('%H:%M:%S'),__file__,'Exception occured in purgatory when setting up plot' print e
def __init__(self,filename,dirname,Freq422,IntTime,Threshold): reload(Stabilization) try: self.plot=gui_exports['plot'] self.purgatory=gui_exports['purgatory'] self.MMAmp=f_read['IonPhotonCounter_MMAMP'] self.Counts=f_read['IonPhotonCounter_COUNT'] self.TopmidRead=f_read['3631A_topmid_+6V'] self.CompRead=f_read['3631A_comp_+6V'] self.TopmidSet=f_set['3631A_topmid_+6V'] self.Unshut=f_set['PIShutter_unshut'] self.Shut=f_set['PIShutter_shut'] self.ScanDone = f_set['AudioAlert_scandone'] self.CompSet=f_set['3631A_comp_+6V'] # self.RFSet=f_set['AGfungen1_Freq'] self.Magic=f_set['IonPhotonCounter_MAGIC'] self.InttimeSet=f_set['IonPhotonCounter_INTTIME'] self.InttimeRead=f_read['IonPhotonCounter_INTTIME'] self.SetParameter=f_set['DDS_PARAM'] self.SetDDS_FREQ1=f_set['DDS_FREQ1'] self.SetDDS_AMP1=f_set['DDS_AMP1'] self.Say = f_set['AudioAlert_say'] self.SetDDS_FREQ0=f_set['DDS_FREQ0'] self.SetDDS_AMP0=f_set['DDS_AMP0'] self.SetDDS_FREQ2=f_set['DDS_FREQ2'] self.ReadParameter=f_read['DDS_PARAM'] self.OvenVoltage=f_read['PSUP_3633A_V'] self.OvenI=f_set['PSUP_3633A_I'] self.F422=f_read['WS7_F3'] self.F461=f_read['WS7_F1'] self.F674=f_read['WS7_F5'] # saving initial values in case something goes wrong: # self.Topmid_i=self.TopmidRead() # self.Comp_i=self.CompRead() self.inttime_i=self.InttimeRead() self.inttime=int(IntTime) self.InttimeSet(self.inttime) # self.Magic(1) # self.RF_i=14.32e6 # self.RF_high=14.32e6 # self.RF_low=14.26e6 self.MMAmp_i=self.MMAmp() # Set DDS freq/amp for 422! self.OvenThreshold=1#0.437 self.Threshold=Threshold self.Freq422=Freq422 self.Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) self.const = self.Stab.LoadConstants(DAQ_HOME+'/scripts/StabilizationConstants') self.CavStab = CavityStabilization.CavityStabilization(f_set, f_read, gui_exports) self.const = self.CavStab.LoadConstants(DAQ_HOME+'/scripts/CavityStabilizationConstants') except Exception as e: print "Exception occured while instantiating AutoloadIonClass:",e raise e # Setting up database: self.mydb = data.database(filename, dirname, 1, 2, 'Oven Voltage,Counts' )
def __init__(self,filename,dirname,Freq422,IntTime,Threshold,OvenTime,WaitTime,OvenCurrent): reload(Stabilization) try: self.plot=gui_exports['plot'] self.purgatory=gui_exports['purgatory'] self.MMAmp=f_read['IonPhotonCounter_MMAMP'] self.Counts=f_read['IonPhotonCounter_COUNT'] self.TopmidRead=f_read['3631A_topmid_+6V'] self.CompRead=f_read['3631A_comp_+6V'] self.TopmidSet=f_set['3631A_topmid_+6V'] self.Unshut=f_set['PIShutter_unshut'] self.Shut=f_set['PIShutter_shut'] self.ScanDone = f_set['AudioAlert_scandone'] self.CompSet=f_set['3631A_comp_+6V'] self.Magic=f_set['IonPhotonCounter_MAGIC'] self.InttimeSet=f_set['IonPhotonCounter_INTTIME'] self.InttimeRead=f_read['IonPhotonCounter_INTTIME'] self.SetParameter=f_set['DDS_PARAM'] self.SetDDS_FREQ1=f_set['DDS_FREQ1'] self.SetDDS_AMP1=f_set['DDS_AMP1'] self.Say = f_set['AudioAlert_say'] self.SetDDS_FREQ0=f_set['DDS_FREQ0'] self.SetDDS_AMP0=f_set['DDS_AMP0'] self.SetDDS_FREQ2=f_set['DDS_FREQ2'] self.ReadParameter=f_read['DDS_PARAM'] self.OvenVoltage=f_read['PSUP_3633A_V'] self.OvenI=f_set['PSUP_3633A_I'] self.F422=f_read['WS7_F3'] self.F461=f_read['WS7_F1'] self.F674=f_read['WS7_F5'] self.inttime_i=self.InttimeRead() self.OvenTime=OvenTime self.inttime=int(IntTime) self.InttimeSet(self.inttime) self.MMAmp_i=self.MMAmp() self.OvenThreshold=0.460 self.Threshold=Threshold self.OvenCurrent=OvenCurrent self.Freq422=Freq422 self.WaitTime=WaitTime self.Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) self.const = self.Stab.LoadConstants(DAQ_HOME+'/scripts/StabilizationConstants') self.CavStab = CavityStabilization.CavityStabilization(f_set, f_read, gui_exports) self.const = self.CavStab.LoadConstants(DAQ_HOME+'/scripts/CavityStabilizationConstants') except Exception as e: print "Exception occured while instantiating AutoloadIonClass:",e raise e
def Scan422(filename, dirname, StartCav, EndCav, FinishCav, ScanPoints, ScanRepeat, DDSFREQ, DDSAMP): # Import functions: reload(Stabilization) plot = gui_exports['plot'] purgatory = gui_exports['purgatory'] OpenDDS = f_set['DDS_SETPROG'] RunDDS = f_set['DDS_RUNPROG'] ReadUnshelved = f_read['DDS_NBRIGHT'] ReadAvgBright = f_read['DDS_LASTAVG'] SetBlueCav = f_set['MonoLasers_421'] ReadBlueCav = f_read['MonoLasers_421'] SetDDS_FREQ1 = f_set['DDS_FREQ1'] SetDDS_FREQ2 = f_set['DDS_FREQ2'] SetDDS_AMP1 = f_set['DDS_AMP1'] SetDDS_FREQ0 = f_set['DDS_FREQ0'] SetDDS_AMP0 = f_set['DDS_AMP0'] SetParameter = f_set['DDS_PARAM'] ReadParameter = f_read['DDS_PARAM'] ReadIonPMT = f_read['IonPhotonCounter_COUNT'] Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME + '/scripts/StabilizationConstants') CavStab = CavityStabilization.CavityStabilization(f_set, f_read, gui_exports) const = CavStab.LoadConstants(DAQ_HOME + '/scripts/CavityStabilizationConstants') #### Locking ####### #if BlueLockOn==1: # bluelockrv, BlueCav = Stab.BlueLock() # Set up plotting: try: # purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.TWODPLOT) purgatory(plot.set_labels, 'BlueCav[DAC2]', 'IonPhotonCounter_COUNTS', '<empty>') except Exception, e: print time.strftime( '%H:%M:%S' ), __file__, 'Exception occured in purgatory when setting up plot' print e
def Scan1092(filename,dirname,StartCav,EndCav,FinishCav,ScanPoints,ScanRepeat): # Import functions: reload(Stabilization) plot=gui_exports['plot'] purgatory=gui_exports['purgatory'] OpenDDS = f_set['DDS_SETPROG'] RunDDS = f_set['DDS_RUNPROG'] SetCav1092 = f_set['MonoLasers_1091'] ReadCav1092 = f_read['MonoLasers_1091'] SetParameter = f_set['DDS_PARAM'] ReadParameter = f_read['DDS_PARAM'] ReadIonPMT = f_read['IonPhotonCounter_COUNT'] Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME+'/scripts/StabilizationConstants') # Set up plotting: try: # purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.TWODPLOT) purgatory(plot.set_labels, 'Cav1092[DAC2]', 'IonPhotonCounter_COUNTS','<empty>') except Exception,e: print time.strftime('%H:%M:%S'),__file__,'Exception occured in purgatory when setting up plot' print e
def RunScript(filename, dirname, PARAMETERS, ScanPoints, ScanRepeat, LockOption): reload(Stabilization) reload(CavityStabilization) plot = gui_exports['plot'] purgatory = gui_exports['purgatory'] LockOption = int(LockOption) IonCount = 1 CavLockRead = f_read['DMM_top_V'] CavLockTreshold = 1.0 try: Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME+'/scripts/StabilizationConstants') CavStab = CavityStabilization.CavityStabilization(f_set, f_read, gui_exports) const = CavStab.LoadConstants(DAQ_HOME+'/scripts/CavityStabilizationConstants') plotLabels = ['BlueCav', 'CavOffset', 'RedPiTime', 'RedPiTime'] # Locking step # set up plotting print "Running..." purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.DUALTWODPLOT) ## label the x-axis as appropriate purgatory(plot.set_labels, 'XLABEL', 'Shelving Rate', plotLabels[LockOption & 3]) # Perform the experiment ## define local variables etc as needed ## save and then set some global parameters that aren't changed during scan for i in range(int(ScanRepeat)): if __main__.STOP_FLAG: break print "Scan %d"%(i) time.sleep(1) CavLockOk=0 CavLockPast=1 # print "CavLockRead()" while CavLockOk==0: if CavLockRead() > CavLockTreshold: CavLockOk=1 if CavLockPast==0: print "resuming measurement in 5 sec..." time.sleep(1) print "resuming measurement in 4 sec..." time.sleep(1) print "resuming measurement in 3 sec..." time.sleep(1) print "resuming measurement in 2 sec..." time.sleep(1) print "resuming measurement in 1 sec..." time.sleep(1) print "Cavity relocked" else: print "Cavity lock ok" else: print "Cavity unlocked!" CavLockPast=0 for j in range(int(ScanPoints)*3): if __main__.STOP_FLAG: break # Science step ## more local var defs, iterators etc ## open the desired pulse sequence, e.g. Shelving.pp ## set some parameters ## identify the x-variable to plot ## anything else: fitting, etc ## restore global parameters and any other changed parameters to reasonable values except Exception,e: print "Exception occurred in RunScript:", e traceback.print_exc()
def RunScript(filename, dirname, LoadIon, DoScan422, DoOptimize1092, DoMicroMotionMinimization, DoScan674, DoScan1092, DoRabiShort, DoSidebandScan, DoRabiLong, DoCavityResonanceScan, DoCavityStandingWaveScan, DoCavitySidebandScan, DoCavityCoolingDataRun, BlueLockOn, BlueLockLoop, CavLockCheckOn, ProbeLockOn, DoFitAll, DoBlogAll): timestart = time.time() plot = gui_exports['plot'] purgatory = gui_exports['purgatory'] dirname_Lazy = dirname + '/' + filename print "Welcome to the Lazy Physicist! Your one stop shop for all things automatic." print "Saving in:", dirname_Lazy # Putting everything in a separate folder: if (os.access(dirname, os.F_OK) == 0): os.mkdir(dirname) if (os.access(dirname_Lazy, os.F_OK) == 0): os.mkdir(dirname_Lazy) ScanDone = f_set['AudioAlert_scandone'] Say = f_set['AudioAlert_say'] SetBlueCav = f_set['MonoLasers_421'] ReadBlueCav = f_read['MonoLasers_421'] Set1092Cav = f_set['MonoLasers_1091'] Read1092Cav = f_read['MonoLasers_1091'] SetDDS_FREQ1 = f_set['DDS_FREQ1'] SetDDS_AMP1 = f_set['DDS_AMP1'] SetParameter = f_set['DDS_PARAM'] ReadParameter = f_read['DDS_PARAM'] reload(CavityStabilization) reload(Stabilization) Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) CavStab = CavityStabilization.CavityStabilization(f_set, f_read, gui_exports) const = CavStab.LoadConstants(DAQ_HOME + '/scripts/CavityStabilizationConstants') success = 1 ################## List of tasks: ################### # LoadIon: if LoadIon == 1 and __main__.STOP_FLAG == False: AutoloadIon_filename = 'AutoloadIon' + time.strftime('-%H%M') __main__.app.wTree.plotframe.set_label(AutoloadIon_filename) Freq422 = 710.96304 IntTime_Autoload = 1000 Threshold_Autoload = 1500 OvenTime = 120 WaitTime = 15 OvenCurrent = 2.8 LoadingTime = 10 NumberOfLoads = 10 DoScan422 = 1 deltatime, NumberOfIons = AutoloadIon2( AutoloadIon_filename, dirname_Lazy, Freq422, IntTime_Autoload, Threshold_Autoload, OvenTime, WaitTime, OvenCurrent, LoadingTime, NumberOfLoads, DoScan422) if NumberOfIons == 0: __main__.STOP_FLAG = True # DoScan422: if DoScan422 == 1 and __main__.STOP_FLAG == False: timestamp = time.strftime('%H%M') Scan422_filename = 'Scan422-' + timestamp __main__.app.wTree.plotframe.set_label(Scan422_filename) SetDDS_FREQ1(ReadParameter('F_BlueHi')) SetDDS_AMP1(ReadParameter('A_BlueHi')) Stab.BlueLockFreq() plot.clear() BlueCav = ReadBlueCav() ScanPoints = 80 ScanRepeat = 1 DDSFREQ = [ReadParameter('F_BlueHi'), ReadParameter('F_BlueOn')] DDSAMP = [ReadParameter('A_BlueHi'), ReadParameter('A_BlueOn')] daccalibration = 149 # MHz/V delta = 20. / daccalibration # approximate calibration of 20 MHz. (to do both 251 and 231 scans) Width = 0.70 # To get rigth width of scan offset = -0.10 #0.08 # To get right start of scan for i in range(len(DDSFREQ)): if __main__.STOP_FLAG: break StartCav = BlueCav + offset + i * delta EndCav = BlueCav + offset - Width + i * delta FinishCav = BlueCav + offset + i * delta Scan422(Scan422_filename, dirname_Lazy, StartCav, EndCav, FinishCav, ScanPoints, ScanRepeat, DDSFREQ[i], DDSAMP[i]) time.sleep(1) try: reload(hansfit) fit = hansfit.fitScan422s(dirname_Lazy, timestamp) except Exception, e: print "Exception occured while doing hansfit.fitScan422s:", e traceback.print_exc(file=sys.stdout) print "Continuing anyways"
def __init__(self, filename, dirname, Freq422, IntTime, Threshold, OvenTime, WaitTime, OvenCurrent, LoadingTime, NumberOfLoads, DoScan422): reload(Stabilization) try: self.plot = gui_exports['plot'] self.purgatory = gui_exports['purgatory'] self.dirname = dirname self.MMAmp = f_read['IonPhotonCounter_MMAMP'] self.Counts = f_read['IonPhotonCounter_COUNT'] self.TopmidRead = f_read['3631A_topmid_+6V'] self.CompRead = f_read['3631A_comp_+6V'] self.TopmidSet = f_set['3631A_topmid_+6V'] self.Unshut = f_set['PIShutter_unshut'] self.Shut = f_set['PIShutter_shut'] self.ScanDone = f_set['AudioAlert_scandone'] self.CompSet = f_set['3631A_comp_+6V'] self.Magic = f_set['IonPhotonCounter_MAGIC'] self.InttimeSet = f_set['IonPhotonCounter_INTTIME'] self.InttimeRead = f_read['IonPhotonCounter_INTTIME'] self.SetParameter = f_set['DDS_PARAM'] self.SetDDS_FREQ1 = f_set['DDS_FREQ1'] self.SetDDS_AMP1 = f_set['DDS_AMP1'] self.Say = f_set['AudioAlert_say'] self.SetDDS_FREQ0 = f_set['DDS_FREQ0'] self.SetDDS_AMP0 = f_set['DDS_AMP0'] self.SetDDS_FREQ2 = f_set['DDS_FREQ2'] self.ReadParameter = f_read['DDS_PARAM'] self.OvenVoltage = f_read['PSUP_3633A_V'] self.OvenI = f_set['PSUP_3633A_I'] self.F422 = f_read['WS7_F3'] self.F461 = f_read['WS7_F1'] self.F674 = f_read['WS7_F5'] self.ReadBlueCav = f_read['MonoLasers_421'] self.DoScan422 = DoScan422 self.inttime_i = self.InttimeRead() self.OvenTime = OvenTime self.LoadingTime = LoadingTime self.inttime = int(IntTime) self.InttimeSet(self.inttime) self.MMAmp_i = self.MMAmp() self.OvenThreshold = 0.460 self.RFOutput = f_set['AGfungen1_OutPut'] self.Threshold = Threshold self.OvenCurrent = OvenCurrent self.Freq422 = Freq422 self.WaitTime = WaitTime self.NumberOfLoads = NumberOfLoads self.Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) self.const = self.Stab.LoadConstants( DAQ_HOME + '/scripts/StabilizationConstants') self.CavStab = CavityStabilization.CavityStabilization( f_set, f_read, gui_exports) self.const = self.CavStab.LoadConstants( DAQ_HOME + '/scripts/CavityStabilizationConstants') label = 'OvenCurrent=%f, WaitTime=%f, Threshold=%f, Freq422=%f, IntTime=%.f, NumberOfLoads=%f, LoadingTime=%f, OvenTime=%f' % ( OvenCurrent, WaitTime, Threshold, Freq422, IntTime, NumberOfLoads, LoadingTime, OvenTime) label = label + '\n#LoadingTime,Probability of ion loading, Oven voltage Start, Oven voltage End' self.mydb = data.database(filename, dirname, 1, 2, label) self.purgatory(self.plot.clear) self.purgatory(self.plot.set_mode, pyextfigure.TWODPLOT) self.purgatory(self.plot.set_labels, 'Exp no', 'Ion loaded?', '<empty>') except Exception as e: print "Exception occured while instantiating AutoloadIonClass:", e raise e
def RunScript(filename, dirname, SecFRQ, StartT, EndT, ScanPoints, ScanRepeat, LockOption, CavLockCheck): reload(Stabilization) plot = gui_exports['plot'] purgatory = gui_exports['purgatory'] OpenDDS = f_set['DDS_SETPROG'] RunDDS = f_set['DDS_RUNPROG'] ReadUnshelved = f_read['DDS_NBRIGHT'] ReadAvgBright = f_read['DDS_LASTAVG'] SetParameter = f_set['DDS_PARAM'] ReadParameter = f_read['DDS_PARAM'] LockOption = int(LockOption) ScanDone = f_set['AudioAlert_scandone'] IonCount = 1 try: saved_StarkSec = ReadParameter('F_StarkSec1') # FIXME: I don't need this? #SetParameter('F_StarkSec1', SecFRQ) Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME + '/scripts/StabilizationConstants') plotLabels = ['BlueCav', 'CavOffset', 'RedPiTime', 'RedPiTime'] # Locking step bluerv, BlueCav = Stab.BlueLock() ramseylockrv, CavOffset = Stab.RamseyLock(LockOption, True) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, True) CavStab = CavityStabilization.CavityStabilization( f_set, f_read, gui_exports) const = CavStab.LoadConstants(DAQ_HOME + '/scripts/CavityStabilizationConstants') if CavLockCheck == 1: CavStab.CavLockCheck() # set up plotting print "Running..." purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.DUALTWODPLOT) purgatory(plot.set_labels, 'Delay Time', 'Red Shelving', 'Blue Shelving') mydb = data.database( filename, dirname, 1, 9, 'Heating rate scan at sec freq %g\n#DelayTime, RedShelv, BlueShelv, Scatter, RamseyShelv, RabiShelv, BlueCav, CavOffset, RedPiTime' % (SecFRQ * 2)) # Perform the experiment timestep = (1.0 * EndT - StartT) / (ScanPoints - 1) for i in range(int(ScanRepeat)): if __main__.STOP_FLAG: break print "Scan %d" % (i) j = 0 while j <= int(ScanPoints): #for j in range(int(ScanPoints)): if __main__.STOP_FLAG: break ramseylockrv, CavOffset = Stab.RamseyLock(LockOption, False) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, False) # Science step OpenDDS('prog/Shelving.pp') timeval = StartT + j * timestep SetParameter('ms_ReadoutDly', timeval) SetParameter('F_RedOn', CavOffset - SecFRQ) RunDDS() bsrv = ReadUnshelved(hist=True) SetParameter('F_RedOn', CavOffset + SecFRQ) RunDDS() rsrv = ReadUnshelved(hist=True) if ((IonCount == 1) and (bsrv[2] + rsrv[2] > 20)): IonCount = 2 if (IonCount == 2): bsrv = bsrv[1] rsrv = rsrv[1] else: bsrv = bsrv[0] rsrv = rsrv[0] bluerv, BlueCav = Stab.BlueLockNoDDSRun() SaveDataPoint = False if CavLockCheck == 1: if CavStab.CavLockCheck(): SaveDataPoint = True else: SaveDataPoint = False else: SaveDataPoint = True if SaveDataPoint: mydb.add_data_point([ timeval, rsrv, bsrv, bluerv, ramseylockrv, rabilockrv, BlueCav, CavOffset, RedPiTime ], int(i * ScanPoints + j)) purgatory(plot.add_point, timeval, rsrv, bsrv) purgatory(plot.repaint) j = j + 1 try: expdata, mask = mydb.get_all_data_with_mask() fitdataX = expdata[0:int((i + 1) * int(ScanPoints)), 0] fitdataR = expdata[0:int((i + 1) * int(ScanPoints)), 1] fitdataB = expdata[0:int((i + 1) * int(ScanPoints)), 2] # Becomes infinite sometimes! ie. when data is bad. fitdataY = fitdataR / (fitdataB - fitdataR) fitdata = numarray.transpose( numarray.array([fitdataX, fitdataY])) fit = linear_fit(fitdata) if sp.isnan(fit).any(): print "Fit returned:", fit print "Printing raw data:" print fitdata print "Fit after %d runs: n(t) = %g t + %g" % ( i + 1, fit[1] * 1000 * (2 * SecFRQ)**2, fit[0]) except Exception, e: print "Exception in Heating.py while fitting:", e SetParameter('ms_ReadoutDly', 0) SetParameter('F_StarkSec1', saved_StarkSec) return mydb ScanDone()
def __init__( self, filename, dirname, Freq422, Threshold, OvenTime, WaitTime, OvenCurrent, LoadingTime, NumberOfLoads, ): reload(Stabilization) try: self.plot = gui_exports['plot'] self.purgatory = gui_exports['purgatory'] self.Counts = f_read['XEM6001_PhotonCounter_counts'] self.TopmidRead = f_read['3631A_topmid_+6V'] self.CompRead = f_read['3631A_comp_+6V'] self.TopmidSet = f_set['3631A_topmid_+6V'] self.Unshut422 = lambda: f_set['PIShutter-RedCryo_422_set_open'](1) self.Shut422 = lambda: f_set['PIShutter-RedCryo_422_set_open'](0) self.Unshut405 = lambda: f_set['PIShutter-RedCryo_405_set_open'](1) self.Shut405 = lambda: f_set['PIShutter-RedCryo_405_set_open'](0) self.Unshut461 = lambda: f_set['PIShutter-RedCryo_461_set_open'](1) self.Shut461 = lambda: f_set['PIShutter-RedCryo_461_set_open'](0) # self.Say = f_set['AudioAlert_say'] # self.ScanDone = f_set['AudioAlert_scandone'] self.CompSet = f_set['3631A_comp_+6V'] self.SetParameter = f_set['DDS_PARAM'] self.SetDDS_FREQ1 = f_set['DDS_FREQ1'] self.SetDDS_AMP1 = f_set['DDS_AMP1'] self.SetDDS_FREQ0 = f_set['DDS_FREQ0'] self.SetDDS_AMP0 = f_set['DDS_AMP0'] self.SetDDS_FREQ2 = f_set['DDS_FREQ2'] self.ReadParameter = f_read['DDS_PARAM'] self.OvenVoltage = f_read['PSUP_3633A_V'] self.OvenI = f_set['PSUP_3633A_I'] self.F422 = f_read['WS7_F3'] self.F461 = f_read['WS7_F1'] self.F674 = f_read['WS7_F5'] self.OvenTime = OvenTime self.LoadingTime = LoadingTime self.OvenThreshold = 0.460 self.RFFreq = f_set['AG33250ws2_Freq'] self.RFAmp = f_set['AG33250ws2_Vamp'] self.Threshold = Threshold self.OvenCurrent = OvenCurrent self.Freq422 = Freq422 self.WaitTime = WaitTime self.NumberOfLoads = NumberOfLoads self.Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) self.const = self.Stab.LoadConstants( DAQ_HOME + '/scripts/StabilizationConstants') self.CavStab = \ CavityStabilization.CavityStabilization(f_set, f_read, gui_exports) self.const = self.CavStab.LoadConstants( DAQ_HOME + '/scripts/CavityStabilizationConstants') label = \ 'OvenCurrent=%f, WaitTime=%f, Threshold=%f, Freq422=%f, NumberOfLoads=%f, LoadingTime=%f, OvenTime=%f'\ % ( OvenCurrent, WaitTime, Threshold, Freq422, NumberOfLoads, LoadingTime, OvenTime, ) label = label\ + '\n#LoadingTime,Probability of ion loading, Oven voltage Start, Oven voltage End' self.mydb = data.database(filename, dirname, 1, 2, label) self.purgatory(self.plot.clear) self.purgatory(self.plot.set_mode, pyextfigure.TWODPLOT) self.purgatory(self.plot.set_labels, 'Exp no', 'Ion loaded?', '<empty>') except Exception, e: print 'Exception occured while instantiating AutoloadIonClass:', \ e raise e
def CavityCoolRabi_0deg_IONPOS(filename, dirname, StartT, EndT, CavityOnDF, ReadoutDF, ScanPoints, ScanRepeat, LockOption, CavLockOn, ProbeLockOn, ProbeSet, ProbeSet_SB, IonLockOn, IonSet, IonPosition): # IonSet = 0 locks to the cavity standing wave antinode # IonSet = 1 locks halfway between the node and the antinode # IonSet = 2 locks to the node reload(Stabilization) reload(CavityStabilization) plot = gui_exports['plot'] purgatory = gui_exports['purgatory'] OpenDDS = f_set['DDS_SETPROG'] RunDDS = f_set['DDS_RUNPROG'] ReadUnshelved = f_read['DDS_NBRIGHT'] ReadAvgBright = f_read['DDS_LASTAVG'] SetParameter = f_set['DDS_PARAM'] ReadParameter = f_read['DDS_PARAM'] LockOption = int(LockOption) CavFreqSet = f_set['DDS_FREQ2'] f421quiet = f_set['MonoLasers_Quiet421'] CavBeamSet = f_set['3631A_botleft_+25V'] ProbePowerRead = f_read['3631A_leftmost_+25V'] ProbePowerSet = f_set['3631A_leftmost_+25V'] IonCount = 1 CavLockThreshold = 0.1 IonPosSet = f_set['3631A_topright_-25V'] beam0 = 24. beam90 = 0. maxProbePower = 15. try: time.strftime("%H:%M:%S: Doing CavityCoolRabi_0deg_Doppler scan") saved_redtime = ReadParameter('us_RedTime') ################################################## # Set up locks ################################################## CavFreqSet(0) Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME + '/scripts/StabilizationConstants') bluelockrv, BlueCav = Stab.BlueLock() ramseylockrv, RedCenter = Stab.RamseyLock(LockOption, True) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, True) CavStab = CavityStabilization.CavityStabilization( f_set, f_read, gui_exports) const = CavStab.LoadConstants(DAQ_HOME + '/scripts/CavityStabilizationConstants') cavlockrv, CavCenter = CavStab.CavLock(CavLockOn, True) probelockrv, ProbePower = CavStab.ProbeLock_0deg( ProbeLockOn, ProbeSet, True) ionlockrv, IonPos = CavStab.IonLock_0deg(IonLockOn, IonSet, True) probelockrv, ProbePower = CavStab.ProbeLock_0deg_SB( ProbeLockOn, ProbeSet_SB, True) ################################################## # Set up plotting ################################################## # if IonLockOn > 0: # plotLabel = 'IonPos' # elif CavLockOn > 0: # plotLabel = 'CavCenter' # elif ProbeLockOn > 0: # plotLabel = 'ProbePower' # else: # plotLabel = ['BlueCav', 'RedCenter', 'RedPiTime', 'RedCenter'][LockOption] plotLabel = ['BlueCav', 'RedCenter', 'RedPiTime', 'RedCenter'][LockOption] purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.DUALTWODPLOT) purgatory(plot.set_labels, 'Rabi pulse length [us]', 'Shelving rate', plotLabel) mydb = data.database( filename, dirname, 1, 16, 'Rabi pulse length [us], P[0], P[1], P[2], bluelockrv, BlueCav, ramseylockrv, RedCenter, rabilockrv, RedPiTime, cavlockrv, CavCenter, probelockrv, ProbePower, ionlockrv, IonPos' ) ################################################## # Perform the experiment ################################################## print "Running..." timestep = (1.0 * EndT - StartT) / (ScanPoints - 1) for i in range(int(ScanRepeat)): if __main__.STOP_FLAG: break print "Scan %d" % (i) j = 0 while j <= int(ScanPoints): if __main__.STOP_FLAG: break ################################################## # Lock step ################################################## ramseylockrv, RedCenter = Stab.RamseyLock(LockOption, False) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, False) cavlockrv, CavCenter = CavStab.CavLock(CavLockOn, False) probelockrv, ProbePower = CavStab.ProbeLock_0deg( ProbeLockOn, ProbeSet, False) ionlockrv, IonPos = CavStab.IonLock_0deg( IonLockOn, IonSet, False) # Inserted extra probelock step with SB probeset: probelockrv, ProbePower = CavStab.ProbeLock_0deg_SB( ProbeLockOn, ProbeSet_SB, False) IonPosSet(IonPos + IonPosition) print "IonPosSet(IonPos+IonPosition)=IonPosSet(%f+%f)" % ( IonPos, IonPosition) CavStab.CavLockCheck() ################################################## # Measurement step ################################################## #CavBeamSet(beam90) CavBeamSet(beam0) ProbePowerSet(ProbePower) f421quiet(1) time.sleep(0.2) # time.sleep(2) # Tried this without any remarkable results. timeval = StartT + j * timestep OpenDDS('prog/CavityCoolShelving.pp') SetParameter('F_CavityOn', ReadParameter('F_CavityCenter') + CavityOnDF) SetParameter('F_RedOn', RedCenter + ReadoutDF) SetParameter('us_RedTime', timeval) RunDDS() # This is where the magic happens! isok = 0 while not isok: try: sciencerv = ReadUnshelved(hist=True) if not len(sciencerv) < 2: isok = 1 else: print "[", __file__, time.asctime( ), "] Empty value in sciencerv? = ", sciencerv print "[", __file__, "] Retrying" sys.stdout.flush() time.sleep(0.5) except Exception, inst: print "[", __file__, time.asctime( ), "] Error in ReadUnshelved Exception: ", inst sys.stdout.flush() time.sleep(0.5) if ((IonCount == 1) and (sciencerv[2] > 10)): IonCount = 2 if (IonCount == 2): plotrv = sciencerv[1] else: plotrv = sciencerv[0] f421quiet(0) ################################################## # Lock 422 step ################################################## bluerv, BlueCav = Stab.BlueLockNoDDSRun() #checking if cavity is still locked. If so, plot and save. #Otherwise, repeat point if CavStab.CavLockCheck(): ################################################## # Plot and save step ################################################## mydb.add_data_point([ timeval, sciencerv[0], sciencerv[1], sciencerv[2], bluelockrv, BlueCav, ramseylockrv, RedCenter, rabilockrv, RedPiTime, cavlockrv, CavCenter, probelockrv, ProbePower, ionlockrv, IonPos ], int(i * ScanPoints + j)) purgatory(plot.add_point, timeval, plotrv, eval(plotLabel)) purgatory(plot.repaint) j = j + 1 else: print "Discarding and repeating measurement" SetParameter('us_RedTime', saved_redtime)
def RunScript(filename, dirname, Width, ScanPoints, ScanRepeat, ProbePower, WithSC, LockOption, BlueLockOn, CavLockOn, IonLockOn, IonSet): # IonSet = 0 locks to the cavity standing wave antinode # IonSet = 1 locks halfway between the node and the antinode # IonSet = 2 locks to the node reload(Stabilization) reload(CavityStabilization) reload(ReadDDSmemory) plot = gui_exports['plot'] purgatory = gui_exports['purgatory'] ReadParameter = f_read['DDS_PARAM'] SetParameter = f_set['DDS_PARAM'] CavFreqSet = f_set['DDS_FREQ2'] ReadCavPMT = f_read['CavityPhotonCounter_COUNT'] OpenDDS = f_set['DDS_SETPROG'] RunDDS = f_set['DDS_RUNPROG'] RunDDSandReadTotal = f_read['DDS_RUNNTOTAL'] f421quiet = f_set['MonoLasers_Quiet421'] CavBeamRead = f_read['3631A_botleft_+25V'] CavBeamSet = f_set['3631A_botleft_+25V'] ProbePowerRead = f_read['3631A_leftmost_+25V'] ProbePowerSet = f_set['3631A_leftmost_+25V'] beam0 = 24. beam90 = 0. try: ################################################## # Set up locks ################################################## CavFreqSet(0) CavStab = CavityStabilization.CavityStabilization(f_set, f_read, gui_exports) const = CavStab.LoadConstants(DAQ_HOME+'/scripts/CavityStabilizationConstants') bluelockrv, BlueCav = CavStab.BlueLock(BlueLockOn, True) cavlockrv, CavCenter = CavStab.CavLock(CavLockOn, True) ionlockrv, IonPos = CavStab.IonLock(IonLockOn, IonSet, True) if WithSC: LockOption = int(LockOption) Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME+'/scripts/StabilizationConstants') ramseylockrv, RedCenter = Stab.RamseyLock(LockOption, True) ################################################## # Set up plotting ################################################## purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.DUALTWODPLOT) purgatory(plot.set_labels, 'Frequency offset [MHz]', 'Average cavity transmission [counts/s]', 'Differential cavity transmission [counts/s]') mydb = data.database(filename, dirname, 1, 10, 'Frequency offset [MHz], Cavity transmission due to lock [counts/s], Cavity transmission at IonPos1 [counts/s], Cavity transmission at IonPos2 [counts/s], bluelockrv, BlueCav, cavlockrv, CavCenter, ionlockrv, IonPos') ################################################## # Perform the experiment ################################################## print "Running ..." FreqOffsetVals = (scipy.array(range(int(ScanPoints))) - (ScanPoints - 1.)/2.)/(ScanPoints - 1)*Width k = 0. DiffCavTransMean = 0. for i in range(int(ScanRepeat)): if __main__.STOP_FLAG: break print "Scan %d"%(i) for j in range(len(FreqOffsetVals)): if __main__.STOP_FLAG: break k = k + 1. ################################################## # Lock step ################################################## bluelockrv, BlueCav = CavStab.BlueLock(BlueLockOn, False) cavlockrv, CavCenter = CavStab.CavLock(CavLockOn, False) ionlockrv, IonPos = CavStab.IonLock(IonLockOn, IonSet, False) if WithSC: ramseylockrv, RedCenter = Stab.RamseyLock(LockOption, False) if __main__.STOP_FLAG: break ################################################## # Measurement step ################################################## CavBeamSet(beam0) ProbePowerSet(ProbePower) f421quiet(1) time.sleep(0.2) FreqOffset = FreqOffsetVals[j] SetParameter('F_CavityOn', ReadParameter('F_CavityCenter') + FreqOffset) if WithSC: OpenDDS('prog/CavityTransmissionScan_withSC.pp') else: OpenDDS('prog/CavityTransmissionScan.pp') RunDDS() DDSmemory = ReadDDSmemory.ReadDDSmemory() CavityTransmission0 = DDSmemory[0] CavityTransmission1 = DDSmemory[1] CavityTransmission2 = DDSmemory[2] CavFreqSet(0) f421quiet(0) time.sleep(0.2) mydb.add_data_point([FreqOffset, CavityTransmission0, CavityTransmission1, CavityTransmission2, bluelockrv, BlueCav, cavlockrv, CavCenter, ionlockrv, IonPos], int(i*len(FreqOffsetVals) + j)) purgatory(plot.add_point, FreqOffset, 0.5*(CavityTransmission1 + CavityTransmission2) - CavityTransmission0, CavityTransmission2 - CavityTransmission1) purgatory(plot.repaint) DiffCavTransMean = DiffCavTransMean*(k - 1.)/k + (CavityTransmission2 - CavityTransmission1)/k print "mean(Differential cavity transmission) = %f counts/s"%(DiffCavTransMean) except Exception,e: print "Exception occurred in RunScript:", e traceback.print_exc()
def Rabi(filename, dirname, StartT, EndT, ReadoutDF, ScanPoints, ScanRepeat, LockOption,SCloops): reload(Stabilization) plot = gui_exports['plot'] ScanDone = f_set['AudioAlert_scandone'] purgatory = gui_exports['purgatory'] OpenDDS = f_set['DDS_SETPROG'] RunDDS = f_set['DDS_RUNPROG'] ReadUnshelved = f_read['DDS_NBRIGHT'] ReadAvgBright = f_read['DDS_LASTAVG'] SetParameter = f_set['DDS_PARAM'] ReadParameter = f_read['DDS_PARAM'] LockOption = int(LockOption) IonCount = 1 try: saved_redtime = ReadParameter('us_RedTime') Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME+'/scripts/StabilizationConstants') CavStab = CavityStabilization.CavityStabilization(f_set, f_read, gui_exports) const = CavStab.LoadConstants(DAQ_HOME+'/scripts/CavityStabilizationConstants') plotLabels = ['BlueCav', 'CavOffset', 'RedPiTime', 'CavOffset'] # Locking step bluerv, BlueCav = Stab.BlueLock() ramseylockrv, CavOffset = Stab.RamseyLock(LockOption, True) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, True) # set up plotting print "Running..." purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.DUALTWODPLOT) purgatory(plot.set_labels, 'Pulse Length', 'Shelving Rate', plotLabels[LockOption & 3]) mydb = data.database(filename, dirname, 1, 10, 'RabiLength, P[0], P[1], P[2], Scatter, RamseyShelv, RabiShelv, BlueCav, CavOffset, RedPiTime') # Perform the experiment timestep = (1.0*EndT - StartT)/(ScanPoints - 1) for i in range(int(ScanRepeat)): if __main__.STOP_FLAG: break print "Scan %d"%(i) for j in range(int(ScanPoints)): if __main__.STOP_FLAG: break CavStab.MonoLaserLockCheck('421') CavStab.MonoLaserLockCheck('1091') CavStab.MonoLaserLockCheck('674') CavStab.MonoLaserLockCheck('1033') ramseylockrv, CavOffset = Stab.RamseyLock(LockOption, False) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, False) # Science step timeval = StartT + j * timestep; OpenDDS('prog/Shelving.pp') SetParameter('F_RedOn', CavOffset + ReadoutDF) SetParameter('us_RedTime',timeval) SetParameter('SCloops',SCloops) RunDDS() isok = 0 while not isok: try: sciencerv = ReadUnshelved(hist=True) if not len(sciencerv)<2: isok = 1 else: print "[",__file__,time.asctime(),"] Empty value in sciencerv? = ",sciencerv print "[",__file__,"] Retrying" sys.stdout.flush() time.sleep(0.5) except Exception, inst: print "[",__file__, time.asctime(),"] Error in ReadUnshelved Exception: ", inst sys.stdout.flush() time.sleep(0.5) #sciencerv = ReadUnshelved(hist=True) if ((IonCount == 1) and (sciencerv[2] > 10)): IonCount = 2 if (IonCount == 2): plotrv = sciencerv[1] else: plotrv = sciencerv[0] bluerv, BlueCav = Stab.BlueLockNoDDSRun() mydb.add_data_point([timeval, sciencerv[0], sciencerv[1], sciencerv[2], bluerv, ramseylockrv, rabilockrv, BlueCav, CavOffset, RedPiTime], int(i*ScanPoints + j)) purgatory(plot.add_point, timeval, plotrv, eval(plotLabels[LockOption])) purgatory(plot.repaint) # RUTHS CODE for fitting print 'Fitting...' expdata, mask = mydb.get_all_data_with_mask() timedata = expdata[i*int(ScanPoints):(i+1)*int(ScanPoints), 0] rabidata = expdata[i*int(ScanPoints):(i+1)*int(ScanPoints), 1] fitfunc = lambda p, x: p[0]*scipy.sin(scipy.pi/p[1]*x+p[2])**2 errfunc = lambda p, x, y: fitfunc(p,x) - y # Distance to the target function p0 = [50., EndT - StartT, 0.] # Initial guess for the parameters p1,success = scipy.optimize.leastsq(errfunc, p0, args = (timedata, rabidata)) print 'amp: %g # Pi: %g us'%(p1[0], p1[1]/2) SetParameter('us_RedTime',saved_redtime) ScanDone()
def RunScript(filename, dirname, StartT, EndT, ReadoutDF, RamseyPh, ScanPoints, ScanRepeat, LockOption, OnSideband): reload(Stabilization) plot = gui_exports['plot'] purgatory = gui_exports['purgatory'] OpenDDS = f_set['DDS_SETPROG'] RunDDS = f_set['DDS_RUNPROG'] ReadUnshelved = f_read['DDS_NBRIGHT'] ReadAvgBright = f_read['DDS_LASTAVG'] SetParameter = f_set['DDS_PARAM'] ReadParameter = f_read['DDS_PARAM'] LockOption = int(LockOption) IonCount = 1 try: Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME + '/scripts/StabilizationConstants') plotLabels = ['BlueCav', 'CavOffset', 'RedPiTime', 'CavOffset'] # Locking step bluerv, BlueCav = Stab.BlueLock() ramseylockrv, CavOffset = Stab.RamseyLock(LockOption, True) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, True) # set up plotting print "Running..." purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.DUALTWODPLOT) purgatory(plot.set_labels, 'Pulse Length', 'Shelving Rate', plotLabels[LockOption]) mydb = data.database( filename, dirname, 1, 10, 'RamseyTime, P[0], P[1], P[2], Scatter, RamseyShelv, RabiShelv, BlueCav, CavOffset, RedPiTime' ) # Perform the experiment timestep = (1.0 * EndT - StartT) / (ScanPoints - 1) saved_RamseyDly = ReadParameter('us_RamseyDly') for i in range(int(ScanRepeat)): if __main__.STOP_FLAG: break print "Scan %d" % (i) for j in range(int(ScanPoints)): if __main__.STOP_FLAG: break ramseylockrv, CavOffset = Stab.RamseyLock(LockOption, False) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, False) # Science step timeval = StartT + j * timestep if (OnSideband): OpenDDS('prog/SRamsey.pp') else: OpenDDS('prog/Ramsey.pp') SetParameter('F_RedOn', CavOffset + ReadoutDF) SetParameter('us_RamseyDly', timeval) SetParameter('Ph_Ramsey', RamseyPh) RunDDS() isok = 0 while not isok: try: sciencerv = ReadUnshelved(hist=True) if not len(sciencerv) < 2: isok = 1 else: print "[", __file__, time.asctime( ), "] Empty value in sciencerv? = ", sciencerv print "[", __file__, "] Retrying" sys.stdout.flush() time.sleep(0.5) except Exception, inst: print "[", __file__, time.asctime( ), "] Error in ReadUnshelved Exception: ", inst sys.stdout.flush() time.sleep(0.5) # sciencerv = ReadUnshelved(hist=True) if ((IonCount == 1) and (sciencerv[2] > 10)): IonCount = 2 if (IonCount == 2): plotrv = sciencerv[1] else: plotrv = sciencerv[0] bluerv, BlueCav = Stab.BlueLockNoDDSRun() mydb.add_data_point([ timeval, sciencerv[0], sciencerv[1], sciencerv[2], bluerv, ramseylockrv, rabilockrv, BlueCav, CavOffset, RedPiTime ], int(i * ScanPoints + j)) purgatory(plot.add_point, timeval, plotrv, eval(plotLabels[LockOption])) purgatory(plot.repaint) ## anything else: fitting, etc SetParameter('us_RamseyDly', saved_RamseyDly) SetParameter('Ph_Ramsey', 0.)
def SidebandScan(filename, dirname, StarkSecFRQ1, StarkSecFRQ2, StarkSecFRQ3, Width, ReadoutDLY, ScanPoints, ScanRepeat, LockOption,SCloops): reload(Stabilization) plot = gui_exports['plot'] purgatory = gui_exports['purgatory'] f421quiet = f_set['MonoLasers_Quiet421'] OpenDDS = f_set['DDS_SETPROG'] RunDDS = f_set['DDS_RUNPROG'] ReadUnshelved = f_read['DDS_NBRIGHT'] SetParameter = f_set['DDS_PARAM'] ReadParameter = f_read['DDS_PARAM'] ScanDone = f_set['AudioAlert_scandone'] LockOption = int(LockOption) IonCount = 1 try: Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME+'/scripts/StabilizationConstants') plotLabels = ['BlueCav', 'CavOffset', 'RedPiTime', 'RedPiTime'] CavStab = CavityStabilization.CavityStabilization(f_set, f_read, gui_exports) const = CavStab.LoadConstants(DAQ_HOME+'/scripts/CavityStabilizationConstants') # Locking step bluerv, BlueCav = Stab.BlueLock() ramseylockrv, CavOffset = Stab.RamseyLock(LockOption, True) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, True) # set up plotting print "Running..." purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.DUALTWODPLOT) purgatory(plot.set_labels, 'AOM', 'Shelving Rate', plotLabels[LockOption]) mydb = data.database(filename, dirname, 1, 10, 'AOMFrq, P[0], P[1], P[2], Scatter, RamseyShelv, RabiShelv, BlueCav, CavOffset, RedPiTime') # Perform the experiment df = (scipy.array(range(int(ScanPoints))) - (ScanPoints - 1.)/2.)/(ScanPoints - 1)*Width aomvals = scipy.unique(scipy.concatenate([df - StarkSecFRQ3, df - StarkSecFRQ2, df - StarkSecFRQ1, df, df + StarkSecFRQ1, df + StarkSecFRQ2, df + StarkSecFRQ3])) SetParameter('F_StarkSec1',StarkSecFRQ1) SetParameter('F_StarkSec2',StarkSecFRQ2) SetParameter('F_StarkSec3',StarkSecFRQ3) SetParameter('SCloops',SCloops) SetParameter('ms_ReadoutDly', ReadoutDLY) for i in range(int(ScanRepeat)): if __main__.STOP_FLAG: break print "Scan %d"%(i) for j in range(len(aomvals)): if __main__.STOP_FLAG: break CavStab.MonoLaserLockCheck('421') CavStab.MonoLaserLockCheck('1091') CavStab.MonoLaserLockCheck('674') CavStab.MonoLaserLockCheck('1033') ramseylockrv, CavOffset = Stab.RamseyLock(LockOption, False) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, False) # Measurement step # f421quiet(1) # time.sleep(0.1) aomval = aomvals[j] OpenDDS('prog/Shelving.pp') isok = 0 while not isok: try: SetParameter('F_RedOn', CavOffset + aomval) isok = 1 except Exception, inst: print "[",__file__,"] Error in DDS SetParameter Exception: ", inst sys.stdout.flush() time.sleep(0.5) RunDDS() # The sleep line here is probably to give the laser time to go into quiet mode. # f421quiet(0) # time.sleep(0.1) isok = 0 while not isok: try: sciencerv = ReadUnshelved(hist=True) if not len(sciencerv)<2: isok = 1 else: print "[",__file__,time.asctime(),"] Empty value in sciencerv? = ",sciencerv print "[",__file__,"] Retrying" sys.stdout.flush() time.sleep(0.5) except Exception, inst: print "[",__file__, time.asctime(),"] Error in ReadUnshelved Exception: ", inst sys.stdout.flush() time.sleep(0.5) if ((IonCount == 1) and (sciencerv[2] > 10)): IonCount = 2 if (IonCount == 2): plotrv = sciencerv[1] else: plotrv = sciencerv[0] bluerv, BlueCav = Stab.BlueLockNoDDSRun() mydb.add_data_point([aomval, sciencerv[0], sciencerv[1], sciencerv[2], bluerv, ramseylockrv, rabilockrv, BlueCav, CavOffset, RedPiTime], int(i*len(aomvals) + j)) purgatory(plot.add_point, aomval, plotrv, eval(plotLabels[LockOption]) ) purgatory(plot.repaint)
def CavityCoolRabi3(filename, dirname, StartT, EndT, CavityOnDF, ReadoutDF, ScanPoints, ScanRepeat, LockOption, CavLockOn, ProbeLockOn, ProbeSet, IonLockOn, IonSet): # IonSet = 0 locks to the cavity standing wave antinode # IonSet = 1 locks halfway between the node and the antinode # IonSet = 2 locks to the node reload(Stabilization) reload(CavityStabilization) plot = gui_exports['plot'] purgatory = gui_exports['purgatory'] OpenDDS = f_set['DDS_SETPROG'] RunDDS = f_set['DDS_RUNPROG'] ReadUnshelved = f_read['DDS_NBRIGHT'] ReadAvgBright = f_read['DDS_LASTAVG'] SetParameter = f_set['DDS_PARAM'] ReadParameter = f_read['DDS_PARAM'] LockOption = int(LockOption) CavFreqSet = f_set['DDS_FREQ2'] f421quiet = f_set['MonoLasers_Quiet421'] CavBeamSet = f_set['3631A_botleft_+25V'] ProbePowerRead = f_read['3631A_leftmost_+25V'] ProbePowerSet = f_set['3631A_leftmost_+25V'] IonCount = 1 CavLockRead = f_read['DMM_top_V'] CavLockThreshold = 1.0 beam0 = 24. beam90 = 0. maxProbePower = 15. try: saved_redtime = ReadParameter('us_RedTime') ################################################## # Set up locks ################################################## CavFreqSet(0) Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME + '/scripts/StabilizationConstants') bluelockrv, BlueCav = Stab.BlueLock() ramseylockrv, RedCenter = Stab.RamseyLock(LockOption, True) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, True) CavStab = CavityStabilization.CavityStabilization( f_set, f_read, gui_exports) const = CavStab.LoadConstants(DAQ_HOME + '/scripts/CavityStabilizationConstants') cavlockrv, CavCenter = CavStab.CavLock(CavLockOn, True) probelockrv, ProbePower = CavStab.ProbeLock(ProbeLockOn, ProbeSet, True) ionlockrv, IonPos = CavStab.IonLock(IonLockOn, IonSet, True) ################################################## # Set up plotting ################################################## if IonLockOn > 0: plotLabel = 'IonPos' elif CavLockOn > 0: plotLabel = 'CavCenter' elif ProbeLockOn > 0: plotLabel = 'ProbePower' else: plotLabel = ['BlueCav', 'RedCenter', 'RedPiTime', 'RedCenter'][LockOption] purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.DUALTWODPLOT) purgatory(plot.set_labels, 'Rabi pulse length [us]', 'Shelving rate', plotLabel) mydb = data.database( filename, dirname, 1, 16, 'Rabi pulse length [us], P[0], P[1], P[2], bluelockrv, BlueCav, ramseylockrv, RedCenter, rabilockrv, RedPiTime, cavlockrv, CavCenter, probelockrv, ProbePower, ionlockrv, IonPos' ) ################################################## # Perform the experiment ################################################## print "Running..." timestep = (1.0 * EndT - StartT) / (ScanPoints - 1) for i in range(int(ScanRepeat)): if __main__.STOP_FLAG: break print "Scan %d" % (i) j = 0 while j <= int(ScanPoints): if __main__.STOP_FLAG: break #checking if cavity is locked before measurement: #if locked continue with measurement, if not, wait for it #to be relocked and then wait 5sec before proceeding with measurement CavLockOk = 0 CavLockPast = 1 while CavLockOk == 0: if CavLockRead() > CavLockThreshold: CavLockOk = 1 if CavLockPast == 0: print "resuming measurement in 5 sec..." time.sleep(1) print "resuming measurement in 4 sec..." time.sleep(1) print "resuming measurement in 3 sec..." time.sleep(1) print "resuming measurement in 2 sec..." time.sleep(1) print "resuming measurement in 1 sec..." time.sleep(1) print "Cavity relocked" else: print "Cavity lock ok" else: print "Cavity unlocked!" CavLockPast = 0 ################################################## # Lock step ################################################## ramseylockrv, RedCenter = Stab.RamseyLock(LockOption, False) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, False) cavlockrv, CavCenter = CavStab.CavLock(CavLockOn, False) probelockrv, ProbePower = CavStab.ProbeLock( ProbeLockOn, ProbeSet, False) ionlockrv, IonPos = CavStab.IonLock(IonLockOn, IonSet, False) ################################################## # Measurement step ################################################## CavBeamSet(beam90) ProbePowerSet(ProbePower) f421quiet(1) time.sleep(0.2) timeval = StartT + j * timestep OpenDDS('prog/CavityCoolShelving.pp') SetParameter('F_CavityOn', ReadParameter('F_CavityCenter') + CavityOnDF) SetParameter('F_RedOn', RedCenter + ReadoutDF) SetParameter('us_RedTime', timeval) RunDDS() isok = 0 while not isok: try: sciencerv = ReadUnshelved(hist=True) if not len(sciencerv) < 2: isok = 1 else: print "[", __file__, time.asctime( ), "] Empty value in sciencerv? = ", sciencerv print "[", __file__, "] Retrying" sys.stdout.flush() time.sleep(0.5) except Exception, inst: print "[", __file__, time.asctime( ), "] Error in ReadUnshelved Exception: ", inst sys.stdout.flush() time.sleep(0.5) if ((IonCount == 1) and (sciencerv[2] > 10)): IonCount = 2 if (IonCount == 2): plotrv = sciencerv[1] else: plotrv = sciencerv[0] f421quiet(0) ################################################## # Lock 422 step ################################################## bluerv, BlueCav = Stab.BlueLockNoDDSRun() #checking if cavity is still locked. If so, plot and save. #Otherwise, repeat point if CavLockRead() > CavLockThreshold: ################################################## # Plot and save step ################################################## mydb.add_data_point([ timeval, sciencerv[0], sciencerv[1], sciencerv[2], bluelockrv, BlueCav, ramseylockrv, RedCenter, rabilockrv, RedPiTime, cavlockrv, CavCenter, probelockrv, ProbePower, ionlockrv, IonPos ], int(i * ScanPoints + j)) purgatory(plot.add_point, timeval, plotrv, eval(plotLabel)) purgatory(plot.repaint) j = j + 1 else: print "cavity unlocked - discarding and repeating measurement" SetParameter('us_RedTime', saved_redtime)
def DopplerCoolRabi(filename, dirname, StartT, EndT, ReadoutDF, ScanPoints, ScanRepeat, LockOption, StabCount): reload(CavityStabilization) reload(Stabilization) plot = gui_exports['plot'] purgatory = gui_exports['purgatory'] OpenDDS = f_set['DDS_SETPROG'] RunDDS = f_set['DDS_RUNPROG'] ReadUnshelved = f_read['DDS_NBRIGHT'] ReadAvgBright = f_read['DDS_LASTAVG'] SetParameter = f_set['DDS_PARAM'] ReadParameter = f_read['DDS_PARAM'] LockOption = int(LockOption) # CavFreqSet = f_set['DDS_FREQ2'] f421quiet = f_set['MonoLasers_Quiet421'] IonCount = 1 try: saved_redtime = ReadParameter('us_RedTime') ################################################## # Set up locks ################################################## Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME + '/scripts/StabilizationConstants') bluelockrv, BlueCav = Stab.BlueLockCounts(StabCount) ramseylockrv, RedCenter = Stab.RamseyLock(LockOption, True) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, True) CavStab = CavityStabilization.CavityStabilization( f_set, f_read, gui_exports) const = CavStab.LoadConstants(DAQ_HOME + '/scripts/CavityStabilizationConstants') ################################################## # Set up plotting ################################################## plotLabel = ['BlueCav', 'RedCenter', 'RedPiTime', 'RedCenter'][LockOption] purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.DUALTWODPLOT) purgatory(plot.set_labels, 'Rabi pulse length [us]', 'Shelving rate', plotLabel) mydb = data.database( filename, dirname, 1, 10, 'Rabi pulse length [us], P[0], P[1], P[2], bluelockrv, BlueCav, ramseylockrv, RedCenter, rabilockrv, RedPiTime' ) ################################################## # Perform the experiment ################################################## print "Running DopplerCoolRabi.py..." timestep = (1.0 * EndT - StartT) / (ScanPoints - 1) # Looping over scans i.e. how many times should we measure the same thing. for i in range(int(ScanRepeat)): if __main__.STOP_FLAG: break print "Scan %d" % (i) j = 0 # Looping over pulse lengths: while j <= int(ScanPoints): if __main__.STOP_FLAG: break ################################################## # Lock step ################################################## ramseylockrv, RedCenter = Stab.RamseyLock(LockOption, False) rabilockrv, RedPiTime = Stab.RabiLock(LockOption, False) CavLockCheckOn = 0 if CavLockCheckOn == 1: CavStab.CavLockCheck() ################################################## # Measurement step ################################################## f421quiet(1) time.sleep(0.05) # FIXME: Did this break everything? was 0.2. timeval = StartT + j * timestep OpenDDS('prog/DopplerCoolShelving.pp') # SetParameter('F_CavityOn', ReadParameter('F_CavityCenter') + CavityOnDF) # To measure temperature we should compare red and blue sideband i.e. do rabi floppings on both. SetParameter('F_RedOn', RedCenter + ReadoutDF) SetParameter('us_RedTime', timeval) # Run DopplerCoolShelving.pp and get a shelving rate: RunDDS() isok = 0 while not isok: try: sciencerv = ReadUnshelved(hist=True) if not len(sciencerv) < 2: isok = 1 else: print "[", __file__, time.asctime( ), "] Empty value in sciencerv? = ", sciencerv print "[", __file__, "] Retrying" sys.stdout.flush() time.sleep(0.5) except Exception, inst: print "[", __file__, time.asctime( ), "] Error in ReadUnshelved Exception: ", inst sys.stdout.flush() time.sleep(0.5) #### Weird code for the case that there is more than one ion. Should be safe to ignore? if ((IonCount == 1) and (sciencerv[2] > 10)): IonCount = 2 if (IonCount == 2): plotrv = sciencerv[1] else: plotrv = sciencerv[0] f421quiet(0) ################################################## # Lock 422 step ################################################## bluerv, BlueCav = Stab.BlueLockNoDDSRunCounts(StabCount) if not len(sciencerv) < 3: #CavLockRead() > CavLockThreshold: ################################################## # Plot and save step ################################################## datapoint = [ timeval, sciencerv[0], sciencerv[1], sciencerv[2], bluelockrv, BlueCav, ramseylockrv, RedCenter, rabilockrv, RedPiTime ] datapoint_index = int(i * ScanPoints + j) mydb.add_data_point(datapoint, datapoint_index) purgatory(plot.add_point, timeval, plotrv, eval(plotLabel)) purgatory(plot.repaint) j = j + 1 else: print "Something wrong with sciencerv:", sciencerv SetParameter('us_RedTime', saved_redtime)
def twoDMicroMotionScan(filename, dirname, StartX, EndX, FinishX, StartY, EndY, FinishY, StepsX, StepsY, Pause, Beam): # Import functions: reload(Stabilization) Beam = int(Beam) plot = gui_exports['plot'] purgatory = gui_exports['purgatory'] ScanDone = f_set['AudioAlert_scandone'] OpenDDS = f_set['DDS_SETPROG'] RunDDS = f_set['DDS_RUNPROG'] ReadUnshelved = f_read['DDS_NBRIGHT'] ReadAvgBright = f_read['DDS_LASTAVG'] SetBlueCav = f_set['MonoLasers_421'] ReadBlueCav = f_read['MonoLasers_421'] Quiet = f_set['MonoLasers_Quiet421'] SetDDS_FREQ1 = f_set['DDS_FREQ1'] SetDDS_FREQ2 = f_set['DDS_FREQ2'] SetDDS_AMP1 = f_set['DDS_AMP1'] SetDDS_FREQ0 = f_set['DDS_FREQ0'] SetDDS_AMP0 = f_set['DDS_AMP0'] SetParameter = f_set['DDS_PARAM'] ReadParameter = f_read['DDS_PARAM'] ReadIonPMT = f_read['IonPhotonCounter_COUNT'] ReadMMAMP = f_read['IonPhotonCounter_MMAMP'] ReadIonPMTALL = f_read['IonPhotonCounter_ALL'] InttimeSet = f_set['IonPhotonCounter_INTTIME'] InttimeRead = f_read['IonPhotonCounter_INTTIME'] inttime_i = InttimeRead() Magic = f_set['IonPhotonCounter_MAGIC'] ##### # xlabel='3631A_topright_+25V' # Back quarter xlabel = '3631A_topmid_+6V' # Top mid ylabel = '3631A_comp_+6V' # Comp print time.strftime("%H:%M:%S"), "Scanning", xlabel, " and ", ylabel ##### SetX = f_set[xlabel] SetY = f_set[ylabel] Stab = Stabilization.Stabilization(f_set, f_read, gui_exports) const = Stab.LoadConstants(DAQ_HOME + '/scripts/StabilizationConstants') plotlabelz = 'fftmax' #### Locking ####### BlueLockOn = 0 if BlueLockOn == 1: bluelockrv, BlueCav = Stab.BlueLock() CavStab = CavityStabilization.CavityStabilization(f_set, f_read, gui_exports) const = CavStab.LoadConstants(DAQ_HOME + '/scripts/CavityStabilizationConstants') # Set up plotting: try: purgatory(plot.clear) purgatory(plot.set_mode, pyextfigure.THREEDPLOT) purgatory(plot.set_labels, xlabel, ylabel, plotlabelz) StepSizeX = (EndX - StartX) / (StepsX) StepSizeY = (EndY - StartY) / (StepsY) purgatory(plot.set_spot_shape, abs(StepSizeX), abs(StepSizeY)) except Exception, e: print time.strftime( '%H:%M:%S' ), __file__, 'Exception occured in purgatory when setting up plot' print e