Project

Data Analysis

PROGRAM:

\'\'\'
Data analysis
\'\'\'
#Import Modules
import matplotlib.pyplot as graph
import numpy as np 
from numpy import trapz as trp

#input the data
data_file = \'engine_data.out\'
n = 0
Header = 0
Col_Name = []
col_units = []
for line in open(data_file,\'r\'):
	if \'#\' not in line:
		n = n + 1
		cols = len(str.split(line))  # columns
	else:
		Header = Header +1
		if Header == 3:
			line_value = str.split(line)
			for i in range(0,len(line_value)):
				Col_Name.append(line_value[i])
		elif Header == 4:
			line_value = str.split(line)
			for i in range(0,len(line_value)):
				col_units.append(line_value[i])


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

	column_no = 1
	while (column_no <= cols):
		graph.plot(data[:,column_no-1])
		graph.ylabel(Col_Name[column_no]+col_units[column_no])
		graph.savefig(Col_Name[column_no]+\'.png\')
		graph.figure()
		column_no = column_no + 1


	x_col_no = 8
	y_col_no = 2
	x_data = np.array(data[:,x_col_no-1])
	y_data = np.array(data[:,y_col_no-1])
	graph.plot(x_data,y_data)
	graph.xlabel(Col_Name[x_col_no]+col_units[x_col_no])
	graph.ylabel(Col_Name[y_col_no]+col_units[y_col_no])
	graph.savefig(Col_Name[y_col_no]+\' VS \'+Col_Name[x_col_no]+\'.png\') 


	area = trp(y = y_data.transpose(), x = x_data.transpose())
	print(\'Area under Pressure-Volume 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)\')

OUTPUT:

\"\"

The main ideology of the data analysis program is, how to navigate through a large amount of data and extract the necessary data from the bulk on demand and use the data from the file containing the data directly and perform calculations.

The above data analysis program extracts the data from the file \'engine_data.out\' and performs calculations to compute the area under the p-v curve which gives the work done by the system under consideration and it also calculates the power and the Specific fuel consumption in a case where the engine consumes 20 micro grams of fuel.

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.