Project

Data Analysis Using Python

Aim:The task is to write a script that does the following.

1.script should take column numbers as the input and plot the respective columns as separate images

2.Each file should be saved by the name of the column

3.The plot labels should be extracted from the file. If requested 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.

4.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"

5.Calculate the area under the P-V diagram. P is in column 2 and V is in column 8.

6.Calculate the power output of this engine. Assume that RPM is 1500.

7.Calculate its specific fuel consumption when this engine consumed 20 micro grams of fuel (per 1 stroke cycle).

Link for the file:

https://drive.google.com/file/d/1L8GY56d-M8mB1KfceM-xVhGNvnCIqxjm/view

Screenshot of the file:

Code:

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

#compatibility check
filename=input("Enter the filename with extension .out: ")
try:
	data=open(filename,'r')
except FileNotFoundError:
	print("File not recognized.Please provide a valid CONVERGE output file")	

#defining all the empty arrays where values from the file will be stored

Crank=[]
Pressure=[]
Max_Pres=[]
Min_Pres=[]
Mean_Temp=[]
Max_Temp=[]
Min_Temp=[]
Volume=[]
Mass=[]
Density=[]
Integrated_HR=[]
HR_Rate=[]
C_p=[]
C_v=[]
Gamma=[]
Dyn_Visc=[]
Kin_Visc=[]


line_count=1
for line in data:
	if '#' not in line:
		Crank.append(float(line.split()[0]))
		Pressure.append(float(line.split()[1]))
		Max_Pres.append(float(line.split()[2]))
		Min_Pres.append(float(line.split()[3]))
		Mean_Temp.append(float(line.split()[4]))
		Max_Temp.append(float(line.split()[5]))
		Min_Temp.append(float(line.split()[6]))
		Volume.append(float(line.split()[7]))
		Mass.append(float(line.split()[8]))
		Density.append(float(line.split()[9]))
		Integrated_HR.append(float(line.split()[10]))
		HR_Rate.append(float(line.split()[11]))
		C_p.append(float(line.split()[12]))
		C_v.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]))

		line_count=line_count+1
		
parameter = np.array([[0],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],dtype=object)
label=['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(N*s/m^2)']

print("nPlease choose from the list :nCrank=1 nPressure=2 nMax_Pres=3 nMin_Pres=4 nMean_temp=5 nMax_Temp=6 nMin_Temp=7 nVolume=8 nMass=9 nDensity=10 nIntegrated_HR=11 nHR_Rate=12 nC_p=13 nC_v=14 nGamma=15 nKin_Visc=16 nDyn_Visc=17 n")

#inputs to be given
x=input("Enter x axis parameter : ")
x=int(x)
y=input("Enter y axis parameter : ")
y=int(y)		

#plotting
plt.plot(parameter[x],parameter[y])
plt.xlabel(label[x-1])
plt.ylabel(label[y-1])

title=label[y-1]+ ' Vs ' +label[x-1]
plt.title(title)
plt.savefig(title+'.png')
plt.show()

#calculating area under the curve
work=np.trapz(parameter[2],parameter[8])
work=work*1e+6
print('nWork Done : ',work,'Joules')

#calculating power
power=work*(1500/(2*60))
print('nPower :',power,'Watts')

#calculating the specific fuel consumption
fuel_consumed=20*1e-6*3600*1000
sfc=(fuel_consumed)/power
print('nSpecific Fuel Consumption:',sfc,'g/KWhr')

Explanation of code:

1.Importing all the required libraries.

2.Compatibility test is done using try and except function.When the program is run ,if correct file is provided as input ,the rest of the code executes properly else it throws an error saying "File not recognized. Please provide a valid CONVERGE output file".

3.Empty arrays for different properties like crank,pressure,density etc are created where values from the file will be stored.

4.Next,individual line is read,split and the values are stored in the empty arrays created according to their column positions.

5. Printing the list which gives information about the parameters and their corresponding column number.

6.To plot the data between any two columns,the required column number from the above list can be chosen and provided as the inputs to obtain the plots.

7.The graphs between any two parameters with proper labels and title are obtained and saved using the savefig command.

8.Using trapz,the area under the PV diagram is calculated .Also the Power developed and Specific fuel consumption were also calculated using the formulas.

Results:

1.Compatibility test (Wrong Input)

2.Compatibility test (Correct file name)

3.Plot

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.