Challenge

Week 6 - Data analysis

Objective: To write a script that does the following.

  • Data visualizer
  • Compatability check 
  • Basic performance calculation 
  • To calculate the area under PV diagram
  • To calculate the fuel consumption.
  • To calculate the output of an engine ,given RPM=1500

Procedure:

1.Import the matplotlib.pyplot and the numpy libraries for plotting the PV diagram and for calculations.

2.Then we save the data and program in the same folder.

3.If and else loops are used to visualise the data whether is valid or not.

4.Then for loops are used for the compatibility check.

5. Finally the formulas are just used to find the output of engine , workdone , specific fuel consumption.

The given engine data.

Program code: 

import matplotlib.pyplot as plt
import numpy as np
from numpy import trapz
filename = input("Enter the filename:  ")
if filename == 'engine_data.out':
	print('file is valid')
else:
	print('file is invalid')
	exit()
def compat_check(a):
	if 'CONVERGE' not in a:
		print('please provide converge output file to process')
		exit()
	else:
		print('compatibility check successful')
		pass
FILE = []
for line in open(filename):
	if '#' in line:
		FILE.append(line.split())
compat_check(FILE[0])
noc = len(FILE[1])
head = len(FILE[2])
col_no = []
col_val = []
col_units = []
z = FILE[1].index('column')
for i in range(z,noc-1):
	col_no.append(i)
for j in FILE[2]:
	if j is not '#':
		col_val.append(j)
for k in FILE[3]:
	if k is not '#':
		col_units.append(k)
print('data available are:')
for a in range(0,len(col_no)):
	print(col_no[a],col_val[a],col_units[a])
xaxis = int(input('Enter xaxis column no:'))-1
yaxis = int(input('Enter yaxis column no:'))-1
x = []
y = []
for line in open(filename):
	if '#' not in line:
		x.append(float(line.split()[xaxis]))
		y.append(float(line.split()[yaxis]))
plt.plot(x,y,linewidth=1.5)
plt.xlabel(col_val[xaxis])
plt.ylabel(col_val[yaxis])
plt.show()
pressure = []
vol = []
for line in open(filename):
	if '#' not in line:
		pressure.append(float(line.split()[1]))
		vol.append(float(line.split()[7]))
Pressure = 1e6*np.array(pressure)
Volume = np.array(vol)
area = np.trapz(Pressure,Volume)
print('workdone =',area, 'joules')
cyclepersec = 750/60
power = area*(cyclepersec/1000)
print('power=',power,'kw')
mass_flow = 20e-6
sfc = mass_flow*3600/power
print('specific fuel consumption =',sfc,'g/kwh')

 Output:

                    

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.