|
| 1 | + |
| 2 | +""" |
| 3 | +Set up the plot figures, axes, and items to be done for each frame. |
| 4 | +
|
| 5 | +This module is imported by the plotting routines and then the |
| 6 | +function setplot is called to set the plot parameters. |
| 7 | +
|
| 8 | +""" |
| 9 | + |
| 10 | +from __future__ import absolute_import |
| 11 | +from __future__ import print_function |
| 12 | +import os |
| 13 | +if os.path.exists('./1drad/_output'): |
| 14 | + qref_dir = os.path.abspath('./1drad/_output') |
| 15 | +else: |
| 16 | + qref_dir = None |
| 17 | + print("Directory ./1drad/_output not found") |
| 18 | + |
| 19 | + |
| 20 | +#-------------------------- |
| 21 | +def setplot(plotdata=None): |
| 22 | +#-------------------------- |
| 23 | + |
| 24 | + """ |
| 25 | + Specify what is to be plotted at each frame. |
| 26 | + Input: plotdata, an instance of clawpack.visclaw.data.ClawPlotData. |
| 27 | + Output: a modified version of plotdata. |
| 28 | +
|
| 29 | + """ |
| 30 | + |
| 31 | + if plotdata is None: |
| 32 | + from clawpack.visclaw.data import ClawPlotData |
| 33 | + plotdata = ClawPlotData() |
| 34 | + |
| 35 | + |
| 36 | + from clawpack.visclaw import colormaps |
| 37 | + from clawpack.clawutil.data import ClawData |
| 38 | + |
| 39 | + # determine original computational domain |
| 40 | + abldata = ClawData() |
| 41 | + abldata.read(plotdata.outdir + '/abl.data', force=True) |
| 42 | + clawdata = ClawData() |
| 43 | + clawdata.read(plotdata.outdir + '/claw.data', force=True) |
| 44 | + clawdata.lower[0] += abldata.depth_lower[0] |
| 45 | + clawdata.upper[0] -= abldata.depth_upper[0] |
| 46 | + clawdata.lower[1] += abldata.depth_lower[1] |
| 47 | + clawdata.upper[1] -= abldata.depth_upper[1] |
| 48 | + |
| 49 | + plotdata.clearfigures() # clear any old figures,axes,items data |
| 50 | + |
| 51 | + |
| 52 | + # Figure for pressure |
| 53 | + # ------------------- |
| 54 | + |
| 55 | + plotfigure = plotdata.new_plotfigure(name='Pressure', figno=0) |
| 56 | + |
| 57 | + # Set up for axes in this figure: |
| 58 | + plotaxes = plotfigure.new_plotaxes() |
| 59 | + plotaxes.xlimits = 'auto' |
| 60 | + plotaxes.ylimits = 'auto' |
| 61 | + plotaxes.title = 'Pressure' |
| 62 | + plotaxes.scaled = True # so aspect ratio is 1 |
| 63 | + |
| 64 | + # Set up for item on these axes: |
| 65 | + plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor') |
| 66 | + plotitem.plot_var = 0 |
| 67 | + plotitem.pcolor_cmap = colormaps.blue_yellow_red |
| 68 | + plotitem.pcolor_cmin = -2.0 |
| 69 | + plotitem.pcolor_cmax = 2.0 |
| 70 | + plotitem.add_colorbar = True |
| 71 | + |
| 72 | + def plot_original_domain(current_data): |
| 73 | + from matplotlib.pyplot import gca |
| 74 | + ax = gca() |
| 75 | + x = [clawdata.lower[0], clawdata.upper[0], clawdata.upper[0], \ |
| 76 | + clawdata.lower[0], clawdata.lower[0]] |
| 77 | + y = [clawdata.lower[1], clawdata.lower[1], clawdata.upper[1], \ |
| 78 | + clawdata.upper[1], clawdata.lower[1]] |
| 79 | + ax.plot(x, y, '--k') |
| 80 | + |
| 81 | + plotaxes.afteraxes = plot_original_domain |
| 82 | + |
| 83 | + # Figure for scatter plot |
| 84 | + # ----------------------- |
| 85 | + |
| 86 | + plotfigure = plotdata.new_plotfigure(name='scatter', figno=3) |
| 87 | + plotfigure.show = (qref_dir is not None) # don't plot if 1d solution is missing |
| 88 | + |
| 89 | + # Set up for axes in this figure: |
| 90 | + plotaxes = plotfigure.new_plotaxes() |
| 91 | + plotaxes.xlimits = [0,1.5] |
| 92 | + plotaxes.ylimits = [-2.,4.] |
| 93 | + plotaxes.title = 'Scatter plot' |
| 94 | + |
| 95 | + # Set up for item on these axes: scatter of 2d data |
| 96 | + plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data') |
| 97 | + |
| 98 | + def p_vs_r(current_data): |
| 99 | + # Return radius of each grid cell and p value in the cell |
| 100 | + from numpy.ma import MaskedArray, masked_where |
| 101 | + from pylab import sqrt |
| 102 | + x = current_data.x |
| 103 | + y = current_data.y |
| 104 | + r = sqrt(x**2 + y**2) |
| 105 | + r = masked_where(x < clawdata.lower[0], r) |
| 106 | + r = masked_where(x > clawdata.upper[0], r) |
| 107 | + r = masked_where(y < clawdata.lower[1], r) |
| 108 | + r = masked_where(y > clawdata.upper[1], r) |
| 109 | + q = current_data.q |
| 110 | + p = MaskedArray(q[0,:,:], mask=r.mask) |
| 111 | + return r,p |
| 112 | + |
| 113 | + plotitem.map_2d_to_1d = p_vs_r |
| 114 | + plotitem.plot_var = 0 |
| 115 | + plotitem.plotstyle = 'o' |
| 116 | + plotitem.color = 'b' |
| 117 | + plotitem.show = (qref_dir is not None) # show on plot? |
| 118 | + |
| 119 | + # Set up for item on these axes: 1d reference solution |
| 120 | + plotitem = plotaxes.new_plotitem(plot_type='1d_plot') |
| 121 | + plotitem.outdir = qref_dir |
| 122 | + plotitem.plot_var = 0 |
| 123 | + plotitem.plotstyle = '-' |
| 124 | + plotitem.color = 'r' |
| 125 | + plotitem.kwargs = {'linewidth': 2} |
| 126 | + plotitem.show = True # show on plot? |
| 127 | + |
| 128 | + def make_legend(current_data): |
| 129 | + import matplotlib.pyplot as plt |
| 130 | + plt.legend(('2d data', '1d reference solution')) |
| 131 | + |
| 132 | + plotaxes.afteraxes = make_legend |
| 133 | + |
| 134 | + |
| 135 | + # Parameters used only when creating html and/or latex hardcopy |
| 136 | + # e.g., via clawpack.visclaw.frametools.printframes: |
| 137 | + |
| 138 | + plotdata.printfigs = True # print figures |
| 139 | + plotdata.print_format = 'png' # file format |
| 140 | + plotdata.print_framenos = 'all' # list of frames to print |
| 141 | + plotdata.print_fignos = 'all' # list of figures to print |
| 142 | + plotdata.html = True # create html files of plots? |
| 143 | + plotdata.html_homelink = '../README.html' # pointer for top of index |
| 144 | + plotdata.html_movie = 'JSAnimation' # new style, or "4.x" for old style |
| 145 | + plotdata.latex = True # create latex file of plots? |
| 146 | + plotdata.latex_figsperline = 2 # layout of plots |
| 147 | + plotdata.latex_framesperline = 1 # layout of plots |
| 148 | + plotdata.latex_makepdf = False # also run pdflatex? |
| 149 | + |
| 150 | + return plotdata |
0 commit comments