Challenge

Week 6 - Data analysis

1.AIM: Data analysis in python

2.OBJECTIVE: 1.Data visualization

  1. Compatibility check
  2. Basic performance calculation

3.BODY OF THE CONTENT:

MAIN CODE:

#This code is written in python

#File parsing in python
#Engine data analysis in python

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


#Compatability check
try:
	data = open('engine_data.out','r')
except FileNotFoundError:
	print('File not regonized, please put a valid file')


#Data visualizer

#Initialisation
value = []

#reading the data file
for line in data:
	if '#' not in line:
		value.append(line.split())

#Value array is transposed 
column = np.transpose(value)

#column array is cast into float
column = column.astype(float)

#Header of all the columns of the data file
parameters = ['Crank angle','Pressure','Maximum pressure','Minimum pressure','Mean temperature','Maximum pressure','Minimum temperature','Volume','Mass','Density','Heat rejection','Heat rejection rate','C_p','C_v','gamma','Kinematic viscosity','Dynamic viscosity']

#Instructions
print('The numerical code for the corresponding parameters are given below.\n Please follow the instructions')
print(parameters)

#Numerical code for the columns
numerical_code = ['Crank angle = 0','Pressure=1','Maximum pressure=2','Minimum pressure=3','Mean temperature=4','Maximum temperature=5','Minimum temperature=6','Volume=7','Mass=8','Density=9','Heat rejection=10','Heat rejection rate=11','C_p=12','C_v=13','gamma=14','Kinematic viscosity=15','Dynamic viscosity=16']
print(numerical_code)

#Inputs by the user
a = int(input('Please enter the numerical code for the independent variable: \n'))

b = int(input('Please enter the numerical code for the dependent variable: \n'))

#Plotting between the column
plt.plot(column[a,:],column[b,:],linewidth=3,color='green')
#Axes are named
plt.xlabel(parameters[a],color='red')
plt.ylabel(parameters[b],color='red')
#Title for the plot
plt.title(parameters[b]+'VS'+parameters[a])
plt.grid('true')
#Plot is saved in the current directory
plt.savefig(parameters[b]+'VS'+parameters[a]+'.png')
plt.show()


#Basic performance calculation
#Area under PV diagram
data = open('engine_data.out','r')
volume = []
pressure = []

for i in data:
	if '#' not in i:
		pressure.append(float(i.split()[1]))
		volume.append(float(i.split()[7]))

#Calculation of area
area = np.trapz(pressure,volume)
print('Total area under the PV diagram is:',area)

#Calculation of power output of the engine
#Inputs
rpm = 1500
#P = W*N*10^6/9550
power = area*rpm*1e+06/(9550)
print('The power output of the engine in Kilowatt is:',power)

#Calculation of specific fuel consumption
fuel_per_stroke = 20*1e-06
mass_flow_rate = 2.99*1e-10
specific_fuel_consumption = mass_flow_rate/power
print('The specific fuel consumption by the engine in gram per Kilowatt is:',specific_fuel_consumption)

EXPLANATION:

Compatibility check and data visualization:

  1. Importing the necessary libraries
  2. Then I have checked the compatibility by using try except command.
  3. Then I have started a for loop which will read the data inside the file.
  4. By using if command I have neglected the header line containing ‘#’.
  5. Then I have transform the rows into columns for calculations purposes.
  6. Then I have defined the parameters of the data file and also I have assigned the numerical code for each parameters.
  7. Then I took the input from the user.
  8. Then I have plotted the necessary graphs as the user will put the input.

Basic calculation:

  1. I have taken two empty arrays as volume and pressure for extraction of volume and pressure data.
  2. Then I have started a for loop which will extract the data and stores in the array.
  3. Then I have calculated the area under PV diagram by using trapz library.
  4. Again by using formula I have calculated the power output of the engine.
  5. By using formula I have calculated the specific fuel consumption by the engine.

4.OUTPUT:

COMPATIBILITY CHECK:

DATA VISUALIZATION:

I have plotted different plots by using different numerical codes:

BASIC PERFORMANCE CALCULATION:

5.ERRORS AND DEBUGGING: I have made some mistakes in the syntax.

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.