Data Analysis using Python

OBJECTIVE – We have to write the script which should take column numbers as the input and plot the respective columns as separate images. The plot labels should be extracted from the file. If there is a request for a plot between column 1(crank angle) and column 8(volume) , then label information should automatically be extracted and must appear as labels in the plots.Also to calculate the area under the P-V diagram. P is in the column 2 and V is in column 8,the power output of this engine(Assume RPM is 1500) and its specific fuel consumption.

SCRIPT –

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

Crank = []
Pressure = []
Max_Pres = []
Min_Pres = []
Mean_Temp = []
Max_Temp = []
Min_Temp = []
Volume = []
Mass = []
Density = []
Integrated_HR = []
HR_Rate = []
C_v = []
C_p = []
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_v, C_p, Gamma, Kin_Visc, Dyn_Visc])
		
		print('\n Enter the Engine Parameters: ')

		x = input("Engine parameter 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()

		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?')
			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 plt = t = ',T,'N-m')
			print('\nPower = ', P,'Mw')
			print('\nSFC = ', SFC, 'g/KW-h')

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


The P-V plot obtained by the code.

The command line arguments inputs 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.

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.


Projects by Habishek Umapathy

  OBJECTIVE – To write a program to perform curve fitting.   Curve Fitting is the process of constructing a curve or mathematical functions, which possess the closest proximity to the real series of data. By curve fitting, we can mathematically constr Read more

The Newton Raphson method is an iterative technique that is used to find out the roots of a real valued function. It uses the idea that a continuous and differentiable function can be approximated by a straight-line tangent to it. In this case Newton Raphson method is Read more

OBJECTIVE – To write a program to simulate the transient behaviour of a simple pendulum and to create an animation of its motion.   PROCEDURE – In Engineering, ODE is used to describe the transient behavior of a system. A simple example is a pendulum Read more

OBJECTIVE - To write a code for P_V diagram of an Otto cycle and calculate thermal efficiency

 

PROCEDURE –

ASSUMPTIONS

  • Initially state variables p1,t1,t3 and gamma a Read more

OBJECTIVE - 1. Write a function that extracts the 14 co-efficient and calculates the enthalpy, entropy and specific heats for all the species in the data file. Calculate the molecular weight of each species and display it in the command window. Plot the Cp, Ent Read more

OBJECTIVE - Write a code in MATLAB to optimise the stalagmite function and find the global maxima of the function. PROCEDURE- The genetic algorithm is a method for solving both constrained and unconstrained optimization problems that is based on natural sele Read more

OBJECTIVE – To write code to fit a linear and cubic polynomial for the Cp data and plot the linear and cubic fit curves along with the raw data points.   PROCEDURE – Curve Fitting is the process of constructing a curve or mathematical functions, whic Read more


Loading...

The End