Challenge

Week 6 - Data analysis

# IMPORTING IMP MODULE
import math
import numpy as np
import matplotlib.pyplot as plt

#Taking inputs from user
file_name=input("Enter file name :")
print('------------------------------------------------------------------')
#checking for valid file
if file_name == 'engine_data.out':
    print('File found succesfully!! you may continue...n')
else:
    print('File not recognized. Please provide a valid CONVERGE output file')
    exit()
print('------------------------------------------------------------------')

#parameters given below for plot
print('The plot paramters given below in the series n')
print('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')

print('---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------')

name=['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']

# take inputs from users
x = input('Enter the first parameter you need to plot : ')
y = input('Enter the second parameter you need to plot : ')

print('------------------------------------------------------------')
# declare inputs as integer
x = int(x)
y = int(y)
# uesd to store the value
column_1 = []
column_2 = []

# look for taking required data and opening the data file
for line in open(file_name):
    if '#' not in line:
        column_1.append(float(line.split()[x-1]))
        column_2.append(float(line.split()[y-1]))
# plot
plt.figure(1)
plt.plot(column_1, column_2, linewidth=3)
plt.title(name[y-1]+' & '+name[x-1]+' Plot',fontsize=20,color='red')
plt.xlabel(name[x-1],fontsize=12)
plt.ylabel(name[y-1],fontsize=12)
plt.savefig(name[x-1] + ' vs ' + name[y-1] + '.png')
plt.grid()
plt.show()

#basic performance calculation
pressure = []
volume = []

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

P = 1000000*np.array(pressure) # converting to pascal
V = np.array(volume)

#calculating area PV diagram
AREA = np.trapz(P, V)
print('nWorkdone (area under P-V diagram)= ',AREA ,'Joules')

# Calculating power
power = (AREA * 2* math.pi * (1500/60))/1000
print('Power out of the equation = ',power,'KW')

#calculating specific fuel consumption
sfc = 20 * pow(10, -6)* 3600 / power
print('Specific fuel consumption= ',sfc, 'g/kw.h')

#plotting P-V Diagram
plt.figure(2)
plt.plot(volume, pressure, linewidth = 3)
plt.title('P-V diagram',fontsize=20,color='red')
plt.xlabel('Volume',fontsize=12)
plt.ylabel('Pressure',fontsize=12)
plt.grid()
plt.show()





Explanation-

1.Initially, the required modules are imported.

2.File name is taken as an input from user and, to verify the user file with engine_data.out file, if command is used.

3.The Using a for loop every line of file is read line by line and the lines with '#'not include to read data and are appended to an array named 'column_1 & column_2’.

4.Using a for loop the extracted column no and names are displayed for user and asked to make a plot.

5.Then the values of the column selected by user are extracted and stored in an array and further plotted on a graph.

6.For basic performance calculation the values of pressure andvolume column are extracted and using the 'np.trapz(P,V)'

command, area under the PV diagram is calculated which also is the Workdone.

7.Converting the given speed of 1500rpm into rps the power output of the engine is calculated and further the specific fuel

consumption of engine is calculated.

8.All the values calculated are displayed on the screen for the user.

Result -

Output screen and plot-

If the user enters a valid file name & for parameter 1 , 2-

plot obtained-

If the user enters a valid file name & for parameter 1 , 5-

plot obtained-

If the user enters a valid file name & for parameter 1 , 8-

plot obtained-

If the user enters a valid file name & for parameter 1 , 12-

plot obtained-

If the user enters a valid file name & for parameter 2, 5-

plot obtained-

If the user enters a valid file name & for parameter 1, 15-

plot obtained-

If the user enters a valid file name & for parameter 1, 14-

plot obtained-

Along with these program second figure of plot in common is PV diagram:

If the user enters an invalid file name-

Output -

Workdone (area under P-V diagram)= 500.5866274680076 Joules

Power out of the equation = 78.63196356693916 KW

Specific fuel consumption= 0.0009156581717396209 g/kw.h

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.