Repository navigation
Expand file tree
/
Copy pathPyRate_Graphs.py
More file actions
244 lines (209 loc) · 11.2 KB
/
Copy pathPyRate_Graphs.py
File metadata and controls
244 lines (209 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import matplotlib.pyplot as plt
import matplotlib.ticker as tick
import matplotlib.patches as patch
import math
import numpy as np
def make_graph(file_name, spot_sigma, timing, horizontal, vertical, dose, dose_rate, cyclotron_current, spot_map_pattern):
data = np.genfromtxt(file_name, delimiter=',')
max_time = np.max(data[:,0])
duration_no_threshold = (timing[7] - timing[0])
duration_5 = (timing[6] - timing[1])
duration_10 = (timing[5] - timing[2])
duration_15 = (timing[4] - timing[3])
time_0 = round(timing[0], 6)
time_5 = round(timing[1], 6)
time_10 = round(timing[2], 6)
time_15 = round(timing[3], 6)
time_85 = round(timing[4], 6)
time_90 = round(timing[5], 6)
time_95 = round(timing[6], 6)
time_100 = round(timing[7], 6)
dose_rate_no_threshold = dose / duration_no_threshold
dose_rate_5 = (dose * 0.9) / duration_5
dose_rate_10 = (dose * 0.8) / duration_10
dose_rate_15 = (dose * 0.7) / duration_15
spot_t = f'{round(spot_sigma[0],1)}x{round(spot_sigma[1],1)} mm Spot'
target_t = f'{horizontal}x{vertical} mm {spot_map_pattern} Target'
dose_t = f'{dose} Gy at {round(dose_rate,2)} Gy/s Spot Peak Dose Rate ({cyclotron_current}nA)'
fig, ax = plt.subplots(figsize=(12, 8))
ax.set_title(f'{spot_t}, {target_t}, {dose_t}')
ax.set_title(f'Cumulative Dose at Specific Points')
ax.set_xlabel('Time (s)')
ax.set_ylabel('Dose (Gy)')
ax.set_ylim(0, dose*1.3)
ax.hlines(0.05 * dose, 0., max_time, linestyles='--', color='r', linewidth=0.5)
ax.hlines(0.10 * dose, 0., max_time, linestyles='--', color='orange', linewidth=0.5)
ax.hlines(0.15 * dose, 0., max_time, linestyles='--', color='yellow', linewidth=0.5)
ax.hlines(0.85 * dose, 0., max_time, linestyles='--', color='yellow', linewidth=0.5)
ax.hlines(0.90 * dose, 0., max_time, linestyles='--', color='orange', linewidth=0.5)
ax.hlines(0.95 * dose, 0., max_time, linestyles='--', color='r', linewidth=0.5)
ax.hlines(1.00 * dose, 0., max_time, linestyles='--', color='black', linewidth=0.5)
ax.vlines(time_0, 0, dose*1.3, linestyles='--', color='black', linewidth=0.5)
ax.vlines(time_100, 0, dose * 1.3, linestyles='--', color='black', linewidth=0.5)
ax.axvspan(time_5,time_95, alpha=0.2, color='yellow')
ax.axvspan(time_10, time_90, alpha=0.5, color='orange')
ax.axvspan(time_15, time_85, alpha=0.3, color='yellow')
poi_number = len(data[0])-1
colours = ['purple', 'green', '#1f77b4', 'orange']
labels = ['Dose to Centre of Target', 'Dose 1/2 way to Edge of Target', 'Dose to Edge of Target', 'Dose to Edge of Field']
for i in reversed(range(poi_number)):
ax.plot(data[:,0],data[:,i+1], linewidth=1, color=colours[i], label=labels[i], marker='.')
textstr = (f'0% - 100% dose - {round(duration_no_threshold, 3)} s - {round(dose_rate_no_threshold, 2)} Gy/s\n'
f'5% - 95% dose - {round(duration_5, 3)} s - {round(dose_rate_5, 2)} Gy/s\n'
f'10% - 90% dose - {round(duration_10, 3)} s - {round(dose_rate_10, 2)} Gy/s\n'
f'15% - 85% dose - {round(duration_15, 3)} s - {round(dose_rate_15, 2)} Gy/s')
ax.text(0.05, 0.98, textstr, transform=ax.transAxes, fontsize=12,
verticalalignment='top', bbox=dict(boxstyle='round', facecolor='grey', alpha=0.5))
plt.legend()
plt.show()
def plot_spot(map, resolution):
ticks = tick.FuncFormatter(lambda x, pos: '{0:g}'.format(x * resolution))
fig, axs = plt.subplots()
plt.xlabel("x - horizontal (mm)")
plt.ylabel("y - vertical (mm)")
axs.xaxis.set_major_formatter(ticks)
axs.yaxis.set_major_formatter(ticks)
plt.imshow(1 - map, origin='lower', cmap='Greys')
plt.tight_layout()
plt.show()
def plot_map_with_target(map, resolution, target_details, spot_pixels_max, overscan):
target_horizontal_size = target_details[0]
target_vertical_size = target_details[1]
shape = target_details[2]
ticks = tick.FuncFormatter(lambda x, pos: '{0:g}'.format(x * resolution))
fig, axs = plt.subplots(dpi= 200)
plt.xlabel("x - horizontal (mm)", fontsize=20)
plt.ylabel("y - vertical (mm)", fontsize=20)
axs.xaxis.set_major_formatter(ticks)
axs.yaxis.set_major_formatter(ticks)
axs.tick_params(axis='both', which='major', labelsize=15)
axs.set_aspect('equal')
plt.imshow(1 - map, origin='lower', cmap='Greys')
# Add delineation of target area
h = math.ceil(target_horizontal_size / resolution)
v = math.ceil(target_vertical_size / resolution)
bottom_corner_horizontal = spot_pixels_max + overscan[0]
bottom_corner_vertical = spot_pixels_max + overscan[1]
if shape == 'rectangle':
target_volume = patch.Rectangle((bottom_corner_horizontal, bottom_corner_vertical),
h, v,
linewidth=1.5,
edgecolor='r',
facecolor='none',
linestyle='--')
axs.add_patch(target_volume)
elif shape == 'circle':
target_volume = patch.Circle((bottom_corner_horizontal+h/2, bottom_corner_vertical+v/2),
radius=v/2,
linewidth=1.5,
edgecolor='r',
facecolor='none',
linestyle='--')
axs.add_patch(target_volume)
plt.tight_layout()
plt.show()
def plot_map_with_details(map, resolution, point_of_interest, target_horizontal_size, target_vertical_size, spot_pixels_max, overscan, shape, spot_positions):
ticks = tick.FuncFormatter(lambda x, pos: '{0:g}'.format(x * resolution))
fig, axs = plt.subplots(dpi= 200)
plt.title("Simulated Field")
plt.xlabel("x - horizontal (mm)", fontsize=20)
plt.ylabel("y - vertical (mm)", fontsize=20)
axs.xaxis.set_major_formatter(ticks)
axs.yaxis.set_major_formatter(ticks)
axs.tick_params(axis='both', which='major', labelsize=15)
axs.set_aspect('equal')
plt.imshow(1 - map, origin='lower', cmap='Greys')
spot_x = []
spot_y = []
for x, y in spot_positions:
spot_x.append(x)
spot_y.append(y)
# Add location of measurement point
plt.scatter(point_of_interest[0][1], point_of_interest[0][0], s=20, c='purple', marker='o', zorder=2)
plt.scatter(point_of_interest[1][1], point_of_interest[1][0], s=20, c='green', marker='o', zorder=2)
plt.scatter(point_of_interest[2][1], point_of_interest[2][0], s=20, c='#1f77b4', marker='o', zorder=2)
plt.scatter(point_of_interest[3][1], point_of_interest[3][0], s=20, c='orange', marker='o', zorder=2)
plt.plot(spot_x, spot_y, c='lightblue', marker='.', linestyle='-', linewidth='0.5', zorder=1)
# Add delineation of target area
h = math.ceil(target_horizontal_size / resolution)
v = math.ceil(target_vertical_size / resolution)
bottom_corner_horizontal = spot_pixels_max + overscan[0]
bottom_corner_vertical = spot_pixels_max + overscan[1]
if shape == 'rectangle':
target_volume = patch.Rectangle((bottom_corner_horizontal, bottom_corner_vertical), h, v,
linewidth=1.5, edgecolor='r', facecolor='none', linestyle='--')
axs.add_patch(target_volume)
elif shape == 'circle':
target_volume = patch.Circle((bottom_corner_horizontal+h/2,bottom_corner_vertical+v/2), radius=v/2,
linewidth=1.5, edgecolor='r', facecolor='none', linestyle='--')
axs.add_patch(target_volume)
plt.tight_layout()
plt.show()
def plot_map_animation(map, resolution, point_of_interest, number, target_horizontal_size, target_vertical_size, shape, spot_pixels_max, overscan):
ticks = tick.FuncFormatter(lambda x, pos: '{0:g}'.format(x * resolution))
fig, axs = plt.subplots(figsize=(7.2,9.6), dpi= 200)
plt.xlabel("x - horizontal (mm)", fontsize=20)
plt.ylabel("y - vertical (mm)", fontsize=20)
axs.xaxis.set_major_formatter(ticks)
axs.yaxis.set_major_formatter(ticks)
axs.tick_params(axis='both', which='major', labelsize=15)
axs.set_aspect('equal')
plt.imshow(1 - map, origin='lower', cmap='Greys')
# Add location of measurement point
plt.scatter(point_of_interest[0][1], point_of_interest[0][0], s=20, c='purple', marker='o')
plt.scatter(point_of_interest[1][1], point_of_interest[1][0], s=20, c='green', marker='o')
plt.scatter(point_of_interest[2][1], point_of_interest[2][0], s=20, c='#1f77b4', marker='o')
plt.scatter(point_of_interest[3][1], point_of_interest[3][0], s=20, c='orange', marker='o')
# Add delineation of target area
h = math.ceil(target_horizontal_size / resolution)
v = math.ceil(target_vertical_size / resolution)
bottom_corner = spot_pixels_max + overscan
if shape == 'rectangle':
target_volume = patch.Rectangle((bottom_corner,bottom_corner), h, v,
linewidth=1.5, edgecolor='r', facecolor='none', linestyle='--')
axs.add_patch(target_volume)
elif shape == 'circle':
target_volume = patch.Circle((bottom_corner+h/2,bottom_corner+v/2), radius=v/2,
linewidth=1.5, edgecolor='r', facecolor='none', linestyle='--')
axs.add_patch(target_volume)
plt.savefig(f'spot-{number}.png', bbox_inches='tight')
plt.close(fig)
def plot_simple_heat_map(map, resolution, name, cbar_title, target_details, spot_pixels_max, overscan):
target_horizontal_size = target_details[0]
target_vertical_size = target_details[1]
shape = target_details[2]
ticks = tick.FuncFormatter(lambda x, pos: '{0:g}'.format(x * resolution))
fig, axs = plt.subplots( dpi=200)
plt.title(name)
plt.xlabel("x - horizontal (mm)", fontsize=20)
plt.ylabel("y - vertical (mm)", fontsize=20)
axs.xaxis.set_major_formatter(ticks)
axs.yaxis.set_major_formatter(ticks)
axs.tick_params(axis='both', which='major', labelsize=15)
axs.set_aspect('equal')
plt.imshow(map, origin='lower')
cbar = plt.colorbar()
cbar.set_label(cbar_title, rotation=270, labelpad=15)
# Add delineation of target area
h = math.ceil(target_horizontal_size / resolution)
v = math.ceil(target_vertical_size / resolution)
bottom_corner_horizontal = spot_pixels_max + overscan[0]
bottom_corner_vertical = spot_pixels_max + overscan[1]
if shape == 'rectangle':
target_volume = patch.Rectangle((bottom_corner_horizontal, bottom_corner_vertical),
h, v,
linewidth=1.5,
edgecolor='r',
facecolor='none',
linestyle='--')
axs.add_patch(target_volume)
elif shape == 'circle':
target_volume = patch.Circle((bottom_corner_horizontal+h/2, bottom_corner_vertical+v/2),
radius=v/2,
linewidth=1.5,
edgecolor='r',
facecolor='none',
linestyle='--')
axs.add_patch(target_volume)
plt.tight_layout()
plt.show()