Data Analysis- Engine Data file (using Python)
Aim: To perform the data analysis using Python as the scripting language and to
a) Plot a graph between any two quantities (like pressure vs volume, mean temperature vs crank etc)
b) Calculate the area under the 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)
Link for the engine data file:
https://drive.google.com/file/d/1L8GY56d-M8mB1KfceM-xVhGNvnCIqxjm/view
Introduction:
Data Analysis is a process of inspecting, cleansing, transforming and modelling data with the goal of discovering useful information, informing conclusions and supporting decision- making. Data analysis has multiple facets and approaches, encompassing diverse techniques under various names, and is often used in various domains like business, science, and social science.
The process of data analysis has following steps-
i) Data Collection
ii) Data Processing
In data analysis, our prime focus is to read the data from a suitable file format, to analyse the data, plot the graphs, calculate the area under the given curve, calculate the power and specific fuel consumption.
CODE:
CASE 1- Code for performing data analysis and data visualization
# Program to perform the Data analysis- using the engine data file
# 1.To visualize the engine data.
# 2.To check Compatability of file.
# importing basic modules/libraries
from matplotlib.pyplot import *
# Defining the inputs and arrays
linecount = 1
c_num = []
c_name = []
c_units = []
count = 1
t_1 = []
t_2 = []
# To plot a graph between column 5 (Mean Temperature) and column 1(crank angle)
t1 = 0
t2 = 4
# to check compatibility of the file
# if any errors in try block the program will not crash
try:
engine_data = open('engine_data.out', 'r')
for line in engine_data:
for i in range(0, 19):
# i >=2 because there are two extra elements in that row before numbering in the file.
if i >= 2:
if count == 2:
# appending all column number, count==2 because row 2 has column names
c_num.append(int(line.split()[i]))
for j in range(0, 18):
# j >=1 because there are one extra elements in that row in the file.
if j >= 1:
# appending all names of the column. count==3 because column names are in 3rd row
if count == 3:
c_name.append(line.split()[j])
# appending all units of column, count==4 because column units are in 4th row
elif count == 4:
c_units.append(line.split()[j])
# appending all values and avoiding # in file
if '#' not in line:
if count >= 6:
t_1.append(float(line.split()[t1]))
t_2.append(float(line.split()[t2]))
count += 1
# Plotting the graph and automatically labelling.
figure()
plot(t_1, t_2)
title('Plot of ' + str(c_name[t2]) + ' V/S ' + str(c_name[t1]))
xlabel(str(c_name[t1]) + str(c_units[t1]))
ylabel(str(c_name[t2]) + str(c_units[t2]))
savefig(str(c_name[t2]) + ' vs ' + str(c_name[t1]))
show()
# closing the file.
engine_data.close()
# this block will run only if error occured
# it will show which error has occured..
except Exception as error:
print(error)
# this block will run if there is no error
else:
print("NO Errors Occured")
# it always runs no matter what if error occured in try: or not...
# its useful printing or using must commands of program
finally:
pass
EXPLANATION OF THE CODE:
Firstly, we import all the basic libraries/modules for successfully executing the program.
For opening and reading the data file, we make use of the command called as open.
In this program, we make use of try and except commands to display the error prompt if a suitable or compatible file format is not provided. The command try will run if there is no exception and an additional command called as else will run if there is no exception which is ensured when the 'try' command is executed. Under the 'else' command, the necessary inputs and arrays are defined and created and then the two variables for column numbers are initialised by assigning them the respective values.
The area under the curve(work), power and specific fuel consumption are calculated by successfully running the code.
OUTPUTS:
When a non-compatible file is provided as an input-
An error reading that no file or directory found ; when the file was not present in the folder containing the code.
PLOTS:
Few other sample plots when the column numbers are adjusted to plot the desirable graphs.
CALCULATION OF BASIC PERFORMANCE:
CASE 2- Code for performing data analysis, data visualization and calculation of area under P-V diagram, the power output of an engine running at a speed of 1500 RPM and specific fuel consumption.
#Basic performance calculation
# importing libraries or basic modules
from matplotlib.pyplot import *
from scipy.integrate import *
# Defining inputs and arrays
line_count = 1
c_num = []
c_name = []
c_units = []
count = 1
t_1 = []
t_2 = []
# To plot a graph between column 5 (Mean Temperature) and column 1(crank angle)
t1 =0
t2 =4
# to check compatibility of the file
# if any errors in try block the program will not crash
try:
engine_data = open('engine_data.out', 'r')
for line in engine_data:
for i in range(0, 19):
# i >=2 because there are two extra elements in that row before numbering in the file.
if i >= 2:
if count == 2:
# appending all column number, count==2 because row 2 has column names
c_num.append(int(line.split()[i]))
for j in range(0, 18):
# j >=1 because there are one extra elements in that row in the file.
if j >= 1:
# appending all names of the column. count==3 because column names are in 3rd row
if count == 3:
c_name.append(line.split()[j])
# appending all units of column, count==4 because column units are in 4th row
elif count == 4:
c_units.append(line.split()[j])
# appending all values and avoiding # in file
if '#' not in line:
if count >= 6:
t_1.append(float(line.split()[t1]))
t_2.append(float(line.split()[t2]))
count += 1
# closing the file.
engine_data.close()
#To Calculate the area under the P-V diagram
area=simps(t_2,t_1)*pow(10,6)
print('Area under pv curve:',area,'Joules')
# To Calculate the power output of this engine
# give
N=1500
n=1
s=4
x=2
p=n*area*N/(60*1000*x)
print('The output power of engine:',p,'KW')
#To Calculate its specific fuel consumption
#given
m=20
#fuel consumption
fc=N*60*(m*pow(10,-9)/2)
# specific fuel consumption
sfc=fc/p
print('Specific Fuel Consumption:',sfc,'(Kg/hr)/KW')
# This block will run only if an error occurs
# It will show which error has occurred
except Exception as error:
print(error)
# This block will run if there is no error
else:
print("No Errors Occured")
finally:
pass
RESULTS:
Command window with the required results and conveying that no errors took place.