Data analysis
Aim
To parse the given NASA file and calculate area under the graph, power, horsepower and specfic fuel consumption.
For the given 8000 values the required paramters are taken and plotted using matplotlib function. The linesplitting functions are used to separate the parameters from others in a single line. The file is also checked whether its a compatible file.
The graph is plotted and the necessary calculations are performed.
Code
import matplotlib.pyplot as plt
import math
import numpy as np
#declare an empty array for all the parameters
line_count=1
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=[]
#checking the compatibility
check = (input(\'Input the file name: \'))
#checking condition
if check.endswith(\'out\') is True:
for line in open(check):
if \'#\' not in line:
Crank.append(float(line.split()[0]))
Pressure.append(float(line.split()[1]))
Max_Pres.append(float(line.split()[2]))
Min_Pres.append(float(line.split()[3]))
Mean_Temp.append(float(line.split()[4]))
Max_Temp.append(float(line.split()[5]))
Min_Temp.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]))
Kin_Visc.append(float(line.split()[15]))
Dyn_Visc.append(float(line.split()[16]))
#Declaring an array p for storing all the paramters
p=([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])
q=int(input(\"Enter the col. number for x-coordinate:\"))
r=int(input(\"Enter the col. number for y-coordinate:\"))
plt.plot(p[q],p[r], color = \'blue\', linewidth = \'2\')
#Declaring an array for splitting the line for the parameters
sp=[]
line_count = 1
for line in open(check,\'r\'):
if \"#\" in line:
if line_count is 3: # Splitting the third line since all the parameters are present
l=(line.split()[1:18])
sp.append(l)
line_count = line_count+1 #incrementing the count
else:
print(\'File not recognized. Please provide a valid CONVERGE output file\')
plt.xlabel(sp[0][q])
plt.ylabel(sp[0][r])
plt.show()
#for area under tbe graph
A =np.trapz(p[1],p[7])
print(\'Area under the curve\',A)
p1 = A * 1500/60 *1000
P = p1 /0.746
print(\'HP is\',P)
print(\'Power in kw is\',p1)
Result
Output