diff options
author | Dmitry Butyugin <dmbutyugin@google.com> | 2020-12-05 23:48:03 +0100 |
---|---|---|
committer | KevinOConnor <kevin@koconnor.net> | 2020-12-19 11:58:35 -0500 |
commit | 5ccc17042c03667e41abf770b3087294a4f78810 (patch) | |
tree | 13850cda299063fc79fe20cca7fd7ca7072972c0 /scripts/graph_accelerometer.py | |
parent | f84a570dde9bbab7b3f176c2a1e14ff80b56ecc2 (diff) | |
download | kutter-5ccc17042c03667e41abf770b3087294a4f78810.tar.gz kutter-5ccc17042c03667e41abf770b3087294a4f78810.tar.xz kutter-5ccc17042c03667e41abf770b3087294a4f78810.zip |
scripts: Small improvements for input shaper and accelerometer scripts
Signed-off-by: Dmitry Butyugin <dmbutyugin@google.com>
Diffstat (limited to 'scripts/graph_accelerometer.py')
-rwxr-xr-x | scripts/graph_accelerometer.py | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/scripts/graph_accelerometer.py b/scripts/graph_accelerometer.py index 0e975bf5..f6d7cf89 100755 --- a/scripts/graph_accelerometer.py +++ b/scripts/graph_accelerometer.py @@ -12,10 +12,20 @@ sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'klippy', 'extras')) from shaper_calibrate import ShaperCalibrate -MAX_TITLE_LENGTH=80 +MAX_TITLE_LENGTH=65 -def parse_log(logname): - return np.loadtxt(logname, comments='#', delimiter=',') +def parse_log(logname, opts): + with open(logname) as f: + for header in f: + if not header.startswith('#'): + break + if not header.startswith('freq,psd_x,psd_y,psd_z,psd_xyz'): + # Raw accelerometer data + return np.loadtxt(logname, comments='#', delimiter=',') + # Power spectral density data or shaper calibration data + opts.error("File %s does not contain raw accelerometer data and therefore " + "is not supported by graph_accelerometer.py script. Please use " + "calibrate_shaper.py script to process it instead." % (logname,)) ###################################################################### # Raw accelerometer graphing @@ -185,7 +195,7 @@ def setup_matplotlib(output): def main(): # Parse command-line arguments - usage = "%prog [options] <logs>" + usage = "%prog [options] <raw logs>" opts = optparse.OptionParser(usage) opts.add_option("-o", "--output", type="string", dest="output", default=None, help="filename of output graph") @@ -205,7 +215,7 @@ def main(): opts.error("Incorrect number of arguments") # Parse data - datas = [parse_log(fn) for fn in args] + datas = [parse_log(fn, opts) for fn in args] setup_matplotlib(options.output) @@ -215,6 +225,8 @@ def main(): if options.compare: opts.error("comparison mode is not supported with csv output") if options.specgram: + if len(args) > 1: + opts.error("Only 1 input is supported in specgram mode") pdata, bins, t = calc_specgram(datas[0], options.axis) write_specgram(pdata, bins, t, options.output) else: @@ -223,8 +235,12 @@ def main(): # Draw graph if options.raw: + if len(args) > 1: + opts.error("Only 1 input is supported in raw mode") fig = plot_accel(datas[0], args[0]) elif options.specgram: + if len(args) > 1: + opts.error("Only 1 input is supported in specgram mode") fig = plot_specgram(datas[0], args[0], options.max_freq, options.axis) elif options.compare: fig = plot_compare_frequency(datas, args, options.max_freq) |