commit fc35f59a4a6d73800ebb40a10d8b881f86fdcea6 Author: shen_t2 Date: Wed Jun 3 12:08:45 2026 +0200 Upload files to "PLE" diff --git a/PLE/010_CW_PLE_CD.py b/PLE/010_CW_PLE_CD.py new file mode 100644 index 0000000..7226827 --- /dev/null +++ b/PLE/010_CW_PLE_CD.py @@ -0,0 +1,230 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Nov 7 15:38:33 2024 + +@author: shen_t2 +""" + + +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 ext_samp_clk_trig_count_task, gen_trig_src_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 = "_CWCD" + + +# %% Experiment parameters + + +from Global_Experiment_Parameters import * + +MAIN_EXP_folder = 'C:/RE_qubit_TS/202411_CW_PLE_3_g/{:}{:}_BzScan_auto_{:}_{:}/'.format(now.strftime("%Y%m%d"), EXP_TYPE, laser_pol, ODFilter) +# os.chdir(MAIN_EXP_folder) + + +total_average = 1 + + +EMagnet_poles_gap = "small" # "small" or "large" +Bext_field_scan_positive = np.concatenate((np.arange(50, 2000, 50), + np.arange(2000, 3000, 200), + np.arange(3000, 5000, 500), + np.arange(5000, 8000, 1000))) +Bext_field_scan = np.concatenate( ( -Bext_field_scan_positive[::-1], + np.array([0]), + Bext_field_scan_positive ) ) # Gauss, always keep increasing (from - to +) + + +wide_scan_output_channel = 79 # 50 = piezo V // 79 = CTL wl // +# wide_scan_start_wl = 1530.00 # nm +wide_scan_trigger_threshold = 1530.00 # nm +wide_scan_end_wl = 1530.40 # nm +wide_scan_speed = 0.0010 # nm/s + +wide_scan_start_wl = wide_scan_trigger_threshold - 15 * wide_scan_speed + + +DAQ_counting_time = 0.1 # s + +DAQ_counting_rate = 1 / DAQ_counting_time # Hz +DAQ_record_time_est = (wide_scan_end_wl - wide_scan_trigger_threshold) / wide_scan_speed # s +DAQ_samps_per_chan = int(DAQ_record_time_est / DAQ_counting_time) +# DAQ_loop_per_chan = 3 + + +SAPD_dead_time = 15 * 1e-6 # s + + + +# %% Devices initialization + +EMagnet_PowerSupply = PowerSupplyCaylarLib.CaylarPowerSupply(2) +EMagnet_connect_test(EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + + +###################################### + +dlcpro = set_widescan_para(Laser_DLCPRO_IP, + wide_scan_output_channel, + wide_scan_start_wl, + wide_scan_end_wl, + wide_scan_speed, + wide_scan_trigger_threshold) + +dlcpro.open() +print("Wide Scan Status:", dlcpro.laser1.wide_scan.state.get(), dlcpro.laser1.wide_scan.state_txt.get()) + + +###################################### + +try: + task_count.close() + task_clock.close() +except: + pass +finally: + print("------------------------------") + print("Tasks have been cleared.\n") + + +task_count = ext_samp_clk_trig_count_task(DAQ_counting_rate, DAQ_samps_per_chan) +task_clock = gen_trig_src_task(DAQ_counting_rate) + + + + +# %% 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") + + +wl_x_axis = np.linspace(wide_scan_trigger_threshold, wide_scan_end_wl, DAQ_samps_per_chan) +np.save( MAIN_EXP_folder + 'wl_scan_x_axis_{:.2f}_{:.2f}_speed{:.4f}'.format(wide_scan_trigger_threshold, wide_scan_end_wl, wide_scan_speed) + timestempID, + wl_x_axis[1:]) + +np.save( MAIN_EXP_folder + 'wl_scan_Bfields' + timestempID, Bext_field_scan) + + + +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 + + + 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) + dlcpro.laser1.wide_scan.start() + + task_clock.start() + task_count.start() + + print("------------------------------") + print("Start: Exp. {} Gs, Loop {}.".format(B_field, ii)) + + raw_counts_accumulated = task_count.read(nidaqmx.constants.READ_ALL_AVAILABLE, nidaqmx.constants.WAIT_INFINITELY) + + if len(raw_counts_accumulated) == DAQ_samps_per_chan: + # print("------------------------------") + print("End: no errors.") + + + task_count.stop() + task_clock.stop() + + + + # Data processing and saving + + raw_counts_accumulated = np.array(raw_counts_accumulated) + raw_counts = raw_counts_accumulated[1:] - raw_counts_accumulated[:-1] + np.save( MAIN_EXP_folder + 'raw_counts_B{:d}Gs_rep{:d}'.format(B_field, ii) + 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) + timestempID, actual_counts) + print("Data saved.") + + raw_counts_all.append(raw_counts) + + + ####################################### + # real-time plot + plt.figure(1, figsize=[9,6], dpi=100) + plt.clf() + plt.plot(wl_x_axis[1:], actual_counts, '-r', label='loop {:}'.format(ii) ) + plt.grid() + plt.legend(loc=1) + # plt.title(plot_title) + plt.xlabel('Wavelength (nm)') + 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, timestempID) ) + plt.show() + plt.pause(0.1) + + + raw_counts_all = np.array(raw_counts_all) + np.save( MAIN_EXP_folder + 'raw_counts_All_Bfields_rep{:d}'.format(ii) + 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) + timestempID, actual_counts_all) + + + +# %% Completed + +set_Bfield_Current(0, EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + +dlcpro.laser1.wide_scan.trigger.output_enabled.set(False) +dlcpro.close() + +task_count.close() +task_clock.close() + + +print("==============================") +print("ALL END. (NO ERRORS)\n") + + + +# %% END + + diff --git a/PLE/020_CW_PLE_GatedDetect_FastTest.py b/PLE/020_CW_PLE_GatedDetect_FastTest.py new file mode 100644 index 0000000..a54fb4a --- /dev/null +++ b/PLE/020_CW_PLE_GatedDetect_FastTest.py @@ -0,0 +1,359 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Nov 7 15:38:33 2024 + +@author: shen_t2 +""" + + +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 pulse_gated_count_task, gen_trig_src_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 = "_CWGatedD" + + +# %% Experiment parameters + +from Global_Experiment_Parameters import * + +exp_notes = 'laser {:d} mA (w/o EOM), {:}, {:},\n+{:d} Gs, sample{:}, {:}'.format(laser_current, ODFilter, laser_pol, Bext_field_scan[0], sample, Temp_info) +# exp_notes += '\nmotor = 1530.38 nm' +exp_notes += '\npiezo = 60 V' +# exp_notes += '\nEOM: 1.5 GHz, bias AUTO (Not Inv. & QUAD-)' +MAIN_EXP_folder = 'C:/RE_qubit_TS/20260529_PLE_SNSPD/02_PLE_SNSPD/' +# exp_notes = 'laser {:d} mA (with 1600 MHz EOM), {:}, {:},\n+{:d} Gs, sample{:}, {:}'.format(laser_current, ODFilter, laser_pol, Bext_field_scan[0], sample, Temp_info) +# MAIN_EXP_folder = 'P:/Tianyang/Data_Thibaut_2026/20260527/02_SPD/' + +# os.chdir(MAIN_EXP_folder) + + +total_average = 1 + + +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 + + +wide_scan_output_channel = 79 # 50 = piezo V // 79 = CTL wl // +# wide_scan_start_wl = 1530.0 # nm +wide_scan_trigger_threshold = 1530.00 # nm +wide_scan_end_wl = 1530.800 # nm +wide_scan_speed = 0.0200/2 # nm/s + + +# wide_scan_output_channel = 50 # 50 = piezo V // 79 = CTL wl // +# # wide_scan_start_wl = 0 # V +# wide_scan_trigger_threshold = 20 # V +# wide_scan_end_wl = 130 # V +# wide_scan_speed = 2/2 # V/s + + +wide_scan_start_wl = wide_scan_trigger_threshold - 15 * wide_scan_speed +if wide_scan_output_channel == 50: + wide_scan_start_wl = wide_scan_trigger_threshold - 2 * wide_scan_speed + wide_scan_start_wl = max(5, wide_scan_start_wl) + + +AOM_ON_time = 0.010 # s +DAQ_counting_time = 0.010 # s + +DAQ_counting_rate = 1 / (AOM_ON_time + DAQ_counting_time) # Hz +DAQ_record_time_est = (wide_scan_end_wl - wide_scan_trigger_threshold) / wide_scan_speed # s +DAQ_samps_per_chan = int(DAQ_record_time_est * DAQ_counting_rate) +# DAQ_loop_per_chan = 3 + + + +# %% Devices initialization + +# EMagnet_PowerSupply = PowerSupplyCaylarLib.CaylarPowerSupply(2) +# EMagnet_connect_test(EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + + +###################################### + +dlcpro = set_widescan_para(Laser_DLCPRO_IP, + wide_scan_output_channel, + wide_scan_start_wl, + wide_scan_end_wl, + wide_scan_speed, + wide_scan_trigger_threshold) + +dlcpro.open() +print("Wide Scan Status:", dlcpro.laser1.wide_scan.state.get(), dlcpro.laser1.wide_scan.state_txt.get()) + + +###################################### + +try: + task_count.close() + task_clock.close() +except: + pass +finally: + print("------------------------------") + print("Tasks have been cleared.\n") + + +task_count = pulse_gated_count_task(DAQ_samps_per_chan) +task_clock = gen_trig_src_task(DAQ_counting_rate, + pulse_duty_cycle = AOM_ON_time * DAQ_counting_rate) + + + +# %% 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") + + +wl_x_axis = np.linspace(wide_scan_trigger_threshold, wide_scan_end_wl, DAQ_samps_per_chan) +np.save( MAIN_EXP_folder + 'wl_scan_x_axis_{:.2f}_{:.2f}_speed{:.4f}'.format(wide_scan_trigger_threshold, wide_scan_end_wl, wide_scan_speed) + EXP_TYPE + timestempID, + wl_x_axis) + +# np.save( MAIN_EXP_folder + 'wl_scan_Bfields' + timestempID, Bext_field_scan) + + + +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) + dlcpro.laser1.wide_scan.start() + + task_clock.start() + task_count.start() + + print("------------------------------") + print("Start: Exp. {} Gs, Loop {}.".format(B_field, ii)) + + 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() + task_clock.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) + 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) + timestempID, actual_counts) + print("Data saved.") + + raw_counts_all.append(raw_counts) + + + ####################################### + # real-time plot + + # plt.figure(20, 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) + # if wide_scan_output_channel == 79: + # plt.xlabel('Wavelength (nm)') + # if wide_scan_output_channel == 50: + # plt.xlabel('Piezo Voltage (V)') + # plt.ylabel('Actual photon counts (cps)') + # plt.savefig( MAIN_EXP_folder + 'plot_counts_B{:d}Gs_rep{:d}{:}.jpg'.format(B_field, ii, timestempID) ) + # plt.show() + # plt.pause(0.1) + + + fig, ax1 = plt.subplots(num=20, figsize=[9,6], dpi=100) + fig.clf() + fig, ax1 = plt.subplots(num=20, figsize=[9,6], dpi=100) + fig.suptitle(exp_notes) + + if wide_scan_output_channel == 79: + ax1.set_xlabel('Wavelength (nm)') + if wide_scan_output_channel == 50: + ax1.set_xlabel('Piezo Voltage (V)') + + color = 'r' + ax1.set_ylabel('Actual photon counts (cps)', color=color) + ax1.plot(wl_x_axis, actual_counts, '.-'+color, label='loop {:}, corrected'.format(ii) ) + ax1.tick_params(axis='x', direction='in') + ax1.tick_params(axis='y', direction='in', labelcolor=color) + + ax2 = ax1.twinx() + color = 'y' + ax2.set_ylabel('Counts in {:.0f} ms detection window'.format(DAQ_counting_time*1e3), color=color) + ax2.plot(wl_x_axis, raw_counts, '.'+color, label='loop {:}, raw counts'.format(ii) ) + ax2.tick_params(axis='y', direction='in', labelcolor=color) + # ax2.ticklabel_format(axis='y', style='sci', scilimits=(0,0)) + + fig.legend(loc=1) + fig.tight_layout() # otherwise the right y-label is slightly clipped + + fig.savefig( MAIN_EXP_folder + 'plot_counts_B{:d}Gs_rep{:d}{:}.jpg'.format(B_field, ii, 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) + 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) + timestempID, actual_counts_all) + + + +# %% Completed + +# set_Bfield_Current(0, EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + +dlcpro.laser1.wide_scan.trigger.output_enabled.set(False) +dlcpro.close() + +task_count.close() +task_clock.close() + + +print("==============================") +print("ALL END. (NO ERRORS)\n") + + + +# %% single axis plot + + +# plt.figure(20-1, 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) +# if wide_scan_output_channel == 79: +# plt.xlabel('Wavelength (nm)') +# if wide_scan_output_channel == 50: +# plt.xlabel('Piezo Voltage (V)') +# plt.ylabel('Actual photon counts (cps)') +# fig.tight_layout() +# # plt.savefig( MAIN_EXP_folder + 'plot_counts_B{:d}Gs_rep{:d}{:}.jpg'.format(B_field, ii, timestempID) ) +# plt.show() + + + +# %% double axes plot + + +# try: +# fig.clf() +# except: +# pass +# finally: +# fig, ax1 = plt.subplots(num=20, figsize=[9,6], dpi=100) +# fig.suptitle(exp_notes) + +# if wide_scan_output_channel == 79: +# ax1.set_xlabel('Wavelength (nm)') +# if wide_scan_output_channel == 50: +# ax1.set_xlabel('Piezo Voltage (V)') + +# color = 'r' +# ax1.set_ylabel('Actual photon counts (cps)', color=color) +# ax1.plot(wl_x_axis, actual_counts, '.-'+color, label='loop {:}, corrected'.format(ii) ) +# ax1.tick_params(axis='x', direction='in') +# ax1.tick_params(axis='y', direction='in', labelcolor=color) + +# ax2 = ax1.twinx() +# color = 'y' +# ax2.set_ylabel('Counts in {:.0f} ms detection window'.format(DAQ_counting_time*1e3), color=color) +# ax2.plot(wl_x_axis, raw_counts, '.'+color, label='loop {:}, raw counts'.format(ii) ) +# ax2.tick_params(axis='y', direction='in', labelcolor=color) +# # ax2.ticklabel_format(axis='y', style='sci', scilimits=(0,0)) + +# fig.legend(loc=1) +# fig.tight_layout() # otherwise the right y-label is slightly clipped + +# fig.savefig( MAIN_EXP_folder + 'plot_counts_B{:d}Gs_rep{:d}{:}.jpg'.format(B_field, ii, timestempID) ) +# plt.show() +# plt.pause(0.1) + + + +# %% 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/021_CW_PLE_GatedDetect_scanBfield.py b/PLE/021_CW_PLE_GatedDetect_scanBfield.py new file mode 100644 index 0000000..240d2d3 --- /dev/null +++ b/PLE/021_CW_PLE_GatedDetect_scanBfield.py @@ -0,0 +1,268 @@ +# -*- coding: utf-8 -*- +""" +Created on Thu Nov 7 15:38:33 2024 + +@author: shen_t2 +""" + + +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 pulse_gated_count_task, gen_trig_src_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 = "_CWGatedD" + + +# %% Experiment parameters + +from Global_Experiment_Parameters import * + +exp_notes = 'laser {:d} mA (w/o EOM), {:}, {:},\ndiff. Gs, sample{:}, {:}'.format(laser_current, ODFilter, laser_pol, sample, Temp_info) +exp_notes += '\nPiezo = 60V' +MAIN_EXP_folder = 'P:/Tianyang/Data_Thibaut_2026/20260505/03_Bfield_dependence/' +# os.chdir(MAIN_EXP_folder) + + +total_average = 1 + + +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 + + +Bext_field_scan = np.concatenate((np.arange(-500, 600, 10), + np.arange(600, 2020, 20))) # Gauss, always keep increasing (from - to +) +Bext_field_scan = np.arange(-500, 2600, 50) +# Bext_field_scan = [+1000] + + +wide_scan_output_channel = 79 # 50 = piezo V // 79 = CTL wl // +# wide_scan_start_wl = 1530.0 # nm +wide_scan_trigger_threshold = 1530.00 # nm +wide_scan_end_wl = 1530.80 # nm +wide_scan_speed = 0.0200/2 # nm/s + + +# wide_scan_output_channel = 50 # 50 = piezo V // 79 = CTL wl // +# # wide_scan_start_wl = 0 # V +# wide_scan_trigger_threshold = 20 # V +# wide_scan_end_wl = 130 # V +# wide_scan_speed = 1/2 # V/s + + +wide_scan_start_wl = wide_scan_trigger_threshold - 15 * wide_scan_speed +if wide_scan_output_channel == 50: + wide_scan_start_wl = wide_scan_trigger_threshold - 2 * wide_scan_speed + wide_scan_start_wl = max(5, wide_scan_start_wl) + + +AOM_ON_time = 0.010 # s +DAQ_counting_time = 0.010 # s + +DAQ_counting_rate = 1 / (AOM_ON_time + DAQ_counting_time) # Hz +DAQ_record_time_est = (wide_scan_end_wl - wide_scan_trigger_threshold) / wide_scan_speed # s +DAQ_samps_per_chan = int(DAQ_record_time_est * DAQ_counting_rate) +# DAQ_loop_per_chan = 3 + + + +# %% Devices initialization + +EMagnet_PowerSupply = PowerSupplyCaylarLib.CaylarPowerSupply(2) +EMagnet_connect_test(EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + + +###################################### + +dlcpro = set_widescan_para(Laser_DLCPRO_IP, + wide_scan_output_channel, + wide_scan_start_wl, + wide_scan_end_wl, + wide_scan_speed, + wide_scan_trigger_threshold) + +dlcpro.open() +print("Wide Scan Status:", dlcpro.laser1.wide_scan.state.get(), dlcpro.laser1.wide_scan.state_txt.get()) + + +###################################### + +try: + task_count.close() + task_clock.close() +except: + pass +finally: + print("------------------------------") + print("Tasks have been cleared.\n") + + +task_count = pulse_gated_count_task(DAQ_samps_per_chan) +task_clock = gen_trig_src_task(DAQ_counting_rate, + pulse_duty_cycle = AOM_ON_time * DAQ_counting_rate) + + + +# %% 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") + + +wl_x_axis = np.linspace(wide_scan_trigger_threshold, wide_scan_end_wl, DAQ_samps_per_chan) +np.save( MAIN_EXP_folder + 'wl_scan_x_axis_{:.2f}_{:.2f}_speed{:.4f}'.format(wide_scan_trigger_threshold, wide_scan_end_wl, wide_scan_speed) + EXP_TYPE + timestempID, + wl_x_axis) + +np.save( MAIN_EXP_folder + 'wl_scan_Bfields' + timestempID, Bext_field_scan) + + + +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) + dlcpro.laser1.wide_scan.start() + + task_clock.start() + task_count.start() + + print("------------------------------") + print("Start: Exp. {} Gs, Loop {}.".format(B_field, ii)) + + 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() + task_clock.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) + 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) + timestempID, actual_counts) + print("Data saved.") + + raw_counts_all.append(raw_counts) + + + ####################################### + # real-time plot + plt.figure(21, 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) + if wide_scan_output_channel == 79: + plt.xlabel('Wavelength (nm)') + if wide_scan_output_channel == 50: + plt.xlabel('Piezo Voltage (V)') + 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, timestempID) ) + plt.show() + plt.pause(0.1) + + + raw_counts_all = np.array(raw_counts_all) + np.save( MAIN_EXP_folder + 'raw_counts_All_Bfields_rep{:d}'.format(ii) + 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) + timestempID, actual_counts_all) + + + +# %% Completed + +set_Bfield_Current(0, EMagnet_PowerSupply, EMagnet_PSUPPLY_IP, EMagnet_PSUPPLY_PORT) + +dlcpro.laser1.wide_scan.trigger.output_enabled.set(False) +dlcpro.close() + +task_count.close() +task_clock.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/030_Pulse_PLE_GatedDetect.py b/PLE/030_Pulse_PLE_GatedDetect.py new file mode 100644 index 0000000..ebb75e9 --- /dev/null +++ b/PLE/030_Pulse_PLE_GatedDetect.py @@ -0,0 +1,279 @@ +# -*- 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 = "_PulsePLE" + + +# %% 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 = 1 + + +freq_init = 150.0 # in [MHz] +freq_final = 3000.0 +freq_step = 10.0 +freq_list = np.linspace(freq_init, freq_final, int((freq_final-freq_init)/freq_step)+1) +x_all = freq_list +x_all = -freq_list[::-1] +x_all = np.concatenate( ( -freq_list[::-1], freq_list ) ) + +# x_all = freq_list +DAQ_samps_per_chan = len(x_all) +# DAQ_loop_per_chan = 3 + + +AOM_ON_time = 10e-3 # s +DAQ_counting_time = 10e-3 # s + + + +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 += '\nExcitation pulse = {:.1f} ms, DAQ counting window = {:.0f} ms'.format(AOM_ON_time*1e3, DAQ_counting_time*1e3) +exp_notes += '\nCavity length piezo = 0.0 V, PDH lock to 48.28 V, as single ion 0-0, IQ delay -750ps' + + +MAIN_EXP_folder = 'C:/RE_qubit_TS/202512_pulse_PLE/03_pulse_PLE_25GHz/high_detuning/' +MAIN_EXP_folder = 'P:/Tianyang/Data_Thibaut_2026/20260331/03_pulse_PLE/' +# 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 + 'MWfreq_x_axis_pm{:.0f}-{:.0f}MHz_per{:.0f}MHz'.format(freq_init, freq_final, freq_step) + 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) + 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) + 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(30, figsize=[9,6], dpi=100) + # plt.clf() + # plt.plot(x_all, raw_counts, '.-b', label='loop {:}, raw counts'.format(ii) ) + # plt.plot(x_all, actual_counts, '.-r', label='loop {:}, corrected'.format(ii) ) + # plt.grid() + # plt.legend(loc=1) + # plt.title(exp_notes) + # plt.xlabel('Laser detuning (MHz)') + # 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, timestempID) ) + # plt.show() + # plt.pause(0.1) + + + fig, ax1 = plt.subplots(num=30, figsize=[9,6], dpi=100) + fig.clf() + fig, ax1 = plt.subplots(num=30, figsize=[9,6], dpi=100) + fig.suptitle(exp_notes) + + ax1.set_xlabel('Laser detuning (MHz)') + + color = 'r' + ax1.set_ylabel('Actual photon counts (cps)', color=color) + ax1.plot(x_all, actual_counts, '.-'+color, label='loop {:}, corrected'.format(ii) ) + ax1.tick_params(axis='x', direction='in') + ax1.tick_params(axis='y', direction='in', labelcolor=color) + + ax2 = ax1.twinx() + color = 'y' + ax2.set_ylabel('Counts in {:.0f} ms detection window'.format(DAQ_counting_time*1e3), color=color) + ax2.plot(x_all, raw_counts, '.'+color, label='loop {:}, raw counts'.format(ii) ) + ax2.tick_params(axis='y', direction='in', labelcolor=color) + # ax2.ticklabel_format(axis='y', style='sci', scilimits=(0,0)) + + fig.legend(loc=1) + fig.tight_layout() # otherwise the right y-label is slightly clipped + + fig.savefig( MAIN_EXP_folder + 'plot_counts_B{:d}Gs_rep{:d}{:}.jpg'.format(B_field, ii, 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) + 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) + 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(30, figsize=[9,6], dpi=100) +# plt.clf() +# plt.plot(-x_all, actual_counts, '.-b', label='inverse x') +# plt.plot(x_all, actual_counts, '.-r', label='loop {:}, corrected'.format(ii) ) +# plt.grid() +# plt.legend(loc=1) +# plt.title(exp_notes) +# plt.xlabel('Laser detuning (MHz)') +# plt.ylabel('Actual photon counts (cps)') +# # plt.xlim(0, ) +# plt.tight_layout() +# # plt.savefig( MAIN_EXP_folder + 'plot_counts_B{:d}Gs_rep{:d}{:}_inversex.jpg'.format(B_field, ii, timestempID) ) +# plt.show() + diff --git a/PLE/031_Pulse_T1.py b/PLE/031_Pulse_T1.py new file mode 100644 index 0000000..e234a1d --- /dev/null +++ b/PLE/031_Pulse_T1.py @@ -0,0 +1,280 @@ +# -*- 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_T1" + + +# %% 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 detection delay time after excitation pulse +time_init = 0 # in [us] +time_final = 180 * 1e3 +time_step = 3 * 1e3 +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 = 10e-3#1e-6#30e-3 # s +DAQ_counting_time = 3e-3 # s +resonance_freq = -1550 # 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 += '\nExcitation pulse = {:.1f} ms, DAQ counting window = {:.0f} ms'.format(AOM_ON_time*1e3, DAQ_counting_time*1e3) +exp_notes += '\nCavity length piezo = 0.0 V, PDH lock to 58.87 V, as single ion 0-0' +exp_notes += '\nResonance frequency = {:.0f} MHz'.format(resonance_freq) +# exp_notes += '\nwithout EOM, laser directly set to its transition line' + +fn_suffix = '_exc{:.0f}ms_count{:.0f}ms'.format(AOM_ON_time*1e3, DAQ_counting_time*1e3) + +MAIN_EXP_folder = 'C:/RE_qubit_TS/202511_dilute_sample2/TEST02/'.format(ODFilter) +MAIN_EXP_folder = 'P:/Tianyang/Data_Thibaut_2026/20260331/04_pulse_T1/' +# MAIN_EXP_folder = 'C:/RE_qubit_TS/202503_Pulse_echo_sample2/02_thicker_Cu_plate/61_left3_left_splitting/run9_avg{:d}_exc{:.0f}ns_noEOM/'.format(total_average, AOM_ON_time*1e9) +# 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 + 'detection_delay_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(31, 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('Detection delay 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) + + + fig, ax1 = plt.subplots(num=31, figsize=[9,6], dpi=100) + fig.clf() + fig, ax1 = plt.subplots(num=31, figsize=[9,6], dpi=100) + fig.suptitle(exp_notes) + + ax1.set_xlabel('Detection delay time (ms)') + + color = 'r' + ax1.set_ylabel('Actual photon counts (cps)', color=color) + ax1.plot(x_all * 1e-3, actual_counts_sum /(ii+1), '.-'+color, label='avg {:}, corrected'.format(ii+1) ) + ax1.tick_params(axis='x', direction='in') + ax1.tick_params(axis='y', direction='in', labelcolor=color) + + ax2 = ax1.twinx() + color = 'y' + ax2.set_ylabel('Counts in {:.0f} ms detection window'.format(DAQ_counting_time*1e3), color=color) + ax2.plot(x_all * 1e-3, raw_counts_sum /(ii+1), '.-'+color, label='avg {:}, raw counts'.format(ii+1) ) + ax2.tick_params(axis='y', direction='in', labelcolor=color) + # ax2.ticklabel_format(axis='y', style='sci', scilimits=(0,0)) + + fig.legend(loc=1) + fig.tight_layout() # otherwise the right y-label is slightly clipped + + fig.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(31-1, 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('Detection delay time/ms') +# plt.ylabel('Actual photon counts (cps)') +# plt.tight_layout() +# plt.show() + +