Skip to content

Commit

Permalink
Run black and isort
Browse files Browse the repository at this point in the history
  • Loading branch information
b1quint committed Sep 15, 2023
1 parent 6e1fca7 commit 0eada6a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from astropy.time import Time
from lsst.summit.utils.efdUtils import getEfdData
from lsst.summit.utils.tmaUtils import TMAEvent, TMAEventMaker

from plots import inertia_compensation_system
from plots import inertia_compensation_system

# Configure the logger
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
Expand Down Expand Up @@ -284,8 +283,8 @@ def pack_stats_series(self):
Returns:
--------
pandas.Series
A Series with custom index labels based on the column names and
index positions. The Series contains values from all columns of the
A Series with custom index labels based on the column names and
index positions. The Series contains values from all columns of the
DataFrame.
"""
if isinstance(self.stats, pd.Series):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@

import matplotlib.pyplot as plt
from astropy.time import Time


def plot_hp_data(ax, topic, data, label):
l = ax.plot(data, "-", label=label, lw=0.5)
return l


def mark_slew_begin_end(ax, slew_begin, slew_end):
ax.axvline(slew_begin.datetime, lw=0.5, ls="--", c="k", zorder=-1)
l = ax.axvline(slew_end.datetime, lw=0.5, ls="--", c="k", zorder=-1, label="Slew Start/Stop")
l = ax.axvline(
slew_end.datetime, lw=0.5, ls="--", c="k", zorder=-1, label="Slew Start/Stop"
)
return l


def mark_padded_slew_begin_end(ax, begin, end):
ax.axvline(begin.datetime, alpha=0.5, lw=0.5, ls="-", c="k", zorder=-1)
l = ax.axvline(end.datetime, alpha=0.5, lw=0.5, ls="-", c="k", zorder=-1, label="Padded Slew Start/Stop")
l = ax.axvline(
end.datetime,
alpha=0.5,
lw=0.5,
ls="-",
c="k",
zorder=-1,
label="Padded Slew Start/Stop",
)
return l


def customize_hp_plot(ax, dataset, lines):
t_fmt = "%Y%m%d %H:%M:%S"
ax.set_title(
f"HP Measured Data\n "
f"DayObs {dataset.event.dayObs} "
f"SeqNum {dataset.event.seqNum} "
f"SeqNum {dataset.event.seqNum} "
f"v{dataset.event.version}\n "
f"{dataset.df.index[0].strftime(t_fmt)} - "
f"{dataset.df.index[-1].strftime(t_fmt)}"
Expand All @@ -31,49 +44,60 @@ def customize_hp_plot(ax, dataset, lines):
ax.grid(":", alpha=0.2)
ax.legend(ncol=4, handles=lines)


def plot_velocity_data(ax, dataset):
l_az_vel = ax.plot(dataset.df["az_actual_velocity"], color='royalblue', label='Az Velocity')
l_el_vel = ax.plot(dataset.df["el_actual_velocity"], color='teal', label='El Velocity')
l_az_vel = ax.plot(
dataset.df["az_actual_velocity"], color="royalblue", label="Az Velocity"
)
l_el_vel = ax.plot(
dataset.df["el_actual_velocity"], color="teal", label="El Velocity"
)
ax.grid(":", alpha=0.2)
ax.set_ylabel("Actual Velocity\n [deg/s]")
ax.legend(ncol=2)


def plot_torque_data(ax, dataset):
l_az_vel2 = ax.plot(dataset.df["az_actual_torque"], color='firebrick', label='Az Torque')
l_el_vel2 = ax.plot(dataset.df["el_actual_torque"], color='salmon', label='El Torque')
l_az_vel2 = ax.plot(
dataset.df["az_actual_torque"], color="firebrick", label="Az Torque"
)
l_el_vel2 = ax.plot(
dataset.df["el_actual_torque"], color="salmon", label="El Torque"
)
ax.grid(":", alpha=0.2)
ax.set_ylabel("Actual Torque\n [kN.m]")
ax.legend(ncol=2)


def plot_stable_region(fig, begin, end, label="", color="b"):
for ax in fig.axes:
span = ax.axvspan(begin.datetime, end.datetime, fc=color, alpha=0.1, zorder=-2, label=label)
span = ax.axvspan(
begin.datetime, end.datetime, fc=color, alpha=0.1, zorder=-2, label=label
)
return span


def finalize_and_save_figure(fig, name):

def finalize_and_save_figure(fig, name):
fig.tight_layout()
fig.savefig(
name
.replace("/", "")
name.replace("/", "")
.replace(" ", "_")
.replace(" ", "_")
.replace(",", "")
.replace("%", "pc")
)

plt.show()


def plot_hp_measured_data(dataset):

figure_name = (
f"hp_measured_forces_"
f"{dataset.event.dayObs}_"
f"sn{dataset.event.seqNum}_"
f"v{dataset.event.version}"
)

fig, (ax_hp, ax_tor, ax_vel) = plt.subplots(
num=figure_name,
dpi=120,
Expand All @@ -88,28 +112,39 @@ def plot_hp_measured_data(dataset):
topic = dataset.measured_forces_topics[hp]
line = plot_hp_data(ax_hp, topic, dataset.df[topic], f"HP{hp+1}")
lines.extend(line)

slew_begin = Time(dataset.event.begin, scale="utc")
slew_end = Time(dataset.event.end, scale="utc")

mark_slew_begin_end(ax_hp, slew_begin, slew_end)
mark_slew_begin_end(ax_vel, slew_begin, slew_end)
line = mark_slew_begin_end(ax_tor, slew_begin, slew_end)
lines.append(line)

mark_padded_slew_begin_end(ax_hp, slew_begin - dataset.outer_pad, slew_end + dataset.outer_pad)
mark_padded_slew_begin_end(ax_vel, slew_begin - dataset.outer_pad, slew_end + dataset.outer_pad)
line = mark_padded_slew_begin_end(ax_tor, slew_begin - dataset.outer_pad, slew_end + dataset.outer_pad)

mark_padded_slew_begin_end(
ax_hp, slew_begin - dataset.outer_pad, slew_end + dataset.outer_pad
)
mark_padded_slew_begin_end(
ax_vel, slew_begin - dataset.outer_pad, slew_end + dataset.outer_pad
)
line = mark_padded_slew_begin_end(
ax_tor, slew_begin - dataset.outer_pad, slew_end + dataset.outer_pad
)
lines.append(line)

stable_begin, stable_end = dataset.find_stable_region()
stat_begin, stat_end = stable_begin + dataset.inner_pad, stable_end - dataset.inner_pad

stat_begin, stat_end = (
stable_begin + dataset.inner_pad,
stable_end - dataset.inner_pad,
)

plot_velocity_data(ax_vel, dataset)
plot_torque_data(ax_tor, dataset)
span_stable = plot_stable_region(fig, stable_begin, stable_end, "Stable", color="k")
span_with_padding = plot_stable_region(fig, stat_begin, stat_end, "Stable w/ Padding", color="b")
span_with_padding = plot_stable_region(
fig, stat_begin, stat_end, "Stable w/ Padding", color="b"
)
lines.extend([span_stable, span_with_padding])

customize_hp_plot(ax_hp, dataset, lines)
finalize_and_save_figure(fig, figure_name)
finalize_and_save_figure(fig, figure_name)

0 comments on commit 0eada6a

Please sign in to comment.