def set_plotdata(self): from clawpack.visclaw import data from clawpack.visclaw import frametools plotdata = data.ClawPlotData() plotdata.setplot = self.setplot self.plotdata = frametools.call_setplot(self.setplot, plotdata) plotdata._mode = 'iplotclaw'
def __init__(self, setplot='setplot.py', outdir=None, \ completekey='tab', stdin=None, stdout=None): """Instantiate a line-oriented interpreter framework. The optional argument 'completekey' is the readline name of a completion key; it defaults to the Tab key. If completekey is not None and the readline module is available, command completion is done automatically. The optional arguments stdin and stdout specify alternate input and output file objects; if not specified, sys.stdin and sys.stdout are used. """ import sys if stdin is not None: self.stdin = stdin else: self.stdin = sys.stdin if stdout is not None: self.stdout = stdout else: self.stdout = sys.stdout self.cmdqueue = [] self.completekey = completekey self.setplot = setplot plotdata = data.ClawPlotData() plotdata.setplot = self.setplot plotdata._mode = 'iplotclaw' if outdir is None: try: # possibly set by 'make .output' and stored in .output: dot_output = open('.output', 'r') outdir = dot_output.readline().strip() dot_output.close() except: outdir = '.' plotdata.outdir = outdir # Note also that outdir might be reset by setplot! try: plotdata = frametools.call_setplot(self.setplot, plotdata) except: print '*** Problem executing setplot in Iplotclaw' #print ' plotdata = ', plotdata print ' setplot = ', self.setplot print '*** Either this file does not exist or ' print ' there is a problem executing the function setplot in this file.' print '*** PLOT PARAMETERS MAY NOT BE SET! ***' raise #return self.plotdata = plotdata self.prevplotdata = plotdata self.restart = False self.prevframeno = 0
def setup(): # Create plotdata object for reading in gauges in tests below: global plotdata global olddir plotdata = data.ClawPlotData() plotdata.outdir = '_output' # Now set current working directory to regression_tests.py olddir = os.getcwd() testdir = os.path.abspath(os.path.dirname(__file__)) os.chdir(testdir)
def plot_contour(data_dir="./_output", out_dir='./', num_layers=2, num_frames=1000, ref_lines=[-130e3, -30e3], color=True): """Plot a contour plot of a shelf based simluation""" # Create plot data plot_data = data.ClawPlotData() plot_data.outdir = data_dir # Read in bathymetry sol = [Solution(0, path=data_dir, read_aux=True)] b = sol[0].state.aux[0, :] # Extract x coordinates, this assumes that these do not change through the # simluation (they should not) x = sol[0].state.grid.dimensions[0].centers # Read in all solutions print "Reading in solutions..." for frame in xrange(1, num_frames): try: sol.append(Solution(frame, path=data_dir)) except IOError: # We have reached the last frame before given num_frames reached num_frames = frame - 1 break print "Found %s frames to plot." % num_frames # Create plotting arrays print "Constructing plotting variables..." eta = np.ndarray((num_frames, num_layers, len(x))) t = np.ndarray((num_frames)) for frame in xrange(num_frames): # Append data to eta and t lists t[frame] = sol[frame].t / 3600.0 # Calculate from the bottom up layer_index = 2 * (num_layers - 1) eta[frame, num_layers - 1, :] = sol[frame].q[layer_index, :] / rho[-1] + b # Calculate the rest of the layers for layer in xrange(num_layers - 2, -1, -1): layer_index = 2 * layer eta[frame, layer, :] = sol[frame].q[layer_index, :] / rho[layer] + eta[ frame, layer + 1, :] # Create mesh grid for plot X, T = np.meshgrid(x, t) # Plot the contours of each layer clines = np.linspace(.025, .4, 8) title = ['top', 'internal'] print "Creating plots..." fig = plt.figure(figsize=[10, 8]) for layer in xrange(num_layers): axes = fig.add_subplot(1, num_layers, layer + 1) # Plot positive and negative contours eta_plot = eta[:, layer, :] - eta_init[layer] plot = axes.contour(X, T, eta_plot, clines, colors='r') plot = axes.contour(X, T, eta_plot, -clines, colors='b') for ref_line in ref_lines: axes.plot([ref_line, ref_line], [0, 2], 'k:') # X ticks and labels axes.set_xticks([-300e3, -200e3, -100e3, -30e3]) axes.set_xticklabels([300, 200, 100, 30], fontsize=15) axes.set_xlabel("Kilometers offshore", fontsize=15) axes.set_xlim([-200e3, 0.0]) # First plot from left to right, write y ticks if layer == 0: plt.yticks(fontsize=15) axes.set_ylabel("Hours", fontsize=20) else: # Remove tick labels axes.set_yticklabels(['' for label in axes.get_yticklabels()]) axes.set_title("Contours of %s surface" % title[layer], fontsize=15) file_name = os.path.join(out_dir, "contour.png") print "Writing out to %s" % file_name plt.savefig(file_name)