Week 6 - Data analysis
Aim:
Performing data Analysis on Engine Performance Data using PYTHON.
Objective -
There are four objectives :-
To perform data analysis and
a) plot a graph between any two quantities (like pressure vs volume, pressure vs crank, crank vs volume, etc.)
b) calculate the area under P-V diagram
c) calculate the power output of an engine running at a speed of 1500 RPM
d) calculate the specific fuel consumption for an engine which consumes 20 micro grams of fuel (per 1 stroke cycle)
PROCEDURE
- Initially we are going to import the “matplotlib.pyplot” and “numpy” libraries to plot the graph and calculate the values.
- First we save the program and then data file and program file is in the same folder.
- The “try and except” command used to check the data file is in the same folder or it has name mistake.
- Then we are going to open the file using the “for loop” command and then we read the data line by line. And using some counting line, if and else commands to separate the heading and numerical data.
- Using “line.split” command to split all the data present in the data file.
- For easy to calculate we creating some input commands to plot the graphs. The data input in the x-axis and y-axis.
- Then we create two empty arrays for the x input and the y input and then we read the data again. The data created then using the float, the values float and append all the values for the x and y input arrays.
- We create the plot command for the x and y input arrays and then we make all the labels and the title of the graph.
- After that we calculate the area under the curve of a PV diagram and we know that the area under the curve is work done.
- Then we calculate the power output the engine and Specific Fuel Consumption and then we print the values.
PROGRAM
#program for data anaylsis
#by Sallavodiin
"""
Demonstrating the engine data analysis
"""
import matplotlib.pyplot as plt
import math
import numpy as np
#import numpy as np
try:
file=open('engine_data.out')
print('data is found successfully! Now you can proceed to the next Calculationsn')
except:
print('unfortunately the data is not found.Please check the file or filenamen')
file.close()
print('Information about input parameters')
pressure=[]
temperature=[]
volume=[]
column_name=[]
column_units=[]
#data parsing
count_data=1
for line in open('engine_data.out'):
if '#' not in line:
count_data=count_data+1
else:
count_data=count_data+1
if count_data == 4:
column_name=line.split()
print(column_name)
elif count_data==5:
coulumn_units=line.split()
#inputs
nx = int(input("Please enter the x-axis data of column(1-17) 1.Crank to 17.Dynamic Viscosity"))
print(nx-1)
ny = int(input("Please enter the y-axis data of column(1-17) 1.Crank to 17.Dynamic Viscosity"))
print(ny-1)
print('the plot is',column_name[ny],"vs",column_name[nx])
data_array_x=[]
data_array_y=[]
for line in open('engine_data.out'):
if '#' not in line:
data_array_x.append(float(line.split()[nx-1]))
#print(data_array_x)
for line in open('engine_data.out'):
if '#' not in line:
data_array_y.append(float(line.split()[ny-1]))
#print(data_array_y)
#plotting the data
plt.plot(data_array_x,data_array_y)
plt.xlabel(column_name[nx]+coulumn_units[nx])
plt.ylabel(column_name[ny]+coulumn_units[ny])
plt.title(column_name[nx]+column_name[ny]+'Diagram')
plt.savefig(column_name[nx]+'VS'+column_name[ny]+'.png')
plt.show()
for line in open('engine_data.out'):
if '#' not in line:
pressure.append(float(line.split()[1]))
volume.append(float(line.split()[7]))
#calculating area under the pv curve
work=[]
for i in range(0,8664):
work.append((volume[i+1]-volume[i])*(pressure[i+1]+pressure[i])*0.5)
work_done=0
for j in range(0,len(work)):
work_done=work_done+work[j]
work_done1=work_done*1*1e6
print('Workdone is',work_done1,'j')
area=np.trapz(pressure,volume)
#print('the total area under the curve is',area,'m^2')
#calculating power output of the engine
rpm=1500
power=area*1e+06*rpm/9550
print('The power output of the engine is',power,'KW')
#calculating Specific fuel consumption
fps=20*1e-06
mass_flow_rate=2.99*1e-10
SFC=mass_flow_rate*36000/power
print('The specific Fuel Consumption is',SFC,'g/KW hr')
OUTPUT
Result window
PLOTS
PV diagram
crank pressure diagram
crank volume diagram
crank mean temp diagram
CONCLUSIONS
- The area under the PV Diagram curve is calculated. We know that the area under pv diagram is workdone.
- The specific Fuel Consumption(SFC) and power output of the engine also calculated.
- The data visualization is shown in the output window.