Skip to content

Commit

Permalink
Merged in feature/RAM-4046_interactive_WL_plots (pull request #465)
Browse files Browse the repository at this point in the history
finalize WL plotly plots

Approved-by: Randy Taylor
  • Loading branch information
jrkerns committed Nov 1, 2024
2 parents 7a8874d + dbba085 commit 2ee84c5
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
105 changes: 105 additions & 0 deletions pylinac/winston_lutz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,111 @@ def plotly_analyzed_images(
add_title(iso_fig, "3D Isocenter visualization")
figs["Isocenter Visualization"] = iso_fig

# polar plot and POV plots
for axis, start_angle, clock, marker_name in zip(
(Axis.GANTRY, Axis.COLLIMATOR, Axis.COUCH, Axis.EPID),
(90, 270, 270, 90),
("clockwise", "counterclockwise", "counterclockwise", "clockwise"),
("BB", "BB", "BB", "EPID"),
):
if axis == Axis.EPID:
attr = "cax2epid_vector"
variable_axis = Axis.GANTRY
else:
attr = "cax2bb_vector"
variable_axis = axis
# get axis images, angles, and shifts
imgs = [
image
for image in self.images
if image.variable_axis in (variable_axis, Axis.REFERENCE)
]
angles = [
getattr(image, f"{variable_axis.value.lower()}_angle") for image in imgs
]
xz_sag = np.array([getattr(img, attr).x for img in imgs])
y_sag = np.array([getattr(img, attr).y for img in imgs])
rms = np.sqrt(xz_sag**2 + y_sag**2)
# append the first point to the end to close the loop
angles = np.append(angles, angles[0])
xz_sag = np.append(xz_sag, xz_sag[0])
y_sag = np.append(y_sag, y_sag[0])
rms = np.append(rms, rms[0])

# X/Y POV plots
fig = go.Figure()
title = f"{axis.value} POV displacement"
fig.add_scatter(
x=xz_sag,
y=y_sag,
hovertext=[
f"Angle: {angle}\N{DEGREE SIGN}; Total: {r:.3f}mm"
for angle, r in zip(angles, rms)
],
hoverinfo="text+x+y",
mode="lines+markers",
name=f"{marker_name} positions",
)
fig.add_scatter(
x=[0],
y=[0],
name="Field Center",
mode="markers",
)
fig.add_scatter(
x=[xz_sag.mean()],
y=[y_sag.mean()],
hoverinfo="text+x+y",
hovertext=f"Displacement: {math.hypot(xz_sag.mean(), y_sag.mean()):.3f}mm",
name=f"{marker_name} Centroid",
mode="markers",
)
add_title(fig, title)
add_vertical_line(fig, 0, "black", name="y=0")
add_horizontal_line(fig, 0, "black", name="x=0")
fig.update_layout(
showlegend=show_legend,
xaxis_title="X (+Left) (mm)",
yaxis_title="Y (+In) (mm)",
xaxis_scaleanchor="y",
)
figs[title] = fig

# polar plots
fig = go.Figure()
title = f"In-plane {axis.value} displacement"
for name, data in zip(
["Y-axis (In/Out)", "X/Z-axis (Gantry plane)", "RMS"],
[y_sag, xz_sag, rms],
):
fig.add_scatterpolar(
r=data,
theta=angles,
name=name,
)
add_title(fig, f"{axis.value} Error Plot")
fig.update_layout(
title=title,
showlegend=show_legend,
polar=dict(
angularaxis=dict(
rotation=start_angle,
direction=clock, # Change the direction to clockwise (can also be 'counterclockwise')
),
radialaxis=dict(
title="Displacement from Field (mm)", visible=True
),
),
)
# add 0-value highlight
fig.add_scatterpolar(
r=[0] * 100,
theta=np.linspace(0, 360, 100),
mode="lines",
name="0-line",
)
figs[title] = fig

if show:
for f in figs.values():
f.show()
Expand Down
2 changes: 1 addition & 1 deletion tests_basic/test_winstonlutz.py
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ class KatyiX0(WinstonLutzMixin, PlotlyTestMixin, TestCase):
machine_scale = MachineScale.VARIAN_IEC
bb_shift_vector = Vector(x=-0.4, y=0.15, z=-0.5)
print_results = True
num_figs = 18
num_figs = 26
fig_data = {
0: {
"title": "1",
Expand Down

0 comments on commit 2ee84c5

Please sign in to comment.