Week 6 - Data analysis
Aim :
1)To utilise data from file also check for file compatibility
2)plot required plots
Introduction:
python is great language for data analysis and data visualisation in these project we will analyse engine_data.out file and plot data
Code for data analysis-
"""
data visualisation
"""
import matplotlib.pyplot as plt
import numpy as np
import math
import sys
#file open
try:
f =open('engine_data.out','r')
except:
print('file not found')
sys.exit(1)
value=[]
#reading
for line in f:
if '#' not in line :
values =line.split()
value.append(values)
col1 =np.transpose(value)
col1 =col1.astype(np.float)
#area
xvar =col1[1]
yvar =col1[7]
dx=[]
k=0
while k<8664 :
dif =xvar[k+1]-xvar[k]
dx.append(dif)
k=k+1
w=[]
work =0
t=0
while t< 8664 :
w.append(((dx[t])/2)*(yvar[0]+2*(yvar[t+1])+yvar[8664]))
t=t+1
for n in range(0,len(w)):
work =work+w[n]
#work
work =work*1000000
print('work output in joules is ')
print(abs(work))
print('power output in watt is ')
power =(work*2*1500*math.pi*0.001)/60
print(abs(power))
print('specific fuel consumption in gram/joule is ')
bsfc =0.02/abs(power)
print(bsfc)
name =['Crank','Pressure','Max_pres','Min_pres','Mean_Temp','Min temp','Max temp','Volume','Mass','Density','Integrated_HR','C_p','C_v','Gamma','Kin_Visc','Dyn_Visc']
print('Press \n 1 for Crank \n 2 for pressure \n 3 for Max_pres \n 4 for Min pres \n 5 for Mean_temp \n 6 for Max_temp \n 7 for Min_temp \n 8 for Volume \n 9 for Mass \n 10 for Density \n 11 for Integrated_HR \n 12 for HR_Rate \n 13 for C_p \n 14 for C_v \n 15 for Gamma \n 16 for Kin_Visc \n 17 for Dyn_Visc')
x=int(input('enter number corresponding to value you want to plot on X-axis & then press enter\n'))
y=int(input('enter number corresponding to value you want to plot on y axis & then press enter\n'))
#plotting
plt.figure(1)
plt.plot(col1[x-1],col1[y-1])
plt.title(name[y-1]+' & '+name[x-1]+' plot',fontsize = 20 , color ='red')
plt.xlabel(name[x-1],fontsize =12)
plt.ylabel(name[y-1],fontsize =12)
plt.savefig(name[x-1] + ' vs ' + name[y-1] + '.png')
plt.show()
#plotting p-V diagram
plt.figure(2)
plt.plot(col1[7],col1[1])
plt.title('P-V diagram',fontsize = 20 ,color ='red')
plt.xlabel('Volume',fontsize =12)
plt.ylabel('Pressure',fontsize =12)
plt.show()
Explaination of code -
importing libraries ,try exept for error handling.
extract the data from file and plot curve by taking input from user
calculate work,power
plot p-v diagram
Output-
plots-