Project

data analysis

#Importing libraries
import matplotlib.pyplot as graph
import numpy as np 
from numpy import trapz as trp

#Compatability check
try:
  f=open(\'engine_data .out\')

except FileNotFoundError:
	print(\'File not recognized. Please provide a valid CONVERGE output file!\')
	sys.exit()

#input
file = \'engine_data .out\'
count = 0 ; count_head = 0
column_title = [] ; column_units = []
for line in open(file):
	if \'#\' not in line:
		count = count + 1
		columns = len(str.split(line))
	else:
		count_head = count_head +1
		if count_head == 3:
			line_content = str.split(line)
			for i in range(0,len(line_content)):
				column_title.append(line_content[i])
		elif count_head == 4:
			line_content = str.split(line)
			for i in range(0,len(line_content)):
				column_units.append(line_content[i])


if (count_head < 4 or count < 1 or columns < 8):
	print(\'Invalid data file\')
else:
	data = np.zeros((count,columns,1))
	row = 0
	for line in open(file,\'r\'):
		if \'#\' not in line:		
			column = 0
			data_line = str.split(line)
			while (column < columns):
				data[row,column] =  float(data_line[column])
				column = column + 1
			row = row + 1

	col = 1
	while (col <= columns):
		graph.plot(data[:,col-1])
		graph.ylabel(column_title[col]+column_units[col])
		graph.savefig(column_title[col]+\'.png\')
		graph.figure()
		col = col + 1


	x_col = 8
	y_col = 2
	x_data = np.array(data[:,x_col-1])
	y_data = np.array(data[:,y_col-1])
	graph.plot(x_data,y_data)
	graph.xlabel(column_title[x_col]+column_units[x_col])
	graph.ylabel(column_title[y_col]+column_units[y_col])
	graph.savefig(column_title[y_col]+\' VS \'+column_title[x_col]+\'.png\') 


	area = trp(y = y_data.transpose(), x = x_data.transpose())
	print(\'Area under pv diagram:\',area,\'(MJ)\') 
	#Power in kw = Nm * RPM / 9550
	RPM = 1500
	power = area * 1e+06*RPM/(9550)
	print(\'Power:\',power,\'(kw)\')
	fuel_per_stroke = 20*1e-06
	fuel_per_sec = fuel_per_stroke*RPM*60
	Spec_fuel_cons = fuel_per_sec/ (power * 1e+03)
	print(\'Specific Fuel Consumption:\',Spec_fuel_cons,\'(g/J)\')
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.