Commit c1038ef6 authored by Dominique Piche's avatar Dominique Piche

more intuitive util class

parent a5ad4f30
......@@ -64,6 +64,7 @@ class MecaRobot:
self.run('SetAutoConf', [1])
self.run('SetBlending', [0])
self.run('SetTRF', [0,0,0,0,-90,0])
# Sending the robot to its initial position
self.zero_joints()
......
......@@ -3,65 +3,63 @@ import pytg43
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# TODO : doc
def get_spherical_coordinates(x, y, z):
r = np.sqrt((x**2 + y**2 + z**2))
theta = np.arccos(z/r) * 180 / np.pi
return r, theta
def export_tg43_dose_rate(number_of_scintillators=1, show_figure=False):
def export_tg43_dose_rate(show_figure=False, seed_name='Flexisource'):
# Exports the dose rate corresponding to each dwell position in the Data folder calculatead using the TG43 formalism.
seed = pytg43.Seed('Flexisource')
seed = pytg43.Seed(seed_name)
scintillator_number = 1
while True:
try:
cart_coords = np.genfromtxt('Data/scintillator_{}_position_relative_to_source.txt'.format(scintillator_number), delimiter=',') / 10
except OSError:
break
for scintillator in range(number_of_scintillators):
cart_coords = np.genfromtxt('Data/scintillator_{}_position_relative_to_source.txt'.format(scintillator+1), delimiter=',') / 10
x, y, z = cart_coords[:, 0], cart_coords[:, 1], cart_coords[:, 2]
r, theta = get_spherical_coordinates(x, y, z)
dose = np.array(seed.dose(r, theta))
np.savetxt('Data/scintillator_{}_tg43_dose_rate.txt'.format(scintillator+1), dose, delimiter=',')
np.savetxt('Data/scintillator_{}_tg43_dose_rate.txt'.format(scintillator_number), dose, delimiter=',')
if show_figure:
plt.figure(scintillator_number)
plt.plot(dose)
plt.title('Scintillator {} TG43 dose rate'.format(scintillator+1))
plt.title('Scintillator {} TG43 dose rate'.format(scintillator_number))
plt.xlabel('Dwell position')
plt.ylabel('Dose []')
plt.show()
def export_measured_dose_rate(show_figure=False):
calibration_matrix = np.array([[1,0,0,0],[0,1,0,0],[0,0,1,0]])
plt.ylabel('Dose')
scintillators_signal = np.loadtxt('Data/scintillators_signal.txt', delimiter=',')
try:
dose = np.matmul(calibration_matrix, np.transpose(scintillators_signal))
except ValueError:
print('Calibration matrix for experimental dose rate only implemented for 4 signals channels.')
for scintillator in range(3):
np.savetxt('Data/scintillator_{}_measured_dose_rate.txt'.format(scintillator+1), dose[scintillator, :], delimiter=',')
if show_figure:
plt.plot(dose[scintillator, :], label='Scintillator {}'.format(scintillator+1))
scintillator_number += 1
if show_figure:
plt.legend()
plt.show()
def export_trajectory_graph(number_of_scintillators=1, show_figure=False):
def export_trajectory_graph(show_figure=False):
# Exports a PNG of the robot trajectory graph correspoding to the positions in the Data folder.
for scintillator in range(number_of_scintillators):
data = np.genfromtxt('Data/scintillator_{}_position_relative_to_source.txt'.format(scintillator+1), delimiter=',')
scintillator_number = 1
while True:
try:
cart_coords = np.genfromtxt('Data/scintillator_{}_position_relative_to_source.txt'.format(scintillator_number), delimiter=',') / 10
except OSError:
break
x, y, z = data[:,0], data[:,1], data[:,2]
x, y, z = cart_coords[:,0], cart_coords[:,1], cart_coords[:,2]
x, y, z = np.round(x, 10), np.round(y, 10), np.round(z, 10)
NPOINTS = len(x)
COLOR='blue'
fig = plt.figure()
fig = plt.figure(scintillator_number)
ax = fig.add_subplot(111, projection='3d')
for i in range(NPOINTS-1):
......@@ -71,14 +69,16 @@ def export_trajectory_graph(number_of_scintillators=1, show_figure=False):
ax.set_xlabel('x [mm]')
ax.set_ylabel('y [mm]')
ax.set_zlabel('z [mm]')
ax.set_title('Scintillator {} trajectory'.format(scintillator+1))
ax.set_title('Scintillator {} trajectory'.format(scintillator_number))
ax.legend()
plt.savefig('Data/trajectory_scint_{}.png'.format(scintillator+1), dpi=600)
plt.savefig('Data/trajectory_scint_{}.png'.format(scintillator_number), dpi=600)
if show_figure:
plt.show()
scintillator_number += 1
if show_figure:
plt.show()
def export_list_of_commands():
# Writes in the list_of_movement_commands.txt file all of the movement commands in the log.txt file. These can then be copy pasted
......@@ -98,9 +98,3 @@ def export_list_of_commands():
break
else:
export_file.write(line[6:])
def export_all(number_of_scintillators=1, show_figure=False):
export_tg43_dose_rate(number_of_scintillators=number_of_scintillators, show_figure=show_figure)
export_measured_dose_rate(show_figure=show_figure)
export_trajectory_graph(number_of_scintillators=number_of_scintillators,show_figure=show_figure)
export_list_of_commands()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment