diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2013-01-21 12:44:51 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2013-01-21 12:44:51 +0100 |
commit | 8a49454d28ebfe8746d601d8085f978481374117 (patch) | |
tree | e243d98834fc645aefc88c63c283c01a9e5d48d2 | |
parent | a9c9f31951f8d04d530aa0e7f8f5b60d4794155f (diff) |
scripts/random-muscle-activation.py: Allow to specify initial value interval
-rwxr-xr-x | scripts/random-muscle-activation.py | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/scripts/random-muscle-activation.py b/scripts/random-muscle-activation.py index 587661e..981cac2 100755 --- a/scripts/random-muscle-activation.py +++ b/scripts/random-muscle-activation.py @@ -32,6 +32,8 @@ options: -f force overwrite of existing file -n N set number of data points to N (default: {}) -p plot data after generating it + -i N set minimum initial y value to N (default: {}) + -I N set maximum initial y value 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: {}) @@ -39,16 +41,17 @@ options: -d N set minimum y change value to N (default: {}) -D N set maximum y change value to N (default: {})""".format( os.path.basename(sys.argv[0]), DEFAULT_N, + DEFAULT_YMIN, DEFAULT_YMAX, DEFAULT_XMIN, DEFAULT_XMAX, DEFAULT_YMIN, DEFAULT_YMAX, DEFAULT_YDMIN, DEFAULT_YDMAX)) -def generate_activation_data(N, xmin, xmax, ymin, ymax, ydmin, ydmax): +def generate_activation_data(N, xmin, xmax, ymin, ymax, ydmin, ydmax, imin, imax): 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) ]) - Y[0] = (ymax - ymin) * np.random.random_sample() + ymin + Y[0] = (imax - imin) * np.random.random_sample() + imin for y in range(1, N): Y[y] = Y[y-1] + ((ydmax - ydmin) * np.random.random_sample() + ydmin) if Y[y] < ymin: @@ -62,7 +65,7 @@ def generate_activation_data(N, xmin, xmax, ymin, ymax, ydmin, ydmax): def main(): try: - opts, args = getopt.getopt(sys.argv[1:], "fn:px:X:y:Y:d:D:h") + opts, args = getopt.getopt(sys.argv[1:], "fn:pi:I:x:X:y:Y:d:D:h") except getopt.GetoptError as err: print(str(err)) usage() @@ -71,6 +74,8 @@ def main(): do_overwrite = False do_plot = False N = DEFAULT_N + imin = DEFAULT_YMIN + imax = DEFAULT_YMAX xmin = DEFAULT_XMIN xmax = DEFAULT_XMAX ymin = DEFAULT_YMIN @@ -89,6 +94,20 @@ def main(): sys.exit(-1) elif o == '-p': do_plot = True + elif o == '-i': + try: + imin = float(a) + except ValueError: + print("Error: imin must be a float") + usage() + sys.exit(-1) + elif o == '-I': + try: + imax = float(a) + except ValueError: + print("Error: imax must be a float") + usage() + sys.exit(-1) elif o == '-x': try: xmin = float(a) @@ -153,6 +172,18 @@ def main(): print("Error: ydmin must be smaller than or equal to ydmax") sys.exit(-1) + if not imin < imax: + print("Error: imin must be smaller than imax") + sys.exit(-1) + + if imin < ymin or imin > ymax: + print("Error: imin must be between ymin and ymax ({} <= {} <= {})".format(ymin, imin, ymax)) + sys.exit(-1) + + if imax < ymin or imax > ymax: + print("Error: imax must be between ymin and ymax ({} <= {} <= {})".format(ymin, imax, ymax)) + sys.exit(-1) + if len(args) < 1: print("Error: no output file(s) specified") sys.exit(-1) @@ -165,7 +196,7 @@ def main(): print("Generating {} files with {} data points each...".format(len(args), N)) for a in args: with open(a, 'w') as f: - act = generate_activation_data(N, xmin, xmax, ymin, ymax, ydmin, ydmax) + act = generate_activation_data(N, xmin, xmax, ymin, ymax, ydmin, ydmax, imin, imax) f.write('x,y\n') for x, y in act: f.write('{},{}\n'.format(x, y)) |