Data Analysis
Problem Statement:
Write the python coding for data visalisation.
Objectives:
- Data Visualisation
- Compatibility Check
- Basic Perfromance check
Python Coding:
\'\'\'
In order to run program - please follow below procedure
Tools » SublimeREPL » Python » Python-Run Current file
\'\'\'
import math
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
#Compatibility check
try:
file = open(\'engine_data.out\')
except FileNotFoundError:
print( \"File not recognized. Please provide a valid CONVERGE output file\")
# reading data in file
data = []
for line in file:
if \'#\' not in line:
a = line.split()
data.append(a)
# concerting rows to column
data_transpose = np.transpose(data)
data_transpose = data_transpose.astype(float) # as nos. in data are floating nos
# creating code guide for users
print(\'Kindly refer below chart to select code associated with parameters to plot\')
parameters = [\'crank angle\',\'pressure\',\'max_pressure\',\'min_pressure\',\'mean_temperature\',\'max_temperature\',\'min_temperature\',\'volume\',\'mass\',\'density\',\'integrated_HR\',\'HR_rate\',\'Cp\',\'Cv\',\'gamma\',\'Kinematicv iscosity\',\'dynamic viscosity\']
code = [\'0\',\'1\',\'2\',\'3\',\'4\',\'5\',\'6\',\'7\',\'8\',\'9\',\'10\',\'11\',\'12\',\'13\',\'14\',\'15\',\'16\']
units = [\'°\',\'MPa\',\'MPa\',\'MPa\',\'K\',\'K\',\'K\',\'m³\',\'Kg\',\'Kg/m³\',\'J\',\'J/time\',\'J/Kg-K\',\'J/Kg-K\',\'none\',\'m²/sec\',\'N-sec/m²\']
code_guide = {\'Parameters\':parameters, \'code\': code} # defining coluns
df = pd.DataFrame(code_guide, index = parameters ,columns=[\'code\']) # creating dataframe
print(df)
# providing input
x = int(input(\'Please enter the code for x-axis parameter of plot- \'))
y = int(input(\'Please enter the code for y-axis parameter of plot- \'))
# Area under curve by trapezoidal rule
v = data_transpose[7,:]
p = data_transpose[1,:] * pow(10,6)
work = []
for i in range(0,8664):
w = 0.5 * (v[i+1] - v[i]) * (p[i+1] + p[i])
work.append(w)
work_done = 0
for j in range(0,len(work)):
work_done = work_done + work[j]
print(\'\\nNet work done or area under p-v diagram is: \' + \'%0.2f\' %(work_done) + \' J.\')
# performance calculations
speed = 1500/60
power = work_done*speed
print(\'\\nPower output of the engine is: \' + \'%0.2f\' %(power/1000) + \' KW.\')
fuel_mass = 20*pow(10,-6)
sfc = (fuel_mass/power)*3600
print(\'\\nSpecific fuel comsuption: \' + str(sfc) + \'gm/KW-hr\' )
#plotting results
plt.plot(data_transpose[x,:], data_transpose[y,:], color=\'red\', linewidth=2 )
plt.xlabel(parameters[x] + \' in \' + units[x])
plt.ylabel(parameters[y] + \' in \' + units[y])
plt.title(parameters[y] + \' v/s \' + parameters[x])
plt.savefig(parameters[y] + \' vs \' + parameters[x] + \'.png\')
plt.show()
Stepwise procedure:
- First step is to import modules required to write the script. Modules required in this case are matplotlib for plotting results, numpy for numerical calculations and pandas for creating data frame.
- As mentioned in objectives, one of our aim for this script is compatibility check. Its purpose is to check whether data output file is provided is valid or not. This chcek is done using try & except statement. If required output file is not provided an instruction will be printed as \"File not recognized. Please provide a valid CONVERGE output file.\"
- If the compatibility check is successfull and there is no \'FileNotFoundError\', next job is to read the file to extract no. of observations stored in it. File consists of 17 columns and 8665 observations per each column. Data obtained is columnwise, to convert this data to row-wise for easy extracting, transpose() function is used. Also data is of float type, astype() function is used to assign same to data.
- As script input must be in terms of integers, its necessary to assign unique code to each parameter and also guide the end user regarding these codes. pandas module is used to create the tabular data showing each parameter with its unique code.
- input() function is used to provide input to script. Input will be in the form of code for ploting the graph of input 1 or x as x-axis parameter against input 2 or y as y axis parameter.
- Another aim for the script is to calculate area under curve of p-v diagram. Area under p-v curve is also known as work done. For calculating AUC trapezoidal rule is referred. This method gives approximate calculation of area. Under this method, a curve is divided into no. of intervals, here no of obseravation. At each section area is calculated and oveall area will be sum of all such areas. Equation for trapezoidal rule for this script will be; area = Σ 0.5 x (vol.@n+1 - vol.@n) x (press.@n+1 - press.@n)
- Final aim is to calculate power output and specific fuel consumption. power = (work done in J x speed in rps) /1000 KW Specific fuel consuption = (fuel consumed / power) x 3600 gm/KW-Hr
- After giving all input and calculating power and Specific fuel consumption, final target is to show the plots.
Results:
- Procedure to obtain results:
- The script is designed to take input from the end user, but Sublime Text does not readily accept the input from user. Input needs to be given through script only. For sublime text to accept the input from outside, a sublime text package named \'SublimeREPL\' needs to be installed.
- After installing the package below procedure needs to be followed;
- After following above procedure; python ask to provide code for parameters to be plotted on x & y axis. For guidance nedded to chosing appropriate code a liabrary is provided in tabular form.
- Plots taken for code checking; P-V plot, P-crank angle plot
- Work done, Power output & Specific Fuel Comsumption: Area under cureve or Net work done = 500.59 J. Power Output of the Engine = 12.51 KW. Specific Fuel Consuption = 5.7532 e^-06 gm/KW-hr
Conclusion:
This project demonstrates handling large amount of data using python. Using python coding all important information can be extracted in very less time. This reduces fatigue to engineer handling such a large data manually. Even continuous monitoring on important parameters can be done through python coding.