Skip to content

Commit

Permalink
Fix plotting of Tune Test (#81)
Browse files Browse the repository at this point in the history
* Fix plotting of Tune Test

Closes #72

* remove unused variable
  • Loading branch information
ksunden authored and untzag committed Jan 20, 2020
1 parent 4db6baa commit eb20dbc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
2 changes: 1 addition & 1 deletion attune/workup/_intensity.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def intensity(
units = None

new_curve = Curve(
setpoints, [Dependent(offsets, dependent, units, differential=True)], name="intensity"
setpoints, [Dependent(offsets, dependent, units, differential=True)], name="intensity",
)

if curve is not None:
Expand Down
62 changes: 33 additions & 29 deletions attune/workup/_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def plot_intensity(data, channel, dependent, curve, prior_curve=None, raw_offset
prior_curve_plot_kwargs = {"lw": 2, "c": "k"}
ax.plot(curve.setpoints[:], curve[dependent][:], **curve_plot_kwargs)
if prior_curve:
ax.plot(prior_curve.setpoints[:], prior_curve[dependent][:], **prior_curve_plot_kwargs)
ax.plot(
prior_curve.setpoints[:], prior_curve[dependent][:], **prior_curve_plot_kwargs,
)
ax.set_ylabel(dependent)
wt.artists.plot_gridlines()
ax.set_xlim(*curve.get_limits())
Expand All @@ -36,14 +38,14 @@ def plot_intensity(data, channel, dependent, curve, prior_curve=None, raw_offset
ax.plot(curve.setpoints[:], ypoints, **curve_plot_kwargs)
ax.axhline(0, **prior_curve_plot_kwargs)
wt.artists.plot_gridlines()
ax.set_ylabel(r"$\mathsf{{\Delta {dependent}}}$".format(dependent=dependent))
ax.set_xlabel(f"Setpoint ({curve.setpoints.units})")
ax.set_ylabel(fr"$\mathsf{{\Delta {dependent}}}$")
ax.set_xlabel(data.axes[0].label)
ax.set_xlim(*curve.get_limits())

cax = plt.subplot(gs[1, 1])
ticks = np.linspace(data[channel].null, data[channel].max(), 11)
wt.artists.plot_colorbar(
cax, clim=(data[channel].null, data[channel].max()), ticks=ticks, label=channel
cax, vlim=(data[channel].null, data[channel].max()), ticks=ticks, label=channel
)

return fig, gs
Expand All @@ -60,7 +62,9 @@ def plot_setpoint(data, channel, dependent, curve, prior_curve=None, raw_offsets
ax.set_xlim(*curve.get_limits())
ax.xaxis.set_tick_params(label1On=False)
if prior_curve:
ax.plot(prior_curve.setpoints[:], prior_curve[dependent][:], **prior_curve_plot_kwargs)
ax.plot(
prior_curve.setpoints[:], prior_curve[dependent][:], **prior_curve_plot_kwargs,
)
ax.set_ylabel(dependent)
wt.artists.plot_gridlines()

Expand All @@ -85,24 +89,25 @@ def plot_setpoint(data, channel, dependent, curve, prior_curve=None, raw_offsets
ax.axhline(0, **prior_curve_plot_kwargs)
wt.artists.plot_gridlines()
ax.set_ylabel(fr"$\mathsf{{\Delta {dependent}}}$")
units = curve.setpoints.units
if units is None:
ax.set_xlabel("Setpoint")
else:
symbol = wt.units.get_symbol(units)
units_str = wt.units.dicts[wt.units.kind(units)][units][2]
label = fr"$\mathsf{{{symbol}_{{setpoint}}\,\left({units_str}\right)}}$"
ax.set_xlabel(label)
ax.set_xlabel(data.axes[0].label)
ax.set_xlim(*curve.get_limits())

cax = plt.subplot(gs[1, 1])
ticks = np.linspace(*limits, 11)
wt.artists.plot_colorbar(cax, clim=limits, ticks=ticks, label=channel, cmap="signed")
wt.artists.plot_colorbar(cax, vlim=limits, ticks=ticks, label=channel, cmap="signed")

return fig, gs


def plot_tune_test(data, channel, curve, prior_curve, raw_offsets=None):
def plot_tune_test(data, channel, curve, used_offsets, raw_offsets=None):
data = data.copy()
data.convert("wn")
curve = curve.copy()
if curve.setpoints.units == "nm":
used_offsets = used_offsets[::-1]
if raw_offsets is not None:
raw_offsets = raw_offsets[::-1]
curve.convert("wn")
fig, gs = wt.artists.create_figure(default_aspect=0.5, cols=[1, "cbar"])
# heatmap
ax = plt.subplot(gs[0, 0])
Expand All @@ -113,19 +118,13 @@ def plot_tune_test(data, channel, curve, prior_curve, raw_offsets=None):
ax.plot(curve.setpoints[:], raw_offsets, c="grey", lw=5, alpha=0.5)

ax.plot(
prior_curve.setpoints[:],
curve.setpoints[:] - prior_curve.setpoints[:],
c="k",
lw=5,
alpha=0.5,
curve.setpoints[:], used_offsets, c="k", lw=5, alpha=0.5,
)
ax.axhline(c="k", lw=1)
ax.grid()

ax.set_xlabel(r"$\mathsf{{Setpoint, ({units})}}$".format(units=curve.setpoints.units))
ax.set_ylabel(
r"$\mathsf{{\Delta {symbol}}}$".format(symbol=wt.units.get_symbol(curve.setpoints.units))
)
ax.set_xlabel(data.axes[0].label)
ax.set_ylabel(fr"$\mathsf{{\Delta}}$ {data.axes[0].label}")

# colorbar
cax = plt.subplot(gs[:, -1])
Expand Down Expand Up @@ -172,7 +171,7 @@ def plot_holistic(
vmax=np.max(center_ticks),
)
ax_cen.contour(
data, channel=amp_channel, levels=amp_ticks, cmap=amp_cmap, linewidths=2, alpha=1
data, channel=amp_channel, levels=amp_ticks, cmap=amp_cmap, linewidths=2, alpha=1,
)

wt.artists.set_fig_labels(xlabel=data.axes[0].label, ylabel=data.axes[1].label)
Expand All @@ -186,10 +185,10 @@ def plot_holistic(
axis[np.isnan(data[amp_channel])] = np.nan

amin = min(
np.min(curve[dependents[i]]), np.min(prior_curve[dependents[i]]), np.nanmin(axis)
np.min(curve[dependents[i]]), np.min(prior_curve[dependents[i]]), np.nanmin(axis),
)
amax = max(
np.max(curve[dependents[i]]), np.max(prior_curve[dependents[i]]), np.nanmax(axis)
np.max(curve[dependents[i]]), np.max(prior_curve[dependents[i]]), np.nanmax(axis),
)
arange = amax - amin
amin -= arange * 0.05
Expand All @@ -210,11 +209,16 @@ def plot_holistic(
zorder=2,
)
ax.plot(
curve[dependents[0]], curve[dependents[1]], color="k", linewidth=6, alpha=0.5, zorder=2
curve[dependents[0]],
curve[dependents[1]],
color="k",
linewidth=6,
alpha=0.5,
zorder=2,
)
if raw_offsets is not None:
ax.scatter(
raw_offsets[:, 0], raw_offsets[:, 1], color="w", s=50, zorder=10, marker="*"
raw_offsets[:, 0], raw_offsets[:, 1], color="w", s=50, zorder=10, marker="*",
) # TODO don't be bad about point handleing

return fig, gs
2 changes: 1 addition & 1 deletion attune/workup/_setpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def setpoint(
units = None

new_curve = Curve(
setpoints, [Dependent(offsets, dependent, units, differential=True)], name="setpoint"
setpoints, [Dependent(offsets, dependent, units, differential=True)], name="setpoint",
)

if curve is not None:
Expand Down
2 changes: 1 addition & 1 deletion attune/workup/_tune_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def tune_test(
# plot ----------------------------------------------------------------------------------------

fig, _ = plot_tune_test(
data, channel.natural_name, new_curve, prior_curve=old_curve, raw_offsets=raw_offsets
data, channel.natural_name, new_curve, used_offsets=offsets, raw_offsets=raw_offsets,
)

# finish --------------------------------------------------------------------------------------
Expand Down

0 comments on commit eb20dbc

Please sign in to comment.