From 2747d21d4db8f4f123874743dfce512d0cabc875 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 29 Apr 2020 08:58:14 +0200 Subject: move running_mean helper from dfatool to utils --- bin/cal-hist | 3 ++- bin/gradient | 3 ++- bin/mim-vs-keysight.py | 7 ++----- bin/mimosa-etv | 3 ++- bin/mimplot | 3 ++- bin/workload.py | 5 ----- lib/dfatool.py | 13 +------------ lib/utils.py | 11 +++++++++++ 8 files changed, 22 insertions(+), 26 deletions(-) diff --git a/bin/cal-hist b/bin/cal-hist index 96c4469..f615c57 100755 --- a/bin/cal-hist +++ b/bin/cal-hist @@ -7,7 +7,8 @@ import struct import sys import tarfile import matplotlib.pyplot as plt -from dfatool import running_mean, MIMOSA +from dfatool import MIMOSA +from utils import running_mean voltage = float(sys.argv[1]) shunt = float(sys.argv[2]) diff --git a/bin/gradient b/bin/gradient index e54f10f..eb79b25 100755 --- a/bin/gradient +++ b/bin/gradient @@ -7,7 +7,8 @@ import struct import sys import tarfile import matplotlib.pyplot as plt -from dfatool import running_mean, MIMOSA +from dfatool import MIMOSA +from utils import running_mean voltage = float(sys.argv[1]) shunt = float(sys.argv[2]) diff --git a/bin/mim-vs-keysight.py b/bin/mim-vs-keysight.py index d017c30..df37d8b 100755 --- a/bin/mim-vs-keysight.py +++ b/bin/mim-vs-keysight.py @@ -1,13 +1,10 @@ #!/usr/bin/env python3 -import csv import numpy as np -import os -import struct import sys -import tarfile import matplotlib.pyplot as plt -from dfatool import running_mean, MIMOSA, KeysightCSV +from dfatool import MIMOSA, KeysightCSV +from utils import running_mean voltage = float(sys.argv[1]) shunt = float(sys.argv[2]) diff --git a/bin/mimosa-etv b/bin/mimosa-etv index 8e8ba44..417f1cf 100755 --- a/bin/mimosa-etv +++ b/bin/mimosa-etv @@ -8,7 +8,8 @@ import numpy as np import os import re import sys -from dfatool import aggregate_measures, running_mean, MIMOSA +from dfatool import aggregate_measures, MIMOSA +from utils import running_mean opt = dict() diff --git a/bin/mimplot b/bin/mimplot index 60da5c0..cd71a4f 100755 --- a/bin/mimplot +++ b/bin/mimplot @@ -9,7 +9,8 @@ import struct import sys import tarfile import matplotlib.pyplot as plt -from dfatool import running_mean, MIMOSA +from dfatool import MIMOSA +from utils import running_mean opt = dict() diff --git a/bin/workload.py b/bin/workload.py index c0a03c7..c78e9a8 100755 --- a/bin/workload.py +++ b/bin/workload.py @@ -7,11 +7,6 @@ from lex import TimedSequence, TimedWord, Workload args = sys.argv[1:] -# TODO loops im raw_word: -# init(); repeat { foo(); sleep(5m); bar(); ... } o.ä. -# - Zeitangaben mit Einheit in sleep -# - Ausgabe in Gesamt, Init und Schleifeninhalt aufdröseln - loops = dict() ptafiles = list() loop_names = set() diff --git a/lib/dfatool.py b/lib/dfatool.py index 607028e..b206250 100644 --- a/lib/dfatool.py +++ b/lib/dfatool.py @@ -16,7 +16,7 @@ from functions import analytic from functions import AnalyticFunction from parameters import ParamStats from utils import vprint, is_numeric, soft_cast_int, param_slice_eq, remove_index_from_tuple -from utils import by_name_to_by_param, match_parameter_values +from utils import by_name_to_by_param, match_parameter_values, running_mean try: from pubcode import Code128 @@ -29,17 +29,6 @@ except ImportError: arg_support_enabled = True -def running_mean(x: np.ndarray, N: int) -> np.ndarray: - """ - Compute `N` elements wide running average over `x`. - - :param x: 1-Dimensional NumPy array - :param N: how many items to average - """ - cumsum = np.cumsum(np.insert(x, 0, 0)) - return (cumsum[N:] - cumsum[:-N]) / N - - def gplearn_to_function(function_str: str): """ Convert gplearn-style function string to Python function. diff --git a/lib/utils.py b/lib/utils.py index a582d6b..26a591e 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -14,6 +14,17 @@ def vprint(verbose, string): print(string) +def running_mean(x: np.ndarray, N: int) -> np.ndarray: + """ + Compute `N` elements wide running average over `x`. + + :param x: 1-Dimensional NumPy array + :param N: how many items to average + """ + cumsum = np.cumsum(np.insert(x, 0, 0)) + return (cumsum[N:] - cumsum[:-N]) / N + + def human_readable(value, unit): for prefix, factor in (('p', 1e-12), ('n', 1e-9), (u'µ', 1e-6), ('m', 1e-3), ('', 1), ('k', 1e3)): if value < 1e3 * factor: -- cgit v1.2.3