Project

Data parsing using python

Code to obtain the data from the Converge output file and plot the p-V relationship:

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

#Assigning an empty array to all the engine parameters
Crank = []
Pressure = []
Max_Pres = []
Min_Pres = []
Mean_Temp = []
Max_Temp = []
Min_Temp = []
Volume = []
Mass = []
Density = []
Integrated_HR = []
HR_Rate = []
C_p = []
C_v = []
Gamma = []
Kin_Visc = []
Dyn_Visc = []
label = []
Units = []



filename = input(\'Enter a Converge output file: \')
try:
	file = open(filename, \'r\')

	line_count = 1


	for line in file:
		if \'#\' in line:

			if line_count is 3:		
				for j in range(1,18):	
					label.append(line.split()[j])

			if line_count is 4:
				for k in range(1,18):
					Units.append(line.split()[k])

			line_count = line_count + 1

		if \'#\' not in line:

			Crank.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]))
			C_p.append(float(line.split()[12]))
			C_v.append(float(line.split()[13]))
			Gamma.append(float(line.split()[14]))
			Kin_Visc.append(float(line.split()[15]))
			Dyn_Visc.append(float(line.split()[16]))
			
	Inp = np.array([[0], Crank, Pressure, Max_Pres, Min_Pres, Mean_Temp, Max_Temp, Min_Temp, Volume, Mass, Density, Integrated_HR, HR_Rate, C_p, C_v, Gamma, Kin_Visc, Dyn_Visc])

	print(\'\\nEnter the engine parameters: \')


	x = input(\"Engine parameter on the x axis: \")
	x = int(x)

	y = input(\"Engine parameter on the y axis: \")
	y = int(y)

	plt.plot(Inp[x],Inp[y])
	plt.title(str(label[x-1]) + \' v \' + str(label[y-1]) + \' plot \')
	plt.xlabel(str(label[x-1]) + str(Units[x-1]))
	plt.ylabel(str(label[y-1]) + str(Units[y-1]))
	plt.savefig(str(label[x-1]) + \'v\' + str(label[y-1]))
	plt.show()

	#plotting the curve only if the input data asks for pressure and volume
	if x == 2 and y == 8 or x == 8 and y == 2:

		rpm = input(\'\\nWhat is the engine rpm? \')
		rpm = float(rpm)
		r = input(\'\\nWhat is the fuel consumption(in microgram/second)? \')
		r = float(r)
		T = np.trapz(Inp[x], Inp[y])
		P = (2*math.pi*rpm*T)/(60)
		SFC = ((r*rpm)*(pow(10,-6))*(3600))/(P*1000*60)
		print(\'\\nArea under the pV plot = T = \', T, \'N-m\')
		print(\'\\nPower = \', P, \'MW\')
		print(\'\\nSFC = \', SFC, \'g/kW-h\')

except:
	print(\'Enter a valid Converge output file\')


Data visualiser:

The following lines of code store the data from the .out file to specific arrays with the arrays being named for each parameter. The parameter can then be called to plot the graphs and study the relationships between any 2 variables.

The data is taken and stored in an array of the name of the variable. Each variable is then assiged to a data set named Inp that stores the data such that each parameter can be called by its column number.

The data is then asked as inputs and plot to study the relationship.

For the case of this study, the pressure and volume were plot and the work done calculated as the area under the p-V plot to calculate power and SFC.

The script is written such that the area under the plot will only be calculated if the inputs are for a p-v plot. Else, the script only shows the plot. The script can be written such that specific graphs have specific data calculated.

The p-V plot as so obtained by the code:

\"\"

The command line arguments input to obtain the results:

\"\"

The code is written such that the rpm and fuel consumption values can be input for different running conditions. Sublime text is modified with a package such that it is able to take in user input and read the input to provide the output. The results for the Power and SFC calculations are as above and the p-V plot is added below.

The p-V plot:

\"\"

For any other variables, the area under the plot isn\'t a case of study and it will not be printed as part of the output.

\"\"

As we can see, the area under the graph and subsequent calculations haven\'t been done for this case plotting crank angle and pressure.

The result as obtained from this:

\"\"

Finally, the script is written such that the file must be an output file from Converge. If not an error will be displayed.

\"\"

The script has been written to be modular and find any data that the user required from the data file.

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.