Challenge

Week 6 - Data analysis

DATA VISUALIZER PROGRAM:

following python code takes column numbers as input from user and then fulfills all the purpose listed in question stem for data visualizer program.

NOTE: sublime ide does not support taking inputs from user, hence, the 'sublime REPL' package has been installed in order to modify sublime for taking inputs from user. 

evaluators can copy and paste the code to another input compatible environment for python code and check the validity of my results.

FUNCTIONS OF DATA VISUALIZER:

the following code serves the following requirements:

  • it takes column numbers as input
  • extracts information like property name, unit, labels, and titles for plot
  • stores the simulation results in an array and plots values with respect to other column values.
  • saves plot with a particular name, with a particular format.
  • plot titles, labels, and saved file names are chosen automatically
  • units are also picked automatically

INPUT:

import math as M
import numpy as np
import matplotlib.pyplot as plt

# DATA VISUALISATION ANALYSIS ON I.C ENGINE SIMULATION PROPERTIES


# data visualizer program

i = int(input("Enter column number of a property you wanna plot on x-axis: "))  # INPUT 1
j = int(input("Enter column number of a property you wanna plot on y-axis: "))  # INPUT 2


# file parsing

property_x = []          # property to be plotted on x-axis
property_y = []          # property to be plotted on y-axis 


for line in open('engine_data.out'):
	if '#' not in line:

		property_x.append(float(line.split()[i-1]))
		property_y.append(float(line.split()[j-1]))

# code section picking information about property name and unit 


px_name = []                                # name of property 1                  
py_name = []                                # name of property 2
px_unit = []                                # unit of property 1
py_unit = []                                # unit of property 2

line_pointer = 1
for line2 in open('engine_data.out'):
	
	if line_pointer == 3:

		px_name.append((line2.split()[i]))
		py_name.append((line2.split()[j]))


	if line_pointer == 4:

		px_unit.append((line2.split()[i]))
		py_unit.append((line2.split()[j]))

	line_pointer = line_pointer + 1


# code for gernerating variable title,units and labels


set_title = 'ENGINE CHARECTERISTICS: {} VS. {}'.format(py_name[0],px_name[0])
set_xlabel = "{}{}".format(px_name[0],px_unit[0])
set_ylabel = "{}{}".format(py_name[0],py_unit[0])


# plotting section


plt.plot(property_x,property_y,linewidth=3)
plt.title(set_title)
plt.xlabel(set_xlabel)
plt.ylabel(set_ylabel)
plt.savefig('{} VS.{}.png'.format(py_name[0],px_name[0]) )
plt.show()

REPL INPUT INTERFACE:

OUTPUT:

screenshot of saved file:

COMPATIBILITY CHECK MODIFICATION:

when making errors, users are exposed to sudden outbursts of technical details regarding the failure of script thrown in output window.

here, however, we can make use of some conditional block that can print some ' user-defined error message ' which can give insight to user in certain cases for script failure.

for example, if an invalid file is entered, output window throws specific message to the user.

for this task, we will make use of ' try: ......   except:.... ' block which will print error message in case of invalid file name insertion. with this slight modification in file parsing block, we can achieve the compatibility check task.

INPUT:

# file parsing

property_x = []          # property to be plotted on x-axis
property_y = []          # property to be plotted on y-axis 

try:

	for line in open('wallpaper.png'):
		if '#' not in line:

			property_x.append(float(line.split()[i-1]))
			property_y.append(float(line.split()[j-1]))

except:

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

OUTPUT:

as we can observe, exception message is being printed out saying "File not recognized. Please provide a valid CONVERGE output file".

BASIC PERFORMANCE CALCULATION:

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.

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.