#!/usr/bin/env python #------------------------------------------------------------------------------ # Title : maxeff.py # Purpose : plot efficiency targets for a given battery pack # Author : Synthetic Transport (synthetictransport.com) # Date : Oct 2, 2007 #------------------------------------------------------------------------------ import os, sys, getopt, Gnuplot def plotpowerpoints(output, watthours, startspeed, endspeed, startdist, enddist, disttics): g = Gnuplot.Gnuplot(debug=1) g.title('Efficient Power Targets using %0.0f Watthours' %watthours) g('set data style linespoints') g('set key top left') g('set grid') g('set ytics 25') g('set xtics 1') g.xlabel('Speed (MPH)') g.ylabel('Power (Watts)') for i in range(startdist, enddist+1, disttics): curve =[] # calculate efficiency targets for each speed at this distance for x in range(startspeed, endspeed+1): curve.append((x, watthours / (i/float(x)))) g.replot(Gnuplot.Data(curve, title="%d miles (%0.0f Wh/m)" \ %(i, watthours/i))) if output: g.hardcopy(output, enhanced=1, color=1) raw_input('Press return to exit...\n') def usage(msg): sys.stdout = sys.stderr if msg: print msg print 'usage: %s -o(utputfile -w(atthours -s(tartspeed -e(ndspeed -S(tartdist E(nddist' \ %os.path.basename(sys.argv[0]) sys.exit(2) if __name__ == '__main__': try: opts, args = getopt.getopt(sys.argv[1:], 'o:w:s:e:S:E:?') except getopt.error, msg: usage('Incorrect arguments') output = '' watthours = 1440. startspeed = 15. endspeed = 30. startdist = 60. enddist = 100. disttics = 10 for o, a in opts: if o in ['-?', '-h']: usage('') if o == '-o': output = a if o == '-w': watthours = float(a) if o == '-s': startspeed = float(a) if o == '-e': endspeed = float(a) if o == '-E': enddist = float(a) if o == '-S': startdist = float(a) if enddist - startdist <= 20: disttics = 5 if enddist - startdist <= 10: disttics = 2 plotpowerpoints(output, watthours, startspeed, endspeed, startdist, enddist, disttics)