Project

DATA ANALYSIS USING PYTHON

1.AIM :

TO WRITE A PYTHON PROGRAM WHICH READS THE ENGINE OUTPUT PARAMETER DATA FILE AND PERFORM THE REQUIRED OBJECTIVES

2.OBJECTIVE :

  1. To read the data from a given data file.
  2. To take the file name as an input from user and check whether the file is present or not.
  3. To plot a graph between 2 parameter given by user as an input.
  4. To do basic performance calculation by calculating area under the P-V diagram, power output of this engine and specific fuel consumption.

3.PROBLEM STATEMENT :

Read the data from a given file named 'engine_data.out' using python program, plot a curve between 2 engine parameters (parameters to be given by user as an input) and perform basic performanc calculation by calculating area under the P-V diagram, power output of this engine(Assume that RPM is 1500) and specific fuel consumption (engine consumed 20 micro grams of fuel (per 1 stroke cycle)).

Link to the data file

4.SOLUTION PROCEDURE :

To solve the above given problem statement, following procedure is followed:

  1. Using a python program initally the name of the data file is taken as an input from user and checked whether the file is present or not, if the file is not pressent then the program is terminated.
  2. Then the file is opened and data is read line by line and stored.
  3. The name of parameters, their units and their coulmn number are stored as an array and dispalyed in form a table for the user to select the required columns.
  4. Then the column no for independent parameter (x-axis) and dependent parameter (yaxis) is taken from user and the values of those clumn are extracted fromdata file and further plotted.
  5. Ath the end the values under pressure and volume column are extracted from data file and the area under the PV diagram is calculated which gives the workdone, then multiplying it with speed the value of power output by engine is caalculated and at the end the specific fuel consumption is also calculated and displayed.

5.PYTHON PROGRAM :

#Importing required modules
import matplotlib.pyplot as plt
import numpy as np 

#Taking inputs from user
fname=input("Enter file name :")
print('------------------------------------------------------------------')
#checking for valid file
if fname == 'engine_data.out':
	print('File found succesfully!! you may continue...\n')
else:
	print('File not recognized. Please provide a valid CONVERGE output file')
	exit()

print('------------------------------------------------------------------')
data=[]

for line in open(fname):
	if '#' in line:
		data.append(line.split())

#no of columns
nc=len(data[1])

#column numbers
cn=[]
#column name
cv=[]
#column units
cu=[]

a=data[1].index('column')
for i in range(a,nc-1):
	cn.append(i)

for i in data[2]:
	if i is not '#':
		cv.append(i)

for i in data[3]:
	if i is not '#':
		cu.append(i)


#showing available data
print('\nShowing data present in file...\n')
print('COLUMN NO','    ','PARAMETER')

for i in range(0,len(cn)):
	print('   ',cn[i],'    -   ',cv[i],cu[i])

print('------------------------------------------------------------------')

#taking user input for plot
xaxis=int(input('\nEnter independent parameter (x-axis) column no:'))
yaxis=int(input('Enter dependent parameter (yaxis) column no:'))
#reducing value by 1 for program to pick correct value 
xaxis=xaxis-1
yaxis=yaxis-1

print('------------------------------------------------------------------')

x=[]
y=[]

for line in open(fname):
	if '#' not in line:
		x.append(float(line.split()[xaxis]))
		y.append(float(line.split()[yaxis]))


#Plotting 
plt.plot(x,y,linewidth=3)
plt.xlabel(cv[xaxis]+cu[xaxis])
plt.ylabel(cv[yaxis]+cu[yaxis])
plt.title(cv[yaxis]+'-'+cv[xaxis]+' diagram')
plt.show()

#Basic performance calculation

pressure=[]
volume=[]

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


P = 1000000*np.array(pressure)#converting to pascal
V = np.array(volume)
#calculating area under PV diagram
area=np.trapz(P,V)

print('\nWorkdone (area under P-V diagram) = ',area,'joules')

#calculating power
power=(area*(1500/60))/1000
print('\nPower output of the engine =',power,'KW')

#calculating specific fuel consumptiion 
sfc=20*pow(10,-6)*3600/power
print('\nSpecific fuel consumption =',sfc,'g/kw.h')

print('------------------------------------------------------------------')

Explanation:

  1. Initially, the required modules are imported.
  2. Filnename is taken as an input from user and, to verify the user file with engine_data.out file, if command is used.
  3. The Using a for loop every line of file is read line by line and the lines with '#' are appended to an array named 'data'.
  4. Then the column numbers and column names (parameter name and unit of parameter) are separated and stored in an array.
  5. Using a for loop the extracted column no and names are displayed for user and asked to select 2 columns to make a plot.
  6. Then the values of the column selected by user are extracted and stored in an array and further plotted on a graph.
  7. For basic performance calculation the values of pressure and volume column are extracted and using the 'np.trapz(P,V)' command, area under the PV diagram is calculated which also is the Workdone.
  8. Converting the given speed of 1500rpm into rps the power output of the engine is calculated and further the specific fuel consumption of engine is calculated.
  9. All the values calculated are displayed on the screen for the user.

6.RESULTS :

Output screen and plot-

If the user enters a valid file name-

plot obtained-

Result of performance calculations:

Area under PV diagram(Workdone) = 500.5866274680076 joules

Power output of the engine = 12.514665686700189 KW

Specific fuel consumption = 0.005753249971073309 g/kw.h

If the user enters an invalid file name-

Output plots for some other parameters:-

7. CONCLUSIONS:

  1. The data from the output file was read successfully and the plot required as per the user need was made.
  2. The performance calculations were done and displayed successfully.

Area under PV diagram(Workdone) = 500.5866274680076 joules

Power output of the engine = 12.514665686700189 KW

Specific fuel consumption = 0.005753249971073309 g/kw.h

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.