Project

Data analysis USING PYTHON FOR AN GIVEN OUTPUT FILE

Data analysis USING PYTHON FOR AN GIVEN OUTPUT FILE

Here in this challenge we have to study file parsing/in general data analysis, using a data file [containing the data of engine internal behaviour (Crank_angle,Temperature,Pressure ,and Volume reading)]. by writing a code on python, we have to read the data from the file engine_data.out . Also create different plots depending on the instruction given.

CODE EXPLANATION:-

To properly execute the result at the end, we need to import matplotlib.py plot, also for any math calculation included. import math module.

for the program to start ,we need to define or provide a line of code that should read a data from engine_data.out , And the santax for that is .[for line in open (\'engine_data.out\'):] but before defining that we must provide an initial input array, so that the values from the code can be extracted . Also a counter variable is added ,so that the code can read each information line by line with respect to column and row.

Here in this code first counter variable [1] is initialize and an empty array has been created for crank angle, pressure,temperature and volume. After that file prasing starts.the santax mentioned above is having a meaning i.e, read all data in row and column line by line without any commented section from the data file.

After that within the the above mentioned FOR LOOP ,we created a string variable using float that can read the specific column data from the (engine_data.out) file .

example= crank.append(float (line.split()[0])

depending upon the above line of code other parameters auch as pressure , temperature, volume are encoded in python code. After these all lines ,we have to add +1 counter on the line_count variable,so that the data was counted and stored line by line.

After that A,B variables having aempty error which can store the value of pressure and volume , so that we can calculate the area under p-v values. using np.trapz.

After calculating the area the engine performance characterstics are calculated depending upon the values provided.and the program itself having the explanation on each of the line comment by comment.

coding:-

\"\"\"
demonstarating file prasing in python
\"\"\"
import matplotlib.pyplot as plt
import numpy as np
import math
from numpy import trapz

line_count = 1
crank=[]
pressure=[]
temperature=[]
volume=[]

try:
	open(\'engine_data.out\')

except:
	print(\"File is not recognized.Please provide the valid input file.\")

#file parsing codes
for line in open(\'engine_data.out\'):
	if \'#\' not in line:
		crank.append(float(line.split()[0]))
		pressure.append(float(line.split()[1]))
		temperature.append(float(line.split()[4]))
		volume.append(float(line.split()[7]))

		line_count= line_count+1


A=volume
b=pressure

area=np.trapz(b,A)
print(\'AREA UNDER P-V DIAGRAM =\',area,)

# Given engine performance charactersrtics.
# mass flow rate =20  , the engine consumes 20 micrograms of fuel. per stroke cycle
speed= 1500 #The engine crank rotation is 1500 rpm in 60 sec.
# As the two revolution of crank makes four stroke and one revolution of crank makes two stroke in the four stroke engine.
# Therefore there is 750 strokes are compeleting in 60sec
#Also a single stroke occurs in (60/750)=0.08 sec.

mfr=0.08*20*pow(10,-6)
work=area*1*pow(10,6)  #converting work from MJ TO JOULES.
power=work*(speed/120) #power output from the engine.
power=power/1000       #calculating power in KW.
sfc= mfr/power         #calculation of specific fuel consumption.

print(\'POWER OUTPUT FROM THE ENGINE=\',power,\'KW\')

print(\'SPECIFIC FUEL CONSUMPTION=\',sfc,\'g/kwh\')

#figure
plt.plot(crank,pressure,linewidth=2,color=\"red\")
plt.xlabel(\'crank\')
plt.ylabel(\'pressure\')
plt.show()
plt.plot(crank,temperature,linewidth=2,color=\"green\")
plt.xlabel(\'crank\')
plt.ylabel(\'temperature\')
plt.show()
plt.plot(volume,pressure,linewidth=3,color=\"magenta\")
plt.xlabel(\'volume\')
plt.ylabel(\'pressure\')
plt.show()

solution obtained from program.

1) Area under p-v diagram.

2)power output from the engine.

3)specific fuel consumption rate.

4) plot pressure v/s crank rotation.

5)plot temperature v/s crank rotation

6)plot pressure v/s volume diagram

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.