Challenge

Week 6 - Data analysis

OBJECTIVE:

Write program for data visulizer, compability check and basic calculation.(Data analysis)

PROCEDURE:

1. Import matplotlib.pyplot and numpy package.

#File parsing in python

import matplotlib.pyplot as plt
import numpy as np

2. For compability check use try and except loop.

try:
	open('engine_data.out')
	print('File opened successfully')
	
except FileNotFoundError as e:
	print("File not recognized. Please provide a valid CONVERGE output file",e)

3. No. of lines, No. of columns, column number, column name and units of column calculated from data file by using following program. Basically i have used for and if loop.

# Regarding data files
line_count=1
headline_count=1


#File parasing program
for line in open('engine_data.out'):
	if '#' not in line:
		line_count=line_count+1
		column_count=len(line.split())
		
	if '#' in line:
		headline_count=headline_count+1
		if headline_count==3:
			column_number=(line.split())
		if headline_count==4:
			column_name=(line.split())
		if headline_count==5:
			column_units=(line.split())


print(line_count)
print(column_count)
print(column_number)
print(column_name)
print(column_units)

4. Enter input value of column no.(1 to 17) to plot graph between x-axis and y-axis

print('Column parameter(1-17)','1:crank,2:Pressure, 3:Max_Pressure, 4:Min_Pressure, 5:Mean_Temp, 6:Max_Temp, 7:Min_Temp, 8:Volume, 9:Mass'
      +'10:density, 11:integrated_HR, 12:HR_Rate, 13:C_p, 14:C_v, 15:Gamma, 16:kin-Vics, 17:Dyn_Visc')


first_column = input("Please enter column number for x axis between 1 to 17:")
first_column=(int(first_column) -1)
second_column =input("Please enter column number for y axis between 1 to 17:")
second_column=(int(second_column) -1)


print('You have requested graph between', column_name[((first_column)+1)], 'vs' ,column_name[((second_column)+1)])

5. Values of first column and second column stored by using append command.

values_first_column=[]
values_second_column=[]

for line in open('engine_data.out'):
	if '#' not in line:
		values_first_column.append(float(line.split()[first_column]))

for line in open('engine_data.out'):
	if '#' not in line:
		values_second_column.append(float(line.split()[second_column]))

6. Plot graph between selected two column. File name and lable update as per selection of column.

plt.plot(values_first_column,values_second_column)
plt.savefig(column_name[((first_column)+1)]+' VS '+ column_name[((second_column)+1)]+'.png')
plt.xlabel(column_name[((first_column)+1)] + column_units[((first_column)+1)] )
plt.ylabel(column_name[((second_column)+1)] + column_units[((second_column)+1)])
plt.show()

7. For calculating area under P-V curve stored value of pressure and volume by using append command. After that use trapz to calculate area under curve. Work done by engine equal to area under p-v curve.

#Area under P-V diagram
volume=[]
pressure=[]

for line in open('engine_data.out'):
	if '#' not in line:
		volume.append(float(line.split()[7]))
		pressure.append(float(line.split()[1]))



#Area under the PV curve calculation
area = np.trapz(pressure,volume)
print('Total area under the P-V diagram = ',area,'MJ')

#Work done per cycle
work_done=area          # work_done=area under p-v curve

8. Output power = No. of cycle per second for 4 stroke engine X Area under curve

=(RPM/(2x60)) x Area under curve

RPM=1500	#RPM of 4 stroke engine

# Number of cycle per second for 4 stroke engine
n=RPM/(2*60)

#Power output of engine
power = area*n
print('Power output of engine =',power,'MW')

9. specific fuel consumption = fuel consumption per hour / power

= (20 x 10^(-6) x 1500 x 60) / power

#Calculate fuel consumption
fuel_consumption=20*pow(10,-6)
fuel_consumption_perhour=fuel_consumption*1500*60
specific_fuel_consumption=fuel_consumption_perhour/power
print('specific fuel consumption =',specific_fuel_consumption,'gram/MW.hr')

RESULT:

Complete code

#File parsing in python

import matplotlib.pyplot as plt
import numpy as np

#Compability check

try:
	open('engine_data.out')
	print('File opened successfully')
	
except FileNotFoundError as e:
	print("File not recognized. Please provide a valid CONVERGE output file",e)

# Regarding data files
line_count=1
headline_count=1


#File parasing program
for line in open('engine_data.out'):
	if '#' not in line:
		line_count=line_count+1
		column_count=len(line.split())
		
	if '#' in line:
		headline_count=headline_count+1
		if headline_count==3:
			column_number=(line.split())
		if headline_count==4:
			column_name=(line.split())
		if headline_count==5:
			column_units=(line.split())


print(line_count)
print(column_count)
print(column_number)
print(column_name)
print(column_units)

print('Column parameter(1-17)','1:crank,2:Pressure, 3:Max_Pressure, 4:Min_Pressure, 5:Mean_Temp, 6:Max_Temp, 7:Min_Temp, 8:Volume, 9:Mass'
      +'10:density, 11:integrated_HR, 12:HR_Rate, 13:C_p, 14:C_v, 15:Gamma, 16:kin-Vics, 17:Dyn_Visc')


first_column = input("Please enter column number for x axis between 1 to 17:")
first_column=(int(first_column) -1)
second_column =input("Please enter column number for y axis between 1 to 17:")
second_column=(int(second_column) -1)


print('You have requested graph between', column_name[((first_column)+1)], 'vs' ,column_name[((second_column)+1)])

values_first_column=[]
values_second_column=[]

for line in open('engine_data.out'):
	if '#' not in line:
		values_first_column.append(float(line.split()[first_column]))

for line in open('engine_data.out'):
	if '#' not in line:
		values_second_column.append(float(line.split()[second_column]))

plt.plot(values_first_column,values_second_column)
plt.savefig(column_name[((first_column)+1)]+' VS '+ column_name[((second_column)+1)]+'.png')
plt.xlabel(column_name[((first_column)+1)] + column_units[((first_column)+1)] )
plt.ylabel(column_name[((second_column)+1)] + column_units[((second_column)+1)])
plt.show()


#Area under P-V diagram
volume=[]
pressure=[]

for line in open('engine_data.out'):
	if '#' not in line:
		volume.append(float(line.split()[7]))
		pressure.append(float(line.split()[1]))



#Area under the PV curve calculation
area = np.trapz(pressure,volume)
print('Total area under the P-V diagram = ',area,'MJ')

#Work done per cycle
work_done=area          # work_done=area under p-v curve


RPM=1500	#RPM of 4 stroke engine

# Number of cycle per second for 4 stroke engine
n=RPM/(2*60)

#Power output of engine
power = area*n
print('Power output of engine =',power,'MW')

#Calculate fuel consumption
fuel_consumption=20*pow(10,-6)
fuel_consumption_perhour=fuel_consumption*1500*60
specific_fuel_consumption=fuel_consumption_perhour/power
print('specific fuel consumption =',specific_fuel_consumption,'gram/MW.hr')

2. Pressure vs volume plot

3. crank vs volume plot

4. Area under p-v curve = 0.0005005866274680075 MJ

5. power output = 0.006257332843350094 MW

6. specific fuel consumption = 287.6624985536655 gram/MW.hr

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.