DATA ANALYSIS USING PYTHON
OBJECTIVE:
The main objective of this challenge is to read all the data from given data table and execute the following results
- 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.
CODE FOR GIVEN DATA ANALYSIS:
#data analysis
import matplotlib.pyplot as plt
import numpy as np
import os
import math
ct=1
try:
crank=[]
pressure=[]
max_press=[]
min_press=[]
mean_temp=[]
max_temp=[]
min_temp=[]
volume=[]
mass=[]
density=[]
integrated_hr=[]
hr_rate=[]
c_p=[]
c_v=[]
gamma=[]
kin_visc=[]
dyn_visc=[]
z=input(\"enter file name: \")
for line in open(z):
if \'#\' not in line:
crank.append(float((line.split()[0])))
pressure.append(float((line.split()[1])))
max_press.append(float((line.split()[2])))
min_press.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])))
x=int(input(\"first column number: \"))
y=int(input(\"second column number: \"))
w=np.array([crank,pressure,max_press,min_press,mean_temp,max_temp,min_temp,volume,mass,density,integrated_hr,hr_rate,c_p,c_v,gamma,kin_visc,dyn_visc])
f = open(z,\"r\")
a=f.readline()
b=f.readline()
c=f.readline()
d=f.readline()
c1=c.split()
d1=d.split()
area=np.trapz(w[1],w[7])
area=area*1000
print(area,\'(KJ)\',\'area\')
power=(area*2*math.pi*25)
print(power,\'(KW)\',\'power\')
sfc=(20*pow(10,-9)*3600)/(power*0.08)
print(sfc,\'(Kg/KWH)\',\'specific fuel consumption\')
BHP=power/0.746
print(BHP,\'brake horse power\')
plt.plot(w[x-1],w[y-1])
plt.xlabel(c1[x]+d1[x])
plt.ylabel(c1[y]+d1[y])
plt.title( str(c1[x])+ \" vs \" +str(c1[y]) )
plt.show()
plt.savefig(str(c1[x])+ \"vs\"+ str(c1[y]))
except FileNotFoundError as e:
print(\"FILE IS NoT VALID\")
COMMANDS USED IN THE CODE:
matplotlib -> matplotlib is an amazing visualization library in python for 2D plots of arrays.This command is used to plot graphs using the code
math -> This library is uesd when we use the trigonometric functions
def () -> This keyword is used to define function along with all suitable parameters related to the problem
return() -> The return statement is used when a function is ready to return a value to its caller.
numpy -> This module is used for assigning n vaues in between two values with same common difference
append() -> This function is used to append the calculated values in an empty array
plt.figure() -> This command is used to display the multiple graphs at a time side by side to compare results
plt.plot() -> This command is used to draw graphs according to their assigned values
plt.label() -> This command is used to label the axis to differentiate the values on the curves
plt.show() -> This command is used to display the results graphs on the screen as output
plt.savefig() -> This command is used to save the output images in particular folder
plt.title() -> This command is used to give title for the drawn graph
plt.legend() -> This command is used to label inside the graph
scipy -> This library is used to get access to the function with which we plot graph for given data points
curve_fit() -> This function is used for fitting the curve according to the given data
func() -> This function is used to define a function for drawing a curve
open() -> This is used to open file and read the data
line.split() -> This function is used to split data into to arrays
float() -> This function is used to assign decimal values to the variable
readfile() -> This file is used to read the line of the given data
input() -> This function is used to give any input manually after to execute the given condition
trapez() -> This function is used to calculate the area of trapezium shaped curve
OUTPUT:
PLOT CRANK ANGLE VS VOLUME:
COMPATABILITY CHECK:
enter file name: data.out
FILE IS NoT VALID
***Repl Closed***
- If we give any file name other than data file name it wont execute the code and program terminates by showing the error as FILE IS NOT VALID
CALCULATION OF AREA UNDER P-V CURVE,POWER,SPECIFIC FUEL CONSUMPTION AND BRAKE HORSE POWER:
enter file name: engine_data.out
first column number: 2
second column number: 8
0.5005866274680075 (KJ) area
78.63196356693915 (KW) power
1.1445727146745263e-05 (Kg/KWH) specific fuel consumption
105.40477689938224 brake horse power
***Repl Closed***
CONCLUSION:
- Giving column numbers to the titles is completed
- plotting the curves between column numbers is completed
- compatability check is completed
- calculation of area under p-v curve i.e., work done,power, specific fuel consumption and brake horse power is completed and mention its units