Challenge

Week 6 - Data analysis

Objective:- In this project, we will write a python program to analyse the data and calculate the required data.

Code for Data analysis:-

#Python program for data analysis

import matplotlib.pyplot as plt
import math
import numpy as np


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





value=[]
for line in data:
	if '#' not in line:
		value.append(line.split())
		
column=np.transpose(value)
column=column.astype(float)


parameter=['Crank Angle','Pressure','Maximum Pressure','Minimum Pressure','Mean Temperature','Maximum Temperature','Minimum Temperature','Volume','Mass','Density','Heat Rejection','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 Rate=11','C_p=12','C_v=13','gamma=14','Kin Vis=15','Dyn Vis=16']

print(corresponding_num)
print("please enter the code for independent variable then press enter: \n")
x=int(input())
print("please enter the code for dependent variable then press enter: \n")
y=int(input())
plt.plot(column[x,:],column[y,:],linewidth=2,color='blue')
plt.xlabel(parameter[x],color='red',fontsize=12)
plt.ylabel(parameter[y],color='red',fontsize=12)
plt.title(parameter[y]+'    VS    '+parameter[x],color='b',fontsize=15)
plt.savefig(parameter[y]+'VS'+parameter[x]+'.png')
plt.show()

vol=column[7,:]
press=column[1,:]*pow(10,6)  #converting the pressure into Pascal


#area under curve

work=[]
for i in range(0,8664):
	work.append((vol[i+1]-vol[i])*(press[i+1]+press[i])*0.5)

work_done=0
for j in range(0,len(work)):
	work_done=work_done+work[j]

print('Work Done :',work_done,'J')

#power calculations
speed=1500/60 #in rev per sec
power=work_done*speed
print('Power:',power/1000,'KW')

#bsfc
m_f=20*pow(10,-6)   #since mass of fuel consumed is 20 micrograms
bsfc=(m_f*3600)/power
print('Specific Fuel Consumption:',bsfc,'gm/KWhr')

Understanding the Code:-

  1. For opening and reading the file "open" command is used.
  2. Exception handling is used to display the error handelling prompt if suitable file format is not provided.
  3. The transpose method returns a transposed view of the passed multi-dimensional matrix.
  4. astype-Copy of the array, cast to a specified type,here we have used astype to cast into float.
  5. Then corresponding codes for the parameters as well as parameters is printed on the screen and program asks for user input as independent and dependent variable and gives the plot between the dependent vs independent variables and also save the plot as in name"dependent vs independent"
  6. After calculating the area under curve (work),Power and specific fuel consumption is calculated as per the given data.

Output

Pressure Vs Volume diagram:-

Pressure Vs Crank Angle diagram:-

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.