Script for Data Analysis using python
OBJECTIVE
The main objective of this challenge is to script a program for the data analysis for the given data.
INSTRUCTIONS TO DO WITH DATA ANALYSIS
-
- The script to be written according to the data that column as input and plotting the respective columns in separate images with each of the image saving is to have the filename of the plotting column is taken from.
- And the labeling of the plotting image is also should be the same as the column name in e=which the values are taken from.
- As the data file to be imported should be a valid file that which has the specific file formats as converge output file (filename.out).
- Calculating the area under the pressure and volume within the given data.
- As we analyzing the engine data the rpm is specified and with that, the power output is to be calculated.
- The last important thing is the specific fuel consumption is to be calculated that the engine consumed 20 micrograms per stroke cycle.
PROGRAM
import matplotlib.pyplot as plt
import numpy as np
import math
filename=input(\'enter the filename:\')
try:
val=int(input())
val2=int(input())
p=[]
p2=[]
lc=1
file=open(filename)
#if file is (\' .out\'):
for i in file:
if \'#\' not in i:
plot=(i.split()[(val-1)])
plot2=(i.split()[val2-1])
p.append(float(plot))
p2.append(float(plot2))
#print(len(i))
if \'#\' in i:
j=i.split()
if lc is 3:
xx=(j[val])
yy=(j[val2])
if lc is 4:
xy=(j[val])
yx=(j[val2])
lc=lc+1
plt.xlabel(xx+xy)
plt.ylabel(yy+yx)
plt.plot(p,p2)
#plt.show()
plt.title(xx+\' vs \'+yy)
plt.savefig(xx+\' vs \'+yy+\'.png\')
#needs=input(\'do you what to know power,specifc_fuelconsumption\')
if val is (2):
if val2 is (8):
area=np.trapz(p,p2)
f_c=float(input(\'enter the fuel consumption:\'))
rpm=int(input(\'enter the rpm:\'))
power_output=((area*rpm*3.14*2)/60)*10**3
mass=(f_c*10**(-9)*3600)/(0.08)
specifc_fuelcons=mass/power_output
print(\'power_output\', power_output,\'kw\')
print(\'specifc_fuel_consumption\',specifc_fuelcons,\'g/kwh\')
except:
print(\'file format not supported\')
OUTPUT
- This output is that the plotting I did for the 11 and the 12th column in the data file. As specified in the important notes the name of the column data which is taken from the file.
- As of the requirements, the column data can be differentiated and the result will be according to the column number given as input.
- This below image will represent the when trying to import the unsupported file to execute this program.
- This below image shows the output when the 2 and 8 columns of the data are only called to be plotted then the engine power will be calculated with given data like rpm and the specific fuel consumption is calculated with data using around the data orom the file.
- As the script before entering to execute in calculating the power of the plotted images will be saved to the default directory.
- the condition in this program only when the pressure in column 2 and volume in column 8 is called, then the engine power calculation segment open to execute.
COMMANDS USED
-
matplotlib - matplotlib is an amazing visualization library in python for 2D plots of arrays. This command is used to plot graphs using the code.
-
math - This library is used when we use the trigonometric functions.
-
def file_name(arguments) - This keyword is used to define function along with all suitable parameters related to the problem as according to the user needs.
-
return() - The return statement is used when a function is ready to return a value to its calling function.
-
numpy - This module is used for assigning n values in between two values with the same common difference.
-
append() - This function is used to append the calculated values in an empty array.
-
plt.figure()- This command is used to display the multiple graphs at a time side by side to compare results.
-
plt.plot() - This command is used to draw graphs according to their assigned values.
-
plt.label()- This command is used to label the axis to differentiate the values on the curves.
-
plt.show() - This command is used to display the results graphs on the screen as output.
-
plt.savefig()- This command is used to save the output images in a particular folder.
-
plt.title()- This command is used to give title for the drawn graph.
-
plt.legend()- This command is used to the label inside the graph.
-
scipy - This library is used to get access to the function with which we plot a graph for given data points.
-
curve_fit()- This function is used for fitting the curve according to the given data.
-
func()- This function is used to define a function for drawing a curve.
-
open()- This is used to open a file and read the data.
-
split()- This function is used to split data into arrays.
-
float()-This function is used to assign decimal values to the variable.
-
readfile()- This file is used to read the line of the given data.
-
input()- This function is used to give any input manually after to execute the given condition.
- int - this function is to take the data as integer format.
-
trapz()- This function is used to calculate the area of the trapezoidal logic.
CONCLUSION
The conclusion of this script is to have the required data with plotting the data as required by the user and the challenge is to calculate the power of the engine using the engine data that is given and the specific fuel consumption accordingly.