summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2021-01-13 14:54:00 +0100
committerDaniel Friesel <daniel.friesel@uos.de>2021-01-13 14:54:00 +0100
commitd60d8afd4e81de9ff2615bdfe0fac829ec80663e (patch)
tree356fe3d646cfa7c2553d9f1b072cb7cf3a5d101a /lib
parent5f883c967621ae220f4eebdf128a8f11a8496bd9 (diff)
pelt: Allow overrides via environment variables
Diffstat (limited to 'lib')
-rw-r--r--lib/lennart/DataProcessor.py17
-rw-r--r--lib/pelt.py10
2 files changed, 23 insertions, 4 deletions
diff --git a/lib/lennart/DataProcessor.py b/lib/lennart/DataProcessor.py
index 437001e..ec17ca8 100644
--- a/lib/lennart/DataProcessor.py
+++ b/lib/lennart/DataProcessor.py
@@ -94,8 +94,6 @@ class DataProcessor:
if (self.et_timestamps[-1] - sync_start) > self.power_sync_len:
datasync_timestamps.append((sync_start, pre_outliers_ts))
- # print(datasync_timestamps)
-
# time_stamp_data contains an entry for each level change on the Logic Analyzer input.
# So, time_stamp_data[0] is the first low-to-high transition, time_stamp_data[2] the second, etc.
# -> time_stamp_data[2] is the low-to-high transition indicating the end of the first sync pulse
@@ -201,9 +199,13 @@ class DataProcessor:
return compensated_timestamps
def compensateDrift(self, sync_timestamps):
+ """Use ruptures (e.g. Pelt, Dynp) to determine transition timestamps."""
from dfatool.pelt import PELT
- pelt = PELT(min_dist=5, with_multiprocessing=False)
+ # TODO die Anzahl Changepoints ist a priori bekannt, es könnte mit ruptures.Dynp statt ruptures.Pelt besser funktionieren.
+ # Vielleicht sollte man auch "rbf" statt "l1" nutzen.
+ # "rbf" und "l2" scheinen ähnlich gut zu funktionieren, l2 ist schneller.
+ pelt = PELT(with_multiprocessing=False)
expected_transition_start_timestamps = sync_timestamps[::2]
transition_start_candidate_weights = list()
compensated_timestamps = list()
@@ -223,7 +225,11 @@ class DataProcessor:
et_timestamps_start : et_timestamps_end + 1
]
candidate_weight = dict()
- for penalty in (1, 2, 5, 10, 15, 20):
+ if os.getenv("DFATOOL_DRIFT_COMPENSATION_PENALTY"):
+ penalties = (int(os.getenv("DFATOOL_DRIFT_COMPENSATION_PENALTY")),)
+ else:
+ penalties = (1, 2, 5, 10, 15, 20)
+ for penalty in penalties:
for changepoint in pelt.get_changepoints(energy_data, penalty=penalty):
if changepoint in candidate_weight:
candidate_weight[changepoint] += 1
@@ -254,6 +260,9 @@ class DataProcessor:
expected_start_ts += drift
expected_end_ts = sync_timestamps[i * 2 + 1] + drift
+
+ # Wähle die beiden nächsten Kandidaten um den erwarteten Sync-Punkt, einmal nach links
+ # (kleinerer Timestamp) und einmal nach rechts (größerer Timestamp)
right_sync = bisect_left(candidates, expected_start_ts)
left_sync = right_sync - 1
diff --git a/lib/pelt.py b/lib/pelt.py
index 613ae80..58bc9c1 100644
--- a/lib/pelt.py
+++ b/lib/pelt.py
@@ -1,5 +1,8 @@
+#!/usr/bin/env python3
+
import logging
import numpy as np
+import os
from multiprocessing import Pool
logger = logging.getLogger(__name__)
@@ -41,6 +44,13 @@ class PELT:
self.with_multiprocessing = True
self.__dict__.update(kwargs)
+ if os.getenv("DFATOOL_PELT_MODEL"):
+ self.model = os.getenv("DFATOOL_PELT_MODEL")
+ if os.getenv("DFATOOL_PELT_JUMP"):
+ self.jump = int(os.getenv("DFATOOL_PELT_JUMP"))
+ if os.getenv("DFATOOL_PELT_MIN_DIST"):
+ self.min_dist = int(os.getenv("DFATOOL_PELT_MIN_DIST"))
+
# signals: a set of uW measurements belonging to a single parameter configuration (i.e., a single by_param entry)
def needs_refinement(self, signals):
count = 0