Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions opppy/dump_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def point_value_3d(data, x_key, y_key, z_key, value_key, x_value, y_value, z_val



def data2grid(data, x_key, y_key, value_key, npts=500, method='nearest', log_scale=False):
def data2grid(data, x_key, y_key, value_key, npts=500, method='nearest'):
'''
This function takes a 2D data structure from dictionary and creates a 2D
grid for each array by interpolating. This is useful for plotting.
Expand All @@ -146,18 +146,14 @@ def data2grid(data, x_key, y_key, value_key, npts=500, method='nearest', log_sca
grid_data = {}
value = data[value_key]
grid_data[value_key] = griddata((X, Y), value, (xi, yi), method).T
if(log_scale):
grid_data[value_key] = [[0.0 if val<=0.0 else math.log10(val) for val in vals] for vals in
grid_data[value_key]]
grid_data[x_key] = xi
grid_data[y_key] = yi

return grid_data



def data2gridbox(data, x_key, y_key, value_key, xmin, ymin, xmax, ymax,npts=500, method='nearest',
log_scale=False):
def data2gridbox(data, x_key, y_key, value_key, xmin, ymin, xmax, ymax,npts=500, method='nearest'):
'''
This function takes a 2D data structure from a data dictionary and creates
a 2D grid for each array by interpolating in a user defined region.
Expand Down Expand Up @@ -186,18 +182,14 @@ def data2gridbox(data, x_key, y_key, value_key, xmin, ymin, xmax, ymax,npts=500,
grid_data = {}
value = data[value_key]
grid_data[value_key] = griddata((X, Y), value, (xi, yi), method).T
if(log_scale):
grid_data[value_key] = [[0.0 if val<=0.0 else math.log10(val) for val in vals] for vals in
grid_data[value_key]]
grid_data[x_key] = xi
grid_data[y_key] = yi

return grid_data



def data2grid3Dslice(data, x_key, y_key, z_key, value_key, z_slice_value, npts=500,method='nearest',
log_scale=False):
def data2grid3Dslice(data, x_key, y_key, z_key, value_key, z_slice_value, npts=500,method='nearest'):
'''
This function takes a 3D data structure from a data dictionary and creates
a 2D grid for each array by interpolating. This is useful for plotting.
Expand All @@ -222,9 +214,6 @@ def data2grid3Dslice(data, x_key, y_key, z_key, value_key, z_slice_value, npts=5
grid_data = {}
V = data[value_key]
grid_data[value_key] = griddata((X, Y, Z), V, (xi, yi, zi), method).T[0]
if(log_scale):
grid_data[value_key] = [[0.0 if val<=0.0 else math.log10(val) for val in vals] for vals in
grid_data[value_key]]
grid_data[x_key] = xi.T[0]
grid_data[y_key] = yi.T[0]

Expand Down Expand Up @@ -418,8 +407,7 @@ def extract_series_line(data_list,series_key,value_key,dim_keys,point0_values,po

return t, grid

def extract_series_2d(data_list, series_key, value_key, dim_keys, npts=500, method='nearest',
log_scale=False, box=[]):
def extract_series_2d(data_list, series_key, value_key, dim_keys, npts=500, method='nearest', box=[]):
'''
This function extracts the data values along a specified line from a
series of data dictionaries.
Expand Down Expand Up @@ -448,18 +436,18 @@ def extract_series_2d(data_list, series_key, value_key, dim_keys, npts=500, meth
data[value_key].shape[0] == data[dim_keys[1]].shape[0]):
grid.append(data)
else:
grid.append(data2grid(data, dim_keys[0], dim_keys[1], value_key, npts, method, log_scale))
grid.append(data2grid(data, dim_keys[0], dim_keys[1], value_key, npts, method))
else:
grid.append(data2gridbox(data, dim_keys[0], dim_keys[1], value_key, box[0], box[1],
box[2], box[3],npts,method, log_scale))
box[2], box[3],npts,method))

t = {}
t[series_key] = array(T)

return t, grid

def extract_series_2d_slice(data_list,series_key,value_key,dim_keys, slice_value, npts=500,
method='nearest', log_scale=False):
method='nearest'):
'''
This function extracts the data values along a specified line from a
series of data dictionaries.
Expand Down Expand Up @@ -487,7 +475,7 @@ def extract_series_2d_slice(data_list,series_key,value_key,dim_keys, slice_value
sys.exit(0)

grid.append(data2grid3Dslice(data, dim_keys[0], dim_keys[1], dim_keys[2],value_key,
slice_value, npts, method, log_scale))
slice_value, npts, method))

t = {}
t[series_key] = array(T)
Expand Down
16 changes: 8 additions & 8 deletions opppy/interactive_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def plot_output(self, args):
try:
fig = figure(figsize=(xsize,ysize))
except:
PyPloter.switch_backend('agg')
plt.switch_backend('agg')
fig = figure(figsize=(xsize,ysize))

xlog_flag = 0
Expand Down Expand Up @@ -863,13 +863,13 @@ def plot_series_contour(self, args):
sys.exit(0)
tracer_t, tracer_grid = extract_series_2d_slice(dictionary_list, args.series_key,
args.data_name, args.dimension_keys, args.z_slice_location,
args.number_of_points, args.interpolation_method, args.log_scale)
args.number_of_points, args.interpolation_method)
else:
if len(args.dimension_keys) != 2:
print('Error: z_slice_location specified is not specified so length of dimension_keys must be 2')
tracer_t, tracer_grid = extract_series_2d(dictionary_list, args.series_key,
args.data_name, args.dimension_keys, args.number_of_points,
args.interpolation_method, args.log_scale)
args.interpolation_method)
series_data = series_pair(tracer_t, tracer_grid)
elif args.pickle_file is not None:
dictionary = pickle.load(open(args.pickle_file,'rb'))
Expand All @@ -885,13 +885,13 @@ def plot_series_contour(self, args):
sys.exit(0)
tracer_t, tracer_grid = extract_series_2d_slice(dictionary_list, args.series_key,
args.data_name, args.dimension_keys, args.z_slice_location,
args.number_of_points, args.interpolation_method, args.log_scale)
args.number_of_points, args.interpolation_method)
else:
if len(args.dimension_keys) != 2:
print('Error: z_slice_location specified is not specified so length of dimension_keys must be 2')
tracer_t, tracer_grid = extract_series_2d(dictionary_list, args.series_key,
args.data_name, args.dimension_keys, args.number_of_points,
args.interpolation_method, args.log_scale)
args.interpolation_method)
series_data = series_pair(tracer_t, tracer_grid)
if args.case_file is not None:
dictionary_list = build_case_data_list(args.case_file, None, self.dump_parser, args.key_words)
Expand All @@ -903,13 +903,13 @@ def plot_series_contour(self, args):
sys.exit(0)
tracer_t, tracer_grid = extract_series_2d_slice(dictionary_list, args.series_key,
args.data_name, args.dimension_keys, args.z_slice_location,
args.number_of_points, args.interpolation_method, args.log_scale)
args.number_of_points, args.interpolation_method)
else:
if len(args.dimension_keys) != 2:
print('Error: z_slice_location specified is not specified so length of dimension_keys must be 2')
tracer_t, tracer_grid = extract_series_2d(dictionary_list, args.series_key,
args.data_name, args.dimension_keys, args.number_of_points,
args.interpolation_method, args.log_scale)
args.interpolation_method)
series_data = series_pair(tracer_t, tracer_grid)

args.x_value_name= args.dimension_keys[0]
Expand Down Expand Up @@ -1181,7 +1181,7 @@ def plot_interactive_tally(self, args):
try:
fig = figure(figsize=(xsize,ysize))
except:
PyPloter.switch_backend('agg')
plt.switch_backend('agg')
fig = figure(figsize=(xsize,ysize))

xlog_flag = 0
Expand Down
52 changes: 28 additions & 24 deletions opppy/plot_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
plot_dictionary

'''
import matplotlib.pyplot as PyPloter
import matplotlib.pyplot as plt
import matplotlib.axes as axes
import string, sys, os
import numpy as np
Expand All @@ -25,6 +25,10 @@

from opppy.plotting_help import *

# Remove empty legend box on all plots
plt.rcParams['legend.frameon']=False
plt.rcParams['legend.edgecolor']='none'

class plot_dictionary():
'''
This class encapsolates a basic dictionary plotter. The important class
Expand Down Expand Up @@ -95,7 +99,7 @@ def plot_dict(self, args, dictionaries, data_names):
data_names names associated with the dictionaries to be plotted
'''
if(args.hide_plot):
PyPloter.switch_backend('agg')
plt.switch_backend('agg')

if len(dictionaries) is not len(data_names):
print("Error: len of dictionaries do not match length of associated data names")
Expand Down Expand Up @@ -209,19 +213,19 @@ def plot_dict(self, args, dictionaries, data_names):
last_y.append(y[-1])

if(args.font_size is not None):
PyPloter.rcParams.update({'font_size':args.font_size})
plt.rcParams.update({'font_size':args.font_size})

if(args.plot_max):
last_y.append(sum(sorted(y,reverse=True)[0:2])/3.0)
last_x.append(x[-1])
elif(data_line_color != '' and data_line_type != ''):
PyPloter.plot(x,y,label = data_name, linestyle = data_line_type, color = data_line_color)
plt.plot(x,y,label = data_name, linestyle = data_line_type, color = data_line_color)
elif(data_line_color != '' ):
PyPloter.plot(x,y,label = data_name, color = data_line_color)
plt.plot(x,y,label = data_name, color = data_line_color)
elif(data_line_type != '' ):
PyPloter.plot(x,y,label = data_name, linestyle = data_line_type)
plt.plot(x,y,label = data_name, linestyle = data_line_type)
else:
PyPloter.plot(x,y,label = data_name)
plt.plot(x,y,label = data_name)

interp_x = x[0]
if(args.plot_arrival):
Expand All @@ -246,44 +250,44 @@ def plot_dict(self, args, dictionaries, data_names):
print(data_name, "max y value ", x[y.index(min(y))], min(y))

if(args.last_point_only):
PyPloter.plot(last_x, last_y, label = data_name)
plt.plot(last_x, last_y, label = data_name)
elif(args.plot_arrival and found_arrival):
color=PyPloter.gca().lines[-1].get_color()
PyPloter.plot(interp_x, args.y_exceeds_value, linestyle=None, color=color, marker='o', label = data_name + " exceeds y="+str(args.y_exceeds_value)+" @ x="+str(interp_x))
color=plt.gca().lines[-1].get_color()
plt.plot(interp_x, args.y_exceeds_value, linestyle=None, color=color, marker='o', label = data_name + " exceeds y="+str(args.y_exceeds_value)+" @ x="+str(interp_x))
elif(args.plot_max):
print("max y= "+str(last_y)+" @ x="+str(last_x))
color=PyPloter.gca().lines[-1].get_color()
PyPloter.plot(last_x, last_y, linestyle=None, color=color, marker='x', label = data_name + " max y="+str(last_y)+" @ x="+str(last_x))
color=plt.gca().lines[-1].get_color()
plt.plot(last_x, last_y, linestyle=None, color=color, marker='x', label = data_name + " max y="+str(last_y)+" @ x="+str(last_x))

if(args.x_label is not None):
PyPloter.xlabel(args.x_label)
plt.xlabel(args.x_label)
else:
PyPloter.xlabel(xname)
plt.xlabel(xname)

if(args.x_limits is not None):
PyPloter.xlim(args.x_limits)
plt.xlim(args.x_limits)

if(args.y_label is not None):
PyPloter.ylabel(args.y_label)
plt.ylabel(args.y_label)
else:
PyPloter.ylabel(dictionary_name)
plt.ylabel(dictionary_name)

if(args.y_limits is not None):
PyPloter.ylim(args.y_limits)
plt.ylim(args.y_limits)

if(args.plot_grid):
PyPloter.grid()
plt.grid()

PyPloter.legend(loc='best')
plt.legend(loc='best')
if(args.log_x):
PyPloter.xscale("log")
plt.xscale("log")
if(args.log_y):
PyPloter.yscale("log")
plt.yscale("log")
if(args.figure_name is not None):
fig = PyPloter.savefig(args.figure_name, dpi=args.figure_resolution)
fig = plt.savefig(args.figure_name, dpi=args.figure_resolution)
print("Plot save as -- "+args.figure_name)
elif(not args.hide_plot):
warnings.filterwarnings("ignore")
PyPloter.show()
plt.show()


Loading