Challenge

Week 6 - Data analysis

TITLE: DATA ANLYSIS USING PYTHON

OBJECTIVE: To analyse the data of an engine file.

PROCEDURE:

  • At first imported the matplotlib and numpy module.
  • For compactibility check used try and except loop.
  • Now writing the code to plot the curve between two parametres.
  • Now I write code to take inputs of colums between 1(included) and 17(included)
  • Now used for and if loop,to calculate the number of columns,line count,column name and column number.
  • Now to append the values of first and 2nd column I use empty array.
  • Now I move to write the code to calculate area under,P_V curve,Power genearted by the engine and specific fuel consumption of the engine.
  • The following formuale used are given below.

Given data,

rpm = 1500

speed = rpm/60

power = area * speed

mass of specif fuel = `20xx 10^6`

specific fuel consumption = mass of fuel / power

  • Now I use print command to print the above values.
  • Now I use plt. command to plot the curves and label according to the column names.
  • I use plt.savefig command to save the figure according to their column names.

CODE:

import matplotlib.pyplot as plt
import numpy as np

line_count = 1
#compactability test
try:
	file = open('engine_data.out')
	print('file opened successfully')

except:
	print('File not recognized.Please provide a valid CONVERGE output file')


#To take the inputs for the curve
print('The plot parameters are given in the series below')
print('1-cranck,  2-pressur,  3-Max_preesure,  4-Min_pressure,  5-Mean_temp,  6-Max_temp,  7-Min_temp,  8-Volume,  9-Mass'
	+'10-density,  11-intergrated_HR,  12-HR_Rate,  13-C_p,  14-C_v,  15-Gamma,  16-Kin_Visc,  17-Dyn_visc')

first_column = int(input('Enter the column number 1 for which you want to plot(choose a number between 1(included) and 17(included):'))

second_column = int(input('Enter the column number 2 for the plot(choose other number then column number 1):'))

print('\n')

first_column = (int(first_column)-1)
second_column = (int(second_column)-1)


#To append the vales of the 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+1]
		column_name_2=line.split()[second_column+1]
	line_count+=1 

	if '#' not in line:
		values_of_column_1.append(float(line.split()[first_column]))
for line in open('engine_data.out'):
	if '#' not in line:
		values_of_column_2.append(float(line.split()[second_column]))

#Area under pv diagram

volume =[]
pressure = []

for line in open('engine_data.out'):
	if '#' not in line:
		volume.append(float(line.split()[8]))
		pressure.append(float(line.split()[2]))

area = np.trapz(pressure,volume)
print('total area under p_v curve =',area)

rpm = 1500
speed = rpm/60
power = area * speed #power
print('power output of engine =', power)

mass_of_fuel =20*pow(10,-6)
sfc = mass_of_fuel/power
print('specific_fuel_consumption =',sfc,)		

#To print the plots and save figure

plt.plot(values_of_column_1,values_of_column_2)
plt.xlabel(column_name_1)	
plt.ylabel(column_name_2)
plt.title(column_name_2+'    vs    ' +column_name_1)
plt.savefig(column_name_2 + "   vs   " + column_name_1+'.png')
plt.show()

RESULTS:

  1. Pressure vs Volume curve

2. crank vs volume curve

3. C_P vs C_V curve

  • Now the results for the following data.

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.