Challenge

Week 6 - Data analysis

import matplotlib.pyplot as PLT
import math
import sys
from numpy import trapz
from scipy.integrate import simps
import numpy as NP

# TO IDENTIFY AND READ THE INPUT FILE
try:
    with open('engine_data.out') as file:
        read_data = file.read()
except:
    print('File not recognized. Please provide a valid CONVERGE output file')
    sys.exit()

# TO GET COLUMN NUMBERS AS INPUT
print('ENTER THE COLUMN NUMBERS(within 1 to 17) SEPERATED BY SPACE')
print('EXAMPLE: 10 11')
x, y = input("Enter column numbers of the properties you wish to plot(x y): ").split() 

# TO CONVERT STR INTO INT
xaxis = int(x) 
yaxis = int(y)

# TO CHECK THE INPUT COLUMN NUMBERS
if xaxis == 0 or xaxis < 0 or xaxis > 17 or yaxis == 0 or yaxis < 0 or yaxis > 17 or xaxis == yaxis:
	print('Check The X And Y Column Number')
	sys.exit()

# TO GET AND STORE THE COLUMN NAMES AND UNITS
count_num = 0

for line in open("engine_data.out"):
	if '#' in line:
		count_num = count_num+1
		if count_num == 3:
			column_names = (line.split())
		if count_num == 4:
			units = (line.split())


x_name = column_names[xaxis]
y_name = column_names[yaxis]
x_unit = units[xaxis]
y_unit = units[yaxis]
print("Entered x column Is: ",x_name)
print("Entered y column Is: ",y_name)

# TO EXTRACT DATA OF COLUMNS AND PLOT THE GRAPH

x_property = []
y_property = []

for data in open('engine_data.out'):
	if '#' not in data:
		x_property.append(float(data.split()[xaxis-1]))
		y_property.append(float(data.split()[yaxis-1]))

PLT.plot(x_property,y_property,color='red',linewidth='3')
PLT.xlabel(x_name+x_unit)
PLT.ylabel(y_name+y_unit)
PLT.title(y_name + ' Vs ' + x_name)
PLT.grid()
PLT.savefig(y_name+'_Vs_'+x_name)
PLT.show()	

# TO CALCULATE THE AREA UNDER PV GRAPH,POWER AND SPECIFIC FUEL CONSUMPTION

if x_name.casefold() == "volume".casefold() and y_name.casefold() == "pressure".casefold():

	# AREA
	area = simps(y_property, x_property)	
	print("area under pv diagram gives work =", area,"In Newton meter")	

	# POWER
	RPM = 1500								
	power = area*(RPM/60)*1000
	print('power =',power,"In Kilo Watts")

	# SPECIFIC FUEL CONSUMPTION
	cycle_sec = (RPM/60)/2		# Number of cycle = 0.5*Number of revolutions
	fuel_consumed = 20*pow(10,-9)*cycle_sec*3600
	sfc = fuel_consumed/power
	print('specific fuel consumption =',sfc,"In kg/KwHr")

else:
	print('power,sfc calculations are Not executed because selected columns are Not pressure And volume')

RESULTS :

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.