Week 6 - Data analysis
AIM: Performing Data Analysis of engine using Python.
OBJECTIVE
- Make data visualizer and perform the data analysis.
- Plot the graph for column number which is given by user.
- Calculate the area under PV diagram.
- Find the power output of the engine.
- Find specific fuel consumption.
PROBLEM STATEMENT
Data visualizer
- Your 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
Compatibility check
- You 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.
DATA ANALYSIS
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.
Whenever we take any decision in our day-to-day life is by thinking about what happened last time or what will happen by choosing that particular decision. This is nothing but analyzing our past or future and making decisions based on it. For that, we gather memories of our past or dreams of our future. So that is nothing but data analysis. Now same thing analyst does for business purposes, is called Data Analysis.
For this challenge, we have to write program to read the file or check that file is converge or not. Then take the data from file performing some operation on it.
FORMLA USED:
1.Power Output
`P=W/s` watt
We know that the power is nothing but work-done per second. Area under the PV diagram gives work-done/cycle. For calculate the power output, we need to multiply work done/cycle with No. of power stroke/second.
Now for 4 stroke engine no. of power stroke is equal half of the engine rpm because this engine complete 1 cycle in 2 revolution. So,
`P=W×N/(60×2)` watt
`P=(W×N)/(60×1000×2)` KW
2.Specific Fuel Consumption
It is the ratio of mass of fuel consumption to power output.
Where
Mass of fuel consumption in Kg/h
For our case fuel consumption is given in to micro gram/cycle. So, we have to convert them into Kg/h. for these we have to multiply the No. power stroke /hour and 10-9.
STEP-WISE EXPLANATION OF CODE
- First, we have to import some important module like math, matplotlib, numpy, scipy, os and simps.
- For check the input file is converge or not I use try and except statement.so it gives error if the file is not present or not in proper type.
- Now I create empty array and then use for loop to extract the line and split the line and append the values in empty array.
- Again, I check the input file is converge or not by checking no. or rows equal to 8670 or not using if-else statement.
- In this if statement, I used another if statement to check the input file.
- If the file is converged than whole program is run so I use else command for above for loop.
- In this else command, first I extract the column no. column label and unit of parameter arrays and save them in particular variable.
- Then I delete unwanted elements from these 3 arrays.
- Now file has 17 different parameter columns so I create the 17 empty arrays.
- Data value of these parameter start from the 6 rows of file. So, I used the for loop from 6 loop to length of file and extract the data value of different parameter and appending the value in particular empty array of that parameter.
- I store all the array in one array.
- Then I print the information like which column contain which parameter. So, user can give the input easily from see the information.
- Now, I take the inputs for x and y axis column no. and check the input that it is in range and it gives proper input or not.
- I print the x and y axis parameter to check user give right input column no. for plotting graph.
- Now I create the directory to save the all the plot figure in it using mkdir command from os module.
- I create some variable of plot like title, x-label, y-label and filename which extract information from file automatically.
- Then I plot the graph.
- Now I calculate the area under the PV diagram using simps command from scipy.integrate module.
- Print the area under PV diagram.
- Then I calculate the power using formula which is discuss above in formula used section.
- I convert the fuel consumption to Kg/h and calculate Specific fuel consumption using formula discuss above.
- Then I write the else command of first if statement which check the length of the file row.
PROGRAM
#perfoming data analysis and calculate some parameters
import math
import matplotlib.pyplot as plt
import numpy as np
import os
from scipy.integrate import simps
#Compatability check
try:
f=open('engine_data.out','r')
except:
print('File not recognized. Please provide a valid CONVERGE output file')
#read the file and convert it in form of array
all_row=[]
count=1
for line in f:
a=line.split()
all_row.append(a)
if len(all_row)==8670:
if 'CONVERGE' not in all_row[0][1]:
print('File not recognized as original. Please provide a valid CONVERGE output file')
else:
print('you are entered valid file')
#extract the data of column no,label and unit in particular array
column_no=all_row[1]
label=all_row[2]
unit=all_row[3]
#delete unwanted data from array
del(column_no[0],column_no[0],label[0],unit[0])
#extrct the values of parameter and append in parameter array
crank=[]
pressure=[]
max_pres=[]
min_pres=[]
mean_temp=[]
max_temp=[]
min_temp=[]
volume=[]
mass=[]
density=[]
HR=[]
HR_rate=[]
cp=[]
cv=[]
gamma=[]
kin_vis=[]
dyn_vis=[]
data_row=all_row[5:]
for i in range(len(data_row)):
crank.append(float(data_row[i][0]))
pressure.append(float(data_row[i][1]))
max_pres.append(float(data_row[i][2]))
min_pres.append(float(data_row[i][3]))
mean_temp.append(float(data_row[i][4]))
max_temp.append(float(data_row[i][5]))
min_temp.append(float(data_row[i][6]))
volume.append(float(data_row[i][7]))
mass.append(float(data_row[i][8]))
density.append(float(data_row[i][9]))
HR.append(float(data_row[i][10]))
HR_rate.append(float(data_row[i][11]))
cp.append(float(data_row[i][12]))
cv.append(float(data_row[i][13]))
gamma.append(float(data_row[i][14]))
kin_vis.append(float(data_row[i][15]))
dyn_vis.append(float(data_row[i][16]))
data=[crank,pressure,max_pres,min_pres,mean_temp,max_temp,min_temp,volume,mass,density,HR,HR_rate,cp,cv,gamma,kin_vis,dyn_vis]
#printing information of file
print('Column Name and Column No in file as below:')
for j in range(len(column_no)):
print(label[j],'=',j+1)
#take the inputs from user
x=input('Enter the column no for X-axis=')
try:
x=int(x)
if x not in list(range(1,17)):
print('ERROR: Enter number between 1 to 17')
except:
print('ERROR: Valid number(Accepted value:1 to 17)')
x=x-1
print(label[x])
y=input('Enter the column no for Y-axis=')
try:
y=int(y)
if y not in list(range(1,17)):
print('ERROR: Enter number between 1 to 17')
except:
print('ERROR: Valid number(Accepted value:1 to 17)')
y=y-1
print(label[y])
#make the directory for saving plot
path='F:\Skill lync\python\Data analysis\plot'
print(path)
try:
os.mkdir(path)
print("Directory " , path , " Created ")
except FileExistsError:
print("Directory " , path , " already exists")
#plotting the graph
title=label[y]+unit[y]+' '+'VS'+' '+label[x]+unit[x]
x_label=label[x]+unit[x]
y_label=label[y]+unit[y]
filename=label[y]+' '+'VS'+' '+label[x]
plt.plot(data[x],data[y])
plt.xlabel(x_label)
plt.ylabel(y_label)
plt.title(title)
plt.savefig('plot/{}'.format(filename))
plt.show()
#calculate area under the P-V diagram which gives the workdone
area=simps(data[1],data[7])*pow(10,6)
print('Area under P-V diagram=',area)
#calculate power output for single cylinder and four stroke engine
n_c=1
N=1500
P=area*N/(1000*2*60)
print('Power output in KW=',P)
#calculate Specific fuel consumption
fs=20*pow(10,-9)*60*(N/2)
sfc=fs/P
print('Specific Fuel Consumption in Kg/KWh=',sfc)
else:
print('File not recognized original as there are some data line missing. Please provide a valid CONVERGE output file')
RESULTS
COMPATIBILITY CHECK SCREEN-SHOT
1.when the file is not present in folder or file having different file type
2.If the file not having 8670 rows
3.If the file has not ‘converge’ word in first line
DIFFERENT PLOT
Pressure Vs Crank
Pressure Vs Volume
Mean Temperature Vs Crank
Mass Vs Crank
Volume Vs Crank
OUTPUT
Screen shot of folder where I save my all plot using program