Menu

Executive Programs

Workshops

Projects

Blogs

Careers

Placements

Student Reviews


For Business


More

Academic Training

Informative Articles

Find Jobs

We are Hiring!


All Courses

Choose a category

Mechanical

Electrical

Civil

Computer Science

Electronics

Offline Program

All Courses

All Courses

logo

CHOOSE A CATEGORY

Mechanical

Electrical

Civil

Computer Science

Electronics

Offline Program

Top Job Leading Courses

Automotive

CFD

FEA

Design

MBD

Med Tech

Courses by Software

Design

Solver

Automation

Vehicle Dynamics

CFD Solver

Preprocessor

Courses by Semester

First Year

Second Year

Third Year

Fourth Year

Courses by Domain

Automotive

CFD

Design

FEA

Tool-focused Courses

Design

Solver

Automation

Preprocessor

CFD Solver

Vehicle Dynamics

Machine learning

Machine Learning and AI

POPULAR COURSES

coursePost Graduate Program in Hybrid Electric Vehicle Design and Analysis
coursePost Graduate Program in Computational Fluid Dynamics
coursePost Graduate Program in CAD
coursePost Graduate Program in CAE
coursePost Graduate Program in Manufacturing Design
coursePost Graduate Program in Computational Design and Pre-processing
coursePost Graduate Program in Complete Passenger Car Design & Product Development
Executive Programs
Workshops
For Business

Success Stories

Placements

Student Reviews

More

Projects

Blogs

Academic Training

Find Jobs

Informative Articles

We're Hiring!

phone+91 9342691281Log in
  1. Home/
  2. Sourabh Lakhera/
  3. Data analysis using python

Data analysis using python

AIM: To write a script that does data analysis on python. OBJECTIVE : Visualizing the data, i.e., to plot a graph between any two quantities according to the user's input. Compatibility Check, i.e., code should exit gracefully, if a non-compatible file is provided as an input. To calculate basic engine performance…

  • PYTHON
  • Sourabh Lakhera

    updated on 15 Jul 2020

AIM: To write a script that does data analysis on python.

OBJECTIVE :

  1. Visualizing the data, i.e., to plot a graph between any two quantities according to the user's input.
  2. Compatibility Check, i.e., code should exit gracefully, if a non-compatible file is provided as an input.
  3. To calculate basic engine performance calculations.

INTRODUCTION : 

Data analysis is a process of inspecting, cleansing, transforming, and modeling data with the goal of discovering useful information, informing conclusions, and supporting decision-making. Data analysis has multiple facets and approaches, encompassing diverse techniques under a variety of names, and is used in different business, science, and social science domains. In today's business world, data analysis plays a role in making decisions more scientific and helping businesses operate more effectively.

Data analysis is a somewhat abstract concept to understand without the help of examples. So to better illustrate how and why data analysis is important for businesses, here are the 4 types of data analysis and examples of each.

  • Descriptive Analysis: Descriptive data analysis looks at past data and tells what happened. This is often used when tracking Key Performance Indicators (KPIs), revenue, sales leads, and more.
  • Diagnostic Analysis: Diagnostic data analysis aims to determine why something happened. Once your descriptive analysis shows that something negative or positive happened, diagnostic analysis can be done to figure out the reason. A business may see that leads increased in the month of October and use diagnostic analysis to determine which marketing efforts contributed the most.
  • Predictive Analysis: Predictive data analysis predicts what is likely to happen in the future. In this type of research, trends are derived from past data which are then used to form predictions about the future. For example, to predict next year’s revenue, data from previous years will be analyzed. If revenue has gone up 20% every year for many years, we would predict that revenue next year will be 20% higher than this year. This is a simple example, but predictive analytics can be applied to much more complicated issues such as risk assessment, sales forecasting, or qualifying leads.
  • Prescriptive Analysis: Prescriptive data analysis combines the information found from the previous 3 types of data analysis and forms a plan of action for the organization to face the issue or decision. This is where data-driven choices are made.

These 4 types of data analysis can be applied to any issue with data related to it. And with the internet, data can be found about pretty much everything.

GOVERNING EQUATIONS USED :
Since the data file given consists of various parameters for an engine. Several calculations can be made from it. But for our interest, the following parameters are to be calculated-

  • Work is done by the engine (`W_(out)): This can be found by plotting p-V diagram of the engine and calculating area under the curve.
  • The power output of the engine: This is generally called engine brake power and can be found as,

Power=Wout⋅RPM⋅n60⋅1000⋅2">Power=Wout⋅RPM⋅n60⋅1000⋅2Power=Wout⋅RPM⋅n60⋅1000⋅2 in kW">kWkW . Here n">nn is the number of cylinders of the engine, RPM">RPMRPM is the engine speed in minutes, it's to be converted into seconds by dividing by 60">6060, 2">22 in the denominator, the term is present because the given engine is a 4 stroke engine.

  • Specific fuel consumption (SFC">SFCSFC) : FCPower">FCPowerFCPower , where FC">FCFC is the amount of fuel consumed by the engine in kghr">kghrkg .

INPUTS: RPMRPM = 1500 , fuel consumed per stroke = 20">2020 micro grams.

PROCEDURE : 

  1. At first important modules such as math, matplotlib, numpy, scipy are imported for their various functions.
  2. For checking compatibility of the program, 'try' and 'except' command is used according to their syntax and the given data file is opened using 'open' command within a for a loop. If the file name is misspelled or is wrong, the code will yield error with the following message "File not recognized. Please provide a valid CONVERGE output file" and will not execute and exit.
  3. For the purpose of plotting curve between two quantities according to user input, first, a line counter is initiated from 1 and null arrays of volume and pressure and data is created for further uses. Now an 'if' loop is iterated with the condition that if '#' is not in line, (i.e., if only numerical digits is present and not any other line) all the numerical values present in the data file is now to be stored in the data array as string (by default).
  4. For engine performance calculations, the first area under pV curve is to be calculated and this can be done by either the Trapezoidal method or Simpson method. Here it has been calculated by both methods by entering the required inputs and the necessary formulas.
  5. The array of data obtained earlier consists of a column matrix of strings of each quantity present inside it. So the column matrix is transposed into several row matrices according to various quantities using 'np.transpose' command and is further converted into float data types using "astype" command.
  6. Two arrays of name of the parameters and their units are made according to data file given and then user has to choose from them to plot respective graphs. For this the two inputs of the user are taken using 'input' command in python 3 and its datatype is set as 'int' and plotted using 'plt.plot' command. Basically user is entering column number as input and accordingly, result is generated.

 

SOME Figures to explain the procedures as shown Above:- 

        

  

        

       

 

     

     

  •   

      

PYTHON CODE : 

# A program to calculate engine parameters and to plot graph between two quantites according to user input
import math
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import simps

# Compatability check
try:
  open('engine_data.out')

  line_count = 1

  # Creating of empty arrays to store the value of Volume and pressure respectively
  Volume = []
  pressure = []

  # Volume and pressure in the data file is present in column 8 and 2 respectively. Calling them and storing their data into arrays 
  v = 8
  p = 2

  # Creating a null array and storing all the values of data file into it

  data=[]

  for line in open('engine_data.out'):
        if '#' not in line:
          data.append(line.split())
          if line_count >= 6:
                Volume.append(float(line.split()[v-1]))
                pressure.append(float(line.split()[p-1]))
        line_count = line_count + 1


  # Plotting p-V diagram
  plt.plot(Volume, pressure, color = 'r', linewidth = 2)
  plt.xlabel('Volume (m^3)')
  plt.ylabel('Pressure (MPa)')
  plt.title("p-V diagram of Engine")
  plt.grid()
  plt.savefig('p-V diagram of Engine')
  plt.show()

    
  # Calculation of area under PV diagram using the simpsons rule
    
  area = simps(pressure, Volume)
  print('Area under the curve using Simpsons Rule : ' + str(area) + ' units')
  print('Work done by the engine : ' + str(area) + ' MJ')
  area = area*1e6
  print('Work done by the engine : ' + str(area) + ' J')
    
  #Inputs
  #Speed of an engine (RPM)
  rpm = 1500
  rps = 1500/60
  stroke_cycle = rps/2

  #Fuel consumption in micro grams per 1 stroke cycle
  fuel_consumption = 20

  #Engine Specifications
  #Number of cylinder=
  n = 1
  # 4 stroke engine
    
  # Calcualtions of Power output and specific fuel consumption
    
  power_output = n*area*stroke_cycle/(1000)
  print('Power ouput from engine : ' + str(power_output) + ' KW')  
  SFC = (fuel_consumption*pow(10,-6)*stroke_cycle*3600)/(power_output*1000)
  print('Specific Fuel Consumption, SFC = ' + str(SFC) + ' (kg/hr)/KW')
  print('t')

  # Calculation of area under PV diagram using the trapezoidal rule and work done,power sfc
  Area = np.trapz(pressure,Volume)
  print('Area under the curve using trapezoidal Rule : ' + str(Area) + ' units')
  print('Work done by the engine : ' + str(Area) + ' MJ')
  Area = Area*1e6
  print('Work done by the engine : ' + str(Area) + ' J')
  power_output = n*Area*stroke_cycle/(1000)
  print('Power ouput from engine : ' + str(power_output) + ' KW')  
  SFC = (fuel_consumption*pow(10,-6)*stroke_cycle*3600)/(power_output*1000)
  print('Specific Fuel Consumption, SFC = ' + str(SFC) + ' (kg/hr)/KW')
  print('t')

          
  # Tansposing columns into row matrix and converting them into float type from string type
  transpose=np.transpose(data)
  float_f=transpose.astype(np.float)

   # Array for header and their units
  parameters = ['Crank','Pressure','Maximum Pressure','Minimum Pressure','Mean Temperature','Maximum Temperature','Minimum Temperature','Volume','Mass','Density','Integrated HR','HR Rate','Cp','Cv','Gamma','Kinematic Viscosity','Dynamic Viscosity']

  units = ['(DEG)','(MPa)','(MPa)','(MPa)','(K)','(K)','(K)','(m^3)','(kg)','(kg/m^3)','(J)','(J/time)','(J/kgK)','(J/kgK)','','(m^2/s)','(Ns/m^2)']

  # Providing user choice of picking two parameters for plotting
  print('Choose from the following options and press enter key')
  print(' 1 Crank n 2 Pressure n 3 Maximum Pressure n 4 Minimum Pressure n 5 Mean Temperature n 6 Maximum Temperature n 7 Minimum Temperature n 8 Volume n 9 Mass n 10 Density n 11 Integrated HR n 12 HR Rate n 13 Cp n 14 Cv n 15 gamma n 16 Kinematic Viscosity n 17 Dynamic Viscosity')

  X=int(input('Enter your choice on X-axis n'))

  Y=int(input('Enter your choice on Y-axis n'))

  # Plotting the graph based on user choice
  plt.figure(1)
  plt.plot(float_f[X-1],float_f[Y-1],linewidth=3,color='blue')
  plt.title(' Plot for ' + parameters[X-1]+ ' versus ' +parameters[Y-1],color='blue')
  plt.xlabel(parameters[X-1] + ' ' + units[X-1])
  plt.ylabel(parameters[Y-1] + ' ' + units[Y-1],)
  plt.savefig(parameters[X-1] + ' vs ' + parameters[Y-1] + '.png')
  plt.grid()
  plt.show()

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

 

RESULTS :

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

 

  • This was made possible only if correct data file is opened. If there were different files to be opened the following message is dispalyed in the command window,

 

  • For user input for plotting curves, the .py file is opened and run as shown,

  • The following 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,

 

  • Screenshot of the folder where these plots are saved automatically,

ERRORS : Several types of indentation errors were made and rectified but one error was due to not transposing the data as explained in the procedure. On running the program just yields this error. This was due to converting all the strings into float type without indicating a particular item of line.split()[]. To avoid this error, the data was appended without converting into float at line 16, but rather creating a transpose and converting into float type using 'astype' command in further steps.

REFERENCES :

  1. python - how to find area under curve? [closed]
  2. Data analysis
  3. Data Analysis

Leave a comment

Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.

Please  login to add a comment

Other comments...

No comments yet!
Be the first to add a comment

Read more Projects by Sourabh Lakhera (26)

Project 1 - Data Cleaning and Transformation using Pivot table and Charts for the Report on requirement of Team Hiring

Objective:

Project Documentation: Optimizing Team Hiring Insights through Data Cleaning and TransformationIntroductionIn today's data-driven environment, businesses thrive on informed decision-making. At ABC Private Limited, a manufacturer and seller of diverse products ranging from Classic Cars to Trucks and Buses, understanding…

calendar

26 Sep 2024 02:54 PM IST

    Read more

    Project 2

    Objective:

    Project Documentation: Alumni Career Choices AnalysisAimThe aim of this project is to analyze the career choices of alumni from two universities with respect to their passing year and the courses they completed. This analysis helps in understanding the career growth of alumni, which plays a crucial role in the institute's…

    calendar

    10 Jul 2024 08:03 AM IST

      Read more

      Project 1

      Objective:

      From the series of queries and actions conducted on the ecommerceecommerce database, several insights can be derived regarding the user demographics and their activities on the platform. Firstly, the database contains information about users' demographics, such as their gender, country, language, and usage of applications like…

      calendar

      28 Feb 2024 07:45 PM IST

        Read more

        Project 2 - EDA on Vehicle Insurance Customer Data

        Objective:

        EDA on Vehicle Insurance Customer Data Aim: The aim of this project is to perform exploratory data analysis (EDA) and data cleaning on two datasets containing customer details and policy details. The objective is to prepare the data for future analysis and modeling, identify patterns, and derive insights to aid business…

        calendar

        19 Feb 2024 08:36 PM IST

          Read more

          Schedule a counselling session

          Please enter your name
          Please enter a valid email
          Please enter a valid number

          Related Courses

          coursecard

          Core and Advanced Python Programming

          4.8

          30 Hours of Content

          coursecard

          Applying CV for Autonomous Vehicles using Python

          Recently launched

          21 Hours of Content

          coursecardcoursetype

          Mechanical Engineering Essentials Program

          4.7

          21 Hours of Content

          coursecardcoursetype

          Internal Combustion Engine Analyst course using Python and Cantera

          4.8

          22 Hours of Content

          coursecard

          Computational Combustion Using Python and Cantera

          4.9

          9 Hours of Content

          Schedule a counselling session

          Please enter your name
          Please enter a valid email
          Please enter a valid number

          logo

          Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.

          https://d27yxarlh48w6q.cloudfront.net/web/v1/images/facebook.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/insta.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/twitter.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/youtube.svghttps://d27yxarlh48w6q.cloudfront.net/web/v1/images/linkedin.svg

          Our Company

          News & EventsBlogCareersGrievance RedressalSkill-Lync ReviewsTermsPrivacy PolicyBecome an Affiliate
          map
          EpowerX Learning Technologies Pvt Ltd.
          4th Floor, BLOCK-B, Velachery - Tambaram Main Rd, Ram Nagar South, Madipakkam, Chennai, Tamil Nadu 600042.
          mail
          info@skill-lync.com
          mail
          ITgrievance@skill-lync.com

          Top Individual Courses

          Computational Combustion Using Python and CanteraIntroduction to Physical Modeling using SimscapeIntroduction to Structural Analysis using ANSYS WorkbenchIntroduction to Structural Analysis using ANSYS Workbench

          Top PG Programs

          Post Graduate Program in Hybrid Electric Vehicle Design and AnalysisPost Graduate Program in Computational Fluid DynamicsPost Graduate Program in CADPost Graduate Program in Electric Vehicle Design & Development

          Skill-Lync Plus

          Executive Program in Electric Vehicle Embedded SoftwareExecutive Program in Electric Vehicle DesignExecutive Program in Cybersecurity

          Trending Blogs

          How to Learn CAD Design: Step-by-Step GuideGD&T Basics: How to Read and Apply GD&T Symbols SolidWorks vs Creo: Best CAD Software to Learn for Mechanical Engineers Engineering Edtech in India: Busting Myths & Building Careers How to Get a Core Mechanical Engineering Job After Graduation

          © 2025 Skill-Lync Inc. All Rights Reserved.

                      Do You Want To Showcase Your Technical Skills?
                      Sign-Up for our projects.