upper limit of Babs check in b_field_rotation added

This commit is contained in:
ryantan 2025-04-15 15:23:42 +02:00
parent bcf86c4d70
commit 28263aaefb

View File

@ -779,6 +779,8 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
# TODO: possibly rename instr1 and instr2 to the dual and single power supplies respectively?? # TODO: possibly rename instr1 and instr2 to the dual and single power supplies respectively??
# TODO: add logging to the script # TODO: add logging to the script
# TODO: add check if Babs is within the limits of the power supply, and if not, raise an error
# defines the folder, in which the data from the spectrometer is temporarily stored in # defines the folder, in which the data from the spectrometer is temporarily stored in
temp_folder_path = "C:/Users/localadmin/Desktop/Users/Lukas/B_Field_Dump" temp_folder_path = "C:/Users/localadmin/Desktop/Users/Lukas/B_Field_Dump"
@ -838,8 +840,11 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
write_no_echo(instr1, f'RATE 0 {min_range_lst[0]};RATE 1 {min_range_lst[1]}') write_no_echo(instr1, f'RATE 0 {min_range_lst[0]};RATE 1 {min_range_lst[1]}')
write_no_echo(instr2, f'RATE 0 {min_range_lst[0]};RATE 1 {min_range_lst[1]}') write_no_echo(instr2, f'RATE 0 {min_range_lst[0]};RATE 1 {min_range_lst[1]}')
if Babs <= BX_MAX:
write_no_echo(instr1, f'CHAN 2;ULIM {Babs*10};SWEEP UP') # sets to B_x, the B_x upper limit and sweeps the magnet field to the upper limit write_no_echo(instr1, f'CHAN 2;ULIM {Babs*10};SWEEP UP') # sets to B_x, the B_x upper limit and sweeps the magnet field to the upper limit
print(f'SWEEPING B-X TO {Babs} T NOW') print(f'SWEEPING B-X TO {Babs} T NOW')
else:
raise ValueError(f'{Babs=}T value exceeds the max limit of the Bx field {BX_MAX}T!')
# wait for Babs to be reached by the Bx field # wait for Babs to be reached by the Bx field
actual_bval = sep_num_from_units(query_no_echo(instr1, 'IMAG?'))[0]*0.1 # convert kG to T actual_bval = sep_num_from_units(query_no_echo(instr1, 'IMAG?'))[0]*0.1 # convert kG to T
@ -961,7 +966,7 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
wl = np.array(loaded_files.wavelength) wl = np.array(loaded_files.wavelength)
np.savetxt("Wavelength.txt", wl) np.savetxt("Wavelength.txt", wl)
# TODO: data struct of device_target_values is not correct # NOTE: data struct of device_target_values is a list of dictionaries, where each dictionary contains the target values for each device
device_target_values = [{'2301034': bval[0], '2101014': bval[1]} for bval in cartesian_coords] device_target_values = [{'2301034': bval[0], '2101014': bval[1]} for bval in cartesian_coords]
# call the helper function to carry out the rotation/measurement of spectrum # call the helper function to carry out the rotation/measurement of spectrum
@ -972,8 +977,50 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
# b_sweep_val and implement it in this function # b_sweep_val and implement it in this function
def sweep_b_angle(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.Resource, def sweep_b_angle(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.Resource,
min_bval:float, max_bval:float, res:float, min_bval:float, max_bval:float, res:float,
Settings:str, clockwise=True, base_file_name='', zerowhenfin_bool=False): Settings:str, clockwise=True, base_file_name='',
reversescan_bool=False, zerowhenfin_bool=False, loopscan_bool=False):
# defines the folder, in which the data from the spectrometer is temporarily stored in
temp_folder_path = "C:/Users/localadmin/Desktop/Users/Lukas/B_Field_Dump"
# temp_folder_path = "C:/Users/localadmin/Desktop/Users/Lukas/2024_02_08_Map_test"
if base_file_name =='':
base_file_name = datetime.datetime.now().strftime('%Y_%m_%d_%H.%M')
start_time = time.time() # start of the scan function
startangle = startangle % 360
endangle = endangle % 360 # ensures that the angles are within [0,360)
idnstr1 = query_no_echo(instr1, '*IDN?')
idnstr2 = query_no_echo(instr2, '*IDN?')
intensity_data = [] # To store data from each scan
cwd = os.getcwd() # save original directory
# find which one is the dual power supply, then, ramp B_x to Babs value
if '2301034' in idnstr1: # serial no. the dual power supply
pass pass
elif '2101034' in idnstr2:
# swap instruments, instr 1 to be the dual power supply (^= x-axis)
instr1, instr2 = instr2, instr1
# save initial low and high sweep limits of each device, and set them back after the rotation
instr1_bsettings = list(sep_num_from_units(el) for el in query_no_echo(instr1, 'UNITS?;LLIM?;ULIM?').split(';')) # deliver a 3 element tuple of tuples containing the set unit, llim and ulim
instr2_bsettings = list(sep_num_from_units(el) for el in query_no_echo(instr2, 'UNITS?;LLIM?;ULIM?').split(';')) # deliver a 3 element tuple of tuples containing the set unit, llim and ulim
if instr1_bsettings[0][0] == 'T':
instr1_bsettings[1][0] = instr1_bsettings[1][0]*0.1 # rescale kG to T, device accepts values only in kG or A, eventho we set it to T
instr1_bsettings[2][0] = instr1_bsettings[2][0]*0.1
if instr2_bsettings[0][0] == 'T':
instr2_bsettings[1][0] = instr2_bsettings[1][0]*0.1 # rescale kG to T, device accepts values only in kG or A, eventho we set it to T
instr2_bsettings[2][0] = instr2_bsettings[2][0]*0.1
# initialise the sweep angle list as well as the sweep limits and directions for each instrument
instr1_lim, instr2_lim = 'LLIM', 'ULIM'
instr1_sweep, instr2_sweep = 'DOWN', 'UP'
# TODO: see later parts of b_field_rotation from line 820 onwards, and see if same logic can be applied here
################################################################# END OF FUNCTION DEFS ########################################################################################### ################################################################# END OF FUNCTION DEFS ###########################################################################################