Week 6 - Data analysis
AIM: To write a script that does data analysis on python.
OBJECTIVE :
- Compatibility Check with code should exist gracefully if a non-compatible file is provided as an input.
- Visualising the data, to plot a graph between any two quantities according to the user's input.
- To calculate basic engine performance calculations.
INTRODUCTION :
Data analysis is a process of inspecting, cleansing, transforming and modelling data to find useful information, inform judgments and supporting decision-making. Data analysis has multiple aspects and approaches, incorporating diverse techniques under a variety of names, and is used in different business, science, and social science domains. In today's business world, data analysis plays a role in making decisions more scientific and helping businesses operate more effectively.
Data analysis is a somewhat abstract concept to understand without the help of examples. So to better explain how and why data analysis is important for businesses, here are the 4 types of data analysis and examples of each.
- Descriptive Analysis: Descriptive data analysis looks at past data and tells what passed. This is often used when tracking Key Performance Indicators (KPIs), revenue, sales leads, and more.
- Diagnostic Analysis: Diagnostic data analysis aims to determine why something happened. Once your descriptive analysis shows that something negative or positive happened, diagnostic analysis can be done to figure out the reason. A business may see that leads increased in October and use diagnostic analysis to determine which marketing efforts contributed the most.
- Predictive Analysis: Predictive data analysis predicts what is likely to happen in the future. In this type of research, trends are derived from past data which are then used to form predictions. For example, to predict next year’s revenue, data from previous years will be analyzed. If revenue has gone up 20% every year for many years, we would predict that revenue next year will be 20% higher than this year. This is a simple example, but predictive analytics can be applied to much more complicated issues such as risk assessment, sales forecasting, or qualifying leads.
- Prescriptive Analysis: Prescriptive data analysis combines the information found from the earlier 3 types of data analysis and forms a plan of action for the organization to face the issue or decision. This is where data-driven choices are made.
These 4 types of data analysis can be applied to any issue with data related to it.
Python Program
"""
A program to calculate engine parameters and to plot a graph between two quantites according to user input
"""
import math as mt
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import simps
# Compatability check
try:
data = open('engine_data.out','r')
except FileNotFoundError:
print('"File not recognized. Please provide a valid output file"')
line_temp=[]
line_count = 1
for line in open ('engine_data.out'):
if line_count == 2:
line_temp=(line.split())
number=[]
for i in range (2,len(line_temp)):
number.append(line_temp[i])
if line_count == 3:
line_temp=(line.split())
parameter=[]
for i in range (1,len(line_temp)):
parameter.append(line_temp[i])
if line_count == 4:
line_temp=(line.split())
units=[]
for i in range (1,len(line_temp)):
units.append(line_temp[i])
if line_count == 5:
print("\nThe following are the parameter recognized from the engine_data.out")
for i in range(0,len(number)):
print((number[i]),'.) ',parameter[i],units[i])
line_count = line_count + 1
#Creating API
print('\nEnter the serial number of the parameter as listed in above to find plot relation')
first_column=input('Enter the first parameter :')
second_column=input('Enter the second parameter :')
first_column=int(first_column)
second_column=int(second_column)
# loding parameters names and there units as user preferences
P1=parameter[first_column-1]
P2=parameter[second_column-1]
U1=units[first_column-1]
U2=units[second_column-1]
values_of_column_1=[]
values_of_column_2=[]
for line in open('engine_data.out'):
if'#' not in line:
values_of_column_1.append(float(line.split()[first_column-1]))
values_of_column_2.append(float(line.split()[second_column-1]))
line_count+=1
# Plotting between two parameters with label and title
plt.plot(values_of_column_2,values_of_column_1 ,linewidth=3,color='red')
plt.xlabel(P2+''+U2,color='green',fontsize=12)
plt.ylabel(P1+''+U1,color='green',fontsize=12)
plt.title(P1+''+U1+' V/S '+P2+''+U2,color='b',fontsize=15)
plt.savefig(P1+'VS'+P2+'.png')
plt.show()
# For calculation of area, power, specific fuel consumption
if first_column==2 and second_column==8:
area=float(simps(values_of_column_1, values_of_column_2))
print('\nArea under the curve :',abs(area),'m^3')
rpm=1500
rps=rpm/60
power=area*rps*1000/2
print('\nPower from the engine at 1500 RPM :',power,'kW')
mass_of_fuel = 20*pow(10,-6)*.5*3600
specific_fuel_consumption=mass_of_fuel/(power)
print('\nEngine consumed 20 micro grams of fuel (per 1 stroke cycle)\nthen Specific fuel consumption :', specific_fuel_consumption,'(kg/hr)/KW')
Output
For pressure and volume diagram and area under it and power produced from engine and SFC.
The following are the parameter recognized from the engine_data.out
1 .) Crank (DEG)
2 .) Pressure (MPa)
3 .) Max_Pres (MPa)
4 .) Min_Pres (MPa)
5 .) Mean_Temp (K)
6 .) Max_Temp (K)
7 .) Min_Temp (K)
8 .) Volume (m^3)
9 .) Mass (kg)
10 .) Density (kg/m^3)
11 .) Integrated_HR (J)
12 .) HR_Rate (J/time)
13 .) C_p (J/kg-K)
14 .) C_v (J/kg-K)
15 .) Gamma (none)
16 .) Kin_Visc (m^2/s)
17 .) Dyn_Visc (N*s/m^2)
Enter the serial number of the parameter as listed in above to find plot relation
Enter the first parameter :2
Enter the second parameter :8
Area under the curve : 0.5005864474262364 kJ
Power from the engine at 1500 RPM : 6.257330592827954 kW
Engine consumed 20 micro grams of fuel (per 1 stroke cycle)
then Specific fuel consumption : 0.005753252040296957 (kg/hr)/KW
>>>
Plot between pressure and Volume

Plot between Crank and Mean Temperature
The following are the parameter recognized from the engine_data.out
1 .) Crank (DEG)
2 .) Pressure (MPa)
3 .) Max_Pres (MPa)
4 .) Min_Pres (MPa)
5 .) Mean_Temp (K)
6 .) Max_Temp (K)
7 .) Min_Temp (K)
8 .) Volume (m^3)
9 .) Mass (kg)
10 .) Density (kg/m^3)
11 .) Integrated_HR (J)
12 .) HR_Rate (J/time)
13 .) C_p (J/kg-K)
14 .) C_v (J/kg-K)
15 .) Gamma (none)
16 .) Kin_Visc (m^2/s)
17 .) Dyn_Visc (N*s/m^2)
Enter the serial number of the parameter as listed above to find plot relation
Enter the first parameter:1
Enter the second parameter:5

Plot between Crank and Volume

Plot between Crank and Pressure

If the engine_data file not found

Conclusion
Hence, the data analysis has been done and all the questions were answered