#Imports
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#Load CSVs
noload = pd.read_csv('1030.txt', sep='\t')
noload = noload.drop('Pressure(V)',axis=1)
#Plot of Pressure and Tachometer vs Time
#Point picking
fig, ax1 = plt.subplots(clear=True)
lns1 = ax1.plot(noload['Time (s)'], noload['Pressure (psi)'], 'r-', label='Pressure')
ax1.set(xlim=[10.07, 10.13], title = 'Pressure and Tachometer vs Time', xlabel='Time (s)', ylabel = 'Pressure (psi)')
ax1.plot(10.073415, 19.131265, 'ko', markerfacecolor="none")
ax1.plot(10.081415, 94.526161, 'ko', markerfacecolor="none")
ax1.plot(10.082748, 111.001633, 'ko', markerfacecolor="none")
ax1.plot(10.093081, 34.586826, 'ko', markerfacecolor="none")
ax2 = ax1.twinx()
lns2 = ax2.plot(noload['Time (s)'], noload['Tach Output (V)'], 'b-', label='Tachometer')
ax2.set(ylim=[0, 8], ylabel = 'Tachometer (V)')
#Making legend
lns=lns1+lns2
labs = [l.get_label() for l in lns]
ax1.legend(lns, labs, loc=0)
plt.savefig('Point_Picking.png')
#point 1 pressure
peak = noload[noload['Time (s)']>10.0734]
peak.head(1)
#point 4 pressure
peak = peak[peak['Time (s)'] < 10.0933]
peak.tail(1)
#Point 3 pressure and time
m = np.max(peak['Pressure (psi)'])
t = peak[peak['Pressure (psi)'] == m]['Time (s)'].values[0]
print("Pressure at Point 3: {} \nTime at Point 3: {}".format(m, t))
#Point 2 pressure and time
peak = peak[peak['Time (s)']>10.08141]
peak.head(1)
#Next peak pressure and time
peak2 = noload[noload['Time (s)']>10.11]
peak2 = peak2[peak2['Time (s)']<10.13]
m2 = np.max(peak2['Pressure (psi)'])
t2 = peak2[peak2['Pressure (psi)'] == m2]['Time (s)'].values[0]
print("Pressure at next Point 3: {} \nTime at next Point 3: {}".format(m2, t2))
#Plotting V vs. T
period = 0.04
R = 0.875
L = 2.875
r = 1.2815
omega = np.divide(4*np.pi, period)
def x(t):
return R*(1-np.cos(omega*t)) + np.divide(R**2, L)*((np.sin(omega*t))**2)
def V(t):
return (np.pi*(r**2)*x(t) + 2.0217166)
noload['X (in)'] = x(noload['Time (s)'])
noload['V (in^3)'] = V(noload['Time (s)'])
v_max = max(noload['V (in^3)'].values)
print(v_max)
fig, ax = plt.subplots(clear=True)
ax.plot(noload['Time (s)'], noload['V (in^3)'], 'b-')
ax.set(xlim=[0, 0.08])
ax.set(xlabel = 'Time (s)', ylabel=r'Volume (in$^3$)', title = 'Volume vs. Time at 3000 RPM')
plt.savefig('VolumeTime.png')
#For Plotting PV
cycle = noload[noload['Time (s)'] >= t]
cycle = cycle[cycle['Time (s)'] <= t2]
t_series = cycle['Time (s)'].values - t
v2 = V(0)
p2 = 94.526161
p3 = m
new_t = np.linspace(0, 0.01, 100)
# Pressure vs. Volume
fig, ax = plt.subplots(clear=True)
ax.plot(V(t_series), cycle['Pressure (psi)'], 'bD')
ax.set(xlabel=r'Volume (in$^3$)', ylabel='Pressure (psi)', title='Pressure vs. Volume')
ax.plot([V(0),V(0)],[m,94.526161],'r-')
ax.plot(V(new_t), np.divide(((v2**1.4)*p2), V(new_t)**1.4), 'r-')
ax.plot(V(new_t), np.divide(((v2**1.4)*p3), V(new_t)**1.4), 'r-')
plt.grid()
plt.savefig('PressureVolume.png')