In [1]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os
In [2]:
dirPath = os.path.realpath('.')
fileName = 'rawData/lab 6 measurements.xlsx'
filePath = os.path.join(dirPath, fileName)
df = pd.read_excel(filePath,sheetname="Part1",header=0)
print(df)
cols = df.columns
In [3]:
plt.figure(1)
plt.errorbar(df[cols[0]],df[cols[2]],xerr=2*df[cols[1]],yerr=2*df[cols[3]])
plt.errorbar(df[cols[4]],df[cols[6]],xerr=2*df[cols[5]],yerr=2*df[cols[7]])
plt.title('Voltage vs delta h')
plt.xlabel('delta h (cm)')
plt.ylabel('Voltage (mV)')
plt.legend(['Ramp Down','Ramp Up'])
plt.grid()
plt.savefig('pressure.png')
plt.show()
In [4]:
plt.figure(1)
plt.errorbar(df[cols[0]],df[cols[2]],xerr=2*df[cols[1]],yerr=2*df[cols[3]])
plt.errorbar(df[cols[4]],df[cols[6]],xerr=2*df[cols[5]],yerr=2*df[cols[7]])
plt.title('Voltage vs delta h (Hysteresis Effects)')
plt.xlabel('delta h (cm)')
plt.ylabel('Voltage (mV)')
plt.legend(['Ramp Down','Ramp Up'])
plt.axis([-10,1,-50,5])
plt.grid()
plt.savefig('pressureHysteresis.png')
plt.show()
In [5]:
sensitivity = df['V (mV)'][1:]/df['deltah(cm)'][1:]
print('sensitivity =',np.average(sensitivity), 'mV/cm')
sens_error = np.sqrt((df['error(cm)'][1:]/df['V (mV)'][1:])**2 + (df['error (mV)'][1:]/df['deltah(cm)'][1:])**2)*sensitivity
print('sensitivity error =', np.average(sens_error), 'mV/cm')
In [6]:
sensitivity_h = (270+df['V (mV).1'][1:10])/(75+df['deltah(cm).1'][1:10])
print(sensitivity_h)
print('sensitivity =',np.average(sensitivity_h), 'mV/cm')
sens_error_h = np.sqrt((df['error(cm).1'][1:10]/df['V (mV).1'][1:10])**2 + (df['error (mV)'][1:10]/df['deltah(cm).1'][1:10])**2)*sensitivity_h
print('sensitivity error =', np.average(sens_error_h), 'mV/cm')
In [7]:
# difference in sensitivity
diff = np.abs(np.average(sensitivity_h)-np.average(sensitivity))
diff_error = np.sqrt(np.average(sens_error_h)**2 + np.average(sens_error)**2)
print('difference in sens =',diff)
print(diff_error)
In [8]:
hysteresisOffset = df[cols[1]][0]-df[cols[6]][len(df[cols[4]])-1]
print('Hysteresis Offset =', hysteresisOffset,'mV')
hysteresisError = np.sqrt(1**2 + 1**2)
print('Hysteresis Error =',hysteresisError, 'mV')
In [9]:
dfangle = pd.read_excel(filePath,sheetname="accelAngle",header=0)
print(dfangle)
colsangle = dfangle.columns
In [10]:
plt.figure(2)
plt.errorbar(dfangle[colsangle[0]],dfangle[colsangle[2]],xerr=2*dfangle[colsangle[1]],yerr=2*dfangle[colsangle[3]])
plt.grid()
plt.title('Voltage vs Angle')
plt.xlabel('Angle (degrees)')
plt.ylabel('Voltage (mV)')
plt.savefig('accelAngle.png')
plt.show()
In [11]:
Vout = dfangle['Voltage (mV)'][1:8]
accelSensitivity = Vout/(np.cos(np.deg2rad(dfangle['Angle (deg)'][1:8])))
accelError = np.sqrt(1/30**2 + 0.5/628**2)*727
print('Accel Sensitivity =',np.average(accelSensitivity), 'mV/g')
print('Accel Error =', accelError, 'mV/g')
print(accelSensitivity)
print('std dev.', np.std(accelSensitivity))
print('variance', np.var(accelSensitivity))
dfangle['Voltage (mV)']
Out[11]:
In [12]:
dfstatic = pd.read_excel(filePath,sheetname="staticMeasurements",header=0)
print(dfstatic)
colsstatic = dfstatic.columns
In [13]:
gravity = 9.81 # m/s/s
kstatic = dfstatic['Force']/dfstatic['disp (m)']
print('kstatic')
print(kstatic)
kstatic_error = kstatic*np.sqrt((dfstatic['Force Error']/dfstatic['Force'])**2 + (dfstatic['error (cm)']/dfstatic['Displacement (cm)'])**2)
print('\n error in kstatic =')
print(kstatic_error)
In [14]:
dfdynamic = pd.read_excel(filePath,sheetname="dynamicMeasurements",header=0)
print(dfdynamic)
colsdynamic = dfdynamic.columns
NOTE: We also need to define the mass
In [15]:
MASS = 0.2772
In [16]:
kdynamic = MASS*dfdynamic['omega']**2
print('kdynamic =')
print(kdynamic)
print(np.average(kdynamic))
# now calculate error
num = range(0,5)
kdynamic_error = dfdynamic['error']/dfdynamic['freq (Hz)']*kdynamic*2
print('\nkdynamic error =')
print(kdynamic_error)
print(np.average(kdynamic_error))
print(np.var(kdynamic))
In [17]:
plt.figure(4)
plt.errorbar(num,kdynamic,yerr=kdynamic_error,fmt='o')
plt.title('Kdynamic, multiple calculations')
plt.xlabel('Trial Number')
plt.ylabel('k dynamic (N/m)')
plt.legend(['k dynamic'])
plt.axis([-0.1,4.1,0,55])
plt.grid()
plt.savefig('kdynamic.png')
plt.show()