Compare commits
3 Commits
main
...
JulyPullTe
Author | SHA1 | Date | |
---|---|---|---|
c859404a15 | |||
1ddd3e96a4 | |||
130fdfbab1 |
@ -8,6 +8,7 @@ Lightfield + Positioner
|
|||||||
# Packages from Ryan
|
# Packages from Ryan
|
||||||
import re
|
import re
|
||||||
import pyvisa
|
import pyvisa
|
||||||
|
import threading
|
||||||
# from pyvisa import ResourceManager, constants
|
# from pyvisa import ResourceManager, constants
|
||||||
|
|
||||||
# B Field Limits (in T)
|
# B Field Limits (in T)
|
||||||
@ -31,6 +32,7 @@ from System import String
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import datetime
|
import datetime
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
|
||||||
#First choose your controller
|
#First choose your controller
|
||||||
@ -351,19 +353,22 @@ def write_no_echo(instr:pyvisa.resources.Resource, command:str, sleeptime=0.01)-
|
|||||||
except pyvisa.VisaIOError as e:
|
except pyvisa.VisaIOError as e:
|
||||||
print(f"Error communicating with instrument: {e}")
|
print(f"Error communicating with instrument: {e}")
|
||||||
|
|
||||||
# TODO: implement the reverse scan and zero when finish functionality
|
|
||||||
# receive values in units of T, rescale in kg to talk with the power supplyy. 1T = 10kG
|
# 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.
|
||||||
|
# TODO: add a param to allow the
|
||||||
def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float,
|
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",
|
||||||
singlepowersupply_bool=False, reversescan_bool=False, zerowhenfin_bool=False)->None:
|
reversescan_bool=False, zerowhenfin_bool=False, loopscan_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
|
# TODO: update docs in the end
|
||||||
of the probe in the cryostat is made, using the LightField spectrometer.
|
""" 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:
|
Args:
|
||||||
instr (pyvisa.resources.Resource): chosen power supply device to connect to
|
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)
|
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)
|
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)
|
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.
|
Settings (str): experiment settings, included in file name.
|
||||||
base_file_name (str, optional): base file name. Defaults to ''.
|
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".
|
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".
|
||||||
@ -375,31 +380,69 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float,
|
|||||||
ValueError: when By limit is exceeded.
|
ValueError: when By limit is exceeded.
|
||||||
ValueError: when Bz limit is exceeded.
|
ValueError: when Bz limit is exceeded.
|
||||||
ValueError: when Bx limit is exceeded.
|
ValueError: when Bx limit is exceeded.
|
||||||
|
ConnectionError: when no device is connected.
|
||||||
""" ''''''
|
""" ''''''
|
||||||
|
def pyramid_list(lst) -> Union[list, np.ndarray]:
|
||||||
|
"""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.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
lst (list or np.ndarray):
|
||||||
|
Raises:
|
||||||
|
TypeError: if the input object isn't a list or np.ndarray
|
||||||
|
Returns:
|
||||||
|
Union[list, np.ndarray]: the pyramid list
|
||||||
|
""" ''''''
|
||||||
|
if isinstance(lst, list):
|
||||||
|
return lst + lst[-2::-1]
|
||||||
|
elif isinstance(lst, np.ndarray):
|
||||||
|
return np.append(lst, lst[-2::-1])
|
||||||
|
else:
|
||||||
|
raise TypeError('Please input a list!')
|
||||||
|
|
||||||
if base_file_name =='':
|
if base_file_name =='':
|
||||||
base_file_name = datetime.datetime.now().strftime('%Y_%m_%d_%H.%M')
|
base_file_name = datetime.datetime.now().strftime('%Y_%m_%d_%H.%M')
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time() # start of the scan function
|
||||||
|
|
||||||
|
instr_info = query_no_echo(instr, '*IDN?')
|
||||||
|
|
||||||
instr_bsettings = list(sep_num_from_units(el) for el in query_no_echo(instr, 'UNITS?;LLIM?;ULIM?').split(';')) # deliver a 3 element tuple of tuples containing the set unit, llim and ulim
|
instr_bsettings = list(sep_num_from_units(el) for el in query_no_echo(instr, 'UNITS?;LLIM?;ULIM?').split(';')) # deliver a 3 element tuple of tuples containing the set unit, llim and ulim
|
||||||
|
|
||||||
if instr_bsettings[0][0] == 'T':
|
if instr_bsettings[0][0] == 'T':
|
||||||
instr_bsettings[1][0] = instr_bsettings[1][0]*0.1 # rescale kG to T, device accepts values only in kG or A, eventho we set it to T
|
instr_bsettings[1][0] = instr_bsettings[1][0]*0.1 # rescale kG to T, device accepts values only in kG or A, eventho we set it to T
|
||||||
instr_bsettings[2][0] = instr_bsettings[2][0]*0.1
|
instr_bsettings[2][0] = instr_bsettings[2][0]*0.1
|
||||||
|
|
||||||
if singlepowersupply_bool: # checks limits of Bx or By
|
# if singlepowersupply_bool: # checks limits of Bx or By
|
||||||
|
# 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 '1' in query_no_echo(instr, 'CHAN?'): # 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
|
||||||
|
# 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 and (magnet_coil=='y-axis'): # single power supply
|
||||||
if (min_bval< -BY_MAX) or (max_bval > BY_MAX):
|
if (min_bval< -BY_MAX) or (max_bval > BY_MAX):
|
||||||
raise ValueError('Input limits exceed that of the magnet By! Please input smaller limits.')
|
raise ValueError('Input limits exceed that of the magnet By! Please input smaller limits.')
|
||||||
elif '1' in query_no_echo(instr, 'CHAN?'): # check if its the coils for Bz
|
elif '2301034' in instr_info: # dual power supply
|
||||||
if (min_bval < -BZ_MAX) or (max_bval > BZ_MAX):
|
if magnet_coil=='z-axis': # check if its the coils for Bz
|
||||||
raise ValueError('Input limits exceed that of the magnet (Bz)! Please input smaller limits.')
|
if (min_bval < -BZ_MAX) or (max_bval > BZ_MAX):
|
||||||
else: # checks limits of Bx
|
raise ValueError('Input limits exceed that of the magnet (Bz)! Please input smaller limits.')
|
||||||
if (min_bval< -BX_MAX) or (max_bval > BX_MAX):
|
write_no_echo(instr, 'CHAN 1')
|
||||||
raise ValueError('Input limits exceed that of the magnet Bx! Please input smaller limits.')
|
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
|
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
|
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_lim, subsequent_lim = 'LLIM', 'ULIM'
|
||||||
init_sweep, subsequent_sweep = 'DOWN', 'UP'
|
init_sweep, subsequent_sweep = 'DOWN', 'UP'
|
||||||
@ -417,24 +460,18 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float,
|
|||||||
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
|
||||||
|
|
||||||
|
if loopscan_bool:
|
||||||
|
bval_lst = pyramid_list(bval_lst)
|
||||||
|
|
||||||
total_points = len(bval_lst)
|
total_points = len(bval_lst)
|
||||||
|
middle_index_bval_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
|
||||||
|
|
||||||
#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:
|
# NOTE: helper function for the scanning loop
|
||||||
# # if initial bval is equal to the element of the given iteration from the bval_lst, then commence measuring the spectrum
|
def helper_scan_func(idx, bval, instr=instr, init_lim=init_lim, init_sweep=init_sweep,
|
||||||
# pass
|
subsequent_lim=subsequent_lim, subsequent_sweep=subsequent_sweep, sleep=5):
|
||||||
# else:
|
if idx == 0: # for first iteration, sweep to one of the limits
|
||||||
|
|
||||||
# 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'{init_lim} {bval*10}') # convert back to kG
|
||||||
write_no_echo(instr, f'SWEEP {init_sweep}')
|
write_no_echo(instr, f'SWEEP {init_sweep}')
|
||||||
else:
|
else:
|
||||||
@ -449,6 +486,40 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float,
|
|||||||
actual_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1
|
actual_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1
|
||||||
# update the actual bval
|
# update the actual bval
|
||||||
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
|
||||||
|
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:
|
||||||
|
|
||||||
|
# NOTE: original code without the loop scan
|
||||||
|
################################################
|
||||||
|
# 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}')
|
||||||
|
# else:
|
||||||
|
# write_no_echo(instr, f'{subsequent_lim} {bval*10}') # convert back to kG
|
||||||
|
# write_no_echo(instr, f'SWEEP {subsequent_sweep}')
|
||||||
|
|
||||||
|
# actual_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1 # convert kG to T
|
||||||
|
# print(f'Actual magnet strength: {actual_bval} T,', f'Target magnet strength: {bval} T')
|
||||||
|
|
||||||
|
# while abs(actual_bval - bval) > 0.0001:
|
||||||
|
# time.sleep(5) # little break
|
||||||
|
# actual_bval = sep_num_from_units(query_no_echo(instr, 'IMAG?'))[0]*0.1
|
||||||
|
# # update the actual bval
|
||||||
|
# print(f'Actual magnet strength: {actual_bval} T,', f'Target magnet strength: {bval} T')
|
||||||
|
###############################################
|
||||||
|
if not loopscan_bool:
|
||||||
|
helper_scan_func(i, bval)
|
||||||
|
else:
|
||||||
|
if i <= middle_index_bval_lst:
|
||||||
|
helper_scan_func(i, bval)
|
||||||
|
else:
|
||||||
|
helper_scan_func(i, bval, instr=instr, init_lim=subsequent_lim, init_sweep=subsequent_sweep,
|
||||||
|
subsequent_lim=init_lim, subsequent_sweep=init_sweep, sleep=5)
|
||||||
|
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
# we acquire with the LF
|
# we acquire with the LF
|
||||||
@ -476,6 +547,8 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval: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')
|
||||||
|
|
||||||
|
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
|
write_no_echo(instr, 'SWEEP ZERO') # if switched on, discharges the magnet after performing the measurement loop above
|
||||||
|
|
||||||
@ -514,8 +587,9 @@ powerbox_dualsupply = rm.open_resource('ASRL8::INSTR',
|
|||||||
|
|
||||||
write_no_echo(powerbox_dualsupply, 'REMOTE') # turn on the remote mode
|
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)
|
# 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
|
# Setup connection to AMC
|
||||||
amc = AMC.Device(IP)
|
amc = AMC.Device(IP)
|
||||||
@ -550,21 +624,16 @@ 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
|
#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')}"
|
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
|
# this moves the probe in xy-direction and measures spectrum there
|
||||||
# move_scan_xy(range_x, range_y, resolution, experiment_settings, experiment_name)
|
# move_scan_xy(range_x, range_y, resolution, experiment_settings, experiment_name)
|
||||||
|
|
||||||
# perform the B-field measurement for selected axis above
|
# 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, 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, singlepowersupply_bool=False, zerowhenfin_bool=True, reversescan_bool=False)
|
experiment_settings, experiment_name, zerowhenfin_bool=True, reversescan_bool=False)
|
||||||
|
|
||||||
# Internally, axes are numbered 0 to 2
|
# Internally, axes are numbered 0 to 2
|
||||||
|
|
||||||
write_no_echo(powerbox_dualsupply, 'LOCAL') # turn off the remote mode
|
write_no_echo(powerbox_dualsupply, 'LOCAL') # turn off the remote mode
|
||||||
# time.sleep(0.5)
|
# time.sleep(0.5)
|
||||||
powerbox_dualsupply.close()
|
powerbox_dualsupply.close()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user