def load_ion(): curr.on() pmt_on() time.sleep(0.3) ccd_on() time.sleep(1) costed_time = 0 while (not has_ion() and costed_time < 1200): shutter_370.on() shutter_399.on() t2 = time.time() costed_time = t2 - t1 print('ION? %s' % has_ion()) print('LOADING ... %.1fs' % costed_time) time.sleep(0.5) if costed_time > 1200: print('COSTEM TIME IS OUT OF MAX TIME') ccd_on() curr.off() # shutter_370.off() shutter_399.off() curr.beep(3)
def load_ion(self): self.curr.on() self.flip_mirror.off() time.sleep(0.3) self.flip_mirror.on() time.sleep(1) t1 = time.time() costed_time = 0 while (not has_ion() and costed_time < 1200 and self.isLoading): self.shutter_370.on() self.shutter_399.on() t2 = time.time() costed_time = t2 - t1 print('\rION? %s LAODING %.1F' % (has_ion(), costed_time), end=' ') # print('LOADING ... %.1fs' % costed_time) time.sleep(0.5) if costed_time > 1200: print('COSTEM TIME IS OUT OF MAX TIME') return False if has_ion(): self.flip_mirror.on() self.curr.off() self.shutter_370.off() self.shutter_399.off() self.curr.beep(3) register_data(costed_time) return True else: return False
def reload_ion(): t1 = time.time() print('RELOADING...') pmt_on() rf_signal.on() time.sleep(0.3) ccd_on() time.sleep(1) # is_there_ion = has_ion() costed_time = 0 ion_num = has_ion() is_thermalized = False while (costed_time < 600 and not ion_num == 1): # 如果有多个ion 关闭RF放掉离子 if ion_num > 1: rf_signal.off() time.sleep(5) rf_signal.on() # when ion_num = -1 it means that the ion is thermalized # therefore, turn off rf and adjust 370 to toward red direction if ion_num == -1: is_thermalized = True rf_signal.off() wm.relock(2) time.sleep(2) rf_signal.on() curr.on() shutter_370.on() shutter_399.on() time.sleep(2) ion_num = has_ion() costed_time = time.time() - t1 print('COSTED TIME:%.1fs' % (costed_time)) # adjust the 370 wavelength to initial point if is_thermalized: wm.relock(2, -0.000005) # if run out of time and do not catch ion # raise warning information for turther processing if costed_time > 600 or ion_num != 1: curr.off() win32api.MessageBox(0, "Please Check 370 WaveLength", "Warning", win32con.MB_ICONWARNING) # else there is ion # turn to 435 laser scan pmt_on() curr.off() shutter_370.off() shutter_399.off() curr.beep()
def reload_ion(self): wait_time = 5 costed_time = 0 while (costed_time < wait_time and not has_ion()): time.sleep(1) costed_time += 1 if has_ion(): self.curr.off() self.curr.beep(3) else: self.load_ion()
def reload_ion(): t1 = time.time() print('RELOADING...') """ pmt_on() time.sleep(0.3) ccd_on() time.sleep(1) """ # is_there_ion = has_ion() costed_time = 0 while (not has_ion() and costed_time < 900): # if not curr.is_on: curr.on() shutter_370.on() shutter_399.on() costed_time = time.time() - t1 print('COSTED TIME:%.1fs' % (costed_time)) time.sleep(2) pmt_on() curr.off() shutter_370.off() shutter_399.off() curr.beep()
def reload_ion(): shutter_370.on() wait_time = 5 costed_time = 0 while (costed_time < wait_time and not has_ion()): time.sleep(1) costed_time += 1 if has_ion(): curr.off() shutter_370.off() shutter_399.off() curr.beep(3) else: load_ion()
def run(self): self.pre_set() pmt_on() shutter_370.off() center_fre = 260 scan_step = 0.1 fre_width = 1 N = int(fre_width / scan_step) init_fre = center_fre - N / 2 * scan_step # init_fre = 342.57 lock_point = 871.034694 widgets = [ 'Progress: ', Percentage(), ' ', Bar('#'), ' ', Timer(), ' ', ETA(), ' ' ] pbar = ProgressBar(widgets=widgets, maxval=10 * N).start() file_name = 'data\\'+str(lock_point)[5::]+'-'+str(init_fre)+'-' + \ str(float(init_fre+N*scan_step))+'.csv' file = open(file_name, 'w+') file.close() data = np.zeros((4, N)) data[0, :] = np.linspace(init_fre, init_fre + scan_step * (N - 1), N) x_data = list(range(100)) y_data1 = [None] * 100 y_data2 = [None] * 100 """ plt.figure(1) fig1 = plt.subplot(211) line1, = fig1.plot(x_data,y_data1) show_data1 = 'Effiency:0' txt1 = fig1.text(0.8,0.8,show_data1 ,verticalalignment = 'center', \ transform=fig1.transAxes) fig2 = plt.subplot(212) line2, = fig2.plot(x_data,y_data2) show_data2 = 'Count:0' txt2 = fig2.text(0.8,0.8,show_data2,verticalalignment = 'center', \ transform=fig2.transAxes) """ for i in range(N): AOM_435 = init_fre + scan_step * i # - 0.001*N/2 # wait for 871 to be locked while not is_871_locked(lock_point): time.sleep(5) # change AOM frequency code = "conda activate base && python dds.py " + str(AOM_435) os.system(code) time.sleep(0.1) # run detection and save data temp = self.run_sequence() if temp[0] < 50: ccd_on() time.sleep(0.7) if not has_ion(): costed_time = 0 while not has_ion() and costed_time < 300: shutter_370.on() time.sleep(5) costed_time += 5 shutter_370.off() time.sleep(0.5) temp = self.run_sequence() else: pmt_on() y_data1 = y_data1[1::] + [temp[0]] y_data2 = y_data2[1::] + [temp[1]] # print information data_item = [AOM_435, temp[0], temp[1], wm.get_data()[0]] data[:, i] = data_item # write data content = str(data[0, i])+','+str(data[2, i]) + \ ','+str(data[1, i])+','+str(data[3, i])+'\n' file_write(file_name, content) print_info(data_item) pbar.update(10 * i + 1) print('\n') shutter_370.on() file.close() save_file(data, __file__[:-3])
def run(self): self.pre_set() pmt_on() # aom frequnecy is interms of MHz aom_scan_step = 10 / 1000 # 50kHz rescan_file = 'data\\manual-rescan-344179220.0-344178920.0-2019-12-12-20-10.csv' rescan_data = get_data(rescan_file, aom_scan_step) N = len(rescan_data) widgets = [ 'Progress: ', Percentage(), ' ', Bar('#'), ' ', Timer(), ' ', ETA(), ' ' ] pbar = ProgressBar(widgets=widgets, maxval=10 * N).start() # save file time_now = time.strftime("%Y-%m-%d-%H-%M") file_name = 'data\\auto-rescan' + '-' + time_now + '.csv' file = open(file_name, 'w+') file.close() # save data data = np.zeros((4, N)) """ x_data = list(range(100)) y_data1 = [None]*100 y_data2 = [None]*100 """ """ plt.figure(1) fig1 = plt.subplot(211) line1, = fig1.plot(x_data,y_data1) show_data1 = 'Effiency:0' txt1 = fig1.text(0.8,0.8,show_data1 ,verticalalignment = 'center', \ transform=fig1.transAxes) fig2 = plt.subplot(212) line2, = fig2.plot(x_data,y_data2) show_data2 = 'Count:0' txt2 = fig2.text(0.8,0.8,show_data2,verticalalignment = 'center', \ transform=fig2.transAxes) """ for i in range(N): fre_871 = rescan_data[i][1] AOM_435 = rescan_data[i][0] # convert MHz in to THz laser_871_lock.lock(fre_871 / 10**6) laser_871_lock.lock_on() # wait for 871 to be locked while not is_871_locked(fre_871 / 10**6): print('wait for 871 to be locked ...') time.sleep(1) # change AOM frequency code = "conda activate base && python dds.py " + str(AOM_435) os.system(code) # run detection and save data temp = self.run_sequence() # judge if has ion if temp[1] < 90 and not has_ion(): reload_ion() temp = self.run_sequence() # print information data_item = [AOM_435, fre_871, temp[0], temp[1]] data[:, i] = data_item # write data content = str(data[0, i])+','+str(data[3, i])+\ ',' + str(data[2, i])+','+str(data[1, i])+'\n' file_write(file_name, content) print('Count:%d' % temp[1]) print('Effiency:%.1f%%' % temp[0]) pbar.update(10 * i + 1) print('\n') file.close()
def run(self): self.pre_set() pmt_on() shutter_370.off() scan_step = 0.000001 # fre_width = 1 # N = int(fre_width/scan_step) N = 8000 init_fre = 871.034000 # init_fre = 342.57 # lock_point = 871.034694 widgets = [ 'Progress: ', Percentage(), ' ', Bar('#'), ' ', Timer(), ' ', ETA(), ' ' ] pbar = ProgressBar(widgets=widgets, maxval=10 * N).start() file_name = 'data\\'+str(init_fre)[5::]+'-'+str(init_fre)+'-' + \ str(float(init_fre+N*scan_step))+'.csv' file = open(file_name, 'w+') file.close() data = np.zeros((4, N)) data[0, :] = np.linspace(init_fre, init_fre + scan_step * (N - 1), N) x_data = list(range(100)) y_data1 = [None] * 100 y_data2 = [None] * 100 """ plt.figure(1) fig1 = plt.subplot(211) line1, = fig1.plot(x_data,y_data1) show_data1 = 'Effiency:0' txt1 = fig1.text(0.8,0.8,show_data1 ,verticalalignment = 'center', \ transform=fig1.transAxes) fig2 = plt.subplot(212) line2, = fig2.plot(x_data,y_data2) show_data2 = 'Count:0' txt2 = fig2.text(0.8,0.8,show_data2,verticalalignment = 'center', \ transform=fig2.transAxes) """ for i in range(N): # lock 871 fre_871 = init_fre + i * scan_step wm.lock(1, fre_871) time.sleep(0.1) # run detection and save data temp = self.run_sequence() # check state when detection effiency < 50 if temp[0] < 3 * 50: ccd_on() time.sleep(0.7) # reload ion if not has_ion(): costed_time = 0 curr.on() while not has_ion() and costed_time < 300: shutter_370.on() time.sleep(5) costed_time += 5 shutter_370.off() time.sleep(0.5) temp = self.run_sequence() else: curr.off() pmt_on() y_data1 = y_data1[1::] + [temp[0]] y_data2 = y_data2[1::] + [temp[1]] # print information data_item = [fre_871, temp[0] / 3, temp[1], wm.get_data()[0]] data[:, i] = data_item # write data content = str(data[0, i])+','+str(data[2, i]) + \ ','+str(data[1, i])+','+str(data[3, i])+'\n' file_write(file_name, content) print_info(data_item) pbar.update(10 * i + 1) print('\n') shutter_370.on() file.close() save_file(data, __file__[:-3])
def run(self): self.pre_set() pmt_on() # aom frequnecy is interms of MHz init_aom_fre = 210 stop_aom_fre = 240 aom_scan_step = 50 / 1000 # 50kHz aom_N = int((stop_aom_fre - init_aom_fre) / aom_scan_step) # laser_frequency is interms of MHz laser_scan_step = -(stop_aom_fre - init_aom_fre) init_laser_fre = 344.179520 * 10**6 laser_N = 2 N = laser_N * aom_N # calculate min and max frequency min_fre = init_laser_fre - 2 * 240 max_fre = init_laser_fre - 2 * 240 + laser_N * laser_scan_step # progressbar widgets = [ 'Progress: ', Percentage(), ' ', Bar('#'), ' ', Timer(), ' ', ETA(), ' ' ] pbar = ProgressBar(widgets=widgets, maxval=10 * N).start() # save file time_now = time.strftime("%Y-%m-%d-%H-%M") file_name = 'data\\' + str(min_fre) + '-' + str( max_fre) + '-' + time_now + '.csv' file = open(file_name, 'w+') file.close() rescan_file_name = 'data\\rescan-' + str(min_fre) + '-' + str( max_fre) + '-' + time_now + '.csv' rescan_file = open(rescan_file_name, 'w+') rescan_file.close() manual_rescan_file_name = 'data\\manual-rescan-' + \ str(min_fre)+'-'+str(max_fre)+'-'+time_now+'.csv' manual_rescan_file = open(manual_rescan_file_name, 'w+') manual_rescan_file.close() # save data data = np.zeros((4, N)) data[0, :] = np.linspace(min_fre, max_fre, N) x_data = list(range(100)) y_data1 = [None] * 100 y_data2 = [None] * 100 """ plt.figure(1) fig1 = plt.subplot(211) line1, = fig1.plot(x_data,y_data1) show_data1 = 'Effiency:0' txt1 = fig1.text(0.8,0.8,show_data1 ,verticalalignment = 'center', \ transform=fig1.transAxes) fig2 = plt.subplot(212) line2, = fig2.plot(x_data,y_data2) show_data2 = 'Count:0' txt2 = fig2.text(0.8,0.8,show_data2,verticalalignment = 'center', \ transform=fig2.transAxes) """ for i in range(laser_N): fre_871 = init_laser_fre + i * laser_scan_step # convert MHz in to THz laser_871_lock.lock(fre_871 / 10**6) laser_871_lock.lock_on() # wait for 871 to be locked while not is_871_locked(fre_871 / 10**6): print('wait for 871 to be locked ...') time.sleep(1) for j in range(aom_N): index = i * aom_N + j AOM_435 = init_aom_fre + aom_scan_step * j # change AOM frequency code = "conda activate base && python dds.py " + str(AOM_435) os.system(code) # run detection and save data temp = self.run_sequence() y_data1 = y_data1[1::] + [temp[0]] y_data2 = y_data2[1::] + [temp[1]] # print information data_item = [AOM_435, temp[0], temp[1], wm.get_data()[0]] data[:, index] = data_item # write data content = str(data[0, index])+','+str(data[1, index]) + \ ','+str(data[2, index])+','+str(data[3, index])+','+str(fre_871)+'\n' file_write(file_name, content) # print('coming to line 298') print_info(data_item) pbar.update(10 * index + 1) print('\n') # rescan at most n times when effiency is less than 80% rescan_time = 0 temp_data = [] if temp[0] < 90: while rescan_time < 5: # check if there is ion ccd_on() time.sleep(0.5) # there is ion try to cool the ion if has_ion(): shutter_370.on() time.sleep(0.5) shutter_370.off() pmt_on() time.sleep(0.2) temp1 = self.run_sequence() temp_data.append(list(temp1)) rescan_time += 1 print('rescan:%d, effiency:%d' % (rescan_time, temp1[0])) print('\n') # there is no ion reload ion else: reload_ion() pmt_on() if rescan_time == 5: # print('saveing data') temp_data = np.array(temp_data, dtype=np.int) effiencies = temp_data[:, 0] counts = temp_data[:, 1] rescan_content = str(AOM_435) for k in range(5): rescan_content = rescan_content + ',' + str( effiencies[k]) for kk in range(5): rescan_content = rescan_content + ',' + str(counts[kk]) rescan_content = rescan_content + ',' + str(fre_871) + '\n' file_write(rescan_file_name, rescan_content) if effiencies.mean() < 90: file_write(manual_rescan_file_name, rescan_content) # update figure # line1.set_xdata(data[0,0:index]) file.close() rescan_file.close() manual_rescan_file.close() save_file(data, __file__[:-3])
import time from image_processing import has_ion from ttl_client import shutter shutter_370 = shutter(com=0) flip_mirror = shutter(com=1) shutter_399 = shutter(com=2) ccd_on = flip_mirror.off pmt_on = flip_mirror.on t = 0.6 pmt_on() time.sleep(t) for i in range(10): ccd_on() time.sleep(t) if not has_ion(): print('There is no ion') pmt_on() time.sleep(0.6)
def run(self): self.pre_set() pmt_on() AOM_435 = 315.55 lock_point = 871.034867 rabi_time = 1000 run_times = 100 N = 1000 #widgets = ['Progress: ', Percentage(), ' ', Bar('#'), ' ', #Timer(), ' ', ETA(), ' '] #pbar = ProgressBar(widgets=widgets, maxval=10*N).start() # save file #time_now = time.strftime("%Y-%m-%d-%H-%M") #file_name = 'data\\435-rabi-scan'+'-'+time_now+'.csv' #file = open(file_name, 'w+') #file.close() # save data data = np.zeros((4, N)) """ x_data = list(range(100)) y_data1 = [None]*100 y_data2 = [None]*100 """ """ plt.figure(1) fig1 = plt.subplot(211) line1, = fig1.plot(x_data,y_data1) show_data1 = 'Effiency:0' txt1 = fig1.text(0.8,0.8,show_data1 ,verticalalignment = 'center', \ transform=fig1.transAxes) fig2 = plt.subplot(212) line2, = fig2.plot(x_data,y_data2) show_data2 = 'Count:0' txt2 = fig2.text(0.8,0.8,show_data2,verticalalignment = 'center', \ transform=fig2.transAxes) """ for i in range(N): # wait for 871 to be locked while not is_871_locked(lock_point): print('wait for 871 to be locked ...') time.sleep(1) # change AOM frequency code = "conda activate base && python dds.py " + str(AOM_435) os.system(code) # run detection and save data temp = self.run_sequence(rabi_time,run_times) # judge if has ion if temp[1] < 90 and not has_ion(): reload_ion() temp = self.run_sequence(rabi_time, run_times) # print information data_item = [AOM_435,rabi_time,temp[1],temp[0]] data[:, i] = data_item # write data #content = str(data[0, i])+','+str(data[1, i]) +\ #',' + str(data[2, i])+','+str(data[3, i])+'\n' #file_write(file_name, content) print('Count:%d' % temp[1]) print('Effiency:%.1f%%' % temp[0]) #pbar.update(10*i+1) print('\n') #rabi_time = rabi_time + rabi_time_step file.close()
def run(self): self.pre_set() pmt_on() init_fre = 210 lock_point = 871.034661 scan_step = 0.01 N = 5000 widgets = ['Progress: ', Percentage(), ' ', Bar('#'), ' ', Timer(), ' ', ETA(), ' '] pbar = ProgressBar(widgets=widgets, maxval=10*N).start() file_name = 'data\\'+str(lock_point)[5::]+'-'+str(init_fre)+'-' + \ str(float(init_fre+N*scan_step))+'.csv' file = open(file_name, 'w+') file.close() rescan_file_name = 'data\\rescan' + str(lock_point)[5::]+'-' + \ str(init_fre)+'-'+str(float(init_fre+N*scan_step))+'.csv' rescan_file = open(rescan_file_name, 'w+') rescan_file.close() manual_rescan_file_name = 'data\\manual_rescan' + str(lock_point)[5::]+'-' + \ str(init_fre)+'-'+str(float(init_fre+N*scan_step))+'.csv' manual_rescan_file = open(manual_rescan_file_name, 'w+') manual_rescan_file.close() data = np.zeros((4, N)) data[0, :] = np.linspace(init_fre, init_fre+scan_step*(N-1), N) x_data = list(range(100)) y_data1 = [None]*100 y_data2 = [None]*100 """ plt.figure(1) fig1 = plt.subplot(211) line1, = fig1.plot(x_data,y_data1) show_data1 = 'Effiency:0' txt1 = fig1.text(0.8,0.8,show_data1 ,verticalalignment = 'center', \ transform=fig1.transAxes) fig2 = plt.subplot(212) line2, = fig2.plot(x_data,y_data2) show_data2 = 'Count:0' txt2 = fig2.text(0.8,0.8,show_data2,verticalalignment = 'center', \ transform=fig2.transAxes) """ for i in trange(N): AOM_435 = init_fre+scan_step*i # - 0.001*N/2 # wait for 871 to be locked while not is_871_locked(lock_point): print('Laser is locking...') time.sleep(3) # change AOM frequency code = "conda activate base && python dds.py " + str(AOM_435) os.system(code) # run detection and save data temp = self.run_sequence() y_data1 = y_data1[1::]+[temp[0]] y_data2 = y_data2[1::]+[temp[1]] # print information data_item = [AOM_435, temp[0], temp[1], wl_871] data[:, i] = data_item # write data content = str(data[0, i])+','+str(data[1, i]) + \ ','+str(data[2, i])+','+str(data[3, i])+'\n' file_write(file_name, content) print_info(data_item) pbar.update(10*i+1) print('\n') # rescan at most n times when effiency is less than 80% rescan_time = 0 temp_data = [] # there may multi # ple ion if temp[1] > 800: if has_ion() > 1: reload_ion() pmt_on() if temp[0] < 70: while rescan_time < 5: # check if there is ion ccd_on() time.sleep(0.8) # there is ion try to cool the ion if has_ion(): shutter_370.on() time.sleep(0.5) shutter_370.off() pmt_on() time.sleep(0.2) temp1 = self.run_sequence() temp_data.append(list(temp1)) rescan_time += 1 print('rescan:%d, effiency:%d' % (rescan_time, temp1[0])) print('\n') # there is no ion reload ion else: reload_ion() pmt_on() if rescan_time == 5: # print('saveing data') temp_data = np.array(temp_data, dtype=np.int) effiencies = temp_data[:, 0] counts = temp_data[:, 1] rescan_content = str(AOM_435) for k in range(5): rescan_content = rescan_content+','+str(effiencies[k]) for kk in range(5): rescan_content = rescan_content+','+str(counts[kk]) rescan_content = rescan_content + '\n' file_write(rescan_file_name, rescan_content) if effiencies.mean() < 90: file_write(manual_rescan_file_name, rescan_content) # update figure # line1.set_xdata(data[0,0:i]) file.close() rescan_file.close() manual_rescan_file.close() save_file(data, __file__[:-3]) curr.off()
def is_ion(self): return has_ion()