Week 6 - Data analysis
Introduction:
This assignment is to create an analysis of the then engine performance and represent it in the form of plots and values where the assignment is split into three parts ,data visualizer, compatibility check and basic performance calculation.
Explanation:
We start the code by importing all the needed modules, then create empty list to store the extracted data from the file so that the values can be used later to print plots and do calculations on.
Data visualizer :
This part of the program takes the column numbers as input and print the plot plots in a x-y plane to get a understanding of how the data varies with respect to the other data.
Compatibility check:
The code should exit without error message, 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. This value gives the work done by the engine and multiplying it with cycles per second we can calculate the power output of this engine. Assumed that RPM is 1500This engine consumed 20 micro grams of fuel (per 1 stroke cycle). Calculating its specific fuel consumption.
#impoting modules
import matplotlib.pyplot as plt
import numpy as np
from numpy import trapz
#data visualizer:
x=int(input("enter the number: "))
y=int(input("enter the number: "))
c1=[]
c2=[]
n1=[]
n2=[]
u1=[]
u2=[]
try:
for line in open('engine_data.out'):
if '#' not in line:
c1.append(float(line.split()[x-1]))
c2.append(float(line.split()[y-1]))
if '#' in line:
if '13' not in line:
if '(' not in line:
n1.append(line.split())
n2.append(line.split())
if '(' in line:
u1.append(line.split())
u2.append(line.split())
x_name=str(n1[0][x]+u1[0][x])
y_name=str(n2[0][y]+u2[0][y])
plt.plot(c1,c2)
plt.xlabel(x_name)
plt.ylabel(y_name)
plt.show()
except IndexError:
print("give a proper input")
except FileNotFoundError:
print("please check the file in the directory")
#performence calculation:
p=[]
v=[]
for line in open('engine_data.out'):
if '#' not in line:
p.append(float(line.split()[1]))
v.append(float(line.split()[7]))
plt.plot(v,p)
plt.show()
#work done
p=np.array(p)
v=np.array(v)
w=trapz(p,v)
#print(w)
rpm=1500 #cycles per second
power=w*(rpm/60)#mega joules per second
print("power: %f mega joules/second" %power)
sfc=(20*1e-3*1500/60)*3600/(power*1e+6)*1000## in g/kwh
print("specific fuel consuption: %d grams/kwh"%sfc)
plots and screen shots:
crank angle vs volume plot:
pressure vs volume plot:
power and bsfc calculation:
Passing out message to give in proper inputs using try and except:
Conclusion:
the above mentioned works are been done and the code was successfully executed.