Data analysis-Engine data file
Aim:
To perform data analysis using python.
Objectives:
- To visualize the engine data.
- To check Compatability of file.
- To Basic performance calculation.
Problem Statement:
Data visualizer
- Your script should take column numbers as the input and plot the respective columns as separate images
- Each file should be saved by the name of the column
- The plot labels should be extracted from the file. If, I request for a plot between column 1 (crank angle) and column 8(volume), then the label information should automatically be extracted and must appear as labels in the plots. THIS SHOULD NOT BE DONE MANUALLY
Compatability check
- You code should exit gracefully, if a non-compatible file is provided as an input. It should say something like "File not recognized. Please provide a valid CONVERGE output file"
Basic performance calculation
- Calculate the area under the P-V diagram. P is in column 2 and V is in column 8.
- Calculate the power output of this engine. Assume that RPM is 1500
- This engine consumed 20 micro grams of fuel (per 1 stroke cycle). Calculate its specific fuel consumption.
Theory:
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 a variety of names, and is used in different business, science, and social science domains. In today's business world, data analysis plays a role in making decisions more scientific and helping businesses operate more effectively.[1]
Code:
# Data analysis
# 1.To visualize the engine data.
# 2.To check Compatability of file.
# code by Abhishek Savakar
# importing modules
from matplotlib.pyplot import *
# defining arrays and inputs
line_count = 1
c_num = []
c_name = []
c_units = []
count = 1
t_1 = []
t_2 = []
# for a plot between column 1 (crank angle) and column 8(volume)
t1 =0
t2 = 7
# 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
Code output:
Code output when a non-compatible file is provided as an input:
output screen showing No such file or directory: 'engine_data.out'. when the file was not present in the folder containing the code.
when Ran succesfully:
Output screen showing No errors occured.
Output plots:
other sample plots when column number changed.
Basic performance calculation
Code:
# Data analysis
# 3.To Basic performance calculation.
# code by Abhishek Savakar
# importing modules
from matplotlib.pyplot import *
from scipy.integrate import *
# defining arrays and inputs
line_count = 1
c_num = []
c_name = []
c_units = []
count = 1
t_1 = []
t_2 = []
# for a plot between column 1 (crank angle) and column 8(volume)
t1 =7
t2 = 1
# 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 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
output screen:
Reference: