Project

Data Analysis Python

Description: In the Code given below, we are provided with a \".out\" file, which contains the thermodynamic data of a given species, we are supposed to analyse the data, compare and plot the respective Properties against one another, for example: plot Pressure Vs Volume.

In the Code, we first Perform the Compatibility Check:

Logic: We see that the compatible Converge Output file always is of the format \".out\", hence if the given file is not having an extension \".out\", then the program throws out an error stating \"File not recognized. Please provide a valid CONVERGE output file.\", and gracefully exits the code.
The Part of the Code performing this activity is as given below:

import sys
G=input(\'Enter the file name along with the format that needs to be worked on: \')
#engine_data.out#
if \'.out\' not in G:
    print(\"File not recognized. Please provide a valid CONVERGE output file.\")
    sys.exit()
else:
    print(\"File recognized\")   

The Second Part of the Code is the Data Visualizer:

Logic: We could observe that the \".out\" file provided follows a particular style, that is, all the headings of the Data start with a \"#\"hence we skip these lines with an \"if \"#\" not in line\", statement, meanwhile we have 17 different properties that needs to be analysed and plotted, hence for these 17 properties we create 17 different arrays, and feed the data for the respective arrays.
Once the data is sorted, we then plot the data.
The Part of the Code performing this activity is as given below:

import matplotlib.pyplot as plt
import sys
import numpy as np
Crank = []
Pressure = []
Max_Pressure = []
Min_Pressure = []
Mean_Temperature = []
Max_Temperature = []
Min_Temperature = []
Volume = []
Mass = []
Density = []
Integrated_HR = []
HR_Rate = []
C_p = []
C_v = []
Gamma = []
Kinematic_Viscosity = []
Dynamic_Viscosity = []
#Code for Data Parsing Starts Here#
line_count = 1
for line in open(G, \'r\'):
    if \'#\' not in line:
        line.split()
        Crank.append(float(line.split()[0]))
        Pressure.append(float(line.split()[1]))
        Max_Pressure.append(float(line.split()[2]))
        Min_Pressure.append(float(line.split()[3]))
        Mean_Temperature.append(float(line.split()[4]))
        Max_Temperature.append(float(line.split()[5]))
        Min_Temperature.append(float(line.split()[6]))
        Volume.append(float(line.split()[7]))
        Mass.append(float(line.split()[8]))
        Density.append(float(line.split()[9]))
        Integrated_HR.append(float(line.split()[10]))
        HR_Rate.append(float(line.split()[11]))
        C_p.append(float(line.split()[12]))
        C_v.append(float(line.split()[13]))
        Gamma.append(float(line.split()[14]))
        Kinematic_Viscosity.append(float(line.split()[15]))
        Dynamic_Viscosity.append(float(line.split()[16]))
        line_count = line_count + 1
print(\"\\nEnter a column number in the format \'column x\', where x is between 0 and 16.\")
a = input(\"Enter the 1st column to be compared: \")
b = input(\"Enter the 2nd column to be compared: \")
if (a == \'column 0\'):
        a = Crank
        i = \"Crank\"
elif (a==\'column 1\'):
        a = Pressure
        i = \"Pressure\"
elif (a==\'column 2\'):
        a = Max_Pressure
        i = \"Max_Pressure\"
elif (a==\'column 3\'):
        a = Min_Pressure
        i = \"Min_Pressure\"
elif (a==\'column 4\'):
        a = Mean_Temperature
        i = \"Mean_Temperature\"
elif (a==\'column 5\'):
        a = Max_Temperature
        i = \"Max_Temperature\"
elif (a==\'column 6\'):
        a = Min_Temperature
        i = \"Min_Temperature\"
elif (a==\'column 7\'):
        a = Volume
        i = \"Volume\"
elif (a==\'column 8\'):
        a = Mass
        i = \"Mass\"
elif (a==\'column 9\'):
        a = Density
        i = \"Density\"
elif (a==\'column 10\'):
        a = Integrated_HR
        i = \"Integrated_HR\"
elif (a==\'column 11\'):
        a = HR_Rate
        i = \"HR_Rate\"
elif (a==\'column 12\'):
        a = C_p
        i = \"C_p\"
elif (a==\'column 13\'):
        a = C_v
        i = \"C_v\"
elif (a==\'column 14\'):
        a = Gamma
        i = \"Gamma\"
elif (a==\'column 15\'):
        a = Kinematic_Viscosity
        i = \"Kinematic_Viscosity\"
elif (a==\'column 16\'):
        a = Dynamic_Viscosity
        i = \"Dynamic_Viscosity\"
else:
        print(\"The Column 1 entered is not in the list\\n\")
        print(\"Enter the Column Numbers between 0 and 16\\n\")
if (b == \'column 0\'):
        b = Crank
        j = \"Crank\"
elif (b==\'column 1\'):
        b = Pressure
        j = \"Pressure\"
elif (b==\'column 2\'):
        b = Max_Pressure
        j = \"Max_Pressure\"
elif (b==\'column 3\'):
        b = Min_Pressure
        j = \"Min_Pressure\"
elif (b==\'column 4\'):
        b = Mean_Temperature
        j = \"Mean_Temperature\"
elif (b==\'column 5\'):
        b = Max_Temperature
        j = \"Max_Temperature\"
elif (b==\'column 6\'):
        b = Min_Temperature
        j = \"Min_Temperature\"
elif (b==\'column 7\'):
        b = Volume
        j = \"Volume\"
elif (b==\'column 8\'):
        b = Mass
        j = \"Mass\"
elif (b==\'column 9\'):
        b = Density
        j = \"Density\"
elif (b==\'column 10\'):
        b = Integrated_HR
        j = \"Integrated_HR\"
elif (b==\'column 11\'):
        b = HR_Rate
        j = \"HR_Rate\"
elif (b==\'column 12\'):
        b = C_p
        j = \"C_p\"
elif (b==\'column 13\'):
        b = C_v
        j = \"C_v\"
elif (b==\'column 14\'):
        b = Gamma
        j = \"Gamma\"
elif (b==\'column 15\'):
        b = Kinematic_Viscosity
        j = \"Kinematic_Viscosity\"
elif (b==\'column 16\'):
        b = Dynamic_Viscosity
        j = \"Dynamic_Viscosity\"
else:
        print(\"The Column 2 entered is not in the list\\n\")
        print(\"Enter the Column Numbers between 0 and 16\\n\")
A = str(print(\"{} Vs {}\".format(i,j)))
B = \'A\' + \'.png\'
#plotting#
print(\'We are plotting a graph of {} Vs {}\'.format(i,j))
plt.plot(a,b,linewidth=3)
plt.xlabel(i)
plt.ylabel(j)
plt.savefig(B)
plt.show()

The Third Part of the code is the Basic Performance Calculation:
a - We calculate the area under the PV diagram using,

1- Trapezoidal Rule
2- Simpsons Rule

b - The Power output of the Engine is calculated using the formula as given below:

Where,
p = Power Output
W = work done by the engine (Area under the PV Diagram)
cps = cycles per second (we have been provided with RPM so we multiply by 60).

c - The Specific Fuel Consumption is calculated using the formula as given below:

Where,
r = fuel consumption rate in grams per second (g/s)

P = Power Output

The Code for performing this operation is as follows:

#Calculating Area under PV Diagram#
#Work done by the Gas during a thermodynamic Process#
Area = abs(np.trapz(Volume, Pressure, dx = 0.1))
print(\"Area under the PV Diagram using Trapezoidal Rule\")
print(\"Area under the PV Diagram is: \",Area)
Area2 = abs(simps(Volume, Pressure, dx = 0.1))
print(\"Area under the PV Diagram using Simpsons Rule\")
print(\"Area under the PV Diagram is: \",Area2)
#Calculating the Power Output of the Engine#
Power_Output = Area * 1500 * 60
print(\"The Power Output of the Engine is: {}\".format(Power_Output))
print(\"Source for the Formula used: https://www.grc.nasa.gov/WWW/K-12/airplane/ottoa.html\")
#Calculating Specific Fuel Consumption#
Specific_Fuel_Consumption = (((20/1000000)/Power_Output)*60)
print(\"The Brake Specific Fuel Comsumption in g/KW.h is : {}\".format(Specific_Fuel_Consumption))
print(\"Source for the Formula used: https://en.wikipedia.org/wiki/Brake_specific_fuel_consumption\")

The Complete Code for the Data Analysis is as given Below:

# -*- coding: utf-8 -*-
\"\"\"
Created on Thu Jul 12 12:49:43 2018

@author: shabarish
\"\"\"
\"\"\"Code for Data Parsing, Analysing and Plotting\"\"\"
import matplotlib.pyplot as plt
import sys
import numpy as np
from scipy.integrate import simps
G=input(\'Enter the file name along with the format that needs to be worked on: \')
#engine_data.out#
if \'.out\' not in G:
    print(\"File not recognized. Please provide a valid CONVERGE output file.\")
    sys.exit()
else:
    print(\"File recognized\")    
Crank = []
Pressure = []
Max_Pressure = []
Min_Pressure = []
Mean_Temperature = []
Max_Temperature = []
Min_Temperature = []
Volume = []
Mass = []
Density = []
Integrated_HR = []
HR_Rate = []
C_p = []
C_v = []
Gamma = []
Kinematic_Viscosity = []
Dynamic_Viscosity = []
#Code for Data Parsing Starts Here#
line_count = 1
for line in open(G, \'r\'):
    if \'#\' not in line:
        line.split()
        Crank.append(float(line.split()[0]))
        Pressure.append(float(line.split()[1]))
        Max_Pressure.append(float(line.split()[2]))
        Min_Pressure.append(float(line.split()[3]))
        Mean_Temperature.append(float(line.split()[4]))
        Max_Temperature.append(float(line.split()[5]))
        Min_Temperature.append(float(line.split()[6]))
        Volume.append(float(line.split()[7]))
        Mass.append(float(line.split()[8]))
        Density.append(float(line.split()[9]))
        Integrated_HR.append(float(line.split()[10]))
        HR_Rate.append(float(line.split()[11]))
        C_p.append(float(line.split()[12]))
        C_v.append(float(line.split()[13]))
        Gamma.append(float(line.split()[14]))
        Kinematic_Viscosity.append(float(line.split()[15]))
        Dynamic_Viscosity.append(float(line.split()[16]))
        line_count = line_count + 1
print(\"\\nEnter a column number in the format \'column x\', where x is between 0 and 16.\")
a = input(\"Enter the 1st column to be compared: \")
b = input(\"Enter the 2nd column to be compared: \")
if (a == \'column 0\'):
        a = Crank
        i = \"Crank\"
elif (a==\'column 1\'):
        a = Pressure
        i = \"Pressure\"
elif (a==\'column 2\'):
        a = Max_Pressure
        i = \"Max_Pressure\"
elif (a==\'column 3\'):
        a = Min_Pressure
        i = \"Min_Pressure\"
elif (a==\'column 4\'):
        a = Mean_Temperature
        i = \"Mean_Temperature\"
elif (a==\'column 5\'):
        a = Max_Temperature
        i = \"Max_Temperature\"
elif (a==\'column 6\'):
        a = Min_Temperature
        i = \"Min_Temperature\"
elif (a==\'column 7\'):
        a = Volume
        i = \"Volume\"
elif (a==\'column 8\'):
        a = Mass
        i = \"Mass\"
elif (a==\'column 9\'):
        a = Density
        i = \"Density\"
elif (a==\'column 10\'):
        a = Integrated_HR
        i = \"Integrated_HR\"
elif (a==\'column 11\'):
        a = HR_Rate
        i = \"HR_Rate\"
elif (a==\'column 12\'):
        a = C_p
        i = \"C_p\"
elif (a==\'column 13\'):
        a = C_v
        i = \"C_v\"
elif (a==\'column 14\'):
        a = Gamma
        i = \"Gamma\"
elif (a==\'column 15\'):
        a = Kinematic_Viscosity
        i = \"Kinematic_Viscosity\"
elif (a==\'column 16\'):
        a = Dynamic_Viscosity
        i = \"Dynamic_Viscosity\"
else:
        print(\"The Column 1 entered is not in the list\\n\")
        print(\"Enter the Column Numbers between 0 and 16\\n\")
if (b == \'column 0\'):
        b = Crank
        j = \"Crank\"
elif (b==\'column 1\'):
        b = Pressure
        j = \"Pressure\"
elif (b==\'column 2\'):
        b = Max_Pressure
        j = \"Max_Pressure\"
elif (b==\'column 3\'):
        b = Min_Pressure
        j = \"Min_Pressure\"
elif (b==\'column 4\'):
        b = Mean_Temperature
        j = \"Mean_Temperature\"
elif (b==\'column 5\'):
        b = Max_Temperature
        j = \"Max_Temperature\"
elif (b==\'column 6\'):
        b = Min_Temperature
        j = \"Min_Temperature\"
elif (b==\'column 7\'):
        b = Volume
        j = \"Volume\"
elif (b==\'column 8\'):
        b = Mass
        j = \"Mass\"
elif (b==\'column 9\'):
        b = Density
        j = \"Density\"
elif (b==\'column 10\'):
        b = Integrated_HR
        j = \"Integrated_HR\"
elif (b==\'column 11\'):
        b = HR_Rate
        j = \"HR_Rate\"
elif (b==\'column 12\'):
        b = C_p
        j = \"C_p\"
elif (b==\'column 13\'):
        b = C_v
        j = \"C_v\"
elif (b==\'column 14\'):
        b = Gamma
        j = \"Gamma\"
elif (b==\'column 15\'):
        b = Kinematic_Viscosity
        j = \"Kinematic_Viscosity\"
elif (b==\'column 16\'):
        b = Dynamic_Viscosity
        j = \"Dynamic_Viscosity\"
else:
        print(\"The Column 2 entered is not in the list\\n\")
        print(\"Enter the Column Numbers between 0 and 16\\n\")
A = str(print(\"{} Vs {}\".format(i,j)))
B = \'A\' + \'.png\'
#plotting#
print(\'We are plotting a graph of {} Vs {}\'.format(i,j))
plt.plot(a,b,linewidth=3)
plt.xlabel(i)
plt.ylabel(j)
plt.savefig(B)
plt.show()
#Calculating Area under PV Diagram#
#Work done by the Gas during a thermodynamic Process#
Area = abs(np.trapz(Volume, Pressure, dx = 0.1))
print(\"Area under the PV Diagram using Trapezoidal Rule\")
print(\"Area under the PV Diagram is: \",Area)
Area2 = abs(simps(Volume, Pressure, dx = 0.1))
print(\"Area under the PV Diagram using Simpsons Rule\")
print(\"Area under the PV Diagram is: \",Area2)
#Calculating the Power Output of the Engine#
Power_Output = Area * 1500 * 60
print(\"The Power Output of the Engine is: {}\".format(Power_Output))
print(\"Source for the Formula used: https://www.grc.nasa.gov/WWW/K-12/airplane/ottoa.html\")
#Calculating Specific Fuel Consumption#
Specific_Fuel_Consumption = (((20/1000000)/Power_Output)*60)
print(\"The Brake Specific Fuel Comsumption in g/KW.h is : {}\".format(Specific_Fuel_Consumption))
print(\"Source for the Formula used: https://en.wikipedia.org/wiki/Brake_specific_fuel_consumption\")

Some Results:


Volume VS Pressure
Diagram

Observations:

We could observe that the area under the PV diagram is negative, this means the value of work done by the given species is negative, which also means that the work is done by the given species, thus energy is spent by the species, hence the work done is negative (Please note that in the code I have taken the absolute value to make it positive)

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.