Challenge

Week 6 - Data analysis

Data visualizer

  • 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

  • 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

  • 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 1800
  • This engine consumed 20 micro grams of fuel (per 1 stroke cycle). Calculate its specific fuel consumption.

program:-

import matplotlib.pyplot as plt
import math
import numpy as np
from scipy.integrate import simps

line_count = 1

try:
	data = open('engine_data.out','r')
except FileNotFoundError:
#	print('"File not recognized. Please provide a valid output file"')



parameter = ['Crank Angle','Pressure','Maximum Pressure','Minimum Pressure','Mean Temperature','Maximum Temperature','Minimum Temperature','volume','Mass','Density','Heat Rejection Rate','C_p','C_v','gamma','Kinematic Viscosity','Dynamic Viscosity']
#print(parameter)
#print('Followings are the codes for corresponding parameters,Please follow the Instructions')
corresponding_num = ['crank_angle=0','pressure=1','max_pres=2','min_pres=3','mean_temp=4','max_temp=5','min_temp=6','volume=7','mass=8','density=9','Heat Rejection=10','Heat Rejection=11','C_p=12','C_v=13','gamma=14','Kinematic Viscosity=15','Dynamic Viscosity=16']
#print(corresponding_num)

first_column=input('Enter the first column:')
second_column=input('Enter the second column:')
#print('\n')


first_column=int(first_column)
second_column=int(second_column)

values_of_column_1=[]
values_of_column_2=[]

for line in open('engine_data.out'):
if line_count is 3:
	column_name_1=line.split()[first_column]
	column_name_2=line.split()[second_column]
	if'#' not in line:
	values_of_column_1.append(float(line.split()[first_column-1]))
	values_of_column_2.append(float(line.split()[second_column-1]))

		line_count+=1

area=float(simps(values_of_column_1, values_of_column_2))
#print('area:{}\n' .format(area))


rpm=1800
speed=rpm/60
power=area*speed
#print('power:{} \n' .format(power))

mass_of_fuel = 20*pow(9,-6)
specific_fuel_consumption=mass_of_fuel/power
#print('specific_fuel_consumption: {}\n'.format(specific_fuel_consumption))

plt.plot(values_of_column_2,values_of_column_1 ,linewidth=3,color='red')
plt.xlabel(column_name_1,color='green',fontsize=12)
plt.ylabel(column_name_2,color='green',fontsize=12)
plt.title(column_name_2+'  VS  '+column_name_1,color='b',fontsize=15)
plt.savefig(column_name_2+'VS'+column_name_1+'.png')
plt.show()
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.