b_field_rotation: more bug fixes and progress
This commit is contained in:
parent
5c01110ce5
commit
080ce6b1e6
@ -576,84 +576,11 @@ def sweep_b_val(instr:pyvisa.resources.Resource, min_bval:float, max_bval:float,
|
||||
wl = np.array(loaded_files.wavelength)
|
||||
np.savetxt("Wavelength.txt", wl)
|
||||
|
||||
# TODO: old function, DELETE LATER
|
||||
# def polar_to_cartesian(radius, start_angle, end_angle, step_size):
|
||||
# """_summary_
|
||||
|
||||
# Args:
|
||||
# radius (_type_): _description_
|
||||
# start_angle (_type_): _description_
|
||||
# end_angle (_type_): _description_
|
||||
# step_size (_type_): _description_
|
||||
|
||||
# Returns:
|
||||
# _type_: _description_
|
||||
# """ """"""
|
||||
# # Initialize lists to hold angles and (x, y) pairs
|
||||
# angles = []
|
||||
# coordinates = []
|
||||
|
||||
# # Normalize angles to the range [0, 360)
|
||||
# start_angle = start_angle % 360
|
||||
# end_angle = end_angle % 360
|
||||
|
||||
# # Calculate the clockwise and counterclockwise differences
|
||||
# clockwise_diff = (start_angle - end_angle) % 360
|
||||
# counterclockwise_diff = (end_angle - start_angle) % 360
|
||||
|
||||
# # Determine the shorter path
|
||||
# if clockwise_diff <= counterclockwise_diff:
|
||||
# # Clockwise is shorter
|
||||
# current_angle = start_angle
|
||||
# while current_angle >= end_angle:
|
||||
# # Append the current angle to the angles list
|
||||
# angles.append(current_angle % 360)
|
||||
|
||||
# # Convert the current angle to radians
|
||||
# current_angle_rad = math.radians(current_angle % 360)
|
||||
|
||||
# # Convert polar to Cartesian coordinates
|
||||
# x = radius * math.cos(current_angle_rad)
|
||||
# y = radius * math.sin(current_angle_rad)
|
||||
|
||||
# # Append the (x, y) pair to the list
|
||||
# coordinates.append((x, y))
|
||||
|
||||
# # Check if we've reached the end_angle
|
||||
# if (current_angle ) % 360 == end_angle:
|
||||
# break
|
||||
|
||||
# # Decrement the current angle by the step size
|
||||
# current_angle -= step_size
|
||||
# else:
|
||||
# # Counterclockwise is shorter
|
||||
# current_angle = start_angle
|
||||
# while current_angle <= end_angle:
|
||||
# # Append the current angle to the angles list
|
||||
# angles.append(current_angle % 360)
|
||||
|
||||
# # Convert the current angle to radians
|
||||
# current_angle_rad = math.radians(current_angle % 360)
|
||||
|
||||
# # Convert polar to Cartesian coordinates
|
||||
# x = radius * math.cos(current_angle_rad)
|
||||
# y = radius * math.sin(current_angle_rad)
|
||||
|
||||
# # Append the (x, y) pair to the list
|
||||
# coordinates.append((x, y))
|
||||
|
||||
# # Check if we've reached the end_angle
|
||||
# if (current_angle ) % 360 == end_angle:
|
||||
# break
|
||||
|
||||
# # Increment the current angle by the step size
|
||||
# current_angle += step_size
|
||||
|
||||
# return [angles, coordinates]
|
||||
|
||||
def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True):
|
||||
# TODO: DOCS
|
||||
"""_summary_
|
||||
"""Creates a list of discrete cartesian coordinates (x,y), given the radius, start- and end angles, the angle step size, and the direction of rotation.
|
||||
Function then returns a list of two lists: list of angles and list of cartesian coordinates (x,y coordinates in a tuple).
|
||||
|
||||
Args:
|
||||
radius (_type_): _description_
|
||||
@ -730,7 +657,8 @@ def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True
|
||||
# TODO: write a function that simultaneously controls the two power supplies and perform the rotation of the B-field. => Threading
|
||||
# in function head should be func(instr1, instr2, args1, kwargs1, args2, kwargs2)
|
||||
def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.Resource,
|
||||
Babs:float, startangle:float, endangle:float, angle_stepsize:float, path_save='', base_file_name='', sweepdown=False)->None:
|
||||
Babs:float, startangle:float, endangle:float, angle_stepsize:float, clockwise=True, path_save='', base_file_name='', sweepdown=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.
|
||||
|
||||
@ -741,8 +669,13 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
|
||||
startangle (float): start angle in degrees
|
||||
endangle (float): end angle in degrees
|
||||
angle_stepsize (float): angle step size in degrees
|
||||
clockwise (bool): determines the direction of rotation of the B-field. Defaults to True.
|
||||
sweepdown (bool, optional): after finishing the rotation, both B-field components should be set to 0 T. Defaults to False.
|
||||
"""
|
||||
|
||||
def wait_for_b_val_helper_func(instr,):
|
||||
pass
|
||||
|
||||
if path_save =='':
|
||||
path_save = datetime.datetime.now().strftime("%Y_%m_%d_%H%M_hrs_") # TODO: add path_save, base_file_name in the function header
|
||||
if base_file_name =='':
|
||||
@ -763,15 +696,15 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
|
||||
if '2301034' in idnstr1: # serial no. the dual power supply
|
||||
pass
|
||||
elif '2101034' in idnstr2:
|
||||
# swap instruments, instr 1 to be the dual power supply
|
||||
# swap instruments, instr 1 to be the dual power supply (^= x-axis)
|
||||
instr1, instr2 = instr2, instr1
|
||||
|
||||
# initialise the sweep angle list as well as the sweep limits and directions for each instrument
|
||||
instr1_lim, instr2_lim = 'LLIM', 'ULIM'
|
||||
instr1_sweep, instr2_sweep = 'DOWN', 'UP'
|
||||
angles, cartesian_coords = polar_to_cartesian(Babs, startangle, endangle, angle_stepsize) # create
|
||||
angles, cartesian_coords = polar_to_cartesian(Babs, startangle, endangle, angle_stepsize, clockwise=clockwise) # create lists of angles and discrete Cartesian coordinates
|
||||
|
||||
if startangle > endangle:
|
||||
if clockwise: # NOTE: old conditional was: startangle > endangle see if this works....
|
||||
# reverse sweep limits and directions for the clockwise rotation
|
||||
instr1_lim, instr2_lim = instr2_lim, instr1_lim
|
||||
instr1_sweep, instr2_sweep = instr2_sweep, instr1_sweep
|
||||
@ -800,12 +733,10 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
|
||||
|
||||
# TODO: begin the rotation of the B-field, saving the spectrum for each angle, including the start- and end angles
|
||||
# NOTE: implement PID control, possibly best option to manage the b field DO THIS LATER ON, WE DO DISCRETE B VALUES RN
|
||||
# TODO: polar_to_cartesian does not work when the angle is 0°!!!! fix bug
|
||||
|
||||
# TODO: write the for loop for the rotation here
|
||||
# bug fix for polar_to_cartesian (27.08.2024, 15:52 hrs)
|
||||
# TODO: write the for loop for the rotation here, implement threading => create a helper function to enter into the threads
|
||||
for idx, angle in enumerate(angles):
|
||||
pass
|
||||
|
||||
# # we acquire with the LF
|
||||
# acquire_name_spe = f'{base_file_name}_{bval}T'
|
||||
# AcquireAndLock(acquire_name_spe) #this creates a .spe file with the scan name.
|
||||
|
Loading…
Reference in New Issue
Block a user