Challenge

Week 6 - Data analysis using Python

Aim: To write a script that does data analysis on python

Objective:

1) Visualizing the data by opening and reading the file and plotting the graph between user desired entities.
2) Compatibility check, i.e, code should exit gracefully if a non-compatible file is provided.
3) To calculate basic engine performance calculations.

Introduction:
Data analysis is a process of inspecting, cleansing, transforming, and modeling data with the goal of discovering useful information, informing conclusions, and supporting decision-making. Data analysis has multiple facets and approaches, encompassing diverse techniques under a variety of names, and is used in different business, science, and social science domains. In today's business world, data analysis plays a role in making decisions more scientific and helping businesses operate more effectively. Using 4 types of analysis, the

  • Descriptive Analysis: Descriptive data analysis looks at past data and tells what happened. This is often used when tracking Key Performance Indicators (KPIs), revenue, sales leads, and more.
  • Diagnostic Analysis: Diagnostic data analysis aims to determine why something happened. Once your descriptive analysis shows that something negative or positive happened, diagnostic analysis can be done to figure out the reason. A business may see that leads increased in the month of October and use diagnostic analysis to determine which marketing efforts contributed the most.
  • Predictive Analysis: Predictive data analysis predicts what is likely to happen in the future. In this type of research, trends are derived from past data which are then used to form predictions about the future. For example, to predict next year’s revenue, data from previous years will be analyzed. If revenue has gone up 20% every year for many years, we would predict that revenue next year will be 20% higher than this year. This is a simple example, but predictive analytics can be applied to much more complicated issues such as risk assessment, sales forecasting, or qualifying leads.
  • Prescriptive Analysis: Prescriptive data analysis combines the information found from the previous 3 types of data analysis and forms a plan of action for the organization to face the issue or decision. This is where data-driven choices are made.

These 4 types of data analysis can be applied to any issue with data related to it. And with the internet, data can be found about pretty much everything.

Data analysis has been used here to open and read the contents of the data and perform some basic calculations using certain formulas.

Governing Equations used:

Since the data file consists of various parameters for an engine, the file contents can be used to perform certain basic engine calculations.
The quantities calculated here are:

  • Work done by the engine (Area under the curve).
  • The power output of the engine. This is generally called engine brake power.

Using the 'trapezoidal' rule and 'Simpsons' rule, the area under the curve can be computed. For calculating the power and the specific fuel consumption, the following equations are used:

`Power = (W_(out) * RPM * n)/(60*1000*2)` in kW. Here, n is the number of cylinders of the engine. RPM is converted to RPS. Given a 4-stroke engine , the entire term is divided by 2.

`SFC = (FC)/(Power`, where FC is the amount of fuel consumed by the engine in kg/hr

INPUTS: RPM = 1500 , fuel consumed per stroke = micro grams.

Procedure:

The first step is to import the useful modules in python

The next part of the assignment is to perform a compatibility check on the file.

The next part of the program asks the user which file he/she would like to open. It opens the file and prints out the data available to us.

From this point on, the user is asked to input the column numbers for which he would like to display the data.

After that, the selected columns are separated into lists and the graph is plotted

The final part of this assignment will be to calculate Power and SFC.

CODE IN Python:

import math
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import simps
from numpy import trapz

'''
objective: 1) make python read the file. 2) ensure it ignores the redundant line. 3) using linesplit() command, the columns can be split. convert strings to 4) read whichevercolumn you need using the linespit()[]. Also set a counter for line-count.
'''
line_count = 1
number_of_column = 17
myfile = (input('which file would you like to read : '))

if myfile == 'engine_data.out':
	with open(myfile,'r') as f:
		for each_line in f:
				if 'CONVERGE' in each_line:
					testfunc()


    

else:
    print('File not comptaible. Please input a valid CONVERGE file')



def testfunc():    

	#Dsiplaying the data available:
	i = 1
	lis1 = []
	lis2 = []
	for row in open('engine_data.out'):

		if i == 3:

			a = (row.split())
		elif i == 4:
			b = (row.split())

		i = i + 1
	c = []
	m = []
	print('Data available to us right now is: ')
	for l in range(0,17):
	    
	    c = a[l + 1] + b[l + 1]
	    m.append(c)
	    print(c)
	    
	    


	#Taking column numbers as input

	x, y = input("Enter the column numbers : ").split()
	j = int(x)
	k = int(y)
	n = 1



	lis1 = []
	lis2 = []
	with open(myfile,'r') as read_obj:

					for proceed in open(myfile):
						line_count = 1

						if '#' not in proceed:

							lis1.append(float(proceed.split()[j]))
							lis2.append(float(proceed.split()[k]))
							line_count = line_count+1






	plt.plot(lis2,lis1)
	plt.xlabel(m[k])
	plt.ylabel(m[j])
	filename = (m[j]) + ('vs') + (m[k]) + '.png'
	plt.savefig(filename)
	plt.show()

	if j == 1 and k == 7:
		# Calculation of area under the curve using Trapz rule
		Area_Trapz = trapz(lis1,lis2)
		print('Area using Trapz rule: ',Area_Trapz)
		final_area = Area_Trapz*1e6
		print('Area: ',final_area)

		#Calculation of area under the curve using Simpsons rule
		Area_sim = simps(lis1,lis2)
		print('area using simpson rule:',Area_sim)

		#calculation of Engine power output and the Specific Fuel Consumption


		RPM = 1500 
		RPS = RPM/60
		stroke_cycle = RPS/2
		fuel_consumption = 20

		power_output = n*final_area*stroke_cycle/(1000) 
		print('Power output from the engine' + str(power_output) + 'kW')


		SFC = (fuel_consumption*pow(10,-6)*stroke_cycle*3600)/(power_output*1000)
		print('specific Fuel Consumption =' + str(SFC) + 'kg/hr')

Results:

Output Window:

Engine Calculations:

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.