data analysis using PYTHON
Aim:
To write a code for data analysis of engine file and to find the spcific fuel consumption,power output of the engine
Code for data analysis
import math
import numpy as n1
import matplotlib.pyplot as plt
import sys
try:
open('engine_ .out','r')
print('hi')
except :
print('File not recognized. Please provide a valid CONVERGE output file!')
sys.exit()
f=open('engine_data.out','r')
for i,l1 in enumerate(f):
if '#' in l1:
if i==2:
e=l1.split()
x=1
y=7
xname=e[x]
yname=e[y]
xdata=[]
ydata=[]
for line in open('engine_data.out','r'):
if '#' not in line:
d=line.split()
xdata.append(float(d[x-1]))
ydata.append(float(d[y-1]))
plt.plot(xdata,ydata)
plt.xlabel(e[x])
plt.ylabel(e[y])
plt.show()
x=1
y=7
volume=[]
pressure=[]
n=1500 #rpm
for line in open('engine_data.out','r'):
if '#' not in line:
a=line.split()
pressure.append(float(a[x]))
volume.append(float(a[y]))
plt.plot(volume,pressure)
plt.xlabel('volume')
plt.ylabel('pressure')
plt.show()
area=n1.trapz(pressure,volume)
print('area under pv diagram is',area)#cm^2
''' in y axis pressure would in Mpa'''
workdone=area*pow(10,6) # Nm
power=2*math.pi*workdone*n/(60*1000) # KW
print(power)
fuel=20e-6 # gram
sfc=(3600*fuel*n)/(60*power) #g/kw.hr
print(sfc)
I used enumerate keyword.It assigns the value for the individual line, assigned values are stored in I variable.I want the 3rd line so using the if condition i==2. I separated out the 3rd line and split it out.Store the split value in a variable and I choose column no as input ( x,y ) and it used to assign a label in the graph.By using the trapz command area of the pv diagram is calculated. From this area power output of the engine is calculatted
COMMAND WINDOW
OUTPUT GRAPH
COMPATIBILITY CHECK
I changed the filename in the try section
Thank You