progress till reversescan_bool condition check, probs remove the init_lim and so on....most likely redundant

This commit is contained in:
Ryan Tan 2024-10-31 10:41:46 +01:00
parent 0b7e1b1b6a
commit 96405afdad

View File

@ -354,11 +354,23 @@ 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: modify b field scan script for Dasha, to be used for the KLC controller
# 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='',
reversescan_bool=False, zerowhenfin_bool=False, loopscan_bool=False)->None: reversescan_bool=False, zerowhenfin_bool=False, loopscan_bool=False)->None:
# TODO: docstring
"""_summary_
Args:
handle (int): _description_
init_voltage (float): _description_
final_voltage (float): _description_
res (float): _description_
base_file_name (str, optional): _description_. Defaults to ''.
reversescan_bool (bool, optional): _description_. Defaults to False.
zerowhenfin_bool (bool, optional): _description_. Defaults to False.
loopscan_bool (bool, optional): _description_. Defaults to False.
"""
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
the end of the original list and returned as the 'pyramid' list. the end of the original list and returned as the 'pyramid' list.
@ -385,43 +397,37 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
start_time = time.time() # start of the scan function start_time = time.time() # start of the scan function
# if '2101014' in instr_info and (magnet_coil=='y-axis'): # single power supply # Check if the given start and/or end voltages are within the accepted limits
# if (min_bval< -BY_MAX) or (max_bval > BY_MAX): if (init_voltage >= V_MAX):
# raise ValueError('Input limits exceed that of the magnet By! Please input smaller limits.') raise ValueError('Maximum device voltage exceeded! Please input a smaller initial voltage!')
# elif '2301034' in instr_info: # dual power supply elif (end_voltage >= V_MAX):
# if magnet_coil=='z-axis': # check if its the coils for Bz raise ValueError('Maximum device voltage exceeded! Please input a smaller final voltage!')
# if (min_bval < -BZ_MAX) or (max_bval > BZ_MAX): elif (res >= V_MAX):
# raise ValueError('Input limits exceed that of the magnet (Bz)! Please input smaller limits.') raise ValueError('Entered step size exceeds 25 V! Please choose a smaller step size!')
# write_no_echo(instr, 'CHAN 1')
# elif magnet_coil=='x-axis': # checks limits of Bx
# if (min_bval< -BX_MAX) or (max_bval > BX_MAX):
# raise ValueError('Input limits exceed that of the magnet Bx! Please input smaller limits.')
# write_no_echo(instr, 'CHAN 2')
# else:
# raise ConnectionError('Device is not connected!')
write_no_echo(instr, f'LLIM {min_bval*10};ULIM {max_bval*10}') # sets the given limits, must convert to kG for the device to read # creates list of voltage values to measure at, with given resolution, in V
bval_lst = np.arange(min_bval, max_bval + res, res) # creates list of B values to measure at, with given resolution, in T voltage_lst = np.arange(init_voltage, final_voltage + res, res)
# TODO: remove the two lines below, probs not needed
init_lim, subsequent_lim = 'LLIM', 'ULIM' init_lim, subsequent_lim = 'LLIM', 'ULIM'
init_sweep, subsequent_sweep = 'DOWN', 'UP' init_sweep, subsequent_sweep = 'DOWN', 'UP'
# if reverse scan, flips the direction of the scan
# if reverse scan, then flip the values in the b list, and swap the initial limit and sweep conditions
if reversescan_bool: if reversescan_bool:
bval_lst = bval_lst[::-1] voltage_lst = voltage_lst[::-1]
init_lim, subsequent_lim = subsequent_lim, init_lim init_lim, subsequent_lim = subsequent_lim, init_lim
init_sweep, subsequent_sweep = subsequent_sweep, init_sweep init_sweep, subsequent_sweep = subsequent_sweep, init_sweep
# creates the pyramid list of B vals if one were to perform a hysteresis measurement # creates the pyramid list of B vals if one were to perform a hysteresis measurement
if loopscan_bool: if loopscan_bool:
bval_lst = pyramid_list(bval_lst) voltage_lst = pyramid_list(voltage_lst)
total_points = len(bval_lst) total_points = len(voltage_lst)
middle_index_bval_lst = total_points // 2 middle_index_voltage_lst = total_points // 2
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!
# NOTE: helper function for the scanning loop # NOTE: helper function for the scanning loop
def helper_scan_func(idx, bval, instr=instr, init_lim=init_lim, init_sweep=init_sweep, def helper_scan_func(idx, bval, instr=instr, init_lim=init_lim, init_sweep=init_sweep,
subsequent_lim=subsequent_lim, subsequent_sweep=subsequent_sweep, sleep=5): subsequent_lim=subsequent_lim, subsequent_sweep=subsequent_sweep, sleep=5):
@ -442,12 +448,12 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
print(f'Actual magnet strength: {actual_bval} T,', f'Target magnet strength: {bval} T') print(f'Actual magnet strength: {actual_bval} T,', f'Target magnet strength: {bval} T')
#scanning loop #scanning loop
for i, bval in enumerate(bval_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_bval_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=instr, init_lim=subsequent_lim, init_sweep=subsequent_sweep, helper_scan_func(i, bval, instr=instr, init_lim=subsequent_lim, init_sweep=subsequent_sweep,
@ -511,11 +517,11 @@ try:
if(len(devs)<=0): if(len(devs)<=0):
print('There is no device connected') print('There is no device connected')
sys.exit() sys.exit()
klc = devs[0] klc = devs[0] # devs is a list of 2-element lists, in which the serial-nr. and device name are contained
serialnumber = klc[0] serialnumber = klc[0]
# Connect device # Connect device
KLC_handle = klcOpen(serialnumber, 115200, 3) KLC_handle = klcOpen(serialnumber, 115200, 3) # baud rate and timeout(in s)
if(KLC_handle<0): if(KLC_handle<0):
print("open ", serialnumber, " failed") print("open ", serialnumber, " failed")
sys.exit() sys.exit()