Project

Data Analysis - Python

Aim :- To create a Data Visualizer Tool that does the following things.

Data Visualizer

  • Your script should take column numbers as the input and plot the respective columns as separate images.
  • Each file should be saved by the name of the column.
  • The plot labels should be extracted from the file. If, I request for a plot between column 1 (crank angle) and column 8(volume), then the label information should automatically be extracted and must appear as labels in the plots. THIS SHOULD NOT BE DONE MANUALLY.

Compatability Check

  • Your code should exit gracefully, if a non-compatible file is provided as an input. It should say something like \"File not recognized. Please provide a valid CONVERGE output file\".

Basic Performance Calculation

  • Calculate the area under the P-V diagram. P is in column 2 and V is in column 8.
  • Calculate the power output of this engine. Assume that RPM is 1500.
  • This engine consumed 20 micro grams of fuel (per 1 stroke cycle). Calculate its specific fuel consumption.

#CONVERGE data file :-

\"\"

#Python code for Data Analysis :-

#Python code for Data Analysis
#By DIPESH SALUNKE

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 path directory where Python code is saved.\')
file_name = input(\'Enter the CONVERGE file having .out Extension : \')

#Compatibility Check
try :
	data = open(file_name,\'r\')
	print(\'\\nData file is succesfully 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))                             #First Column \'#\' has no data.

		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] + Line.split()[x]
			y_label = line.split()[y] + 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)                         #In MJ
	Workdone = Area*1000                                   #In KJ
	Power = 2*math.pi*RPM*Workdone/60                      #In KW
	Fuel_per_Stroke = 20*1e-6                              #In grams per stroke
	Fuel_per_Sec = Fuel_per_Stroke*RPM*(0.5/60)            #In grams per second
	Fuel_per_Hour = Fuel_per_Sec*3600                      #In grams per hour
	BSFC = Fuel_per_Hour/Power                             #In g/KWh

	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\')




#Code Explanation :-

  • Importing useful modules from different libraries.
  • Printing General Instructions and then asking for input a CONVERGE file from User.
  • In compatability check, if CONVERGE file exists at specified directory then it will show \'Data file is Succesfully opened.\'
  • If a non-compatible file is provided as an input. It would say something like \"Please Enter a valid filename.\" & the code should exit gracefully.
  • Here, line_count is for counting a lines of CONVERGE data file.
  • In third line, spliting a different parameters of CONVERGE data file.
  • Splitting of line is identified by \' \'. --> [Delimiter(Blank Space)] That\'s why it has total 18 columns but first column \'#\' has no data. After neglecting first column in consideration, it has total 17 columns that contains useful data.
  • In fourth line, splitting an Units of different parameters.
  • Printing different parameters with their respective units.
  • Getting an input from the user.Here, X-axis parameter is independent variable and Y-axis parameter is dependent variable. This terminology is used for data visualization.
  • Defining an empty array x_data & y_data.
  • In third line, splitting a different parameters and then assigning into X_label & Y_label w.r.t. given input.(For title of Plot)
  • Then splitting a different parameters plus their respective units. And, putting them into x_label & y_label w.r.t. given input.
  • If \'#\' is not in a line then extracting all that data in float form & appending into x_data & y_data w.r.t. given input.
  • Assigning a title,xlabel,ylabel & filename to a plot w.r.t. given input.And,saving it in a predefined directory.
  • If X=8 & Y=2 then calculating area under the curve of P-V diagram using \"trapz\" from \"numpy\".And,Defining workdone in KJ, Power in KW & Specific Fuel Consumption in g/KWh by using respective formulas.
  • And, all these done automatically.

(Note : Sublime window is not meant for command prompt. It is meant for output. So, \"SublimeREPL\" package is required to install.)

#Compatability Check :-

\"\"

If a non-compatible file is provided as an input. It would say something like \"Please Enter a valid filename.\" & it would exit gracefully.

#Result :-

\"\"

#Data Visualization :-

#P-V Diagram :-

\"\"

#Effect of Mean Temperature on Cp :-

\"\"

#Effect of Mean Temperature on Cv :-

\"\"

#Effect of Crank Angle on Pressure :-

\"\"

#Effect of Crank Angle on Volume :-

\"\"

All these visualization shows that how dependent variable(Y-Parameter) changes w.r.t. change in independent variable(X-Parameter).

#Output :-

Area under the P-V diagram(Workdone) : 0.5005866274680075 KJ
Power Output of this Engine : 78.63196356693915 KW
Specific Fuel Consumption : 0.011445727146745265 g/KWh

#============#==========#===========#==========#========#

1 comment
  1. Nagamani YadavalliVery elaborated explanation.
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.