280 lines
8.8 KiB
Python
280 lines
8.8 KiB
Python
# -*- 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()
|
|
|