Week 6 - Data analysis
Aim:- To analyse data using Python
Objective:-
1.Visualie data for plotting plots
2.Generating names for plot automatically according to parameter no.
3.Calculating basic performances( area,work done, specific fuel consumption)
Solution Procedure:-
1.Used Python coding language
2.imported needed libraries in python
3.using try command correct file opened or not is checked and according to that output printed
4.Parameters are assigned in data file
5.Users are allowed to input parameter for which want to calculate performane
6.Defined empty arrays to store values of parameter
7.Commands written to generate plot
8.Commands written to calculate peformances using formulaes.
# -*- coding: utf-8 -*-
"""
data Analysis and file parsing
"""
## Importing modules
import matplotlib.pyplot as plt
from scipy.integrate import simps ## importing sims function .used to calculate area
import numpy as np
## basic intialization
row_no=0 ## defining starting line count
row_count=[]
for parameter in open('engine_data.out'):
if '#' not in parameter:
row_count.append(parameter.split()[3])
column_count=len(parameter.split()) ## to calculate no. of columns in file
## defining empty arrays to store parameters in file
try:
data =open('engine_data.out')
print('File opened sucessfully') ## to show the output if correct format file slected
except:
print('File not recgonized.Please provide a valide CONVERGE output file') ## If file is not CONVERGE file
parameters=['1-Crnak Angle','2-Pressure','3-Maximum Pressure','4-Minimum Pressure','5-Mean Temperature','6-Maximum Temperature','7-Minimum Temperature','8-Volume','9-Mass','10-Density','11-Heat Rejection','12-Heat Rate','13-Specific heat','14-Specific volume','15-Gamma','16-Kinematic Viscosity','17-Dynamic Viscosity'] ## defining names and serial no. for parameters
print('parameters are:',parameters)
first_parameter=input('Enter the no. of first parameter that you want to plot :') ## asked user to enter first_parameter
second_parameter=input('Enter the no. of second parameter that you want to plot :')
first_parameter=int(first_parameter) ## values are converted to ineger
a=str(first_parameter) ## converting to strng to use it for plot saving command
second_parameter=int(second_parameter)
b=str(second_parameter)
value_first_parameter=[] ## defining empty arrays to store values of parameters
value_second_parameter=[]
## file parsing
for parameter in open('engine_data.out'): ## defining open the data in engine_data file and store in parameter variable
if '#' not in parameter:## defining not to consider # stareted lines in data file
column_no=len(parameter.split())
value_first_parameter.append(float(parameter.split()[first_parameter-1])) ## command to split the data in parameter by commas and assign the value at to empty array
value_second_parameter.append(float(parameter.split()[second_parameter-1]))
row_no=row_no+1 ## to append the row no. one by one
##Plots
plot_name= a + 'vs'+ b+ '.png' ## plot name format
plt.plot(value_second_parameter,value_first_parameter,linewidth=3)
plt.xlabel(parameters[second_parameter-1])
plt.ylabel(parameters[first_parameter-1])
plt.show()
plt.savefig(plot_name)
## Area under curve(Work done) calculation
area=float(simps(value_first_parameter,value_second_parameter))
print('area=',area)
##Power Calculation
rpm=1500 ## Given in problem
speed=(rpm/60)
power=(area*speed)
print('Power=',power)
## Specific fuel Consumption
Mass_of_fuel=(20*pow(10,-6))
specific_fuel_consumption=(Mass_of_fuel/power)
print('Specific fuel consumption=',specific_fuel_consumption)
Plot:
2 Vs 8 Parameter (pressure vs volume)
2 vs 6
Screenshots: