diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-01-30 16:43:46 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-01-30 16:43:46 +0100 |
commit | 606424e28b40d4754575bb8ebc86f9103b034f16 (patch) | |
tree | f30361267b39487a764666e4f0c0df7d0373b339 /lib | |
parent | c1e6a149318313713a4f2a655c6a1507f1c54f51 (diff) |
keysightdlog: Add plotting
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/keysightdlog.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/keysightdlog.py b/lib/keysightdlog.py index 3864d6e..0cf8da1 100755 --- a/lib/keysightdlog.py +++ b/lib/keysightdlog.py @@ -1,12 +1,35 @@ #!/usr/bin/env python3 import lzma +import matplotlib.pyplot as plt import numpy as np import os import struct import sys import xml.etree.ElementTree as ET +def plot_y(Y, **kwargs): + plot_xy(np.arange(len(Y)), Y, **kwargs) + +def plot_xy(X, Y, xlabel = None, ylabel = None, title = None, output = None): + fig, ax1 = plt.subplots(figsize=(10,6)) + if title != None: + fig.canvas.set_window_title(title) + if xlabel != None: + ax1.set_xlabel(xlabel) + if ylabel != 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 output: + plt.savefig(output) + with open('{}.txt'.format(output), 'w') as f: + print('X Y', file=f) + for i in range(len(X)): + print('{} {}'.format(X[i], Y[i]), file=f) + else: + plt.show() + filename = sys.argv[1] with open(filename, 'rb') as logfile: @@ -73,8 +96,30 @@ for i, channel in enumerate(channels): if i > 0 and channel_type == 'A' and channels[i-1][2] == 'V' and channel_id == channels[i-1][0]: power = data[i-1] * data[i] + power = 3.6 * data[i] print('channel {:d} ({:s}): min {:f}, max {:f}, mean {:f} W'.format( channel_id, channel_model, np.min(power), np.max(power), np.mean(power))) + min_power = np.min(power) + max_power = np.max(power) + power_border = np.mean([min_power, max_power]) + low_power = power[power < power_border] + high_power = power[power >= power_border] + plot_y(power) + print(' avg low / high power (delta): {:f} / {:f} ({:f}) W'.format( + np.mean(low_power), np.mean(high_power), + np.mean(high_power) - np.mean(low_power))) + #plot_y(low_power) + #plot_y(high_power) + high_power_durations = [] + current_high_power_duration = 0 + for is_hpe in power >= power_border: + if is_hpe: + current_high_power_duration += interval + else: + if current_high_power_duration > 0: + high_power_durations.append(current_high_power_duration) + current_high_power_duration = 0 + print(' avg high-power duration: {:f} µs'.format(np.mean(high_power_durations) * 1000000)) #print(xml_header) #print(raw_header) |