Challenge

Week 6 - Data analysis

FILE ANALYSIS USING PYTHON

AIM: Parsing a data file using Python and calculating various performance parameters

OBJECTIVE:

  1. Obtaining the data points for each perameters using data parsing techniques
  2. Plotting the graph between two parameters as per user requirements
  3. Optimizing the code by preventing it from getting blown if the target file is not found
  4. Calculating parameters like Work done, power output and specific fuel consumption

PROBLEM STATEMENT:

The scripts are quite commonly used in companies for data analysis, and comparing the data for various parameters, and helps us to reduce lot of time by implementing such parsing techniques. Therefore we are writing a code to extract useful data points from the target file.

EQUATIONS USED:

`"Power output ="A*n*10^6" W"`

A = area under the curve

`n=N/(2*60)`

N = revolutions per minute

`SFC"(Specific Fuel consumption)" ="Fuel consumed in kg/hr"/"Power output in kW"`

** The sample file cound be downloaded here

CODE AND STEP-WISE EXPLAINATION:

"""
File Parsing using python
"""
# importing modules
import matplotlib.pyplot as plt
from scipy.integrate import simps
# creating a file handle
# setting up a compatability check
try:
    fh = open('engine_data.out')
    fh1 = open('engine_data.out')
    fh2 = open('engine_data.out')
except FileNotFoundError:
    print("File not recognized. Please provide a valid CONVERGE output file")
    exit()

# extracting the values for parameters in a array
parameters = []
for lines in fh:
    if not lines.startswith('#          C'): continue
    para = lines.split()
    parameters.extend(para[1:])

# extracting the units for parameters in a array
units = []
for lines in fh1:
    if not lines.startswith('#          ('): continue
    unit = lines.split()
    units.extend(unit[1:])


# inputs for the columns to be extracted
print(' enter the numbers between 1 - 17')
col1 = int(input('Enter the dependant column number[0-17]: '))
col2 = int(input('Enter the in-dependant column number[0-17]:'))

# array for the extracted data
xdata = []
ydata = []


# function to extract all data for each parameters
def plots(col1, col2):
    for data in fh2:
        if data.startswith('#'): continue
        words = data.split()
        xdata.append(float(words[col1-1]))
        ydata.append(float(words[col2-1]))
    return xdata, ydata


# plotting the plot for given number of columns
# and giving appropriate labels and title
xdata, ydata = plots(col1, col2)
plt.plot(xdata, ydata)
plt.xlabel(parameters[col1-1] + units[col1-1])
plt.ylabel(parameters[col2-1] + units[col2-1])
plt.title(parameters[col2-1] +' VS '+ parameters[col1-1] + ' Characterictics')
plt.savefig(parameters[col2-1]+' VS '+parameters[col1-1] + '.png')
plt.show()

"""
Basic Performance Calculations
"""
# area under p-v curve
vol, pres = plots(8, 2) # vol col is 8 and pres col is 2
area = simps(pres, vol, even='First') * pow(10,6)
print('Area under the curve(Work done)= ',area ,'J')

# Power output
RPM = 1500
# number of cycles/sec for 4-s engine
n = RPM/120
P = area * n
print('Power output at',RPM, 'RPM is',P,'W')

# specific-fuel consumption
f = 20  # amt of fuel consumed
f = f*n*3600/pow(10, 6)  # fuel consumption in g/hr
# sfc = fuel consumption(g/J) / P (W)
sfc = f/P   # in g per joules
print('The Sfc is', sfc, 'g/J')

RESULTS AND DISCUSSION:

1) Compatability check

Hence as shown in the above image the program doesn’t throws an error if a invalid input is given instead it displays an error and peacefully exits the code

2)Data Visualizer:

Hence the plots for requested column numbers is displayed as the output with title and labels allocated automatically

They are also saved in the folder with appropriate names:

3) Performance calculations

Hence we have calculated various performance parameters using the equations specified under the "EQUATIONS USED" section

CONCLUSION:

  1. We have parsed the data file using a smart techniques which makes the task easier , simpler and more sophisticated
  2. We could also compare the various data characteristics we want by just entering the column number
  3. We also calculated the performance characteristics for the engine which helps us analysing its efficiency and performance
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.