Project

Engine Data Analysis using Python

AIM

Write a code of file parsing for a file “engine_data” and plot the curve for the following respective column present in the file.

To find the area of the plot and to calculate the specific fuel consumption.

GIVEN

Engine parameter file named as engine_data.out

FORMULA USED

BODY OF CONTENT

PARSING

Parsing, syntax analysis, or syntactic analysis is the process of analyzing a string of symbols, either in natural language, computer languages or data structures, conforming to the rules of a formal grammar. The term parsing comes from Latin pars (orationis), meaning part (of speech).

STEPS OF PYTHON PROGRAM

Before start of coding we have to confirm that the data files are in same directory where you are going to save the PYTHON program.

  1. Provide topic of the code which is under comment
  1. Calling of library which will used for plotting and calculating i.e. math, numpy, scipy and matplotlib.pyplot library.
  1. From line 11 to 16 program is written to take input of the file name from user.

In line 14, print command is used to show the comment for the input of file name.

In line 16, input command is used to take the name of the file from user.

  1. From line 19 to 27 code is written to check the compatibility of the program.

Here try and except command is used to check the name of the file otherwise give error of file not found.

In line 23, file is open in read mode and store it in the file name.

In line 27, print command is used to display the error when the file name do not match.

  1. From line 30 to 43, code is written to extract the comment and the data from the file and store in an array.

In line 33 and 34, empty array of the comment and data are defined.

In line 38, for loop is used to separate the comment and values from the given file and store it in the empty array of the particular type. Comment array store the comments and data array stores the data from the given file.

  1. From line 45 to 49, code is written to define the column of different parameter.

In line 48, print command is use to display the parameter and their corresponding column.

  1. From line 51 to 62, code is written to calculate and store the values of data for the particular parameter.

In line 54 and 55, code is written to define the empty array for X and Y variables.

In line 58 and 59, code is written to take the input from the user for the column of x and Y axis.

In line 60 and 61, code is written to convert the value which is input from the user into integer.

In line 62, count variable is used for defining the starting point of count variable.

  1. From line 79 to 87, code is written to plot and save the image.

In line 80, plot command is used to plot the curve of the data which is present in the given file.

In line 81 and 82, label command is used to provide the label of the X and Y axis of the plot.

In line 86, savefig command is used to save the figure into .png format.

In line 87, show command is used to display the plot.

  1. From line 90 to 94 code is written for calculating the area of the plot.

In line 93, float is used to take the decimal values and simps is used to integrate the values of X and Y axis variable to calculate the area.

  1. From 97 to 111, code is written to calculate the basic performance of the engine which works only for Pressure and Volume diagram.

In line 101 “ if ” command is used to limit the functioning of the program for only Pressure and volume calculation.

In line 102 Rpm is written for giving the rotation speed of the engine in RPM.

In line 103, program is written to calculate the speed in RPS.

Area under the PV diagram is considered as a work done which is written in line 104 and in line 105 print command is used to print the value of work done.

In line 106, code is written to calculate the power by multiplying the area and speed.

In line 107, code is written to print the value of the power which is calculated above.

In line 109, Program is written to calculate the mass of the fuel.

In line 110, specific fuel consumption is calculated by dividing the mass of fuel with power.

In line 111, print command is used to print the value of specific fuel consumption.

PYTHON PROGRAM

"""
Program for parsing data
"""

#importing of library to be used
import matplotlib.pyplot as plt
import math
import numpy as np
from scipy.integrate import simps

#=================================== TAKING INPUT OF FILE FROM USER ===========================================================#

#giving instruction for input of file
print ("Input the name of the file")
#taking file input from user 
file = input("FILE NAME (Ex- xyz.out) :")


#======================================= COMPATIBILITY CHECK ===================================================================#

#Try and except command for checking the file
try:
	filename =open(file,'r')            #open the file in read mode
        
except FileNotFoundError:
        #defining the errror to be print when file is wrong
	print("File not recognized. Please provide a valid CONVERGE output file")


#=================================== SEPARATING OF THE DATA FROM FILE ==========================================================#
	
#Defining of empty array for storing values
comment=[]                                      #empty array for storing comment
data = []                                       #empty array for storing data


#for loop for separating and storing the comment and data from file
for i in filename:
	if '#' in i:                            #if loop for reading # sign in the file
		
		comment.append(i.split())       #storing the commnent in the empty array
	else:                                   #defining else condition                            
		data.append(i.split())          #storing the data in the empty array

#===================================== DEFING THE COLUMN WITH NO. =============================================================#

#printing the column no. of parameter 
print( "1-Crank   2-Pressure   3-Max_Pres   4-Min_Pres   5-Mean_Temp   6-Max_Temp   7-Min_Temp   8-Volume   9-Mass   10-Density   11-Integrated_HR   12-HR_Rate   13-C_p   14-C_v   15-Gamma   16-Kin_Visc   17-Dyn_Visc")


#================================== STORING AND CALCULATING THE DATA FOR PLOT ==================================================#

#defining the empty array for storing the x and y variable
x_variable = []                                 #empty array for storing x coordinates              
y_variable = []                                 #empty array for storing y coordinates

#getting input for two coulmn from user
x_parameter= input("Input column no. for X axis : ")
y_parameter= input("Input column no. for Y axis : ")
x = int(x_parameter)                            #converting the x input into integer
y = int(y_parameter)                            #converting the y input into integer
count = 1                                       #starting of variable count from 1

#for loop for storing the values of x and y axis
#for loop for taking the name of the column
for i in range(len(data)):

        column_name_x = comment[2][x]           #Selecting the x axis column name
        column_name_y = comment[2][y]           #Selecting the y axis column name

        x_cor = data[i][x-1]                    #calculating the x axis coordinates	
        y_cor = data[i][y-1]                    #calculating the x axis coordinates

        x_variable.append(float(x_cor))         #storing the x axis coordinates
        y_variable.append(float(y_cor))         #storing the y axis coordinates
        count = count + 1                       #increament of count by 1


#plotting of figure
plt.plot(x_variable,y_variable)                 #Plot of X and Y axis for the selected column
plt.xlabel(column_name_x)                       #proving the name of X axis
plt.ylabel(column_name_y)                       #proving the name of Y axis


#Command to save the figure
plt.savefig(column_name_x +'Vs' + column_name_y + '.png')
plt.show()                                      #Command to show the plot


#============================================ CALCULATING THE AREA OF THE PLOT ==========================================================#

#command to calculate the area of the plot
Area = float(simps(y_variable,x_variable,even='first')*pow(10,6))
print('\n AREA: {}\n' .format(Area))            #printing the area of the plot


#============================================== BASIC PERFORMANCE CALCULATION ===========================================================#
#=================================================== ONLY FOR PV DIAGRAM ================================================================# 

#Basic performance calculation
if x==8 and y==2:
        rpm = 1500                                              #Defining the RPM of the engine
        speed= rpm/60                                           #Converting the RPM in RPS
        workdone = Area
        print('\n WORKDONE (Joule): {} \n' .format(workdone))   #printing of the power
        power = Area*speed                                      #Calculating of the power
        print('\n POWER (Watt): {} \n' .format(power))          #printing of the power

        mass_of_fuel=20*pow(10,-6)                              #Caculating the mass fuel consumption 
        specific_fuel_consumption = mass_of_fuel*3600/power     #calculating specific fuel consumption
        print('\n SPECIFIC FUEL CONSUMPTION (gm/KWhr): {}\n' .format(specific_fuel_consumption))     #printing the value of specific fuel consumption

ERROR OBTAIN WHILE PROGRAMMMING

  1. The input value entered from the user is array we need to convert it into integer otherwise program will not run and give an error as shown in the figure.

RESULTS

Various plot obtains after running the code.

  1. Plot of Crank Vs Mean Temp

  1. Plot of Crank Vs Pressure

  1. Plot of Crank Vs Mass

  1. Plot of Volume Vs Pressure

Result in the Command Window

Result of save figure with their name

CONCLUSION

  1. By the help of this program we can plot the curve easily between two parameters.
  2. This program calculate the values of specific fuel consumption in case of PV diagram only. Because area under the PV curve gives the work done which is used in calculating the specific fuel consumption.

REFERENCES

  1. skill lync video lecture

Note:- May be the input command will not work in sublime text application. Try using IDLE for better functioning of the program.

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.