From aed96a10b28c70f2f3d6e5432a0b402d099a33c8 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 8 Jan 2013 15:47:14 +0100 Subject: scripts: random-muscle-activation: Add basic script structure No random data yet (just 0 for y values) --- scripts/random-muscle-activation.py | 122 ++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100755 scripts/random-muscle-activation.py (limited to 'scripts') diff --git a/scripts/random-muscle-activation.py b/scripts/random-muscle-activation.py new file mode 100755 index 0000000..e0c3899 --- /dev/null +++ b/scripts/random-muscle-activation.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2013 Tobias Klauser +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. + +import os +import sys +import getopt +import numpy as np + +DEFAULT_N = 1000 +DEFAULT_XMIN = 0.0 +DEFAULT_XMAX = 100.0 +DEFAULT_YMIN = 0.0 +DEFAULT_YMAX = 50.0 + +def usage(): + print("""usage: {} [OPTION...] FILE... + + -f force overwrite of existing file + -n N set number of data points to N (default: {}) + -x N set minimum x value to N (default: {}) + -X N set maximum x value to N (default: {}) + -y N set minimum y value to N (default: {}) + -Y N set maximum y value to N (default: {}) +""".format(os.path.basename(sys.argv[0]), DEFAULT_N, DEFAULT_XMIN, DEFAULT_XMAX, + DEFAULT_YMIN, DEFAULT_YMAX)) + +def generate_activation_data(N, xmin, xmax, ymin, ymax): + X = np.array([ ((x / float(N)) * (xmax - xmin)) + xmin for x in range(0, N) ]) + Y = np.zeros(N) + # Y = np.array([ ((y / float(N)) * (ymax - ymin)) + ymin for y in range(0, N) ]) + act = np.array((X, Y)).transpose() + + return act + +def main(): + try: + opts, args = getopt.getopt(sys.argv[1:], "fn:x:X:y:Y:h") + except getopt.GetoptError as err: + print(str(err)) + usage() + sys.exit(-1) + + overwrite = False + N = DEFAULT_N + xmin = DEFAULT_XMIN + xmax = DEFAULT_XMAX + ymin = DEFAULT_YMIN + ymax = DEFAULT_YMAX + for o, a in opts: + if o == '-f': + overwrite = True + elif o == '-n': + try: + N = int(a) + except ValueError: + print("Error: number of data points must be an integer > 0") + usage() + sys.exit(-1) + elif o == '-x': + try: + xmin = float(a) + except ValueError: + print("Error: xmin must be a float") + usage() + sys.exit(-1) + elif o == '-X': + try: + xmax = float(a) + except ValueError: + print("Error: xmax must be a float") + usage() + sys.exit(-1) + elif o == '-y': + try: + ymin = float(a) + except ValueError: + print("Error: ymin must be a float") + usage() + sys.exit(-1) + elif o == '-Y': + try: + ymax = float(a) + except ValueError: + print("Error: ymax must be a float") + usage() + sys.exit(-1) + elif o == '-h': + usage() + sys.exit(0) + + if N <= 0: + print("Error: invalid number of data points ({}), must be > 0".format(N)) + usage() + sys.exit(-1) + + if len(args) < 1: + print("Error: no output file(s) specified") + usage() + sys.exit(-1) + + for a in args: + if not overwrite and os.path.exists(a): + print("Error: output file {} already exists, use -f to overwrite".format(a)) + sys.exit(-1) + + for a in args: + with open(a, 'w') as f: + act = generate_activation_data(N, xmin, xmax, ymin, ymax) + f.write('x,y\n') + for x,y in act: + f.write('{},{}\n'.format(x,y)) + + sys.exit(0) + +if __name__ == '__main__': + main() -- cgit v1.2.3-54-g00ecf