Example #1
0
def setplot(plotdata=None):
    #--------------------------
    """ 
    Specify what is to be plotted at each frame.
    Input:  plotdata, an instance of clawpack.visclaw.data.ClawPlotData.
    Output: a modified version of plotdata.
    
    """

    if plotdata is None:
        from clawpack.visclaw.data import ClawPlotData
        plotdata = ClawPlotData()

    plotdata.clearfigures()  # clear any old figures,axes,items data

    def draw_interface_add_legend(current_data):
        from pylab import plot
        from numpy import abs, where, log10, exp, sin, linspace
        #plot([0., 0.], [-1000., 1000.], 'k--')
        try:
            from clawpack.visclaw import legend_tools
            labels = [
                'Level 1', 'Level 2', 'Level 3', 'Level 4', 'Level 5',
                'Level 6', 'Level 7', 'Level 8', 'Level 9', 'Level 10'
            ]
            legend_tools.add_legend(labels,
                                    colors=amr_color,
                                    markers=amr_marker,
                                    linestyles=amr_linestyle,
                                    loc='upper left')
        except:
            pass

        # exact solution:
        t = current_data.t
        xx = linspace(-12, 12, 10000)
        #xpct = xx + t
        #xmct = xx - t
        #p_true = ar*exp(-betar*(xpct-5)**2) * sin(freqr*xpct) + \
        #         al*exp(-betal*(xmct+5)**2) * sin(freql*xmct)
        p_true = p_true_fcn(xx, t)
        plot(xx, p_true, 'k')

    def draw_interface_add_legend_innerprod(current_data):
        from pylab import plot
        #plot([0., 0.], [-1000., 1000.], 'k--')
        try:
            from clawpack.visclaw import legend_tools
            labels = ['Level 3', 'Level 4']
            legend_tools.add_legend(labels,
                                    colors=['r', 'c'],
                                    markers=['o', '^'],
                                    linestyles=['', ''],
                                    loc='upper left')
        except:
            pass

    def add_grid(current_data):
        from pylab import grid
        grid(True)

    def color_by_level(current_data):
        from pylab import vstack, contourf, plot, ones, arange, colorbar
        fs = current_data.framesoln
        pout, level = gridtools1.grid_output_1d(fs, 0, xout, return_level=True)
        Xout = vstack((xout, xout))
        Yout = vstack((-1.1 * ones(xout.shape), 1.1 * ones(xout.shape)))
        L = vstack((level, level))
        contourf(Xout, Yout, L, v_levels, colors=c_levels)
        cb = colorbar(ticks=range(1, maxlevels + 1))
        cb.set_label('AMR Level')
        plot(xout, pout, 'k')
        #import pdb; pdb.set_trace()

    def error_color_by_level(current_data):
        from pylab import vstack,contourf,plot,ones,arange,colorbar,\
                          ylim,semilogy
        fs = current_data.framesoln
        t = current_data.t
        pout, level = gridtools1.grid_output_1d(fs, 0, xout, return_level=True)
        err = abs(pout - p_true_fcn(xout, t))
        Xout = vstack((xout, xout))
        Yout = vstack((ylimits_error[0] * ones(xout.shape),
                       ylimits_error[1] * ones(xout.shape)))
        L = vstack((level, level))
        contourf(Xout, Yout, L, v_levels, colors=c_levels)
        cb = colorbar(ticks=range(1, maxlevels + 1))
        cb.set_label('AMR Level')
        semilogy(xout, err, 'k')
        #semilogy(xout,level,'k')
        if tolerance is not None:
            plot(xout, tolerance * ones(xout.shape), 'r--')

    # Figure for q[0]
    plotfigure = plotdata.new_plotfigure(name='Pressure and Velocity', figno=1)
    plotfigure.kwargs = {'figsize': (8, 8)}
    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(2,1,1)'  # top figure
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = [-1.1, 1.1]
    plotaxes.title = 'Pressure'
    plotaxes.afteraxes = draw_interface_add_legend

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 0
    plotitem.amr_color = amr_color
    plotitem.amr_plotstyle = amr_plotstyle
    plotitem.amr_data_show = [1, 1, 1]
    plotitem.amr_kwargs = [{
        'markersize': 5
    }, {
        'markersize': 4
    }, {
        'markersize': 3
    }]

    # Figure for error

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(2,1,2)'  # bottom figure
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = [1e-10, 1]
    plotaxes.title = 'abs(Error)'
    plotaxes.afteraxes = add_grid

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='1d_semilogy')
    plotitem.plot_var = abs_error
    plotitem.amr_color = amr_color
    plotitem.amr_plotstyle = amr_plotstyle
    plotitem.amr_data_show = [1, 1, 1, 1, 1]

    plotfigure = plotdata.new_plotfigure(name='Pressure and Error', figno=2)
    plotfigure.show = False
    plotfigure.kwargs = {'figsize': (12, 8)}
    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(2,1,1)'  # top figure
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = [-1.1, 1.1]
    plotaxes.title = 'Pressure'
    plotaxes.beforeaxes = color_by_level
    plotaxes.afteraxes = add_grid  #draw_interface_add_legend

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.show = False
    plotitem.plot_var = 0
    plotitem.amr_color = amr_color
    plotitem.amr_plotstyle = amr_plotstyle
    plotitem.amr_data_show = [1, 1, 1]
    plotitem.amr_kwargs = [{
        'markersize': 5
    }, {
        'markersize': 4
    }, {
        'markersize': 3
    }]

    # Figure for error

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(2,1,2)'  # bottom figure
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits_error
    plotaxes.title = 'abs(Error)'
    plotaxes.beforeaxes = error_color_by_level
    plotaxes.afteraxes = add_grid

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='1d_semilogy')
    plotitem.show = False
    plotitem.plot_var = abs_error
    plotitem.amr_color = amr_color
    plotitem.amr_plotstyle = amr_plotstyle
    plotitem.amr_data_show = [1, 1, 1, 1, 1]

    def plot_finest(current_data):
        from pylab import vstack,contourf,plot,ones,arange,colorbar,\
                          xlim,ylim,semilogy,figure,title,clf,subplot,show,draw,\
                          tight_layout,ylabel,grid

        fs = current_data.framesoln
        t = current_data.t
        print('+++ plot_finest at t = %.4f' % t)
        pout, level = gridtools1.grid_output_1d(fs, 0, xout, return_level=True)
        err = abs(pout - p_true_fcn(xout, t))
        Xout = vstack((xout, xout))
        L = vstack((level, level))
        figure(3, figsize=(12, 8))
        clf()

        subplot(311)
        Yout = vstack((-1.1 * ones(xout.shape), 1.1 * ones(xout.shape)))
        contourf(Xout, Yout, L, v_levels, colors=c_levels)
        cb = colorbar(ticks=range(1, maxlevels + 1))
        cb.set_label('AMR Level')
        plot(xout, pout, 'k')
        xlim(xlimits)
        ylim(-1.1, 1.1)
        title('Pressure at t = %.4f' % t)

        subplot(312)
        Yout = vstack((ylimits_error[0] * ones(xout.shape),
                       ylimits_error[1] * ones(xout.shape)))
        contourf(Xout, Yout, L, v_levels, colors=c_levels)
        cb = colorbar(ticks=range(1, maxlevels + 1))
        cb.set_label('AMR Level')
        semilogy(xout, err, 'k')
        if tolerance is not None:
            plot(xout, tolerance * ones(xout.shape), 'r--')
        xlim(xlimits)
        ylim(ylimits_error)
        ylabel('abs(error)')
        grid(True)

        subplot(313)
        Yout = vstack(
            (0 * ones(xout.shape), (maxlevels + 1) * ones(xout.shape)))
        contourf(Xout, Yout, L, v_levels, colors=c_levels)
        cb = colorbar(ticks=range(1, maxlevels + 1))
        cb.set_label('AMR Level')
        plot(xout, level, 'k')
        xlim(xlimits)
        ylim(0, maxlevels + 1)
        ylabel('AMR Level')
        tight_layout()
        grid(True)
        draw()

    plotfigure = plotdata.new_plotfigure(name='finest', figno=3)
    plotfigure.kwargs = {'figsize': (12, 8)}
    plotdata.afterframe = plot_finest

    # Figure for inner product, q[2]

    plotfigure = plotdata.new_plotfigure(name='Inner Product', figno=10)
    plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [-12, 12]
    plotaxes.ylimits = [
        -15, 1
    ]  # use when taking inner product with forward solution
    #plotaxes.ylimits = [-0.01,0.02]    # use when taking inner product with Richardson error
    plotaxes.title = 'log10(Inner Product)'
    plotaxes.afteraxes = draw_interface_add_legend

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='1d')
    plotitem.plot_var = plot_innerprod
    plotitem.amr_color = amr_color
    plotitem.amr_plotstyle = amr_plotstyle
    plotitem.amr_data_show = [0, 1, 1, 1, 0]
    plotitem.show = True  # show on plot?

    # Figure for abs(error)

    plotfigure = plotdata.new_plotfigure(name='Error', figno=11)
    plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [-12, 12]
    plotaxes.ylimits = [-15, 1]
    plotaxes.title = 'log10(Error)'
    plotaxes.afteraxes = draw_interface_add_legend

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='1d')
    plotitem.plot_var = 0  #plot_error
    plotitem.amr_color = amr_color
    plotitem.amr_plotstyle = amr_plotstyle
    plotitem.amr_data_show = [1, 1, 1, 1, 1]
    plotitem.show = True  # show on plot?

    #-----------------------------------------
    # Figures for gauges
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='q', figno=300, \
                                         type='each_gauge')
    plotfigure.clf_each_gauge = True
    plotfigure.kwargs = {'figsize': (10, 10)}

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(211)'
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'Pressure'
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 0
    plotitem.plotstyle = 'b-'

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(212)'
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'Velocity'
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 1
    plotitem.plotstyle = 'b-'

    # Parameters used only when creating html and/or latex hardcopy
    # e.g., via clawpack.visclaw.frametools.printframes:

    plotdata.printfigs = True  # print figures
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = 'all'  # list of frames to print
    plotdata.print_fignos = 'all'  # list of figures to print
    plotdata.html = True  # create html files of plots?
    plotdata.html_homelink = '../README.html'
    plotdata.latex = True  # create latex file of plots?
    plotdata.latex_figsperline = 2  # layout of plots
    plotdata.latex_framesperline = 1  # layout of plots
    plotdata.latex_makepdf = False  # also run pdflatex?

    return plotdata
Example #2
0
def setplot(plotdata=None):
    #--------------------------
    """
    Specify what is to be plotted at each frame.
    Input:  plotdata, an instance of pyclaw.plotters.data.ClawPlotData.
    Output: a modified version of plotdata.

    """

    from clawpack.visclaw import colormaps, geoplot
    from numpy import linspace

    if plotdata is None:
        from clawpack.visclaw.data import ClawPlotData
        plotdata = ClawPlotData()

    plotdata.clearfigures()  # clear any old figures,axes,items data
    plotdata.format = 'binary'

    def timeformat(t):
        from numpy import mod
        hours = int(t / 3600.)
        tmin = mod(t, 3600.)
        min = int(tmin / 60.)
        sec = int(mod(tmin, 60.))
        timestr = '%s:%s:%s' % (hours, str(min).zfill(2), str(sec).zfill(2))
        return timestr

    def title_hours(current_data):
        from pylab import title
        t = current_data.t
        timestr = timeformat(t)
        title('%s after earthquake' % timestr)

    #-----------------------------------------
    # Figure for surface
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Domain and transects', figno=0)
    plotfigure.kwargs = {'figsize': (11, 7)}
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    #plotaxes.axescmd = 'axes([.1,.4,.8,.5])'
    plotaxes.axescmd = 'axes([.1,.1,.4,.8])'
    plotaxes.title = 'Surface'
    #plotaxes.xlimits = [-122.4, -122.16]
    #plotaxes.ylimits = [47.4, 47.8]

    x1_tr1 = -122.29
    x2_tr1 = -122.215
    y1_tr1 = 47.57
    y2_tr1 = 47.705

    x1_tr2 = -122.21
    x2_tr2 = -122.265
    y1_tr2 = 47.4925
    y2_tr2 = 47.545

    def aa_transects(current_data):
        from pylab import ticklabel_format, xticks, plot, text, gca, cos, pi
        title_hours(current_data)
        ticklabel_format(useOffset=False)
        xticks(rotation=20)
        plot([x1_tr1, x2_tr1], [y1_tr1, y2_tr1], 'w')
        plot([x1_tr2, x2_tr2], [y1_tr2, y2_tr2], 'w')
        text(x2_tr1 - 0.01,
             y2_tr1 + 0.005,
             'Transect 1',
             color='w',
             fontsize=8)
        text(x1_tr2 - 0.01,
             y1_tr2 - 0.008,
             'Transect 2',
             color='w',
             fontsize=8)
        gca().set_aspect(1. / cos(48 * pi / 180.))
        #addgauges(current_data)

    plotaxes.afteraxes = aa_transects

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = surface_or_depth_lake
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = cmin
    plotitem.pcolor_cmax = cmax
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [0, 0, 0, 0]
    plotitem.amr_data_show = [1, 1, 1, 1, 1, 0, 0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.land
    plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = cmax_land
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0]
    plotitem.amr_patchedges_show = [0, 0, 0, 0]
    plotitem.amr_data_show = [1, 1, 1, 1, 1, 0, 0]

    # add contour lines of bathy if desired:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    #plotitem.show = False
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = [sea_level]
    plotitem.amr_contour_colors = ['g']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid', 'linewidths': 0.5}
    plotitem.amr_contour_show = [0, 1, 0, 0]  # only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0

    #-----------------------------------------
    # Plots along transect:
    #-----------------------------------------

    eta1 = lambda q: q[3, :, :]
    B1 = lambda q: q[3, :, :] - q[0, :, :]

    def plot_xsec(current_data):
        import matplotlib.pyplot as plt
        import numpy
        import gridtools
        from clawpack.pyclaw import Solution

        framesoln = current_data.framesoln

        topo_color = [.8, 1, .8]
        water_color = [.5, .5, 1]

        plt.figure(0)

        # Transect 1:
        plt.axes([.55, .5, .4, .3])
        xout = numpy.linspace(x1_tr1, x2_tr1, 1000)
        yout = numpy.linspace(y1_tr1, y2_tr1, 1000)
        eta = gridtools.grid_output_2d(framesoln, eta1, xout, yout)
        topo = gridtools.grid_output_2d(framesoln, B1, xout, yout)

        eta = numpy.where(eta > topo, eta, numpy.nan)

        plt.fill_between(yout, eta, topo, color=water_color)
        plt.fill_between(yout, topo, -10000, color=topo_color)
        plt.plot(yout, eta, 'b')
        plt.plot(yout, topo, 'g')
        plt.plot(yout, sea_level + 0 * topo, 'k--')
        #plt.xlim(47.5,47.8)
        plt.ylim(ylim_transects)
        plt.ylabel('meters')
        plt.grid(True)
        timestr = timeformat(framesoln.t)
        plt.title('Elevation on Transect 1')

        # Transect 2:
        plt.axes([.55, .1, .4, .3])
        xout = numpy.linspace(x1_tr2, x2_tr2, 1000)
        yout = numpy.linspace(y1_tr2, y2_tr2, 1000)
        eta = gridtools.grid_output_2d(framesoln, eta1, xout, yout)
        topo = gridtools.grid_output_2d(framesoln, B1, xout, yout)

        eta = numpy.where(eta > topo, eta, numpy.nan)
        topo_color = [.8, 1, .8]
        water_color = [.5, .5, 1]

        plt.fill_between(yout, eta, topo, color=water_color)
        plt.fill_between(yout, topo, -10000, color=topo_color)
        plt.plot(yout, eta, 'b')
        plt.plot(yout, topo, 'g')
        plt.plot(yout, sea_level + 0 * topo, 'k--')
        #plt.xlim(47.5,47.8)
        plt.ylim(ylim_transects)
        plt.ylabel('meters')
        plt.grid(True)
        timestr = timeformat(framesoln.t)
        plt.title('Elevation on Transect 2')

    plotdata.afterframe = plot_xsec

    #-----------------------------------------
    # Figure for zoomed area
    #-----------------------------------------

    # To use, set the limits as desired and set `plotfigure.show = True`
    x1, x2, y1, y2 = [-122.23, -122.2, 47.69, 47.71]
    plotfigure = plotdata.new_plotfigure(name="zoomed area", figno=11)
    plotfigure.show = False
    plotfigure.kwargs = {'figsize': (8, 7)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.scaled = False

    plotaxes.xlimits = [x1, x2]
    plotaxes.ylimits = [y1, y2]

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi
        title_hours(current_data)
        ticklabel_format(useOffset=False)
        xticks(rotation=20)
        gca().set_aspect(1. / cos(48 * pi / 180.))

    plotaxes.afteraxes = aa

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = surface_or_depth_lake
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = cmin
    plotitem.pcolor_cmax = cmax
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.patchedges_show = 0

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.land
    plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = cmax_land
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0]
    plotitem.patchedges_show = 0

    #-----------------------------------------
    # Figures for gauges
    #-----------------------------------------

    time_scale = 1. / 3600.
    time_label = 'hours'

    plotfigure = plotdata.new_plotfigure(name='gauge depth', figno=300, \
                    type='each_gauge')

    #plotfigure.clf_each_gauge = False

    def setglimits_depth(current_data):
        from pylab import xlim, ylim, title, argmax, show, array, ylabel
        gaugeno = current_data.gaugeno
        q = current_data.q
        depth = q[0, :]
        t = current_data.t
        g = current_data.plotdata.getgauge(gaugeno)
        level = g.level
        maxlevel = max(level)

        #find first occurrence of the max of levels used by
        #this gauge and set the limits based on that time
        argmax_level = argmax(level)
        xlim(time_scale * array(t[argmax_level], t[-1]))
        ylabel('meters')
        min_depth = depth[argmax_level:].min()
        max_depth = depth[argmax_level:].max()
        ylim(min_depth - 0.5, max_depth + 0.5)
        title('Gauge %i : Flow Depth (h)\n' % gaugeno + \
              'max(h) = %7.3f,    max(level) = %i' %(max_depth,maxlevel))
        #show()

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.time_scale = time_scale
    plotaxes.time_label = time_label

    # Plot depth as blue curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 0
    plotitem.plotstyle = 'b-'

    ## Set the limits and the title in the function below
    plotaxes.afteraxes = setglimits_depth

    plotfigure = plotdata.new_plotfigure(name='gauge surface eta', figno=301, \
                    type='each_gauge')

    #plotfigure.clf_each_gauge = False

    def setglimits_eta(current_data):
        from pylab import xlim, ylim, title, argmax, show, array, ylabel
        gaugeno = current_data.gaugeno
        q = current_data.q
        eta = q[3, :]
        t = current_data.t
        g = current_data.plotdata.getgauge(gaugeno)
        level = g.level
        maxlevel = max(level)

        #find first occurrence of the max of levels used by
        #this gauge and set the limits based on that time
        argmax_level = argmax(level)  #first occurrence of it
        xlim(time_scale * array(t[argmax_level], t[-1]))
        ylabel('meters')
        min_eta = eta[argmax_level:].min()
        max_eta = eta[argmax_level:].max()
        ylim(min_eta - 0.5, max_eta + 0.5)
        title('Gauge %i : Surface Elevation (eta)\n' % gaugeno + \
              'max(eta) = %7.3f,    max(level) = %i' %(max_eta,maxlevel))
        #show()

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.time_scale = time_scale
    plotaxes.time_label = time_label

    # Plot surface (eta) as blue curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 3
    plotitem.plotstyle = 'b-'

    ## Set the limits and the title in the function below
    plotaxes.afteraxes = setglimits_eta

    plotfigure = plotdata.new_plotfigure(name='speed', figno=302, \
                    type='each_gauge')

    #plotfigure.clf_each_gauge = False

    def speed(current_data):
        from numpy import sqrt, maximum, where
        q = current_data.q
        h = q[0, :]
        hu = q[1, :]
        hv = q[2, :]
        s = sqrt(hu**2 + hv**2) / maximum(h, 0.001)
        s = where(h > 0.001, s, 0.0)
        return s

    def setglimits_speed(current_data):
        from pylab import xlim, ylim, title, argmax, show, array, ylabel
        gaugeno = current_data.gaugeno
        s = speed(current_data)
        t = current_data.t
        g = current_data.plotdata.getgauge(gaugeno)
        level = g.level
        maxlevel = max(level)

        #find first occurrence of the max of levels used by
        #this gauge and set the limits based on that time
        argmax_level = argmax(level)  #first occurrence of it
        xlim(time_scale * array(t[argmax_level], t[-1]))
        ylabel('meters/sec')
        min_speed = s[argmax_level:].min()
        max_speed = s[argmax_level:].max()
        ylim(min_speed - 0.5, max_speed + 0.5)
        title('Gauge %i : Speed (s)\n' % gaugeno + \
              'max(s) = %7.3f,    max(level) = %i' %(max_speed,maxlevel))
        #show()

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.time_scale = time_scale
    plotaxes.time_label = time_label

    # Plot speed (s) as blue curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = speed
    plotitem.plotstyle = 'b-'

    ## Set the limits and the title in the function below
    plotaxes.afteraxes = setglimits_speed

    #-----------------------------------------
    # Figures for fgmax plots
    #-----------------------------------------
    # Note: need to move fgmax png files into _plots after creating with
    #   python run_process_fgmax.py
    # This just creates the links to these figures...

    if 0:
        ### Putting them in _other_figures with the proper name as a link
        ### Can run process fgmax either before or after setplot now.
        otherfigure = plotdata.new_otherfigure(name='max depth',
                        fname='_other_figures/%s_%s_h_onshore.png' \
                                % (params.loc,params.event))
        otherfigure = plotdata.new_otherfigure(name='max depth on GE image',
                        fname='_other_figures/%s_%s_h_onshore_GE.png' \
                                % (params.loc,params.event))
        otherfigure = plotdata.new_otherfigure(name='max speed',
                        fname='_other_figures/%s_%s_speed.png' \
                                % (params.loc,params.event))

    # Plots of timing (CPU and wall time):

    def make_timing_plots(plotdata):
        import os
        from clawpack.visclaw import plot_timing_stats
        try:
            timing_plotdir = plotdata.plotdir + '/_timing_figures'
            os.system('mkdir -p %s' % timing_plotdir)
            units = {
                'comptime': 'hours',
                'simtime': 'hours',
                'cell': 'billions'
            }
            plot_timing_stats.make_plots(outdir=plotdata.outdir,
                                         make_pngs=True,
                                         plotdir=timing_plotdir,
                                         units=units)
            os.system('cp %s/timing.* %s' % (plotdata.outdir, timing_plotdir))
        except:
            print('*** Error making timing plots')

    otherfigure = plotdata.new_otherfigure(name='timing',
                                           fname='_timing_figures/timing.html')
    otherfigure.makefig = make_timing_plots

    #-----------------------------------------

    # Parameters used only when creating html and/or latex hardcopy
    # e.g., via pyclaw.plotters.frametools.printframes:

    plotdata.printfigs = True  # print figures
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = 'all'  # list of frames to print
    plotdata.print_gaugenos = 'all'  # list of gauges to print
    plotdata.print_fignos = 'all'  # list of figures to print
    plotdata.html = True  # create html files of plots?
    plotdata.html_homelink = '../README.html'  # pointer for top of index
    plotdata.latex = True  # create latex file of plots?
    plotdata.latex_figsperline = 2  # layout of plots
    plotdata.latex_framesperline = 1  # layout of plots
    plotdata.latex_makepdf = False  # also run pdflatex?
    plotdata.parallel = True  # make multiple frame png's at once

    return plotdata