Skip to content

Commit

Permalink
Add plots for inertia compensation system
Browse files Browse the repository at this point in the history
  • Loading branch information
b1quint committed Sep 15, 2023
1 parent df85069 commit 6e1fca7
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import pandas as pd
from astropy import units as u
from astropy.time import Time
from lsst.summit.utils.efdUtils import getEfdData, makeEfdClient
from lsst.summit.utils.efdUtils import getEfdData
from lsst.summit.utils.tmaUtils import TMAEvent, TMAEventMaker

from plots import inertia_compensation_system

Check failure on line 12 in python/lsst/summit/testing/analysis/m1m3/inertia_compensation_system.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

python/lsst/summit/testing/analysis/m1m3/inertia_compensation_system.py:12:46: W291 Trailing whitespace

Check failure on line 12 in python/lsst/summit/testing/analysis/m1m3/inertia_compensation_system.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (W291)

python/lsst/summit/testing/analysis/m1m3/inertia_compensation_system.py:12:46: W291 Trailing whitespace

# Configure the logger
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
formatter.datefmt = "%Y-%m-%d %H:%M:%S"

Expand Down Expand Up @@ -281,8 +284,9 @@ 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 DataFrame.
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):
self.logger.info("Stats are already packed into a Series.")
Expand Down Expand Up @@ -446,3 +450,5 @@ def evaluate_single_slew(day_obs, seq_number):
if __name__ == "__main__":
logger.info("Start")
results = evaluate_single_slew(20230802, 38)
inertia_compensation_system.plot_hp_measured_data(results)
logger.info("End")
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

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")
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")
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"v{dataset.event.version}\n "
f"{dataset.df.index[0].strftime(t_fmt)} - "
f"{dataset.df.index[-1].strftime(t_fmt)}"
)
ax.set_xlabel("Time [UTC]")
ax.set_ylabel("HP Measured Forces [N]")
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')
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')
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)
return span


def finalize_and_save_figure(fig, name):

fig.tight_layout()
fig.savefig(
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,
figsize=(9, 6),
nrows=3,
sharex=True,
height_ratios=[2, 1, 1],
)

lines = []
for hp in range(dataset.number_of_hardpoints):
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)
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

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")
lines.extend([span_stable, span_with_padding])

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

0 comments on commit 6e1fca7

Please sign in to comment.