Week 6 - Data analysis
AIM:-
To write a python program whic reads the engine output parameter data file and perform required objectives.
Objectives:-
- To read the data from a given file.
- By taking file name as input from user and cheking the file is present or not.
- ploting the graphs by using parameters.
- performance calculations.
- Calculate the area under the P-V diagram. P is in column 2 and V is in column 8.
- Calculate the power output of this engine. Assume that RPM is 1500
- This engine consumed 20 micro grams of fuel (per 1 stroke cycle). Calculate its specific fuel consumption
procedure:-
- Using of python initially the name of data file is taken as an input from user and checked whether the file is present or not,if the file is not present then the program is terminated .
- when file is opend the data is read line by line and stored.
- the name of parameter, their units and their coloumn numer are stored as an array and dispalyed in the form a table for the user to select the required columns.
- Then the column number for independent parameter(x-axis) and dependent parameters(y-axis)is taken from user and the values of those columnare extracted from datafile and further ploted.
- work done is calculated by the area under the pv-diagram.
python code:-
#importing required modules
import math
import matplotlib.pyplot as plt
import numpy as np
from numpy import trapz
#opening the file and reading it
#data visualizer
fname=input("Enter the file name: ")
if fname=='engine_data.out':
print('file is valid')
else:
print('file is invalid')
exit()
def compatability_check(a):
if 'CONVERGE' not in a:
print('please provid converge output file to process')
exit()
else:
print('compatability check is successful')
pass
FILE=[]
for line in open(fname):
if '#' in line:
FILE.append(line.split())
#checking the compatability
compatability_check(FILE[0])
noc=len(FILE[1])
head=len(FILE[2])
#creating the arrays
col_no=[]
col_val=[]
col_units=[]
# making the data in the form of arrays
z=FILE[1].index('column')
for i in range(z,noc-1):
col_no.append(i)
for j in FILE[2]:
if j is not '#':
col_val.append(j)
for k in FILE[3]:
if k is not '#':
col_units.append(k)
print('data available are:')
for a in range(0,len(col_no)):
print(col_no[a],col_val[a],col_units[a])
#ploting using column
xaxis=int(input('Enter xaxis column no:'))-1
yaxis=int(input('Enter yaxis column no:'))-1
x=[]
y=[]
for line in open(fname):
if '#'not in line:
x.append(float(line.split()[xaxis]))
y.append(float(line.split()[yaxis]))
plt.plot(x,y,linewidth=1.5)
plt.xlabel(col_val[xaxis])
plt.ylabel(col_val[yaxis])
plt.show()
# calculating the engine performance
pressure = []
vol = []
for line in open(fname):
if '#' not in line:
pressure.append(float(line.split()[1]))
vol.append(float(line.split()[7]))
Pressure = 1e6*np.array(pressure)
Volume = np.array(vol)
area = np.trapz(Pressure,Volume)
print('workdone =',area, 'joules')
cyclepersec = 750/60
power = area*(cyclepersec/1000)
print('power=',power,'kw')
mass_flow = 20e-6
sfc = mass_flow*3600/power
print('specific fuel consumption =',sfc,'g/kwh')
code explanation:-
- Initially , the required modules are imported.
- filename is taken as 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
- Then the column number and column names are seperate and stored in an array.
- using for loop the extracted column number and names are to user and asked to select columns to make plot.
- For the performance calculation the values of pressure and volume are extracted and area under pv diagram work done is calculated.
- calulating the mass flow and fuel consumptin off their respective formulae.
output:-



giving the x-axis column number 'Enter'.

giving the y-axis column number and 'Enter'.

closing the figure and we get.

conclusion:-
By entering values of column number we can plot the graph between any two parameters automatically.
performance parameters calculated.
workdone = 500.5866274680076 joules
power= 6.257332843350095 kw
specific fuel consumption = 0.011506499942146618 g/kwh