Esempio n. 1
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 = 'forestclaw'    # 'ascii' or 'binary' to match setrun.py

    # To plot gauge locations on pcolor or contour plot, use this as
    # an afteraxis function:

    def addgauges(current_data):
        from clawpack.visclaw import gaugetools
        gaugetools.plot_gauge_locations(current_data.plotdata, \
             gaugenos='all', format_string='ko', add_labels=True)

    #-----------------------------------------
    # Figure for surface
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Surface', figno=0)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.title = 'Surface'
    plotaxes.scaled = True

    def fixup(current_data):
        import pylab
        addgauges(current_data)
        t = current_data.t
        t = t / 3600.  # hours
        pylab.title('Surface at %4.2f hours' % t, fontsize=20)
        pylab.xticks(fontsize=15)
        pylab.yticks(fontsize=15)

    plotaxes.afteraxes = fixup

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

    # 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 = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0, 0, 0, 0, 0]
    plotitem.patchedges_show = 1
    plotaxes.xlimits = [-120, -60]
    plotaxes.ylimits = [-60, 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 = linspace(-3000, -3000, 1)
    plotitem.amr_contour_colors = ['y']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid', 'linewidths': 2}
    plotitem.amr_contour_show = [0, 0, 0, 0, 0]
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0

    #-----------------------------------------
    # Figures for gauges
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Surface at gauges', figno=300, \
                    type='each_gauge')
    plotfigure.clf_each_gauge = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'Surface'

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

    # Plot topo as green curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.show = False

    def gaugetopo(current_data):
        q = current_data.q
        h = q[0, :]
        eta = q[3, :]
        topo = eta - h
        return topo

    plotitem.plot_var = gaugetopo
    plotitem.plotstyle = 'g-'

    def add_zeroline(current_data):
        from pylab import plot, legend, xticks, floor, axis, xlabel
        t = current_data.t
        gaugeno = current_data.gaugeno

        if gaugeno == 32412:
            try:
                plot(TG32412[:, 0], TG32412[:, 1], 'r', label='Obs')
                legend(['GeoClaw', 'Obs'], loc='lower right')
            except:
                pass
            axis((0, t.max(), -0.3, 0.3))

        plot(t, 0 * t, 'k')
        n = int(floor(t.max() / 3600.) + 2)
        xticks([3600 * i for i in range(n)], ['%i' % i for i in range(n)])
        xlabel('time (hours)')

    plotaxes.afteraxes = add_zeroline

    #-----------------------------------------
    # Plots of timing (CPU and wall time):

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

    otherfigure = plotdata.new_otherfigure(name='timing plots',
                                           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 = False  # 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 = False  # make multiple frame png's at once

    return plotdata
Esempio n. 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'


    # To plot gauge locations on pcolor or contour plot, use this as
    # an afteraxis function:

    def addgauges(current_data):
        from clawpack.visclaw import gaugetools
        gaugetools.plot_gauge_locations(current_data.plotdata, \
             gaugenos='all', format_string='ko', add_labels=True)
    

    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='Surface', figno=0)
    plotfigure.kwargs = {'figsize':(8,5)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Surface'
    plotaxes.scaled = False # need to set aspect ratio properly for lat/long

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

    plotaxes.afteraxes = aa
    #plotaxes.xlimits = [-122.7,-122.16]
    #plotaxes.ylimits = [47.2,48.3]

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = cmin
    plotitem.pcolor_cmax = cmax
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = 0.8
    plotitem.amr_celledges_show = [0]
    #plotitem.celledges_show = 0
    #plotitem.patchedges_show = 0
    plotitem.amr_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




    #-----------------------------------------
    # Figure for zoom on Eagle Harbor
    #-----------------------------------------
    
    plotfigure = plotdata.new_plotfigure(name="fgmax region", figno=11)
    #plotfigure.show = False
    plotfigure.kwargs = {'figsize': (9,6)}

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

    plotaxes.xlimits = [-122.55,-122.48]
    plotaxes.ylimits = [47.61,47.64]
    if bg_image:
        plotaxes.beforeaxes = background_image

    plotaxes.afteraxes = aa

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = cmin
    plotitem.pcolor_cmax = cmax
    plotitem.add_colorbar = True
    plotitem.amr_data_show = [0,0,1] # only show on finest
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.patchedges_show = 0

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = False
    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

    # 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 = [0]
    plotitem.amr_contour_colors = ['yellow']  # color on each level
    plotitem.kwargs = {'linestyles':'solid','linewidths':2}
    plotitem.amr_contour_show = [0,0,1]  
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    
    #-----------------------------------------
    # Figure for zoom on Bainbridge / Seattle
    #-----------------------------------------
    
    plotfigure = plotdata.new_plotfigure(name="Bainbridge", figno=12)
    # not needed for this small domain
    plotfigure.show = False
    plotfigure.kwargs = {'figsize': (9,6)}

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

    plotaxes.xlimits = [-122.65, -122.3]
    plotaxes.ylimits = [47.5, 47.76]

    plotaxes.afteraxes = aa

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    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
    #-----------------------------------------

    plotfigure = plotdata.new_plotfigure(name='gauge plot', figno=300, \
                    type='each_gauge')
    plotfigure.kwargs = {'figsize': (11,6)}
    #plotfigure.clf_each_gauge = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(2,1,1)'
    #plotaxes.ylimits = [-1,10]
    plotaxes.title = 'Flow depth'
    plotaxes.time_scale = 1./60.
    plotaxes.time_label = ''
    
    def add_ylabel_depth(current_data):
        from pylab import ylabel, grid
        ylabel('water depth (m)')
        grid(True)
        
    plotaxes.afteraxes = add_ylabel_depth

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


    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(2,1,2)'
    #plotaxes.ylimits = [-1,10]
    plotaxes.title = 'Flow speed (m/s)'
    plotaxes.time_scale = 1./60.
    plotaxes.time_label = 'minutes'

    def add_ylabel_speed(current_data):
        from pylab import ylabel, tight_layout, grid
        ylabel('speed (m/s)')
        grid(True)
        tight_layout()
        
    plotaxes.afteraxes = add_ylabel_speed
    
    def speed(current_data):
        from numpy import sqrt, maximum
        q = current_data.q
        h = q[0,:]
        hu = q[1,:]
        hv = q[2,:]
        s = sqrt(hu**2 + hv**2) / maximum(h,0.001)
        return s
        
    # Plot depth as blue curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = speed
    plotitem.plotstyle = 'b-'
    

    #-----------------------------------------
    # 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:
        otherfigure = plotdata.new_otherfigure(name='max depth',
                        fname='depth.png')
        otherfigure = plotdata.new_otherfigure(name='max speed',
                        fname='speed.png')



    #-----------------------------------------
    
    # 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
Esempio n. 3
0
def setplot(plotdata=None):
    #--------------------------
    """ 
    Specify what is to be plotted at each frame.
    Input:  plotdata, an instance of visclaw.data.ClawPlotData.
    Output: a modified version of plotdata.
    
    """

    from clawpack.visclaw import colormaps

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

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

    # Figure for pcolor plot
    plotfigure = plotdata.new_plotfigure(name='pcolor', figno=0)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0, 1]
    plotaxes.ylimits = [0, 1]
    plotaxes.title = 'Solution'
    plotaxes.scaled = True

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = 0
    plotitem.pcolor_cmap = colormaps.yellow_red_blue
    plotitem.pcolor_cmin = 0.1
    plotitem.pcolor_cmax = 1.
    plotitem.add_colorbar = True

    plotitem.amr_celledges_show = [0]
    plotitem.amr_patchedges_show = [0]

    # Figure for contour plot
    plotfigure = plotdata.new_plotfigure(name='contour', figno=1)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0, 1]
    plotaxes.ylimits = [0, 1]
    plotaxes.title = 'Solution'
    plotaxes.scaled = True
    plotaxes.afteraxes = addgauges

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = 0
    plotitem.contour_nlevels = 20
    plotitem.contour_min = 0.01
    plotitem.contour_max = 0.99
    plotitem.amr_contour_show = [0, 0, 1, 1]
    plotitem.amr_contour_colors = ['g', 'g', 'r', 'b']  # color on each level
    plotitem.amr_patch_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee', '#ddffff']
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0

    # Figure for grid cells
    plotfigure = plotdata.new_plotfigure(name='cells', figno=2)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0, 1]
    plotaxes.ylimits = [0, 1]
    plotaxes.title = 'Grid patches'
    plotaxes.scaled = True

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_patch')
    plotitem.amr_patch_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee', '#ddffff']
    plotitem.amr_celledges_show = [1, 0, 0]
    plotitem.amr_patchedges_show = [1]

    #-----------------------------------------
    # Figures for gauges
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='q', figno=300, \
                    type='each_gauge')
    plotfigure.clf_each_gauge = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'q'

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

    #-----------------------------------------
    # Plots of timing (CPU and wall time):

    def make_timing_plots(plotdata):
        from clawpack.visclaw import plot_timing_stats
        import os, sys
        try:
            timing_plotdir = plotdata.plotdir + '/_timing_figures'
            os.system('mkdir -p %s' % timing_plotdir)
            # adjust units for plots based on problem:
            units = {
                'comptime': 'seconds',
                'simtime': 'dimensionless',
                'cell': 'millions'
            }
            plot_timing_stats.make_plots(outdir=plotdata.outdir,
                                         make_pngs=True,
                                         plotdir=timing_plotdir,
                                         units=units)
        except:
            print('*** Error making timing plots')

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

    # Parameters used only when creating html and/or latex hardcopy
    # e.g., via 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'  # pointer for top of index
    plotdata.html_movie = 'JSAnimation'  # new style, or "4.x" for old style
    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
Esempio n. 4
0
def setplot(plotdata=None):
    """"""

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

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

    # Load data from output
    clawdata = clawutil.ClawInputData(2)
    clawdata.read(os.path.join(plotdata.outdir, 'claw.data'))
    physics = geodata.GeoClawData()
    physics.read(os.path.join(plotdata.outdir, 'geoclaw.data'))
    surge_data = geodata.SurgeData()
    surge_data.read(os.path.join(plotdata.outdir, 'surge.data'))
    friction_data = geodata.FrictionData()
    friction_data.read(os.path.join(plotdata.outdir, 'friction.data'))

    # Load storm track
    track = surgeplot.track_data(os.path.join(plotdata.outdir, 'fort.track'))

    # Set afteraxes function
    def surge_afteraxes(cd):
        surgeplot.surge_afteraxes(cd,
                                  track,
                                  plot_direction=False,
                                  kwargs={"markersize": 4})

    # Color limits
    surface_range = 5.0
    eta = physics.sea_level
    if not isinstance(eta, list):
        eta = [eta]
    surface_limits = [eta[0] - surface_range, eta[0] + surface_range]
    speed_limits = [0.0, 3.0]
    wind_limits = [0, 64]
    pressure_limits = [935, 1013]
    friction_bounds = [0.01, 0.04]

    def friction_after_axes(cd):
        plt.title(r"Manning's $n$ Coefficient")

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    regions = {
        "Entire Region": {
            "xlimits": (clawdata.lower[0], clawdata.upper[0]),
            "ylimits": (clawdata.lower[1], clawdata.upper[1]),
            "figsize": (13, 10)
        },
        "Caribbean Sub-region": {
            "xlimits": (-86, -58.0),
            "ylimits": (9, 28),
            "figsize": (16, 6)
        },
    }

    for (name, region_dict) in regions.items():

        # Surface Figure
        plotfigure = plotdata.new_plotfigure(name="Surface - %s" % name)
        plotfigure.kwargs = {"figsize": region_dict['figsize']}
        plotaxes = plotfigure.new_plotaxes()
        plotaxes.title = "Surface"
        plotaxes.xlimits = region_dict["xlimits"]
        plotaxes.ylimits = region_dict["ylimits"]
        plotaxes.afteraxes = surge_afteraxes

        surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
        surgeplot.add_land(plotaxes)
        plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

        # Speed Figure
        plotfigure = plotdata.new_plotfigure(name="Currents - %s" % name)
        plotfigure.kwargs = {"figsize": region_dict['figsize']}
        plotaxes = plotfigure.new_plotaxes()
        plotaxes.title = "Currents"
        plotaxes.xlimits = region_dict["xlimits"]
        plotaxes.ylimits = region_dict["ylimits"]
        plotaxes.afteraxes = surge_afteraxes

        surgeplot.add_speed(plotaxes, bounds=speed_limits)
        surgeplot.add_land(plotaxes)
        plotaxes.plotitem_dict['speed'].amr_patchedges_show = [0] * 10
        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10
    #
    # Friction field
    #
    plotfigure = plotdata.new_plotfigure(name='Friction')
    plotfigure.show = friction_data.variable_friction and False

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Entire Region']['xlimits']
    plotaxes.ylimits = regions['Entire Region']['ylimits']
    # plotaxes.title = "Manning's N Coefficient"
    plotaxes.afteraxes = friction_after_axes
    plotaxes.scaled = True

    surgeplot.add_friction(plotaxes, bounds=friction_bounds, shrink=0.9)
    plotaxes.plotitem_dict['friction'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['friction'].colorbar_label = "$n$"

    #
    #  Hurricane Forcing fields
    #
    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure')
    plotfigure.show = surge_data.pressure_forcing and False

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Entire Region']['xlimits']
    plotaxes.ylimits = regions['Entire Region']['ylimits']
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    surgeplot.add_pressure(plotaxes, bounds=pressure_limits)
    surgeplot.add_land(plotaxes)

    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed')
    plotfigure.show = surge_data.wind_forcing and False

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Entire Region']['xlimits']
    plotaxes.ylimits = regions['Entire Region']['ylimits']
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    surgeplot.add_wind(plotaxes, bounds=wind_limits)
    surgeplot.add_land(plotaxes)

    # ========================================================================
    #  Figures for gauges
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Gauge Surfaces',
                                         figno=300,
                                         type='each_gauge')
    plotfigure.show = True
    plotfigure.clf_each_gauge = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [-2, 1]
    # plotaxes.xlabel = "Days from landfall"
    # plotaxes.ylabel = "Surface (m)"
    plotaxes.ylimits = [-1, 5]
    plotaxes.title = 'Surface'

    def gauge_afteraxes(cd):

        axes = plt.gca()
        surgeplot.plot_landfall_gauge(cd.gaugesoln, axes)

        # Fix up plot - in particular fix time labels
        axes.set_title('Station %s' % cd.gaugeno)
        axes.set_xlabel('Days relative to landfall')
        axes.set_ylabel('Surface (m)')
        axes.set_xlim([-2, 1])
        axes.set_ylim([-1, 5])
        axes.set_xticks([-2, -1, 0, 1])
        axes.set_xticklabels([r"$-2$", r"$-1$", r"$0$", r"$1$"])
        axes.grid(True)

    plotaxes.afteraxes = gauge_afteraxes

    # Plot surface as blue curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')

    # plotitem.plot_var = 3
    # plotitem.plotstyle = 'b-'

    #
    #  Gauge Location Plot
    #
    def gauge_location_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos='all',
                                        format_string='ko',
                                        add_labels=True)

    plotfigure = plotdata.new_plotfigure(name="Gauge Locations")
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge Locations'
    plotaxes.scaled = True
    plotaxes.xlimits = [clawdata.lower[0], clawdata.upper[0]]
    plotaxes.ylimits = [clawdata.lower[1], clawdata.upper[1]]
    plotaxes.afteraxes = gauge_location_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    #-----------------------------------------
    # Figures for fgmax plots
    #-----------------------------------------

    from clawpack.geoclaw import fgmax_tools
    fgmax_plotdir = '_plots'
    os.system('mkdir -p %s' % fgmax_plotdir)
    # Read fgmax data:
    fgno = 1
    while (True):
        fg = fgmax_tools.FGmaxGrid()
        try:
            fg.read_fgmax_grids_data(fgno)

            fg.read_output(outdir=plotdata.outdir)

            fg.B0 = fg.B  # no seafloor deformation in this problem
            fg.h_onshore = np.ma.masked_where(fg.B0 < 0., fg.h)
            plt.figure(figsize=(20, 20))

            pc = plt.pcolormesh(fg.X, fg.Y, fg.h_onshore, cmap='hot_r')
            cb = plt.colorbar(pc, extend='max', shrink=0.7)
            cb.set_label('meters')
            plt.contour(fg.X, fg.Y, fg.B, [0], colors='g')

            plt.gca().set_aspect(1. / np.cos(48 * np.pi / 180.))
            plt.ticklabel_format(useOffset=False)
            plt.xticks(rotation=20)
            plt.title('Maximum Onshore flow depth\nfgmax grid {fgno}')
            img_name = f'fgmax{str(fgno).zfill(4)}_h_onshore.png'
            plt.savefig(fname=f'{fgmax_plotdir}/{img_name}')
            otherfigure = plotdata.new_otherfigure(
                name=f'max depth on fgmax grid {fgno}', fname=img_name)
            fgno = fgno + 1
        except:
            break

    # -----------------------------------------
    # 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.latex = False  # 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  # parallel plotting

    return plotdata
Esempio n. 5
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='Computational domain', figno=0)
    plotfigure.kwargs = {'figsize': (8, 7)}
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.title = 'Surface'
    plotaxes.scaled = True

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

    plotaxes.afteraxes = aa

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = cmin
    plotitem.pcolor_cmax = cmax
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = 0.7
    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 = linspace(-3000, -3000, 1)
    plotitem.amr_contour_colors = ['y']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid', 'linewidths': 2}
    plotitem.amr_contour_show = [1, 0, 0]
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0

    #-----------------------------------------
    # Figure for coastal area
    #-----------------------------------------
    x1, x2, y1, y2 = [-0.005, 0.016, -0.01, 0.01]

    plotfigure = plotdata.new_plotfigure(name="coastal area", figno=11)
    plotfigure.show = True
    plotfigure.kwargs = {'figsize': (6, 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_withbox(current_data):
        from pylab import plot
        x1, x2, y1, y2 = (-0.009259, 0.013796, -0.005093, 0.005000)
        if current_data.t > 5 * 60.:
            plot([x1, x1, x2, x2, x1], [y1, y2, y2, y1, y1], 'w--')
        aa(current_data)

    plotaxes.afteraxes = aa_withbox

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.surface
    #plotitem.plot_var = geoplot.surface_or_depth
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = cmin
    plotitem.pcolor_cmax = cmax
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = 0.4
    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

    # 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 = [-2, -1, 0, 1, 2]
    plotitem.amr_contour_colors = ['yellow']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid', 'linewidths': 1}
    plotitem.amr_contour_show = [0, 0, 1, 0]
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0

    # 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': 'minutes',
                'simtime': 'minutes',
                'cell': 'millions'
            }
            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
Esempio n. 6
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
Esempio n. 7
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='Computational domain', figno=0)
    plotfigure.kwargs = {'figsize': (8, 7)}
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.title = 'Surface'
    plotaxes.scaled = True

    def fixup(current_data):
        import pylab
        #addgauges(current_data)
        t = current_data.t
        t = t / 60.  # minutes
        pylab.title('Surface at %4.2f minutes' % t, fontsize=10)
        #pylab.xticks(fontsize=15)
        #pylab.yticks(fontsize=15)

    #plotaxes.afteraxes = fixup

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

    def aa_topo(current_data):
        from pylab import contour, plot
        aa(current_data)
        #addgauges(current_data)
        #contour(topo.X, topo.Y, topo.Z, [0], colors='k')

    def aa_topo_nogauges(current_data):
        from pylab import contour, plot
        aa(current_data)
        #addgauges(current_data)
        #contour(topo.X, topo.Y, topo.Z, [0], colors='k')

    #plotaxes.afteraxes = aa_topo
    plotaxes.afteraxes = aa_topo_nogauges

    ## Limits below never used for AK, CSZ_L1 or SFL
    #plotaxes.xlimits = [-129.16,-122.16]
    #plotaxes.ylimits = [46.0,51.0]

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    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 = linspace(-3000, -3000, 1)
    plotitem.amr_contour_colors = ['y']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid', 'linewidths': 2}
    plotitem.amr_contour_show = [1, 0, 0]
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0

    #-----------------------------------------
    # Figure for fgmax area
    #-----------------------------------------
    x1, x2, y1, y2 = [-122.54, -122.4, 47.9, 48.04]

    plotfigure = plotdata.new_plotfigure(name="fgmax area", figno=11)
    plotfigure.show = True
    plotfigure.kwargs = {'figsize': (6, 7)}

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

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

    plotaxes.afteraxes = aa_topo

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    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: You need to move fgmax png files into _plots/_other_figures after
    # creating them, e.g., by running the process_fgmax notebook or script.
    # The lines below just create links to these figures from _PlotIndex.html

    otherfigure = plotdata.new_otherfigure(
        name='max depth', fname='_other_figures/h_onshore.png')

    otherfigure = plotdata.new_otherfigure(name='max speed',
                                           fname='_other_figures/speed.png')

    # add additional lines for any other figures you want added to the index.

    # 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')

    # create a link to this webpage from _PlotIndex.html:
    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