From 96406d24d0246ac1f7511a59a3102523c6d69767 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 15 May 2020 16:24:45 +0200 Subject: analyze-arche: Add --plot-traces option --- bin/analyze-archive.py | 15 +++++++++++++-- lib/plotter.py | 14 +++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py index f7847c5..b254e76 100755 --- a/bin/analyze-archive.py +++ b/bin/analyze-archive.py @@ -21,6 +21,9 @@ Options: parameters. Also plots the corresponding measurements. If gplearn function is set, it is plotted using dashed lines. +--plot-traces= + Plot power trace for state or transition . + --export-traces= Export power traces of all states and transitions to . Creates a JSON file for each state and transition. Each JSON file @@ -242,7 +245,7 @@ if __name__ == '__main__': try: optspec = ( - 'plot-unparam= plot-param= param-info show-models= show-quality= ' + 'plot-unparam= plot-param= plot-traces= param-info show-models= show-quality= ' 'ignored-trace-indexes= discard-outliers= function-override= ' 'export-traces= ' 'filter-param= ' @@ -293,7 +296,7 @@ if __name__ == '__main__': print(err) sys.exit(2) - raw_data = RawData(args, with_traces=('export-traces' in opts)) + raw_data = RawData(args, with_traces=('export-traces' in opts or 'plot-traces' in opts)) preprocessed_data = raw_data.get_preprocessed_data() @@ -313,6 +316,14 @@ if __name__ == '__main__': with open(target, 'w') as f: json.dump(data, f) + if 'plot-traces' in opts: + traces = list() + for trace in preprocessed_data: + for state_or_transition in trace['trace']: + if state_or_transition['name'] == opts['plot-traces']: + traces.extend(map(lambda x: x['uW'], state_or_transition['offline'])) + plotter.plot_y(traces, xlabel='t [1e-5 s]', ylabel='P [uW]', title=opts['plot-traces'], family=True) + if raw_data.preprocessing_stats['num_valid'] == 0: print('No valid data available. Abort.') sys.exit(2) diff --git a/lib/plotter.py b/lib/plotter.py index b9d5c3e..deed93a 100755 --- a/lib/plotter.py +++ b/lib/plotter.py @@ -100,10 +100,13 @@ def plot_substate_thresholds_p(model, aggregate): def plot_y(Y, **kwargs): - plot_xy(np.arange(len(Y)), Y, **kwargs) + if 'family' in kwargs and kwargs['family']: + plot_xy(None, Y, **kwargs) + else: + plot_xy(np.arange(len(Y)), Y, **kwargs) -def plot_xy(X, Y, xlabel=None, ylabel=None, title=None, output=None): +def plot_xy(X, Y, xlabel=None, ylabel=None, title=None, output=None, family=False): fig, ax1 = plt.subplots(figsize=(10, 6)) if title is not None: fig.canvas.set_window_title(title) @@ -112,7 +115,12 @@ def plot_xy(X, Y, xlabel=None, ylabel=None, title=None, output=None): if ylabel is not None: ax1.set_ylabel(ylabel) plt.subplots_adjust(left=0.1, bottom=0.1, right=0.99, top=0.99) - plt.plot(X, Y, "bo", markersize=2) + if family: + cm = plt.get_cmap('brg', len(Y)) + for i, YY in enumerate(Y): + plt.plot(np.arange(len(YY)), YY, "-", markersize=2, color=cm(i)) + else: + plt.plot(X, Y, "bo", markersize=2) if output: plt.savefig(output) with open('{}.txt'.format(output), 'w') as f: -- cgit v1.2.3