Week 6 - Data analysis
AIM: To perform the data analysis of a given data by programming in Python
Theoritical Background:
Data analysis plays a role in making decisions more scientific and helping businesses operate more effectively. Data analysis is a process of inspecting, cleansing, transforming and modeling 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.
Analysis refers to breaking a whole into its separate components for individual examination. Data analysis is a process for obtaining raw data and converting it into information useful for decision-making by users. Data is collected and analyzed to answer questions, test hypotheses.
- Descriptive Analysis.
- Diagnostic Analysis.
- Predictive Analysis.
- Prescriptive Analysis.
The data file given consist of various parameters of an engine. We have to calculate the below parameters
1] Work done by the engine is obtained by calculating the area under the P-V diagram
2] Power output of the engine is given as below

n - Number of cylinders of engine, RPM - engine speed in minutes,WOut - Work output by the engine
3] Specific Fuel Consumption(SFC)

SFC = mass of fuel consumption / Engine brake power = FC / Pb
PROCEDURE :
To solve the above given problem statement, following procedure is followed:
- Using a python program initally the name of the data file is taken as an input from user and checked whether the file is present or not, if the file is not pressent then the program is terminated.
- Then the file is opened and data is read line by line and stored.
- The name of parameters, their units and their coulmn number are stored as an array and dispalyed in form a table for the user to select the required columns.
- Then the column no for independent parameter (x-axis) and dependent parameter (yaxis) is taken from user and the values of those clumn are extracted from data file and further plotted.
- From the PV diagram Area under the P-V curve is calculated using the Trapezoidal Rule As we Know An area under the P-V diagram is equalto Work Done
- In the next step Work was done that is calculated is used for calculating the power output
Power = Work *Speed
- Specific Fuel Consumption = Mass of Fuel Consumption per hour/Power Developed in KW
Code :
# Python code for data analysis
import matplotlib.pyplot as plt
import numpy as np
import math
from numpy import trapz
print('General Intrustions')
print('Please make sure that the CONVERGENCE data file is saved in the same directory where python file is saved')
# file name = input
file_name = "engine_data.out"
# Compatability check
try:
data = open(file_name,'r')
print('\nData file is sucessfully opened')
except FileNotFoundError:
print('\nPlease enter a valid file name')
line_count = 1
for line in data:
if line_count==3:
parameter=line.split()
columns=len(parameter)
print('\nThis CONVERGENCE file contains following data which is derived from I.C Engine Simulation')
print('It has total %d Data Columns' %(columns-1))
for C_no in range(1,columns):
print(C_no,line.split()[C_no],line.split()[C_no])
break
line_count=line_count+1
print('\nChoose any Two parameters from above')
print('Enter a number corrosponding to parametr 1 to 17\n')
x=int(input("Enter x-axis parameter : "))
y=int(input("Enter Y-axis parameter : "))
x_data=[]
y_data=[]
line_count=1
for line in open(file_name,'r'):
if line_count==3:
x_label = line.split()[x]
y_label = line.split()[y]
if '#' not in line:
x_data.append(float(line.split()[x-1]))
y_data.append(float(line.split()[y-1]))
line_count=line_count+1
file_name=y_label+'vs'+x_label+'.png'
plt.figure()
plt.plot(x_data,y_data)
plt.xlabel(x_label)
plt.ylabel(y_label)
plt.title(y_label+ ' vs ' +x_label)
plt.savefig(file_name)
plt.show()
if x==8 and y==2:
RPM=1500
Area=np.trapz(y_data,x_data)
Workdone=Area*1000
Power=2*math.pi*RPM*Workdone/60
Fuel_per_stroke=20*1e-6
Fuel_per_sec=Fuel_per_stroke*RPM*(0.5/60)
Fuel_per_hour=Fuel_per_sec*3600
BSFC=Fuel_per_hour/Power
print('Area under the P-V diagram(Workdone) :',Workdone,'KJ')
print('Power output of the engine :',Power,'KW')
print('Specific Fuel Consumption :',BSFC,'g/KWh')
Explanation:
- Initially, the required modules are imported.
- File name is taken as an input from user and, to verify the user file with engine_data.out file, if command is used.
- The Using a for loop every line of file is read line by line and the lines with '#'not include to read data and are appended to an array named 'column_1 & column_2’.
- Using a for loop the extracted column no and names are displayed for user and asked to make a plot.
- Then the values of the column selected by user are extracted and stored in an array and further plotted on a graph.
- For basic performance calculation the values of pressure andvolume column are extracted and using the 'np.trapz(P,V)' command, area under the PV diagram is calculated which also is the Workdone.
- Converting the given speed of 1500rpm into rps the power output of the engine is calculated and further the specific fuel consumption of engine is calculated.
- All the values calculated are displayed on the screen for the user.
RESULTS :
Output Screen and Plots :
If the user enters a valid file name & for parameter 8 , 2

plot obtained-

If the user enters a valid file name & for parameter 1 , 8-

plot obtained-

If the user enters a valid file name & for parameter 1 , 12-

plot obtained-

CONCLUSIONS:
- The data from the output file was read successfully and the plot required as per the user need was made.
- The performance calculations were done and displayed successfully.