Challenge

Week 6 - Data analysis

Aim :To create a Data Visualizer Tool that does the following things.

Data Visualizer:

>Your script should take column numbers as the input and plot the respective columns as separate images.
>Each file should be saved by the name of the column.
>The plot labels should be extracted from the file. If, I request for a plot between column 1 (crank angle) and column 8(volume), then the label information should automatically be extracted and must appear as labels in the plots. THIS SHOULD NOT BE DONE MANUALLY.

Compatability Check:

Your 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".

Basic Performance Calculation
 
>Calculate the area under the P-V diagram. P is in column 2 and V is in column 8.
>Calculate the power output of this engine. Assume that RPM is 1500.
>This engine consumed 20 micro grams of fuel (per 1 stroke cycle). Calculate its specific fuel consumption.

Procedure:

1.Initially, the required modules are imported.
2.File name is taken as an input from user and, to verify the user file with engine_data.out file, for which we have used ‘if’ command.
3.Empty arrays are created so that the values that are used for plotting are stored.
4.Two variables are defined for selecting the parameters to be plotted by calling their column numbers.
5.In the main program two for loops are used in which one 'For loop' is used to append the column number values ranging from 0 to 19. 
6.Another 'for loop' is used for appending the column names and column units.
7.An ‘if ‘condition statement is used to nullify the existence of lines with the '#' symbol. The counter variable is incremented by 1 for every time the loops are executed.
8.The graphs are plotted and the title, as well as labels, are automatically assigned. This is done by mentioning the name of the column with the units.
9.Now, the performance parameters are to be considered. The initial input values are assigned, and the Engine Power is calculated.
10.It is followed by the calculation of Fuel Consumption and Specific Fuel Consumption.

Python_Program:

#Data Analysis by Bharadwaj
import math
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import simps

#Compatibilty check of the file with the program
try:
    open('engine_data.out')

except:
    print('File not recognized. Please provide a valid CONVERGE output file')


else:
    #Essential Inputs

    line_count = 1              #Counter variable to keep the line count
    
    column_number = []          #Creation of an empty array to store the value of column number
    column_name = []            #Creation of an empty array to store the column name in the form of string
    column_units =[]            #Creation of an empty array to store the units in the form of string
    
    #Creation of empty arrays to store the value of x and y respectively
    X = []
    Y = []

    #Initialization of value of x and y respectively
    x = 7
    y = 1

    #For loop for reading the file line by line and storing the required data
    for line in open('engine_data.out'): 

        #For loop defined for appending an empty array 'column_number' to store the value of column number from the line number 2 of the data file
        for i in range(0, 19):
            
            #If loop to avoid the storing of non-required characters like the string 'column' and the symbol '#'
            if i >= 2:

                #If loop to store the values of column number in an empty array 'column_number' from only the line number 2  
                if line_count == 2:
                    column_number.append(int(line.split()[i]))

    
        #For loop defined for appending empty arrays 'name_of_column' and 'units' to store the column name and units in the form of string from the line number 3 and 4 respectively of the data file
        for j in range(0, 18):  
        
            #If loop to avoid the storing of non-required characters like the symbol '#'
            if j >= 1:
            

                #If and else if loop 

                #Storing of the character column name in an empty array 'name_of_column' from the line number 3 if the if condition is true 
                if line_count == 3:
                    column_name.append(line.split()[j])

                #Storing of the character units in an empty array 'units' from the line number 4 if the else if condition is true
                elif line_count == 4:
                    column_units.append(line.split()[j])



        #Storing the values from line having numerical values only after the comments
        if '#' not in line:

            #If loop for storing of numeric data i.e quantity 1 and quantity 2 from the line number 6 and beyond that line
            if line_count >= 6:
                X.append(float(line.split()[x]))
                Y.append(float(line.split()[y]))


        #Updating the counter variable
        line_count = line_count + 1


# Plotting Graphs

plt.figure()
plt.plot(X, Y, linewidth=2, color = 'blue')
plt.title(str(column_name[y]) + ' vs ' + str(column_name[x]))
plt.xlabel(str(column_name[x]) + str(column_units[x]))
plt.ylabel(str(column_name[y]) + str(column_units[y]))
plt.savefig(str(column_name[y]) + ' vs ' + str(column_name[x]) + 'for Engine')
plt.show()


# The Results are as follows:
print('RESULTS: -')

# Area under curve
area = simps(Y,X)*pow(10,6)
print('Area under PV diagram (Joule) = ' + str(area) + ' J')

# RPM
N = 1500

# Fuel Consumption (g/stroke cycle)
m = 20

# No. of Strokes
s = 4

# No. of Cylinders
c = 1

# 1 Power Cycle for every Two revolutions (constant for purpose)
k = 2

power = (c*area*N)/(60*k*1000)
print('Power output = ' + str(power) + ' kW')

# Fuel Consumption (kg/hr)
FC = N*60*m*pow(10,-9)/2

# Specific Fuel Consumption
SFC = FC/power
print('Specific Fuel Consumption = ' + str(SFC) + ' kg/hr/kW')


Result:
Upon executing the following program, first a p-v plot appears and according to it the required calculations are made as,

Area under PV diagram (Joule) = 500.58644742623636 J
Power output = 6.257330592827955 kW
Specific Fuel Consumption = 0.00014383130100742393 kg/hr/kW
[Finished in 9.6s]

The P-V plots were observed for the above input.

Similarly other plots were made by providing input to the code and were saved in the folder by their respective name.

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.