Project

DATA ANALYSIS USING PYTHON

DATA ANALYSIS USING PYTHON

Introduction

When large simulations are performed, it generates an enormous amount of data in which searching for the necessary data becomes practically impossible. To simplify the search process, programs can be written which can present us with the required data very quickly.

This project intends to read the data file provided by the CONVERGE analysis of an engine, and retrieve the required information. The data file contains a list of 17 parameters out of which any two parameters can be retrieved at a time and plot against each other.

Program Structure

  • It must be noted that the data file and the program file must be int he same folder.
  • All the necessary modules are first imported and then all the initializations are done.
  • From the module 'os', module 'path' helps to check for the existence of the data file in the same folder.
  • The two parameters are taken from the user by their column numbers.
  • Through a 'for' loop, the entire file is traversed line by line with the help of a variable which stores each line every time as a list. This list is split to strings and the required columns are obtained and stored in separate variables.
  • These variables are plot against each other. The labels are also extracted from the data file similarly and stored as separate '.png' files.

The P-V plot

  • Pressure belongs to the 2nd column and Volume belongs to the 8th column. Once the above steps are completed, the area of the P-V curve calculated.
  • Depending on the slopes of the P-V curve, a number of pressure and volume arrays are formed which would help in arithmetic operation of the area covered under each group of pressure and volume values.
  • The function 'trapz' is imported from the module 'numpy'. This function is used to calculate the area under a given set of values on the Y-axis and. This function divides the region below set of Y values into many trapezoids which it takes as an input in the form of thickness of each trapezoid. Syntax: area variable = trapz(array of y values, dx = thickness of each trapezoid)
  • Once areas under individual curves are calculated, the net area of the P-V diagram is calculated by arithmetic operations. The area under this curve represents Torque imparted to the crank shaft.
  • Now, power is calculated by using the formula,

`P = (2*pi*N*T)/(60*1000)` kW , where N is rotations per minute and T is torque.

  • Specific fuel consumption is calculated by,

`SFC = (mass flow rate)/(power)*3600` kg/kW h.

Python Program

# Import modules
import matplotlib.pyplot as plt
import os.path
from os import path
import numpy as np
from numpy import trapz
import math


# Basic initializations
rpm = 1500
fuelrate = 20e-6*(1500/2)*60 #kg/hr
para1 = [] # Pressure in case of the given question
para2 = [] # Volume in case of the given question
p1 = []
p2 = []
p3 = []
v1 = []
v2 = []
v3 = []
linecount = 1

print('Note that the file "engine_data.out" and the this program file should be saved in the same folder!\n\n')

#Checking for the presence of the file 'engine_data.out' in the same folder

if path.exists("engine_data.out") == False:
	
	print('The file is not present in the current folder.')

else:

	lno1 = int(input("Enter the column number of the parameter to be set on the Y axis: "))  # The parameter on Y axis
	lno2 = int(input("Enter the column number of the parameter to be set on the X axis: "))  # The parameter on X axis
	print('\n')

	for line in open('engine_data.out'):
		if '#' not in line:
			para1.append(float(line.split()[lno1-1]))
			para2.append(float(line.split()[lno2-1]))

		if linecount is 3:
			yl1 = line.split()[lno1]
			xl1 = line.split()[lno2]

		if linecount is 4:
			yl2 = line.split()[lno1]
			xl2 = line.split()[lno2]

		linecount = linecount+1

	cross = " vs "
	filename = yl1+yl2+cross+xl1+xl2+".png"

	plt.figure()
	plt.plot(para2,para1,'-')
	plt.xlabel(xl1+xl2)
	plt.ylabel(yl1+yl2)
	plt.title(yl1+yl2+cross+xl1+xl2)
	plt.savefig(filename)
	print('A plot has been generated and saved in the same folder.')

	# This part of the program is executed in case Y and X parameters are Pressure and Volume
	if lno1==2 and lno2==8 :
		linecount = 1
		for line in open('engine_data.out'):
			if linecount>=(para2.index(max(para2))+1) and linecount<(para2.index(min(para2))+1):
				p3.append(float(line.split()[lno1-1])*pow(10,6))
				v3.append(float(line.split()[lno2-1]))

			if linecount>=(para2.index(min(para2))+1) and linecount<(para1.index(max(para1))+1):
				p2.append(float(line.split()[lno1-1])*pow(10,6))
				v2.append(float(line.split()[lno2-1]))

			if linecount>=(para1.index(max(para1))+1) :
				p1.append(float(line.split()[lno1-1])*pow(10,6))
				v1.append(float(line.split()[lno2-1]))

			linecount = linecount+1

		y1 = np.array(p1)
		y2 = np.array(p2)
		y3 = np.array(p3)


		area1 = trapz(y1, dx=0.00001)
		area2 = trapz(y2, dx=0.00001)
		area3 = trapz(y3, dx=0.00001)
		area = area1+area2-area3
		power = (2*math.pi*rpm*area)/(60*1000)
		sfc = (fuelrate/power)*3600
		print('The approximate area under the P-V curve is %.5f Nm. \n This value can be considered as torque produced.\n'%area)
		print('Power consumed = ',power,'kW')
		print('Specific fuel consumtion = ',sfc,' kg/kW h')

OUTPUT - P-V curve

Thank You.

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.