Project

DATA ANALYSIS IN PYTHON

AIM: To read a file containing information about engine thermodynamic properties and to perform the analysis.

OBJECTIVES: To extract the desired thermodynamic properties data and to plot them.

The Programming Language Used: PYTHON

CODE:

#DATA PARSING 
#IMPORTINING THE MODULES
import matplotlib.pyplot as plt
import numpy as np


try:
	f=open('engine_data.out')
	#file opperation
except FileNotFoundError:
	print('"File not recognized. Please provide a valid CONVERGE output file"')
finally:
	f.close


#EXTRACTING ADDITIONAL INFORMATION

L=[]

for line in f:
	if '#' in line:
		L.append(line)

temp =L[1].split('#')
columns=temp[1].split()
properties=L[2].split()
Units =L[3].split()

for i in range(0,18):
	print(properties[i],':',columns[i])


#TAKING INPUTS FROM USER
var1=input('enter any col :')
print(int(var1))
l1=print(properties[int(var1)])

var2=input('entera any other col:')
print(int(var2))
l2=print(properties[int(var2)])

TP_1=[]
TP_2=[]

#EXTRACTING THE DATA FOR THERMODYANAMIC PROPERTIES (from columns)
for line in open('engine_data.out'):
	if '#' not in line:

		TP_1.append(float(line.split()[int(var1)-1]))
		TP_2.append(float(line.split()[int(var2)-1]))
	
#PLOTTING	
file = var1 + 'vs'+var2+'.png'
plt.figure()
plt.plot(TP_2,TP_1,'b-',linewidth=3)
plt.ylabel(properties[int(var1)]+Units[int(var1)])
plt.xlabel(properties[int(var2)]+Units[int(var2)])
plt.title(properties[int(var1)]+' vs '+properties[int(var2)])
plt.savefig(file)
plt.show()

rpm=1500#revoltions per minute
num_of_strokes=rpm*2# strokes per minute
strokes_per_hour=60*num_of_strokes
#MASS FLOW RATE (mfr)
mfr_per_stroke=20*1e-06# fuel consumption per stroke 
mfr=mfr_per_stroke*strokes_per_hour#fuel consumption per hour
if int(var1)==2:
	if int(var2)==8:
		#from numpy import trapz to calculate work
		work=np.trapz(TP_1,TP_2)*pow(10,6)#converting M to 1e06
		print('work done is %5.5f Joules' % work)
		#power=work*speed(in seconds)
		power=work*(1500/60)#convering rpm to rps
		print('power produced is %5.5f Watts' % power)
		#sfc=mfr(in g/hr)/power
		sfc=mfr/power
		print('specific fuel consumption is %5.5f kg/kWh' % sfc)


EXPLANATION TO THE CODE:

  • Create a new file with .py extension and import the matplotlib and numpy modules.
  • using try, except open and read the file and check for compatibility.if the file is not found show the error. After file operation is done close it.
  • Extract the columns, thermodynamic properties, units using for loop and line command from the file f.
  • Use split to extract the data from each line as many strings in the form of an array.
  • print the properties and respective columns to get proper inputs.
  • Use sublimeREPL to give inputs manually.
  • make sure to convert the inputs into integers as by default inputs are characters.
  • Assign the inputs to index TP_1, TP_2 and properties and units to get the corresponding data.
  • create a new file within columns and save plots after creating them.
  • if the input columns are corresponding to pressure and volume calculate work done, power and specific fuel consumption.
  • to calculate the work done under the PV indicator diagram use trapez from numpy module.
  • display the outputs using the print command.

RESULTS:

PRESSURE VS VOLUME

The theoretical PV diagram and Actual PV diagram are not the same because, in theory, we neglect the former losses.

PRESSURE VS CRANK ANGLE

the pressure is maximum when can't angle is close to zero that means TOP DEAD CENTRE.

dyn_visc vs mean_temp

Dynamic viscosity is directly proportioned to the mean temperature.

files are saved automatically with the column as file name

ERRORS:

  • After opening the file and storing it in any variable(f) and closing. Make sure to open the file again if you are using that variable twice it will give an error you won't get data from it.
  • Remember to use the imported module while using it like np. and plt.
  • Give proper tab spacing and colon after for loop to avoid indentation errors.
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.