Week 6 - Data analysis
PROJECT REPORT
DATA ANALYSIS USING PYTHON
AIM :
To write a Python code to read data from a file containing engine's data and create a data visualizer tool. The programme must also find out power output and the specefic fuel consumption of the engine by plotting the P-V diagram of the engine cycle.
PYTHON CODE :
#Data_Analysis_using_python
import matplotlib.pyplot as plt
from scipy.integrate import simps
line_count = 1
try:
file = open('engine_data.out')
print('file opened sucessfully \n')
except:
print('file does not exist \n')
print('The plot parameters 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-Cp, 14-Cv, 15-Gamma, 16-Kin_Vics, 17-Dyn_Vics')
first_column = input('Enter the 1st column number for which you want a plot (Choose a number between 1(include) and 17(include)):')
second_column = input('Enter the 2nd column number for the plot(please choose different column from column_number_1):')
print('\n')
first_column = int(first_column)
second_column = int(second_column)
values_of_column_1 = []
values_of_column_2 = []
for line in open('engine_data.out'):
if line_count is 3:
column_name_1 = line.split()[first_column]
column_name_2 = line.split()[second_column]
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
#Area under curve that is work done
area = float(simps(values_of_column_1, values_of_column_2))
print('Area:{}\n'.format(area))
rpm = 1500
speed = rpm/60
power = area*speed
print('Power:{}\n'.format(power))
mass_of_fuel = 20*pow(10,-6)
specefic_fuel_consumption = mass_of_fuel/power
print('specefic_fuel_consumption:{}\n'.format(specefic_fuel_consumption))
#Plotting
plt.plot(values_of_column_2, values_of_column_1)
plt.xlabel(column_name_1)
plt.ylabel(column_name_2)
print(' {} vs {}'.format(column_name_1, column_name_2))
plt.show()
RESULTS :
1. User Input parameters
Column 1 = 2 (Pressure) and Column 2 = 8 (Volume)
2. Calculated Area under P-V Diagram and power of the engine
3. Pressure vs Volume plot
4. Other important plots
1. Pressure vs Crank
2. Mean Temperature vs Pressure
3. Dynamic Viscosity vs Kinematic Viscosity
4. Volume vs Crank
and we can have many more plots.
CONCLUSION :
The above python code is capable of generating plots between different parameters of the data file and able to calculate area under the curve and power of the engine.