Finished first version of Dasha's code

This commit is contained in:
Ryan Tan 2024-10-31 12:54:03 +01:00
parent 8ccf19b5cd
commit 912d7bc499

View File

@ -356,11 +356,11 @@ def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True
################################################################# DASHA'S CODE HERE ############################################################################################## ################################################################# DASHA'S CODE HERE ##############################################################################################
# TODO: modify b field scan script for Dasha, to be used for the KLC controller # TODO: Implementation of zerowhenfin_bool, maybe later
# NOTE: all voltage values are the RMS values, and have the unit V # NOTE: all voltage values are the RMS values, and have the unit V
def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float, def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
res:float, base_file_name='', res:float, base_file_name='', folder_name='',
reversescan_bool=False, zerowhenfin_bool=False, loopscan_bool=False)->None: reversescan_bool=False, zerowhenfin_bool=True, loopscan_bool=False)->None:
# TODO: docstring # TODO: docstring
def pyramid_list(lst) -> Union[list, np.ndarray]: def pyramid_list(lst) -> Union[list, np.ndarray]:
"""reverses the list and removes the first element of reversed list. Then, this is appended to """reverses the list and removes the first element of reversed list. Then, this is appended to
@ -412,22 +412,20 @@ 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 helper_scan_func and scanning loop below, after this, the code should be complete! # helper function for the scanning loop
# NOTE: helper function for the scanning loop def helper_scan_func(idx, voltage_val, instr=handle, sleep=0.5): # TODO: idx argument possibly redundant for Dasha's code
def helper_scan_func(idx, voltage_val, instr=handle, sleep=2): # TODO: idx argument possibly redundant for Dasha's code # TODO: docstring
# => enable V1 preset => set voltage for V1 preset # => enable V1 preset => set voltage for V1 preset
klcSetChannelEnable(handle, 1) klcSetChannelEnable(instr, 1)
# initialise actual_voltage_val variable # initialise actual_voltage_val variable
actual_voltage_val = [0] actual_voltage_val = [0]
klcGetVoltage1(handle, actual_voltage_val) klcGetVoltage1(instr, actual_voltage_val)
print(f'Actual output voltage: {actual_voltage_val[0]} V,', f'Target output voltage: {voltage_val} V') print(f'Actual output voltage: {actual_voltage_val[0]} V,', f'Target output voltage: {voltage_val} V')
klcSetVoltage1(handle, voltage_val) klcSetVoltage1(instr, voltage_val)
# TODO: change the while loop for Dasha's code!!
while abs(actual_voltage_val[0] - voltage_val) > 0.0005: # check if target voltage is reached, if not, wait while abs(actual_voltage_val[0] - voltage_val) > 0.0005: # check if target voltage is reached, if not, wait
time.sleep(sleep) # little break time.sleep(sleep) # little break
actual_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1 klcGetVoltage1(instr, actual_voltage_val) # update the actual voltage
# update the actual bval
print(f'Actual output voltage: {actual_voltage_val[0]} V,', f'Target output voltage: {voltage_val} V') print(f'Actual output voltage: {actual_voltage_val[0]} V,', f'Target output voltage: {voltage_val} V')
#scanning loop #scanning loop
@ -438,7 +436,7 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
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, sleep=2) helper_scan_func(i, bval)
time.sleep(5) time.sleep(5)
# we acquire with the LF # we acquire with the LF
@ -466,20 +464,22 @@ 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
if zerowhenfin_bool: if zerowhenfin_bool:
write_no_echo(instr, 'SWEEP ZERO') # if switched on, discharges the magnet after performing the measurement loop above klcSetVoltage1(handle, 0) # sets V1 channel voltage to 0 V
klcSetChannelEnable(handle, 0) # disables channel output
#save intensity & WL data as .txt #save intensity & WL data as .txt
os.chdir('C:/Users/localadmin/Desktop/Users/Dasha') 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')}" # TODO: add folder_name as function argument if folder_name == '':
os.mkdir(new_folder_name) folder_name = f"{datetime.datetime.now().strftime('%Y_%m_%d_%H.%M')}"
else:
folder_name = f"{datetime.datetime.now().strftime('%Y_%m_%d_%H.%M')}_" + folder_name
os.mkdir(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/Dasha/'+ new_folder_name) os.chdir('C:/Users/localadmin/Desktop/Users/Dasha/'+ 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)
@ -490,8 +490,6 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
################################################################# END OF FUNCTION DEFS ########################################################################################### ################################################################# END OF FUNCTION DEFS ###########################################################################################
# NOTE: RYAN INTRODUCED SOME FUNCTIONS HERE TO PERFORM THE SCAN
# ENTER START AND END VOLTAGES, AS WELL AS VOLTAGE STEP SIZE HERE # ENTER START AND END VOLTAGES, AS WELL AS VOLTAGE STEP SIZE HERE
start_voltage = 0 start_voltage = 0
end_voltage = 0.5 end_voltage = 0.5
@ -551,10 +549,10 @@ try:
# InitializerFilenameParams() # InitializerFilenameParams()
# TODO: insert LCR rotation scan function here # TODO: insert LCR rotation scan function here
# 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)
LCR_scan_func(handle=KLC_handle, init_voltage=start_voltage, final_voltage=end_voltage, res=voltage_stepsize,
base_file_name='Test', folder_name='Test_folder')
except Exception() as e: except Exception() as e:
print(e) print(e)