Challenge

Week 6 - Data analysis

AIM: To analyse the data of the input file and perfrom the follwoing tasks

  • Data Visualizer
  • Compatibilty Check
  • Basic Perfomance Calculation

Theory:

The above mentions tasks are completed using the python software and some of the modules like math, scipy, matplotlib. Here, we are only to give the input as per the choice but not the manula coading to get the required outputs.

Compatibilty Check: Here the input file should be checked whether it is the proper converge file or not else the code should be terminated stating to check for the proper file to be given as input.

Data Visualizer: Here the data from the read file is to be plotted as graphs and the data to be read should be given as an input command to read a specific information for plotting. The output should be the plot of the required and given input parameters.

Basic Performance Calculation: Here the area under PV diagram, power and specific fuel consumption of the given engine data it to be calculated, where the speed(N)=1500rpm, mass of the fuel=20micrograms/stroke.
For the area calculation the simps funtion from scipy.integrate module is to be used.

The following Equations would help for the above calculations

`A=PV`= Work done in MJ

`n=N/(2*60)` in number of cycles per second

`Power=A.n.10^3` in KW

to convert the m to kg/hr `rArr dot m=(f*n*3600)/10^9`, where is f is in microgram/stroke

specific fuel consumption`=dotm/(power` in kg/KW.hr

Implementation:

Initially the filenamae is taken as an input(input always stores the information as string (str) type) which is opened and by using the f.readline() each line gets read. This f.readline() advances to the next line as the number of times it is used i.e. it goes to the next line automatically based on the number of times called in the code. Using the if - else conditional statements checking the right file by searching for the string 'CONVERGE', there by the compatibility test is performed. sys module is used to exit from the code if the file is not of the proper type.
***It is important that the any file name given as input should be in the same location as that of the code else the code gets terminated stating an error.

For data visualizer, initially the parameters in the file are displayed and their indexes in order to split the data and append that data to the empty arrays so that these arrays can be used to plot the graphs using the matplotlin.pyplot modules. The index values are taken as an input and then converted to int type from str inorder to index the right column. The readline() function is used to read the line from the file and then convert the required line of the parameter names to a list. As it inclues # as an element it is deleted using the del.parameters[0] from the list. Then indexed as per the input inorder to have the labels for the axis as per the requirement and then the file is closed after the use.

For basic calculations, the file is again opened now with a fresh code of indexing to the required parameters of the Volume and Pressure to find the area under the PV diagram. To find the area simps function is used to integrate using samples along the given axis and the composite Simpson’s rule. There by this value is used to find the power and there by the specific fuel consumption as per the above equations and the values are printed along with the units. It is stated to use the RPM as 1500 and mass of fuel as 20micrograms/stroke and the concersions are made as per the requirement for the equivalence.

The following is the code for the above stated problem and explanation

import math
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import simps
import sys

#checking the compatibility of the input file
filename=input('enter filename with .out extension ')
f=open(filename,'r')
line=f.readline()
if 'CONVERGE' in line:
	print('perfect CONVERGE file\n')
else:
	print('File not recognized. Please provide a valid CONVERGE output file')
	sys.exit()


#data visualizer 
print('\nThe following are the indexed value for the plots to be made')
print('0-Crank_angle 1-Pressure 2-Max_pressure 3- min_pressure 4-mean_temperature 5-max_temperature 6-min_temperature 7-volume 8-mass 9-density 10-integrated_HR 11-HR_rate 12-cp 13-cv 14-gamma 15-kinematic_viscosity 16-dynamic_viscosity')
line_count=1
column_1=[]
column_2=[]
x=int(input('\nenter column number for x axis:'))
y=int(input('\nenter column number for y axis:'))
#loop for seperating the columns and append the required information
for line in open(filename):
	if '#' not in line:
		column_1.append(float(line.split()[x]))
		column_2.append(float(line.split()[y]))
		line_count=line_count+1
#parameter array in order to label the axis
line1=f.readline() #to skip the line
line2=f.readline()
string=(str(line2.split()))
parameters=list(string.split(','))
del parameters[0]
print('the respective plot between',parameters[x],'and',parameters[y],'is shown\n')
#plotting
plt.plot(column_1,column_2)
plt.xlabel(parameters[x])
plt.ylabel(parameters[y])

f.close()
#Basic performance calculation
pressure=[]
volume=[]
for line in open(filename):
	if '#' not in line:
		pressure.append(float(line.split()[1]))
		volume.append(float(line.split()[7]))
area=float(simps(pressure,volume))
print('area under the PV diagram =',area,'MJ\n')
#rpm = 1500
N=1500 
n=N/(2*60)  	#number of cycles per second
p=area*n*pow(10,3)  #results in KW
print('power=',p,'KW\n')
m=20 #mass of fuel in microgram/1stroke of cyle
mf=m*n*3600/pow(10,9) #converting to kg/hr from microgram/stroke
#specific fuel consumption
sfc=mf/p
print('specific fuel consumption=',sfc,'kg/KW.hr')
f.close()
plt.show()

Outputs:

The following is the plotted graph from the code

The above is the graph for the volume vs pressure as per the inputs given above.

Problem faced:

As in sublime it cannot be executed simply and when the code is ran normally the console wouldn't take the input values. So inorder to get the problem solved we need to use the sublimeREPL as shown below. To install the pack the following link of the video would be helpful https://www.youtube.com/watch?v=R5-niid0m8A

Conclusion:

The requirements weremet and the plotting is done as per the given inputs as required.

References:

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.