Challenge

Week 6 - Data analysis

#Python code for data analysis

import matplotlib.pyplot as plt
import math
import numpy as np
from numpy import trapz



file_name=input('Enter the CONVERGE file having .out extension : ')

#Compatability 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))


        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()

#performance calculation
if x==8 and y==2:
    RPM=1500
    Area=np.trapz(y_data,x_data)
    Workdone=Area*1000
    Power=2*math.pi*RPM*Workdone/60
    Fuel_per_Stroke=20*1e-6
    Fuel_per_Sec=Fuel_per_Stroke*RPM*(0.5/60)
    Fuel_per_Hour=Fuel_per_Sec*3600
    BSFC=Fuel_per_Hour/Power

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


Conclusion:

Area under PV diagram is 0.050058 KJ
Power output of this engine is : 78.6319 KW.
Specific fuel consumption : 0.011445 g/KWh.
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.