updated notes, work on the helper_scan_func

This commit is contained in:
Ryan Tan 2024-10-31 11:33:22 +01:00
parent b74152ff2c
commit 450c0d3924
2 changed files with 36 additions and 37 deletions

View File

@ -18,7 +18,9 @@ try:
except OSError as ex: except OSError as ex:
print("Warning:",ex) print("Warning:",ex)
# Maximum output voltage
V_MAX = 25 # corresponds to the max RMS voltage of 25 V of KLC101 device V_MAX = 25 # corresponds to the max RMS voltage of 25 V of KLC101 device
# NOTE: AC output of KLC101 is a square wave, RMS = Amplitude
############################################ ############################################
@ -410,39 +412,32 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
intensity_data = [] # To store data from each scan intensity_data = [] # To store data from each scan
cwd = os.getcwd() # save original directory cwd = os.getcwd() # save original directory
# TODO: edit the helpe_scan_func and scanning loop below, after this, the code should be complete! # TODO: edit the helper_scan_func and scanning loop below, after this, the code should be complete!
# possibly doesnt even need the initial and ffinal lims, no need to differentiate
# NOTE: helper function for the scanning loop # NOTE: helper function for the scanning loop
def helper_scan_func(idx, bval, instr=handle, init_lim=init_lim, init_sweep=init_sweep, def helper_scan_func(idx, voltage_val, instr=handle, sleep=2):
subsequent_lim=subsequent_lim, subsequent_sweep=subsequent_sweep, sleep=5): # TODO: remove sleep function argument
if idx == 0: # for first iteration, sweep to one of the limits # TODO: edit code block below for the LCR controller
write_no_echo(instr, f'{init_lim} {bval*10}') # convert back to kG
write_no_echo(instr, f'SWEEP {init_sweep}')
else:
write_no_echo(instr, f'{subsequent_lim} {bval*10}') # convert back to kG
write_no_echo(instr, f'SWEEP {subsequent_sweep}')
# read the actual voltage and print it out # read the actual voltage and print it out
actual_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1 # convert kG to T # actual_voltage_val = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1 # convert kG to T
print(f'Actual magnet strength: {actual_bval} T,', f'Target magnet strength: {bval} T') actual_voltage_val = [0]
while abs(actual_bval - bval) > 0.0001: # if the actual voltage print(f'Actual magnet strength: {actual_voltage_val} T,', f'Target magnet strength: {voltage_val} T')
time.sleep(5) # little break
while abs(actual_voltage_val - voltage_val) > 0.0001: # if the actual voltage is not reached, keep
time.sleep(sleep) # little break
actual_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1 actual_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1
# update the actual bval # update the actual bval
print(f'Actual magnet strength: {actual_bval} T,', f'Target magnet strength: {bval} T') print(f'Actual magnet strength: {actual_voltage_val} T,', f'Target magnet strength: {voltage_val} T')
#scanning loop #scanning loop
for i, bval in enumerate(voltage_lst): for i, bval in enumerate(voltage_lst):
if not loopscan_bool: if not loopscan_bool:
helper_scan_func(i, bval) helper_scan_func(i, bval)
else: else:
if i <= middle_index_voltage_lst: if i <= middle_index_voltage_lst:
helper_scan_func(i, bval) helper_scan_func(i, bval)
else: else:
helper_scan_func(i, bval, instr=handle, init_lim=subsequent_lim, init_sweep=subsequent_sweep, helper_scan_func(i, bval, instr=handle, sleep=2)
subsequent_lim=init_lim, subsequent_sweep=init_sweep, sleep=5)
time.sleep(5) time.sleep(5)
# we acquire with the LF # we acquire with the LF
@ -470,19 +465,20 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
elapsed_time = (end_time - start_time) / 60 elapsed_time = (end_time - start_time) / 60
print('Scan time: ', elapsed_time, 'minutes') print('Scan time: ', elapsed_time, 'minutes')
# TODO: check all file paths if they are correct for Dasha
write_no_echo(instr, f'LLIM {instr_bsettings[1][0]*10};ULIM {instr_bsettings[2][0]*10}') # reset the initial limits of the device after the scan write_no_echo(instr, f'LLIM {instr_bsettings[1][0]*10};ULIM {instr_bsettings[2][0]*10}') # reset the initial limits of the device after the scan
if zerowhenfin_bool: if zerowhenfin_bool:
write_no_echo(instr, 'SWEEP ZERO') # if switched on, discharges the magnet after performing the measurement loop above write_no_echo(instr, 'SWEEP ZERO') # if switched on, discharges the magnet after performing the measurement loop above
#save intensity & WL data as .txt #save intensity & WL data as .txt
os.chdir('C:/Users/localadmin/Desktop/Users/Lukas') os.chdir('C:/Users/localadmin/Desktop/Users/Dasha')
# creates new folder for MAP data # creates new folder for MAP data
new_folder_name = "Test_Map_" + f"{datetime.datetime.now().strftime('%Y_%m_%d_%H.%M')}" new_folder_name = "Test_Map_" + f"{datetime.datetime.now().strftime('%Y_%m_%d_%H.%M')}" # TODO: add folder_name as function argument
os.mkdir(new_folder_name) os.mkdir(new_folder_name)
# Here the things will be saved in a new folder under user Lukas ! # Here the things will be saved in a new folder under user Lukas !
# IMPORTANT last / has to be there, otherwise data cannot be saved and will be lost!!!!!!!!!!!!!!!! # IMPORTANT last / has to be there, otherwise data cannot be saved and will be lost!!!!!!!!!!!!!!!!
os.chdir('C:/Users/localadmin/Desktop/Users/Lukas/'+ new_folder_name) os.chdir('C:/Users/localadmin/Desktop/Users/Dasha/'+ new_folder_name)
intensity_data = np.array(intensity_data) intensity_data = np.array(intensity_data)
np.savetxt(base_file_name + '.txt', intensity_data) np.savetxt(base_file_name + '.txt', intensity_data)
@ -491,9 +487,20 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
np.savetxt("Wavelength.txt", wl) np.savetxt("Wavelength.txt", wl)
################################################################# END OF FUNCTION DEFS ########################################################################################### ################################################################# END OF FUNCTION DEFS ###########################################################################################
# NOTE: RYAN INTRODUCED SOME FUNCTIONS HERE TO PERFORM THE SCAN # NOTE: RYAN INTRODUCED SOME FUNCTIONS HERE TO PERFORM THE SCAN
# ENTER START AND END VOLTAGES, AS WELL AS VOLTAGE STEP SIZE HERE
start_voltage = 0
end_voltage = 0.5
voltage_stepsize = 0.25
#Here you can specify the filename of the map e.g. put experiment type, exposure time, used filters, etc....
experiment_settings = 'PL_SP_700_LP_700_HeNe_52muW_exp_2s_Start_'
#The program adds the range of the scan as well as the resolution and the date and time of the measurement
experiment_name = f"{start_voltage}V_to_{end_voltage}V_{voltage_stepsize}V_{datetime.datetime.now().strftime('%Y_%m_%d_%H%M')}"
try: try:
# initialise KLC connection # initialise KLC connection
# Find devices # Find devices
@ -539,21 +546,10 @@ try:
experiment.Load("Alison_08.07.24") # NOTE: this should be the experiment.Load("Alison_08.07.24") # NOTE: this should be the
experiment.ExperimentCompleted += experiment_completed # we are hooking a listener. experiment.ExperimentCompleted += experiment_completed # we are hooking a listener.
# experiment.SetValue(SpectrometerSettings.GratingSelected, '[750nm,1200][0][0]') # experiment.SetValue(SpectrometerSettings.GratingSelected, '[750nm,1200][0][0]') # TODO: find out what these two lines of code do, leave commented as of (31.10.2024)
# InitializerFilenameParams() # InitializerFilenameParams()
# ENTER START AND END VOLTAGES, AS WELL AS VOLTAGE STEP SIZE HERE
start_voltage = 0
end_voltage = 0.5
voltage_stepsize = 0.25
#Here you can specify the filename of the map e.g. put experiment type, exposure time, used filters, etc....
experiment_settings = 'PL_SP_700_LP_700_HeNe_52muW_exp_2s_Start_'
#The program adds the range of the scan as well as the resolution and the date and time of the measurement
experiment_name = f"{start_voltage}V_to_{end_voltage}V_{voltage_stepsize}V_{datetime.datetime.now().strftime('%Y_%m_%d_%H%M')}"
# TODO: insert LCR rotation scan function here # TODO: insert LCR rotation scan function here
# use this reference code for the LCR scan later on # use this reference code for the LCR scan later on
# sweep_b_val(powerbox_dualsupply, set_llim_bval, set_ulim_bval, set_res_bval, 'z-axis', # sweep_b_val(powerbox_dualsupply, set_llim_bval, set_ulim_bval, set_res_bval, 'z-axis',
# experiment_settings, base_file_name=experiment_name, zerowhenfin_bool=True, reversescan_bool=False) # experiment_settings, base_file_name=experiment_name, zerowhenfin_bool=True, reversescan_bool=False)

View File

@ -1,4 +1,7 @@
For the code to work, change the directory to load the KLCCommandLib_x64.dll file in 'KLCCommandLib64.py', line 5. 1. For the code to work, change the directory to load the KLCCommandLib_x64.dll file in 'KLCCommandLib64.py', line 5.
The line of code is as follows: The line of code is as follows:
klcLib=cdll.LoadLibrary(r"C:\Users\rtan\Documents\RyanWork2024\Dasha-LCR_Code\Thorlabs_KLC_PythonSDK\"KLCCommandLib_x64.dll") klcLib=cdll.LoadLibrary(r"C:\Users\rtan\Documents\RyanWork2024\Dasha-LCR_Code\Thorlabs_KLC_PythonSDK\"KLCCommandLib_x64.dll")
2. Another issue is then importing the other needed folders, probs have to have all the required files in the same scan
script folder on the offline computer.