Project

Python Project 7 : 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.

PYTHON Program :

''' Engine Data Analysis '''

import matplotlib.pyplot as plt
import numpy as np
from numpy import trapz

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

test = []

#Reading the file for compatibility check and acquiring the column heading values
for line in open(fname):
  if '#' in line:
    test.append(line.split())
#calling the compatibility function to check for valid converge input file
CompCheck(test[0])
colnum=len(test[1])
colhead = len(test[2])

col_num = []
col_val = []
col_unit = []

a=test[1].index("column")
for x in range(a, colnum-1):
  col_num.append(x)

for i in test[2]:
  if i is not '#':
    col_val.append(i)

for j in test[3]:
  if j is not '#':
    col_unit.append(j)

print('Available Data')
for i in range(0,len(col_num)):
  print(col_num[i], col_val[i], col_unit[i])

#Section for user choice for the plots required
x = int(input('Enter X Column No.: '))-1
y = int(input('Enter Y Column No.: '))-1

x_label = col_val[x]
y_label = col_val[y]

X = []
Y = []

#Reading the required column data from the file
for line in open(fname):
  if '#' not in line:
    X.append(float(line.split()[x]))
    Y.append(float(line.split()[y]))

#plotting the column values as required by the user
plt.plot(X, Y, linewidth=2)
plt.xlabel(x_label+col_unit[x])
plt.ylabel(y_label+col_unit[y])
plt.show()

#Engine Performance Calculations
P = [] #creating a pressure array to store the pressure values
V = [] #creating a volume array to store the volume values

for line in open(fname):
  if '#' not in line:
    P.append(float(line.split()[1]))
    V.append(float(line.split()[7]))

Pressure = 1e6* np.array(P) #converting the pressure unit from MPa to Pa
Volume = np.array(V)
AUC = np.trapz(Pressure, Volume) #Calculating the area under the P-V curve
print('Engine Performance Calculations')
print('Work Done', AUC, 'Joules') # work done per cycle
cyclepersec = 750/60 #Assuming engine speed = 1500 rpm, for a 4 stroke engine for every 2 crank rotation 1 cycle is complete, so for 1500 crank rotations 750 cycles are complete
power = AUC*(cyclepersec/1000)
print('Power Output of the engine @ 1500RPM', power, 'kW')
mf= 20e-6 #rate of fuel consumption per cycle= 20 micro grams/cycle
SFC= mf*3600/power
print('Specific Fuel Consumption', SFC, 'g/KW.h')

RESULT :

When provide X column as 1 and Y column as 2 it give Pressure-Crank diagram.

For Pressure vs Volume plot, Provided the respective column input (8: volume and 2:Pressure)

For checking the compatibility wrong file name was provided respectively as input and the following results were displayed
Input: engine_data

THIS PROGRAM IS CREATED IN GOOGLE COLAB

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.