Challenge

Python program to perform data analysis for a 4 stroke engine parameters output data

AIM : Python program to fulfill the following objectives :

  • Writing a code in Python to parse the engine parameters data file.
  • Performing data visualisation i.e. the 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, someone requests for a plot between column 1 (crank angle) and column 8(volume) in the file, then the label information should automatically be extracted and must appear as labels in the plots and this should not be done manually.
  • Performing compatability check i.e. the 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".
  • Performing basic performance calculations i.e. calculate the area under the P-V diagram. P is in column 2 and V is in column 8 in the file, calculate the power output of this engine assuming that RPM is 1500
  • and the engine consumed 20 micro grams of fuel (per 1 stroke cycle). Calculate its specific fuel consumption.

BACKGROUND : The process of "parsing" can be described as reading in a data stream of some sort and building an in-memory model or representation of the semantic content of that data, in order to facilitate performing some kind of transformation on the data. To do the performnace calculations the following formulaes will be used :

`Power(W)= frac(2*pi*N*T)(60*2)`

The power that is obtained is not the output power. It is the Indicated power which is the sum of Brake power(power obtained at the output of the engine shaft) and friction power.

Power= Indicated Power.

N= no. of crank revolutions per minute.

T= torque(Nm).

The data is assumed of a 4 stroke engine.

`SFC(frac(kg)(kW-hr))= frac(mf*3600)(power)`

the above formula wil give brake specific fuel consumption.

SFC= specific fuel consumption.

mf= mass of the fuel.

SOLUTION ALGORITHM :

  • The program begins with import of the necessary modules.
  • The compatibility check will be performed with the help of a try and except block.
  • To obtain the data from the external file we will open it in python and start extracting data from it line by line.
  • The user will be asked to enter the choice of the 2 parameters of which he want to create a plot.
  • To caluclate the area under P-V diagram, numpy.trapz funcction is used.It integrates along the given axis using the composite trapezoidal rule.
  • Then power and specific fuel consumption will be calculated using the above formuales.
  • Sublime REPL needs to be installed as Sublime Text does not support input.
  • The entire script is written in Sublime Text Editor.

PYTHON CODE :

"""
Python program to perform data analysis
By Abhishek Arora

"""

import math
import matplotlib.pyplot as plt
import numpy as np 

#performing compatibility check
#using try and except block

try:
	file= open('engine_data.out')
	print('file recognised successfully')
except:
	print('File not recognized. Please provide a valid CONVERGE output file.')
	file.close()


#data visualiser
parameters=[]
unit=[]

line_count=1
for line in open('engine_data.out'):
	if line_count== 3:
		parameters=line.split()
	if line_count==4:
		unit= line.split()
	line_count=line_count+1

print('following parameters are available to create a plot')
print()
print(parameters)
print()
print('choose the parameter number (1-17) from the list')
print()
for i in range(0,len(parameters)):
	print(i,parameters[i])
x_par= int(input("enter the x axis parameter"))
y_par= int(input("enter the y axis parameter"))
print('the plot is',parameters[x_par],'v/s',parameters[y_par])

par_data_x=[]
par_data_y=[]

for line in open('engine_data.out'):	
	if '#' not in line:
		par_data_x.append(float(line.split()[x_par-1]))

for line in open('engine_data.out'):	
	if '#' not in line:
		par_data_y.append(float(line.split()[y_par-1]))

#plotting the results

plt.plot(par_data_x,par_data_y)
plt.xlabel(parameters[x_par]+unit[x_par])
plt.ylabel(parameters[y_par]+unit[y_par])
plt.title(parameters[x_par]+'v/s'+parameters[y_par])
plt.show()

#basic performance calculations

pressure=[]
volume=[]

for line in open('engine_data.out'):	
	if '#' not in line:
		pressure.append(float(line.split()[1]))
		volume.append(float(line.split()[7]))

#calculating area under pv diagram
area= np.trapz(pressure,volume)
print('area under p-v diagram is ',area)
work= area*1000000
print('work done in joules is ',work)

#calculating power output of the engine
#considering a 4 stroke engine
rpm= 1500
omega= (2*math.pi*rpm)/(60*2)
power= (work*omega)/1000
print('power output in kW is ',power)

#specific fuel consumption
fuel_mass= 20*1e-06
ssc= (fuel_mass*3600)/power
print('the specific fuel consumption in kg/kW-hr is ',ssc)




OUTPUT : The following output is obtained after executing the code.

*compatibility check

(1)when correct file name is provided

(2) when incorrect file name is provided

* data visualisation

*performance value

REFERENCES :

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.