Data analysis File parsing script using Python

Google drive link for the 'Engine_data.out' file:

https://drive.google.com/open?id=1lIh6RdUZRex9klgtDhpQ0tmtRTBY11YC

 

OBJECTIVE

The primary aim is to create a data visualizer tool using python and perform certain things by this code is:

  • The script should take column numbers as the input and plot the respective columns as separate images.
  • The plot labels should be extracted from the file. If User requests 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.
  • 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 micrograms of fuel (per 1 stroke cycle). Calculate its specific fuel consumption.

PROCEDURE

1. We have a file in our database by name of ' Engine_data.out'. For which we have to create data visualizer code.

2. Open a sublime file save it with a proper name that having .py extension.

3. Import all the necessary modules;

  • import matplotlib.pyplot as plt
    This module helps us to plot the graph of the given result.
  • import math
    This module helps us to use mathematical functions like pie, sine, cos, etc.
  • import numpy
    This module helps us to do mathematical operations on an element of an array.
    Whenever we want to define more than one value in a single variable we have to use an array and numpy.linspace is also the same thing it stores value in a range like this; numpy.linspace (lower limit, upper limit, no. of division)
    This works acc. to a formula:
    Size of division = (upper limit-lower limit)/(no. of division-1)
  • From scipy.integrate import odeint
    Odeint function which integrates the system of ODE.

3. Use an empty array for storing a value that we get from FOR loop.

4. Append is a command that will continuously append the value of a variable. It keeps on adding the values into an existing array.
float() this function is used to assign a decimal value to a variable. 

5. Read the engie_data.out file. According to it make empty arrays.

6. Here we take Input from the user by using the input command.
Run a FOR loop, inside the If condition. If # is not in line. 
Append the values in empty arrays.

7. Make again an array of name 'a'.
    'a'
is an array and x & y are integers now & if we don't use 'int' then x & y are strings.

8. For user input for the graph. we make a FOR & ELSE loop.

if the user gives the correct name of the file it will run otherwise it won't run and show an error "File not found, enter correct name".

9. Further, we write a simple code for finding the area, power, and specific fuel consumption by using some basic mechanical formulas.

Here we use one more new command numpy.trapz(x.y) will integrate along the given axis using trapezoidal rule and calculate the area under the curve on points x,y.

"""
Engine_data.out File parsing in python
by jitesh sahjwani
"""

#inputs modules
import math
import matplotlib.pyplot as plt
import numpy

#data reading 

crank = []
pressure = []
max_pres = []
min_pres = []
mean_temp =[]
max_temp = []
min_temp = []
volume = []
mass = []
density = []
Integrated_HR = []
HR_rate = []
c_p = []
c_v = []
gamma = []
kin_visc = []
dyn_visc = []

line_count = 1

j=(input("enter file name"))	#for taking input from user
if j.endswith('.out') is True:		# .out must be in qoutes # if string endswith '.out' loop will run or else print file not found
									# first letter of 'true' should be capital. 
	for line in open (j):		# j should be our file name otherwise loop will not run.
		if '#' not in line:
			crank.append(float(line.split()[0]))
			pressure.append(float(line.split()[1]))
			max_pres.append(float(line.split()[2]))
			min_pres.append(float(line.split()[3]))
			mean_temp.append(float(line.split()[4]))
			max_temp.append(float(line.split()[5]))
			min_temp.append(float(line.split()[6]))
			volume.append(float(line.split()[7]))
			mass.append(float(line.split()[8]))
			density.append(float(line.split()[9]))
			Integrated_HR.append(float(line.split()[10]))
			HR_rate.append(float(line.split()[11]))
			c_p.append(float(line.split()[12]))
			c_v.append(float(line.split()[13]))
			gamma.append(float(line.split()[14]))
			kin_visc.append(float(line.split()[15]))
			dyn_visc.append(float(line.split()[16]))

			
	a = ([crank, pressure, max_pres, min_pres, mean_temp,max_temp,min_temp, volume, mass, density, Integrated_HR, HR_rate,c_p, c_v, gamma, kin_visc, dyn_visc])
	
	## a is array, x & y are integers now. if we dont use 'int' then x & y are string.##''
	
	x=int(input('enter first value for x-axis='))    #for taking input from user
	y=int(input('enter second value for y-axis='))


	#for label
	d=1

	for text in open(j,'r'):
		if '#' in text:
			if d==3:

				c= (text.split()[0:17])

			if d==4:
				de= (text.split()[0:17])
			d=d+ 1
	
	#print(c[x]+de[x])
	#print(c[x]+de[x])

	plt.plot(a[x-1] , a[y-1],color='blue')
	plt.xlabel(c[x]+ de[x])
	plt.ylabel(c[y]+de[y])

	plt.show()

else:
	print('file not found, enter correct name')


#for area and power
area=numpy.trapz(a[1],a[7]) #numpy.trapz(x.y) will integrate along the given axis using trapezoidal rule and calculate area under curve on points x,y .
print('AREA under PV = ',area) 
#area under PV diagram = work done
rpm =1500	 								#given
rps=rpm/60  								#convert into revolution per sec rps=rpm/60 #rps=25 
powerwatt = area*rps*1000 					#in Kwatt #area=W.D earliear in MW 
powerhp = powerwatt/0.746					# 1hp=0.746 KW
print('POWER of engine = ',powerwatt, 'in kWatt, when rpm is 1500')
print('power of engine is',powerhp, 'in horsepower')

sfc=(20*pow(10,-6)*3600)/(0.08*powerwatt)		
print('specific fuel consumption is',sfc ,'in g/KWh')

 

                    The P-V diagram. P is in column 2 and V is in column 8.

enter file nameengine_data.out
enter first value for x-axis=8
enter second value for y-axis=2
AREA under PV =  0.0005005866274680075
POWER of engine =  12.514665686700187 in kWatt, when rpm is 1500
power of engine is 16.775691269035104 in horsepower
specific fuel consumption is 0.07191562463841637 in g/KWh

***Repl Closed***

This is the result that we got after running the program.

CONCLUSION

  • The curve can be plotted by taking input from the User.
  • Calculated the area under the P-V diagram. P is in column 2 and V is in column 8.
  • Calculated the power output of this engine. Assume that RPM is 1500
  • Calculated its specific fuel consumption.

Projects by Jitesh Sahjwani

OBJECTIVE In this challenge, we check and create the properties for a Neon side crash-BIW model and run the simulation & observe results. Question: Neon side crash -BIW Check the unit system and either follow [Mg mm s] or [Kg mm ms]. Create an appropriate int Read more

OBJECTIVE In this challenge, we check and create the properties for a Neon frontal crash-BIW model and run the simulation & observe results. Question: Frontal crash-BIW Check the unit system and either follow[Mg mm s] or [Kg mm ms]. Create an appropriate inte Read more

OBJECTIVE In this report, we mesh a Bumper assembly.Perform simulation on Crash tube and compare the Type-7 simulation results, Type-11 along with Type-7 and different kinematic condition simulation results. Create six different cases  Run the crash tube model Read more

OBJECTIVE The main objective is to analyze and compare the failure behavior of a plate using different material models LAW-1, LAW-2, LAW-27 & LAW-36 along with Johnson-cook Failure card. For LAW-2, Once use Johnson\'s Failure card along with some certain p Read more

OBJECTIVE Using the crash beam file, Comparison of simulation results of the base setup and improved shell element properties. Questions: 1.Using the crash beam file and change the run time to 55 ms. 2. Change the number of animation steps during simulation to a min Read more

Crash Worthiness analysis of housing and arm bracket using Radioss Hypermesh OBJECTIVE The key objective is to create the 2D and 3D meshing for the given models and solve the following questions PROCEDURE & Answers 1. Material property for steel we can ch Read more

Google drive link for Hypermesh files: https://drive.google.com/open?id=1MDhngswNUUJFrXmWwMTR4jfR0R9T6PKd   OBJECTIVE The key objective is to carry out the geometry cleanup operation & ignore holes less than dia 5mm, extract mid surface and create a 2D mesh Read more

OBJECTIVE The key objective of writing this program is to perform curve fitting with the help of a linear and cubic polynomial for the Temp. & Cp data. #1. What does popt and pcov mean? #2. What does np.array(temperature) do? #3. What does the * in *popt Read more

OBJECTIVE The main objective is to Minimize the given equation with respect to the given constraint. Problem: This function `f(x,y) = 5-(x-2)^2 -2(y-1)^2` is subject to the following constraint `x + 4y = 3` Solution: Make a new function as `g(x,y) = Read more


Loading...

The End