Data analysis
Objective: The objective of this project is to write a code for data analysis from an input file and perform the following operations
1. Compatibility Check: The program will ask for the file name with valid extension which if provided incorrect will terminate the program. In case the file name is correct it will further check whether it is a valid Converge output file. If the file is authentic then will proceed to data analysis else it would terminate
2. Data Visualization: The program shall display the contents of data available in the file and ask the user for inputs to plot the results will corresponding units
3. Performance Calculations: the program shall also perform basic performance calculations including area under the P-V curve, power output of the engine (@1500RPM) and specific fuel consumption)
code:
import math
import matplotlib.pyplot as plt
import numpy as np
# input the data file
fname=input('Enter File name for performing data analysis along with file extension: ')
if fname == 'engine_data.out':
print('File name is Ok proceeding to compatibility check')
else:
print('File name is invalid, please enter a valid file name')
exit()
#Fuction to check the compatibility of the input file
def CompCheck(a):
if "CONVERGE" not in a:
print('Incompatible File: Please provide a valid CONVERGE output file, program will exit now')
exit()
else:
print('Compatibility Check Successfull proceeding to data analysis')
pass
#file parsing
row_count = 0
column_count = 0
header_count = 0
column_title = []
for line in open('engine_data.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_data.out','r'):
if '#'not in j:
data.append(float(j.split()[i]))
plt.plot(data)
plt.savefig(column_title[i+1] + '.png')
plt.figure()
del data
# plotting pressure vs volume
pressure =[]
volume = []
#plotting data in each columns
for line1 in open('engine_data.out'):
if '#' not in line1:
pressure.append(float(line1.split()[1]))
volume.append(float(line1.split()[7]))
plt.plot(pressure,volume)
plt.show()
#work done calculation
work=[]
for i in range(0,row_count-1):
work.append((volume[i+1] - volume[i])* (pressure[i+1]+ pressure[i])*0.5)
work_done = 0
for j in range(0,len(work)):
work_done = work_done + work[j]
print('work done is: ', work_done)
#power calculation
speed = 1500/60
power = work_done*speed
print('power is:',power)
#specific fuel consumption
mass_fuel = 20*pow(10,-6)
specific_fuel_consumption = (mass_fuel*3600)/power
print('specific fuel consumption is :',specific_fuel_consumption)
Figures saved with column names
Pressure vs Volume plot
compatibility check and results screenshort