Challenge

Week 6 - Data analysis

Objective : Write a code for Data analysis using python.

Problem Statement :  write a script that does the following.

A IC engine data file has been provided .

Data visualizer :

  • The script should take column numbers as the input and plot the respective columns as separate images
  • Each file should be saved by the name of the column
  • The plot labels should be extracted from the file. If, I request for a plot between column 1 (crank angle) and column 8(volume), then the label information should automatically be extracted and must appear as labels in the plots. THIS SHOULD NOT BE DONE MANUALLY

Compatability check :

  • The code should exit gracefully, if a non-compatible file is provided as an input. It should say something like "File not recognized. Please provide a valid CONVERGE output file"

Basic performance calculation :

  • Calculate the area under the P-V diagram. P is in column 2 and V is in column 8.
  • Calculate the power output of this engine. Assume that RPM is 1500
  • This engine consumed 20 micro grams of fuel (per 1 stroke cycle). Calculate its specific fuel consumption.

 Solution Procedure:

Importing libraries and and then start doing compatability check by using try and except .

Creating empty arrays for the data values parameters,then  reading the file line by line by splitting them and converting into the float value and appending it into the above empty arrays by their column positions.

just creating array calld values to recognize by the input value and further use for plotting ,creating array for label for plots,

then plot the input data.

Also findind area , power ,sfc .

python code is following :

"""Data analysis using python """
import math
import matplotlib.pyplot as plt 
import numpy as np


#Compatability check
filename=input("Enter the filename with extension(.out): ")

#it stores the file to variable 'filename' with the extension '.out'
try:
	eng_data=open(filename,'r') #if the file ewith extension '.out' then the filename is stored in  'data'
except FileNotFoundError:
	print("File not recognized. Please provide a valid CONVERGE output file") #if not displays this message


#parameters and defining them by empty arrray
crank=[]
pressure=[]
max_pressure=[]
min_pressure=[]
mean_temp=[]
min_temp=[]
max_temp=[]
volume=[]
mass=[]
density=[]
int_hr=[]
hr_rate=[]
Cp=[]
Cv=[]
gamma=[]
kin_visc=[]
dyn_visc=[]

ct=1
for line in eng_data:  #reading the file line by line by splitting them and converting into the float value and appending it into the above empty arrays by their column positions                                           
	if '#' not in line:
		crank.append(float(line.split()[0]))
		pressure.append(float(line.split()[1]))
		max_pressure.append(float(line.split()[2]))
		min_pressure.append(float(line.split()[3]))
		mean_temp.append(float(line.split()[4]))
		min_temp.append(float(line.split()[5]))
		max_temp.append(float(line.split()[6]))
		volume.append(float(line.split()[7]))
		mass.append(float(line.split()[8]))
		density.append(float(line.split()[9]))
		int_hr.append(float(line.split()[10]))
		hr_rate.append(float(line.split()[11]))
		Cp.append(float(line.split()[12]))
		Cv.append(float(line.split()[13]))
		gamma.append(float(line.split()[14]))
		kin_visc.append(float(line.split()[15]))
		dyn_visc.append(float(line.split()[16]))
		ct=ct+1

#just creating array calld values to recognize by the input value and futher used for ploting

values=np.array([[0],crank,pressure,max_pressure,min_pressure,mean_temp,max_temp,min_temp,volume,mass,density,int_hr,hr_rate,Cp,Cv,gamma,kin_visc,dyn_visc])

#for label for plots
variable=['crank(Degree)','pressure(MPA)','Maximum Pressure(MPA)','Minimum Pressure(MPA)','Mean Temperature(K)','Maximum Temperature(K)','Minimum Temperature(K)','Volume(m^3)','Mass(kg)','Density(kg/m^3)','Integrated_HR(J)','HR_Rate(J/time)','C_p(J/kg-K)','C_v(J/kg-K)','Gamma','Kinematic Viscosity(m^2/s)','Dynamic Viscosity(Ns/m^2)']



#the above numbers must be given as the inputs to obtain the plots
x=input(" please enter x-coordinate index ")
x=int(x)
y=input(" please enter y-coordinate index ")
y=int(y)

#plotting the results

plt.plot(values[x],values[y], color='red',linewidth=3)
plt.xlabel(variable[x-1])
plt.ylabel(variable[y-1])
plt.show()	
	
#area under the curve (work done)

Area=np.trapz(pressure,volume)                                         
print ('Area under PV diagram is :',Area)

#power

Power=Area*1500/60                                                         
print ('power output of engine is:',Power,'MW')

#specific fuel consumption

SFC=(20*12.5*3.6*pow(10,-6))/Power                                     
print ('specific fuel consumption is :',SFC,'g/kWh')



Results and Discussion:

Data visualizer ,Compatability check, Basic performance calculation :

taking input 8 and 2 :

plot :

taking input as 1 and 2.

output :

plot :

So, By above results and plots we have successfully completed the Data visualizer ,Compatability check, Basic performance calculation . 

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.