Challenge

Week 6 - Data analysis

AIM: From the given file “engine_data.out”, All the data inside the file has to be read and some task to be performed by using tha
data inside the file, with PYTHON programming language.

OBJECTIVE:

Task -1: The PYTHON 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"

Task-2: The PYTHON code should take column numbers as the input and plot the respective columns as separate images
and each file should be saved by the name of the column. This should not be done manually.

Task-3: The PYTHON code to calculate the area under the P-V diagram. P is in column 2 and V is in column 8

Task-4: Calculate the power output of this engine. Assume that RPM is 1500

Task-5: This engine consumed 20 micrograms of fuel (per 1 stroke cycle). Calculate its specific fuel consumption.

Program:-

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

colomData_1= []
colomData_2=[]
Units=[]
properties = []

A= input('Input a file name: ')
if A == 'engine_data.out':
 print('Ok, valid file')
else:
 print('File not recognized. Please provide a valid CONVERGE output file')
 exit()

a = input ("Enter the first column index value: ")
b = input ("Enter the second column index value: ")
a= int(a)
b= int(b)

line_count =1
for line in open(A):

 line_count = line_count + 1
 if line_count == 4:
  properties.append(line.split())
  P1 = (line.split()[a])
  P2 = (line.split()[b])

 if line_count == 5:
  Units.append(line.split())
  U1 = (line.split()[a])
  U2 = (line.split()[b])

 if '#' not in line:
  colomData_1.append(float(line.split()[a-1]))
  colomData_2.append(float(line.split()[b-1]))

# filename = 'property%04d.png' % line_count
plt.figure(line_count)
plt.plot(colomData_1, colomData_2, linewidth =3)
plt.xlabel(P1 + U1)
plt.ylabel(P2 + U2)
plt.savefig((P1 + U1)+' VS '+(P2 + U2)+'.PNG')
plt.show()


# Calculate the area under the P-V diagram

pressure= []
volume=[]
for line in open('engine_data.out'):
 if '#' not in line:
  pressure.append(float(line.split()[1]))
  volume.append(float(line.split()[7]))

Area= np.trapz(pressure,volume)* pow(10,6)

print(Area)

# Calculate the power output of this engine
RPM = 1500
Power = Area * (RPM/60)
Fuel_mass = 20 * pow(10,-6)

# Calculate its specific fuel consumption
Specific_fuel_cons= Fuel_mass/ Power
print('Workdone in Joules = ', Area)
print('Power in Watt = ', Power)
print('Specific fuel consumption in gm/w hr= ',Specific_fuel_cons)

Explanation:-
1)For Compatability check, the file should match with the main file so we take that input as a string and match it with the if else
loop
2)The a and b as integer inputs to use later.
3)We start reading file A after opening it in for loop.
4)In this, we use 3 if conditions in which we save the line of unit and properties in an array and append them into an empty
array.
5)when we split the line it comes in form of an array.
6)from this, I can get any column data of that row/line just by indexing the required value
7)As the crank angle has 1 indexing, pressure has 2 like this we can get any data we want.
8)convert that data into floating-point numbers as it might be a string.
9)Add this to my crank array.
10)Now, save the file name and plot figure.
11)We calculated the below area, power, etc by simply defining the formula in python.
12)At last, we print all of them.

Output:-

Error throw for Invalid file

To change the compability

CONCLUSION:
Hence, the large amount of data stored in a file, can easily studied, compared and analysed, using PYTHON programming
language.

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.