Challenge

Week 6 - Data analysis

Aim : To write a python program which reads the engine output parameter data file and perform the required parameters.

Objective :

  • To read the data from a given 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 2 parameter given by user as an input.
  • To do basic performance calculation by calculating area under the P-V diagram, power output of this engine and specific fuelconsumption.

Problem statement :

Read the data from a given file named 'engine_data.out' using python program, plot a curve between 2 engine parameters (parameters to be given by user as an input) and perform basic performance calculation by calculating area under the P-V diagram, power output of this engine(Assume that RPM is 1500) and specific fuel consumption (engine consumed 20 micro grams of fuel (per 1 stroke cycle)).

Compatability check :

The code checks whether the input file name given exsists with extension '.out' or not, if a non-compatible file is provided as an input. It shows something like "File not recognized. Please provide a valid CONVERGE output file"

Data visualizer :

  • Script takes column numbers as the input and plot the respective columns as separate images
  • Each file is saved by the name of the column
  • The plot labels are extracted from the file.

Procedure :

  • Using a python program initally the name of the data file is taken as an input from user and checked whether the file is present or not, if the file is not pressent then the program is terminated.
  • Then the file is opened and data is read line by line and stored.
  • The name of parameters, their units and their coulmn number are stored as an array and dispalyed in form a table for the user to select the required columns.
  • Then the column no for independent parameter (x-axis) and dependent parameter (yaxis) is taken from user and the values of those clumn are extracted from data file and further plotted.
  • From the PV diagram Area under the P-V curve is calculated using the Trapezoidal Rule As we Know An area under the P-V diagram is equalto Work Done
  • In the next step Work was done that is calculated is used for calculating the power output
  • Power = Work *Speed
  • Specific Fuel Consumption = Mass of Fuel Consumption per hour/Power Developed in KW.

Python code :

# Python  code for data analysis

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

print('General instruction')
print('Please make sure that the converge data file is saved in the same directory where python folder is present')
# File_name = input('Enter the converge file having .out extension : ')
file_name = "engine_data.out"

# Compatability check
try :
    data = open(file_name,'r')
    print('\nData file is sucessfully opened.')

except FileNotFoundError :
    print('\nPlease enter a valid filename.\n')

line_count = 1
for line in data:

    if line_count==3:
        Parameter=line.split()
        Columns=len(Parameter)
        print('\nThis converge file contains following data which is derived from I.C. Engine Simulation :')
        print('It has total %d Data Columns' %(Columns-1))

        for line in data:
            if line_count==4:
                Unit=line.split()
            break

        for C_no in range(1,Columns):
            print(C_no,line.split()[C_no],line.split()[C_no])
        break
    line_count=line_count + 1

print('\nChoose any two parameter from above.')
print('Enter a number corresponding to parameter 1 to 17.\n')
x=int(input("Enter X-axis Parameter : "))
y=int(input("Enter Y-axis Parameter : "))

x_data=[]
y_data=[]

line_count = 1
for line in open(file_name,'r'):
    if line_count==3:
        X_label = line.split()[x]
        Y_label = line.split()[y]
        if line_count<=4:
            x_label=line.split()[x]
            y_label=line.split()[y]

    if '#' not in line:
        x_data.append(float(line.split()[x-1]))
        y_data.append(float(line.split()[y-1]))

    line_count=line_count + 1

filename=Y_label + 'vs' + X_label+'.png'

plt.figure()
plt.plot(x_data,y_data)
plt.xlabel(x_label)
plt.ylabel(y_label)
plt.title(Y_label  + ' vs ' +  X_label)
plt.savefig(filename)
plt.show()

if x==8 and y==2:
    RPM=1500
    Area=np.trapz(y_data,x_data)
    Workdone=Area*1000
    Power=2*math.pi*RPM*Workdone/60
    Fuel_per_Stroke=20*1e-6
    Fuel_per_Sec=Fuel_per_Stroke*RPM*(0.5/60)
    Fuel_per_Hour=Fuel_per_Sec*3600
    BSFC=Fuel_per_Hour/Power

    print('Area under the P-V diagram(Workdone) :',Workdone,'kJ')
    print('Power Output of this Engine :',Power,'kW')
    print('Specific Fuel Consumption :',BSFC,'g/kWh')
    

Explanation :

  • Initially, the required modules are imported.
  • File name is taken as an input from user and, to verify the user file with engine_data.out file, if command is used.
  • The Using a for loop every line of file is read line by line and the lines with '#'not include to read data and are appended to an array named 'column_1 & column_2’.
  • Using a for loop the extracted column no and names are displayed for user and asked to make a plot.
  • Then the values of the column selected by user are extracted and stored in an array and further plotted on a graph.
  • For basic performance calculation the values of pressure andvolume column are extracted and using the 'np.trapz(P,V)'.command, area under the PV diagram is calculated which also is the Workdone.
  • Converting the given speed of 1500rpm into rps the power output of the engine is calculated and further the specific fuel consumption of engine is calculated.
  • All the values calculated are displayed.

Results :

  1. Area under the P-V diagram (workdone) = 0.5005866274680075 kJ.
  2. Power output of this engine is = 78.63196356693975 kW.
  3. Specific fuel consumption = 0.011445727146745265 g/kWh.
  • When we give the parameters as 8 in x-axis and 2 in y-axis then we get Pressure vs Volume plot.

Plot :

  • When we give the parameters as 1 in x-axis and 2 in y-axis then we get Pressure va Crank plot.

Plot :

  • When we give the parameters as 1 in x-axis and 5 in y-axis then we get Mean_Temp vs Crank plot.

Plot :

  • When we give the parameters as 1 in x-axis and 8 in y-axis then we get Volume vs Crank plot.

Plot :

  • When we give the parameters as 1 in x-axis and 12 in y-axis then we get HR_Rate vs Crank plot.

Plot :

  • When we give the parameters as 2 in x-axis and 5 in y-axis then we get Mean_Temp vs Pressure plot.

Plot :

  • When we give the parameters as 1 in x-axis and 15 in y-axis then we get Gamma vs Crank plot.

Plot :

  • When we give the parameters as 1 in x-axis and 14 in y-axis then we get C_v vs Crank plot.

Plot :

  • When we give the parameters as 5 in x-axis and 15 in y-axis then we get Gamma vs Mean_Temp plot.

Plot :

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.

  • Area under the P-V diagram (workdone) = 0.5005866274680075 kJ.
  • Power output of this engine is = 78.63196356693975 kW.
  • Specific fuel consumption = 0.011445727146745265 g/kWh.
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.