A quick-and-dirty script to generate data to feed to R. Typical usage:
gen_testcases_r_finder.py 2000 100000 2000 5
writes a script of r_finder.py commands starting from 2000 ohms incrementing by 2000 ohms up to 100,000 ohms at a tolerance of 5%. It then executes the generated script which writes the raw data to a default file named r_finder.dat.
import argparse import os import stat import subprocess parser = argparse.ArgumentParser() parser.add_argument('start', type=int, help='Starting resistance') parser.add_argument('end', type=int, help='Ending resistance') parser.add_argument('stride', type=int, help='Stride value e.g. 1, 3, 5, . . . has stride 2') parser.add_argument('tolerance', type=float, help='Tolerance of solution') args = parser.parse_args() start = args.start end = args.end stride = args.stride tolerance = args.tolerance file_name = "./testcases_r_finder.sh" outfile = open(file_name, "w") outfile.write("#!/bin/sh\n") for i in range(start, end, stride): outfile.write("./r_finder.py %d %f --record > /dev/null 2>&1\n" % (i, tolerance)) outfile.close() os.chmod(file_name, stat.S_IRWXU|stat.S_IRWXG|stat.S_IRWXO) subprocess.call(file_name) exit(0)