diff --git a/PLE/032_Pulse_Rabi.py b/PLE/032_Pulse_Rabi.py new file mode 100644 index 0000000..27b3724 --- /dev/null +++ b/PLE/032_Pulse_Rabi.py @@ -0,0 +1,250 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Feb 4 23:35:57 2025 + +@author: shen_t2 +""" + +""" +! Remember to start RFSoC codes after running this file ! +""" + + +import os +# os.chdir(os.path.abspath(os.path.dirname(__file__))) + +import time +from datetime import datetime +now = datetime.now() +# timestempID = now.strftime("_%y%m%d%H%M%S") +timestempID = now.strftime("_%m%d%H%M") + +import numpy as np +import matplotlib.pyplot as plt +plt.rcParams.update({'font.size': 14}) + + +import nidaqmx +from DAQCountingFunctions import arbitaryTTL_gated_count_task, correct_cps + +# import PowerSupplyCaylarLib +# from EMagnetSetFields import EMagnet_connect_test, set_Bfield_Gauss, set_Bfield_Current + +# from toptica.lasersdk.dlcpro.v2_6_0 import DLCpro, NetworkConnection, DeviceNotFoundError +# from LaserWideScanSettings import set_widescan_para + +EXP_TYPE = "_Pulse_Rabi" + + +# %% Experiment parameters + +from Global_Experiment_Parameters import * + +EMagnet_poles_gap = "large" # "small" 39 mm upto 1.3 T, or "large" 80 mm upto 0.8 T +EMagnet_initialization = True +EMagnet_initialization = False + +total_average = 100 + + +# Scanning excitation pulse width +time_init = 0.000 # in [us] +time_final = 1.500 +time_step = 0.005 +time_list = np.linspace(time_init, time_final, int((time_final-time_init)/time_step)+1) +# time_list = np.logspace(1, 32, num=50, endpoint=True, base=2.0) / 1e3 +x_all = time_list + +DAQ_samps_per_chan = len(x_all) +# DAQ_loop_per_chan = 3 + +# AOM_ON_time = 30e-3 # s +DAQ_counting_time = 10e-3 # s +resonance_freq = +1500 # in [MHz] + + + +exp_notes = 'laser {:d} mA (with EOM), {:}, {:},\n+{:d} Gs, sample{:}, {:}'.format(laser_current, ODFilter, laser_pol, Bext_field_scan[0], sample, Temp_info) # as plot title +exp_notes += '\nDAQ counting window = {:.0f} ms'.format(DAQ_counting_time*1e3) +# exp_notes += '\nResonance frequency = {:.0f} MHz'.format(resonance_freq) +exp_notes += '\nwithout EOM, laser directly locked to 0-0 transition' + +fn_suffix = '_count{:.0f}ms'.format(DAQ_counting_time*1e3) + +MAIN_EXP_folder = 'C:/RE_qubit_TS/202503_Pulse_echo_sample2/02_thicker_Cu_plate/61_left3_left_splitting/run21_Rabi_smallApt_1500ns_noEOM_count10ms_avg{:d}/'.format(total_average) +# MAIN_EXP_folder += 'excitation_{:.1f}ms_count_{:.0f}ms/'.format(AOM_ON_time*1e3, DAQ_counting_time*1e3) +# os.chdir(MAIN_EXP_folder) + + + +# %% Devices initialization + +# EMagnet_PowerSupply = PowerSupplyCaylarLib.CaylarPowerSupply(2) +# EMagnet_connect_test(EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + + +###################################### + +### Laser NOT used! + + +###################################### + +try: + task_count.close() + task_clock.close() +except: + pass +finally: + print("------------------------------") + print("Tasks have been cleared.\n") + + +task_count = arbitaryTTL_gated_count_task(DAQ_samps_per_chan) + + + +# %% Start experiments + +try: + os.mkdir(MAIN_EXP_folder) +except: + pass +finally: + print("==============================") + print("==============================") + print("==============================") + print("Experiment folder has been created.\n") + print("Experiment STARTS here.\n") + + +np.save( MAIN_EXP_folder + 'excitation_time_x_axis_{:.0f}-{:.0f}ms'.format(time_init * 1e-3, time_final * 1e-3) + EXP_TYPE + timestempID, + x_all) + +# np.save( MAIN_EXP_folder + 'wl_scan_Bfields' + timestempID, Bext_field_scan) + + +raw_counts_sum = np.zeros(len(x_all)) +actual_counts_sum = np.zeros(len(x_all)) +ext_reminder = True + +for ii in range(total_average): + + # raw_counts_all = [] + + + # Always initialize to -100 as minus saturation, + # because the calibration follows the lower branch of the magnetic hysteresis. + # Then, scan from - to + + + if EMagnet_initialization: + set_Bfield_Current(-100, EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + time.sleep(5) + + + for B_field in Bext_field_scan: + + # set_Bfield_Gauss(B_field, EMagnet_poles_gap, EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + # time.sleep(5) + + task_count.start() + + print("------------------------------") + print("Start: Exp. {} Gs, Loop {}.".format(B_field, ii)) + + if ext_reminder == True: + print("==============================") + print("!!! Now, start RFSoC output !!!") + print("!!! And, make sure AOM TTL input from RFSoC Pmod box !!!") + print("==============================") + ext_reminder = False + + raw_counts = task_count.read(nidaqmx.constants.READ_ALL_AVAILABLE, nidaqmx.constants.WAIT_INFINITELY) + + if len(raw_counts) == DAQ_samps_per_chan: + # print("------------------------------") + print("End: no errors.") + + + task_count.stop() + + + + # Data processing and saving + + raw_counts = np.array(raw_counts) + np.save( MAIN_EXP_folder + 'raw_counts_B{:d}Gs_rep{:d}'.format(B_field, ii) + fn_suffix + timestempID, raw_counts) + + actual_counts = correct_cps(raw_counts, DAQ_counting_time, SAPD_dead_time) + np.save( MAIN_EXP_folder + 'actual_counts_B{:d}Gs_rep{:d}'.format(B_field, ii) + fn_suffix + timestempID, actual_counts) + print("Data saved.") + + + raw_counts_sum += raw_counts + actual_counts_sum += actual_counts + + # raw_counts_all.append(raw_counts) + + + ####################################### + # real-time plot + plt.figure(32, figsize=[9,6], dpi=100) + plt.clf() + plt.plot(x_all * 1e-3, raw_counts_sum /(ii+1), '.-b', label='avg {:}, raw counts'.format(ii+1) ) + plt.plot(x_all * 1e-3, actual_counts_sum /(ii+1), '.-r', label='avg {:}, corrected'.format(ii+1) ) + plt.grid() + plt.legend(loc=1) + plt.title(exp_notes) + plt.xlabel('Excitation time/ms') + plt.ylabel('Actual photon counts (cps)') + plt.tight_layout() + plt.savefig( MAIN_EXP_folder + 'plot_counts_B{:d}Gs_rep{:d}{:}{:}.jpg'.format(B_field, ii, fn_suffix, timestempID) ) + plt.show() + plt.pause(0.1) + + + # if len(Bext_field_scan) > 1: + # raw_counts_all = np.array(raw_counts_all) + # np.save( MAIN_EXP_folder + 'raw_counts_All_Bfields_rep{:d}'.format(ii) + fn_suffix + timestempID, raw_counts_all) + + # actual_counts_all = correct_cps(raw_counts_all, DAQ_counting_time, SAPD_dead_time) + # np.save( MAIN_EXP_folder + 'actual_counts_All_Bfields_rep{:d}'.format(ii) + fn_suffix + timestempID, actual_counts_all) + + +if total_average > 1: + np.save( MAIN_EXP_folder + 'raw_counts_{:d}Averaged'.format(total_average) + EXP_TYPE + timestempID, raw_counts_sum / total_average) + np.save( MAIN_EXP_folder + 'actual_counts_{:d}Averaged'.format(total_average) + EXP_TYPE + timestempID, actual_counts_sum / total_average) + + + +# %% Completed + +# set_Bfield_Current(0, EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + + +task_count.close() + + +print("==============================") +print("ALL END. (NO ERRORS)\n") + + + +# %% END + + +plt.figure(32, figsize=[9,6], dpi=100) +plt.clf() +plt.plot(x_all, raw_counts_sum /(ii+1), '.-b', label='avg {:}, raw counts'.format(ii+1) ) +plt.plot(x_all, actual_counts_sum /(ii+1), '.-r', label='avg {:}, corrected'.format(ii+1) ) +plt.grid() +plt.legend(loc=1) +plt.title(exp_notes) +plt.xlabel('Excitation time/us') +plt.ylabel('Actual photon counts (cps)') +# plt.xscale('log') +plt.tight_layout() +plt.savefig( MAIN_EXP_folder + 'plot_counts_B{:d}Gs_{:d}Averaged{:}{:}.jpg'.format(B_field, total_average, fn_suffix, timestempID) ) +plt.show() + + diff --git a/PLE/033_Pulse_echo_halfpi.py b/PLE/033_Pulse_echo_halfpi.py new file mode 100644 index 0000000..4747ff0 --- /dev/null +++ b/PLE/033_Pulse_echo_halfpi.py @@ -0,0 +1,259 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Feb 4 23:35:57 2025 + +@author: shen_t2 +""" + +""" +! Remember to start RFSoC codes after running this file ! +""" + + +import os +# os.chdir(os.path.abspath(os.path.dirname(__file__))) + +import time +from datetime import datetime +now = datetime.now() +# timestempID = now.strftime("_%y%m%d%H%M%S") +timestempID = now.strftime("_%m%d%H%M") + +import numpy as np +import matplotlib.pyplot as plt +plt.rcParams.update({'font.size': 14}) + + +import nidaqmx +from DAQCountingFunctions import arbitaryTTL_gated_count_task, correct_cps + +# import PowerSupplyCaylarLib +# from EMagnetSetFields import EMagnet_connect_test, set_Bfield_Gauss, set_Bfield_Current + +# from toptica.lasersdk.dlcpro.v2_6_0 import DLCpro, NetworkConnection, DeviceNotFoundError +# from LaserWideScanSettings import set_widescan_para + +EXP_TYPE = "_Pulse_echo_halfpi" + + +# %% Experiment parameters + +from Global_Experiment_Parameters import * + +EMagnet_poles_gap = "large" # "small" 39 mm upto 1.3 T, or "large" 80 mm upto 0.8 T +EMagnet_initialization = True +EMagnet_initialization = False + +total_average = 50 + + +t_half_pi = 0.200 # in [us] +tau = 0.400 # in [us] + +# Scanning excitation pulse width (change half_pi time) +time_init = 0.000 # in [us] +time_final = 1.000 +time_step = 0.010 +time_list = np.linspace(time_init, time_final, int((time_final-time_init)/time_step)+1) +x_all = time_list + +DAQ_samps_per_chan = len(x_all) +# DAQ_loop_per_chan = 3 + +# AOM_ON_time = 30e-3 # s +DAQ_counting_time = 3e-3 # s +resonance_freq = +1500 # in [MHz] + + + +exp_notes = 'laser {:d} mA (with EOM), {:}, {:},\n+{:d} Gs, sample{:}, {:}'.format(laser_current, ODFilter, laser_pol, Bext_field_scan[0], sample, Temp_info) # as plot title +exp_notes += '\ntau = {:.1f} ns, DAQ counting window = {:.0f} ms'.format(tau*1e3, DAQ_counting_time*1e3) +# exp_notes += '\nResonance frequency = {:.0f} MHz'.format(resonance_freq) +exp_notes += '\nwithout EOM, laser directly locked to 0-0 transition' + +fn_suffix = '_tau{:.0f}ns_count{:.0f}ms'.format(tau*1e3, DAQ_counting_time*1e3) + +MAIN_EXP_folder = 'C:/RE_qubit_TS/202503_Pulse_echo_sample2/02_thicker_Cu_plate/29_echo_halfpi_play/run1_{:.0f}us_noEOM_avg{:d}/'.format(time_final, total_average) +# MAIN_EXP_folder += 'excitation_{:.1f}ms_count_{:.0f}ms/'.format(AOM_ON_time*1e3, DAQ_counting_time*1e3) +# os.chdir(MAIN_EXP_folder) + + + +# %% Devices initialization + +# EMagnet_PowerSupply = PowerSupplyCaylarLib.CaylarPowerSupply(2) +# EMagnet_connect_test(EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + + +###################################### + +### Laser NOT used! + + +###################################### + +try: + task_count.close() + task_clock.close() +except: + pass +finally: + print("------------------------------") + print("Tasks have been cleared.\n") + + +task_count = arbitaryTTL_gated_count_task(DAQ_samps_per_chan) + + + +# %% Start experiments + +try: + os.mkdir(MAIN_EXP_folder) +except: + pass +finally: + print("==============================") + print("==============================") + print("==============================") + print("Experiment folder has been created.\n") + print("Experiment STARTS here.\n") + + +np.save( MAIN_EXP_folder + 'half_pi_x_axis_{:.0f}-{:.0f}ns'.format(time_init * 1e3, time_final * 1e3) + EXP_TYPE + timestempID, + x_all) + +# np.save( MAIN_EXP_folder + 'wl_scan_Bfields' + timestempID, Bext_field_scan) + + +raw_counts_sum = np.zeros(len(x_all)) +actual_counts_sum = np.zeros(len(x_all)) +ext_reminder = True + +for ii in range(total_average): + + # raw_counts_all = [] + + + # Always initialize to -100 as minus saturation, + # because the calibration follows the lower branch of the magnetic hysteresis. + # Then, scan from - to + + + if EMagnet_initialization: + set_Bfield_Current(-100, EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + time.sleep(5) + + + for B_field in Bext_field_scan: + + # set_Bfield_Gauss(B_field, EMagnet_poles_gap, EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + # time.sleep(5) + + task_count.start() + + print("------------------------------") + print("Start: Exp. {} Gs, Loop {}.".format(B_field, ii)) + + if ext_reminder == True: + print("==============================") + print("!!! Now, start RFSoC output !!!") + print("!!! And, make sure AOM TTL input from RFSoC Pmod box !!!") + print("==============================") + ext_reminder = False + + raw_counts = task_count.read(nidaqmx.constants.READ_ALL_AVAILABLE, nidaqmx.constants.WAIT_INFINITELY) + + if len(raw_counts) == DAQ_samps_per_chan: + # print("------------------------------") + print("End: no errors.") + + + task_count.stop() + + + + # Data processing and saving + + raw_counts = np.array(raw_counts) + np.save( MAIN_EXP_folder + 'raw_counts_B{:d}Gs_rep{:d}'.format(B_field, ii) + fn_suffix + timestempID, raw_counts) + + actual_counts = correct_cps(raw_counts, DAQ_counting_time, SAPD_dead_time) + np.save( MAIN_EXP_folder + 'actual_counts_B{:d}Gs_rep{:d}'.format(B_field, ii) + fn_suffix + timestempID, actual_counts) + print("Data saved.") + + + raw_counts_sum += raw_counts + actual_counts_sum += actual_counts + + # raw_counts_all.append(raw_counts) + + + ####################################### + # real-time plot + plt.figure(33, figsize=[9,6], dpi=100) + plt.clf() + plt.plot(x_all * 1e3, raw_counts_sum /(ii+1), '.-b', label='avg {:}, raw counts'.format(ii+1) ) + plt.plot(x_all * 1e3, actual_counts_sum /(ii+1), '.-r', label='avg {:}, corrected'.format(ii+1) ) + plt.grid() + plt.legend(loc=1) + plt.title(exp_notes) + plt.xlabel('Half pi time/ns') + plt.ylabel('Actual photon counts (cps)') + plt.tight_layout() + plt.savefig( MAIN_EXP_folder + 'plot_counts_B{:d}Gs_rep{:d}{:}{:}.jpg'.format(B_field, ii, fn_suffix, timestempID) ) + plt.show() + plt.pause(0.1) + + + # if len(Bext_field_scan) > 1: + # raw_counts_all = np.array(raw_counts_all) + # np.save( MAIN_EXP_folder + 'raw_counts_All_Bfields_rep{:d}'.format(ii) + fn_suffix + timestempID, raw_counts_all) + + # actual_counts_all = correct_cps(raw_counts_all, DAQ_counting_time, SAPD_dead_time) + # np.save( MAIN_EXP_folder + 'actual_counts_All_Bfields_rep{:d}'.format(ii) + fn_suffix + timestempID, actual_counts_all) + + +if total_average > 1: + np.save( MAIN_EXP_folder + 'raw_counts_{:d}Averaged'.format(total_average) + EXP_TYPE + timestempID, raw_counts_sum / total_average) + np.save( MAIN_EXP_folder + 'actual_counts_{:d}Averaged'.format(total_average) + EXP_TYPE + timestempID, actual_counts_sum / total_average) + + + +# %% Completed + +# set_Bfield_Current(0, EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + + +task_count.close() + + +print("==============================") +print("ALL END. (NO ERRORS)\n") + + + +# %% END + + +# plt.figure(2, figsize=[9,6], dpi=100) +# plt.clf() +# plt.plot(wl_x_axis, raw_counts, '.-b', label='loop {:}, raw counts'.format(ii) ) +# plt.plot(wl_x_axis, actual_counts, '.-r', label='loop {:}, corrected'.format(ii) ) +# plt.grid() +# plt.legend(loc=1) +# plt.title(exp_notes) +# plt.xlabel('Wavelength (nm)') +# plt.ylabel('Actual photon counts (cps)') +# plt.show() + + +# wl_scan = np.load('wl_scan_x_axis_1529.90_1530.50_speed0.0010_12031938.npy') +# actual_counts = np.load('actual_counts_B1000Gs_rep0_12031938.npy') +# raw_counts = np.load('raw_counts_B1000Gs_rep0_12031938.npy') +# plt.figure(3, figsize=[9,6], dpi=100) +# plt.clf() +# plt.plot(wl_scan, raw_counts, '.-b') +# plt.plot(wl_scan, actual_counts, '.-r') +# plt.grid() +# plt.show() + diff --git a/PLE/034_Pulse_echo_tau_T2.py b/PLE/034_Pulse_echo_tau_T2.py new file mode 100644 index 0000000..22fc0bb --- /dev/null +++ b/PLE/034_Pulse_echo_tau_T2.py @@ -0,0 +1,253 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Feb 4 23:35:57 2025 + +@author: shen_t2 +""" + +""" +! Remember to start RFSoC codes after running this file ! +""" + + +import os +# os.chdir(os.path.abspath(os.path.dirname(__file__))) + +import time +from datetime import datetime +now = datetime.now() +# timestempID = now.strftime("_%y%m%d%H%M%S") +timestempID = now.strftime("_%m%d%H%M") + +import numpy as np +import matplotlib.pyplot as plt +plt.rcParams.update({'font.size': 14}) + + +import nidaqmx +from DAQCountingFunctions import arbitaryTTL_gated_count_task, correct_cps + +# import PowerSupplyCaylarLib +# from EMagnetSetFields import EMagnet_connect_test, set_Bfield_Gauss, set_Bfield_Current + +# from toptica.lasersdk.dlcpro.v2_6_0 import DLCpro, NetworkConnection, DeviceNotFoundError +# from LaserWideScanSettings import set_widescan_para + +EXP_TYPE = "_Pulse_echo_tau_T2" + + +# %% Experiment parameters + +from Global_Experiment_Parameters import * + +EMagnet_poles_gap = "large" # "small" 39 mm upto 1.3 T, or "large" 80 mm upto 0.8 T +EMagnet_initialization = True +EMagnet_initialization = False + +total_average = 10 + + +t_half_pi = 0.500 # in [us] +tau = 0.500 # in [us] + +# Scanning excitation pulse width (change half_pi time) +time_init = 0.000 # in [us] +time_final = 10.000 +time_step = 0.050 +time_list = np.linspace(time_init, time_final, int((time_final-time_init)/time_step)+1) +# time_list = np.logspace(1, 30, num=50, endpoint=True, base=2.0) / 1e3 +x_all = time_list + +DAQ_samps_per_chan = len(x_all) +# DAQ_loop_per_chan = 3 + +# AOM_ON_time = 30e-3 # s +DAQ_counting_time = 3e-3 # s +resonance_freq = +1500 # in [MHz] + + + +exp_notes = 'laser {:d} mA (with EOM), {:}, {:},\n+{:d} Gs, sample{:}, {:}'.format(laser_current, ODFilter, laser_pol, Bext_field_scan[0], sample, Temp_info) # as plot title +exp_notes += '\nhalf pi = {:.1f} ns, DAQ counting window = {:.0f} ms'.format(t_half_pi*1e3, DAQ_counting_time*1e3) +# exp_notes += '\nResonance frequency = {:.0f} MHz'.format(resonance_freq) +exp_notes += '\nwithout EOM, laser directly locked to 0-0 transition' + +fn_suffix = '_halfpi{:.0f}ns_count{:.0f}ms'.format(t_half_pi*1e3, DAQ_counting_time*1e3) + +MAIN_EXP_folder = 'C:/RE_qubit_TS/202503_Pulse_echo_sample2/02_thicker_Cu_plate/18_echo_tau_T2_population/run4_1s_noEOM_halfpi{:.0f}ns_avg{:d}/'.format(t_half_pi * 1e3, total_average) +# MAIN_EXP_folder += 'excitation_{:.1f}ms_count_{:.0f}ms/'.format(AOM_ON_time*1e3, DAQ_counting_time*1e3) +# os.chdir(MAIN_EXP_folder) + + + +# %% Devices initialization + +# EMagnet_PowerSupply = PowerSupplyCaylarLib.CaylarPowerSupply(2) +# EMagnet_connect_test(EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + + +###################################### + +### Laser NOT used! + + +###################################### + +try: + task_count.close() + task_clock.close() +except: + pass +finally: + print("------------------------------") + print("Tasks have been cleared.\n") + + +task_count = arbitaryTTL_gated_count_task(DAQ_samps_per_chan) + + + +# %% Start experiments + +try: + os.mkdir(MAIN_EXP_folder) +except: + pass +finally: + print("==============================") + print("==============================") + print("==============================") + print("Experiment folder has been created.\n") + print("Experiment STARTS here.\n") + + +np.save( MAIN_EXP_folder + 'tau_x_axis_{:.0f}-{:.0f}ns'.format(time_init * 1e3, time_final * 1e3) + EXP_TYPE + timestempID, + x_all) + +# np.save( MAIN_EXP_folder + 'wl_scan_Bfields' + timestempID, Bext_field_scan) + + +raw_counts_sum = np.zeros(len(x_all)) +actual_counts_sum = np.zeros(len(x_all)) +ext_reminder = True + +for ii in range(total_average): + + # raw_counts_all = [] + + + # Always initialize to -100 as minus saturation, + # because the calibration follows the lower branch of the magnetic hysteresis. + # Then, scan from - to + + + if EMagnet_initialization: + set_Bfield_Current(-100, EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + time.sleep(5) + + + for B_field in Bext_field_scan: + + # set_Bfield_Gauss(B_field, EMagnet_poles_gap, EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + # time.sleep(5) + + task_count.start() + + print("------------------------------") + print("Start: Exp. {} Gs, Loop {}.".format(B_field, ii)) + + if ext_reminder == True: + print("==============================") + print("!!! Now, start RFSoC output !!!") + print("!!! And, make sure AOM TTL input from RFSoC Pmod box !!!") + print("==============================") + ext_reminder = False + + raw_counts = task_count.read(nidaqmx.constants.READ_ALL_AVAILABLE, nidaqmx.constants.WAIT_INFINITELY) + + if len(raw_counts) == DAQ_samps_per_chan: + # print("------------------------------") + print("End: no errors.") + + + task_count.stop() + + + + # Data processing and saving + + raw_counts = np.array(raw_counts) + np.save( MAIN_EXP_folder + 'raw_counts_B{:d}Gs_rep{:d}'.format(B_field, ii) + fn_suffix + timestempID, raw_counts) + + actual_counts = correct_cps(raw_counts, DAQ_counting_time, SAPD_dead_time) + np.save( MAIN_EXP_folder + 'actual_counts_B{:d}Gs_rep{:d}'.format(B_field, ii) + fn_suffix + timestempID, actual_counts) + print("Data saved.") + + + raw_counts_sum += raw_counts + actual_counts_sum += actual_counts + + # raw_counts_all.append(raw_counts) + + + ####################################### + # real-time plot + plt.figure(34, figsize=[9,6], dpi=100) + plt.clf() + plt.plot(x_all * 1e3, raw_counts_sum /(ii+1), '.-b', label='avg {:}, raw counts'.format(ii+1) ) + plt.plot(x_all * 1e3, actual_counts_sum /(ii+1), '.-r', label='avg {:}, corrected'.format(ii+1) ) + plt.grid() + plt.legend(loc=1) + plt.title(exp_notes) + plt.xlabel('$\\tau$/ns') + plt.ylabel('Actual photon counts (cps)') + plt.tight_layout() + plt.savefig( MAIN_EXP_folder + 'plot_counts_B{:d}Gs_rep{:d}{:}{:}.jpg'.format(B_field, ii, fn_suffix, timestempID) ) + plt.show() + plt.pause(0.1) + + + # if len(Bext_field_scan) > 1: + # raw_counts_all = np.array(raw_counts_all) + # np.save( MAIN_EXP_folder + 'raw_counts_All_Bfields_rep{:d}'.format(ii) + fn_suffix + timestempID, raw_counts_all) + + # actual_counts_all = correct_cps(raw_counts_all, DAQ_counting_time, SAPD_dead_time) + # np.save( MAIN_EXP_folder + 'actual_counts_All_Bfields_rep{:d}'.format(ii) + fn_suffix + timestempID, actual_counts_all) + + +if total_average > 1: + np.save( MAIN_EXP_folder + 'raw_counts_{:d}Averaged'.format(total_average) + EXP_TYPE + timestempID, raw_counts_sum / total_average) + np.save( MAIN_EXP_folder + 'actual_counts_{:d}Averaged'.format(total_average) + EXP_TYPE + timestempID, actual_counts_sum / total_average) + + + +# %% Completed + +# set_Bfield_Current(0, EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + + +task_count.close() + + +print("==============================") +print("ALL END. (NO ERRORS)\n") + + + +# %% END + + +plt.figure(34, figsize=[9,6], dpi=100) +plt.clf() +plt.plot(x_all * 1e3, raw_counts_sum /(ii+1), '.-b', label='avg {:}, raw counts'.format(ii+1) ) +plt.plot(x_all * 1e3, actual_counts_sum /(ii+1), '.-r', label='avg {:}, corrected'.format(ii+1) ) +plt.grid() +plt.legend(loc=1) +plt.title(exp_notes) +plt.xlabel('$\\tau$/ns') +plt.ylabel('Actual photon counts (cps)') +plt.xscale('log') +plt.tight_layout() +plt.savefig( MAIN_EXP_folder + 'plot_counts_B{:d}Gs_{:d}Averaged{:}{:}.jpg'.format(B_field, total_average, fn_suffix, timestempID) ) +plt.show() + + diff --git a/PLE/100_plot_single.py b/PLE/100_plot_single.py new file mode 100644 index 0000000..59716dd --- /dev/null +++ b/PLE/100_plot_single.py @@ -0,0 +1,95 @@ +# -*- coding: utf-8 -*- +""" +Created on Wed Feb 5 13:08:12 2025 + +@author: shen_t2 +""" + + +import os +# os.chdir(os.path.abspath(os.path.dirname(__file__))) + +import numpy as np +import matplotlib.pyplot as plt +plt.rcParams.update({'font.size': 14}) + + +# %% + +MAIN_EXP_folder = 'C:/RE_qubit_TS/20260429_CW_PLE_dilute_sample2/50_pi_test/' +# MAIN_EXP_folder = 'P:/Tianyang/Data_Thibaut_2026/20260505/03_Bfield_dependence/' +os.chdir(MAIN_EXP_folder) + +timestampsuffix = '_05051456.npy' + +# mw_scan = np.load('MWfreq_x_axis_pm100-3000MHz_per10MHz'+ timestampsuffix) +wl_scan = np.load('wl_scan_x_axis_1530.00_1530.80_speed0.0100_CWGatedD'+ timestampsuffix) + +raw_count_sum = np.zeros(len(wl_scan)) +actual_count_sum = np.zeros(len(wl_scan)) +for ii in range(1): + raw_count_rep = np.load('raw_counts_B0Gs_rep{:d}'.format(ii) + timestampsuffix) + raw_count_sum += raw_count_rep + actual_count_rep = np.load('actual_counts_B0Gs_rep{:d}'.format(ii) + timestampsuffix) + actual_count_sum += actual_count_rep + + +# actual_counts_wl = np.load('actual_counts_B0Gs_rep0_'+file_name[-12:]) +# raw_counts_wl = np.load('raw_counts_B0Gs_rep0_'+file_name[-12:]) + + +wn_scan = 1e7 / wl_scan + + +# %% + +plt.figure(100, figsize=[9,6], dpi=100) +plt.clf() +plt.plot(1e7/wl_scan, raw_count_sum, '.-b') +plt.plot(1e7/wl_scan, actual_count_sum, '.-r') +plt.grid() +plt.tight_layout() +plt.show() + + +# %% + +from scipy.optimize import curve_fit + +def _1Lorentzian(x, x_c, area, width, y_offset): +# y_c = y_offset + 2*area/width/np.pi # peak value + return ( y_offset + (2*area/np.pi)*(width/(4*(x-x_c)**2 + width**2))) + + +(popt, pcov, infodict, mesg, ier) = curve_fit(_1Lorentzian, wn_scan, actual_count_rep, + p0 = [6534.34, 1, 1, 1], + bounds = ([6534.0, 0, 0, 0], + [6535.0, np.inf, np.inf, np.inf]), + full_output=True) + + +plt.figure(200, figsize=[9,6], dpi=100) +plt.clf() + +plt.plot(wn_scan, actual_count_rep, '.-', label='experiment') +plt.plot(wn_scan, _1Lorentzian(wn_scan, *popt), '.-', label='fitting') + +plt.grid() +plt.legend(loc=1) + +plt.title('B = 0, $\\nu_c$ = {:.6f} cm-1'.format(popt[0]) ) +plt.xlabel('Recorded wavenumber (cm$^{-1}$)') +plt.ylabel('Photon Counting (cps) ') + +plt.tight_layout() +plt.show() + +print(popt[0]) # 6534.344133644639 cm-1 + + +wn_PLE_c = 6534.22767272914 # with precise fitting +wn_FTIR_c = 6534.356431 +wn_scan = 1e7 / wl_scan - wn_PLE_c + wn_FTIR_c # unit: [cm-1] + + + diff --git a/PLE/101_compare_singles.py b/PLE/101_compare_singles.py new file mode 100644 index 0000000..d04a8b6 --- /dev/null +++ b/PLE/101_compare_singles.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +""" +Created on Mon Nov 11 17:58:41 2024 + +@author: shen_t2 +""" + + +import os +os.chdir(os.path.abspath(os.path.dirname(__file__))) + +import numpy as np +import matplotlib.pyplot as plt +plt.rcParams.update({'font.size': 14}) + + +# %% + +MAIN_EXP_folder = 'C:/RE_qubit_TS/202510_T1_pair/' +os.chdir(MAIN_EXP_folder) + +speed_filename_list = ['wl_scan_x_axis_1530.00_1530.50_speed0.0030_CWGatedD_10091925.npy', + # 'wl_scan_x_axis_1530.00_1530.50_speed0.0050_CWGatedD_10091858.npy', + 'wl_scan_x_axis_1530.00_1530.50_speed0.0075_CWGatedD_10091929.npy', + 'wl_scan_x_axis_1530.00_1530.50_speed0.0100_CWGatedD_10091937.npy', + # 'wl_scan_x_axis_1530.00_1530.50_speed0.0150_CWGatedD_10091908.npy', + 'wl_scan_x_axis_1530.00_1530.50_speed0.0200_CWGatedD_10091939.npy'] + + + +# %% single axis + +plt.figure(101, figsize=[9,6], dpi=100) +plt.clf() + + +for ii, speed_filename in enumerate(speed_filename_list): + + wl_scan_all = np.load(speed_filename) + actual_counts = np.load('actual_counts_B0Gs_rep0_'+speed_filename[-12:]) + + plt.plot(wl_scan_all, actual_counts, '.-', label=speed_filename[-12:-4] ) + + +plt.grid() +plt.legend(loc=2) + +plt.title('Comparison of scan speed \n[0.0030, 0.0075, 0.0100, 0.0200 nm/s]') +plt.xlabel('Wavelength (nm)') +plt.ylabel('Photon counts (cps)') + +plt.tight_layout() +plt.savefig( MAIN_EXP_folder + '20251009_compare_scan_speed_TTL10ms.jpg' ) +plt.show() + + +# %% double axes + +# fig, ax1 = plt.subplots(num=121, figsize=[9,6], dpi=100) +# fig.suptitle('Comparison of CW PLE Gated or not [Bz = +1000 Gs, pi-excitation, OD 3.0]') + +# color = 'k' +# ax1.set_xlabel('Wavelength (nm)') +# ax1.set_ylabel('Photon counts (cps)', color=color) +# ax1.plot(CWCD_wl_scan_all, CWCD_actual_counts, '-'+color, label='CW_CD, actual' ) +# ax1.tick_params(axis='x', direction='in') +# ax1.tick_params(axis='y', direction='in', labelcolor=color) + +# ax2 = ax1.twinx() +# color = 'b' +# ax2.set_ylabel('', color=color) +# ax2.plot(CWGatedD_wl_scan_all, CWGatedD_actual_counts, '-'+color, label='CW_Gated, actual' ) +# ax2.tick_params(axis='y', direction='in', labelcolor=color) +# ax2.ticklabel_format(axis='y', style='sci', scilimits=(0,0)) + +# fig.legend(loc=2, bbox_to_anchor=(0.08, 0.88)) +# fig.tight_layout() # otherwise the right y-label is slightly clipped + +# # fig.savefig( MAIN_EXP_folder + '20241111_compare_CW_Gated_actual_dualY.jpg' ) +# plt.show() + +