fixed general bugs

This commit is contained in:
ryantan 2025-04-15 11:17:52 +02:00
parent 6e1ea0fd8b
commit 45e5fd9107
2 changed files with 20 additions and 9 deletions

View File

@ -706,7 +706,7 @@ def generate_angle_coord_list(radius, start_angle, end_angle, step_size, clockwi
start_angle = start_angle % 360
end_angle = end_angle % 360
if clockwise:
if not clockwise:
# Clockwise rotation
current_angle = start_angle
while True:
@ -951,11 +951,11 @@ def b_field_rotation(instr1:pyvisa.resources.Resource, instr2:pyvisa.resources.R
wl = np.array(loaded_files.wavelength)
np.savetxt("Wavelength.txt", wl)
# modify cartesian_coords to suite the required data struct in monitor_devices
cartesian_coords = [{'2301034': t[0], '2101014': t[1]} for t in cartesian_coords]
# TODO: data struct of device_target_values is not correct
device_target_values = [{'2301034': bval[0], '2101014': bval[1]} for bval in cartesian_coords]
# call the helper function to carry out the rotation/measurement of spectrum
monitor_devices(cartesian_coords, angles, intensity_data)
monitor_devices(device_target_values, angles, intensity_data)
################################################################# END OF FUNCTION DEFS ###########################################################################################

21
Test.py
View File

@ -1,6 +1,6 @@
import math
def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True):
def generate_angle_coord_list(radius, start_angle, end_angle, step_size, clockwise=True):
# TODO: DOCS
"""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).
@ -23,7 +23,7 @@ def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True
start_angle = start_angle % 360
end_angle = end_angle % 360
if clockwise:
if not clockwise:
# Clockwise rotation
current_angle = start_angle
while True:
@ -76,6 +76,7 @@ def polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True
return [angles, coordinates]
def generate_coord_list_fixed_angle(angle, b_val, b_val_step_size, reverse=False):
"""
Generates a list of (x, y) Cartesian coordinates along a line defined by a fixed angle,
@ -119,13 +120,23 @@ if __name__=="__main__":
# Example usage
radius = 5
start_angle = 0
end_angle = 0
end_angle = 180
step_size = 10
angles, coordinates = polar_to_cartesian(radius, start_angle, end_angle, step_size, clockwise=True)
angles, coordinates = generate_angle_coord_list(radius, start_angle, end_angle, step_size, clockwise=True)
print('\n', "Angles:", angles, '\n')
print("Coordinates:", coordinates, '\n',)
# device_target_values = [{'2301034': bval[0], '2101014': bval[1]} for bval in coordinates]
xcoord_tuple, ycoord_tuple = zip(*coordinates)
device_target_values = {'2301034': list(xcoord_tuple), '2101014': list(ycoord_tuple)}
print(f"{device_target_values['2301034']=}")
print(f"{device_target_values['2101014']=}")
for iteration, (device_id,bval_lst) in enumerate(device_target_values.items()):
print(iteration, device_id, bval_lst)
# print(generate_coord_list_fixed_angle(10, 5, 1, reverse=False))
print(generate_coord_list_fixed_angle(10, 5, 1, reverse=False))