magnet_coil param added. Further mods. to the sweep_b-val func

This commit is contained in:
Ryan Tan 2024-07-15 11:41:30 +02:00
parent 130fdfbab1
commit 1ddd3e96a4

View File

@ -8,6 +8,7 @@ Lightfield + Positioner
# Packages from Ryan
import re
import pyvisa
import threading
# from pyvisa import ResourceManager, constants
# B Field Limits (in T)
@ -352,17 +353,20 @@ def write_no_echo(instr:pyvisa.resources.Resource, command:str, sleeptime=0.01)-
print(f"Error communicating with instrument: {e}")
# receive values in units of T, rescale in kg to talk with the power supplyy. 1T = 10kG
# NOTE: removed singlepowersupply_bool, reading serial-nr. of the device instead.
def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float,
res:float, Settings:str, base_file_name='', path_save="C:/Users/localadmin/Desktop/Users/Lukas/2024_02_08_Map_test",
res:float, magnet_coil:str, Settings:str, base_file_name='', path_save="C:/Users/localadmin/Desktop/Users/Lukas/2024_02_08_Map_test",
reversescan_bool=False, zerowhenfin_bool=False)->None:
""" this function performs a sweep of the B field of the chosen magnet coil. It creates a list o B values from the given min and max values, with the given resolution. For each value, a measurement of the spectrum
of the probe in the cryostat is made, using the LightField spectrometer.
# TODO: update docs in the end
""" this function performs a sweep of the B field of the chosen magnet coil. It creates a list o B values from the given min and max values,
with the given resolution. For each value, a measurement of the spectrum of the probe in the cryostat is made, using the LightField spectrometer.
Args:
instr (pyvisa.resources.Resource): chosen power supply device to connect to
min_bval (float): min B value of the scan (please input in units of Tesla)
max_bval (float): max B value of the scan (please input in units of Tesla)
res (float): resolution of the list of B values (please input in units of Tesla)
magnet_coil (str): select magnet coil to be used. String should be 'x-axis','y-axis' or 'z-axis'.
Settings (str): experiment settings, included in file name.
base_file_name (str, optional): base file name. Defaults to ''.
path_save (str, optional): file path where the file will be saved. Defaults to "C:/Users/localadmin/Desktop/Users/Lukas/2024_02_08_Map_test".
@ -400,23 +404,26 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float,
# if (min_bval< -BX_MAX) or (max_bval > BX_MAX):
# raise ValueError('Input limits exceed that of the magnet Bx! Please input smaller limits.')
if '2101014' in instr_info: # single power supply
if '2101014' in instr_info and (magnet_coil=='y-axis'): # single power supply
if (min_bval< -BY_MAX) or (max_bval > BY_MAX):
raise ValueError('Input limits exceed that of the magnet By! Please input smaller limits.')
elif '2301034' in instr_info: # dual power supply
if '1' in query_no_echo(instr, 'CHAN?'): # check if its the coils for Bz
if magnet_coil=='z-axis': # check if its the coils for Bz
if (min_bval < -BZ_MAX) or (max_bval > BZ_MAX):
raise ValueError('Input limits exceed that of the magnet (Bz)! Please input smaller limits.')
else: # checks limits of Bx
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
bval_lst = np.arange(min_bval, max_bval + res, res) # creates list of B values to measure at, with given resolution, in T
init_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1 # queries the initial B value of the coil, rescale from kG to T
# TODO: unused, see if can remove
# init_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1 # queries the initial B value of the coil, rescale from kG to T
init_lim, subsequent_lim = 'LLIM', 'ULIM'
init_sweep, subsequent_sweep = 'DOWN', 'UP'
@ -438,19 +445,13 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float,
intensity_data = [] # To store data from each scan
cwd = os.getcwd() # save original directory
#This gives a directory, in which the script will save the spectrum of each spot as spe
#However, it will open the spectrum, convert it to txt, add it to the intensity_data and delete the spe file
#scanning loop
for i, bval in enumerate(bval_lst):
# if init_bval == bval:
# # if initial bval is equal to the element of the given iteration from the bval_lst, then commence measuring the spectrum
# pass
# else:
# TODO: improve the conditional block later on... try to shorten the number of conditionals needed/flatten the nested conditionals
# else, travel to the lower or higher limit, depending on how far the init val is to each bound, and commence the measurement from there on
# if not reversescan_bool:
if i == 0: # for first iteration, sweep to one of the limits
write_no_echo(instr, f'{init_lim} {bval*10}') # convert back to kG
write_no_echo(instr, f'SWEEP {init_sweep}')
@ -533,8 +534,9 @@ powerbox_dualsupply = rm.open_resource('ASRL8::INSTR',
write_no_echo(powerbox_dualsupply, 'REMOTE') # turn on the remote mode
# TODO: test functionality of the magnet_coil param later on, should work... as this code below is basically implemented inside the scan func.
# select axis for the dual supply, either z-axis(CHAN 1 ^= Supply A) or x-axis(CHAN 2 ^= Supply B)
write_no_echo(powerbox_dualsupply, 'CHAN 1')
# write_no_echo(powerbox_dualsupply, 'CHAN 1')
# Setup connection to AMC
amc = AMC.Device(IP)
@ -569,16 +571,12 @@ 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"{set_llim_bval}T_to_{set_ulim_bval}T_{set_res_bval}T_{datetime.datetime.now().strftime('%Y_%m_%d_%H%M')}"
# # TODO: write the bval scan here
# for idx, bval in enumerate(bval_lst):
# write_no_echo(powerbox_dualsupply, '')
# this moves the probe in xy-direction and measures spectrum there
# move_scan_xy(range_x, range_y, resolution, experiment_settings, experiment_name)
# perform the B-field measurement for selected axis above
# sweep_b_val(powerbox_dualsupply, set_llim_bval, set_ulim_bval, set_res_bval, experiment_settings, experiment_name)
sweep_b_val(powerbox_dualsupply, set_llim_bval, set_ulim_bval, set_res_bval,
sweep_b_val(powerbox_dualsupply, set_llim_bval, set_ulim_bval, set_res_bval, 'z-axis',
experiment_settings, experiment_name, zerowhenfin_bool=True, reversescan_bool=False)
# Internally, axes are numbered 0 to 2