Challenge

Data analysis - python script to extract useful information from CONVERGE output file for engine analysis

Aim: To write a python script to extract useful information from CONVERGE output file for engine analysis

Python Script:

"""
    File parsing and Data visualization using Python
"""

import numpy as np
import matplotlib.pyplot as plt

# File validation and extracting column names and units
line_count = 1
for line in open('engine_data.out','r'):
    if line_count == 1:
        if 'CONVERGE' not in line:
            print('File not recognized. Please provide a valid CONVERGE output file')
            exit()
    if line_count == 3:
        column_names = line.split()
    if line_count == 4:
        column_units = line.split()
    line_count += 1

# Printing Found data details
print('Data Found:')
for i in range(1,len(column_names)):
    print(str(i)+' - '+column_names[i]+column_units[i])

# Inputs
i = int(input('Enter column number for x-axis: '))
j = int(input('Enter column number for y-axis: '))

# Extract data for given inputs
x = []
y = []
for line in open('engine_data.out'):
    if '#' not in line:
        x.append(float(line.split()[i-1]))
        y.append(float(line.split()[j-1]))

# plot extracted data and save as png
plt.figure()
plt.plot(x,y)
plt.xlabel(column_names[i]+column_units[i])
plt.ylabel(column_names[j]+column_units[j])
plt.title(column_names[j]+'_vs_'+column_names[i])
plt.savefig(column_names[j]+'_vs_'+column_names[i])

#Basic performance calulations
#Extracting pressure and volume data
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 under PV Curve
Area = np.trapz(pressure,volume) * 1e+6
print('Area under PV curve(Work done) : '+str(Area) + ' J')
# Power calculation
RPM = 1500
power = Area*1500/(2*60)
print('Power output of Engine : '+str(power)+' W')
#specific fuel consumption calculation
fuel_consumed = 20e-6 #gram
sfc = fuel_consumed*3600/power
print('Specific fuel consumption : '+str(sfc)+' kg/KWh')

line_out is used to keep track of the number of line. For compatability check if statement is used in for loop. If first line doesn't contains the word 'CONVERGE' then it prints a message that 'File not recognized. Please provide a valid CONVERGE output file'. The data from the file is read line by line to extract column names and units information. The values are stored in arrays under suitable names. Found data details, column number, column name and units, are then printed.

Input() function is used to take column number of interest from the user. The data is extracted from the file as earlier according to user input and a plot is made and saved under a suitable name as png. The plot is named and labelled automatically by extarcting data from column_names.

To make basic performnace calculations, pressure and volume data is extracted. The area under PV curve is calculated by using np.trapz function. This function does trapezoidal integration for given values. The power is calculated by multiplying area(work done) with cycles per seconds. For 1500rpm, number of cycle comes out to be 750/min as it takes 2 rotations to complete one cycle. Thus cycles per second = 150/60. The specific fuel consumption is calculated by the formulae and the values are printed using print function.

Output:

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.