From dd69caa42d5beb5aeb37fc757e0fb20ee08a221a Mon Sep 17 00:00:00 2001 From: ryantan Date: Fri, 1 Nov 2024 16:26:56 +0100 Subject: [PATCH] cleaned up the scan script, updated the README.md script (unfinished) --- Dasha_LCRCode.py | 172 +++-------------------------------------------- README.md | 19 ++++-- 2 files changed, 24 insertions(+), 167 deletions(-) diff --git a/Dasha_LCRCode.py b/Dasha_LCRCode.py index 8f50486..91c088f 100644 --- a/Dasha_LCRCode.py +++ b/Dasha_LCRCode.py @@ -130,149 +130,6 @@ def save_as_csv(filename, position_x, position_y): writer.writerow(['x_coordinates','y_coordinates']) writer.writerow([position_x, position_y]) - -# def move_axis(axis, target): -# """ -# This function moves an axis to the specified target and stop moving after it is in the really closed -# vicinity (+- 25nm) of the target (listener hooked to it). -# """ -# amc.move.setControlTargetPosition(axis, target) -# amc.control.setControlMove(axis, True) -# while not (target - 25) < amc.move.getPosition(axis) < (target + 25): -# time.sleep(0.1) -# time.sleep(0.15) -# while not (target - 25) < amc.move.getPosition(axis) < (target + 25): -# time.sleep(0.1) -# amc.control.setControlMove(axis, False) - -# def move_xy(target_x, target_y): # moving in x and y direction closed to desired position -# amc.move.setControlTargetPosition(0, target_x) -# amc.control.setControlMove(0, True) -# amc.move.setControlTargetPosition(1, target_y) -# amc.control.setControlMove(1, True) -# while not (target_x - 25) < amc.move.getPosition(0) < (target_x + 25) and (target_y - 25) < amc.move.getPosition(1) < (target_y + 25): -# time.sleep(0.1) -# time.sleep(0.15) -# while not (target_x - 25) < amc.move.getPosition(0) < (target_x + 25) and (target_y - 25) < amc.move.getPosition(1) < (target_y + 25): -# time.sleep(0.1) - -# amc.control.setControlOutput(0, False) -# amc.control.setControlOutput(1, False) - -# intensity_data = [] # To store data from each scan -# data_list = [] - -# def move_scan_xy(range_x, range_y, resolution, Settings, baseFileName): -# """ -# This function moves the positioners to scan the sample with desired ranges and resolution in 2 dimensions. -# At the end it saves a csv file - -# Parameters -# ---------- -# range_x : integer in nm. max value is 5um -# Scan range in x direction. -# range_y : integer in nm. max value is 5um -# Scan range in y direction. -# resolution : integer in nm. -# Room temprature max res is 50nm. In cyrostat (4K) it is 10nm (check the Attocube manual) -# baseFileName: string. At the end the saved file will be: baseFileName_scan_data.csv and it will be saved to the current directory - -# Returns -# ------- -# None. - -# """ -# start_time = time.time() -# axis_x = 0 #first axis -# axis_y = 1 #second axis -# center_x = amc.move.getPosition(axis_x) -# center_y = amc.move.getPosition(axis_y) -# # #check if the intput range is reasonable -# # if amc.move.getPosition(axis_x) + range_x >= 5000 or amc.move.getPosition(axis_x)- range_x <= 0 or amc.move.getPosition(axis_y) + range_y >=5000 or amc.move.getPosition(axis_y) - range_y <= 5000 : -# # print("scan range is out of range!") -# # return -# # +- range from current positions for x and y directions - - -# array_x = generate_scan_positions(center_x, range_x, resolution) -# array_y = generate_scan_positions(center_y, range_y, resolution) -# total_points = len(array_x)*len(array_y) -# len_y = len(array_y) -# intensity_data = [] # To store data from each scan -# data_list = [] -# 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 -# temp_folder_path = "C:/Users/localadmin/Desktop/Users/Lukas/2024_02_08_Map_test" - -# #scanning loop -# for i, x_positions in enumerate(array_x): -# move_axis(axis_x, x_positions) -# y = False -# for j, y_positions in enumerate(array_y): -# move_axis(axis_y, y_positions) -# #each time when the positioner comes to the beggining of a new line -# #this if will make the positioner wait a bit longer to really go to the target. -# if y == False: -# move_axis(axis_y, y_positions) -# y = True - -# #we acquire with the LF -# acquire_name_spe = f'{baseFileName}_X{x_positions}_Y{y_positions}' -# AcquireAndLock(acquire_name_spe) #this creates a .spe file with the scan name. - -# #read the .spe file and get the data as loaded_files -# cwd = os.getcwd() # save original directory -# os.chdir(temp_folder_path) #change directory -# loaded_files = sl.load_from_files([acquire_name_spe + '.spe']) # get the .spe file as a variable -# os.chdir(cwd) # go back to original directory - -# # Delete the created .spe file from acquiring after getting necessary info -# spe_file_path = os.path.join(temp_folder_path, acquire_name_spe + '.spe') -# os.remove(spe_file_path) - -# distance = calculate_distance(x_positions, y_positions,amc.move.getPosition(axis_x), amc.move.getPosition(axis_y)) - -# points_left = total_points - (i * len_y + (j+1)) + 1 -# 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) -# intensity_data.append(loaded_files.data[0][0][0]) - -# data_list.append({ -# 'position_x': x_positions, -# 'position_y': y_positions, -# 'actual_x': amc.move.getPosition(axis_x), -# 'actual_y': amc.move.getPosition(axis_y), -# 'distance': distance, -# }) - -# #moves back to starting position -# move_axis(axis_x, center_x) -# move_axis(axis_y, center_y) - -# #prints total time the mapping lasted -# end_time = time.time() -# elapsed_time = (end_time - start_time) / 60 -# print('Scan time: ', elapsed_time, 'minutes') - -# # df = pd.DataFrame(data_list) - -# #save intensity & WL data as .txt -# os.chdir('C:/Users/localadmin/Desktop/Users/Lukas') -# # creates new folder for MAP data -# new_folder_name = "Test_Map_" + f"{datetime.datetime.now().strftime('%Y_%m_%d_%H.%M')}" -# os.mkdir(new_folder_name) -# # Here the things will be saved in a new folder under user Lukas ! -# # IMPORTANT last / has to be there, otherwise data cannot be saved and will be lost!!!!!!!!!!!!!!!! -# os.chdir('C:/Users/localadmin/Desktop/Users/Lukas/'+ new_folder_name) - -# intensity_data = np.array(intensity_data) -# np.savetxt(Settings + str(center_x) + '_' + str(center_y) + experiment_name +'.txt', intensity_data) - -# wl = np.array(loaded_files.wavelength) -# np.savetxt("Wavelength.txt", wl) ################################################################# RYAN'S FUNCTIONS HERE ########################################################################################## @@ -356,7 +213,6 @@ def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True ################################################################# DASHA'S CODE HERE ############################################################################################## -# TODO: Implementation of zerowhenfin_bool, maybe later # 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, res:float, base_file_name='', folder_name='', @@ -487,7 +343,6 @@ def LCR_scan_func(handle:int, init_voltage:float, final_voltage:float, wl = np.array(loaded_files.wavelength) np.savetxt("Wavelength.txt", wl) - ################################################################# END OF FUNCTION DEFS ########################################################################################### # ENTER START AND END VOLTAGES, AS WELL AS VOLTAGE STEP SIZE HERE @@ -495,12 +350,16 @@ start_voltage = 0 end_voltage = 0.5 voltage_stepsize = 0.25 -# NOTE: This variable is redundant; either modify the code to include it later on in the file name, or remove it +# ENTER FILE NAME HERE (experiment settings + voltage range, stepsize, actual time) #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 = 'Test settings' #The program adds the range of the scan as well as the resolution and the date and time of the measurement -experiment_name = f"{start_voltage}V_to_{end_voltage}V_{voltage_stepsize}V_{datetime.datetime.now().strftime('%Y_%m_%d_%H%M')}" +experiment_name = experiment_settings + f"{start_voltage}V_to_{end_voltage}V_{voltage_stepsize}V_{datetime.datetime.now().strftime('%Y_%m_%d_%H%M')}" + +# ENTER FOLDER NAME HERE, TO WHICH THE EXP. DATA IS TO BE STORED IN +# NOTE: This folder name is in the path 'C:/Users/localadmin/Desktop/Users/Dasha/' +# suited for Dasha's uses +experiment_folder_name = 'Test_folder' try: # initialise KLC connection @@ -534,27 +393,18 @@ try: if(klcGetEnable(KLC_handle, en)<0): # check if the set enable fucntion was called successfully print("klcGetEnable failed") - # TODO: remove this commented code block later - # Initialise PYVISA ResourceManager - # rm = pyvisa.ResourceManager() - # print(rm.list_resources()) - # '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) - auto = Automation(True, List[String]()) experiment = auto.LightFieldApplication.Experiment acquireCompleted = AutoResetEvent(False) experiment.Load("Alison_08.07.24") # NOTE: this should be the experiment.ExperimentCompleted += experiment_completed # we are hooking a listener. - # experiment.SetValue(SpectrometerSettings.GratingSelected, '[750nm,1200][0][0]') # TODO: find out what these two lines of code do, leave commented as of (31.10.2024) + # experiment.SetValue(SpectrometerSettings.GratingSelected, '[750nm,1200][0][0]') # InitializerFilenameParams() + # TODO: find out what these two lines of code do, leave commented as of (31.10.2024) - # TODO: insert LCR rotation scan function here - # 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) LCR_scan_func(handle=KLC_handle, init_voltage=start_voltage, final_voltage=end_voltage, res=voltage_stepsize, - base_file_name='Test', folder_name='Test_folder') + base_file_name=experiment_name, folder_name=experiment_folder_name) except Exception() as e: print(e) diff --git a/README.md b/README.md index 2a7d362..2d8ae08 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,20 @@ -# Liquid Crystal Retarder(LCR) Controller Code +# Thorlabs K-Cube Liquid Crystal Controller (KLC101) Code -TODO: add read me details, how to use the script, dependencies, etc. +This code is implemented to rotate the Liquid Crystal Retarder. -## Notes for successful operation of the script +## How to use the script -1. For the code to work, change the directory to load the KLCCommandLib_x64.dll file in 'KLCCommandLib64.py', line 5. +The user of the script must enter the given start- and end voltages, as well as the voltage resolution (controller voltage resolution is 1 mV!), which are located at the bottom of the script. TODO: CONTINUE EXPLANATION + +## Notes + +1. For the code to work, change the directory to load the KLCCommandLib_x64.dll file, located in 'KLCCommandLib64.py', line 5, to your specific directory, in which the .dll file is stored. The line of code is as follows: `klcLib=cdll.LoadLibrary(r"C:\Users\rtan\Documents\RyanWork2024\Dasha-LCR_Code\Thorlabs_KLC_PythonSDK\"KLCCommandLib_x64.dll")` -2. Another issue is then importing the other needed folders, probs have to have all the required files in the same scan -script folder on the offline computer. \ No newline at end of file +2. Another issue is then importing the other needed folders, probably have to have all the required files in the same scan +script folder on the offline computer. (This is probably resolved in the newer version of the code.) + +## Standing Issues/Planned Updates +