From 15d55f2c9c13a071b747bfa3509f2721e2ca7d89 Mon Sep 17 00:00:00 2001 From: rtan Date: Fri, 6 Sep 2024 11:20:28 +0200 Subject: [PATCH] Changed var name Path_save -> temp_folder_path; bug fixes for b sweep and b rot --- 20240709SerdarModScript.py | 41 ++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/20240709SerdarModScript.py b/20240709SerdarModScript.py index fba87e9..8fc8beb 100644 --- a/20240709SerdarModScript.py +++ b/20240709SerdarModScript.py @@ -165,8 +165,7 @@ def move_xy(target_x, target_y): # moving in x and y direction closed to desired # intensity_data = [] # To store data from each scan # data_list = [] -# TODO: change the save file path to be entered as in function header for the following functions: -# move_scan_xy, sweep_b_val, b_field_rotation + def move_scan_xy(range_x, range_y, resolution, Settings, baseFileName): """ @@ -210,7 +209,7 @@ def move_scan_xy(range_x, range_y, resolution, Settings, baseFileName): #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 - Path_save = "C:/Users/localadmin/Desktop/Users/Lukas/2024_02_08_Map_test" + temp_folder_path = "C:/Users/localadmin/Desktop/Users/Lukas/2024_02_08_Map_test" #scanning loop for i, x_positions in enumerate(array_x): @@ -230,12 +229,12 @@ def move_scan_xy(range_x, range_y, resolution, Settings, baseFileName): #read the .spe file and get the data as loaded_files cwd = os.getcwd() # save original directory - os.chdir(Path_save) #change 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(Path_save, acquire_name_spe + '.spe') + 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)) @@ -362,7 +361,7 @@ def write_no_echo(instr:pyvisa.resources.Resource, command:str, sleeptime=0)->st # NOTE: removed singlepowersupply_bool, reading serial-nr. of the device instead. # old save folder: "C:/Users/localadmin/Desktop/Users/Lukas/2024_02_08_Map_test" def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float, - res:float, magnet_coil:str, Settings:str, base_file_name='', path_save='', + res:float, magnet_coil:str, Settings:str, base_file_name='', reversescan_bool=False, zerowhenfin_bool=False, loopscan_bool=False)->None: # 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, @@ -376,7 +375,6 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float, 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". singlepowersupply_bool (bool, optional): _description_. Defaults to False. reversescan_bool (bool, optional): _description_. Defaults to False. zerowhenfin_bool (bool, optional): _description_. Defaults to False. @@ -405,9 +403,12 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float, return np.append(lst, lst[-2::-1]) else: raise TypeError('Please input a list!') - - if path_save =='': - path_save = datetime.datetime.now().strftime("%Y_%m_%d_%H%M_hrs_") + + # 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" + + # if path_save =='': + # path_save = datetime.datetime.now().strftime("%Y_%m_%d_%H%M_hrs_") if base_file_name =='': base_file_name = datetime.datetime.now().strftime('%Y_%m_%d_%H.%M') @@ -538,12 +539,12 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float, # read the .spe file and get the data as loaded_files cwd = os.getcwd() # save original directory - os.chdir(path_save) #change 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(path_save, acquire_name_spe + '.spe') + spe_file_path = os.path.join(temp_folder_path, acquire_name_spe + '.spe') os.remove(spe_file_path) points_left = total_points - i - 1 # TODO: SEE IF THIS IS CORRECT @@ -656,7 +657,7 @@ def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.Resource, - Babs:float, startangle:float, endangle:float, angle_stepsize:float, Settings:str, clockwise=True, path_save='', base_file_name='', zerowhenfin_bool=False)->None: + Babs:float, startangle:float, endangle:float, angle_stepsize:float, Settings:str, clockwise=True, base_file_name='', zerowhenfin_bool=False)->None: # TODO: update docs """Rotation of the b-field in discrete steps, spectrum is measured at each discrete step in the rotation. Scan angle is defined as the angle between the x-axis and the current B-field vector, i.e., in the anticlockwise direction. @@ -673,8 +674,10 @@ 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?? - if path_save =='': - path_save = datetime.datetime.now().strftime("%Y_%m_%d_%H%M_hrs_") + + # 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" + if base_file_name =='': base_file_name = datetime.datetime.now().strftime('%Y_%m_%d_%H.%M') @@ -762,7 +765,7 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R # time.sleep(1) # Simulate periodic data checking # Main function to manage threads and iterate over target values - def monitor_devices(device_target_values, angles_lst): + def monitor_devices(device_target_values, angles_lst, intensity_data=intensity_data): for iteration, target in enumerate(device_target_values): print(f"\nStarting iteration {iteration+1} for target values: {target}") # Shared dictionary to store values from devices @@ -791,12 +794,12 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R # read the .spe file and get the data as loaded_files cwd = os.getcwd() # save original directory - os.chdir(path_save) #change 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(path_save, acquire_name_spe + '.spe') + spe_file_path = os.path.join(temp_folder_path, acquire_name_spe + '.spe') os.remove(spe_file_path) # points_left = total_points - i - 1 # TODO: SEE IF THIS IS CORRECT @@ -847,7 +850,7 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R cartesian_coords = [{'2301034': t[0], '2101014': t[1]} for t in cartesian_coords] # call the helper function to carry out the rotation/measurement of spectrum - monitor_devices(cartesian_coords, angles) + monitor_devices(cartesian_coords, angles, intensity_data) ################################################################# END OF FUNCTION DEFS ###########################################################################################