Project

File Parsing and data analysis using python

Objective: To create a data visualiser using python, perform a compatibility check of the file and then calculating some basic performance parameters

Problem Statement:

To visualise the complex data in the file in a sequencial and a more understandable way. Also, how can SublimeREPL adds a more two way relationship in python

Prerequisites:

1) The link for the converge file is given below:

https://drive.google.com/file/d/1L8GY56d-M8mB1KfceM-xVhGNvnCIqxjm/view

2) SublimeREPL must be installed if running the script on sublime and user inputs need to be taken.

Procedure:

  • Requisite variables and lists are initialised
  • Then, the input values are initialised which asks for the values of file name which is to be parsed, and also 2 parameters between which the relationship is to be analysed
  • If the file inputted by the user is compatible, the solver proceeds to the next step. Otherwise, it gives a predefined error message.
  • Afterthat, the file is read using the open command and is splitted in between the columns
  • The user input value then helps in selecting the required columns and then stores them in the predefined empty lists.
  • And then, they are plotted on the x-y graph
  • The x and y labels are taken from the file only
  • And finally, the basic performance parameters are calculated.

The detailed code is given below:

import math
import numpy as np
import matplotlib.pyplot as plt

#initialising empty arrays to store data for the columns to be plotted
value1=[]
value2=[]
volume=[]
pressure=[]
#defining a line counter 
linecount=1

#enter the name of the converge output file in name.out format
open1=('Enter file name in name.out format: ')
file=input(open1)

#taking user inputs for variables to be plotted and storing them in int form
print('List of parameters available for plotting:')
print('0. Crank Angle')
print('1. Pressure')
print('2. Max Pressure')
print('3. Min Pressure')
print('4. Mean Temperature')
print('5. Max Temperature')
print('6. Min Temperature')
print('7. Volume')
print('8. Mass')
print('9. Density')
print('10. Integrated HR')
print('11. HR Rate')
print('12. Cp')
print('13. Cv')
print('14. Gamma')
print('15. Kinematic Viscosity')
print('16. Dynamic Viscosity')
par_a=('Enter parameter 1 no (x-axis variable): ')
a=input(par_a)
a=int(a)
par_b=('Enter parameter 2 no (y-axis variable): ')
b=input(par_b)
b=int(b)

try:

	#opening and reading the data file and storing values of the selected columns inside 2 variables
	for line in open(file,'r'):
		if '#' not in line:
			value1.append(float(line.split()[a]))
			value2.append(float(line.split()[b]))
			pressure.append(float(line.split()[1]))
			volume.append(float(line.split()[7]))
		else:
			#this is used to take the xlabel and ylabel from the data file itself
			if linecount==3:
				labels=line.split()
			linecount=linecount+1

	#calculating the area under the P-V diagram using trapz(y,x)
	area=np.trapz(pressure,volume)
	print('Area under the P-V diagram: ',area,'MJ')

	#calculating the power output of the engine (assuming a RPM of 1500 and 4-stroke)
	power=area*(1500/120)*1000
	print('Power: ',power,'KW')

	#calculating the engine specific fuel consumption (assuming it consumes 20gm of fuel in one stroke)
	sfc= ((20*(1500/120)*3600)/pow(10,9))/power
	print('Specific Fuel Consumption: ',sfc,'Kg/KW.H')
				
	#plotting the graph between the 2 selected columns
	plt.plot(value1,value2)
	plt.xlabel(labels[a+1])
	plt.ylabel(labels[b+1])
	plt.show()

except:
	#if wrong filename is given as input
	print('File not recognized. Please provide a valid CONVERGE output file')	

Results:

Examples:

a) When 7 and 1 are taken as input parameters

b) When 1 and 4 are taken as input parameters

Compatibility Check When the input program is invalid:

Performance Parameters:

Discussion:

It can be inferred from the project that python acts as a very good tool for file parsing and data analysis in some very complex scenarios too.

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.