Data visualizer for a Petrol engine using Python
AIM: To write a program to create a data visualizer for an engine using File Parsing
OBJECTIVE:
- To display engine performance details
- To display parametric plots for various factors affecting an engines performance, based on the users choice
INTRODUCTION
Data Analysis
Data analysis is defined as a process of cleaning, transforming, and modeling data to discover useful information for business decision-making. The purpose of Data Analysis is to extract useful information from data and taking the decision based upon the data analysis.Whenever we take any decision in our day-to-day life is by thinking about what happened last time or what will happen by choosing that particular decision. This is nothing but analyzing our past or future and making decisions based on it. For that, we gather memories of our past or dreams of our future. So that is nothing but data analysis. Now same thing analyst does for business purposes, is called Data Analysis.
Tools used
Data analysis tools like Python, SQL, Java and MATLAB make it easier for users to process and manipulate data, analyze the relationships and correlations between data sets, and it also helps to identify patterns, plots,graphs and trends for interpretation.
Data visualization
Data visualization is very common in your day to day life; they often appear in the form of charts and graphs. In other words, data shown graphically so that it will be easier for the human brain to understand and process it. Data visualization often used to discover unknown facts and trends. By observing relationships and comparing datasets, you can find a way to find out meaningful information.
THEORY
Equations used
- Work Done (WD)= Area under the P-V diagram, which is calculated using Simpson's method.
- Power output (P)=`(WD*N*n)/(60*2*1000)`
- `WD`- work done
- `N`-speed of the engine
- `n`-no. of cylinders
- Specific Fuel Consumption = `F_c/P`
- `F_c`-Fuel consumption/stroke
- `P`-Power output
Inputs
- `N`= 1500
- `n`= 1
- `F_c`= 20
PROGRAM CODE
# Generating plots for 2 random quantities by analysis data using file parsing
import math
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import simps
#Compatability check using try-except block
try:
open('engine_data.out')
check=1
except:
print('File not recognized. Please provide a valid CONVERGE output file')
check=0
if check==1:
#Creating empty lists to store data in each respective column from the file
data=[]
volume = []
pressure = []
x1=open('engine_data.out','r') # storing the readable data in a variable
for i in x1:
if '#' not in i:
a1=i.split() #splitting the string w.r.t spaces
data.append(a1) #adding each line as a nested list
#adding P and V to their respective lists
volume.append(float(a1[7]))
pressure.append(float(a1[1]))
#Plotting the P-V diagram
plt.plot(volume, pressure, color = 'orange', linewidth = 3)
plt.xlabel('Volume(m^3)')
plt.ylabel("Pressure(MPa)")
plt.title("P-V Diagram")
plt.grid()
plt.savefig("P-V Diagram")
plt.show()
#Basic performance calculation
#Input parameters
#Speed
rpm = 1500
rps = 1500/60
s_c= rps/2
#Fuel consumption/stroke cycle
f_c= 20
n = 1 #No of cylinders
print("\t")
print("\t")
print("ENGINE PERFORMANCE DETAILS")
print("\t")
#Calculating area under the curve using Simpson's function/rule
#Area under curve=Work done by the engine
area = simps(pressure, volume)
print('1.Area under the curve:',area,'units')
area = area*pow(10,6)
print('2.Work Done:',area,'J')
#Calculating Power Output and Specific Fuel Consumption(SFC)
p_o= n*area*s_c/(1000)
sfc= (f_c*pow(10,-6)*s_c*3600)/(p_o*1000)
print('3.Power Ouput:',p_o,'KW')
print('4.Specific Fuel Consumption:',sfc,'(kg/hr)/KW')
#Converting columns into rows for ease
t=np.transpose(data)
fl=t.astype(np.float)#convert
#List containing axes labels and units
labels = ['Crank Angle','Pressure','Maximum Pressure','Minimum Pressure','Mean Temperature','Maximum Temperature','Minimum Temperature','Volume','Mass','Density','Integrated HR','HR Rate','Cp','Cv','Gamma','Kinematic Viscosity','Dynamic Viscosity']
units = ['(DEG)','(MPa)','(MPa)','(MPa)','(K)','(K)','(K)','(m^3)','(kg)','(kg/m^3)','(J)','(J/time)','(J/kgK)','(J/kgK)','','(m^2/s)','(Ns/m^2)']
print("\t")
print("\t")
#User Interface
print('__________________________________________________________________________________DATA VISUALIZER FOR AN ENGINE_______________________________________________________________________________')
print('\t')
print(' 1.Crank\n 2.Pressure\n 3.Maximum Pressure\n 4.Minimum Pressure\n 5.Mean Temperature\n 6.Maximum Temperature\n 7.Minimum Temperature\n 8.Volume\n 9.Mass\n 10.Density\n 11.Integrated HR\n 12.HR Rate\n 13.Cp\n 14.Cv\n 15.gamma\n 16.Kinematic Viscosity\n 17.Dynamic Viscosity')
print('\t')
x0=int(input("Enter the number of plots you want to generate"))
for i in range(0,x0):
X=int(input('Enter the key for the component you need on the X-axis:'))
Y=int(input('Enter the key for the component you need on the Y-axis:'))
if X>0 and Y>0 and X<18 and Y<18:
#Plotting graphs based on the user's choice
plt.plot(fl[X-1],fl[Y-1],linewidth=3,color='RED')
plt.title(labels[X-1]+ ' VS ' +labels[Y-1])
plt.xlabel(labels[X-1] + ' ' + units[X-1])
plt.ylabel(labels[Y-1] + ' ' + units[Y-1],)
plt.savefig(labels[X-1] + ' vs ' + labels[Y-1] + '.png')
plt.grid()
plt.show()
else:
print("INVALID OPTION")
print('__________________________________________________________________________________END__________________________________________________________________________________________')
PROCEDURE
- Import the neccesary modules used for calculations and plotting graphs
- Use a try-except block to check the file compatibilty before proceeding futher.
- Read the file and add all the data to a list, awaiting sorting.
- Sort the data and organize them into systemic lists.
- Plot graphs based on the respective lists.
- A User interface is coded for ease of usage
- The program allows the user to generate any plot of choice by selecting the neccesary factors according to the legend given.
RESULTS:
User interface
SCREENSHOT OF NAMES OF THE SAVED IMAGES
GENERATED PLOTS
Minor syntax errors were encountered
CONCLUSION
Hence, using the Python program above, we were able to create a data visualizer for an engine with the data recived from a Converge simulation