Challenge

Week 6 - Data analysis

Data analysis

Aim:-

Write a program to demostrating file parsing in python (data analysis)

Data visualizer

  • Your script should take column numbers as the input and plot the respective columns as separate images
  • Each file should be saved by the name of the column
  • The plot labels should be extracted from the file. If, I request for a plot between column 1 (crank angle) and column 8(volume), then the label information should automatically be extracted and must appear as labels in the plots. THIS SHOULD NOT BE DONE MANUALLY

Compatability check

  • You code should exit gracefully, if a non-compatible file is provided as an input. It should say something like "File not recognized. Please provide a valid CONVERGE output file"

Basic performance calculation

  • Calculate the area under the P-V diagram. P is in column 2 and V is in column 8.
  • Calculate the power output of this engine. Assume that RPM is 1500
  • This engine consumed 20 micro grams of fuel (per 1 stroke cycle). Calculate its specific fuel consumption.

Data Analysis in Python

Python is an increasingly popular tool for data analysis. In recent years, a number of libraries have reached maturity, allowing R and Stata users to take advantage of the beauty, flexibility, and performance of Python without sacrificing the functionality these older programs have accumulated over the years.

This site is designed to offer an introduction to Python specifically tailored for social scientists and people doing applied data analysis – users with little or no serious programming experience who just want to get things done, and who have experience with programs like R and Stata but are anxious for something better.

Data analysis is carried out by extracting the data from the file and plot the respective curve by taking the input from the user the independent variable and independent variable the program automatically extracting the column name and label in pv curve diagram.

Data extraction is a process that involves retrieval of data from various sources. Frequently, companies extract data in order to process it further, migrate the data to a data repository (such as a data warehouse or a data lake) or to further analyze it.

Data visualization is the graphical representation of data It involves producing images that communicate relationships among the represented data to viewers of the images. This communication is achieved through the use of a systematic mapping between graphic marks and data values in the creation of the visualization. This mapping establishes how data values will be represented visually, determining how and to what extent a property of a graphic mark, such as size or color, will change to reflect changes in the value of a datum.

Performance

Pv diagram area under the pv curve is calculate using the trapezoidal rule

that is

Area under the pv diagram is eaqual to work done

Work done are calculating using the power formulae,

Power = Work * speed

specific fuel consuption = mass of the fuel consuption per hr/power developed in kw

Programming

#Data Analysis
import matplotlib.pyplot as plt
import numpy as np
import sys
import math

#Opening the file
try:

f = open('engine_data.out','r')
except FileNotFoundError:
print('File not recognized. please provide a valid converge output file')
sys.exit(1)

value = []

#Reading from file and assigning value to arrays
for line in f:
if '#' not in line:
values = line.split()

value.append(values)


col1 = np.transpose(value)
col1 = col1.astype(np.float)

#Area under PV Diagram using Trapezoidal rule

xvar = col1[7]

dx = []
k = 0
while k < 8664:

dif = xvar[k+1] - xvar[k]
dx.append(dif)
k = k+1

w = []
work = 0
t = 0
while t < 8664:
w.append(((dx[t])/2)*2(yvar[0]+2*(yvar[1+1])+yvar[8664]))


t = t+1


for n in range(0,len(w)):
work = work+w[n]

#Work, Power and Specific fuel consumption calculation and output

work = work*1000000
print('power output in watts is :')
power = (work*2*1500*math.pi*0.015)/60
print(abs(bsfc))

name = ['Crank','Pressure','Max_Pres','Min_Pres','Mean_Temp','Max_Temp','Min_Temp','Volume','Mass','Density','Integrated _HR','HR_Rate','C_p','C_v','Gamma','Dyn_Visc']
print('Press \n 1 for Crank \n 2 Pressure \n 3 for Max_Pres \n 4 for Min_Pres \n 5 fpr Mean_Temp \n 6 for Max_Temp \n 7 for Min_Temp \n 8 for Volume \n 9 for Mass \n 10 for Density \n 11 for Integrated_HR \n 12 for HR_Rate \n 13 for C_p \n 14 for C_v \n 15 for Gamma \n 16 for Kin_Visc \n 17 for Dyn_Visc')
x-axis = int(input('Enter number corresponding to value you want to plot on x-axis & Enter \n')
y-axis = int(input('Enter number corresponding to value you want to plot on y-axis & Enter \n')

#Plot the input provided by the user

plt.figure(1)
plt.plot(col1[x-1],col1[y-1])
plt.title(name[y-1]+'&'+name[x-1]+' plot',fontsize = 20,color = 'red')
plt.xlabel(name[x-1],fontsize = 11)
plt.ylabel(name[y-1],fontsize = 11)
plt.savefig(name[x-1]+' vs ' +name[y-1]+ '.png')
plt.show()


#plot p-v diagram

plt.figure(2)
plt.plot(col1[7],col1[1])
plt.title('P-V diagram ',fontsize = 18,color = 'red')
plt.xlabel('Volume',fontsize = 11)
plt.ylabel('Pressure',fontsize = 11)
plt.show()

Explaination:-

1)Import the all the required important data

2)f = open('engine_data.out','r') use to this command open and read the file

3)try command use to check the compatibility of file

4)Using the except commond to display the error

5)print command use to print the file

6)value = [] is use to empty array to store the value

7)Reading from file and assigning value to arrays and split.line command use to seperate the value.

8)Area under PV Diagram using Trapezoidal rule in this case converted string into array usin append and also here using while and for loop

9)Work, Power and Specific fuel consumption calculation and output using a basic formulae.

\n is use to take the space.

10)plt.plot is use to plot the graph, plt.title use to title the graph, plt.x,ylabel use to label the graph and plt.show() use to show the graph.

Result

plot result

Pressure vs crank

Temperature vs crank

pressure vs volume

Result screenshort value

conclusion

We are successfully analied the data analysis

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.