All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
OBJECTIVE: To write a python script which satisfies the objectives given below: 1. The program should take the columns as input and plot the values in the chosen columns. 2. The plot should be saved by the name of the column. 3. The plot labels should be extracted from the file. 4. If a non-compatible file is given as…
Ashwen Venkatesh
updated on 28 Dec 2020
OBJECTIVE:
To write a python script which satisfies the objectives given below:
1. The program should take the columns as input and plot the values in the chosen columns.
2. The plot should be saved by the name of the column.
3. The plot labels should be extracted from the file.
4. If a non-compatible file is given as input, the script should exit and it should show a message "File Not compatible. Please provide a valid converge output file"
5. The code should calculate the area under the P-V diagram.
6. To print the power output of the engine at 1500 rpm.
7. The code should calculate the specific fuel consumption for given mass 20 micrograms of fuel.
PROBLEM STATEMENT:
The given problem statement can be divided into three parts:
1. Data Visualizer: This part of the problem defines the user as to how to read the data in the given file and how data has to be interpreted for the solution.
2. Compatibility check: This part of the problem generates explains the necessary compatibility checks to be done in the program so that the desired file is read correctly.
3. Basic Performance Calculation: This problem statement demands the code to solve a specific set of problem with the necessary conditions given.
The problem statement is defined by writing a python program which satisfies all the three criterias mentioned above.
:
import matplotlib.pyplot as plt
import numpy as np
import math
#Library for developing GUI
import tkinter as tk
from tkinter import ttk
from tkinter import *
#Checking if the file is proper
try:
file = open('engine_data.out')
print('File located and opened successfully')
except:
print('File not found/not recognized. Please provide a valid converge output file')
#Checking if the file has data
i=0
for line in open('engine_data.out'):
if '#' not in line:
break
i=i+1
j=0
for line in open('engine_data.out'):
j=j+1
if j>i:
break
if j==i:
print('No data is present in the given file')
exit()
#Initialising values given in the probelm
RPM=1500
linecount = 1
values1=[]
values2=[]
column1 = ""
column2 = ""
#Creating GUI Interface
window = tk.Tk()
#Assigning title to the GUI interface
window.title("Data Analysis")
#Giving the size of the screen
window.geometry('450x250')
# Assigning labels
ttk.Label(window, text = "Select the Parameters for X-Axis :",
font = ("Times New Roman", 10)).grid(column = 0,
row = 15, padx = 10, pady = 25)
ttk.Label(window, text = "Select the Parameters for Y-Axis :",
font = ("Times New Roman", 10)).grid(column = 0,
row = 20, padx = 10, pady = 25)
#Function to get the values entered by the user
def dummy():
GraphPlot(headers[xaxis.get()],headers[yaxis.get()])
btn = Button(window, text="Plot", fg='black',command=dummy)
btn.place(x=400, y=50)
n = tk.StringVar()
m = tk.StringVar()
#Creating drop down in for choosing the axes
xaxis = ttk.Combobox(window, width = 27,
textvariable = n)
yaxis = ttk.Combobox(window, width = 27,
textvariable = m)
#Defining dictionaries for the user entered string value
headers={"Crank Angle":1,"Pressure":2,"Maximum Pressure":3,"Minimum Pressure":4,"Mean Temperature":5,"Maximum Temperature":6,"Minimum Temperature":7,"Volume":8,"Mass":9,"Density":10,"Integrated_HR":11,"HR Rate":12,"C_p":13,"C_v":14,"Gamma":15,"Kinematic Viscosity":16,"Dynamic Viscosity":17}
#Listing the drop down for x-axis parameters
xaxis['values'] = ('Crank Angle',
'Pressure',
'Maximum Pressure',
'Minimum Pressure',
'Mean Temperature',
'Maximum Temperature',
'Minimum Temperature',
'Volume',
'Mass',
'Density',
'Integrated_HR',
'HR Rate',
'C_p',
'C_v',
'Gamma',
'Kinematic Viscosity',
'Dynamic Viscosity')
#Listing the drop down for x-axis parameters
yaxis['values'] = ('Crank Angle',
'Pressure',
'Maximum Pressure',
'Minimum Pressure',
'Mean Temperature',
'Maximum Temperature',
'Minimum Temperature',
'Volume',
'Mass',
'Density',
'Integrated_HR',
'HR Rate',
'C_p',
'C_v',
'Gamma',
'Kinematic Viscosity',
'Dynamic Viscosity')
#Defining the grid in the GUI
xaxis.grid(column = 1, row = 15)
yaxis.grid(column = 1, row = 20)
#Defining default values for dropdown
xaxis.current(0)
yaxis.current(1)
#Definin the plotting function
def GraphPlot(val1,val2):
#If case to ensure that user select different axes
if(val1==val2):
print('Please select diffferent axes')
return 0
plt.close()
linecount=1
values1=[]
values2=[]
#Getting the column title and column values from the given file
for line in open('engine_data.out'):
if linecount==3:
column1 = line.split()[val1]
column2 = line.split()[val2]
if '#' not in line:
values1.append(float(line.split()[val1-1]))
values2.append(float(line.split()[val2-1]))
linecount=linecount+1
plt.plot(values1,values2)
plt.xlabel(column1)
plt.ylabel(column2)
#Saving the image file
plt.savefig(r"{} vs {}.png".format(column1,column2))
plt.show()
#Closing the GUI window
window.mainloop()
#Calculating and printing of area, power output and SFC
linecount=1
values1=[]
values2=[]
for line in open('engine_data.out'):
if '#' not in line:
values1.append(float(line.split()[7]))
values2.append(float(line.split()[1]))
linecount=linecount+1
#Calculating and printing the area under the curve
area=np.trapz(values1,values2)
workdone=(area/1000)*pow(10,6)
print('Area under the P-V diagram is', workdone,'kJ')
#Calculating and printing power output
Power=2*(math.pi)*workdone*1500/60
print('Power Output obtained is',Power,'kW')
#Calculating and priting SFC
fuel=20*pow(10,-6)
SFC=(fuel*1500*60)/Power
print('The specific fuel consumption obtained is',SFC,'g/kWh')
Note:
1. The library "tkinter" was used to create the GUI
2. To obtain the values of the calculation the GUI must be closed.
3. To obtain a plot a user must select two different axis.
RESULTS AND CONCLUSION:
1. If the file is not compatible the script will give the following message.
2. If there is no data present in the file, the script will give the message shown below.
3. The following output was obtained for the problem. The area under the P-V diagram, power output and specific fuel consumption is shown below.
4. The GUI interface is shown in the figure below.
5. The different plots obtained are shown in the figures below.
6. The plots saved in the directory with the column name are shown below.
Therefore, all the objectives are satisfied by the program.
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.
Other comments...
Project - 2 - Meshing on the suspension Assembly
OBJECTIVE: To mesh and create connections in the given suspension assembly as per the quality criteria given below using ANSA. PROCEDURE: 1. The given model is imported into the ANSA software and the geometry checks are run. This is shown in the figure below. 2. The errors are fixed using the auto-fix option. If the errors…
28 Jun 2021 11:11 AM IST
Project 1 - 2D meshing on the instrumental Panel
OBJECTIVE: To extract the mid surface and perform meshing in the given geometry as per quality criteria given below using ANSA. S.No Quality Criteria Value 1 Target/Average length 4 2 Minimum Length 2 3 Maximum Length 6 4 Aspect 3 5 Warpage 15 6 Skewness 45 7 Jacobian …
24 Jun 2021 11:46 AM IST
Tool Test 1
PFA the models. Time Taken: Model 1: 4.5 hours Model 2: 1.5 hours
16 Jun 2021 02:54 PM IST
Week - 4 - 2D meshing for Plastic components
OBJECTIVE: To extract mid surface and perform meshing as per the quality criteria given below using ANSA. S.No Quality Criteria Value 1 Target/Average length 1 2 Minimum Length 0.5 3 Maximum Length 3 4 Aspect 3 5 Warpage 15 6 Skewness 45 7 Jacobian 0.7 8 Minimum Quad…
15 Jun 2021 06:06 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.