Challenge

Week 6 - Data analysis

To createa a Data Visualizer Tool that does the following things

DATA VISUALIZER :-

your script should take column numbers as the input and plot the

respective columns as seperate images.

Each file should be saved by the name of the column.

The plot labels should be extracted from the file. If, i request for 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. This should not be done manually.

COMPATIBILITY CHECK :-

Your code should exit gracefully, if a non-compatible file is provided

as an input. It should say something like "File not recognized. Please

provide a valid CONVERGE output file ".

BASIC PRFORMANCE CALCULATION :-

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 micro grams of fuel (per 1 stroke cycle).

Calculate the specific fuel consumtion.

PROGRAM :-

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 == 'CONVERGE data file.out ' :

print('File found succesfully !! you may continue...n')

else :

print('File not recognized. Please provide a valid CONVERGE output file')

exit ()

print (' ')

# parameter given below for plot

print(' The plot parameter 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_Visc, 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 youb need to plot : ')

print(' ')

# declare inputs are integer

x = int(x)

y = int(y)

# used to store the values

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 = 30, 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 calculations

pressure = []

volume = []

for line in open( ' CONVERGE data file .out') :

if '#' not in line:

pressure.append(float(line.split()[1]))

volume.append(float(line.split()[7]))

P = 1000000*np.array(pressure)

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

EXPLANTION :-

Importing useful modules from differnet libraries.

Printing General Instructions and then asking for input a CONVERGE

file from user.

In compatibility check, if CONVERGE file exist at specified directory

then it will show 'Data file is Succesfully opend'.

If a non-compatibility file is provided as an input. It should say something

like " Enter a valid filename ". & the code should exit gracefully.

Then, Here 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 and column_2 .

After that using a for loop the extracted column no and names are displayed

for user and asked to make a plot.

Then the values of the column selected by user are extracted and stored in an

array and further plotted on a graph.

For basic performance calculation the values of pressure and volume column

are extracted and using the 'np.trapz(P,V)'

command area under the PV diagram is calculated which also is the workdone.

Then Converting the given speed of 1500 rpm into rps the power output of

the engine is calculated and further the specific fuel consumption of engine

is calculated.

After that all the values calculated are displayed on the screen for the user.

OUTPUT :-

The program took 1 and 8 as their column inputs and gave the plot between

volume verses crank angle with title, labels of the respective parameters,

similarly it will execute for every other column numbers of the parameters

Compatibility of the program is checked for the converge file and input column values.

PV diagram is plotted and basic performance calculations are executed.

CONCLUSION :-

The data from the output file was read successfully and the plot required as per the

user need was made.

The performance calculation were done and displayed successfully.

nWorkdone (area under P-V diagram) = 500.5866 Joules

Power out of the equation = 78.6319 KW

Specific fuel consumption = 0.00091516 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.

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.