Week 6 - Data analysis
AIM:
To develop a Data Visualizer Tool that would perform the following things.
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.
Compatability Check
- Your 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.
2. METHODOLOGY:
2.1 PYTHON CODE:
#Data Analysis
import math
import matplotlib.pyplot as plt
import numpy as np
import sys
# Compatability Check
try :
open('engine_data.out','r')
except:
print('File not recognized. Please provide a valid CONVERGE output file')
sys.exit()
# DATA VISUALIZER
#File parsing
file = 'engine_data.out'
count_rows = 0
count_columns = 0
count_header=0
column_title = []
column_units = []
for line in open(file,'r'):
if '#' not in line:
count_rows = count_rows + 1
count_columns = len(str.split(line))
else:
count_header = count_header +1
if count_header == 3:
for i in range(0,len(str.split(line))):
column_title.append(str.split(line)[i])
elif count_header == 4:
line_content = str.split(line)
for i in range(0,len(str.split(line))):
column_units.append(str.split(line)[i])
print(column_title)
if (count_header < 4 or count_rows < 1 or count_columns < 8):
print('File not recognized. Please provide a valid CONVERGE output file')
else:
#Plotting of given data columns - Change the column numbers to get the desired plot
x = 8
y = 2
x_array=[]
y_array=[]
for k in open(file,'r'):
if '#' not in k:
y_array.append(float(k.split()[y-1]))
x_array.append(float(k.split()[x-1]))
plt.plot(x_array,y_array)
plt.xlabel(column_title[x]+column_units[x])
plt.ylabel(column_title[y]+column_units[y])
plt.savefig(column_title[x] +' VS '+ column_title[y]+'.png')
plt.show()
#Calcualtion for Area under the PV Diagram using trapz command
x = 8
y = 2
pressure=[]
volume=[]
N=1500 #rpm
for k in open(file,'r'):
if '#' not in k:
pressure.append(float(k.split()[y-1]))
volume.append(float(k.split()[x-1]))
area=np.trapz(pressure,volume)
print('Area under PV diagram is',area,'MJ') # Area in MJ
workdone=area*pow(10,6) # Work Done in Nm or Joule
power=2*math.pi*workdone*N/(60*1000) # Power in KWatt
print('Power Output of engine = ',power,'kw')
fuel=20*1e-6 # Fuel in gram - given 20 micro grams fuel/ stroke
sfc=(3600*fuel*N)/(60*power) # Specific Fuel consumption in g/kw.hr
print('SFC=',sfc,'g/kw.hr')
Explanation: First two empty arrays were created for the X axis parameter and Y axis parameter and then by using append command the values were stored in the respective arrays. From the identified column titles and units, x and y data were plotted with suitabe label. Further trapz command from numpy module was used to calcualte the area under PV diagram and the same is printed. In addition Power output of the engine and Specific fuel consumption was calculated from their respective empirical relation and printed.
Plot
PRESSURE AND THE VOLUME

CRANK AND MIN TEMPERATURE

COMPATIBILITY CHECK

Inference: When the program is executed with wrong file name unavailable in that directory the program displays the comment "File not Recognized. Please provide a valid CONVERGE output file".
OUTPUT

3. CONCLUSION: The program to read the given data and calcualte desired parameter values was developed and executed successfully.