Challenge

Week 6 - Data analysis

Take a look at the data analysis video before you attempt this challenge.

Your task is to write a script that does the following.

Data visualizer (100 points)

  • Your 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, I request for a plot between column 1 (crank angle) and column 8(volume), then the label information should automatically be extracted and must appear as labels in the plots. THIS SHOULD NOT BE DONE MANUALLY

Compatability check (30 points)

  • You 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"

Basic performance calculation (50 points)

  • 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.

Program:

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


file_name =input(' Enter File Name ==>  ')
if file_name == ('engine_data.OUT'):
	crank_angle =[]
	pressure = []
	max_pres = []
	min_pres = []
	mean_temp = []
	max_temp = []
	min_temp = []
	volume =[]
	mass=[]
	density = []
	integrated_hr = []
	hr_rate=[]
	cp = []
	cv = []
	gamma = []
	kin_vis = []
	dyn_vis = []

	parameter =[]
	unit =[]
	lines = 1
	ct =1
	counter = 1
	for line in open('engine_data.OUT'):
		if '#' in line:
			if ct == 3:
				parameter.append(line.split())
			ct=ct+1
			if counter ==4:
				unit.append(line.split())
			counter=counter+1
		if '#' not in line:
			crank_angle.append(float(line.split()[0]))
			pressure.append(float(line.split()[1]))
			max_pres.append(float(line.split()[2]))
			min_pres.append(float(line.split()[3]))
			mean_temp.append(float(line.split()[4]))
			max_temp.append(float(line.split()[5]))
			min_temp.append(float(line.split()[6]))
			volume.append(float(line.split()[7]))
			mass.append(float(line.split()[8]))
			density.append(float(line.split()[9]))
			integrated_hr.append(float(line.split()[10]))
			hr_rate.append(float(line.split()[11]))
			cp.append(float(line.split()[12]))
			cv.append(float(line.split()[13]))
			gamma.append(float(line.split()[14]))
			kin_vis.append(float(line.split()[15]))
			dyn_vis.append(float(line.split()[16]))
			lines = lines+1
	select_parameter = [0, crank_angle, pressure, max_pres,min_pres,mean_temp,max_temp,min_temp,volume,mass,density,integrated_hr,hr_rate,cp,cv,gamma,kin_vis,dyn_vis]

	print('\nAnalysing an IC Engines results Parameter and ploting the data')
	print('\n1.crank_angle \n2.pressure \n3.max_pres \n4.min_pres  \n5.mean_temp \n6.max_temp \n7.min_temp \n8.volume \n9.mass\n10.density\n11.integrated_hr\n12.hr_rate\n13.cp\n14.cv\n15.gamma\n16.kin_vis\n17.dyn_vis')
	print('\nSelect different x and y inputparameters, only from te list given above. \nDo not enter 0 or any other number beyound list given above')
	x = int(input('\nEnter the x_axis paramter to plot the data -  '))
	y = int(input('\nEnter the y_axis paramter to plot the data -  '))
	for i in range (0, len(parameter)):
		for j in range (0, len(unit)):
			fig = plt.figure(linewidth = 5, edgecolor = "k")
			plt.plot(select_parameter[x], select_parameter[y])
			plt.xlabel(parameter[0][x]+unit[0][x], size = '10')
			plt.ylabel(parameter[0][y]+unit[0][y], size = '10')
			plt.title(parameter[0][y] + 'Vs' + parameter[0][x], size = 15)
			plt.savefig(parameter[0][y] + 'Vs' + parameter[0][x]+'.png')

	print('\nEngine performance calculation')
	fuel_consumption = 20
	RPM = 1500
	print('\nFuel consumption is ',fuel_consumption,'mg')
	print('\nEngine RPM is ',RPM)

	workdone = np.trapz(select_parameter[2], select_parameter[8])
	workdone = (workdone*pow(10,6))
	print('\n1.  Work done by engine    =%.5f' %(workdone),'J')

	power = (workdone*(RPM/60))/1000
	print('\n2.  Power output  =%.5f' %(power),'KW')

	RPS =RPM/60
	Total_strokes = 4*RPS
	fuel_consumption = fuel_consumption*Total_strokes
	specifice_fuel_consumption =(fuel_consumption*0.0036)
	print('\n3.  The Fuel consumption/ Second at given engine speed   =%.5f' %(fuel_consumption),'Mg/s')
	print('\n4.  Specific fuel_consumption =%.5f' %(specifice_fuel_consumption),'g/KW.hr')
else:
	print('File not recognized. Please provide a valid CONVERGE output file')

Result:

Plot Between column 11 &15:

Different file name:

PV plot:

The area under the P-V diagram:

The area under PV diagram = Work done ==> 500.58663 J

The power output of the engine ==> 12.51467 KW

The specific fuel consumption of the engine ==> 7.20000 g/KW.hr

Inference:

Thus the program to read the Output file of an engine simulation and calculate the required is done.

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.