cleaned uo function, file naming code, TODO: logic implementation of the LCR rotation

This commit is contained in:
Ryan Tan 2024-10-31 10:16:31 +01:00
parent a24a1ae3fe
commit 0b7e1b1b6a

View File

@ -18,8 +18,7 @@ try:
except OSError as ex: except OSError as ex:
print("Warning:",ex) print("Warning:",ex)
# TODO: add LC Controller limits as constants, as not to be exceeded V_MAX = 25 # corresponds to the max RMS voltage of 25 V of KLC101 device
############################################ ############################################
@ -28,7 +27,7 @@ import csv
import time import time
import clr import clr
import sys import sys
import os import os, glob, string
import spe2py as spe import spe2py as spe
import spe_loader as sl import spe_loader as sl
import pandas as pd import pandas as pd
@ -48,10 +47,6 @@ IP_AMC100 = "192.168.71.100"
# IP = "192.168.1.1" # IP = "192.168.1.1"
IP = IP_AMC100 IP = IP_AMC100
# Import os module
import os, glob, string
# Import System.IO for saving and opening files # Import System.IO for saving and opening files
from System.IO import * from System.IO import *
@ -360,8 +355,8 @@ def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True
# 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
def LCR_scan_func(instr:KLC, min_bval:float, max_bval:float, def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float,
res:float, magnet_coil:str, Settings:str, 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:
def pyramid_list(lst) -> Union[list, np.ndarray]: def pyramid_list(lst) -> Union[list, np.ndarray]:
@ -383,64 +378,34 @@ def LCR_scan_func(instr:KLC, min_bval:float, max_bval:float,
raise TypeError('Please input a list!') raise TypeError('Please input a list!')
# 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/2024_02_08_Map_test" temp_folder_path = "C:/Users/localadmin/Desktop/Users/Dasha/LCR_temp_dump_folder"
# if path_save =='':
# path_save = datetime.datetime.now().strftime("%Y_%m_%d_%H%M_hrs_")
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 of the scan function start_time = time.time() # start of the scan function
instr_info = query_no_echo(instr, '*IDN?') # if '2101014' in instr_info and (magnet_coil=='y-axis'): # single power supply
instr_bsettings = list(sep_num_from_units(el) for el in query_no_echo(instr, 'UNITS?;LLIM?;ULIM?').split(';')) # deliver a 3 element list of lists containing the set unit, llim and ulim
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[2][0] = instr_bsettings[2][0]*0.1
# if singlepowersupply_bool: # checks limits of Bx or By
# 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):
if '2101014' in instr_info and (magnet_coil=='y-axis'): # single power supply # raise ValueError('Input limits exceed that of the magnet Bx! Please input smaller limits.')
if (min_bval< -BY_MAX) or (max_bval > BY_MAX): # write_no_echo(instr, 'CHAN 2')
raise ValueError('Input limits exceed that of the magnet By! Please input smaller limits.') # else:
elif '2301034' in instr_info: # dual power supply # raise ConnectionError('Device is not connected!')
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.')
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 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
# 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'
####################################################
# TODO: decide whether to start at min b val or max b val, depending on which one is nearer, IMPLEMENT THIS LATER
# nearest_bval = (abs(init_bval - min_bval), abs(init_bval - max_bval))
# if nearest_bval[0] <= nearest_bval[1]:
# reversescan_bool = True
####################################################
# if reverse scan, then flip the values in the b list, and swap the initial limit and sweep conditions # 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:
@ -503,7 +468,7 @@ def LCR_scan_func(instr:KLC, min_bval:float, max_bval:float,
spe_file_path = os.path.join(temp_folder_path, acquire_name_spe + '.spe') spe_file_path = os.path.join(temp_folder_path, acquire_name_spe + '.spe')
os.remove(spe_file_path) os.remove(spe_file_path)
points_left = total_points - i - 1 # TODO: SEE IF THIS IS CORRECT points_left = total_points - i - 1
print('Points left in the scan: ', points_left) print('Points left in the scan: ', points_left)
#append the intensity data as it is (so after every #of_wl_points, the spectrum of the next point begins) #append the intensity data as it is (so after every #of_wl_points, the spectrum of the next point begins)
@ -529,7 +494,7 @@ def LCR_scan_func(instr:KLC, min_bval:float, max_bval:float,
os.chdir('C:/Users/localadmin/Desktop/Users/Lukas/'+ new_folder_name) os.chdir('C:/Users/localadmin/Desktop/Users/Lukas/'+ new_folder_name)
intensity_data = np.array(intensity_data) intensity_data = np.array(intensity_data)
np.savetxt(Settings + str(min_bval) + 'T_to_' + str(max_bval) + 'T' + experiment_name +'.txt', intensity_data) np.savetxt(base_file_name + '.txt', intensity_data)
wl = np.array(loaded_files.wavelength) wl = np.array(loaded_files.wavelength)
np.savetxt("Wavelength.txt", wl) np.savetxt("Wavelength.txt", wl)
@ -540,7 +505,7 @@ def LCR_scan_func(instr:KLC, min_bval:float, max_bval:float,
# NOTE: RYAN INTRODUCED SOME FUNCTIONS HERE TO PERFORM THE SCAN # NOTE: RYAN INTRODUCED SOME FUNCTIONS HERE TO PERFORM THE SCAN
try: try:
# initialise KLC connection # initialise KLC connection
#Find devices # Find devices
devs = klcListDevices() devs = klcListDevices()
print("Found devices:",devs,"\n") print("Found devices:",devs,"\n")
if(len(devs)<=0): if(len(devs)<=0):
@ -549,7 +514,7 @@ try:
klc = devs[0] klc = devs[0]
serialnumber = klc[0] serialnumber = klc[0]
#Connect device # Connect device
KLC_handle = klcOpen(serialnumber, 115200, 3) KLC_handle = klcOpen(serialnumber, 115200, 3)
if(KLC_handle<0): if(KLC_handle<0):
print("open ", serialnumber, " failed") print("open ", serialnumber, " failed")
@ -560,9 +525,9 @@ try:
sys.exit() sys.exit()
print("Connected to serial number ", serialnumber) print("Connected to serial number ", serialnumber)
# TODO: continue editing the code below this # TODO: remove this commented code block later
# Initialise PYVISA ResourceManager # Initialise PYVISA ResourceManager
rm = pyvisa.ResourceManager() # rm = pyvisa.ResourceManager()
# print(rm.list_resources()) # print(rm.list_resources())
# 'ASRL8::INSTR' for dual power supply, 'ASRL9::INSTR' for single power supply (online PC) # 'ASRL8::INSTR' for dual power supply, 'ASRL9::INSTR' for single power supply (online PC)
# 'ASRL10::INSTR' for dual power supply, 'ASRL12::INSTR' for single power supply (offline PC) # 'ASRL10::INSTR' for dual power supply, 'ASRL12::INSTR' for single power supply (offline PC)
@ -571,31 +536,28 @@ try:
experiment = auto.LightFieldApplication.Experiment experiment = auto.LightFieldApplication.Experiment
acquireCompleted = AutoResetEvent(False) acquireCompleted = AutoResetEvent(False)
experiment.Load("Lukas_experiment_2024_02_06") experiment.Load("Alison_08.07.24") # NOTE: this should be the
experiment.ExperimentCompleted += experiment_completed # we are hooking a listener. experiment.ExperimentCompleted += experiment_completed # we are hooking a listener.
# experiment.SetValue(SpectrometerSettings.GratingSelected, '[750nm,1200][0][0]') # experiment.SetValue(SpectrometerSettings.GratingSelected, '[750nm,1200][0][0]')
# InitializerFilenameParams() # InitializerFilenameParams()
# ENTER START AND END VOLTAGES, AS WELL AS VOLTAGE STEP SIZE HERE
#set scan range and resolution in nanometers start_voltage = 0
range_x = 20000 end_voltage = 0.5
range_y = 20000 voltage_stepsize = 0.25
resolution = 1000
# set B-field scan range and resolution (all in T)
set_llim_bval = -0.01
set_ulim_bval = 0.01
set_res_bval = 0.01
# TODO: add the start-, end angles, as well as angle step size here (alternatively, add it above)
#Here you can specify the filename of the map e.g. put experiment type, exposure time, used filters, etc.... #Here you can specify the filename of the map e.g. put experiment type, exposure time, used filters, etc....
experiment_settings = 'PL_SP_700_LP_700_HeNe_52muW_exp_2s_Start_' 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"{start_voltage}V_to_{end_voltage}V_{voltage_stepsize}V_{datetime.datetime.now().strftime('%Y_%m_%d_%H%M')}"
# TODO: insert LCR rotation scan function here # 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)
except Exception() as e: except Exception() as e:
print(e) print(e)
finally: finally: