Week 6 - Data analysis
INTRODUCTION:
Data analysis is defined as a process of cleaning, transforming, and modeling 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.
import matplotlib.pyplot as plt
import math
import numpy as np
crank=[]
pressure=[]
max_pres=[]
min_pres=[]
mean_temp=[]
min_temp=[]
max_temp=[]
volume=[]
mass=[]
density=[]
hr_rate=[]
integrated_hr=[]
c_p=[]
c_v=[]
gamma=[]
kin_visc=[]
dyn_visc=[]
label=[]
units=[]
filename=input('enter a converge output file: ')
try:
file=open(filename,'r')
line_count=1
for line in file:
if '#' in line:
if line_count is 3:
for j in range(1,18):
label.append(line.split()[j])
if line_count is 4:
for k in range(1,18):
units.append(line.split([k]))
line_count=line_count+1
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_r.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]))
inp=np.array([[0],crank,pressure,max_pres,min_pres,mean_temp,min_temp,max_temp,volume,mass,density,hr_rate,integrated_hr,c_p,c_v,gamma,kin_visc,dyn_visc])
print('\n enter the engine parameters:')
x=input("engine parameter the x axis: ")
x=int(x)
y=input("engine parameter the y axis: ")
y=int(y)
ply.plot(inp[x],inp[y])
plt.title(str(label[x-1])+'v'+str(label[y-1])+'plot')
plt.xlabel(str(label[x-1])+str(units[x-1]))
plt.ylabel(str(label[y-1])+str(units[y-1]))
plt.savefig(str(label[x-1])+'v'+str(label[y-1]))
plt.show()
if x==2 and y==8 or x==8 and y==2:
rpm=input('\n what is the engine rpm?')
rpm=float(rpm)
r=input('\n what is the fuel consumption?')
r=float(r)
t=np.trapz(inp[x],inp[y])
p=(2*math.pi*rpm*t)/(60)
sfc=((r*rpm)(pow(10,-6))(3600))/(p*1000*60)
print('\n area under the pv plt =t=',t,'n-m')
print('\n power=',p,'mw')
print('\n sfc=',sfc,'g/k2-h')
except:
print("enter a valid converge output file:")
OUTPUTS:
THE P-V PLOT OBTAINED BY THE CODE
THE COMMANDS LINE ARGUMENTS INPUTS TO OBTAIN THE RESULTS
the code is written in such a way that the file must be an output file from converge ,if not error will be displaced
EXPLANATION OF THE CODE:
1) Import all necessary libraries for operations like- calculation, plotting graph.
2) Do compatability check using try and except condition.
3) Initially make total numbers of row, column, header be zero and make a empty array of title.
4)Using for loop, line in open('engine_data.out) which basically open each line in file and we are able to find total numbers of lines(row).
5header_count which means header information is in line3 in file.
6)for i in which means it seperates each data line by line.
7)column_title.append(str.split(line)[il) which append the column name in each column.
8)Make a data array empty and append its value using for loop and save it with column name.
9)Make empty array of pressure, volume.
10)Read each line using linel in open('engine_data.out).
11)Pressure. append(float(linel .split()[l]) which means the pressure data are in second column and append the value in pressure and volume and similarly for volume array.
12)Make empty array of work and using for loop and append the value of work using formula- and print the result. speed = 1 500/60 and power can be calculated as it can be calculated as given formula- mass_fuel = and specific_fuel_consumption - (mass_fuel*3600)/Power and print the result.