Week 6 - Data analysis
Data analysis
Aim: To read the file 'engine_data.out' and perform the following operations on the data.
Objective:
1.) Data Visualizer
2.) Compatibility Check
3.) Basic Performance Calculation
Concept:
The basic concept is to read the file 'engine_data.out' perform several functions on it. As Sublime doesn't allow you to input the data, It is better to define a function Input(), to input the column numbers. I have taken the example of Column nos. 1 & 5. To perform compatibility check, the try and except block: is to be used, as it used for python exceptions i.e. it will display the command 'File not recognized. Please provide a valid CONVERGE output file', if it fails to open. The next task will be to calculate the engine's basic performance calculations i.e.
a) The area under a P-V diagram
used trapz() function from numpy library
area = np.trapz(Pressure,Volume)
b) The power output of the engine
Power output for the 4-stroke engine is given as,
Power = Work done * RPM/2 (Joules)
c) Specific Fuel Consumption
SFC = Area/ Work Done
d) Compatibility Check
use of try() and except() method
Methodology:
Let us go task by the task in solving this assignment:
1. The first task is to enter column numbers as input. As sublime doesn't offer input to the user, therefore, instead of using sublimeREPL as it may result in the slowing of program building, a separate function is to be used, namely Input().
2. Now coming to the main part, the first operation a program should perform is a Compatability check, i.e. the program should check whether the file is compatible or not. This is done by using the try and except block: as explained above.
3. Now the next part will be to define a string that contains all the names of each of the headings in the data so that the names can be automatically retrieved, and then the input function is called for values of columns.
Python Code:
# Importing libraries
import matplotlib.pyplot as plt
import math
import numpy as np
try:
title=[]
for li in open('engine_data.out'):
if 'Crank' in li:
title=li.split()
title.remove('#')
print('Column Number Vs Column Name:')
n=0
for a in title:
print(str(n)+' : '+a)
n=n+1
clmi=[]
clmj=[]
i=int(input("input Column Number 1:"))
j=int(input("input Column Number 2:"))
for line in open('engine_data.out'):
if '#' not in line:
clmi.append(float(line.split()[i]))
clmj.append(float(line.split()[j]))
plt.figure()
plt.plot(clmi,clmj)
plt.xlabel(title[i])
plt.ylabel(title[j])
filename=title[i]+' VS '+title[j]
plt.title(filename)
plt.show()
plt.savefig(filename)
Pressure=[]
Volume=[]
for line in open('engine_data.out'):
if '#' not in line:
Volume.append(float(line.split()[7]))
Pressure.append(float(line.split()[1]))
area = np.trapz(Pressure,Volume)
print('Area under PV diagram', area)
rpm = 1500
rps = rpm/60
power_watt = area*rps*1000
print('power of the engine is', power_watt)
sfc = (20*pow(10,-6)*3600)/(0.08*power_watt)
print('Specific fuel consumption is',sfc)
except:
print('File not recognized. Please provide a valid CONVERGE output file')
Results:
Plots:
Output Screen: