diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-03-16 15:06:16 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-03-16 15:06:16 +0100 |
commit | 9496765702423b9945cd4788dd35f0c34c45d3ad (patch) | |
tree | 8754079dabb9bf4b62d3f57b4fe5a9004bc27181 | |
parent | 862945aa0c6b9eaadd06662dd67bf80f3812b2ec (diff) |
Allow silencing of warning and debug messages
-rwxr-xr-x | bin/test.py | 12 | ||||
-rw-r--r-- | doc/RawData | 1 | ||||
-rwxr-xr-x | lib/dfatool.py | 41 |
3 files changed, 27 insertions, 27 deletions
diff --git a/bin/test.py b/bin/test.py index 021b957..87b8404 100755 --- a/bin/test.py +++ b/bin/test.py @@ -7,7 +7,7 @@ class TestStaticModel(unittest.TestCase): def test_model_singlefile_rf24(self): raw_data = RawData(['../data/20170220_164723_RF24_int_A.tar']) preprocessed_data = raw_data.get_preprocessed_data(verbose = False) - model = EnergyModel(preprocessed_data) + model = EnergyModel(preprocessed_data, verbose = False) self.assertEqual(model.states(), 'POWERDOWN RX STANDBY1 TX'.split(' ')) self.assertEqual(model.transitions(), 'begin epilogue powerDown powerUp setDataRate_num setPALevel_num startListening stopListening write_nb'.split(' ')) static_model = model.get_static() @@ -72,7 +72,7 @@ class TestStaticModel(unittest.TestCase): def test_model_singlefile_mmparam(self): raw_data = RawData(['../data/20161221_123347_mmparam.tar']) preprocessed_data = raw_data.get_preprocessed_data(verbose = False) - model = EnergyModel(preprocessed_data) + model = EnergyModel(preprocessed_data, verbose = False) self.assertEqual(model.states(), 'OFF ON'.split(' ')) self.assertEqual(model.transitions(), 'off setBrightness'.split(' ')) static_model = model.get_static() @@ -100,7 +100,7 @@ class TestStaticModel(unittest.TestCase): ] raw_data = RawData(testfiles) preprocessed_data = raw_data.get_preprocessed_data(verbose = False) - model = EnergyModel(preprocessed_data) + model = EnergyModel(preprocessed_data, verbose = False) self.assertEqual(model.states(), 'ACTIVE POWEROFF'.split(' ')) self.assertEqual(model.transitions(), 'getTemp setHyst setOS shutdown start'.split(' ')) static_model = model.get_static() @@ -129,7 +129,7 @@ class TestStaticModel(unittest.TestCase): ] raw_data = RawData(testfiles) preprocessed_data = raw_data.get_preprocessed_data(verbose = False) - model = EnergyModel(preprocessed_data) + model = EnergyModel(preprocessed_data, verbose = False) self.assertEqual(model.states(), 'DISABLED ENABLED'.split(' ')) self.assertEqual(model.transitions(), 'clear disable enable ioInit sendLine toggleVCOM'.split(' ')) static_model = model.get_static() @@ -161,7 +161,7 @@ class TestStaticModel(unittest.TestCase): ] raw_data = RawData(testfiles) preprocessed_data = raw_data.get_preprocessed_data(verbose = False) - model = EnergyModel(preprocessed_data) + model = EnergyModel(preprocessed_data, verbose = False) self.assertEqual(model.states(), 'B G OFF R'.split(' ')) self.assertEqual(model.transitions(), 'blue green off red'.split(' ')) static_model = model.get_static() @@ -193,7 +193,7 @@ class TestStaticModel(unittest.TestCase): ] raw_data = RawData(testfiles) preprocessed_data = raw_data.get_preprocessed_data(verbose = False) - model = EnergyModel(preprocessed_data) + model = EnergyModel(preprocessed_data, verbose = False) self.assertEqual(model.states(), 'IDLE RX SLEEP SLEEP_EWOR SYNTH_ON TX XOFF'.split(' ')) self.assertEqual(model.transitions(), 'crystal_off eWOR idle init prepare_xmit receive send setSymbolRate setTxPower sleep txDone'.split(' ')) static_model = model.get_static() diff --git a/doc/RawData b/doc/RawData index 863b92b..c849230 100644 --- a/doc/RawData +++ b/doc/RawData @@ -16,6 +16,7 @@ get_preprocessed_data: - timeout: int(us) oder null - energy: int (pJ?) - level: str 'user' 'epilogue' + - offline_attributes: [ ... Namen der in offline_aggregates gespeicherten Modellattribute, z.B. param, duration, energy, timeout ] - offline_aggregates: - power: [float(uW)] Mittlere Leistung während Zustand/Transitions - power_std: [float(uW^2)] Standardabweichung der Leistung diff --git a/lib/dfatool.py b/lib/dfatool.py index 152b25b..b6a732f 100755 --- a/lib/dfatool.py +++ b/lib/dfatool.py @@ -50,8 +50,6 @@ def vprint(verbose, string): if verbose: print(string) -# TODO function override per Argument, z.B. für CC1200 send.duration - def _elem_param_and_arg_list(elem): param_dict = elem['parameter'] paramkeys = sorted(param_dict.keys()) @@ -388,15 +386,14 @@ class RawData: if self._measurement_is_valid(measurement): self._merge_measurement_into_online_data(measurement) num_valid += 1 - elif self.verbose: - print('[W] Skipping {ar:s}/{m:s}: {e:s}'.format( + else: + vprint(self.verbose, '[W] Skipping {ar:s}/{m:s}: {e:s}'.format( ar = self.filenames[measurement['fileno']], m = measurement['info'].name, e = measurement['error'])) - if self.verbose: - print('[I] {num_valid:d}/{num_total:d} measurements are valid'.format( - num_valid = num_valid, - num_total = len(measurements))) + vprint(self.verbose, '[I] {num_valid:d}/{num_total:d} measurements are valid'.format( + num_valid = num_valid, + num_total = len(measurements))) self._concatenate_analyzed_traces() self.preprocessing_stats = { 'num_runs' : len(measurements), @@ -473,7 +470,7 @@ class AnalyticFunction: else: X[i].extend([np.nan] * len(val[model_attribute])) elif key[0] == state_or_tran and len(key[1]) != dimension: - print('[W] Invalid parameter key length while gathering fit data for {}/{}. is {}, want {}.'.format(state_or_tran, model_attribute, len(key[1]), dimension)) + vprint(self.verbose, '[W] Invalid parameter key length while gathering fit data for {}/{}. is {}, want {}.'.format(state_or_tran, model_attribute, len(key[1]), dimension)) X = np.array(X) Y = np.array(Y) @@ -486,15 +483,15 @@ class AnalyticFunction: try: res = optimize.least_squares(error_function, self._regression_args, args=(X, Y), xtol=2e-15) except ValueError as err: - print('[W] Fit failed for {}/{}: {} (function: {})'.format(state_or_tran, model_attribute, err, self._model_str)) + vprint(self.verbose, '[W] Fit failed for {}/{}: {} (function: {})'.format(state_or_tran, model_attribute, err, self._model_str)) return if res.status > 0: self._regression_args = res.x self.fit_success = True else: - print('[W] Fit failed for {}/{}: {} (function: {})'.format(state_or_tran, model_attribute, res.message, self._model_str)) + vprint(self.verbose, '[W] Fit failed for {}/{}: {} (function: {})'.format(state_or_tran, model_attribute, res.message, self._model_str)) else: - print('[W] Insufficient amount of valid parameter keys, cannot fit {}/{}'.format(state_or_tran, model_attribute)) + vprint(self.verbose, '[W] Insufficient amount of valid parameter keys, cannot fit {}/{}'.format(state_or_tran, model_attribute)) def is_predictable(self, param_list): for i, param in enumerate(param_list): @@ -747,7 +744,7 @@ def _mean_std_by_param(by_param, state_or_tran, key, param_index): class EnergyModel: - def __init__(self, preprocessed_data, ignore_trace_indexes = None, discard_outliers = None, function_override = {}): + def __init__(self, preprocessed_data, ignore_trace_indexes = None, discard_outliers = None, function_override = {}, verbose = True): self.traces = preprocessed_data self.by_name = {} self.by_param = {} @@ -758,6 +755,7 @@ class EnergyModel: self._num_args = {} self._outlier_threshold = discard_outliers self.function_override = function_override + self.verbose = verbose if discard_outliers != None: self._compute_outlier_stats(ignore_trace_indexes, discard_outliers) for run in self.traces: @@ -838,7 +836,7 @@ class EnergyModel: return data pruned_data = list(filter(lambda x: np.abs(0.6745 * (x - median) / np.median(np.abs(data - median))) > self._outlier_threshold, data )) if len(pruned_data): - print('[I] Pruned outliers from ({}) {}: {}'.format(key, attribute, pruned_data)) + vprint(self.verbose, '[I] Pruned outliers from ({}) {}: {}'.format(key, attribute, pruned_data)) data = list(filter(lambda x: np.abs(0.6745 * (x - median) / np.median(np.abs(data - median))) <= self._outlier_threshold, data )) return data @@ -903,9 +901,9 @@ class EnergyModel: try: model[name][key] = model_function(elem[key]) except RuntimeWarning: - print('[W] Got no data for {} {}'.format(name, key)) + vprint(self.verbose, '[W] Got no data for {} {}'.format(name, key)) except FloatingPointError as fpe: - print('[W] Got no data for {} {}: {}'.format(name, key, fpe)) + vprint(self.verbose, '[W] Got no data for {} {}: {}'.format(name, key, fpe)) return model def get_static(self): @@ -976,11 +974,11 @@ class EnergyModel: if result['key'][0] == state_or_tran and result['key'][1] == model_attribute: fit_result = result['result'] if fit_result['best_rmsd'] >= min(fit_result['mean_rmsd'], fit_result['median_rmsd']): - print('[I] Not modeling {} {} as function of {}: best ({:.0f}) is worse than ref ({:.0f}, {:.0f})'.format( + vprint(self.verbose, '[I] Not modeling {} {} as function of {}: best ({:.0f}) is worse than ref ({:.0f}, {:.0f})'.format( state_or_tran, model_attribute, result['key'][2], fit_result['best_rmsd'], fit_result['mean_rmsd'], fit_result['median_rmsd'])) elif fit_result['best_rmsd'] >= 0.5 * min(fit_result['mean_rmsd'], fit_result['median_rmsd']): - print('[I] Not modeling {} {} as function of {}: best ({:.0f}) is not much better than ({:.0f}, {:.0f})'.format( + vprint(self.verbose, '[I] Not modeling {} {} as function of {}: best ({:.0f}) is not much better than ({:.0f}, {:.0f})'.format( state_or_tran, model_attribute, result['key'][2], fit_result['best_rmsd'], fit_result['mean_rmsd'], fit_result['median_rmsd'])) else: @@ -1046,9 +1044,10 @@ class EnergyModel: class MIMOSA: - def __init__(self, voltage, shunt): + def __init__(self, voltage, shunt, verbose = True): self.voltage = voltage self.shunt = shunt + self.verbose = verbose self.r1 = 984 # "1k" self.r2 = 99013 # "100k" @@ -1130,7 +1129,7 @@ class MIMOSA: if cal_r2_mean > cal_0_mean: b_lower = (ua_r2 - 0) / (cal_r2_mean - cal_0_mean) else: - print('[W] 0 uA == %.f uA during calibration' % (ua_r2)) + vprint(self.verbose, '[W] 0 uA == %.f uA during calibration' % (ua_r2)) b_lower = 0 b_upper = (ua_r1 - ua_r2) / (cal_r1_mean - cal_r2_mean) @@ -1264,7 +1263,7 @@ class MIMOSA: data['substates'] = substates ssum = np.sum(list(map(lambda x : x['duration'], substates['states']))) if ssum != data['us']: - print("ERR: duration %d vs %d" % (data['us'], ssum)) + vprint(self.verbose, "ERR: duration %d vs %d" % (data['us'], ssum)) if isa == 'transition': # subtract average power of previous state |