예제 #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

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

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

    def set_drytol(current_data):
        # The drytol parameter is used in masking land and water and
        # affects what color map is used for cells with small water depth h.
        # The cell will be plotted as dry if h < drytol.
        # The best value to use often depends on the application and can
        # be set here (measured in meters):
        current_data.user["drytol"] = 1.e-3

    plotdata.beforeframe = set_drytol

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

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.surface
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = -0.1
    plotitem.pcolor_cmax = 0.1
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [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]
    plotitem.patchedges_show = 1
    plotaxes.xlimits = [-2, 2]
    plotaxes.ylimits = [-2, 2]

    # Add contour lines of bathymetry:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.topo
    from numpy import arange, linspace
    plotitem.contour_levels = linspace(-.1, 0.5, 20)
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid'}
    plotitem.amr_contour_show = [1]
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    #-----------------------------------------
    # Figure for cross section
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='cross-section', figno=1)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [-2, 2]
    plotaxes.ylimits = [-0.15, 0.3]
    plotaxes.title = 'Cross section at y=0'

    def plot_topo_xsec(current_data):
        from pylab import plot, hold, cos, sin, where, legend, nan
        t = current_data.t

        hold(True)
        x = linspace(-2, 2, 201)
        y = 0.
        B = h0 * (x**2 + y**2) / a**2 - h0
        eta1 = sigma * h0 / a**2 * (2. * x * cos(omega * t) +
                                    2. * y * sin(omega * t) - sigma)
        etatrue = where(eta1 > B, eta1, nan)
        plot(x, etatrue, 'r', label="true solution", linewidth=2)
        plot(x, B, 'g', label="bathymetry")
        ## plot([0],[-1],'kx',label="Level 1")  # shouldn't show up in plots,
        ## plot([0],[-1],'bo',label="Level 2")  # but will produced desired legend
        plot([0], [-1], 'bo', label="Computed")  ## need to fix plotstyle
        legend()
        hold(False)

    plotaxes.afteraxes = plot_topo_xsec

    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')

    def xsec(current_data):
        # Return x value and surface eta at this point, along y=0
        from pylab import find, ravel
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q

        ij = find((y <= dy / 2.) & (y > -dy / 2.))
        x_slice = ravel(x)[ij]
        eta_slice = ravel(q[3, :, :])[ij]
        return x_slice, eta_slice

    plotitem.map_2d_to_1d = xsec
    plotitem.plotstyle = 'kx'  ## need to be able to set amr_plotstyle
    plotitem.kwargs = {'markersize': 3}
    plotitem.amr_show = [1]  # plot on all levels

    #-----------------------------------------
    # Figure for grids alone
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='grids', figno=2)
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [-2, 2]
    plotaxes.ylimits = [-2, 2]
    plotaxes.title = 'grids'
    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']
    plotitem.amr_celledges_show = [1, 1, 0]
    plotitem.amr_patchedges_show = [1]

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

    # 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 = []  # 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
예제 #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.
    
    """

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

    from clawpack.visclaw import colormaps, geoplot

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

    plotdata.format = 'ascii'  # Format of output

    # plotdata.format = 'netcdf'

    def set_drytol(current_data):
        # The drytol parameter is used in masking land and water and
        # affects what color map is used for cells with small water depth h.
        # The cell will be plotted as dry if h < drytol.
        # The best value to use often depends on the application and can
        # be set here (measured in meters):
        current_data.user['drytol'] = 1.e-2

    plotdata.beforeframe = set_drytol

    # 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 pcolor plot
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='pcolor', figno=0)

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.pcolor_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.pcolor_cmin = -0.3
    plotitem.pcolor_cmax = 0.3
    plotitem.add_colorbar = True

    # 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 = 2.0
    plotitem.add_colorbar = False
    plotaxes.xlimits = [-1, 1]
    plotaxes.ylimits = [-1, 1]

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

    # 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 = [4, 5, 104, 105]  # 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
예제 #3
0
파일: setplot.py 프로젝트: aks2203/geoclaw
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

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


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

    def set_drytol(current_data):
        # The drytol parameter is used in masking land and water and
        # affects what color map is used for cells with small water depth h.
        # The cell will be plotted as dry if h < drytol.
        # The best value to use often depends on the application and can
        # be set here (measured in meters):
        current_data.user["drytol"] = 1.e-3

    plotdata.beforeframe = set_drytol

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

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.surface
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = -0.1
    plotitem.pcolor_cmax = 0.1
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [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]
    plotitem.patchedges_show = 1
    plotaxes.xlimits = [-2,2]
    plotaxes.ylimits = [-2,2]

    # Add contour lines of bathymetry:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.topo
    from numpy import arange, linspace
    plotitem.contour_levels = linspace(-.1, 0.5, 20)
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles':'solid'}
    plotitem.amr_contour_show = [1]  
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    #-----------------------------------------
    # Figure for cross section
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='cross-section', figno=1)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [-2,2]
    plotaxes.ylimits = [-0.15,0.3]
    plotaxes.title = 'Cross section at y=0'
    def plot_topo_xsec(current_data):
        from pylab import plot, cos,sin,where,legend,nan
        t = current_data.t

        x = linspace(-2,2,201)
        y = 0.
        B = h0*(x**2 + y**2)/a**2 - h0
        eta1 = sigma*h0/a**2 * (2.*x*cos(omega*t) + 2.*y*sin(omega*t) -sigma)
        etatrue = where(eta1>B, eta1, nan)
        plot(x, etatrue, 'r', label="true solution", linewidth=2)
        plot(x, B, 'g', label="bathymetry")
        ## plot([0],[-1],'kx',label="Level 1")  # shouldn't show up in plots,
        ## plot([0],[-1],'bo',label="Level 2")  # but will produced desired legend
        plot([0],[-1],'bo',label="Computed")  ## need to fix plotstyle
        legend()
    plotaxes.afteraxes = plot_topo_xsec

    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')

    def xsec(current_data):
        # Return x value and surface eta at this point, along y=0
        from pylab import find,ravel
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q

        ij = find((y <= dy/2.) & (y > -dy/2.))
        x_slice = ravel(x)[ij]
        eta_slice = ravel(q[3,:,:])[ij]
        return x_slice, eta_slice

    plotitem.map_2d_to_1d = xsec
    plotitem.plotstyle = 'kx'     ## need to be able to set amr_plotstyle
    plotitem.kwargs = {'markersize':3}
    plotitem.amr_show = [1]  # plot on all levels


    #-----------------------------------------
    # Figure for grids alone
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='grids', figno=2)
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [-2,2]
    plotaxes.ylimits = [-2,2]
    plotaxes.title = 'grids'
    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']
    plotitem.amr_celledges_show = [1,1,0]   
    plotitem.amr_patchedges_show = [1]


    #-----------------------------------------
    
    # 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 = []             # 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
예제 #4
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.
    
    """

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

    from clawpack.visclaw import colormaps, geoplot

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

    plotdata.format = 'ascii'  # Format of output

    # plotdata.format = 'netcdf'

    def set_drytol(current_data):
        # The drytol parameter is used in masking land and water and
        # affects what color map is used for cells with small water depth h.
        # The cell will be plotted as dry if h < drytol.
        # The best value to use often depends on the application and can
        # be set here (measured in meters):
        current_data.user['drytol'] = 1.e-2

    plotdata.beforeframe = set_drytol

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

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

    # 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.9
    plotitem.pcolor_cmax = 0.9
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [1, 1, 0]
    plotitem.amr_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 = [1, 1, 0]
    plotaxes.xlimits = [-100, 100]
    plotaxes.ylimits = [-100, 100]

    #-----------------------------------------
    # Figure for zoom
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Zoom', figno=10)
    #plotfigure.show = False
    plotfigure.kwargs = {'figsize': [12, 7]}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('diag zoom')
    plotaxes.axescmd = 'axes([0.0,0.1,0.6,0.6])'
    plotaxes.title = 'On diagonal'
    plotaxes.scaled = True
    plotaxes.xlimits = [55, 66]
    plotaxes.ylimits = [55, 66]

    def addgauges(current_data):
        from clawpack.visclaw import gaugetools
        gaugenos = range(101, 110)  # on diagonal
        gaugetools.plot_gauge_locations(current_data.plotdata, \
             gaugenos=gaugenos, format_string='ko', add_labels=True)

    plotaxes.afteraxes = addgauges

    # 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.9
    plotitem.pcolor_cmax = 0.9
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [1, 1, 0]
    plotitem.amr_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 = [1, 1, 0]

    # Add contour lines of bathymetry:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.topo
    from numpy import arange, linspace
    plotitem.contour_levels = arange(-10., 0., 1.)
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid'}
    plotitem.amr_contour_show = [0, 0, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    # Add contour lines of topography:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.topo
    from numpy import arange, linspace
    plotitem.contour_levels = arange(0., 11., 1.)
    plotitem.amr_contour_colors = ['g']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid'}
    plotitem.amr_contour_show = [0, 0, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    # Add dashed contour line for shoreline
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = [0.]
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles': 'dashed'}
    plotitem.amr_contour_show = [0, 0, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    #-----------------------------------------
    # Figure for zoom near axis
    #-----------------------------------------
    #plotfigure = plotdata.new_plotfigure(name='Zoom2', figno=11)
    # now included in same figure as zoom on diagonal

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('x zoom')
    plotaxes.show = True
    plotaxes.axescmd = 'axes([0.5,0.1,0.6,0.6])'
    plotaxes.title = 'On x-axis'
    plotaxes.scaled = True
    plotaxes.xlimits = [82, 93]
    plotaxes.ylimits = [-5, 6]

    def addgauges(current_data):
        from clawpack.visclaw import gaugetools
        gaugenos = range(1, 10)  # on x-axis
        gaugetools.plot_gauge_locations(current_data.plotdata, \
             gaugenos=gaugenos, format_string='ko', add_labels=True)

    plotaxes.afteraxes = addgauges

    # 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.9
    plotitem.pcolor_cmax = 0.9
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [1, 1, 0]
    plotitem.amr_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 = [1, 1, 0]

    # Add contour lines of bathymetry:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.topo
    from numpy import arange, linspace
    plotitem.contour_levels = arange(-10., 0., 1.)
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid'}
    plotitem.amr_contour_show = [0, 0, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    # Add contour lines of topography:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.topo
    from numpy import arange, linspace
    plotitem.contour_levels = arange(0., 11., 1.)
    plotitem.amr_contour_colors = ['g']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid'}
    plotitem.amr_contour_show = [0, 0, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    # Add dashed contour line for shoreline
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = [0.]
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles': 'dashed'}
    plotitem.amr_contour_show = [0, 0, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    #-----------------------------------------
    # Figures for gauges
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Surface & topo', 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 = [-2.0, 2.0]
    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')

    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
        t = current_data.t
        legend(('surface', 'topography'), loc='lower left')
        plot(t, 0 * t, 'k')

    plotaxes.afteraxes = add_zeroline

    #-----------------------------------------
    # Figure for patches alone
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='patches', figno=2)
    plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0, 1]
    plotaxes.ylimits = [0, 1]
    plotaxes.title = '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']
    plotitem.amr_celledges_show = [1, 1, 0]
    plotitem.amr_patchedges_show = [1]

    #-----------------------------------------
    # Scatter plot of surface for radially symmetric
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Scatter', figno=200)
    plotfigure.show = False
    # Note: will not look very good unless more of domain is refined

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0., 100.]
    plotaxes.ylimits = [-1.5, 2.]
    plotaxes.title = 'Scatter plot of surface'

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.plot_var = geoplot.surface

    def q_vs_radius(current_data):
        from numpy import sqrt
        x = current_data.x
        y = current_data.y
        r = sqrt(x**2 + y**2)
        q = current_data.var
        return r, q

    plotitem.map_2d_to_1d = q_vs_radius
    plotitem.plotstyle = 'o'
    plotitem.amr_color = ['b', 'r', 'g']
    plotaxes.afteraxes = "import pylab; pylab.legend(['Level 1','Level 2'])"

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

    # 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 = [4, 5, 104, 105]  # 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
    plotdata.html_movie_width = 800  # width for js movie

    return plotdata
예제 #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.
    
    """

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

        plotdata = ClawPlotData()

    from clawpack.visclaw import colormaps, geoplot

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

    plotdata.format = "ascii"  # Format of output
    # plotdata.format = 'netcdf'

    def set_drytol(current_data):
        # The drytol parameter is used in masking land and water and
        # affects what color map is used for cells with small water depth h.
        # The cell will be plotted as dry if h < drytol.
        # The best value to use often depends on the application and can
        # be set here (measured in meters):
        current_data.user["drytol"] = 1.0e-2

    plotdata.beforeframe = set_drytol

    # 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 pcolor plot
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="pcolor", figno=0)

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

    # 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.9
    plotitem.pcolor_cmax = 0.9
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [1, 1, 0]
    plotitem.amr_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 = [1, 1, 0]
    plotaxes.xlimits = [-100, 100]
    plotaxes.ylimits = [-100, 100]

    # -----------------------------------------
    # Figure for zoom
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="Zoom", figno=10)
    # plotfigure.show = False
    plotfigure.kwargs = {"figsize": [12, 7]}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes("diag zoom")
    plotaxes.axescmd = "axes([0.0,0.1,0.6,0.6])"
    plotaxes.title = "On diagonal"
    plotaxes.scaled = True
    plotaxes.xlimits = [55, 66]
    plotaxes.ylimits = [55, 66]
    plotaxes.afteraxes = addgauges

    # 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.9
    plotitem.pcolor_cmax = 0.9
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [1, 1, 0]
    plotitem.amr_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 = [1, 1, 0]

    # Add contour lines of bathymetry:
    plotitem = plotaxes.new_plotitem(plot_type="2d_contour")
    plotitem.plot_var = geoplot.topo
    from numpy import arange, linspace

    plotitem.contour_levels = arange(-10.0, 0.0, 1.0)
    plotitem.amr_contour_colors = ["k"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid"}
    plotitem.amr_contour_show = [0, 0, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    # Add contour lines of topography:
    plotitem = plotaxes.new_plotitem(plot_type="2d_contour")
    plotitem.plot_var = geoplot.topo
    from numpy import arange, linspace

    plotitem.contour_levels = arange(0.0, 11.0, 1.0)
    plotitem.amr_contour_colors = ["g"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid"}
    plotitem.amr_contour_show = [0, 0, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    # Add dashed contour line for shoreline
    plotitem = plotaxes.new_plotitem(plot_type="2d_contour")
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = [0.0]
    plotitem.amr_contour_colors = ["k"]  # color on each level
    plotitem.kwargs = {"linestyles": "dashed"}
    plotitem.amr_contour_show = [0, 0, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    # -----------------------------------------
    # Figure for zoom near axis
    # -----------------------------------------
    # plotfigure = plotdata.new_plotfigure(name='Zoom2', figno=11)
    # now included in same figure as zoom on diagonal

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes("x zoom")
    plotaxes.show = True
    plotaxes.axescmd = "axes([0.5,0.1,0.6,0.6])"
    plotaxes.title = "On x-axis"
    plotaxes.scaled = True
    plotaxes.xlimits = [82, 93]
    plotaxes.ylimits = [-5, 6]
    plotaxes.afteraxes = addgauges

    # 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.9
    plotitem.pcolor_cmax = 0.9
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [1, 1, 0]
    plotitem.amr_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 = [1, 1, 0]

    # Add contour lines of bathymetry:
    plotitem = plotaxes.new_plotitem(plot_type="2d_contour")
    plotitem.plot_var = geoplot.topo
    from numpy import arange, linspace

    plotitem.contour_levels = arange(-10.0, 0.0, 1.0)
    plotitem.amr_contour_colors = ["k"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid"}
    plotitem.amr_contour_show = [0, 0, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    # Add contour lines of topography:
    plotitem = plotaxes.new_plotitem(plot_type="2d_contour")
    plotitem.plot_var = geoplot.topo
    from numpy import arange, linspace

    plotitem.contour_levels = arange(0.0, 11.0, 1.0)
    plotitem.amr_contour_colors = ["g"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid"}
    plotitem.amr_contour_show = [0, 0, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    # Add dashed contour line for shoreline
    plotitem = plotaxes.new_plotitem(plot_type="2d_contour")
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = [0.0]
    plotitem.amr_contour_colors = ["k"]  # color on each level
    plotitem.kwargs = {"linestyles": "dashed"}
    plotitem.amr_contour_show = [0, 0, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    # -----------------------------------------
    # Figures for gauges
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="Surface & topo", 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 = [-2.0, 2.0]
    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")

    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

        t = current_data.t
        legend(("surface", "topography"), loc="lower left")
        plot(t, 0 * t, "k")

    plotaxes.afteraxes = add_zeroline

    # -----------------------------------------
    # Figure for patches alone
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="patches", figno=2)
    plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0, 1]
    plotaxes.ylimits = [0, 1]
    plotaxes.title = "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"]
    plotitem.amr_celledges_show = [1, 1, 0]
    plotitem.amr_patchedges_show = [1]

    # -----------------------------------------
    # Scatter plot of surface for radially symmetric
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="Scatter", figno=200)
    plotfigure.show = False
    # Note: will not look very good unless more of domain is refined

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0.0, 100.0]
    plotaxes.ylimits = [-1.5, 2.0]
    plotaxes.title = "Scatter plot of surface"

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type="1d_from_2d_data")
    plotitem.plot_var = geoplot.surface

    def q_vs_radius(current_data):
        from numpy import sqrt

        x = current_data.x
        y = current_data.y
        r = sqrt(x ** 2 + y ** 2)
        q = current_data.var
        return r, q

    plotitem.map_2d_to_1d = q_vs_radius
    plotitem.plotstyle = "o"
    plotitem.amr_color = ["b", "r", "g"]
    plotaxes.afteraxes = "import pylab; pylab.legend(['Level 1','Level 2'])"

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

    # 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 = [4, 5, 104, 105]  # 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
예제 #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

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

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

    def set_drytol(current_data):
        # The drytol parameter is used in masking land and water and
        # affects what color map is used for cells with small water depth h.
        # The cell will be plotted as dry if h < drytol.
        # The best value to use often depends on the application and can
        # be set here (measured in meters):
        current_data.user["drytol"] = 1.e-10

    plotdata.beforeframe = set_drytol

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

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

    def max_cmap(current_data):
        q = current_data.q
        return ((q[1, :, :].max()) * 1.1)

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.depth
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = cmax1
    plotitem.add_colorbar = True
    plotitem.colorbar_label = 'm'
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [0.0, domain_x]
    plotaxes.ylimits = [-domain_y / 2.0, domain_y / 2.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 = cmax1
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [0.0, domain_x]
    plotaxes.ylimits = [-domain_y / 2.0, domain_y / 2.0]

    # # Add contour lines of bathymetry:
    # plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    # plotitem.plot_var = geoplot.topo
    # from numpy import arange, linspace
    # plotitem.contour_levels = linspace(-.1, 0.5, 20)
    # plotitem.amr_contour_colors = ['k']  # color on each level
    # plotitem.kwargs = {'linestyles':'solid'}
    # plotitem.amr_contour_show = [1]
    # plotitem.celledges_show = 0
    # plotitem.patchedges_show = 0
    # plotitem.show = True

    #-----------------------------------------
    # Figure for zoomed area pcolor plot
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='zoomed_pcolor', figno=1)

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

    def max_cmap(current_data):
        q = current_data.q
        return ((q[1, :, :].max()) * 1.1)

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.depth
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = cmax1
    plotitem.add_colorbar = True
    plotitem.colorbar_label = 'm'
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [39.6, 42.0]
    plotaxes.ylimits = [-domain_y / 2.0, domain_y / 2.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 = cmax1
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [39.6, 42.0]
    plotaxes.ylimits = [-domain_y / 2.0, domain_y / 2.0]

    #-----------------------------------------
    # Figure for centerline slice
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Centerline_slice', figno=2)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0.0, domain_x]
    plotaxes.ylimits = [0.0, hn * 2.0]
    plotaxes.title = 'Centerline slice'
    #def depth_plot(current_data):
    #from pylab import plot, cos,sin,where,legend,nan
    #t = current_data.t
    #q = current_data.q
    #q1 = q[1,:,centerline_index]
    #x = numpy.linspace(0,domain_x,len(q1))

    #plot(x, q1, 'k.', label="true solution", linewidth=2)

    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 0
    plotitem.plotstyle = 'ko'  ## need to be able to set amr_plotstyle
    #plotitem.kwargs = {'markersize':3}
    #plotitem.amr_show = [1]  # plot on all levels
    #plotaxes.afteraxes = depth_plot

    #-----------------------------------------
    # Figure for grids alone
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='grids', figno=3)
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0.0, domain_x]
    plotaxes.ylimits = [-domain_y / 2.0, domain_y / 2.0]
    plotaxes.title = 'grids'
    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']
    plotitem.amr_celledges_show = [1, 1, 0]
    plotitem.amr_patchedges_show = [1]

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

    # 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 = []  # 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
예제 #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

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

    def change_fonts(current_data):
        pylab.xticks(fontsize=21, fontname="Tex Gyre Pagella")
        pylab.yticks(fontsize=21, fontname="Tex Gyre Pagella")
        # "Fill the step area with a black rectangle."
        import matplotlib.pyplot as plt
        rectangle = plt.Rectangle((x1, y1), 0.4, 0.4, color="k", fill=True)
        plt.gca().add_patch(rectangle)
        
    def change_fonts2(current_data):
        pylab.xticks(fontsize=17, fontname="Tex Gyre Pagella")
        pylab.yticks(fontsize=17, fontname="Tex Gyre Pagella")   
        # "Fill the step area with a black rectangle."
        import matplotlib.pyplot as plt
        rectangle = plt.Rectangle((x1,y1),0.4,0.4,color="k",fill=True)
        plt.gca().add_patch(rectangle)  
        
    plotdata.clearfigures()  # clear any old figures,axes,items data

    def set_drytol(current_data):
        # The drytol parameter is used in masking land and water and
        # affects what color map is used for cells with small water depth h.
        # The cell will be plotted as dry if h < drytol.
        # The best value to use often depends on the application and can
        # be set here (measured in meters):
        current_data.user["drytol"] = 1.e-20

    plotdata.beforeframe = set_drytol

    # -----------------------------------------
    # Figure for pcolor plot
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='pcolor', figno=0)
    plotfigure.kwargs = {'figsize':[10,10],'facecolor':'white'}

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.depth
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = cmax1
    plotitem.add_colorbar = True
    plotitem.colorbar_label = 'm'
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [0.0, domain_x]
    plotaxes.ylimits = [-domain_y/2.0, domain_y/2.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 = cmax1
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [0.0, domain_x]
    plotaxes.ylimits = [-domain_y/2.0, domain_y/2.0]

    # # Add contour lines of bathymetry:
    # plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    # plotitem.plot_var = geoplot.topo
    # from numpy import arange, linspace
    # plotitem.contour_levels = linspace(-.1, 0.5, 20)
    # plotitem.amr_contour_colors = ['k']  # color on each level
    # plotitem.kwargs = {'linestyles':'solid'}
    # plotitem.amr_contour_show = [1]
    # plotitem.celledges_show = 0
    # plotitem.patchedges_show = 0
    # plotitem.show = True
    
    plotaxes.afteraxes = change_fonts

    # -----------------------------------------
    # Figure for zoomed area pcolor plot
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='zoomed_pcolor', figno=1)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.title = 'Depth for Zoomed area'
    plotaxes.scaled = False

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.depth
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = cmax1
    plotitem.add_colorbar = True
    plotitem.colorbar_label = 'm'
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [39.4, 42.0]
    plotaxes.ylimits = [-domain_y/2.0, domain_y/2.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 = cmax1
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [39.5, 42.0]
    plotaxes.ylimits = [-domain_y/2.0, domain_y/2.0]
    
    plotaxes.afteraxes = change_fonts2

    # -----------------------------------------
    # Figure for centerline slice
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Centerline_slice', figno=2)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0.0, domain_x]
    plotaxes.ylimits = [0.0, hn*2.0]
    plotaxes.title = 'Centerline slice'
    # def depth_plot(current_data):
    #from pylab import plot, cos,sin,where,legend,nan
    #t = current_data.t
    #q = current_data.q
    #q1 = q[1,:,centerline_index]
    #x = numpy.linspace(0,domain_x,len(q1))

    #plot(x, q1, 'k.', label="true solution", linewidth=2)

    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 0
    plotitem.plotstyle = 'ko'  # need to be able to set amr_plotstyle
    #plotitem.kwargs = {'markersize':3}
    # plotitem.amr_show = [1]  # plot on all levels
    #plotaxes.afteraxes = depth_plot

    # -----------------------------------------
    # Figure for grids alone
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='grids', figno=3)
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0.0, domain_x]
    plotaxes.ylimits = [-domain_y/2.0, domain_y/2.0]
    plotaxes.title = 'grids'
    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']
    plotitem.amr_celledges_show = [1, 1, 0]
    plotitem.amr_patchedges_show = [1]

    # -----------------------------------------
    # Figure for cross section at y=0
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='cross-section', figno=4)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0.0, domain_x]
    plotaxes.ylimits = [0.0, cmax1*1.80]
    plotaxes.title = 'Cross section at y=0'

    def plot_topo_xsec(current_data):
        from pylab import plot, cos, sin, where, legend, nan
        t = current_data.t

        x = numpy.linspace(0.0, domain_x, 201)
        #y = 0.
        B = where(x > 40.0, where(x < 40.50, 7.0, 0.0), 0.0)
        plot(x, B, 'g', label="bathymetry")
        legend()
        pylab.xticks(fontsize=21, fontname="Tex Gyre Pagella")
        pylab.yticks(fontsize=21, fontname="Tex Gyre Pagella")

    plotaxes.afteraxes = plot_topo_xsec

    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')

    def xsec(current_data):
        # Return x value and surface depth at this point, along y=0
        from pylab import where, ravel
        x = current_data.x
        y = ravel(current_data.y)
        dy = current_data.dy
        q = current_data.q

        ij = where((y <= dy/2.) & (y > -dy/2.))
        x_slice = ravel(x)[ij]
        ij1 = where((x_slice > 40.50) | (x_slice < 40.0))
        x_slice = x_slice[ij1]
        depth_slice = ravel(q[0, :, :])[ij]
        depth_slice = depth_slice[ij1]
        return x_slice, depth_slice

    plotitem.map_2d_to_1d = xsec
    plotitem.plotstyle = 'k-x'  # need to be able to set amr_plotstyle
    plotitem.kwargs = {'markersize': 4}
    plotitem.amr_show = [1]  # plot on all levels

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

    # 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 = []             # 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
예제 #8
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 bay import Bay

    mobile = Bay('bay.info')

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

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

    def set_drytol(current_data):
        # The drytol parameter is used in masking land and water and
        # affects what color map is used for cells with small water depth h.
        # The cell will be plotted as dry if h < drytol.
        # The best value to use often depends on the application and can
        # be set here (measured in meters):
        current_data.user["drytol"] = 1.e-3

    plotdata.beforeframe = set_drytol

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

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.surface
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = -0.5
    plotitem.pcolor_cmax = 0.5
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [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 = mobile.z0
    plotitem.pcolor_cmax = mobile.z_r
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.patchedges_show = 1
    plotaxes.xlimits = [mobile.x_o1, mobile.x_o2]
    plotaxes.ylimits = [mobile.y0, mobile.y_r]

    # Add contour lines of bathymetry:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.topo
    from numpy import arange, linspace
    plotitem.contour_levels = linspace(mobile.z0, mobile.z_r, 10)
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid'}
    plotitem.amr_contour_show = [1]
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    #-----------------------------------------
    # Figures for gauges
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Surface & topo',
                                         figno=1,
                                         type='each_gauge')

    plotfigure.clf_each_gauge = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = [-1.5, 1.5]
    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')

    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
        t = current_data.t
        legend(('surface', 'topography'), loc='lower left')
        plot(t, 0 * t, 'k')

    plotaxes.afteraxes = add_zeroline

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

    # 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