Challenge

Week 6 - Data analysis

AIM: To perform data visualization, compatibility verification, and basic performance analysis using Python.


INTRODUCTION:
Data analysis involves examining, cleaning, transforming, and modeling data to uncover valuable insights, support decision-making, and draw meaningful conclusions. It encompasses various methods and techniques applied across multiple disciplines, including business, science, and social sciences. In the modern business environment, data analysis is pivotal in making informed decisions and improving operational efficiency.

The stages of the data analysis process include:

  1. Identifying Data Requirements
  2. Collecting Data
  3. Processing Data
  4. Cleaning Data
  5. Performing Exploratory Data Analysis (EDA)
  6. Building Models and Algorithms
  7. Developing Data Products
  8. Communicating Insights

OBJECTIVES:

  1. Create a graph to visualize the relationship between two variables in the Converge output file.
  2. Validate the successful opening of the data file.
  3. Calculate the area under a Pressure-Volume (PV) diagram.
  4. Determine the power output of an engine operating at 1500 RPM.
  5. Compute the specific fuel consumption (SFC) when 20 mg of fuel is consumed per stroke cycle.

GOVERNING EQUATIONS:

Power:
Power=2π×T×RPM\text{Power} = 2 \pi \times T \times \text{RPM}Power=2π×T×RPM

Specific Fuel Consumption (SFC):
SFC=FCPower\text{SFC} = \frac{\text{FC}}{\text{Power}}SFC=PowerFC​

Where:

  • TTT = Torque
  • FC\text{FC}FC = Fuel Consumption
  • SFC\text{SFC}SFC = Specific Fuel Consumption


Code Breakdown

1. Importing Required Libraries

  • numpy for numerical operations.
  • matplotlib.pyplot for graph plotting.
  • scipy.integrate.simps for numerical integration using the Simpson's rule (to calculate the area under a curve).
  • This Python script performs data analysis on engine data obtained from a Converge simulation output file (engine_data.out). Here's a breakdown of the code:

  • Purpose

    • Analyze port fuel injection data.
    • Extract specific columns from the file to plot graphs.
    • Compute performance parameters such as the area under the Pressure-Volume (PV) diagram, power output, and specific fuel consumption (SFC).

    Code Breakdown

    1. Importing Required Libraries

    • numpy for numerical operations.
    • matplotlib.pyplot for graph plotting.
    • scipy.integrate.simps for numerical integration using the Simpson's rule (to calculate the area under a curve).

    2. File Handling

    try:

    open('engine_data.out')

    print('File opened successfully')

    print('\n')

    except:

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

  • Attempts to open the file engine_data.out.
    • Prints a success message if the file opens correctly.
    • If the file fails to open, it prints an error message and stops further execution.

    3. Initializing Variables

    line_count = 1 column_num = [] column_name = [] column_units = [] X = [] Y = [] x = 7 # Column number for X-axis y = 1 # Column number for Y-axis

    • line_count: Tracks the line being processed.
    • column_num, column_name, column_units: Store metadata about the file's columns (e.g., column index, names, and units).
    • X, Y: Arrays to store data points for the graph's X and Y axes.
    • x and y: Indices corresponding to specific columns in the file for graph plotting.

    Reading the File Line by Line line ():

    for line in open('engine_data.out'): for i in range(0,19): if i >= 2 and line_count == 2: column_num.append(int(line.split()[i])) for j in range(0,18): if j >= 1: if line_count == 3: column_name.append(line.split()[j]) elif line_count == 4: column_units.append(line.split()[j]) if '#' not in line and line_count >= 6: X.append(float(line.split()[x])) Y.append(float(line.split()[y])) line_count += 1

    • Processes the file line by line.
    • Lines 2-4: Extract column numbers, names, and units.
    • After Line 6: Extracts data values from columns specified by x and y (ignoring lines with #).

    5. Plotting the Graph

    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()

    • Creates a plot of Y vs X.
    • Sets the title, x-label, and y-label using column names and units.
    • Saves the graph as an image file.

    6. Results Calculation

    Area Under PV Diagram

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

    • Calculates the area under the curve (PV diagram) using Simpson's rule.
    • Multiplies by 10610^6106 to adjust units.
    Power Output

    N = 1500 # Engine RPM m = 20 # Fuel consumption per stroke cycle (mg) s = 4 # Number of strokes c = 1 # Number of cylinders k = 2 # Power cycle per two revolutions power = (c * area * N) / (60 * k * 1000) print('Power output = ' + str(power) + ' kW')

    • Power is calculated using the formula: Power=c⋅Area⋅N60⋅k⋅1000\text{Power} = \frac{c \cdot \text{Area} \cdot N}{60 \cdot k \cdot 1000}Power=60⋅k⋅1000c⋅Area⋅N​
    • Assumes 1500 RPM, 4 strokes, and 1 cylinder.
    Specific Fuel Consumption (SFC)

    FC = N * 60 * m * pow(10, -9) / 2 SFC = FC / power print('Specific Fuel Consumption = ' + str(SFC) + ' kg/hr/kW')

    • Fuel consumption (FC) is calculated using the formula: FC=N⋅60⋅m⋅10−92FC = \frac{N \cdot 60 \cdot m \cdot 10^{-9}}{2}FC=2N⋅60⋅m⋅10−9​ Where NNN is the engine RPM, mmm is the fuel consumed per stroke, and 10−910^{-9}10−9 converts milligrams to kilograms.
    • SFC is the ratio of fuel consumption to power output: SFC=FCPower\text{SFC} = \frac{FC}{\text{Power}}SFC=PowerFC​

    Output

    1. Graph of Y vs X saved as an image file.
    2. Prints:
      • Area under the PV diagram.
      • Power output in kilowatts.
      • Specific fuel consumption in kg/hr/kW.

    CONCLUSION

    Code was run successfully

    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.