Week 6 - Data analysis
Data analysis is the process of collecting and organizing data in order to draw helpful conclusions from it. The process of data analysis uses analytical and logical reasoning to gain information from the data. The main purpose of data analysis is to find meaning in data so that the derived knowledge can be used to make informed decisions. It is defined as a process of cleaning, transforming, and modelling data to discover useful information. The purpose of Data Analysis is to extract useful information from data and taking the decision based upon the data analysis.
Data Analysis consists of Data Requirement Gathering, Data Collection, Data Cleaning, Data Analysis, Data Interpretation, and Data Visualization.
OBJECTIVE:
- To extract data of pressure, volume and 15 other parameters from an engine simulation text file.
- Visualization – Creating plots of each engine parameter to observe their nature, plotting P-V diagram of the engine.
- Performance calculation - Power and Specific fuel consumption of the engine.
GOVERNING EQUATION:
GIVEN: RPM = 1500 and engine consumes 20µ gm fuel per stroke cycle
PROGRAM:
import matplotlib.pyplot as plt
import numpy as np
import math
#initializing arrays and varaibles
column_no=[]
name=[]
unit=[]
results=[]
line_count=1
#reading data from txt file
try:
for line in open('engine_data.out'):
if line[0] == '#':
if line_count == 2:
line = line.split()[2::]
for value in line:
column_no.append(float(value))
if line_count == 3:
line=line.split()[1::]
for value in line:
name.append(value)
if line_count == 4:
line=line.split()[1::]
for value in line:
unit.append(value)
else:
line=line.split()
col=[]
for value in line:
col.append(float(value))
results.append(col)
line_count=line_count+1
#converting into useful form
data=[]
for i in range(0,len(column_no)):
col=[]
for j in range(0,len(results)):
col.append(results[j][i])
data.append(col)
#plotting all column_nos
for i in range(0,17):
plt.figure()
plt.plot(data[i],linewidth=4)
plt.ylabel(name[i] + ' ' + unit[i])
plt.savefig(name[i])
#plotting graphs between column_nos
a=8
b=2
plt.figure(18)
plt.plot(data[a-1],data[b-1],'*')
plt.xlabel(name[a-1] + ' ' + unit[a-1])
plt.ylabel(name[b-1] + ' ' + unit[b-1])
filename=name[b-1] + ' - ' + name[a-1]
plt.savefig(filename)
#area under curve
area = np.trapz(data[b-1],data[a-1])
print('Area under P-V: ',area)
#power calculation
rpm=1500/60
stroke_cycle=rpm/2
power = area*stroke_cycle*1000
print('power output of engine is :',str(power) + " KW")
#specific fuel consumption calculation
fuel=(20*pow(10,-6)*stroke_cycle*3600)/power
print('specific fuel consumption :',str(fuel) + ' kg/W.hr')
except:
print('File not recognized. Please provide a valid CONVERGE output file')
STEPS:
- first, we initialize empty arrays for column number, name of engine parameters, and unit.
- An empty called results was created to store all column data as 2D matrix.
- Next, we read the data from engine_data.out file inside try block and in except block we print 'File not recognized. Please provide a valid CONVERGE output file' if any no-compatible file is recognized.
- Inside try block, for loop was executed for every line in the engine text file in order to read it and store values.
- In for loop, a conditional statement was created in order to store column names, their units in empty arrays. This data is utilised to give labels to plots without explicitly giving names to them.
- The logic in the conditional statement is simply that if the line count is 2,3 or 4 then the column name array and unit array appends for every column.
- else, when line count becomes 5 i.e. we are reading data of each engine parameter and storing them into a 2D array results.
- This 3d array(results) contains each column of text line from line 5 as the column of results matrix.
- Therefore, transpose to results matrix was created in and stored in another matrix called data.
- Then, we create plots of each column, the labels of each plot are taken from the name data stored in name array.
- All the plots were saved using plt.savefig command.
- To Plot P-V curve, column no. of pressure and volume was given and for the label, the name was taken from name array.
- To calculate the area under the P-V curve, np.trap(y,x) function was used which gives the area of the curve y=f(x).
- By defining the formula for power and specific fuel consumption, engine performance was calculated.
OUTPUT:
1. Auto-saving all plots
2. Plot between the pressure and volume columns (P-V diagram)
Performance Check:
CONCLUSION:
Python is a very good tool for data analysis. A larger set of raw data can be visualized and processed for extracting useful information. The information extracted can be used for making crucial decisions by observing the behaviour of the data.