Challenge

Week 6 - Data analysis

DATA ANALYSIS

AIM – Write python program to use engine simulation data provided to us in manner that it checks compatibility of given file and can plot graphs between any two parameters. Also, calculate work, power and specific fuel consumption for give data file using area under PV diagram.

OBJECTIVES-

  1. Read the given data file and also create a compatibility check whether the output file is exactly like what this program is intended for.
  2. Get input from user for both parameters they want to visualize.
  3. Format the data provided in such a manner that it could be used by us.
  4. Plot the graph for given input parameter.
  5. Calculate work, power and specific fuel consumption for give data file using area under PV diagram.

 Link to DATA file

INTRODUCTION-

Data analysis is defined as a process of cleaning, transforming, and modelling data to discover useful information for business decision-making. The purpose of Data Analysis is to extract useful information from data and taking the decision based upon the data analysis.

PROCEDURE-

  1. Use ‘open’ command to read given data file.
  2. Use ‘try’ and ‘except’ command to check format compatibility of given file. It also displays exit message in case file is found incompatible.
  3. Use ‘transpose’ command to transpose these multidimensional matrices.
  4. Typecast the data in these matrices to float.
  5. Following code will display a list of parameters along with numerical inputs that user can give to select parameters.
  6. Further, it will generate and save the plot by name of columns.
  7. For area under PV curve has been done using Trapezoidal rule for integration.
  8. The values for work, power and specific fuel consumption has also been done.
"""
Demonstrate file parsing using python
By Sushant Kumar Mishra
"""

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

#basic initialisation
A=[]

try:f =open('engine_data.out','r')
except File_not_found_error:
	print("File not recognized. Please provide valid output Converge file")
	sys.exit(1)

print('Input coloumn number of parameter you want to be plot from following list \n0\tCrank \n1\tPressure \n2\tMax_Pres \n3\tMin_Pres \n4\tMean_Temp \n5\tMax_Temp \n6\tMin_Temp \n7\tVolume \n8\tMass \n9\tDensity \n10\tIntegrated_HR \n11\tHR_Rate \n12\tC_p \n13\tC_v  \n14\tGamma \n15\tKin_Visc \n16\tDyn_Visc')
i=int(input("Input coloumn number of parameter to be plotted on x axis"))
print(i)
j=int(input("Input coloumn number of parameter to be plotted on y axis")) 
print(j)

parameter=['Crank','Pressure','Max_Pres','Min_Pres','Mean_Temp','Max_Temp','Min_Temp','Volume','Mass','Density','Integrated_HR','HR_Rate','C_p','C_v','Gamma','Kin_Visc','Dyn_Visc']
C=[]
D=[]
line_count=1
#File parsing starts here
for line in f:
	if '#' not in line:
		A.append(line.split())
		C.append(float(line.split()[i]))
		D.append(float(line.split()[j]))
		line_count = line_count +1

plt.plot(C,D,linewidth=3,color='green')
plt.xlabel(parameter[i])  
plt.ylabel(parameter[j]) 
plt.title(parameter[i]+' vs '+parameter[j],color='b',fontsize=14)
plt.savefig(parameter[i]+' vs '+parameter[j]+'.png')  
plt.show()

B=np.transpose(A)
B=B.astype(np.float)

#Area under PV graph using trapezoidal rule
Xvar=B[1]
Yvar=B[7]

dx=[]
k=0
while k<8664 :
	dif=Xvar[k+1]-Xvar[k]
	dx.append(dif)

	k=k+1

W=[]
Work=0
t=0
while t<8664:
	W.append(((dx[t]/2)*(Yvar[0]+2*(Yvar[t+1]+Yvar[8664]))))

	t=t+1

for n in range(0,len(W)):
	Work= Work +W[0]

#Work, Power and Specific fuel consumption in 
Work=Work*1000000
print('Work Output in Joules is:')
print(abs(Work))

Power= (Work*2*1500*math.pi*0.001)/60
print('Power Output in Watts is:')
print(abs(Power))

Sfc=20*pow(10,-9)/abs(Power)
print('Specific fuel consumption is')
print(Sfc)

plt.plot(B[7],B[1],color='red')
plt.title('PV diagram',fontsize=20,color='black')
plt.show()

RESULTS-

CONCLUSION AND EXPLANATIONS-

  1. Make sure to write function correctly as there are high chances of making a typing error like missing a parenthesis, writing incorrect formula.
  2. It’s important to first clean and model out our data so that it can be executed in suitable way.
  3. Also, the incompatibility exit code should clearly state error in format of file provided.
  4. Data analysis clearly increases our easiness to handle such a large amount of data.
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.