Skip to content

Commit

Permalink
csm_camera: Update annotation units (#66)
Browse files Browse the repository at this point in the history
The units of the csm camera statistics were given in meters rather than degrees. This PR also updates the plots to use a degree symbol.
  • Loading branch information
dshean authored Nov 25, 2024
1 parent 7e941a3 commit 5ae4380
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions asp_plot/csm_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,20 @@ def format_stat_value(value):
return f"{value:.2e}" if abs(value) < 0.01 else f"{value:.2f}"


def plot_stats_text(ax, mean, std):
def plot_stats_text(ax, mean, std, unit='m'):
"""
Plots a text annotation on the given axis displaying the mean and standard deviation of a value.
Args:
ax (matplotlib.axes.Axes): The axis on which to plot the text annotation.
mean (float): The mean value to display.
std (float): The standard deviation value to display.
unit (str): Unit to use for display. Default is 'm'
Returns:
None
"""
stats_text = f"{format_stat_value(mean)} ± {format_stat_value(std)} m"
stats_text = f"{format_stat_value(mean)} ± {format_stat_value(std)} {unit}"
ax.text(
0.05,
0.1,
Expand Down Expand Up @@ -433,7 +434,7 @@ def csm_camera_summary_plot(
cbar2 = plt.colorbar(
sm2, ax=ax, extend=extend, orientation="vertical", aspect=30, pad=0.05
)
cbar2.set_label("Diff Magnitude (deg)", fontsize=9)
cbar2.set_label("Diff Magnitude (°)", fontsize=9)
cbar2.ax.tick_params(labelsize=9)

# Camera 1 line plots
Expand All @@ -448,7 +449,7 @@ def csm_camera_summary_plot(
lw=1,
label="X position (easting)",
)
plot_stats_text(ax1, cam1_x_position_diff_mean, cam1_x_position_diff_std)
plot_stats_text(ax1, cam1_x_position_diff_mean, cam1_x_position_diff_std, unit='m')
ax2 = axes[0, 2]
ax2.plot(
frame_cam1,
Expand All @@ -457,7 +458,7 @@ def csm_camera_summary_plot(
lw=1,
label="Y position (northing)",
)
plot_stats_text(ax2, cam1_y_position_diff_mean, cam1_y_position_diff_std)
plot_stats_text(ax2, cam1_y_position_diff_mean, cam1_y_position_diff_std, unit='m')
ax3 = axes[0, 3]
ax3.plot(
frame_cam1,
Expand All @@ -466,7 +467,7 @@ def csm_camera_summary_plot(
lw=1,
label="Z position (altitude)",
)
plot_stats_text(ax3, cam1_z_position_diff_mean, cam1_z_position_diff_std)
plot_stats_text(ax3, cam1_z_position_diff_mean, cam1_z_position_diff_std, unit='m')

# Share y-axis for position diff plots
min_val_position_diff = min(
Expand Down Expand Up @@ -524,7 +525,7 @@ def csm_camera_summary_plot(
linestyle="--",
label="Original Roll",
)
plot_stats_text(ax1_r, cam1_roll_diff_mean, cam1_roll_diff_std)
plot_stats_text(ax1_r, cam1_roll_diff_mean, cam1_roll_diff_std, unit='°')

ax2 = axes[1, 2]
ax2.plot(frame_cam1, gdf_cam1.pitch_diff, c="#FFA500", lw=1, label="Pitch Diff")
Expand All @@ -537,7 +538,7 @@ def csm_camera_summary_plot(
linestyle="--",
label="Original Pitch",
)
plot_stats_text(ax2_r, cam1_pitch_diff_mean, cam1_pitch_diff_std)
plot_stats_text(ax2_r, cam1_pitch_diff_mean, cam1_pitch_diff_std, unit='°')

ax3 = axes[1, 3]
ax3.plot(frame_cam1, gdf_cam1.yaw_diff, c="#FFB347", lw=1, label="Yaw Diff")
Expand All @@ -550,7 +551,7 @@ def csm_camera_summary_plot(
linestyle="--",
label="Original Yaw",
)
plot_stats_text(ax3_r, cam1_yaw_diff_mean, cam1_yaw_diff_std)
plot_stats_text(ax3_r, cam1_yaw_diff_mean, cam1_yaw_diff_std, unit='°')

# Share y-axis for angular diff plots
min_val_angle_diff = min(
Expand Down Expand Up @@ -583,10 +584,10 @@ def csm_camera_summary_plot(
ax.set_xticklabels(xtick_labels)
else:
ax.set_xlabel("Position Sample", fontsize=9)
ax.set_ylabel("Original $-$ Optimized (deg)", fontsize=9)
ax.set_ylabel("Original $-$ Optimized (°)", fontsize=9)
if shared_scales:
ax.set_ylim(min_val_angle_diff, max_val_angle_diff)
ax_r.set_ylabel("Original (deg)", fontsize=9)
ax_r.set_ylabel("Original (°)", fontsize=9)
if log_scale_angles:
ax.set_yscale("symlog")
ax.grid(True, linestyle=":", linewidth=0.5, alpha=0.8, color="gray")
Expand Down Expand Up @@ -646,7 +647,7 @@ def csm_camera_summary_plot(
cbar2 = plt.colorbar(
sm2, ax=ax, extend=extend, orientation="vertical", aspect=30, pad=0.05
)
cbar2.set_label("Diff Magnitude (deg)", fontsize=9)
cbar2.set_label("Diff Magnitude (°)", fontsize=9)
cbar2.ax.tick_params(labelsize=9)

frame_cam2 = np.arange(gdf_cam2.shape[0])
Expand All @@ -660,7 +661,7 @@ def csm_camera_summary_plot(
lw=1,
label="X position (easting)",
)
plot_stats_text(ax1, cam2_x_position_diff_mean, cam2_x_position_diff_std)
plot_stats_text(ax1, cam2_x_position_diff_mean, cam2_x_position_diff_std, unit='m')
ax2 = axes[2, 2]
ax2.plot(
frame_cam2,
Expand All @@ -669,7 +670,7 @@ def csm_camera_summary_plot(
lw=1,
label="Y position (northing)",
)
plot_stats_text(ax2, cam2_y_position_diff_mean, cam2_y_position_diff_std)
plot_stats_text(ax2, cam2_y_position_diff_mean, cam2_y_position_diff_std, unit='m')
ax3 = axes[2, 3]
ax3.plot(
frame_cam2,
Expand All @@ -678,7 +679,7 @@ def csm_camera_summary_plot(
lw=1,
label="Z position (altitude)",
)
plot_stats_text(ax3, cam2_z_position_diff_mean, cam2_z_position_diff_std)
plot_stats_text(ax3, cam2_z_position_diff_mean, cam2_z_position_diff_std, unit='m')

# Share y-axis for position diff plots
min_val_position_diff = min(
Expand Down Expand Up @@ -738,7 +739,7 @@ def csm_camera_summary_plot(
linestyle="--",
label="Original Roll",
)
plot_stats_text(ax1_r, cam2_roll_diff_mean, cam2_roll_diff_std)
plot_stats_text(ax1_r, cam2_roll_diff_mean, cam2_roll_diff_std, unit='°')

ax2 = axes[3, 2]
ax2.plot(frame_cam2, gdf_cam2.pitch_diff, c="#FFA500", lw=1, label="Pitch Diff")
Expand All @@ -751,7 +752,7 @@ def csm_camera_summary_plot(
linestyle="--",
label="Original Pitch",
)
plot_stats_text(ax2_r, cam2_pitch_diff_mean, cam2_pitch_diff_std)
plot_stats_text(ax2_r, cam2_pitch_diff_mean, cam2_pitch_diff_std, unit='°')

ax3 = axes[3, 3]
ax3.plot(frame_cam2, gdf_cam2.yaw_diff, c="#FFB347", lw=1, label="Yaw Diff")
Expand All @@ -764,7 +765,7 @@ def csm_camera_summary_plot(
linestyle="--",
label="Original Yaw",
)
plot_stats_text(ax3_r, cam2_yaw_diff_mean, cam2_yaw_diff_std)
plot_stats_text(ax3_r, cam2_yaw_diff_mean, cam2_yaw_diff_std, unit='°')

# Share y-axis for angular diff plots
min_val_angle_diff = min(
Expand Down Expand Up @@ -799,10 +800,10 @@ def csm_camera_summary_plot(
ax.set_xticklabels(xtick_labels)
else:
ax.set_xlabel("Position Sample", fontsize=9)
ax.set_ylabel("Original $-$ Optimized (deg)", fontsize=9)
ax.set_ylabel("Original $-$ Optimized (°)", fontsize=9)
if shared_scales:
ax.set_ylim(min_val_angle_diff, max_val_angle_diff)
ax_r.set_ylabel("Original (deg)", fontsize=9)
ax_r.set_ylabel("Original (°)", fontsize=9)
if log_scale_angles:
ax.set_yscale("symlog")
ax.grid(True, linestyle=":", linewidth=0.5, alpha=0.8, color="gray")
Expand Down

0 comments on commit 5ae4380

Please sign in to comment.