Challenge

Week 6 - Data analysis

Objective: To write a program that would read the file containing an engine's data and create a data visualizer. Also to plot the P-V diagram of the engine and calculate its power output and specific fuel consumption.
Data analysis: Python is an increasingly popular tool for data analysis.
In this task, a file containing data of an automotive engine obtained from CONVERGE CFD software is used to create data visualization using Python. The column numbers are used to give input from the user and the plot between respective column numbers are stored in the name of corresponding column terms.
Compatibility check:
The program is written using the Exceptional file handling function. If the file opens up, the console displays it as 'file opened successfully'.If the file opens up, then the console displays as 'file not recognized'.Please provide a valid CONVERGE output file'.
Libraries used:
Here,matplotlib.pyplot function is used to plot graphs between various engine parameters. Also,NumPy library is used in calculating the area under the P-V diagram.
Engine parameters:
A jagged array is used to define the arrays of each parameter into an array. After the engine data file is read, the parameters' names, units, and values corresponding to the column numbers are added to each array stored in specific names using the 'append' command.
Data visualization:
For any inpu of column numbers in the x-axis and y-axis, a plot is created with plot labels fetched from the engine data file and saved the image with the plot names according.

Program :

"""
Demonstarting the file Parsing
"""

#Module
import math
import matplotlib.pyplot as plt
import numpy as np
from tabulate import tabulate
from numpy import trapz

#Expection handling statement
try:
#compatibilty check for the file
for line in open('engine_data.out')
print('File successfully opened')

#Basic initializaion
crank=[]
pressure=[]
Max_pres=[]
Min_pres=[]
volume=[]
temperature=[]
Max_Temp=[]
Min_Temp=[]
mass=[]
density=[]
integrated_HR=[]
HR_Rate=[]
C_p=[]
C_v=[]
Gamma=[]
Kin_Visc=[]
Dyn_Visc=[]

parameters=[[crank],[pressure],[Max_pres],[Min_pres],[temperature],[volume],[Max_Temp],[Min_Temp],[mass],[density],[integrated_HR],[C_p],[C_v],[Gamma],[Kin_Visc],[Dyn_Visc]]

for line in open('engine_data') :
if 'crank' in line:
crank.append(float(line.split()[1]))
pressure.append(float(line.split()[2]))
Max_pres.append(float(line.split()[3]))
Min_pres.append(float(line.split()[4]))
temperature.append(float(line.split()[5]))
Max_Temp.append(float(line.split()[6]))
Min_Temp.append(float(line.split()[7]))
volume.append(float(line.split()[8]))
mass.append(float(line.split()[9]))
density.append(float(line.split()[10]))
integrated_HR.append(float(line.split()[11]))
HR_Rate.append(float(line.split()[12]))
C_p.append(float(line.split()[13]))
C_v.append(float(line.split()[14]))
Gamma.append(float(line.split()[15]))
Kin_Visc.append(float(line.split()[16]))
Dyn_Visc.append(float(line.split()[17]))

if '(DEG)' in line:
crank.append(float(line.split()[1]))
pressure.append(float(line.split()[2]))
Max_pres.append(float(line.split()[3]))
Min_pres.append(float(line.split()[4]))
temperature.append(float(line.split()[5]))
Max_Temp.append(float(line.split()[6]))
Min_Temp.append(float(line.split()[7]))
volume.append(float(line.split()[8]))
mass.append(float(line.split()[9]))
density.append(float(line.split()[10]))
integrated_HR.append(float(line.split()[11]))
HR_Rate.append(float(line.split()[12]))
C_p.append(float(line.split()[13]))
C_v.append(float(line.split()[14]))
Gamma.append(float(line.split()[15]))
Kin_Visc.append(float(line.split()[16]))
Dyn_Visc.append(float(line.split()[17]))

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]))
temperature.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]))

#reading x data
x_data=int(input('Enter the column number to be in x_axis='))

for i in parameters:
if parameters.index(i)+1 ==x_data:
x_axis=parameters[x_data-1]

#reading y data
y_data=int(input('Enter the column number to be in y_axis ='))

for j in parameters:
if parameters.index(j)+1==y_data:
y_axis=parameters[y_data-1]

#saving filename
file=str(y_axis[0][0]+ 'vs'+str(x_axis[0][0]))

plt.plot((x_axis[0][2:]),(y_axis[0][2:]))
plt.xlabel(x_axis[0][0]+x_axis[0][1])
plt.ylabel(y_axis[0][0]+y_axis[0][1])
plt.title(filename)
plt.savefig(filename)
plt.show()

#Calculating area
area=np.trapz(pressure[2:],volume[2:])
print('Area under P-V curve in m^2=',area)
print('n')

#Calculating power output of the engine
Power=[]
for i in range(2,len(pressure)):
WD=pressure[i]*pow(10,6)*volume[i]
pwr=(WD*1500)/60
Power.append(pwr)

print('Max.Power in W=',max(Power))
print('n')
print('MIn.Power in W',min(Power))
print('n')
print('Average Power in W',(max(Power)+min(Power))/2)
print('n')

#Calculating SFC of the engine
mass_flow_rate=20*pow(10,-6)*3600
power=(max(Power)+min(Power))/2
sfc=(mass_flow_rate/power)
print('SFC in kg/kW hr=',sfc)

except Expection:
print('file not recognized.Please provide a valid CONVERGE output file')

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.