summaryrefslogtreecommitdiff
path: root/lib/drift.py
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2021-04-19 12:31:20 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2021-04-19 12:31:33 +0200
commit6db34440a794b501e0a92b5351effcd473465016 (patch)
treee0a9fef53f1cd7d1d94c6773581d7494e0de6101 /lib/drift.py
parentcefda7634508e68912555b1a1b10ec990ea89093 (diff)
plot drift compensation in power trace graph
Diffstat (limited to 'lib/drift.py')
-rw-r--r--lib/drift.py56
1 files changed, 50 insertions, 6 deletions
diff --git a/lib/drift.py b/lib/drift.py
index be7233f..2361c4b 100644
--- a/lib/drift.py
+++ b/lib/drift.py
@@ -72,15 +72,59 @@ def compensate(data, timestamps, event_timestamps, offline_index=None):
)
if os.getenv("DFATOOL_COMPENSATE_DRIFT_GREEDY"):
- return compensate_drift_greedy(
+ compensated_timestamps = compensate_drift_greedy(
event_timestamps, transition_start_candidate_weights
)
+ else:
+ compensated_timestamps = compensate_drift_graph(
+ event_timestamps,
+ transition_start_candidate_weights,
+ offline_index=offline_index,
+ )
- return compensate_drift_graph(
- event_timestamps,
- transition_start_candidate_weights,
- offline_index=offline_index,
- )
+ if os.getenv("DFATOOL_PLOT_DRIFT_CANDIDATES"):
+ import matplotlib.pyplot as plt
+
+ min_y = min(data)
+ max_y = max(data)
+
+ candidates = list()
+ for i, expected_start_ts in enumerate(expected_transition_start_timestamps):
+ expected_end_ts = event_timestamps[2 * i + 1]
+ for start_drift, _, _ in transition_start_candidate_weights[i]:
+ candidates.append(expected_start_ts + start_drift)
+
+ plt.plot(timestamps, data, "-", label="Measurements")
+ plt.vlines(
+ event_timestamps,
+ min_y,
+ max_y,
+ colors=["red"],
+ linestyles="solid",
+ label="Uncompensated Timestamps",
+ )
+ plt.vlines(
+ candidates,
+ min_y,
+ max_y,
+ colors=["green"],
+ linestyles="dashed",
+ label="Candidates (Changepoints)",
+ )
+ plt.vlines(
+ compensated_timestamps,
+ min_y,
+ max_y,
+ colors=["green"],
+ linestyles="solid",
+ label="Compensated Timestamps",
+ )
+ plt.xlabel("Timestamp [s]")
+ plt.ylabel("Power [W]")
+ plt.legend()
+ plt.show()
+
+ return compensated_timestamps
def compensate_drift_graph(