Challenge

Week 6 - Data analysis

Analysis of data is a vital part of running a successful business. When data is used effectively, it leads to better understanding of a business’s previous performance and better decision-making for its future activities. There are many ways that data can be utilized, at all levels of a company’s operations.

There are four types of data analysis that are in use across all industries. While we separate these into categories, they are all linked together and build upon each other. As you begin moving from the simplest type of analytics to more complex, the degree of difficulty and resources required increases. At the same time, the level of added insight and value also increases.

Four Types of Data Analysis

The four types of data analysis are:

1.Descriptive Analysis, 2. Diagnostic Analysis, 3. Predictive Analysis, 4. Prescriptive Analysis

Below, we will introduce each type and give examples of how they are utilized in business.

Given Data:

RPM =1500, Fuel consumption = 20micro grams per stroke cycle.

Power output by the engine = Wout*RPM*no.of cylinders(n)/(60*1000*2) in kW

n-number of cylinders of engine, RPM – engine speed in minutes. Wout = work done by the engine

Specific fuel consumption = Fuel consumption per unit time/power (kg/kW-hr)

1] Import the modules such as Math, matplotlib, NumPy, SciPy for performing their respective functions.

2] For the purpose of plotting the curves between 2 quantities as per the user input, a line counter is initiated from 1. Now an "if" loop is iterated with the condition if '#' not in line all the numerical values present in the data file is now to be stored in the data array as string. Now another "if" loop is executed with the condition that line counter greater than or equal to 6 all the data will be stored in the pressure and volume array respectively.

3] For Engine performance calculations, the area under the PV diagram has to be calculated and we are using Simpson method for calculating it.

4] Two arrays of name of parameters and their units are made as per the data file given and then the user has to choose from them to plot respective graphs. For these 2 inputs of the user are taken using the input command and data type is set as 'int'. The user is entering column number as input and results are generated.

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

# Checking the compatability of file 
f_name =input("Enter the file name:...")

if f_name == 'engine_data.out':

	print('file is Valid')

else:
	print('file is invalid')

	exit()

def compatibility_check(a):

	if 'CONVERGE' not in a:
		print('Please provide converge output file to process')

		exit()

	else:

		print('Compatability check is Successful')

	
		pass

#try:
open('engine_data.out')

line_count =1
#Creating an empty array to store the values of pressure,Volume respectively.

pressure =[]
volume  =[]

# Creating Null array to store the all values in data file.

data =[] 

#File parsing starts here
for line in open('engine_data.out'):
	if '#' not in line:        

		data.append(line.split())
		pressure.append(float(line.split()[1]))
		volume.append(float(line.split()[7]))

		line_count = line_count+1


#Plotting P-V diagram & saving it to file
plt.plot(volume,pressure,linewidth=3)
plt.xlabel('Volume in m^3')
plt.ylabel('pressure in MPa')
plt.title('P-V Diagram of Engine')
plt.grid()
plt.savefig('P-V Diagram of Engine')
#plt.show()


# calculating  Work done by engine using simpsons rule from P-V Diagram
print('Calculations using Simpsons rule \n')
area =simps(pressure,volume)
print('Area under the curve using Simpson Rule: ' +str(area) +' units''\n')
print('Work done by the engine: '+str(area) +' MJ''\n')
area = area*1e6
print('Work done by engine: '+str(area) +' J''\n')

# calculating the output power by engine using given parameters
rpm =1500
rps = 1500/60
stroke_cycle = rps/2
f_consmp = 20   # fuel consumption is micrograms per stroke cycle

# Engine specifications 
n = 1 # Number of cylinder of four stroke engine 

# Calculation of power output & Specific fuel consumption 
power_output = n*area*stroke_cycle/1000
print('Power output of engine: '+str(power_output) +' KW''\n')
SFC = (f_consmp*pow(10,-6)*stroke_cycle*3600)/(power_output*1000)
print('Specific Fuel Consumption(SFC): '+str(SFC)+'(kg/hr)/KW')
print('----------------------------- \n')


# calculating  Work done by engine,power Output, specific fuel consumption using Trapezoidal rule from P-V Diagram
print('Calculations using trapezoidal rule \n')
area_tpz = np.trapz(pressure,volume)
print('Area under curve using trapezoidal rule:'+str(area_tpz)+' units''\n')
area_tpz = area_tpz*1e6
print('Work done by engine : '+str(area_tpz)+' J''\n')
power_output_tpz = n*area_tpz*stroke_cycle/1000 
print('Power output of engine: '+str(power_output_tpz)+' KW''\n' )
SFC_tpz =(f_consmp*pow(10,-6)*stroke_cycle*3600)/(power_output_tpz*1000)
print('Specific Fuel Consumption (SFC): '+str(SFC_tpz)+'(kg/hr)/KW')
print('--------------------------------- \n')


# Transposing coloumns into row matrix and converting them into float from string type
transpose = np.transpose(data)
float_f = transpose.astype(np.cfloat) 

# Array for header and their units
parameters = ['Crank','Pressure','Max.Pressure','Min.Pressure','Mean.Temp','Max.Temp',
'Min.Temp','Volume','Mass','Density','Integrated_HR','HR_Rate','C_p','C_v','gamma','Kinematic Viscosity',
'Dynamic Viscosity']
Units = ['(Deg)','(MPa)','(MPa)','(MPa)','(K)','(K)','(K)','(m^3)','(kg)','(Kg/(m^3))','(J)','(J/time)','(J/kg-K)',
'(J/kg-K)','','(m^2/s)','(Ns/m^2)']

# Providing User choice of picking 2 parameters for plotting
print('Choose the Number from the following Options & Press enter key')
print('1 for Crank \n','2 for Pressure \n','3 for Max.Pressure \n','4 for Min.Pressure \n','5 for Mean.Temp \n','6 for Max.Temp \n',
	'7 for Min.Temp \n','8 for Volume \n','9 for Mass \n','10 for Density \n','11 for Integrated_HR \n','12 for HR_Rate \n','13 for C_p \n','14 for C_v \n',
	'15 for Gamma \n','16 for Kinematic Viscocity \n','17 for Dynamic Viscocity \n')

X = int(input('Enter the Number of choice on X-axis : '))
Y = int(input('Enter the Number of choice on Y-axis : '))

# Plotting figure based on user choice
plt.figure(parameters[Y-1]+ 'Vs'+parameters[X-1])

plt.plot(float_f[X-1],float_f[Y-1], linewidth = 4,color= 'goldenrod')
plt.title('Plot for ' +parameters[Y-1]+  ' Vs '  +parameters[X-1],color = 'goldenrod')
plt.xlabel(parameters[X-1]+''+Units[X-1])
plt.ylabel(parameters[Y-1]+''+Units[Y-1])
plt.grid()
plt.savefig(parameters[Y-1]+ ' Vs ' + parameters[X-1])
plt.show()

Output:

Plots for random 2 more inputs:

Conclusion:

Code created for given data & Output generated.

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.