Finished first version of Dasha's code
This commit is contained in:
parent
8ccf19b5cd
commit
912d7bc499
@ -356,11 +356,11 @@ def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True
|
||||
|
||||
################################################################# 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
|
||||
def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
|
||||
res:float, base_file_name='',
|
||||
reversescan_bool=False, zerowhenfin_bool=False, loopscan_bool=False)->None:
|
||||
res:float, base_file_name='', folder_name='',
|
||||
reversescan_bool=False, zerowhenfin_bool=True, loopscan_bool=False)->None:
|
||||
# TODO: docstring
|
||||
def pyramid_list(lst) -> Union[list, np.ndarray]:
|
||||
"""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
|
||||
cwd = os.getcwd() # save original directory
|
||||
|
||||
# TODO: edit the helper_scan_func and scanning loop below, after this, the code should be complete!
|
||||
# NOTE: helper function for the scanning loop
|
||||
def helper_scan_func(idx, voltage_val, instr=handle, sleep=2): # TODO: idx argument possibly redundant for Dasha's code
|
||||
# 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
|
||||
# TODO: docstring
|
||||
# => enable V1 preset => set voltage for V1 preset
|
||||
klcSetChannelEnable(handle, 1)
|
||||
klcSetChannelEnable(instr, 1)
|
||||
# initialise actual_voltage_val variable
|
||||
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')
|
||||
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
|
||||
time.sleep(sleep) # little break
|
||||
actual_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1
|
||||
# update the actual bval
|
||||
klcGetVoltage1(instr, actual_voltage_val) # update the actual voltage
|
||||
print(f'Actual output voltage: {actual_voltage_val[0]} V,', f'Target output voltage: {voltage_val} V')
|
||||
|
||||
#scanning loop
|
||||
@ -438,7 +436,7 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
|
||||
if i <= middle_index_voltage_lst:
|
||||
helper_scan_func(i, bval)
|
||||
else:
|
||||
helper_scan_func(i, bval, instr=handle, sleep=2)
|
||||
helper_scan_func(i, bval)
|
||||
|
||||
time.sleep(5)
|
||||
# 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
|
||||
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:
|
||||
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
|
||||
os.chdir('C:/Users/localadmin/Desktop/Users/Dasha')
|
||||
# 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
|
||||
os.mkdir(new_folder_name)
|
||||
if 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 !
|
||||
# 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)
|
||||
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 ###########################################################################################
|
||||
|
||||
# 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
|
||||
@ -551,10 +549,10 @@ try:
|
||||
# InitializerFilenameParams()
|
||||
|
||||
# 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',
|
||||
# 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:
|
||||
print(e)
|
||||
|
Loading…
Reference in New Issue
Block a user