Week 6 - Data analysis
Project title: Data analysis
Objective:
1. Study data file
2. Write a script to extract useful data.
3. Plot the graph from this data
Problem statement:
Data visualizer (100 points)
- 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 (30 points)
- 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 (50 points)
- 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 micrograms of fuel (per 1 stroke cycle). Calculate its specific fuel consumption.
Code
from math import *
from numpy import *
from matplotlib.pyplot import *
# input the data file
fname=input('Enter File name for performing data analysis: ')
if fname == 'engine.out':
print('File name is Ok.')
else:
print('File name is invalid, please enter a valid file name')
exit()
#file parsing
row_count = 0
column_count = 0
header_count = 0
column_title = []
for line in open('engine.out'):
if '#' not in line:
row_count = row_count + 1
column_count = len(str.split(line))
else:
header_count = header_count+1
if header_count == 3:
for i in range(0,len(str.split(line))):
column_title.append(str.split(line)[i])
#plotting columns
for i in range(0,column_count):
data=[]
for j in open('engine.out','r'):
if '#'not in j:
data.append(float(j.split()[i]))
plot(data)
savefig(column_title[i+1] + '.png')
figure()
del data
# plotting pressure vs volume
pressure =[]
volume = []
#plotting data in each columns
for line1 in open('engine.out'):
if '#' not in line1:
pressure.append(float(line1.split()[1]))
volume.append(float(line1.split()[7]))
plot(volume,pressure)
show()
# Calculation of Area under PV Diagram
area = trapz(pressure, volume)
print('Area under PV Diagram (m^2)', area)
# Calculating Power Output
rpm = 1500
rps = rpm/60
Power_Watt = area*rps*1000
print('Power of the engine (Watt) is', Power_Watt)
# Calculating specific fuel consumption
sfc = (20*pow(10,-6)*3600)/(0.08*Power_Watt)
print('Specific fuel consumption (g/kwh) is', sfc)
Code logic
1. first input function is used to check the input file is correct or not
2. second file parsing programme generated where each colour data is separately plotted in a different figure
3. third area under the curve power of the engine and specific fuel consumption is calculated
Output
The area under PV Diagram is 0.00050 m^2
Power of the engine is 12.5146 Watt
Specific fuel consumption is 0.07191 g/kWh
P-V Plot
Cp plot
Cv plot
Crank plot
Density plot
Dyn_Visc plot
Gamma plot
HR_Rate plot
Integrated_HR plot
Kin_Visc plot
Mass plot
Max_Press plot
Max_Temp plot
Mean_Temp plot
Min_Press plot
Min_Temp plot
Pressure plot
Volume plot