Python 2.7.8 Too Few Args or No such file\directory -
new python assume i'm ignorant part. i've spent several hours searching haven't been able implement prepare file written peer. let's i'm embarrassed can't figure out on own , don't want inquire help. i'm hoping won't see this. here code run in terminal plotting info in cvs file.
import argparse import matplotlib.pyplot plt import numpy np import scipy import scipy.fftpack def read_data(filename, period): """ parse input filename, returning dict accel , gyro x, y, , z period of samples given in ms """ # period seconds period = period/1000. open(filename, "rb") f: info = np.loadtxt(f,delimiter=",",skiprows=1) ret = {'accel': {}, 'gyro': {}} ret['time'] = np.arange(0, data.shape[0]*period, period) ret['accel']['x'] = data[:,0] ret['accel']['y'] = data[:,1] ret['accel']['z'] = data[:,2] ret['gyro']['x'] = data[:,3] ret['gyro']['y'] = data[:,4] ret['gyro']['z'] = data[:,5] homecoming ret def plot_data(data): """ plot data, given in form returned read_data plt.show() must called display plots. """ plt.figure() plt.plot(data['time'], data['accel']['x']) plt.title('x acceleration') plt.xlabel('time (s)') plt.ylabel('acceleration (g)') plt.figure() plt.plot(data['time'], data['accel']['y']) plt.title('y acceleration') plt.xlabel('time (s)') plt.ylabel('acceleration (g)') plt.figure() plt.plot(data['time'], data['accel']['z']) plt.title('z acceleration') plt.xlabel('time (s)') plt.ylabel('acceleration (g)') plt.figure() plt.plot(data['time'], data['gyro']['x']) plt.title('x rotational rate') plt.xlabel('time (s)') plt.ylabel('rotational rate (deg/s)') plt.figure() plt.plot(data['time'], data['gyro']['y']) plt.title('y rotational rate') plt.xlabel('time (s)') plt.ylabel('rotational rate (deg/s)') plt.figure() plt.plot(data['time'], data['gyro']['z']) plt.title('z rotational rate') plt.xlabel('time (s)') plt.ylabel('rotational rate (deg/s)') def compute_fft(data, period): """ compute fft of components of data, given in form returned read_data(). sample period given in ms. """ # period seconds period = period/1000. fft = {'accel': {}, 'gyro': {}} fft['freq'] = scipy.fftpack.fftfreq(data['time'].shape[0], d=period) fft['accel']['x'] = scipy.fftpack.fft(data['accel']['x']) fft['accel']['y'] = scipy.fftpack.fft(data['accel']['y']) fft['accel']['z'] = scipy.fftpack.fft(data['accel']['z']) fft['gyro']['x'] = scipy.fftpack.fft(data['gyro']['x']) fft['gyro']['y'] = scipy.fftpack.fft(data['gyro']['y']) fft['gyro']['z'] = scipy.fftpack.fft(data['gyro']['z']) homecoming fft def plot_fft(fft): """ plot fft data, given in form returned compute_fft(). """ plt.figure() plt.plot(fft['freq'], 20*scipy.log10(fft['accel']['x']), 'x') plt.title('x acceleration fft') plt.xlabel('frequency (hz)') plt.ylabel('magnitude (db)') plt.figure() plt.plot(fft['freq'], 20*scipy.log10(fft['accel']['y']), 'x') plt.title('y acceleration fft') plt.xlabel('frequency (hz)') plt.ylabel('magnitude (db)') plt.figure() plt.plot(fft['freq'], 20*scipy.log10(fft['accel']['z']), 'x') plt.title('z acceleration fft') plt.xlabel('frequency (hz)') plt.ylabel('magnitude (db)') plt.figure() plt.plot(fft['freq'], 20*scipy.log10(fft['gyro']['x']), 'x') plt.title('x rotational rate fft') plt.xlabel('frequency (hz)') plt.ylabel('magnitude (db)') plt.figure() plt.plot(fft['freq'], 20*scipy.log10(fft['gyro']['y']), 'x') plt.title('y rotational rate fft') plt.xlabel('frequency (hz)') plt.ylabel('magnitude (db)') plt.figure() plt.plot(fft['freq'], 20*scipy.log10(fft['gyro']['z']), 'x') plt.title('z rotational rate fft') plt.xlabel('frequency (hz)') plt.ylabel('magnitude (db)') if __name__ == "__main__": parser = argparse.argumentparser(description='plot accel , gyro data') parser.add_argument('file', help='csv file data') parser.add_argument('period', type=float, help='sample period in ms') args = parser.parse_args() info = read_data(args.file, args.period) fft = compute_fft(data, args.period) print "max accel x freq: %f" % (fft['freq'][fft['accel']['x'].argmax()]) print "max accel y freq: %f" % (fft['freq'][fft['accel']['y'].argmax()]) print "max accel z freq: %f" % (fft['freq'][fft['accel']['z'].argmax()]) print "max gyro x freq: %f" % (fft['freq'][fft['gyro']['x'].argmax()]) print "max gyro y freq: %f" % (fft['freq'][fft['gyro']['y'].argmax()]) print "max gyro z freq: %f" % (fft['freq'][fft['gyro']['z'].argmax()]) plot_data(data) plot_fft(fft) plt.show()
here command used in terminal window , error.
c:\users\documents>c:\python27\python.exe fft.py shake_1ms.cvs, 1 traceback (most recent phone call last): file "fft.py", line 144, in <module> info = read_data(args.file, args.period) file "fft.py", line 17, in read_data open(filename, "rb") f: ioerror: [errno 2] no such file or directory: 'shake_1ms.cvs,'
i beginner python , forwards help can suggested.
the exception stating it's not able find shake_1ms.cvs
in directory c:\users\documents
. may have meant type shake_1ms.csv
comma-separated value file (notice csv
extension instead of cvs
).
...unless of course of study recording accelerometer info cvs pharmacy...
python python-2.7 ioerror
No comments:
Post a Comment