DATA ANALYSIS OF I C ENGINE USING PYTHON
DATA ANALYSIS OF I.C ENGINE USING PYTHON
Objective: For this challenge, we will be creating a data visualizer tool using the data from I.c engine.
Introduction: Data analysis inspecting, cleansing, transforming and modelling data with the goal of discovering useful information, informing conclusion 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.
In this challenge. I.c engine data file form the converge studio consists of various parameters like crank angle, pressure, temperture etc.... Using this data file a program will be written inorder to plot and get respective information.
Eventhough the data is seperted into rows and columns, it is an impossible task to read the file as it is and use it directly. Since there is this \'#\' symbol right above the values of the crank, Python assigns crank values to \'#\'. Inorder to avoid this problem, we have to create a arrays and name the array appropritatly depending on the type of values it contain.
# File parsing using Python.
import matplotlib.pyplot as plt
import numpy as np
import math
import pandas as pd
Crank = []
Pressure = []
Max_Pres = []
Min_Pres = []
Mean_Temp = []
Max_Temp = []
Min_Temp = []
Volume = []
Mass = []
Density = []
Integrated_HR = []
HR_Rate = []
C_p = []
C_v = []
Gamma = []
Kin_Visc = []
Dyn_Visc = []
try:
open(\'engine_data.out\')
except:
print(\"File not recognized. Please provide a valid CONVERGE output file\")
line_count = 1
for line in open(\'engine_data.out\'):
if \'#\' not in line:
Crank.append(float(line.split()[0]))
Pressure.append(float(line.split()[1]))
Max_Pres.append(float(line.split()[2]))
Min_Pres.append(float(line.split()[3]))
Mean_Temp.append(float(line.split()[4]))
Max_Temp.append(float(line.split()[5]))
Min_Temp.append(float(line.split()[6]))
Volume.append(float(line.split()[7]))
Mass.append(float(line.split()[8]))
Density.append(float(line.split()[9]))
Integrated_HR.append(float(line.split()[10]))
HR_Rate.append(float(line.split()[11]))
C_p.append(float(line.split()[12]))
C_v.append(float(line.split()[13]))
Gamma.append(float(line.split()[14]))
Kin_Visc.append(float(line.split()[15]))
Dyn_Visc.append(float(line.split()[16]))
line_count = line_count + 1
n = []
ct = 1
for k in open(\'engine_data.out\'):
if ct is 3:
n.append(k.split())
ct = ct + 1
df = pd.DataFrame(n)
d = df.to_dict(orient=\'list\')
print(d)
i = [Crank, Pressure, Max_Pres, Min_Pres, Mean_Temp, Max_Temp, Min_Temp, Volume, Mass, Density, Integrated_HR, HR_Rate, C_p, C_v, Gamma, Kin_Visc, Dyn_Visc]
x = 8 #enter the index of parameter to plot on x-axis.
y = 2 #enter the index of parameter to plot on y-axis.
plt.plot(i[x-1],i[y-1])
plt.xlabel(d[x])
plt.ylabel(d[y])
plt.savefig(str(d[y])+ \'vs\' + str(d[x])+\'.png\')
plt.show()
# Calculating p-v area
area = np.trapz(Pressure,Volume)
print(\'Area under p-v graph: \',area)
# power of the engine
p = area * 1500/60
print(\'power of engine: \',p,\'MW\')
#specific fuel consumption.
sfc = (20*12.5*3.6*pow(10,-6))/p
print(\'specific fuel consumption: \',sfc,\'g/Kwh\')
pandas is used to extract the list of names of the values. This names are split by the dataframe automatically. By this we can assign the labels in the plots automatically. Each parameter is represented using number. by selecting the number for x and y we can plot data between them.
By selecting x = 8 and y = 2
we get the plot between the \'pressure vs volume\' and it will be saved with that name.
A set of the code is written to check the compatability of the data of the engine. In case data is not compatable then code will exit displaying \"File not recognized. Please provide a valid CONVERGE output file\". No warning as popped up since the data file is compatable.
Once the data gets extracted and ready to plot. The same data is useed to calculate the area,power and specific fuel consumption of the engine.
Conclusions:
- Data file should be inspected thoroughly to get an idea on writing the commands to read. This will help write the code easily.
- Label automation depends on the type of the data present in the line. if it is number we can use string operation. if it is names then we have use dict operator to read the file and split the names and assign the index.