Challenge

Week 6 - Data analysis

AIM: To write a python program which reads the engine output parameter data file and perform the required objectives

Objective: The objective of this project is to write a python program which reads the engine data file and perform the required objective.

  • To read the data file from a given engine data file.
  • To take the file name as an input from user and check whether the file is present or not.
  • To plot a graph between any two parameter given by user as an input.
  • To do basic performance calculation by calculating area under the P-V diagram, power output of the engine (1500 rpm) and specific fuel consumption where engine consumed 20 micro grams of fuel (per 1 stroke cycle).

Introduction:

Data analysis is a process of inspecting, cleansing, transforming, and modeling data with goal of discovering useful information, informing conclusion, and supporting decision-making. Data analysis has multiple facets and approaches, encompassing diverse techniques under a variety of names, and is used in different business, science and social science domains. In today's business world, data analysis plays a role in making decisions more scientific and helping business operates more effectively.

  • Descriptive Analysis: Descriptive data analysis looks at past data and tells what happened. This is often used when tracking Key Performance Indicators (KPIs), revenue, sales leads, and more.
  • Diagnostic Analysis: Diagnostic data analysis aims to determine why something happened. Once your descriptive analysis shows that something negative or positive happened, diagnostic analysis can be done to figure out the reason. A business may see that leads increased in the month of October and use diagnostic analysis to determine which marketing efforts contributed the most.
  • Predictive Analysis: Predictive data analysis predicts what is likely to happen in the future. In this type of research, trends are derived from past data which are then used to form predictions about the future. For example, to predict next year’s revenue, data from previous years will be analyzed. If revenue has gone up 20% every year for many years, we would predict that revenue next year will be 20% higher than this year. This is a simple example, but predictive analytics can be applied to much more complicated issues such as risk assessment, sales forecasting, or qualifying leads.
  • Prescriptive Analysis: Prescriptive data analysis combines the information found from the previous 3 types of data analysis and forms a plan of action for the organization to face the issue or decision. This is where data-driven choices are made.

These 4 types of data analysis can be applied to any issue with data related to it. And with the internet, data can be found about pretty much everything.

Data analysis has been used here to open and read the contents of the data and perform some basic calculations using certain formulas.

Governing Equations used:

Since the data file consists of various parameters for an engine, the file contents can be used to perform certain basic engine calculations.
The quantities calculated here are:

  • Work done by the engine (Area under the curve).
  • The power output of the engine. This is generally called engine brake power.

Using the 'trapezoidal' rule and 'Simpsons' rule, the area under the curve can be computed. For calculating the power and the specific fuel consumption, the following equations are used:

`power = (Wout * r* n)/(60*1000*2)` in `kW`

Where, `n =`No. of cylinders of the engine.

`r =` rpm is converted to rps (revolution per second)

`Wout =` workdone by the engine (4-stroke so it means devided by 2)

`SFC = (Fuel Cons) / (power)` in `(kg)/(hrs)`

Where, `SFC =` Specific fuel consumption

`Fuel Cons =`Amount of fuel consumption

`power =` power

Engine consumed 20 micro grams of fuel (per 1 stroke cycle) nad RPM = 1500.

Procedure and Explaination:

Step-1: Before writing the program first we have to import command to import libraries which will be used in mathematical operation and plotting.

Function of the libraries is:

  • matplotlib library for plotting graphs
  • numpy library to use np as command which returns evenly spaced samples

Step-2: Compatibility check of the file.

Here we create myfile function where we give input file name and using if else we check given file is present or not in given directory. f(t)=y=at+b">

Step-3: Data availability

Now the next part of the program is to asks the user which file we would like to open. It opens the file and prints out the data available to us.

Use return to read all the line step by step and store values in empty array accordingly.

Step-4: Asking column number and plotitng graph accordingly

From this point on, the user is asked to input the column numbers for which we would like to display the data. After that, the selected columns are separated into lists and the graph is plotted.

Step-5: Basic performance calculation

The final part of this assignment will be to calculate area under P-V diagram, Power and specific fuel consumption.

After defining all the terms we need the output so to do that we are using the plot command and plot the graph. Plotting pressure vs volume graph

After properly arranging the program we get out the desired program.

Python Program for Engine data analysis

CODE:

"""
Engine Data Analysis
"""
#Importing required modules
import matplotlib.pyplot as plt
import numpy asnp

#Taking inputs from user
myfile = input("Enter file name :")

#checking for valid file
if myfile == 'engine_data.out':
print('File found succesfully, you may continue...\n')
else:
print('File not recognized. Please provide a valid CONVERGE output file')
exit()

data = []

# reading the file for compatibility check and acquiring the column heading
for line in open(myfile):
if '#' in line:
data.append(line.split())

#no of columns
nc = len(data[1])

#column numbers
cn = []
#column name
cv = []
#column units
cu = []

a = data[1].index('column')

for i in range(a,nc-1):
cn.append(i)

for i in data[2]:
if i is not '#':
cv.append(i)

for i in data[3]:
if i is not '#':
cu.append(i)

#showing available data
print('\nShowing data present in file...\n')
print('COLUMN NO',' ','PARAMETER')

for i in range(0,len(cn)):
print(' ',cn[i],' - ',cv[i],cu[i])


#taking user input for plot
xaxis = int(input('\nEnter independent parameter (x-axis) column no:'))
yaxis = int(input('Enter dependent parameter (yaxis) column no:'))

#reducing value by 1 for program to pick correct value
xaxis = xaxis-1
yaxis = yaxis-1

x = []
y = []

# file parsing
for line in open(myfile):
if '#' not in line:
x.append(float(line.split()[xaxis]))
y.append(float(line.split()[yaxis]))


#Plotting
plt.figure(1)
plt.plot(x,y,linewidth=3)
plt.xlabel(cv[xaxis]+cu[xaxis])
plt.ylabel(cv[yaxis]+cu[yaxis])
plt.title(cv[yaxis]+'-'+cv[xaxis]+' diagram')
plt.show()

#Basic performance calculation
pressure = []
volume = []

# file parsing
for line in open(myfile):
if '#' not in line:
pressure.append(float(line.split()[1]))
volume.append(float(line.split()[7]))

# converting pressure into pascal
P = 1000000*np.array(pressure)
V = np.array(volume)

#calculating area under PV diagram usin trapozoidal rule
area = np.trapz(P,V)

print('\nWorkdone (area under P-V diagram) = ',area,'joules')

#calculating power
power = (area*(1500/60))/1000
print('\nPower output of the engine =',power,'KW')

#calculating specific fuel consumptiion (g/kW.h)
sfc = 20*pow(10,-6)*3600/power

print('\nSpecific fuel consumption =',sfc,'g/kw.h')


#plotting P-V Diagram
plt.figure(2)
plt.plot(volume, pressure, linewidth = 3)
plt.title('P-V diagram',fontsize=12,color='green')
plt.xlabel('Volume',fontsize=12)
plt.ylabel('Pressure',fontsize=12)
plt.show()

print('Program End')
OUTPUT RESULTS:

CONCLUSION:

  • The data from the output file was read successfully and the plot required as per the user need was made.
  • The performance calculations were done and displayed successfully.

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.