Beispiel #1
0
def setplotfg(fgno=1, outdir='_output'):
    from pyclaw.plotters import plotfg, colormaps, geoplot
    from numpy import arange

    # max used for surface and inundation colormaps below:
    etamax = 5.0  

    fgdata = plotfg.ClawPlotFGData()
    #xfgdata.format = 'binary'
    # Set attributes as desired:

    fgdata.outdir = outdir
    fgdata.plotdir = '.'

    # Fixed grid to display:
    fgdata.fgno = fgno

    if fgno>0:

        # Could set things differently for each fgno if desired...

        # Contour levels for all plots:
        fgdata.clines = arange(-20,32,4)

        # For plot of surface eta each frame:
        fgdata.eta_show = True
        my_cmap_surface = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                              -0.02: [0.75,0.75,1.0], \
                                               0.0: [1.0,1.0,1.0], \
                                               0.02: [1.0,0.75,0.75], \
                                               1.0: [1.0,0.0,0.0]})
        fgdata.water_cmap =  my_cmap_surface
        fgdata.water_clim = (-etamax,etamax)


        fgdata.land_cmap =  geoplot.land_colors
        fgdata.land_clim = (0,40)

        # For plot of inundation region:
        fgdata.inundated_show = True
        fgdata.inundated_clim =(0,etamax)
	# colormap that scales up to etamax:
        fgdata.inundated_cmap =  colormaps.make_colormap({0:[0,0.3,1],\
                0.1*etamax:[0,1,1],1.01*etamax:[0,1,1], \
                0.4*etamax:[0,1,0], etamax:[1,0.2,0.2]})
        fgdata.inundated_add_colorbar = True

        # For plot of exposed seafloor:
        fgdata.seafloor_show = True
        fgdata.seafloor_cmap =  geoplot.seafloor_colormap
        fgdata.seafloor_clim = (-1,0)

        fgdata.save_png = False
        fgdata.seafloor_add_colorbar = True

        fgdata.drytol = 1.e-2
        fgdata.exposed_tol = 1.e-2

    return fgdata
Beispiel #2
0
def setplotfg(fgno=1, outdir='_output'):
    from pyclaw.plotters import plotfg, colormaps, geoplot
    from numpy import arange

    # max used for surface and inundation colormaps below:
    etamax = 1.0

    fgdata = plotfg.ClawPlotFGData()

    # Set attributes as desired:

    fgdata.outdir = outdir
    fgdata.plotdir = '.'

    # Fixed grid to display:
    fgdata.fgno = fgno

    if fgno > 0:

        # Could set things differently for each fgno if desired...

        # Contour levels for all plots:
        fgdata.clines = arange(-20, 32, 4)

        # For plot of surface eta each frame:
        fgdata.eta_show = True
        my_cmap_surface = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                              -0.02: [0.75,0.75,1.0], \
                                               0.0: [1.0,1.0,1.0], \
                                               0.02: [1.0,0.75,0.75], \
                                               1.0: [1.0,0.0,0.0]})
        fgdata.water_cmap = my_cmap_surface
        fgdata.water_clim = (-etamax, etamax)

        fgdata.land_cmap = geoplot.land_colors
        fgdata.land_clim = (0, 40)

        # For plot of inundation region:
        fgdata.inundated_show = True
        fgdata.inundated_clim = (0, etamax)
        # colormap that scales up to etamax:
        fgdata.inundated_cmap =  colormaps.make_colormap({0:[0,0.3,1],\
                0.1*etamax:[0,1,1],1.01*etamax:[0,1,1], \
                0.4*etamax:[0,1,0], etamax:[1,0.2,0.2]})
        fgdata.inundated_add_colorbar = True

        # For plot of exposed seafloor:
        fgdata.seafloor_show = True
        fgdata.seafloor_cmap = geoplot.seafloor_colormap
        fgdata.seafloor_clim = (-1, 0)

        fgdata.save_png = False
        fgdata.seafloor_add_colorbar = True

        fgdata.drytol = 1.e-2
        fgdata.exposed_tol = 1.e-2

    return fgdata
Beispiel #3
0
def setplotfg(fgno=1, outdir='_output'):
    from pyclaw.plotters import plotfg, colormaps, geoplot
    from numpy import arange

    fgdata = plotfg.ClawPlotFGData()

    # Set attributes as desired:

    fgdata.outdir = outdir
    fgdata.plotdir = '.'

    # Fixed grid to display:
    fgdata.fgno = fgno

    if fgno==1:

        # Plot parameters for Fixed Grid 1.
        # Repeat as needed for other fixed grids.
        # Contour levels for all plots:
        fgdata.clines = arange(-20,33,4)

        # For plot of surface eta each frame:
        fgdata.eta_show = True
        my_cmap_surface = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                              -0.02: [0.75,0.75,1.0], \
                                               0.0: [1.0,1.0,1.0], \
                                               0.02: [1.0,0.75,0.75], \
                                               1.0: [1.0,0.0,0.0]})
        fgdata.water_cmap =  my_cmap_surface
        fgdata.water_clim = (-20,20)

        fgdata.land_cmap =  geoplot.land_colors
        fgdata.land_clim = (0,40)

        # For plot of inundation region:
        fgdata.inundated_show = True
        fgdata.inundated_cmap =  colormaps.make_colormap({0:[0,0,1],\
                1:[0,1,1],1.01:[0,1,1], 4:[0,1,0], 10:[1,0,0]})

        fgdata.inundated_clim =(0,10)

        # For plot of exposed seafloor:
        fgdata.seafloor_show = False
        fgdata.seafloor_cmap =  geoplot.seafloor_colormap
        fgdata.seafloor_clim = (-1,0)

        fgdata.save_png = False

        fgdata.drytol = 1.e-2
        fgdata.exposed_tol = 1.e-2



    return fgdata
Beispiel #4
0
def setplotfg(fgno=1, outdir='_output'):
    from pyclaw.plotters import plotfg, colormaps, geoplot
    from numpy import arange

    fgdata = plotfg.ClawPlotFGData()

    # Set attributes as desired:

    fgdata.outdir = outdir
    fgdata.plotdir = '.'

    # Fixed grid to display:
    fgdata.fgno = fgno

    if fgno>0:

        # Plot parameters for Fixed Grid 1.
        # Repeat as needed for other fixed grids.
        # Contour levels for all plots:
        fgdata.clines = arange(-20,32,2)

        # For plot of surface eta each frame:
        fgdata.eta_show = True
        my_cmap_surface = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                              -0.02: [0.75,0.75,1.0], \
                                               0.0: [1.0,1.0,1.0], \
                                               0.02: [1.0,0.75,0.75], \
                                               1.0: [1.0,0.0,0.0]})
        fgdata.water_cmap =  my_cmap_surface
        fgdata.water_clim = (-20,20)

        fgdata.land_cmap =  geoplot.land_colors
        fgdata.land_clim = (0,40)

        # For plot of inundation region:
        fgdata.inundated_show = True
        fgdata.inundated_cmap =  colormaps.make_colormap({0:[0,0.3,1],\
                1:[0,1,1],1.01:[0,1,1], 4:[0,1,0], 10:[1,0.2,0.2]})
        fgdata.inundated_clim =(0,10)

        # For plot of exposed seafloor:
        fgdata.seafloor_show = False
        fgdata.seafloor_cmap =  geoplot.seafloor_colormap
        fgdata.seafloor_clim = (-1,0)

        fgdata.save_png = False

        fgdata.drytol = 1.e-2
        fgdata.exposed_tol = 1.e-2



    return fgdata
Beispiel #5
0
 def add_surface_elevation(plotaxes,bounds=None,plot_type='pcolor'):
     if plot_type == 'pcolor' or plot_type == 'imshow':            
         plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
         # plotitem.plotvar = eta
         plotitem.plot_var = geoplot.surface
         plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
         if bounds is not None:
             plotitem.imshow_cmin = bounds[0]
             plotitem.imshow_cmax = bounds[1]
         plotitem.add_colorbar = True
         plotitem.amr_gridlines_show = [0,0,0]
         plotitem.amr_gridedges_show = [1,1,1]
     elif plot_type == 'contour':            
         plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
         plotitem.plot_var = geoplot.surface
         if bounds is None:
             plotitem.contour_levels = [-2.5,-1.5,-0.5,0.5,1.5,2.5]
         # plotitem.contour_nlevels = 21
         # plotitem.contour_min = -2.0
         # plotitem.contour_max = 2.0
         # plotitem.kwargs = {''}
         plotitem.amr_contour_show = [1,1,1]
         plotitem.amr_gridlines_show = [0,0,0]
         plotitem.amr_gridedges_show = [1,1,1]
         plotitem.amr_contour_colors = 'k'
Beispiel #6
0
    def __init__(self, fgno=1):
        super(ClawPlotFGData, self).__init__()
        self.add_attribute("fgno", fgno)
        self.add_attribute("drytol", 1.0e-2)
        self.add_attribute("exposed_tol", 1.0e-2)
        self.add_attribute("clines", linspace(-20, 20, 21))

        self.add_attribute("water_cmap", geoplot.tsunami_colormap)
        self.add_attribute("land_cmap", geoplot.land_colors)
        self.add_attribute("seafloor_cmap", geoplot.seafloor_colormap)
        self.add_attribute(
            "inundated_cmap",
            colormaps.make_colormap({0.0: [1, 0.9, 0.9], 1.0: [1, 0, 0]}),
        )

        self.add_attribute("water_clim", (-1, 1))
        self.add_attribute("land_clim", (0, 10))
        self.add_attribute("seafloor_clim", (-1, 0))
        self.add_attribute("inundated_clim", (0, 1))

        self.add_attribute("water_add_colorbar", True)
        self.add_attribute("land_add_colorbar", False)
        self.add_attribute("seafloor_add_colorbar", True)
        self.add_attribute("inundated_add_colorbar", True)

        self.add_attribute("eta_show", True)
        self.add_attribute("seafloor_show", True)
        self.add_attribute("inundated_show", True)

        self.add_attribute("outdir", "_output")
        self.add_attribute("plotdir", None)
        self.add_attribute("save_png", False)
        self.add_attribute("solutions", {})
        self.add_attribute("grids", {})
        self.add_attribute("combined_figure", True)
Beispiel #7
0
    def __init__(self, fgno=1):
        super(ClawPlotFGData, self).__init__()
        self.add_attribute('fgno', fgno)
        self.add_attribute('drytol', 1.e-2)
        self.add_attribute('exposed_tol', 1.e-2)
        self.add_attribute('clines', linspace(-20, 20, 21))

        self.add_attribute('water_cmap', geoplot.tsunami_colormap)
        self.add_attribute('land_cmap', geoplot.land_colors)
        self.add_attribute('seafloor_cmap', geoplot.seafloor_colormap)
        self.add_attribute('inundated_cmap', \
             colormaps.make_colormap({0.:[1,.9,.9], 1.:[1,0,0]}))

        self.add_attribute('water_clim', (-1, 1))
        self.add_attribute('land_clim', (0, 10))
        self.add_attribute('seafloor_clim', (-1, 0))
        self.add_attribute('inundated_clim', (0, 1))

        self.add_attribute('water_add_colorbar', True)
        self.add_attribute('land_add_colorbar', False)
        self.add_attribute('seafloor_add_colorbar', True)
        self.add_attribute('inundated_add_colorbar', True)

        self.add_attribute('eta_show', True)
        self.add_attribute('seafloor_show', True)
        self.add_attribute('inundated_show', True)

        self.add_attribute('outdir', '_output')
        self.add_attribute('plotdir', None)
        self.add_attribute('save_png', False)
        self.add_attribute('solutions', {})
        self.add_attribute('grids', {})
        self.add_attribute('combined_figure', True)
Beispiel #8
0
    def add_surface_elevation(plotaxes,surface,bounds=None,plot_type='pcolor'):
        if plot_type == 'pcolor' or plot_type == 'imshow':
            plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
            # plotitem.plot_var = geoplot.surface
            if surface == 1:
                plotitem.plot_var = eta1
            elif surface == 2:
                plotitem.plot_var = eta2
            if bounds is not None:                
                plotitem.imshow_cmin = bounds[0]
                plotitem.imshow_cmax = bounds[1]
            # plotitem.pcolor_cmap = geoplot.tsunami_colormap
            plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
            plotitem.add_colorbar = True
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1,1,1]

        elif plot_type == 'contour':
            plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
            plotitem.plot_var = surface + 5
            if bounds is not None:
                plotitem.contour_levels = bounds
            plotitem.amr_contour_show = [1,1,1]
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1,1,1]
            plotitem.amr_contour_colors = 'k'
        else:
            raise NotImplementedError("Plot type %s not implemented" % plot_type)
Beispiel #9
0
    def __init__(self,fgno=1):
        super(ClawPlotFGData,self).__init__()
        self.add_attribute('fgno',fgno)
        self.add_attribute('drytol',1.e-2)
        self.add_attribute('exposed_tol',1.e-2)
        self.add_attribute('clines',linspace(-20,20,21))

        self.add_attribute('water_cmap', geoplot.tsunami_colormap)
        self.add_attribute('land_cmap', geoplot.land_colors)
        self.add_attribute('seafloor_cmap', geoplot.seafloor_colormap)
        self.add_attribute('inundated_cmap', \
             colormaps.make_colormap({0.:[1,.9,.9], 1.:[1,0,0]}))

        self.add_attribute('water_clim',(-1,1))
        self.add_attribute('land_clim',(0,10))
        self.add_attribute('seafloor_clim',(-1,0))
        self.add_attribute('inundated_clim',(0,1))

        self.add_attribute('water_add_colorbar',True)
        self.add_attribute('land_add_colorbar',False)
        self.add_attribute('seafloor_add_colorbar',True)
        self.add_attribute('inundated_add_colorbar',True)

        self.add_attribute('eta_show',True)
        self.add_attribute('seafloor_show',True)
        self.add_attribute('inundated_show',True)

        self.add_attribute('outdir','_output')
        self.add_attribute('plotdir',None)
        self.add_attribute('save_png',False)
        self.add_attribute('solutions',{})
        self.add_attribute('grids',{})
        self.add_attribute('combined_figure',True)
Beispiel #10
0
 def add_layer_depth(plotaxes,layer,bounds=None,plot_type='pcolor'):
     if plot_type == 'pcolor' or plot_type == 'imshow':
         plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
         if layer == 1:
             plotitem.plot_var = 0
         elif layer == 2:
             plotitem.plot_var = 3
         if bounds is not None:
             plotitem.imshow_cmin = bounds[0]
             plotitem.imshow_cmax = bounds[1]
         plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
         plotitem.add_colorbar = True
         plotitem.amr_gridlines_show = [0,0,0]
         plotitem.amr_gridedges_show = [1,1,1]
     elif plot_type == 'profile':
         plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
         plotitem.map_2d_to_1d = upper_surface
         if surface == 1:
             plotitem.plot_var = 0
         elif surface == 2:
             plotitem.plot_var = 3
         if bounds is not None:
             plotitem.ylimits = bounds
         plotitem.amr_plotstyle = ['-','-.','+','x','.']
         # plotitem.color = (0.2,0.8,1.0)
     else:
         raise NotImplementedError("Plot type %s not implemented" % plot_type)
Beispiel #11
0
def setplot(plotdata):
#--------------------------
    
    """ 
    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 pyclaw.plotters import colormaps

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

    plotfigure = plotdata.new_plotfigure(name='Pressure', figno=0)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [-1., 1.]
    plotaxes.ylimits = [-1., 1.]
    plotaxes.title = 'Pressure'
    plotaxes.scaled = True        # so aspect ratio is 1

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = 0
    plotitem.contour_nlevels = 21
    plotitem.contour_min = 0.0
    plotitem.contour_max = 3.0

    # Use a custom colormap ranging from blue to red:
    blue_red_cmap = colormaps.make_colormap({0:'b', 1:'r'})
    plotitem.contour_cmap = blue_red_cmap
    plotitem.add_colorbar = True

    plotitem.show = True             # show on plot?
    

    # 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_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 = 1           # layout of plots
    plotdata.latex_framesperline = 2         # layout of plots
    plotdata.latex_makepdf = True            # also run pdflatex?

    return plotdata
Beispiel #12
0
def setplot(plotdata):
    #--------------------------
    """ 
    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 pyclaw.plotters import colormaps

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

    plotfigure = plotdata.new_plotfigure(name='Pressure', figno=0)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [-1., 1.]
    plotaxes.ylimits = [-1., 1.]
    plotaxes.title = 'Pressure'
    plotaxes.scaled = True  # so aspect ratio is 1

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = 0
    plotitem.contour_nlevels = 21
    plotitem.contour_min = 0.0
    plotitem.contour_max = 3.0

    # Use a custom colormap ranging from blue to red:
    blue_red_cmap = colormaps.make_colormap({0: 'b', 1: 'r'})
    plotitem.contour_cmap = blue_red_cmap
    plotitem.add_colorbar = True

    plotitem.show = True  # show on plot?

    # 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_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 = 1  # layout of plots
    plotdata.latex_framesperline = 2  # layout of plots
    plotdata.latex_makepdf = True  # also run pdflatex?

    return plotdata
Beispiel #13
0
 def add_layer_depth(plotaxes,layer,bounds=None,plot_type='pcolor'):
     if plot_type == 'pcolor' or plot_type == 'imshow':
         plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
         if layer == 1:
             plotitem.plot_var = 0
         elif layer == 2:
             plotitem.plot_var = 3
         if bounds is not None:
             plotitem.imshow_cmin = bounds[0]
             plotitem.imshow_cmax = bounds[1]
         plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
         plotitem.add_colorbar = True
         plotitem.amr_gridlines_show = [0,0,0]
         plotitem.amr_gridedges_show = [1,1,1]
Beispiel #14
0
    def add_surface_elevation(plotaxes,surface,bounds=None,plot_type='pcolor'):
        if plot_type == 'pcolor' or plot_type == 'imshow':
            plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
            # plotitem.plot_var = geoplot.surface
            if surface == 1:
                plotitem.plot_var = eta1
            elif surface == 2:
                plotitem.plot_var = eta2
            if bounds is not None:                
                plotitem.imshow_cmin = bounds[0]
                plotitem.imshow_cmax = bounds[1]
            # plotitem.pcolor_cmap = geoplot.tsunami_colormap
            plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
            plotitem.add_colorbar = True
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1,1,1]
            
        elif plot_type == 'profile':
            plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
            if surface == 1:
                plotitem.plot_var = eta1
                plotitem.map_2d_to_1d = upper_surface
            elif surface == 2:
                plotitem.plot_var = eta2
                plotitem.map_2d_to_1d = lower_surface
            if bounds is not None:
                plotitem.ylimits = bounds
            plotitem.amr_plotstyle = ['-','-.','+','x','.']
            # plotitem.color = (0.2,0.8,1.0)

        elif plot_type == 'contour':
            plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
            plotitem.plot_var = surface + 5
            if bounds is not None:
                plotitem.contour_levels = bounds
            plotitem.amr_contour_show = [1,1,1]
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1,1,1]
            plotitem.amr_contour_colors = 'k'
        else:
            raise NotImplementedError("Plot type %s not implemented" % plot_type)
def setplot(plotdata):
#--------------------------
    
    """ 
    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 pyclaw.plotters import colormaps, geoplot

    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-4


    plotdata.beforeframe = set_drytol

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

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

    # ========================================================================
    #  Water Velocity Helper Functions
    # ========================================================================        
    def water_velocity(current_data,DRY_TOL=1e-6):
        r"""Calculate velocity from the momentum and depth
        
        Calculates the x and y velocities from the momenta.  A mask is 
        constructed so that division by a small depth is avoided, controlled
        by the optional keyword argument DRY_TOL (default = 1e-6).  A check
        for NaNs is also made.  Any point not satisfying either of these
        criteria is set to 0.0.
        
        returns numpy.ndarray, nump.ndarray
        """
        h = current_data.q[:,:,0]
        hu = current_data.q[:,:,1]
        hv = current_data.q[:,:,2]
        u = np.zeros(hu.shape)
        v = np.zeros(hv.shape)
        
        index = np.nonzero((np.abs(h) > DRY_TOL) * (h != np.nan))
        u[index[0],index[1]] = hu[index[0],index[1]] / h[index[0],index[1]]
        v[index[0],index[1]] = hv[index[0],index[1]] / h[index[0],index[1]]
        
        return u,v
        
    def vorticity(current_data):
        r"""Calculate vorticity of velocity field
        
        Using matrix operations, calculate u_y + v_x, note that second order,
        centered differences are used for interior points and forward and
        backward differences for the boundary values.
        
        returns numpy.ndarray of shape of u and v
        """
        u,v = water_velocity(current_data)
        dx = current_data.dx
        dy = current_data.dy
        
        u_y = np.zeros(u.shape)
        u_y[:,0] = (-3.0*u[:,0] + 4.0 * u[:,1] - u[:,2]) / (2.0 * dy)
        u_y[:,-1] = (u[:,-3] - 4.0 * u[:,-2] + 3.0 * u[:,-1]) / (2.0 * dy)
        u_y[:,1:-1] = (u[:,2:] - u[:,0:-2]) / (2.0 * dy)

        v_x = np.zeros(v.shape)
        v_x[0,:] = (-3.0*v[0,:] + 4.0 * v[1,:] - v[2,:]) / (2.0 * dx)
        v_x[-1,:] = (u[-3,:] - 4.0 * u[-2,:] + 3.0 * u[-1,:]) / (2.0 * dx)
        v_x[1:-1,:] = (v[2:,:] - v[0:-2,:]) / (2.0 * dx)
        
        return v_x - u_y
        
        
    def water_speed(current_data):
        u,v = water_velocity(current_data)
        return np.sqrt(u**2+v**2)
        
    def water_quiver(current_data):
        u = water_u(current_data)
        v = water_v(current_data)
            
        plt.hold(True)
        Q = plt.quiver(current_data.x[::2,::2],current_data.y[::2,::2],
                        u[::2,::2],v[::2,::2])
        max_speed = np.max(np.sqrt(u**2+v**2))
        label = r"%s m/s" % str(np.ceil(0.5*max_speed))
        plt.quiverkey(Q,0.15,0.95,0.5*max_speed,label,labelpos='W')
        plt.hold(False)    
    

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

    # 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.02
    plotitem.pcolor_cmax = 0.02
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_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 = 0.05
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0,0,0]
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'

    

    #-----------------------------------------
    # Figure for imshow plot
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Surface and Gauge 1', figno=20)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('imshow')
    plotaxes.axescmd = "axes([.1,.5,.8,.4])"
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.afteraxes = addgauges

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.imshow_cmap = geoplot.tsunami_colormap
    plotitem.imshow_cmin = -0.03
    plotitem.imshow_cmax = 0.03
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 0.05
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0,0,0]
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'


    # Gauge trace:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "axes([.1,.1,.8,.3])"
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = [-0.02, 0.05]
    plotaxes.title = 'Gauge 1'

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


    #-----------------------------------------
    # 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('monai')
    #plotaxes.axescmd = 'axes([0.0,0.1,0.6,0.6])'
    plotaxes.title = 'Zoom near Monai Valley'
    plotaxes.scaled = True
    plotaxes.xlimits = [4.0, 5.2]
    plotaxes.ylimits = [1.3, 2.5]

    # 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.02
    plotitem.pcolor_cmax = 0.02
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0]
    plotitem.amr_gridedges_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 = 0.05
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [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(-0.02, 0., .0025)
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles':'solid'}
    plotitem.amr_contour_show = [1]  # show contours only on finest level
    plotitem.gridlines_show = 0
    plotitem.gridedges_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., .2, .01)
    plotitem.amr_contour_colors = ['w']  # color on each level
    plotitem.kwargs = {'linestyles':'solid'}
    plotitem.amr_contour_show = [1]  # show contours only on finest level
    plotitem.gridlines_show = 0
    plotitem.gridedges_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 = [1]  # show contours only on finest level
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0
    plotitem.show = True




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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0,60]
    plotaxes.ylimits = [-0.02, 0.05]
    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.clf_each_gauge = False
    plotitem.plotstyle = 'g-'
    def afteraxes(current_data):
        from pylab import plot, legend, loadtxt
        t = current_data.t
        plot(t, 0*t, 'k')
        try:
            labgage = loadtxt('WaveGages.txt',skiprows=1)
        except:
            print "*** Did not find WaveGages.txt from benchmark"
        gaugeno = current_data.gaugeno
        
        if gaugeno in [1,2,3]:
            plot(labgage[:,0],0.01*labgage[:,gaugeno],'r')
            legend(('GeoClaw','topography','sea level','lab data'),loc='upper right')
        else:
            legend(('GeoClaw','topography','sea level'),loc='upper right')
            
        

    plotaxes.afteraxes = afteraxes


    #-----------------------------------------
    # Figure for grids alone
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='grids', 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 = 'grids'
    plotaxes.scaled = True

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_grid')
    plotitem.amr_grid_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']
    plotitem.amr_gridlines_show = [1,1,0]   
    plotitem.amr_gridedges_show = [1]     
    
    
    # ========================================================================
    #  Water Currents
    # ========================================================================
    max_speed = 1.0
    
    # ========================================================================
    # Full plot
    plotfigure = plotdata.new_plotfigure(name='currents', figno=400)
    plotfigure.kwargs = {'figsize':[12,7]}
    plotfigure.show = True

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

    # Speed
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = water_speed
    plotitem.imshow_cmap = plt.get_cmap('PuBu')
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = max_speed
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.add_colorbar = False
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 0.05
    
    # ========================================================================
    # Zoomed plot
    plotfigure = plotdata.new_plotfigure(name='currents_zoomed', figno=401)
    plotfigure.kwargs = {'figsize':[12,7]}
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Currents Zoomed Domain'
    plotaxes.scaled = True
    plotaxes.xlimits = [4.0, 5.2]
    plotaxes.ylimits = [1.3, 2.5]

    # Speed
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = water_speed
    plotitem.imshow_cmap = plt.get_cmap('PuBu')
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = max_speed
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.add_colorbar = False
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 0.05
    
    # ========================================================================
    # Vorticity plot
    vorticity_limits = [-3,3]
    #  Full domain
    plotfigure = plotdata.new_plotfigure(name='full_vorticity', figno=500)
    plotfigure.show = True

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

    # Speed
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = vorticity
    plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.imshow_cmin = vorticity_limits[0]
    plotitem.imshow_cmax = vorticity_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.add_colorbar = False
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 0.05

    #-----------------------------------------
    
    # 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 = [1,2,3,12]  # 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?

    return plotdata
Beispiel #16
0
yellow1= [.98,.96,.01];
tan1 = [.98,.83,.01];
tan2 = [.71,.62,.085];
tan3 = [.65,.56,.07];
tan4 = [.58,.50,.064];
tan5 = [.48,.415,.043];
tan6 = [0.42,0.36,0.038];
tan7 = [.36,.233,.029];

brown1=[.42,.167,.03];


# Colormaps
TSUNAMI_MAX_AMPLITUDE = 0.6
tsunami_colormap = colormaps.make_colormap({-TSUNAMI_MAX_AMPLITUDE:blue,
                                            0.0:blue_green,
                                            TSUNAMI_MAX_AMPLITUDE:red})

oso_debris_colormap = colormaps.make_colormap({0.0:white,
                                            10.0: light_blue,
                                            20.0: blue,
                                            30.0: dark_blue})

oso_debris_colormap_invert = colormaps.make_colormap({0.0:dark_blue,
                                            #10.0: blue,
                                            #20.0: light_blue,
                                            30.0: white})

oso_land_colormap_gray = colormaps.make_colormap({0.0: gray8,
                                           1.0: gray5})
Beispiel #17
0
def plot_topo_file(topoplotdata):
    """
    Read in a topo or bathy file and produce a pcolor map.
    """

    import os
    import pylab
    from pyclaw.data import Data

    fname = topoplotdata.fname
    topotype = topoplotdata.topotype
    if topoplotdata.climits:
        # deprecated option
        cmin = topoplotdata.climits[0]
        cmax = topoplotdata.climits[1]
    else:
        cmin = topoplotdata.cmin
        cmax = topoplotdata.cmax
    figno = topoplotdata.figno
    addcolorbar = topoplotdata.addcolorbar
    addcontour = topoplotdata.addcontour
    contour_levels = topoplotdata.contour_levels
    xlimits = topoplotdata.xlimits
    ylimits = topoplotdata.ylimits
    coarsen = topoplotdata.coarsen
    imshow = topoplotdata.imshow
    gridedges_show = topoplotdata.gridedges_show
    neg_cmap = topoplotdata.neg_cmap
    pos_cmap = topoplotdata.pos_cmap
    print_fname = topoplotdata.print_fname


    if neg_cmap is None:
        neg_cmap = colormaps.make_colormap({cmin:[0.3,0.2,0.1],
                                                0:[0.95,0.9,0.7]})
    if pos_cmap is None:
        pos_cmap = colormaps.make_colormap({    0:[.5,.7,0],
                                              cmax:[.2,.5,.2]})

    if abs(topotype) == 1:

        X,Y,topo = topotools.topofile2griddata(fname, topotype)
        topo = pylab.flipud(topo)
        Y = pylab.flipud(Y)
        x = X[0,:]
        y = Y[:,0]
        xllcorner = x[0]
        yllcorner = y[0]
        cellsize = x[1]-x[0]


    elif abs(topotype) == 3:

        file = open(fname, 'r')
        lines = file.readlines()
        ncols = int(lines[0].split()[0])
        nrows = int(lines[1].split()[0])
        xllcorner = float(lines[2].split()[0])
        yllcorner = float(lines[3].split()[0])
        cellsize = float(lines[4].split()[0])
        NODATA_value = int(lines[5].split()[0])

        print "Loading file ",fname
        print "   nrows = %i, ncols = %i" % (nrows,ncols)
        topo = pylab.loadtxt(fname,skiprows=6,dtype=float)
        print "   Done loading"

        if 0:
            topo = []
            for i in range(nrows):
                topo.append(pylab.array(lines[6+i],))
            print '+++ topo = ',topo
            topo = pylab.array(topo)

        topo = pylab.flipud(topo)

        x = pylab.linspace(xllcorner, xllcorner+ncols*cellsize, ncols)
        y = pylab.linspace(yllcorner, yllcorner+nrows*cellsize, nrows)
        print "Shape of x, y, topo: ", x.shape, y.shape, topo.shape

    else:
        raise Exception("*** Only topotypes 1 and 3 supported so far")


    if coarsen > 1:
        topo = topo[slice(0,nrows,coarsen), slice(0,ncols,coarsen)]
        x = x[slice(0,ncols,coarsen)]
        y = y[slice(0,nrows,coarsen)]
        print "Shapes after coarsening: ", x.shape, y.shape, topo.shape


    if topotype < 0:
        topo = -topo

    if figno:
        pylab.figure(figno)

    if topoplotdata.imshow:
            color_norm = Normalize(cmin,cmax,clip=True)
            xylimits = (x[0],x[-1],y[0],y[-1])
            #pylab.imshow(pylab.flipud(topo.T), extent=xylimits, \
            pylab.imshow(pylab.flipud(topo), extent=xylimits, \
                    cmap=cmap, interpolation='nearest', \
                    norm=color_norm)
    else:
        neg_topo = ma.masked_where(topo>0., topo)
        all_masked = (ma.count(neg_topo) == 0)
        if not all_masked:
            pylab.pcolormesh(x,y,neg_topo,cmap=neg_cmap)
            pylab.clim([cmin,0])
            if addcolorbar:
                pylab.colorbar()

        pos_topo = ma.masked_where(topo<0., topo)
        all_masked = (ma.count(pos_topo) == 0)
        if not all_masked:
            pylab.pcolormesh(x,y,pos_topo,cmap=pos_cmap)
            pylab.clim([0,cmax])
            if addcolorbar:
                pylab.colorbar()

    pylab.axis('scaled')


    if addcontour:
        pylab.contour(x,y,topo,levels=contour_levels,colors='k')

    if gridedges_show:
        pylab.plot([x[0],x[-1]],[y[0],y[0]],'k')
        pylab.plot([x[0],x[-1]],[y[-1],y[-1]],'k')
        pylab.plot([x[0],x[0]],[y[0],y[-1]],'k')
        pylab.plot([x[-1],x[-1]],[y[0],y[-1]],'k')

    if print_fname:
        fname2 = os.path.splitext(fname)[0]
        pylab.text(xllcorner+cellsize, yllcorner+cellsize, fname2, color='m')

    topodata = Data()
    topodata.x = x
    topodata.y = y
    topodata.topo = topo

    return topodata
Beispiel #18
0
light_green = [0.8, 1.0, 0.5]
blue = [0.0, 0.0, 1.0]
dark_blue = [0.2, 0.2, 0.7]
light_blue = [0.5, 0.5, 1.0]
blue_green = [0.0, 1.0, 1.0]
tan = [0.9, 0.8, 0.2]
tan = [0.8, 0.5, 0.2]
brown = [0.9, 0.8, 0.2]
gray8 = [0.8, 0.8, 0.8]
purple = [0.8, 0.3, 0.8]

# Colormaps
TSUNAMI_MAX_AMPLITUDE = 0.6
tsunami_colormap = colormaps.make_colormap({
    -TSUNAMI_MAX_AMPLITUDE: blue,
    0.0: blue_green,
    TSUNAMI_MAX_AMPLITUDE: red
})

land1_colormap = colormaps.make_colormap({
    0.0: dark_green,
    1000.0: green,
    2000.0: light_green,
    4000.0: tan
})

land2_colormap = colormaps.make_colormap({
    0: dark_green,
    50: green,
    100: light_green,
    200: tan
Beispiel #19
0
dark_green = [0.1,0.4,0.0];
light_green = [0.8,1.0,0.5];
blue = [0.0,0.0,1.0];
dark_blue = [0.2,0.2,0.7];
light_blue = [0.5,0.5,1.0];
blue_green = [0.0,1.0,1.0];
tan = [0.9,0.8,0.2];
tan = [0.8,0.5,0.2];
brown = [0.9,0.8,0.2];
gray8 = [0.8,0.8,0.8];
purple = [0.8,0.3,0.8];

# Colormaps
TSUNAMI_MAX_AMPLITUDE = 0.6
tsunami_colormap = colormaps.make_colormap({-TSUNAMI_MAX_AMPLITUDE:blue,
                                            0.0:blue_green,
                                            TSUNAMI_MAX_AMPLITUDE:red})
                                            
land1_colormap = colormaps.make_colormap({0.0:dark_green,
                                          1000.0:green,
                                          2000.0:light_green,
                                          4000.0:tan})
                                         
land2_colormap = colormaps.make_colormap({0:dark_green,
                                          50:green,
                                          100:light_green,
                                          200:tan})
                                          
water_land_colormap = colormaps.make_colormap({-1000:dark_blue,
                                               -500:blue,
                                               0:light_blue,
Beispiel #20
0
def setplot(plotdata):
    # --------------------------

    """
    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 pyclaw.plotters import colormaps, geoplot

    plotdata.clearfigures()  # clear any old figures,axes,items dat
    #   plotdata.format = "netcdf"

    try:
        tsudata = open(plotdata.outdir + "/settsunami.data").readlines()
        for line in tsudata:
            if "sealevel" in line:
                sealevel = float(line.split()[0])
                print "sealevel = ", sealevel
    except:
        print "Could not read sealevel, setting to 0."
        sealevel = 0.0

    # clim_ocean = 2.0
    # clim_CC = 2.0
    clim_ocean = 5.0
    clim_CC = 5.0

    cmax_ocean = clim_ocean + sealevel
    cmin_ocean = -clim_ocean + sealevel
    cmax_CC = clim_CC + sealevel
    cmin_CC = -clim_CC + sealevel

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

    def addgauges(current_data):
        from pyclaw.plotters import gaugetools

        gaugetools.plot_gauge_locations(current_data.plotdata, gaugenos=[0], format_string="ko", add_labels=True)

    def timeformat(t):
        from numpy import mod

        hours = int(t / 3600.0)
        tmin = mod(t, 3600.0)
        min = int(tmin / 60.0)
        sec = int(mod(tmin, 60.0))
        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)

    def aframe(current_data):
        from pylab import figure, savefig

        if 0:
            tminutes = int(current_data.t / 60.0)

            figure(0)
            fname = "Pacific%s.png" % tminutes
            savefig(fname)
            print "Saved ", fname

            figure(11)
            fname = "GraysHarbor%s.png" % tminutes
            savefig(fname)
            print "Saved ", fname

            figure(12)
            fname = "Westport%s.png" % tminutes
            savefig(fname)
            print "Saved ", fname

            figure(13)
            fname = "Ocosta%s.png" % tminutes
            savefig(fname)
            print "Saved ", fname

    plotdata.afterframe = aframe

    # -----------------------------------------
    # Figure for big area
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="Pacific", figno=0)
    plotfigure.kwargs = {"figsize": (10, 6)}
    # plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    # plotaxes.cmd = 'subplot(121)'
    plotaxes.title = "Pacific"
    plotaxes.scaled = False
    # modified for debug:
    # plotaxes.xlimits = [231.5,236.5]
    # plotaxes.ylimits = [45,49]
    # plotaxes.xlimits = [235.8,236.2]
    # plotaxes.ylimits = [46.1,46.9]

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, savefig

        title_hours(current_data)
        ticklabel_format(format="plain", useOffset=False)
        xticks(rotation=20)
        a = gca()
        a.set_aspect(1.0 / cos(46.349 * pi / 180.0))

    plotaxes.afteraxes = aa

    # Water
    plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap(
        {-1.0: [0.0, 0.0, 1.0], -0.5: [0.5, 0.5, 1.0], 0.0: [1.0, 1.0, 1.0], 0.5: [1.0, 0.5, 0.5], 1.0: [1.0, 0.0, 0.0]}
    )
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = cmin_ocean
    plotitem.imshow_cmax = cmax_ocean
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]
    # plotaxes.afteraxes = addgauges

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

    plotitem.contour_levels = linspace(-6000, 0, 7)
    plotitem.amr_contour_colors = ["g"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid"}
    plotitem.amr_contour_show = [0, 0, 1, 0]  # show contours only on finest level
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

    # Add contour lines of topography:
    plotitem = plotaxes.new_plotitem(plot_type="2d_contour")
    plotitem.show = False
    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, 0, 1]  # show contours only on finest level
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

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

    def eta_slice(current_data):
        from pylab import find, nan, array

        x = current_data.x
        y = current_data.y
        q = current_data.q
        j1 = find(y[0, :] > 47.5)
        if len(j1) == 0:
            x = eta = array([nan])
        else:
            j = min(j1)
            x = x[:, j]
            eta = q[:, j, 3]
        return x, eta

    def B_slice(current_data):
        from pylab import find, nan, array

        x = current_data.x
        y = current_data.y
        q = current_data.q
        j1 = find(y[0, :] > 47.5)
        if len(j1) == 0:
            x = B = array([nan])
        else:
            j = min(j1)
            x = x[:, j]
            eta = q[:, j, 3]
            h = q[:, j, 0]
            B = eta - h
        return x, B

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes("line")
    plotaxes.axescmd = "subplot(212)"
    plotaxes.title = "Bathymetry"

    # Water
    plotitem = plotaxes.new_plotitem(plot_type="1d_from_2d_data")
    plotitem.show = False
    plotitem.map_2d_to_1d = eta_slice
    plotitem.color = "b"
    plotitem.kwargs = {"linewidth": 2}

    # Topography
    plotitem = plotaxes.new_plotitem(plot_type="1d_from_2d_data")
    # plotitem.show = False
    plotitem.map_2d_to_1d = B_slice
    plotitem.color = "k"
    plotitem.plotstyle = "o-"

    def aa(current_data):
        from pylab import ticklabel_format

        ticklabel_format(format="plain", useOffset=False)

    plotaxes.afteraxes = aa

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes("linezoom")
    # plotaxes.show = False
    plotaxes.axescmd = "subplot(211)"
    plotaxes.title = "Surface"
    # plotaxes.xlimits = [-0.1,0.1]
    plotaxes.ylimits = [-4, 6]

    # Water
    plotitem = plotaxes.new_plotitem(plot_type="1d_from_2d_data")
    plotitem.map_2d_to_1d = eta_slice
    plotitem.color = "b"
    plotitem.plotstyle = "o-"
    plotitem.kwargs = {"linewidth": 2}

    # -----------------------------------------
    # Figure for zoom2
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="Gray's Harbor", figno=11)
    plotfigure.show = False
    plotfigure.kwargs = {"figsize": (10, 9)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    # plotaxes.cmd = 'subplot(122)'
    plotaxes.title = "Gray's Harbor"
    plotaxes.scaled = False

    # Water
    plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap(
        {-1.0: [0.0, 0.0, 1.0], -0.5: [0.5, 0.5, 1.0], 0.0: [1.0, 1.0, 1.0], 0.5: [1.0, 0.5, 0.5], 1.0: [1.0, 0.0, 0.0]}
    )
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = cmin_CC
    plotitem.imshow_cmax = cmax_CC
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [0]
    plotaxes.xlimits = [235.8, 236.2]
    plotaxes.ylimits = [46.75, 47.1]

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, savefig

        # addgauges(current_data)
        title_hours(current_data)
        ticklabel_format(format="plain", useOffset=False)
        xticks(rotation=20)
        a = gca()
        a.set_aspect(1.0 / cos(46.86 * pi / 180.0))

    plotaxes.afteraxes = aa

    # 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.0]
    plotitem.amr_contour_colors = ["k"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid", "linewidths": 2}
    plotitem.amr_contour_show = [0, 0, 0, 0, 1, 0]
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

    # -----------------------------------------
    # Figure for zoom
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="Washington", figno=10)
    plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = "Washington"
    plotaxes.scaled = False
    plotaxes.afteraxes = aa

    # Water
    plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap(
        {-1.0: [0.0, 0.0, 1.0], -0.1: [0.5, 0.5, 1.0], 0.0: [1.0, 1.0, 1.0], 0.1: [1.0, 0.5, 0.5], 1.0: [1.0, 0.0, 0.0]}
    )
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = cmin_ocean
    plotitem.imshow_cmax = cmax_ocean
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]
    plotaxes.xlimits = [235, 236.5]
    plotaxes.ylimits = [46, 49]
    plotaxes.afteraxes = aa

    # -----------------------------------------
    # Figure for zoom3
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="Long Beach", figno=12)
    plotfigure.show = False
    plotfigure.kwargs = {"figsize": (8, 7)}

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
    # plotitem.show = False
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap(
        {-1.0: [0.0, 0.0, 1.0], -0.5: [0.5, 0.5, 1.0], 0.0: [1.0, 1.0, 1.0], 0.5: [1.0, 0.5, 0.5], 1.0: [1.0, 0.0, 0.0]}
    )
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = cmin_ocean
    plotitem.imshow_cmax = cmax_ocean
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
    plotitem.plot_var = geoplot.land
    # plotitem.plot_var = 3
    land_cmap = colormaps.make_colormap({0.0: [0.0, 0.0, 1.0], 0.5: [1.0, 0.0, 0.0], 1.0: [0.0, 1.0, 0.0]})
    plotitem.imshow_cmap = geoplot.land_colors
    # plotitem.imshow_cmap = land_cmap
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 10.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [0]
    plotaxes.xlimits = [235.90, 235.98]
    plotaxes.ylimits = [46.30, 46.39]

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, imshow, savefig, plot
        from pyclaw.plotters.plottools import plotbox

        # addgauges(current_data)
        title_hours(current_data)
        ticklabel_format(format="plain", useOffset=False)
        xticks(rotation=20)
        a = gca()
        # a.set_aspect(1./cos(46.86*pi/180.))
        a.set_aspect(1.0 / cos(46.349 * pi / 180.0))
        plot([235.9499], [46.3490], "wo")
        # extent = (235.8756, 235.9116, 46.854, 46.8756)
        # plotbox(extent)
        # imshow(OcostaGE,extent=extent, alpha=0.5)
        # extent = (235.81, 235.95, 46.85, 46.95)
        # imshow(WestportGE,extent=extent, alpha=0.8)

    plotaxes.afteraxes = aa

    # 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.0]
    plotitem.amr_contour_colors = ["k"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid", "linewidths": 2}
    plotitem.amr_contour_show = [0, 0, 0, 0, 1, 0]
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

    # -----------------------------------------
    # Figure for zoom4
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="Berm", figno=13)
    plotfigure.show = False
    plotfigure.kwargs = {"figsize": (12, 8)}

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
    # plotitem.show=False
    plotitem.plot_var = geoplot.depth
    # plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({0.0: [1.0, 1.0, 1.0], 0.5: [1.0, 0.8, 0.0], 1.0: [1.0, 0.0, 0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 3.0
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
    # plotitem.show=False
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 20.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    # plotaxes.xlimits = [235.88, 235.905]
    # plotaxes.ylimits = [46.855, 46.87]
    plotaxes.xlimits = [235.947, 235.951]
    plotaxes.ylimits = [46.347, 46.35]

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, imshow, savefig, plot

        addgauges(current_data)
        title_hours(current_data)
        ticklabel_format(format="plain", useOffset=False)
        xticks(rotation=20)
        plot([235.9499], [46.3490], "wo")
        # extent = (235.8756, 235.9116, 46.854, 46.8756)
        # imshow(OcostaGE,extent=extent, alpha=0.5)
        a = gca()
        a.set_aspect(1.0 / cos(46.349 * pi / 180.0))
        # extent = (235.81, 235.95, 46.85, 46.95)
        # imshow(WestportGE,extent=extent, alpha=0.8)

    plotaxes.afteraxes = aa

    # 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.0]
    plotitem.amr_contour_colors = ["k"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid", "linewidths": 2}
    plotitem.amr_contour_show = [0, 0, 0, 0, 1, 0]
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

    # -----------------------------------------
    # Figure for zoom4 speed
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="Ocosta speed", figno=14)
    plotfigure.show = False
    plotfigure.kwargs = {"figsize": (12, 8)}

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
    # plotitem.show=False
    def speed(current_data):
        from numpy import sqrt, where

        q = current_data.q
        h = q[:, :, 0]
        hu = q[:, :, 1]
        hv = q[:, :, 2]
        u = where(h > 0.01, hu / h, 0.0)
        v = where(h > 0.01, hv / h, 0.0)
        speed = sqrt(u ** 2 + v ** 2)
        return v

    plotitem.plot_var = speed
    # plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({0.0: [0.0, 0.0, 1.0], 0.5: [1.0, 1.0, 1.0], 1.0: [1.0, 0.0, 0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = -3.0
    plotitem.imshow_cmax = 3.0
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type="2d_imshow")
    # plotitem.show=False
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 20.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    # plotaxes.xlimits = [235.88, 235.905]
    # plotaxes.ylimits = [46.855, 46.87]
    plotaxes.xlimits = [235.88, 235.935]
    plotaxes.ylimits = [46.845, 46.875]

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, imshow, savefig

        addgauges(current_data)
        title_hours(current_data)
        ticklabel_format(format="plain", useOffset=False)
        xticks(rotation=20)
        # extent = (235.8756, 235.9116, 46.854, 46.8756)
        # imshow(OcostaGE,extent=extent, alpha=0.5)
        a = gca()
        a.set_aspect(1.0 / cos(46.86 * pi / 180.0))
        # extent = (235.81, 235.95, 46.85, 46.95)
        # imshow(WestportGE,extent=extent, alpha=0.8)

    plotaxes.afteraxes = aa

    # 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.0]
    plotitem.amr_contour_colors = ["k"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid", "linewidths": 2}
    plotitem.amr_contour_show = [0, 0, 0, 0, 1, 0]
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

    # -----------------------------------------
    # Figures for gauges
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="gauge plot", figno=300, type="each_gauge")
    # plotfigure.clf_each_gauge = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.ylimits = [-1, 10]
    plotaxes.xlimits = [-1, 10]
    plotaxes.title = "Surface"

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

    def axes_gauge(current_data):
        from pylab import plot, legend, xticks, floor, yticks, xlabel, savefig, xlim, ylim, xlabel, ylabel

        t = current_data.t
        gaugeno = current_data.gaugeno
        xticks(linspace(0, 1, 7), [str(i) for i in range(0, 7, 10)])
        xlabel("time (minutes) after quake", fontsize=15)
        ylabel("meters", fontsize=15)
        ylim(-1, 10)

    plotaxes.afteraxes = axes_gauge

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

    # 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_fignos = "all"  # list of figures to print
    plotdata.print_gaugenos = "all"  # list of gauges 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?

    return plotdata
Beispiel #21
0
def setplot(plotdata):
# --------------------------
    
    """ 
    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 pyclaw.plotters import colormaps, geoplot

    plotdata.clearfigures()  # clear any old figures,axes,items dat
#   plotdata.format = "netcdf"

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

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

    def title_hours(current_data):
        from pylab import title
        t = current_data.t
        h = t/3600.
        title('%5.2f Hours after Quake' % h)

    def plotcc(current_data):
        from pylab import plot,text
        plot([235.8162], [41.745616],'wo')
        text(235.8,41.9,'Cr.City',color='w',fontsize=10)
    

    #-----------------------------------------
    # Figure for big area
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Pacific', figno=0)
    plotfigure.kwargs = {'figsize': (16,4)}
    plotfigure.show = True

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

    def aa(current_data):
        title_hours(current_data)
        if 0:
            from pylab import savefig
            fname = 'pacific%s.png' % str(current_data.frameno).zfill(4)
            savefig(fname)
            print 'Saved ',fname
    plotaxes.afteraxes = aa

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                     -0.1: [0.5,0.5,1.0], \
                                      0.0: [1.0,1.0,1.0], \
                                      0.1: [1.0,0.5,0.5], \
                                      1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = -0.3
    plotitem.imshow_cmax = 0.3
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]
    plotaxes.xlimits = [132,238] 
    plotaxes.ylimits = [30,50]
    #plotaxes.afteraxes = addgauges

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

    # Add contour lines of topography:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = False
    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,0,1]  # show contours only on finest level
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

    #-----------------------------------------
    # Figure for zoom
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='California', figno=10)
    #plotfigure.show = False

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                      -0.1: [0.5,0.5,1.0], \
                                       0.0: [1.0,1.0,1.0], \
                                       0.1: [1.0,0.5,0.5], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = -0.3
    plotitem.imshow_cmax = 0.3
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]
    plotaxes.xlimits = [227,237] 
    plotaxes.ylimits = [35,45]
    def af(current_data):
        from pylab import savefig,figure
        figure(10)
        plotcc(current_data)
        title_hours(current_data)
        addgauges(current_data)
        if 0:
            fname = '/Users/rjl/OUTPUT/Users/rjl/Dropbox/mygeo/CC/_plots/' +\
               'california%s.png' % str(current_data.frameno).zfill(4)
            savefig(fname)
            print 'Saved ',fname

    #plotdata.afterframe = af
    plotaxes.afteraxes = af
    
    # Add contour lines of eta:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.surface
    from numpy import arange, linspace
    plotitem.contour_levels = linspace(-0.3,0.3,13)
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles':'solid'}
    plotitem.amr_contour_show = [0,0,1,0]  # AMR levels to show contours
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0
    plotitem.show = False

    # 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(-4500,0,10)
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles':'solid'}
    plotitem.amr_contour_show = [0,0,1,0]  # AMR levels to show contours
    plotitem.gridlines_show = 0
    plotitem.gridedges_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,0,1]  # show contours only on finest level
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0
    plotitem.show = False
 

    #-----------------------------------------
    
    # 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_fignos = 'all'            # list of figures to print
    plotdata.print_gaugenos = 'all'          # list of gauges 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?

    return plotdata
Beispiel #22
0
yellow1 = [.98, .96, .01]
tan1 = [.98, .83, .01]
tan2 = [.71, .62, .085]
tan3 = [.65, .56, .07]
tan4 = [.58, .50, .064]
tan5 = [.48, .415, .043]
tan6 = [0.42, 0.36, 0.038]
tan7 = [.36, .233, .029]

brown1 = [.42, .167, .03]

# Colormaps
TSUNAMI_MAX_AMPLITUDE = 0.6
tsunami_colormap = colormaps.make_colormap({
    -TSUNAMI_MAX_AMPLITUDE: blue,
    0.0: blue_green,
    TSUNAMI_MAX_AMPLITUDE: red
})

oso_debris_colormap = colormaps.make_colormap({
    0.0: white,
    10.0: light_blue,
    20.0: blue,
    30.0: dark_blue
})

oso_debris_colormap_invert = colormaps.make_colormap({
    0.0: dark_blue,
    #10.0: blue,
    #20.0: light_blue,
    30.0: white
Beispiel #23
0
def plot_topo_file(topoplotdata):
    """
    Read in a topo or bathy file and produce a pcolor map.
    """

    import os
    import pylab
    from pyclaw.data import Data

    fname = topoplotdata.fname
    topotype = topoplotdata.topotype
    if topoplotdata.climits:
        # deprecated option
        cmin = topoplotdata.climits[0]
        cmax = topoplotdata.climits[1]
    else:
        cmin = topoplotdata.cmin
        cmax = topoplotdata.cmax
    figno = topoplotdata.figno
    addcolorbar = topoplotdata.addcolorbar
    addcontour = topoplotdata.addcontour
    contour_levels = topoplotdata.contour_levels
    xlimits = topoplotdata.xlimits
    ylimits = topoplotdata.ylimits
    coarsen = topoplotdata.coarsen
    imshow = topoplotdata.imshow
    gridedges_show = topoplotdata.gridedges_show
    neg_cmap = topoplotdata.neg_cmap
    pos_cmap = topoplotdata.pos_cmap
    print_fname = topoplotdata.print_fname

    if neg_cmap is None:
        neg_cmap = colormaps.make_colormap({
            cmin: [0.3, 0.2, 0.1],
            0: [0.95, 0.9, 0.7]
        })
    if pos_cmap is None:
        pos_cmap = colormaps.make_colormap({
            0: [.5, .7, 0],
            cmax: [.2, .5, .2]
        })

    if abs(topotype) == 1:

        X, Y, topo = topotools.topofile2griddata(fname, topotype)
        topo = pylab.flipud(topo)
        Y = pylab.flipud(Y)
        x = X[0, :]
        y = Y[:, 0]
        xllcorner = x[0]
        yllcorner = y[0]
        cellsize = x[1] - x[0]

    elif abs(topotype) == 3:

        file = open(fname, 'r')
        lines = file.readlines()
        ncols = int(lines[0].split()[0])
        nrows = int(lines[1].split()[0])
        xllcorner = float(lines[2].split()[0])
        yllcorner = float(lines[3].split()[0])
        cellsize = float(lines[4].split()[0])
        NODATA_value = int(lines[5].split()[0])

        print "Loading file ", fname
        print "   nrows = %i, ncols = %i" % (nrows, ncols)
        topo = pylab.loadtxt(fname, skiprows=6, dtype=float)
        print "   Done loading"

        if 0:
            topo = []
            for i in range(nrows):
                topo.append(pylab.array(lines[6 + i], ))
            print '+++ topo = ', topo
            topo = pylab.array(topo)

        topo = pylab.flipud(topo)

        x = pylab.linspace(xllcorner, xllcorner + ncols * cellsize, ncols)
        y = pylab.linspace(yllcorner, yllcorner + nrows * cellsize, nrows)
        print "Shape of x, y, topo: ", x.shape, y.shape, topo.shape

    else:
        raise Exception("*** Only topotypes 1 and 3 supported so far")

    if coarsen > 1:
        topo = topo[slice(0, nrows, coarsen), slice(0, ncols, coarsen)]
        x = x[slice(0, ncols, coarsen)]
        y = y[slice(0, nrows, coarsen)]
        print "Shapes after coarsening: ", x.shape, y.shape, topo.shape

    if topotype < 0:
        topo = -topo

    if figno:
        pylab.figure(figno)

    if topoplotdata.imshow:
        color_norm = Normalize(cmin, cmax, clip=True)
        xylimits = (x[0], x[-1], y[0], y[-1])
        #pylab.imshow(pylab.flipud(topo.T), extent=xylimits, \
        pylab.imshow(pylab.flipud(topo), extent=xylimits, \
                cmap=cmap, interpolation='nearest', \
                norm=color_norm)
    else:
        neg_topo = ma.masked_where(topo > 0., topo)
        all_masked = (ma.count(neg_topo) == 0)
        if not all_masked:
            pylab.pcolormesh(x, y, neg_topo, cmap=neg_cmap)
            pylab.clim([cmin, 0])
            if addcolorbar:
                pylab.colorbar()

        pos_topo = ma.masked_where(topo < 0., topo)
        all_masked = (ma.count(pos_topo) == 0)
        if not all_masked:
            pylab.pcolormesh(x, y, pos_topo, cmap=pos_cmap)
            pylab.clim([0, cmax])
            if addcolorbar:
                pylab.colorbar()

    pylab.axis('scaled')

    if addcontour:
        pylab.contour(x, y, topo, levels=contour_levels, colors='k')

    if gridedges_show:
        pylab.plot([x[0], x[-1]], [y[0], y[0]], 'k')
        pylab.plot([x[0], x[-1]], [y[-1], y[-1]], 'k')
        pylab.plot([x[0], x[0]], [y[0], y[-1]], 'k')
        pylab.plot([x[-1], x[-1]], [y[0], y[-1]], 'k')

    if print_fname:
        fname2 = os.path.splitext(fname)[0]
        pylab.text(xllcorner + cellsize,
                   yllcorner + cellsize,
                   fname2,
                   color='m')

    topodata = Data()
    topodata.x = x
    topodata.y = y
    topodata.topo = topo

    return topodata
Beispiel #24
0
def setplot(plotdata):
# --------------------------
    
    """ 
    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 pyclaw.plotters import colormaps, geoplot

    plotdata.clearfigures()  # clear any old figures,axes,items dat
#   plotdata.format = "netcdf"

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

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

    def title_hours(current_data):
        from pylab import title
        t = current_data.t
        h = t/3600.
        title('%5.2f Hours after Quake' % h)

    def plotcc(current_data):
        from pylab import plot,text
        plot([235.8162], [41.745616],'wo')
        text(235.8,41.9,'Cr.City',color='w',fontsize=10)
    

    #-----------------------------------------
    # Figure for big area
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Pacific', figno=0)
    plotfigure.kwargs = {'figsize': (16,4)}
    plotfigure.show = True

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

    def aa(current_data):
        title_hours(current_data)
        if 0:
            from pylab import savefig
            fname = 'pacific%s.png' % str(current_data.frameno).zfill(4)
            savefig(fname)
            print 'Saved ',fname
    plotaxes.afteraxes = aa

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                     -0.1: [0.5,0.5,1.0], \
                                      0.0: [1.0,1.0,1.0], \
                                      0.1: [1.0,0.5,0.5], \
                                      1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = -0.3
    plotitem.imshow_cmax = 0.3
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]
    plotaxes.xlimits = [132,238] 
    plotaxes.ylimits = [30,50]
    #plotaxes.afteraxes = addgauges

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

    # Add contour lines of topography:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = False
    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,0,1]  # show contours only on finest level
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

    #-----------------------------------------
    # Figure for zoom
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='California', figno=10)
    #plotfigure.show = False

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                      -0.1: [0.5,0.5,1.0], \
                                       0.0: [1.0,1.0,1.0], \
                                       0.1: [1.0,0.5,0.5], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = -0.3
    plotitem.imshow_cmax = 0.3
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]
    plotaxes.xlimits = [227,237] 
    plotaxes.ylimits = [35,45]
    def af(current_data):
        from pylab import savefig,figure
        figure(10)
        plotcc(current_data)
        title_hours(current_data)
        addgauges(current_data)
        if 0:
            fname = '/Users/rjl/OUTPUT/Users/rjl/Dropbox/mygeo/CC/_plots/' +\
               'california%s.png' % str(current_data.frameno).zfill(4)
            savefig(fname)
            print 'Saved ',fname

    #plotdata.afterframe = af
    plotaxes.afteraxes = af
    
    # Add contour lines of eta:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.surface
    from numpy import arange, linspace
    plotitem.contour_levels = linspace(-0.3,0.3,13)
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles':'solid'}
    plotitem.amr_contour_show = [0,0,1,0]  # AMR levels to show contours
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0
    plotitem.show = False

    # 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(-4500,0,10)
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles':'solid'}
    plotitem.amr_contour_show = [0,0,1,0]  # AMR levels to show contours
    plotitem.gridlines_show = 0
    plotitem.gridedges_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,0,1]  # show contours only on finest level
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0
    plotitem.show = False
 
  #-----------------------------------------
    # Figure for zoom2
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Crescent City', figno=11)
    plotfigure.show = False

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                      -0.1: [0.5,0.5,1.0], \
                                       0.0: [1.0,1.0,1.0], \
                                       0.1: [1.0,0.5,0.5], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = -1.0
    plotitem.imshow_cmax = 1.0
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]
    plotaxes.xlimits = [235.76,235.84] 
    plotaxes.ylimits = [41.72,41.77]
    plotaxes.afteraxes = addgauges

#    # 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,0,1]  # show contours only on finest level
#    plotitem.gridlines_show = 0
#    plotitem.gridedges_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,0,1]  # show contours only on finest level
#    plotitem.gridlines_show = 0
#    plotitem.gridedges_show = 0
#    plotitem.show = True
 

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [9*3600, 13*3600]
    #plotaxes.xlimits = [8*3600, 15*3600]
    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 fix_gauge(current_data):
        from pylab import plot, legend, xticks, floor, yticks
        t = current_data.t
        gaugeno = current_data.gaugeno
        if gaugeno == 19750:
            plot(TG_19750[:,0],TG_19750[:,1],'r')
            legend(('GeoClaw','Tide Gauge'),loc='lower left')
        #plot([0,10800],[0,0],'k')
        n = int(floor(t.max()/3600.) + 2)
        xticks([3600*i for i in range(n)],[str(i) for i in range(n)],\
          fontsize=15)
        yticks(fontsize=15)

    plotaxes.afteraxes = fix_gauge


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

    # 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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.surface
    plotitem.contour_nlevels = 40
    plotitem.contour_min = -0.1
    plotitem.contour_max = 0.1
    plotitem.amr_contour_colors = ['r','k','b']  # color on each level
    plotitem.amr_contour_show = [0,1]            # show lines on each level?
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0
    plotitem.amr_grid_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']
    plotitem.show = True 

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.land
    plotitem.contour_nlevels = 40
    plotitem.contour_min = 0.0
    plotitem.contour_max = 100.0
    plotitem.amr_contour_colors = ['g']  # color on each level
    plotitem.amr_grid_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0
    plotitem.show = False 

    # Fixed grid plots:
    # -----------------

    if setplotfg is not None:

        # Repeat as desired for other fixed grids...
	# These show up when using 'make .plots'
        otherfig = plotdata.new_otherfigure('Fixed Grid 1')
        fgno = 1
        sfgno = str(fgno).zfill(2)  # e.g. '01'
        otherfig.fname = '_PlotIndex_FixedGrid%s.html' % sfgno
        def make_fgplots(plotdata):
            fgdata = setplotfg(fgno, outdir=plotdata.outdir)
            # See the setplotfg function for setting up fixed grid plots
            fgdata.fg2html(framenos='all')
        otherfig.makefig = make_fgplots


    #-----------------------------------------
    
    # 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_fignos = 'all'            # list of figures to print
    plotdata.print_gaugenos = 'all'          # list of gauges 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?

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

    import os

    import numpy as np
    import matplotlib.pyplot as plt

    from pyclaw.plotters import colormaps, geoplot
    from pyclaw.data import Data

    amrdata = Data(os.path.join(plotdata.outdir,'amr2ez.data'))
    hurricane_data = Data(os.path.join(plotdata.outdir,'hurricane.data'))
    multilayer_data = Data(os.path.join(plotdata.outdir,'multilayer.data'))
    
    if multilayer_data.bathy_type == 1:
        ref_lines = [multilayer_data.bathy_location]
    elif multilayer_data.bathy_type == 2:
        ref_lines = [multilayer_data.x0,multilayer_data.x1,multilayer_data.x2]
    else:
        ref_lines = []
    
    plotdata.clearfigures()
    plotdata.clear_frames = False
    plotdata.clear_figs = True
    
    plotdata.save_frames = False
    
    # ========================================================================
    #  Generic helper functions
    # ========================================================================        
    def bathy_ref_lines(current_data):
        plt.hold(True)
        y = [amrdata.ylower,amrdata.yupper]
        for ref_line in ref_lines:
            plt.plot([ref_line,ref_line],y,'y--')
        plt.hold(False)
        
    def day_figure_title(current_data):
        t = current_data.t
        title = current_data.plotaxes.title
        plt.title('%s at time t = %s days' % (title,str(t/(3600.0*24.0))))
        
    def m_to_km_labels(current_data=None):
        plt.xlabel('km')
        plt.ylabel('km')
        locs,labels = plt.xticks()
        labels = locs/1.e3
        plt.xticks(locs,labels)
        locs,labels = plt.yticks()
        labels = locs/1.e3
        plt.yticks(locs,labels)
    
    def pcolor_afteraxes(current_data):
        day_figure_title(current_data)
        m_to_km_labels()
        bathy_ref_lines(current_data)
        # gauge_locations(current_data)
        
    def contour_afteraxes(current_data):
        day_figure_title(current_data)
        m_to_km_labels()
        bathy_ref_lines(current_data)

    # ========================================================================
    # Gauge functions
    # ========================================================================
    def gauge_locations(current_data,gaugenos='all'):
        from pyclaw.plotters import gaugetools
        plt.hold(True)
        gaugetools.plot_gauge_locations(current_data.plotdata, \
             gaugenos=gaugenos, format_string='kx', add_labels=True)
        plt.hold(False)

    def gaugetopo(current_data):
        q = current_data.q
        h = q[:,0]
        eta = q[:,3]
        topo = eta - h
        return topo
        
    def gauge_afteraxes(current_data):
        # Change time to hours
        plt.xlabel('t (days)')
        plt.ylabel('m')
        locs,labels = plt.xticks()
        # import pdb; pdb.set_trace()
        labels = np.trunc(locs/(24.0*3600.0))
        # locs = np.linspace(-12.0,40,52)
        # labels = range(-12,41)
        plt.xticks(locs,labels)
        
        # Add sea level line
        # t = current_data.t
        plt.hold(True)
        plt.plot([0,0],[0,40],'k-')
        plt.hold(False)
        
    # ========================================================================
    #  Water helper functions
    # ========================================================================
    def b(cd):
        return cd.q[:,:,3] - cd.q[:,:,0]
        
    def extract_eta(h,eta,DRY_TOL=10**-3):
        index = np.nonzero((np.abs(h) < DRY_TOL) + (h == np.nan))
        eta[index[0],index[1]] = np.nan
        return eta
    
    def extract_velocity(h,hu,DRY_TOL=10**-8):
        # u = np.ones(hu.shape) * np.nan
        u = np.zeros(hu.shape)
        index = np.nonzero((np.abs(h) > DRY_TOL) * (h != np.nan))
        u[index[0],index[1]] = hu[index[0],index[1]] / h[index[0],index[1]]
        return u
    
    def eta(cd):
        return extract_eta(cd.q[:,:,0],cd.q[:,:,3])
        
    def water_u(cd):
        # index = np.nonzero(current_data.q[:,:,0] > 1e-6)
        # u = np.zeros(current_data.q[:,:,1].shape)
        # u[index] = current_data.q[index,1] / current_data.q[index,0]
        # return u
        return extract_velocity(cd.q[:,:,0],cd.q[:,:,1])
        # return np.where(abs(current_data.q[:,:,0]) > 10**-16,
        #     current_data.q[:,:,1] / current_data.q[:,:,0],
        #     0.0)
        
    def water_v(cd):
        # index = np.nonzero(current_data.q[:,:,0] > 1e-6)
        # v = np.zeros(current_data.q[:,:,2].shape)
        # v[index] = current_data.q[index,2] / current_data.q[index,0]
        # return u
        return extract_velocity(cd.q[:,:,0],cd.q[:,:,2])
        # return np.where(abs(current_data.q[:,:,0]) > 10**-16,
        #     current_data.q[:,:,2] / current_data.q[:,:,0],
        #     0.0)
        
    def water_speed(current_data):
        u = water_u(current_data)
        v = water_v(current_data)
            
        return np.sqrt(u**2+v**2)
        
    def water_quiver(current_data):
        u = water_u(current_data)
        v = water_v(current_data)
            
        plt.hold(True)
        Q = plt.quiver(current_data.x[::2,::2],current_data.y[::2,::2],
                        u[::2,::2],v[::2,::2])
        max_speed = np.max(np.sqrt(u**2+v**2))
        label = r"%s m/s" % str(np.ceil(0.5*max_speed))
        plt.quiverkey(Q,0.15,0.95,0.5*max_speed,label,labelpos='W')
        plt.hold(False)
            
    def wind_x(cd):
        return cd.q[:,:,4]
    def wind_y(cd):
        return cd.q[:,:,5]
    def wind_speed(cd):
        return np.sqrt(wind_x(cd)**2 + wind_y(cd)**2)

    # ========================================================================
    #  Profile functions
    # ========================================================================
    class PlotProfile(object):
    
        def __init__(self,slice_value = 0.0):
            self.slice_value = slice_value
    
        def slice_index(self,cd):
            if cd.grid.y.lower < self.slice_value < cd.grid.y.upper:
                return int((self.slice_value - cd.grid.y.lower) / cd.dy - 0.5)
            else:
                return None
    
        def bathy_profile(self,current_data):
            index = self.slice_index(current_data)
            if index:
                return current_data.x[:,index], b(current_data)[:,index]
            else:
                return None, None
        
        def surface_profile(self,current_data):
            index = self.slice_index(current_data)
            if index:
                return current_data.x[:,index], eta(current_data)[:,index]
            else:
                return None, None

    # ========================================================================
    #  Plot items
    # ========================================================================
    def add_surface_elevation(plotaxes,bounds=None,plot_type='pcolor'):
        if plot_type == 'pcolor' or plot_type == 'imshow':            
            plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
            # plotitem.plotvar = eta
            plotitem.plot_var = geoplot.surface
            plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
            if bounds is not None:
                plotitem.imshow_cmin = bounds[0]
                plotitem.imshow_cmax = bounds[1]
            plotitem.add_colorbar = True
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1,1,1]
        elif plot_type == 'contour':            
            plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
            plotitem.plot_var = geoplot.surface
            if bounds is None:
                plotitem.contour_levels = [-2.5,-1.5,-0.5,0.5,1.5,2.5]
            # plotitem.contour_nlevels = 21
            # plotitem.contour_min = -2.0
            # plotitem.contour_max = 2.0
            # plotitem.kwargs = {''}
            plotitem.amr_contour_show = [1,1,1]
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1,1,1]
            plotitem.amr_contour_colors = 'k'
            # plotitem.amr_contour_colors = ['r','k','b']  # color on each level
            # plotitem.amr_grid_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']
    
    def add_speed(plotaxes,bounds=None,plot_type='pcolor'):
        if plot_type == 'pcolor' or plot_type == 'imshow':
            plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
            plotitem.plot_var = water_speed
            # plotitem.plot_var = 1
            plotitem.imshow_cmap = plt.get_cmap('PuBu')
            if bounds is not None:
                plotitem.imshow_cmin = bounds[0]
                plotitem.imshow_cmax = bounds[1]
            plotitem.add_colorbar = True
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1]
        elif plot_type == 'quiver':
            plotitem = plotaxes.new_plotitem(plot_type='2d_quiver')
            plotitem.quiver_var_x = water_u
            plotitem.quiver_var_y = water_v
            plotitem.amr_quiver_show = [4,10,10]
            plotitem.amr_show_key = [True,True,False]
            plotitem.key_units = 'm/s'
            
        elif plot_type == 'contour':
            plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
            plotitem.plot_var = water_speed
            plotitem.kwargs = {'linewidths':1}
            # plotitem.contour_levels = [1.0,2.0,3.0,4.0,5.0,6.0]
            plotitem.contour_levels = [0.5,1.5,3,4.5,6.0]
            plotitem.amr_contour_show = [1,1,1]
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1,1,1]
            plotitem.amr_contour_colors = 'k'
            # plotitem.amr_contour_colors = ['r','k','b']  # color on each level
            # plotitem.amr_grid_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']
            

    def add_x_velocity(plotaxes,plot_type='pcolor',bounds=None):
        if plot_type == 'pcolor' or plot_type == 'imshow':
            plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
            plotitem.plot_var = water_u
            if bounds is not None:
                plotitem.imshow_cmin = bounds[0]
                plotitem.imshow_cmax = bounds[1]
            plotitem.add_colorbar = True
            plotitem.imshow_cmap = plt.get_cmap('PiYG')
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1]
        elif plot_type == 'contour':
            pass
    
    def add_y_velocity(plotaxes,plot_type='pcolor',bounds=None):
        if plot_type == 'pcolor' or plot_type == 'imshow':
            plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
            plotitem.plot_var = water_v
            if bounds is not None:
                plotitem.imshow_cmin = bounds[0]
                plotitem.imshow_cmax = bounds[1]
            plotitem.imshow_cmap = plt.get_cmap('PiYG')
            plotitem.add_colorbar = True
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1]
        elif plot_type == 'contour':
            pass
            
    def add_wind(plotaxes,bounds=None,plot_type='pcolor'):
        if plot_type == 'pcolor' or plot_type == 'imshow':
            plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
            plotitem.plot_var = wind_speed
            plotitem.imshow_cmap = plt.get_cmap('PuBu')
            if bounds is not None:
                plotitem.imshow_cmin = bounds[0]
                plotitem.imshow_cmax = bounds[1]
            plotitem.add_colorbar = True
            plotitem.amr_imshow_show = [1,1,1]
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1,1,1]
        elif plot_type == 'contour':
            plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
            plotitem.plot_var = wind_speed
            plotitem.contour_nlevels = hurricane_data.max_wind_nest
            plotitem.countour_min = hurricane_data.wind_refine[0]
            plotitem.gridedges_show = 1
        elif plot_type == 'quiver':
            plotitem = plotaxes.new_plotitem(plot_type='2d_quiver')
            plotitem.quiver_var_x = wind_x
            plotitem.quiver_var_y = wind_y
            plotitem.amr_quiver_show = [0,0,1]
            plotitem.amr_quiver_key_show = [True,False,False]
            plotitem.amr_quiver_key_units = 'm/s'
            
    def add_vorticity(plotaxes,bounds=None,plot_type="pcolor"):
        if plot_type == 'pcolor' or plot_type == 'imshow':            
            plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
            plotitem.plot_var = 9
            plotitem.imshow_cmap = plt.get_cmap('PRGn')
            if bounds is not None:
                plotitem.imshow_cmin = bounds[0]
                plotitem.imshow_cmax = bounds[1]
            plotitem.add_colorbar = True
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1]
            
    def add_land(plotaxes,plot_type='pcolor'):
        if plot_type == 'pcolor':
            plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
            plotitem.show = True
            plotitem.plot_var = geoplot.land
            plotitem.pcolor_cmap = geoplot.land_colors
            plotitem.pcolor_cmin = 0.0
            plotitem.pcolor_cmax = 80.0
            plotitem.add_colorbar = False
            plotitem.amr_gridlines_show = [0,0,0]
            plotitem.amr_gridedges_show = [1,1,1]
        elif plot_type == 'contour':            
            plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
            plotitem.plot_var = geoplot.land
            plotitem.contour_nlevels = 40
            plotitem.contour_min = 0.0
            plotitem.contour_max = 100.0
            plotitem.amr_contour_colors = ['g']  # color on each level
            plotitem.amr_grid_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']
            plotitem.gridlines_show = 0
            plotitem.gridedges_show = 0

    # Limits
    xlimits = [amrdata.xlower,amrdata.xupper]
    ylimits = [amrdata.ylower,amrdata.yupper]
    multilayer_data.eta = eta
    # surface_limits = [-0.15,0.15]
    # speed_limits = [0.0,0.1]
    surface_limits = None
    speed_limits = None
    
    vorticity_limits = [-1.e-2,1.e-2]
    
    # ========================================================================
    #  Surface Elevation
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface', figno=0)
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits
    plotaxes.afteraxes = pcolor_afteraxes
    
    add_surface_elevation(plotaxes,bounds=surface_limits)
    add_land(plotaxes)
    
    # ========================================================================
    #  Water Speed
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='speed', figno=100)
    plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Currents'
    plotaxes.scaled = True
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits
    plotaxes.afteraxes = pcolor_afteraxes

    # Speed
    add_speed(plotaxes,bounds=speed_limits)

    # Land
    add_land(plotaxes)
    
    # X-Velocity
    plotfigure = plotdata.new_plotfigure(name='velocity_x',figno=101)
    plotfigure.show = True
    plotfigure.kwargs = {'figsize':(14,4)}

    # X Velocity
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(121)'
    plotaxes.title = 'X-Velocity'
    plotaxes.scaled = True
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits
    plotaxes.afteraxes = pcolor_afteraxes

    add_x_velocity(plotaxes,bounds=speed_limits)
    add_land(plotaxes)
    
    # Y Velocity
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(122)'
    plotaxes.title = 'Y-Velocity'
    plotaxes.scaled = True
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits
    plotaxes.afteraxes = pcolor_afteraxes

    add_y_velocity(plotaxes,bounds=speed_limits)
    add_land(plotaxes)
    
    
    # ========================================================================
    #  Wind speed
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='wind',figno=2)
    plotfigure.show = True
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = "Wind"
    plotaxes.scaled = True
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits
    plotaxes.afteraxes = pcolor_afteraxes
    
    # Wind
    add_wind(plotaxes)
    add_land(plotaxes)

    # ========================================================================
    #  Profile Plots
    # ========================================================================
    # Profile variables
            
    def profile_afteraxes(current_data):
        day_figure_title(current_data)
        loc,label = plt.xticks()
        label = loc/1.e3
        plt.xticks(loc,label)
        plt.xlabel('km')
        if current_data.plotaxes.title == 'Wind':
            plt.ylabel('m/s')
        else:
            plt.ylabel('m')
            
        t = current_data.t
        # Hurricane eye
        x = t * hurricane_data.hurricane_velocity[0] + hurricane_data.R_eye_init[0]
        plt.hold(True)
        plt.plot(x,0.0,'r+')
        plt.hold(False)
            
    def remove_labels_profile(cd,direction='x'):
        plt.hold(True)
        if direction == 'x':
            plt.xlabel('')
            locs,labels = plt.xticks()
            # labels = np.flipud(locs)/1.e3
            labels = ['' for i in xrange(len(locs))]
            plt.xticks(locs,labels)
            plt.ylabel('m')
        elif direction == 'y':
            plt.ylabel('')
            locs,labels = plt.yticks()
            # labels = np.flipud(locs)/1.e3
            labels = ['' for i in xrange(len(locs))]
            plt.yticks(locs,labels)
            plt.xlabel('m')
        plt.hold(False)
        
    def labels_profile(cd,direction='x'):
        if direction == 'x':
            loc,label = plt.xticks()
            label = loc/1.e3
            plt.xticks(loc,label)
            plt.xlabel('km')
            if cd.plotaxes.title == 'Wind':
                plt.ylabel('m/s')
            else:
                plt.ylabel('m')
        elif direction == 'y':
            loc,label = plt.yticks()
            label = loc/1.e3
            plt.yticks(loc,label)
            plt.ylabel('km')
            if cd.plotaxes.title == 'Wind':
                plt.xlabel('m/s')
            else:
                plt.xlabel('m')
        
    def profile_afteraxes(current_data):
        day_figure_title(current_data)
        labels_profile(current_data)
        # bathy_ref_lines_profile(current_data,surface_limits)
    
    
    plotfigure = plotdata.new_plotfigure(name='profile', figno=4)
    plotfigure.show = False
        
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Profiles'
    plotaxes.xlimits = xlimits
    # plotaxes.ylimits = surface_limits
    plotaxes.afteraxes = profile_afteraxes
    
    profile_plot = PlotProfile(0.0)
    plotitem = plotaxes.new_plotitem(plot_type="1d_from_2d_data")
    plotitem.map_2d_to_1d = profile_plot.surface_profile
    plotitem.amr_plotstyle = ['-','-.','+','x','.']
    plotitem.color = 'b'#(0.2,0.8,1.0)
    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.map_2d_to_1d = profile_plot.bathy_profile
    plotitem.amr_plotstyle = ['-','-.','+','x','.']  
    plotitem.color = 'k'
        
    # ========================================================================
    #  Bathy Profile
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='bathy_profile',figno=20)
    plotfigure.show = False
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [amrdata.xlower,amrdata.xupper]
    plotaxes.title = "Bathymetry Profile"
    plotaxes.scaled = 'equal'
    
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = b
    plotitem.imshow_cmap = plt.get_cmap('earth')
    plotitem.imshow_cmin = -3300
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = True
    plotitem.amr_imshow_show = [1,1,1]
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1,1,1]
    plotitem.show = True
    
    # ========================================================================
    # Figure for grids alone
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='grids', figno=11)
    plotfigure.show = False
    
    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [amrdata.xlower,amrdata.xupper]
    plotaxes.xlimits = [amrdata.ylower,amrdata.yupper]
    plotaxes.title = 'grids'
    plotaxes.afteraxes = pcolor_afteraxes
    plotaxes.scaled = True
    
    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_grid')
    # plotitem.amr_grid_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']
    plotitem.amr_grid_bgcolor = ['blue','red','green','cyan','yellow']
    plotitem.amr_gridlines_show = [1,1,0,0,0,0]   
    plotitem.amr_gridedges_show = 1
    
    # ========================================================================
    # Figures for momentum
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='x-momentum', figno=13)
    plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'X-Velocity'
    plotaxes.scaled = True
    plotaxes.xlimits = [amrdata.xlower,amrdata.xupper]
    plotaxes.ylimits = [amrdata.ylower,amrdata.yupper]
    plotaxes.afteraxes = pcolor_afteraxes
    
    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    # plotitem.plot_var = geoplot.surface
    plotitem.plot_var = water_u
    plotitem.pcolor_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    # plotitem.pcolor_cmin = -1.e-10
    # plotitem.pcolor_cmax = 1.e-10
    # plotitem.pcolor_cmin = -2.5 # -3.0
    # plotitem.pcolor_cmax = 2.5 # 3.0
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1,1,1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True
    plotitem.plot_var = geoplot.land
    plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 80.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1,1,1]
    
    plotfigure = plotdata.new_plotfigure(name='y-momentum', figno=14)
    plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Y-Velocity'
    plotaxes.scaled = True
    plotaxes.xlimits = [amrdata.xlower,amrdata.xupper]
    plotaxes.ylimits = [amrdata.ylower,amrdata.yupper]
    plotaxes.afteraxes = pcolor_afteraxes
    
    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    # plotitem.plot_var = geoplot.surface
    plotitem.plot_var = water_v
    plotitem.pcolor_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    # plotitem.pcolor_cmin = -1.e-10
    # plotitem.pcolor_cmax = 1.e-10
    # plotitem.pcolor_cmin = -2.5 # -3.0
    # plotitem.pcolor_cmax = 2.5 # 3.0
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1,1,1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True
    plotitem.plot_var = geoplot.land
    plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 80.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1,1,1]
    
    # ========================================================================
    #  Contour plot for surface
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='contour_surface',figno=15)
    plotfigure.show = False
    
    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = [amrdata.xlower,amrdata.xupper]
    plotaxes.ylimits = [amrdata.ylower,amrdata.yupper]
    plotaxes.afteraxes = contour_afteraxes
    
    # Surface
    add_surface_elevation(plotaxes,plot_type='contour')
    
    # Land
    add_land(plotaxes,plot_type='contour')
    
    # ========================================================================
    #  Contour plot for speed
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='contour_speed',figno=16)
    plotfigure.show = False
    
    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Current'
    plotaxes.scaled = True
    plotaxes.xlimits = [amrdata.xlower,amrdata.xupper]
    plotaxes.ylimits = [amrdata.ylower,amrdata.yupper]
    plotaxes.afteraxes = contour_afteraxes
    
    # Surface
    add_surface_elevation(plotaxes,plot_type="contour")
    
    # Land
    add_land(plotaxes,plot_type='contour')
    
    # ========================================================================
    #  Vorticity Plot
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='vorticity',figno=17)
    plotfigure.show = False
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = "Vorticity"
    plotaxes.scaled = True
    plotaxes.xlimits = [amrdata.xlower,amrdata.xupper]
    plotaxes.ylimits = [amrdata.ylower,amrdata.yupper]
    plotaxes.afteraxes = pcolor_afteraxes
    
    # Vorticity
    add_vorticity(plotaxes)

    # Land
    add_land(plotaxes)
    
    
    # ========================================================================
    #  Figures for gauges
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface & topo', figno=300, \
                    type='each_gauge')
    plotfigure.show = False
    plotfigure.clf_each_gauge = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [0.0,40.0*3600.0]
    # plotaxes.ylimits = [0,150.0]
    plotaxes.ylimits = [-3.0, 3.0]
    plotaxes.title = 'Surface'
    plotaxes.afteraxes = gauge_afteraxes

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

    # # Plot topo as green curve:
    # plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    # plotitem.plot_var = gaugetopo
    # plotitem.plotstyle = 'g+'

    #-----------------------------------------
    
    # 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_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?

    return plotdata
Beispiel #26
0
def plotfg(fgno, frameno, outdir='_output', save_png=False):
    fname = "fort.fg%s_%s" % (str(fgno).zfill(2), str(frameno).zfill(4))
    fname = os.path.join(outdir, fname)
    if not os.path.exists(fname):
        print "*** Did not find file ", fname, " in directory ", outdir
        raise IOError("Missing fixed grid output file")

    print "Plotting fixed grid output from ", fname

    # Read parameters from header:

    file = open(fname, 'r')

    line = file.readline()
    t = float(line.split()[0])
    print 't = %s' % t

    line = file.readline()
    mx = int(line.split()[0])

    line = file.readline()
    my = int(line.split()[0])

    line = file.readline()
    xlow = float(line.split()[0])

    line = file.readline()
    ylow = float(line.split()[0])

    line = file.readline()
    xhi = float(line.split()[0])

    line = file.readline()
    yhi = float(line.split()[0])

    if 0:
        print 'mx = %s' % mx
        print 'my = %s' % my
        print 'xlow = %s' % xlow
        print 'ylow = %s' % ylow
        print 'xhi = %s' % xhi
        print 'yhi = %s' % yhi
    file.close()

    x = linspace(xlow, xhi, mx + 1)
    y = linspace(ylow, yhi, my + 1)
    dx = x[1] - x[0]
    dy = y[1] - y[0]
    xcenter = x[:-1] + dx / 2.
    ycenter = y[:-1] + dy / 2.

    d = loadtxt(fname, skiprows=8)

    h = reshape(d[:, 0], (my, mx))
    B = reshape(d[:, 3], (my, mx))
    eta = reshape(d[:, 4], (my, mx))
    surface = ma.masked_where(isnan(eta), eta)
    land = ma.masked_where(h > drytol, B)

    # plot commands:
    # ==============

    # ===================================================
    # Adjust these:

    # Define function to plot topo contours for use in multiple places:
    def add_contours():
        clines = linspace(-20, 20, 21)
        contour(xcenter, ycenter, B, clines, colors='k')
        contour(xcenter, ycenter, B, [0.], colors='k', linewidths=2)

    # Set colormaps:
    water_cmap = geoplot.tsunami_colormap
    land_cmap = geoplot.land_colors
    seafloor_cmap = geoplot.seafloor_colormap
    inundated_cmap = colormaps.make_colormap({0.: [1, .9, .9], 1.: [1, 0, 0]})

    # ===================================================

    figno = 150
    figure(figno)
    clf()

    if ma.count(surface) != 0:
        pcolormesh(x, y, surface, cmap=water_cmap)
        clim((-5, 5))
        colorbar()

    if ma.count(land) != 0:
        pcolormesh(x, y, land, cmap=land_cmap)
        #clim((-0.02,0.02))

    add_contours()

    ncols = d.shape[1]
    axis('scaled')
    title('Surface on fixed grid %s at time = %8.5f' % (fgno, t))
    xlim((xlow, xhi))
    ylim((ylow, yhi))

    if save_png:
        fname = 'FixedGrid%sFrame%sFig%s.png' \
            %  (str(fgno).zfill(2), str(frameno).zfill(4), figno)
        savefig(fname)
        print "Saved figure as ", fname

    return_fg = True  # return all the fg arrays for other purposes?
    if return_fg:
        fg = empty((my, mx, ncols), dtype=float)
        for col in range(ncols):
            fg[:, :, col] = reshape(d[:, col], (my, mx))

    if ncols > 5:
        etamin = reshape(d[:, 5], (my, mx))
        etamax = reshape(d[:, 6], (my, mx))

        #etamax2 = where(B<0, 1., etamax)
        etamax2 = where(B < 0, 1., etamax)

        # Add red contour of maximum eta
        #contour(xcenter,ycenter,etamax2,[drytol],colors='r',linewidths=2)

        # Add brown contour of minimum eta
        #contour(xcenter,ycenter,etamin-B,[exposed_tol],colors=([.9,.8,.2],),linewidths=2)

        # Determine exposed and inundatated regions:

        exposed = ma.masked_where(((B > 0) | (etamin > B + exposed_tol)),
                                  etamin)
        inundated = ma.masked_where(((B < 0) | (etamax < B + drytol)), etamax)

        figno = 151
        figure(figno)
        clf()

        if ma.count(inundated) != 0:
            pcolormesh(x, y, inundated, cmap=inundated_cmap)
            clim((0, 5))
            colorbar()
        add_contours()
        # Add red contour of maximum eta
        #contour(xcenter,ycenter,etamax2,[drytol],colors='r',linewidths=2)
        title("Inundated region for t <= %8.5f" % t)
        axis('scaled')
        xlim((xlow, xhi))
        ylim((ylow, yhi))
        if save_png:
            fname = 'FixedGrid%sFrame%sFig%s.png' \
                %  (str(fgno).zfill(2), str(frameno).zfill(4), figno)
            savefig(fname)
            print "Saved figure as ", fname

        figno = 152
        figure(figno)
        clf()

        if ma.count(exposed) != 0:
            pcolormesh(x, y, exposed, cmap=seafloor_cmap)
            #clim((-0.02,0.02))
            colorbar()
        add_contours()
        # Add brown contour of minimum eta
        #contour(xcenter,ycenter,etamin-B,[exposed_tol],colors=([.9,.8,.2],),linewidths=2)
        title("Exposed seabed for t <= %8.5f" % t)
        axis('scaled')
        xlim((xlow, xhi))
        ylim((ylow, yhi))
        if save_png:
            fname = 'FixedGrid%sFrame%sFig%s.png' \
                %  (str(fgno).zfill(2), str(frameno).zfill(4), figno)
            savefig(fname)
            print "Saved figure as ", fname

        return fg
Beispiel #27
0
def setplot(plotdata):
#--------------------------
    
    """ 
    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 pyclaw.plotters import colormaps, geoplot
    from numpy import linspace

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


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

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

    # ========================================================================
    #  Water Velocity Helper Functions
    # ========================================================================        
    def water_velocity(current_data,DRY_TOL=1e-6):
        r"""Calculate velocity from the momentum and depth
        
        Calculates the x and y velocities from the momenta.  A mask is 
        constructed so that division by a small depth is avoided, controlled
        by the optional keyword argument DRY_TOL (default = 1e-6).  A check
        for NaNs is also made.  Any point not satisfying either of these
        criteria is set to 0.0.
        
        returns numpy.ndarray, nump.ndarray
        """
        h = current_data.q[:,:,0]
        hu = current_data.q[:,:,1]
        hv = current_data.q[:,:,2]
        u = np.zeros(hu.shape)
        v = np.zeros(hv.shape)
        
        index = np.nonzero((np.abs(h) > DRY_TOL) * (h != np.nan))
        u[index[0],index[1]] = hu[index[0],index[1]] / h[index[0],index[1]]
        v[index[0],index[1]] = hv[index[0],index[1]] / h[index[0],index[1]]
        
        return u,v
        
    def vorticity(current_data):
        r"""Calculate vorticity of velocity field
        
        Using matrix operations, calculate u_y + v_x, note that second order,
        centered differences are used for interior points and forward and
        backward differences for the boundary values.
        
        returns numpy.ndarray of shape of u and v
        """
        u,v = water_velocity(current_data)
        dx = current_data.dx
        dy = current_data.dy
        
        u_y = np.zeros(u.shape)
        u_y[:,0] = (-3.0*u[:,0] + 4.0 * u[:,1] - u[:,2]) / (2.0 * dy)
        u_y[:,-1] = (u[:,-3] - 4.0 * u[:,-2] + 3.0 * u[:,-1]) / (2.0 * dy)
        u_y[:,1:-1] = (u[:,2:] - u[:,0:-2]) / (2.0 * dy)

        v_x = np.zeros(v.shape)
        v_x[0,:] = (-3.0*v[0,:] + 4.0 * v[1,:] - v[2,:]) / (2.0 * dx)
        v_x[-1,:] = (u[-3,:] - 4.0 * u[-2,:] + 3.0 * u[-1,:]) / (2.0 * dx)
        v_x[1:-1,:] = (v[2:,:] - v[0:-2,:]) / (2.0 * dx)
        
        return v_x - u_y
        
        
    def water_speed(current_data):
        u,v = water_velocity(current_data)
        return np.sqrt(u**2+v**2)
        
    def water_quiver(current_data):
        u = water_u(current_data)
        v = water_v(current_data)
            
        plt.hold(True)
        Q = plt.quiver(current_data.x[::2,::2],current_data.y[::2,::2],
                        u[::2,::2],v[::2,::2])
        max_speed = np.max(np.sqrt(u**2+v**2))
        label = r"%s m/s" % str(np.ceil(0.5*max_speed))
        plt.quiverkey(Q,0.15,0.95,0.5*max_speed,label,labelpos='W')
        plt.hold(False)    

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

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

    def fixup(current_data):
        import pylab
        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)
        pylab.plot([139.7],[35.6],'wo',markersize=10)
        pylab.text(138.2,35.9,'Tokyo',color='w',fontsize=25)
        x_airport = 140.9317
        y_airport = 38.1389
        pylab.plot([x_airport],[y_airport],'wo',markersize=4)
        pylab.text(x_airport-.15,y_airport+.04,'Airport',color='w',fontsize=15)

    plotaxes.afteraxes = fixup

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.imshow_cmap = geoplot.tsunami_colormap
    plotitem.imshow_cmin = -1.0
    plotitem.imshow_cmax = 1.0
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.gridedges_show = 1

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.gridedges_show = 1
    plotaxes.xlimits = [138,148]
    plotaxes.ylimits = [34,42]

    # 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.gridlines_show = 0
    plotitem.gridedges_show = 0


    #-----------------------------------------
    # Figure for zoom plot
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Sendai Bay', figno=1)

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

    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)
        x_airport = 140.9317
        y_airport = 38.1389
        pylab.plot([x_airport],[y_airport],'wo',markersize=10)
        pylab.text(x_airport-.05,y_airport+.04,'Airport',color='w',fontsize=25)
        #addgauges(current_data)
    plotaxes.afteraxes = fixup

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.imshow_cmap = geoplot.tsunami_colormap
    plotitem.imshow_cmin = -1.0
    plotitem.imshow_cmax = 1.0
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.gridedges_show = 1

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.gridedges_show = 1
    plotaxes.xlimits = [140.8,141.8]
    plotaxes.ylimits = [37.3,38.6]

    # 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.gridlines_show = 0
    plotitem.gridedges_show = 0


    #-----------------------------------------
    # Figure for zoom plot
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Airport', figno=2)

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

    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)
        x_airport = 140.9317
        y_airport = 38.1389
        pylab.plot([x_airport],[y_airport],'wo',markersize=10)
        pylab.text(x_airport,y_airport+.01,'Airport',color='w',fontsize=25)
        addgauges(current_data)
    plotaxes.afteraxes = fixup

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.imshow_cmap = geoplot.tsunami_colormap
    plotitem.imshow_cmin = -1.0
    plotitem.imshow_cmax = 1.0
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.gridedges_show = 1

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.gridedges_show = 1
    plotaxes.xlimits = [140.85,141.0]
    plotaxes.ylimits = [38.08,38.20]

    # 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.gridlines_show = 0
    plotitem.gridedges_show = 0


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

    # 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
        t = current_data.t
        #legend(('surface','topography'),loc='lower left')
        plot(t, 0*t, 'k')
        n = floor(t.max()/3600.) + 2
        xticks([3600*i for i in range(n)])

    plotaxes.afteraxes = add_zeroline

    # ========================================================================
    #  Water Current Plots
    # ========================================================================
    max_speed = 5.0
    
    #  Full figure
    plotfigure = plotdata.new_plotfigure(name='full_currents', figno=400)
    plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Currents Full Domain'
    plotaxes.scaled = True
    plotaxes.xlimits = [138,148]
    plotaxes.ylimits = [34,42]

    # Speed
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = water_speed
    plotitem.imshow_cmap = plt.get_cmap('PuBu')
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = max_speed
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]
    # plotitem.aftergrid = water_quiver

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.add_colorbar = False
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    
    # ========================================================================
    #  Zoomed Figure - Sendai Bay
    plotfigure = plotdata.new_plotfigure(name='sendai_bay_currents', figno=401)
    plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Currents Sendai Bay'
    plotaxes.scaled = True
    plotaxes.xlimits = [140.8,141.8]
    plotaxes.ylimits = [37.3,38.6]

    # Speed
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = water_speed
    plotitem.imshow_cmap = plt.get_cmap('PuBu')
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = max_speed
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.add_colorbar = False
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    
    # ========================================================================
    #  Zoomed Figure - Airport
    plotfigure = plotdata.new_plotfigure(name='airport_currents', figno=402)
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Currents Airport'
    plotaxes.scaled = True
    plotaxes.xlimits = [140.85,141.0]
    plotaxes.ylimits = [38.08,38.20]

    # Speed
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = water_speed
    plotitem.imshow_cmap = plt.get_cmap('PuBu')
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = max_speed
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.add_colorbar = False
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    
    # ========================================================================
    #  Vorticity Plots
    # ========================================================================
    vorticity_limits = [-2,2]
    #  Full domain
    plotfigure = plotdata.new_plotfigure(name='full_vorticity', figno=500)
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Vorticity'
    plotaxes.scaled = True
    plotaxes.xlimits = [138,148]
    plotaxes.ylimits = [34,42]

    # Speed
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = vorticity
    plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.imshow_cmin = vorticity_limits[0]
    plotitem.imshow_cmax = vorticity_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.add_colorbar = False
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0


    #-----------------------------------------
    
    # 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 = [400,401,402]            # 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?

    return plotdata
Beispiel #28
0
def setplot(plotdata):
    #--------------------------
    """ 
    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 pyclaw.plotters import colormaps, geoplot
    from numpy import linspace

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

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

    def addgauges(current_data):
        from pyclaw.plotters import gaugetools
        gaugetools.plot_gauge_locations(current_data.plotdata, \
             gaugenos='all', format_string='ko', add_labels=True, fontsize=8)

    #-----------------------------------------
    # Figure for pcolor plot
    #-----------------------------------------

    plotfigure = plotdata.new_plotfigure(name='full domain', figno=0)
    plotfigure.show = True  # Turn the pcolor plot on or off (True or False)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.show = True  ### Turn on or off the full domain plot
    plotaxes.title = 'Surface'
    plotaxes.scaled = True

    def fixup(current_data):
        import pylab
        t = current_data.t
        # pylab.title('Surface at %4.2f seconds' % t, fontsize=20)
        t = t / 60.  # minutes
        pylab.title('Surface at %4.2f minutes' % t, fontsize=20)
        pylab.xticks(fontsize=15)
        pylab.yticks(fontsize=15)
        #pylab.plot([205],[20],'wo',markersize=5)
        #pylab.text(201,22,'Hawaii',color='w',fontsize=15)
        # pylab.plot([139.7],[35.6],'wo',markersize=5)
        # pylab.text(135.2,35.9,'Tokyo',color='w',fontsize=15)
        # pylab.plot([235.81],[41.75],'wo',markersize=5)
        # pylab.text(235.9,42,'Crescent City',color='w',fontsize=15)
        addgauges(current_data)

    plotaxes.afteraxes = fixup

    # plotaxes.s = [137.57,141.41] # Full Domain
    # plotaxes.ylimits = [39.67,44.15] # Full Domain
    # plotaxes.xlimits = [139., 140.] ## Okushiri Island (Large area)
    # plotaxes.ylimits = [41.5, 42.5]   ## Okushiri Island  (Large area)
    # plotaxes.xlimits = [139.43, 139.48] ## Aonae peninsula
    # plotaxes.ylimits = [42.03, 42.06]   ## Aonae peninsula
    # plotaxes.xlimits = [139.35, 139.6] ## Okushiri Island (Tight)
    # plotaxes.ylimits = [42.0, 42.25]   ## Okushiri Island (Tight)
    # plotaxes.xlimits = [139.41, 139.43] ## Monai Long Coast
    # plotaxes.ylimits = [42.08, 42.15]   ## Monai Long Coast
    # plotaxes.xlimits = [139.418, 139.426] ## Monai Short
    # plotaxes.ylimits = [42.096, 42.106]   ## Monai Short

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    # plotitem.pcolor_cmap = geoplot.tsunami_colormap
    # plotitem.pcolor_cmap = colormaps.blue_white_red
    # dictionary of [R,G,B] values at different levels:
    my_cmap_surface = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                      -0.02: [0.75,0.75,1.0], \
                                       0.0: [1.0,1.0,1.0], \
                                       0.02: [1.0,0.75,0.75], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.pcolor_cmap = my_cmap_surface
    plotitem.pcolor_cmin = -50.
    plotitem.pcolor_cmax = 50.
    plotitem.add_colorbar = True
    plotitem.amr_gridedges_show = [1]
    # plotitem.amr_gridlines_show = [0,0,0,0,0] # Turn off/0n = 0/1 gridlines for levels [1,2,3, ...]
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,1,0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True
    plotitem.plot_var = geoplot.land
    my_cmap_land = colormaps.make_colormap({ \
                                            0.0: [0.0,1.0,0.0], \
                                            1.0: [0.0,0.5,0.0] \
                                            })
    plotitem.pcolor_cmap = my_cmap_land
    # plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = True
    # plotitem.amr_gridlines_show = [0,0,0]
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,1,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(-20,20,11)
    plotitem.contour_levels = [0.]
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid', 'linewidths': 1}
    plotitem.amr_contour_show = [0, 0, 0, 1]

    # plotitem.gridlines_show = 0
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,0]

    # Topo = Bathymetry and Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = False
    plotitem.plot_var = geoplot.topo
    # plotitem.pcolor_cmap = geoplot.bathy3_colormap  #Try 1, 2 & 3

    my_cmap_topo = colormaps.make_colormap({ \
        -5000.0: [0,0,1], 0.0: [1,1,1], 100.0: [0.0,0.5,0.0] \
                                            })
    plotitem.pcolor_cmap = my_cmap_topo

    plotitem.pcolor_cmin = -5000.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = False
    # plotitem.amr_gridlines_show = [0,0,0]
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,1,0]

    # add contour lines of topo if desired:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = False
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = linspace(-5000, -100, 6)
    plotitem.amr_contour_colors = ['y']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid', 'linewidths': 1}
    # plotitem.amr_contour_show = [0,0,0]
    # plotitem.gridlines_show = 0
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,0]

    #-----------------------------------------
    # Figure for velocity plot
    #-----------------------------------------

    plotfigure = plotdata.new_plotfigure(name='speed', figno=20)
    plotfigure.show = False  # Turn the pcolor plot on or off (True or False)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.show = True  ### Turn on or off the full domain plot
    plotaxes.title = 'Water speed'
    plotaxes.scaled = True

    plotaxes.afteraxes = fixup

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True

    def speed(current_data):
        from numpy import where, sqrt
        q = current_data.q
        x = current_data.x
        y = current_data.y
        level = current_data.level

        h = q[:, :, 0]
        hu = q[:, :, 1]
        hv = q[:, :, 2]
        u = where(h > 0, hu / h, 0.)
        v = where(h > 0, hv / h, 0.)
        s = sqrt(u**2 + v**2)
        print "level = %s, max speed = %s" % (level, s.max())
        i = s.argmax()
        print "   at x = %s, y = %s" % (x.flat[i], y.flat[i])
        return s

    plotitem.plot_var = speed

    my_cmap_surface = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                      -0.02: [0.75,0.75,1.0], \
                                       0.0: [1.0,1.0,1.0], \
                                       0.02: [1.0,0.75,0.75], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.pcolor_cmap = my_cmap_surface
    plotitem.pcolor_cmin = -50.
    plotitem.pcolor_cmax = 50.
    plotitem.add_colorbar = True
    plotitem.amr_gridedges_show = [1]
    # plotitem.amr_gridlines_show = [0,0,0,0,0] # Turn off/0n = 0/1 gridlines for levels [1,2,3, ...]
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,1,0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True
    plotitem.plot_var = geoplot.land
    my_cmap_land = colormaps.make_colormap({ \
                                            0.0: [0.0,1.0,0.0], \
                                            1.0: [0.0,0.5,0.0] \
                                            })
    plotitem.pcolor_cmap = my_cmap_land
    # plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = True
    # plotitem.amr_gridlines_show = [0,0,0]
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,1,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(-20,20,11)
    plotitem.contour_levels = [0.]
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid', 'linewidths': 1}
    plotitem.amr_contour_show = [0, 0, 0, 1]

    #-----------------------------------------
    # Figure for zoom plot
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Zoom', figno=1)
    plotfigure.show = False  # Turn the zoom plot on or off (True or False)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    ##
    # plotaxes.xlimits = [140.3, 140.5] ## Esashi Tide Gage
    # plotaxes.ylimits = [41.75, 41.95] ## Esashi Tide Gage
    # plotaxes.xlimits = [139.35, 139.6] ## Okushiri Island
    # plotaxes.ylimits = [42.0, 42.25]   ## Okushiri Island
    # plotaxes.xlimits = [139.43, 139.48] ## Aonae peninsula
    # plotaxes.ylimits = [42.03, 42.06]   ## Aonae peninsula
    # plotaxes.xlimits = [139.41, 139.43] ## Monai
    # plotaxes.ylimits = [42.08, 42.15]   ## Monai
    # plotaxes.xlimits = [139.41385190, 139.42639510] ## MB05 Monai grid
    # plotaxes.ylimits = [42.09458550, 42.10343920]   ## MB05 Monai grid
    plotaxes.xlimits = [139., 140.]  ## Okushiri Island
    plotaxes.ylimits = [41.5, 42.5]  ## Okushiri Island

    # dx = 0.00005
    # dy = 0.00005
    # plotaxes.xlimits = [139.423714744650-dx, 139.423714744650+dx] ## Station 8, Monai valley
    # plotaxes.ylimits = [ 42.100414145210-dy,  42.100414145210+dy] ## Station 8, Monai valley

    def fixup(current_data):
        import pylab
        addgauges(current_data)
        t = current_data.t
        pylab.title('Surface at %4.2f seconds' % t, fontsize=20)
        # t = t / 60.  # minutes
        # pylab.title('Surface at %4.2f minutes' % t, fontsize=20)
#       pylab.plot([139.7],[35.6],'wo',markersize=10)
#       pylab.text(138.2,35.9,'Tokyo',color='w',fontsize=25)

    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_cmap = colormaps.blue_white_red
    plotitem.pcolor_cmin = -5.
    plotitem.pcolor_cmax = 5.
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]  ##Levels of refinement
    plotitem.gridedges_show = 1

    # add contour lines of bathy if desired:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = True
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = linspace(-1000, 100, 11)
    plotitem.amr_contour_colors = ['y']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid', 'linewidths': 2}
    plotitem.amr_contour_show = [1, 0, 0]
    plotitem.gridlines_show = 1
    plotitem.gridedges_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 = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.gridedges_show = 1

    # add contour lines of land if desired:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = True
    plotitem.plot_var = geoplot.land
    plotitem.contour_levels = linspace(0, 100, 10)
    plotitem.amr_contour_colors = ['y']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid', 'linewidths': 2}
    plotitem.amr_contour_show = [0, 0, 0]
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

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

    plotfigure = plotdata.new_plotfigure(name='Surface & topo', figno=2, \
                    type='each_gauge')
    plotfigure.clf_each_gauge = False  # Switch gauge figures on or off

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

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

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

    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, xlim
        t = current_data.t
        dtaxis = 60.  # Set the axis time increment, in seconds
        #t = t/dtaxis
        tmax = t.max()
        #print "tmax = ",tmax
        legend(('surface', 'topography'), loc='lower left')
        plot([0, tmax], [0, 0], 'k')
        n = int(floor(tmax) + 2)
        xticks([dtaxis * i for i in range(n)])
        xlim(0., tmax)

    plotaxes.afteraxes = add_zeroline

    def plot_TG(current_data):
        import pylab
        gaugeno = current_data.gaugeno
        if gaugeno == 5000:
            try:
                pylab.plot(Esashidata[:, 0], Esashidata[:, 1], 'k')
                pylab.legend(['GeoClaw', 'Esashi data'])
            except:
                pylab.legend(['GeoClaw'])
        if gaugeno == 6000:
            try:
                pylab.plot(Iwanaidata[:, 0], Iwanaidata[:, 1], 'k')
                pylab.legend(['GeoClaw', 'Iwanai data'])
            except:
                pylab.legend(['GeoClaw'])
        add_zeroline(current_data)

    plotaxes.afteraxes = plot_TG

    # Fixed grid plots:
    # -----------------

    if setplotfg is not None:

        # Repeat as desired for other fixed grids...
        otherfig = plotdata.new_otherfigure('Fixed Grid 1')
        fgno = 1
        sfgno = str(fgno).zfill(2)  # e.g. '01'
        otherfig.fname = '_PlotIndex_FixedGrid%s.html' % sfgno

        def make_fgplots(plotdata):
            fgdata = setplotfg(fgno, outdir=plotdata.outdir)
            fgdata.fg2html('all')

        otherfig.makefig = make_fgplots

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

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

# Figure Printing
    plotdata.printfigs = True  # All figures printed
    # plotdata.printfigs = False             # No figures printed
    plotdata.print_format = 'png'  # file format
    # Frame Printing
    plotdata.print_framenos = 'all'  # All frame figures printed
    # plotdata.print_framenos = []               # No frame figures printed
    # plotdata.print_framenos = range(0,21)    # List of frame figures to print (n1:n2-1)
    # Gauge Printing
    # plotdata.print_gaugenos = 'all'        # All gauge figures printed
    plotdata.print_gaugenos = []  # No gauge figures printed
    # plotdata.print_gaugenos = range(201,210) # List of gauge figures to print range(n1,n2-1)

    # Print Figures (Both Frames and Gauges)
    plotdata.print_fignos = 'all'  # list of figures to print

    # Create html or latex files
    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?

    # Specify Layout of Plots
    plotdata.latex_figsperline = 2  # layout of plots
    plotdata.latex_framesperline = 1  # layout of plots
    plotdata.latex_makepdf = False  # also run pdflatex?

    return plotdata
Beispiel #29
0
def setplot(plotdata):
    # --------------------------
    """ 
    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 pyclaw.plotters import colormaps, geoplot

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

    #   plotdata.format = "netcdf"

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

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

    def title_hours(current_data):
        from pylab import title
        t = current_data.t
        h = t / 3600.
        title('%5.2f Hours after Quake' % h)

    def plotcc(current_data):
        from pylab import plot, text
        plot([235.8162], [41.745616], 'wo')
        text(235.8, 41.9, 'Cr.City', color='w', fontsize=10)

    #-----------------------------------------
    # Figure for big area
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Pacific', figno=0)
    plotfigure.kwargs = {'figsize': (16, 4)}
    plotfigure.show = True

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

    def aa(current_data):
        title_hours(current_data)
        if 0:
            from pylab import savefig
            fname = 'pacific%s.png' % str(current_data.frameno).zfill(4)
            savefig(fname)
            print 'Saved ', fname

    plotaxes.afteraxes = aa

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                     -0.1: [0.5,0.5,1.0], \
                                      0.0: [1.0,1.0,1.0], \
                                      0.1: [1.0,0.5,0.5], \
                                      1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = -0.3
    plotitem.imshow_cmax = 0.3
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]
    plotaxes.xlimits = [132, 238]
    plotaxes.ylimits = [30, 50]
    #plotaxes.afteraxes = addgauges

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

    # Add contour lines of topography:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = False
    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, 0,
                                 1]  # show contours only on finest level
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

    #-----------------------------------------
    # Figure for zoom
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='California', figno=10)
    #plotfigure.show = False

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                      -0.1: [0.5,0.5,1.0], \
                                       0.0: [1.0,1.0,1.0], \
                                       0.1: [1.0,0.5,0.5], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = -0.3
    plotitem.imshow_cmax = 0.3
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]
    plotaxes.xlimits = [227, 237]
    plotaxes.ylimits = [35, 45]

    def af(current_data):
        from pylab import savefig, figure
        figure(10)
        plotcc(current_data)
        title_hours(current_data)
        addgauges(current_data)
        if 0:
            fname = '/Users/rjl/OUTPUT/Users/rjl/Dropbox/mygeo/CC/_plots/' +\
               'california%s.png' % str(current_data.frameno).zfill(4)
            savefig(fname)
            print 'Saved ', fname

    #plotdata.afterframe = af
    plotaxes.afteraxes = af

    # Add contour lines of eta:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = geoplot.surface
    from numpy import arange, linspace
    plotitem.contour_levels = linspace(-0.3, 0.3, 13)
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid'}
    plotitem.amr_contour_show = [0, 0, 1, 0]  # AMR levels to show contours
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0
    plotitem.show = False

    # 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(-4500, 0, 10)
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid'}
    plotitem.amr_contour_show = [0, 0, 1, 0]  # AMR levels to show contours
    plotitem.gridlines_show = 0
    plotitem.gridedges_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, 0,
                                 1]  # show contours only on finest level
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0
    plotitem.show = False

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

    # 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_fignos = 'all'  # list of figures to print
    plotdata.print_gaugenos = 'all'  # list of gauges 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?

    return plotdata
Beispiel #30
0
def setplot(plotdata):
#--------------------------
    
    """ 
    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 pyclaw.plotters import colormaps, geoplot
    from pyclaw.plotters.plottools import fix_long_tick_labels
    from numpy import linspace

    plotdata.clearfigures()  # clear any old figures,axes,items data
    plotdata.rundir = plotdata.outdir  # where to find data files, e.g.
                                       # gauge locations

    def set_drytol(current_data):
        current_data.user.drytol = 1.e-2

    plotdata.beforeframe = set_drytol

    def saveframe(current_data):
        import pylab
        fname = 'ok_%smin.png' % current_data.frameno
        pylab.savefig(fname)
        print 'Saved ',fname
    #plotdata.afterframe = saveframe

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

    def addgauges(current_data):
        from pyclaw.plotters import gaugetools
        gaugetools.plot_gauge_locations(current_data.plotdata, \
             gaugenos='all', format_string='ko', add_labels=True, fontsize=8)

    #-----------------------------------------
    # Figure for pcolor plot
    #-----------------------------------------

    plotfigure = plotdata.new_plotfigure(name='full domain', figno=0)
    plotfigure.show = True  # Turn the pcolor plot on or off (True or False) 

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.show = True  ### Turn on or off the full domain plot
    plotaxes.title = 'Surface'
    plotaxes.scaled = True

    
    # xlimits = [137.57,141.41] # Full Domain
    # ylimits = [39.67,44.15] # Full Domain
    # xlimits = [139., 140.] ## Okushiri Island (Large area)
    # ylimits = [41.5, 42.5]   ## Okushiri Island  (Large area)
    # xlimits = [139.43, 139.48] ## Aonae peninsula
    # ylimits = [42.03, 42.06]   ## Aonae peninsula
    # xlimits = [139.41, 139.43] ## Monai Long Coast
    # ylimits = [42.08, 42.15]   ## Monai Long Coast
    # xlimits = [139.418, 139.426] ## Monai Short
    # ylimits = [42.096, 42.106]   ## Monai Short

    #xlimits = 'auto'          ## full domain
    #ylimits = 'auto'          ## full domain
    xlimits = [139.35, 139.6] ## Okushiri Island (Tight)
    ylimits = [42.0, 42.25]   ## Okushiri Island (Tight)

    # xlimits and ylimits need to be set for fixup to work!
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits

    def fixup(current_data):
        import pylab
        t = current_data.t
        # pylab.title('Surface at %4.2f seconds' % t, fontsize=20)       
        t = t / 60.  # minutes
        pylab.title('Surface at %4.2f minutes' % t, fontsize=20)
        fix_long_tick_labels(xlimits,ylimits)
        addgauges(current_data)

    plotaxes.afteraxes = fixup

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    # plotitem.pcolor_cmap = geoplot.tsunami_colormap
    # plotitem.pcolor_cmap = colormaps.blue_white_red
    # dictionary of [R,G,B] values at different levels:
    my_cmap_surface = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                      -0.02: [0.75,0.75,1.0], \
                                       0.0: [1.0,1.0,1.0], \
                                       0.02: [1.0,0.75,0.75], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.pcolor_cmap = my_cmap_surface
    plotitem.pcolor_cmin = -5.
    plotitem.pcolor_cmax =  5.
    plotitem.add_colorbar = False
    plotitem.amr_gridedges_show = [1]
    # plotitem.amr_gridlines_show = [0,0,0,0,0] # Turn off/0n = 0/1 gridlines for levels [1,2,3, ...]
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,1,0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True
    plotitem.plot_var = geoplot.land
    my_cmap_land = colormaps.make_colormap({ \
                                            0.0: [0.0,1.0,0.0], \
                                            1.0: [0.0,0.5,0.0] \
                                            })
    plotitem.pcolor_cmap = my_cmap_land                                   
    # plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = False
    # plotitem.amr_gridlines_show = [0,0,0]
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,1,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(-20,20,11)
    plotitem.contour_levels = [0.]
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles':'solid','linewidths':1}
    plotitem.amr_contour_show = [0,0,0,1]  
    
    
    # plotitem.gridlines_show = 0
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,0]
    
    

    # Topo = Bathymetry and Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = False
    plotitem.plot_var = geoplot.topo
    # plotitem.pcolor_cmap = geoplot.bathy3_colormap  #Try 1, 2 & 3
    
    my_cmap_topo = colormaps.make_colormap({ \
        -5000.0: [0,0,1], 0.0: [1,1,1], 100.0: [0.0,0.5,0.0] \
                                            })
    plotitem.pcolor_cmap = my_cmap_topo
    
    plotitem.pcolor_cmin = -5000.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = False
    # plotitem.amr_gridlines_show = [0,0,0]
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,1,0]

    # add contour lines of topo if desired:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = False
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = linspace(-5000,-100,6)
    plotitem.amr_contour_colors = ['y']  # color on each level
    plotitem.kwargs = {'linestyles':'solid','linewidths':1}
    # plotitem.amr_contour_show = [0,0,0]  
    # plotitem.gridlines_show = 0
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,0]

    #-----------------------------------------
    # Figure for velocity plot
    #-----------------------------------------

    plotfigure = plotdata.new_plotfigure(name='speed', figno=20)
    plotfigure.show = False  # Turn the pcolor plot on or off (True or False) 

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.show = True  ### Turn on or off the full domain plot
    plotaxes.title = 'Water speed'
    plotaxes.scaled = True

    plotaxes.afteraxes = fixup
    

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True

    def speed(current_data):
        from numpy import where,sqrt
        q = current_data.q
        x = current_data.x
        y = current_data.y
        level = current_data.level

        h = q[:,:,0]
        hu = q[:,:,1]
        hv = q[:,:,2]
        u = where(h>0, hu/h, 0.)
        v = where(h>0, hv/h, 0.)
        s = sqrt(u**2 + v**2)
        print "level = %s, max speed = %s" %(level,s.max())
        i = s.argmax()
        print "   at x = %s, y = %s" % (x.flat[i],y.flat[i])
        return s

    plotitem.plot_var = speed

    my_cmap_surface = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                      -0.02: [0.75,0.75,1.0], \
                                       0.0: [1.0,1.0,1.0], \
                                       0.02: [1.0,0.75,0.75], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.pcolor_cmap = my_cmap_surface
    plotitem.pcolor_cmin = -50.
    plotitem.pcolor_cmax =  50.
    plotitem.add_colorbar = True
    plotitem.amr_gridedges_show = [1]
    # plotitem.amr_gridlines_show = [0,0,0,0,0] # Turn off/0n = 0/1 gridlines for levels [1,2,3, ...]
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,1,0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True
    plotitem.plot_var = geoplot.land
    my_cmap_land = colormaps.make_colormap({ \
                                            0.0: [0.0,1.0,0.0], \
                                            1.0: [0.0,0.5,0.0] \
                                            })
    plotitem.pcolor_cmap = my_cmap_land                                   
    # plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = True
    # plotitem.amr_gridlines_show = [0,0,0]
    # plotitem.gridedges_show = 0
    #plotitem.amr_data_show = [1,1,1,1,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(-20,20,11)
    plotitem.contour_levels = [0.]
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles':'solid','linewidths':1}
    plotitem.amr_contour_show = [0,0,0,1]  
    

    #-----------------------------------------
    # Figure for zoom plot  
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Zoom', figno=1)
    plotfigure.show = False  # Turn the zoom plot on or off (True or False) 

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    ## 
    # plotaxes.xlimits = [140.3, 140.5] ## Esashi Tide Gage
    # plotaxes.ylimits = [41.75, 41.95] ## Esashi Tide Gage
    # plotaxes.xlimits = [139.35, 139.6] ## Okushiri Island
    # plotaxes.ylimits = [42.0, 42.25]   ## Okushiri Island
    # plotaxes.xlimits = [139.43, 139.48] ## Aonae peninsula
    # plotaxes.ylimits = [42.03, 42.06]   ## Aonae peninsula
    # plotaxes.xlimits = [139.41, 139.43] ## Monai
    # plotaxes.ylimits = [42.08, 42.15]   ## Monai
    # plotaxes.xlimits = [139.41385190, 139.42639510] ## MB05 Monai grid
    # plotaxes.ylimits = [42.09458550, 42.10343920]   ## MB05 Monai grid
    plotaxes.xlimits = [139., 140.] ## Okushiri Island
    plotaxes.ylimits = [41.5, 42.5]   ## Okushiri Island

    # dx = 0.00005
    # dy = 0.00005
    # plotaxes.xlimits = [139.423714744650-dx, 139.423714744650+dx] ## Station 8, Monai valley
    # plotaxes.ylimits = [ 42.100414145210-dy,  42.100414145210+dy] ## Station 8, Monai valley

    def fixup(current_data):
        import pylab
        addgauges(current_data)
        t = current_data.t
        pylab.title('Surface at %4.2f seconds' % t, fontsize=20)       
        # t = t / 60.  # minutes
        # pylab.title('Surface at %4.2f minutes' % t, fontsize=20)       
#       pylab.plot([139.7],[35.6],'wo',markersize=10)
#       pylab.text(138.2,35.9,'Tokyo',color='w',fontsize=25)
    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_cmap = colormaps.blue_white_red
    plotitem.pcolor_cmin = -5.
    plotitem.pcolor_cmax =  5.
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0,0,0]  ##Levels of refinement
    plotitem.gridedges_show = 1
    
    # add contour lines of bathy if desired:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = True
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = linspace(-1000,100,11)
    plotitem.amr_contour_colors = ['y']  # color on each level
    plotitem.kwargs = {'linestyles':'solid','linewidths':2}
    plotitem.amr_contour_show = [1,0,0]  
    plotitem.gridlines_show = 1
    plotitem.gridedges_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 = True
    plotitem.amr_gridlines_show = [0,0,0]
    plotitem.gridedges_show = 1

    # add contour lines of land if desired:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = True
    plotitem.plot_var = geoplot.land
    plotitem.contour_levels = linspace(0,100,10)
    plotitem.amr_contour_colors = ['y']  # color on each level
    plotitem.kwargs = {'linestyles':'solid','linewidths':2}
    plotitem.amr_contour_show = [0,0,0]  
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

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

    plotfigure = plotdata.new_plotfigure(name='Surface & topo', figno=2, \
                    type='each_gauge')
    plotfigure.clf_each_gauge = False    # Switch gauge figures on or off

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

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

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

    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, xlim
        t = current_data.t
        dtaxis=60.  # Set the axis time increment, in seconds
        #t = t/dtaxis
        tmax = t.max()
	#print "tmax = ",tmax
        legend(('surface','topography'),loc='lower left')
        plot([0,tmax],[0,0],'k')
        n = int(floor(tmax) + 2)
        xticks([dtaxis*i for i in range(n)])
        xlim(0.,tmax)
    plotaxes.afteraxes = add_zeroline
    
    def plot_TG(current_data):
        import pylab
        gaugeno = current_data.gaugeno
        if gaugeno == 5000:
            try:
                pylab.plot(Esashidata[:,0],Esashidata[:,1],'k')
                pylab.legend(['GeoClaw','Esashi data'])
            except:
                pylab.legend(['GeoClaw'])
        if gaugeno == 6000:
            try:
                pylab.plot(Iwanaidata[:,0],Iwanaidata[:,1],'k')
                pylab.legend(['GeoClaw','Iwanai data'])
            except:
                pylab.legend(['GeoClaw'])
        add_zeroline(current_data)
    plotaxes.afteraxes = plot_TG

    # Fixed grid plots:
    # -----------------

    if setplotfg is not None:

        fgnos = [1,2,3,4]      ## list of fixed grid numbers to plot
        framenos = 'all'   ## or list of frames to plot for each fgno

        def make_fgplot_generator(fgno):
            def make_fgplot(plotdata):
                fgdata = setplotfg(fgno, outdir=plotdata.outdir)
                fgdata.fg2html(framenos)
            return make_fgplot

        for fgno in fgnos:
            otherfig = plotdata.new_otherfigure('Fixed Grid %s' % fgno)
            sfgno = str(fgno).zfill(2)  # e.g. '01'
            otherfig.fname = '_PlotIndex_FixedGrid%s.html' % sfgno
            otherfig.makefig = make_fgplot_generator(fgno)


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

# Figure Printing
    plotdata.printfigs = True                # All figures printed
    # plotdata.printfigs = False             # No figures printed
    plotdata.print_format = 'png'            # file format
# Frame Printing
    plotdata.print_framenos = 'all'          # All frame figures printed
    # plotdata.print_framenos = []               # No frame figures printed
    # plotdata.print_framenos = range(0,21)    # List of frame figures to print (n1:n2-1)
# Gauge Printing
    # plotdata.print_gaugenos = 'all'        # All gauge figures printed
    plotdata.print_gaugenos = []         # No gauge figures printed
    # plotdata.print_gaugenos = range(201,210) # List of gauge figures to print range(n1,n2-1)

# Print Figures (Both Frames and Gauges)
    plotdata.print_fignos = 'all'            # list of figures to print

# Create html or latex files
    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?

# Specify Layout of Plots
    plotdata.latex_figsperline = 2           # layout of plots
    plotdata.latex_framesperline = 1         # layout of plots
    plotdata.latex_makepdf = False           # also run pdflatex?

    return plotdata
Beispiel #31
0
    plt.hold(False)
    plt.savefig(topo_file)
    plt.show()

# Domain plot
domain_file = '/Users/mandli/Documents/research/Papers/awr10/figures/ss_domain.png'
# domain_file = './ss_domain.png'
if not os.path.exists(domain_file):
    plt.figure(2)
    plt.hold(True)
    
    # Water and land
    water = np.ma.masked_where(bath>0.0,np.zeros(bath.shape))
    plt.pcolor(X,Y,bath.T,cmap=geoplot.land_colors)
    # light blue = [0,0.5,1]
    plt.pcolor(X,Y,water.T,cmap=colormaps.make_colormap({1.0:'w',0.0:'w'}))
    
    # Hurricane Track
    plt.plot([-200e3,500e3],[0.0,0.0],'r-',lw=2)
    for n in [0,5]:
        plt.plot(n*3600*5,0.0,'rD',markersize=10)
        plt.text(n*3600*5-4e3,15e3,"%s hr" % n)
    for n in [-6,13,20]:
        plt.plot(n*3600*5,0.0,'rD',markersize=10)
        plt.text(n*3600*5-10e3,15e3,"%s hr" % n)
    # plt.annotate('Position of Storm (h)',(0.0,-5e3),(-100e3,-100e3),arrowprops={'width':1,'color':'k','shrink':0.10})

    # Gauges
    setgauges = gt.read_setgauges('./_output')
    offset = 30e3
    n = 9
Beispiel #32
0
def plotfg(fgno, frameno, outdir='_output', save_png=False):
    fname = "fort.fg%s_%s" % (str(fgno).zfill(2), str(frameno).zfill(4))
    fname = os.path.join(outdir,fname)
    if not os.path.exists(fname):
        print "*** Did not find file ",fname," in directory ",outdir
        raise IOError("Missing fixed grid output file")
    
    print "Plotting fixed grid output from ",fname

    # Read parameters from header:

    file = open(fname,'r')

    line = file.readline()
    t = float(line.split()[0])
    print 't = %s' % t

    line = file.readline()
    mx = int(line.split()[0])

    line = file.readline()
    my = int(line.split()[0])

    line = file.readline()
    xlow = float(line.split()[0])

    line = file.readline()
    ylow = float(line.split()[0])

    line = file.readline()
    xhi = float(line.split()[0])

    line = file.readline()
    yhi = float(line.split()[0])

    if 0:
        print 'mx = %s' % mx
        print 'my = %s' % my
        print 'xlow = %s' % xlow
        print 'ylow = %s' % ylow
        print 'xhi = %s' % xhi
        print 'yhi = %s' % yhi
    file.close()



    x = linspace(xlow,xhi,mx+1)
    y = linspace(ylow,yhi,my+1)
    dx = x[1]-x[0]
    dy = y[1]-y[0]
    xcenter = x[:-1] + dx/2.
    ycenter = y[:-1] + dy/2.

    d = loadtxt(fname, skiprows=8)

    h = reshape(d[:,0], (my,mx))
    B = reshape(d[:,3], (my,mx))
    eta = reshape(d[:,4], (my,mx))
    surface = ma.masked_where(isnan(eta),eta)
    land = ma.masked_where(h>drytol,B)


    # plot commands: 
    # ==============

    # ===================================================
    # Adjust these:

    # Define function to plot topo contours for use in multiple places:
    def add_contours():
        clines = linspace(-20,20,21)
        contour(xcenter,ycenter,B,clines,colors='k')
        contour(xcenter,ycenter,B,[0.],colors='k',linewidths=2)

    # Set colormaps:
    water_cmap = geoplot.tsunami_colormap
    land_cmap = geoplot.land_colors
    seafloor_cmap = geoplot.seafloor_colormap
    inundated_cmap = colormaps.make_colormap({0.:[1,.9,.9], 1.:[1,0,0]})
    
    # ===================================================

    figno = 150
    figure(figno)
    clf()
    
    if ma.count(surface) != 0:
        pcolormesh(x,y,surface,cmap=water_cmap)
        clim((-5,5))
        colorbar()
    
    if ma.count(land) != 0:
        pcolormesh(x,y,land,cmap=land_cmap)
        #clim((-0.02,0.02))
    
    add_contours()
    
    
    ncols = d.shape[1]
    axis('scaled')
    title('Surface on fixed grid %s at time = %8.5f' % (fgno,t))
    xlim((xlow,xhi))
    ylim((ylow,yhi))

    if save_png:
        fname = 'FixedGrid%sFrame%sFig%s.png' \
            %  (str(fgno).zfill(2), str(frameno).zfill(4), figno)
        savefig(fname)
        print "Saved figure as ",fname
    
    
    return_fg = True  # return all the fg arrays for other purposes?
    if return_fg:
        fg = empty((my,mx,ncols), dtype=float)
        for col in range(ncols):
            fg[:,:,col] = reshape(d[:,col],(my,mx))
    
    if ncols > 5:
        etamin = reshape(d[:,5], (my,mx))
        etamax = reshape(d[:,6], (my,mx))

        #etamax2 = where(B<0, 1., etamax)
        etamax2 = where(B<0, 1., etamax)
        
        # Add red contour of maximum eta
        #contour(xcenter,ycenter,etamax2,[drytol],colors='r',linewidths=2)
        
        # Add brown contour of minimum eta
        #contour(xcenter,ycenter,etamin-B,[exposed_tol],colors=([.9,.8,.2],),linewidths=2)

        # Determine exposed and inundatated regions:

        exposed = ma.masked_where(((B>0) | (etamin > B+exposed_tol)), etamin)
        inundated = ma.masked_where(((B<0) | (etamax < B+drytol)), etamax)

        figno = 151
        figure(figno)
        clf()
        
        if ma.count(inundated) != 0:
            pcolormesh(x,y,inundated,cmap=inundated_cmap)
            clim((0,5))
            colorbar()
        add_contours()
        # Add red contour of maximum eta
        #contour(xcenter,ycenter,etamax2,[drytol],colors='r',linewidths=2)
        title("Inundated region for t <= %8.5f" % t)
        axis('scaled')
        xlim((xlow,xhi))
        ylim((ylow,yhi))
        if save_png:
            fname = 'FixedGrid%sFrame%sFig%s.png' \
                %  (str(fgno).zfill(2), str(frameno).zfill(4), figno)
            savefig(fname)
            print "Saved figure as ",fname
    

        figno = 152
        figure(figno)
        clf()
        
        if ma.count(exposed) != 0:
            pcolormesh(x,y,exposed,cmap=seafloor_cmap)
            #clim((-0.02,0.02))
            colorbar()
        add_contours()
        # Add brown contour of minimum eta
        #contour(xcenter,ycenter,etamin-B,[exposed_tol],colors=([.9,.8,.2],),linewidths=2)
        title("Exposed seabed for t <= %8.5f" % t)
        axis('scaled')
        xlim((xlow,xhi))
        ylim((ylow,yhi))
        if save_png:
            fname = 'FixedGrid%sFrame%sFig%s.png' \
                %  (str(fgno).zfill(2), str(frameno).zfill(4), figno)
            savefig(fname)
            print "Saved figure as ",fname
            
            
        return fg
Beispiel #33
0
def setplot(plotdata):
    # --------------------------

    """ 
    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 pyclaw.plotters import colormaps, geoplot
    from numpy import linspace

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

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

    def addgauges(current_data):
        from pyclaw.plotters import gaugetools

        gaugetools.plot_gauge_locations(
            current_data.plotdata, gaugenos="all", format_string="ko", add_labels=True, fontsize=8
        )

    # -----------------------------------------
    # Figure for pcolor plot
    # -----------------------------------------

    plotfigure = plotdata.new_plotfigure(name="full domain", figno=0)
    plotfigure.show = True  # Turn the pcolor plot on or off (True or False)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes("pcolor")
    plotaxes.show = True  ### Turn on or off the full domain plot
    plotaxes.title = "Surface"
    plotaxes.scaled = True

    def fixup(current_data):
        import pylab

        t = current_data.t
        # pylab.title('Surface at %4.2f seconds' % t, fontsize=20)
        t = t / 60.0  # minutes
        pylab.title("Surface at %4.2f minutes" % t, fontsize=20)
        pylab.xticks(fontsize=15)
        pylab.yticks(fontsize=15)
        # pylab.plot([205],[20],'wo',markersize=5)
        # pylab.text(201,22,'Hawaii',color='w',fontsize=15)
        # pylab.plot([139.7],[35.6],'wo',markersize=5)
        # pylab.text(135.2,35.9,'Tokyo',color='w',fontsize=15)
        # pylab.plot([235.81],[41.75],'wo',markersize=5)
        # pylab.text(235.9,42,'Crescent City',color='w',fontsize=15)
        addgauges(current_data)

    plotaxes.afteraxes = fixup

    # plotaxes.s = [137.57,141.41] # Full Domain
    # plotaxes.ylimits = [39.67,44.15] # Full Domain
    # plotaxes.xlimits = [139., 140.] ## Okushiri Island (Large area)
    # plotaxes.ylimits = [41.5, 42.5]   ## Okushiri Island  (Large area)
    # plotaxes.xlimits = [139.43, 139.48] ## Aonae peninsula
    # plotaxes.ylimits = [42.03, 42.06]   ## Aonae peninsula
    # plotaxes.xlimits = [139.35, 139.6] ## Okushiri Island (Tight)
    # plotaxes.ylimits = [42.0, 42.25]   ## Okushiri Island (Tight)
    # plotaxes.xlimits = [139.41, 139.43] ## Monai Long Coast
    # plotaxes.ylimits = [42.08, 42.15]   ## Monai Long Coast
    # plotaxes.xlimits = [139.418, 139.426] ## Monai Short
    # plotaxes.ylimits = [42.096, 42.106]   ## Monai Short

    # Water
    plotitem = plotaxes.new_plotitem(plot_type="2d_pcolor")
    plotitem.show = True
    # plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    # plotitem.pcolor_cmap = geoplot.tsunami_colormap
    # plotitem.pcolor_cmap = colormaps.blue_white_red
    # dictionary of [R,G,B] values at different levels:
    my_cmap_surface = colormaps.make_colormap(
        {
            -1.0: [0.0, 0.0, 1.0],
            -0.02: [0.75, 0.75, 1.0],
            0.0: [1.0, 1.0, 1.0],
            0.02: [1.0, 0.75, 0.75],
            1.0: [1.0, 0.0, 0.0],
        }
    )
    plotitem.pcolor_cmap = my_cmap_surface
    plotitem.pcolor_cmin = -50.0
    plotitem.pcolor_cmax = 50.0
    plotitem.add_colorbar = True
    plotitem.amr_gridedges_show = [1]
    # plotitem.amr_gridlines_show = [0,0,0,0,0] # Turn off/0n = 0/1 gridlines for levels [1,2,3, ...]
    # plotitem.gridedges_show = 0
    # plotitem.amr_data_show = [1,1,1,1,0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type="2d_pcolor")
    plotitem.show = True
    plotitem.plot_var = geoplot.land
    my_cmap_land = colormaps.make_colormap({0.0: [0.0, 1.0, 0.0], 1.0: [0.0, 0.5, 0.0]})
    plotitem.pcolor_cmap = my_cmap_land
    # plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = True
    # plotitem.amr_gridlines_show = [0,0,0]
    # plotitem.gridedges_show = 0
    # plotitem.amr_data_show = [1,1,1,1,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(-20,20,11)
    plotitem.contour_levels = [0.0]
    plotitem.amr_contour_colors = ["k"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid", "linewidths": 1}
    plotitem.amr_contour_show = [0, 0, 0, 1]

    # plotitem.gridlines_show = 0
    # plotitem.gridedges_show = 0
    # plotitem.amr_data_show = [1,1,1,0]

    # Topo = Bathymetry and Land
    plotitem = plotaxes.new_plotitem(plot_type="2d_pcolor")
    plotitem.show = False
    plotitem.plot_var = geoplot.topo
    # plotitem.pcolor_cmap = geoplot.bathy3_colormap  #Try 1, 2 & 3

    my_cmap_topo = colormaps.make_colormap({-5000.0: [0, 0, 1], 0.0: [1, 1, 1], 100.0: [0.0, 0.5, 0.0]})
    plotitem.pcolor_cmap = my_cmap_topo

    plotitem.pcolor_cmin = -5000.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = False
    # plotitem.amr_gridlines_show = [0,0,0]
    # plotitem.gridedges_show = 0
    # plotitem.amr_data_show = [1,1,1,1,0]

    # add contour lines of topo if desired:
    plotitem = plotaxes.new_plotitem(plot_type="2d_contour")
    plotitem.show = False
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = linspace(-5000, -100, 6)
    plotitem.amr_contour_colors = ["y"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid", "linewidths": 1}
    # plotitem.amr_contour_show = [0,0,0]
    # plotitem.gridlines_show = 0
    # plotitem.gridedges_show = 0
    # plotitem.amr_data_show = [1,1,1,0]

    # -----------------------------------------
    # Figure for velocity plot
    # -----------------------------------------

    plotfigure = plotdata.new_plotfigure(name="speed", figno=20)
    plotfigure.show = True  # Turn the pcolor plot on or off (True or False)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes("pcolor")
    plotaxes.show = True  ### Turn on or off the full domain plot
    plotaxes.title = "Water speed"
    plotaxes.scaled = True

    plotaxes.afteraxes = fixup

    # Water
    plotitem = plotaxes.new_plotitem(plot_type="2d_pcolor")
    plotitem.show = True

    def speed(current_data):
        from numpy import where, sqrt

        q = current_data.q
        x = current_data.x
        y = current_data.y
        level = current_data.level

        h = q[:, :, 0]
        hu = q[:, :, 1]
        hv = q[:, :, 2]
        u = where(h > 0, hu / h, 0.0)
        v = where(h > 0, hv / h, 0.0)
        s = sqrt(u ** 2 + v ** 2)
        print "level = %s, max speed = %s" % (level, s.max())
        i = s.argmax()
        print "   at x = %s, y = %s" % (x.flat[i], y.flat[i])
        return s

    plotitem.plot_var = speed

    my_cmap_surface = colormaps.make_colormap(
        {
            -1.0: [0.0, 0.0, 1.0],
            -0.02: [0.75, 0.75, 1.0],
            0.0: [1.0, 1.0, 1.0],
            0.02: [1.0, 0.75, 0.75],
            1.0: [1.0, 0.0, 0.0],
        }
    )
    plotitem.pcolor_cmap = my_cmap_surface
    plotitem.pcolor_cmin = -50.0
    plotitem.pcolor_cmax = 50.0
    plotitem.add_colorbar = True
    plotitem.amr_gridedges_show = [1]
    # plotitem.amr_gridlines_show = [0,0,0,0,0] # Turn off/0n = 0/1 gridlines for levels [1,2,3, ...]
    # plotitem.gridedges_show = 0
    # plotitem.amr_data_show = [1,1,1,1,0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type="2d_pcolor")
    plotitem.show = True
    plotitem.plot_var = geoplot.land
    my_cmap_land = colormaps.make_colormap({0.0: [0.0, 1.0, 0.0], 1.0: [0.0, 0.5, 0.0]})
    plotitem.pcolor_cmap = my_cmap_land
    # plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = True
    # plotitem.amr_gridlines_show = [0,0,0]
    # plotitem.gridedges_show = 0
    # plotitem.amr_data_show = [1,1,1,1,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(-20,20,11)
    plotitem.contour_levels = [0.0]
    plotitem.amr_contour_colors = ["k"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid", "linewidths": 1}
    plotitem.amr_contour_show = [0, 0, 0, 1]

    # -----------------------------------------
    # Figure for zoom plot
    # -----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="Zoom", figno=1)
    plotfigure.show = False  # Turn the zoom plot on or off (True or False)

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes("pcolor")
    plotaxes.title = "Surface"
    plotaxes.scaled = True
    ##
    # plotaxes.xlimits = [140.3, 140.5] ## Esashi Tide Gage
    # plotaxes.ylimits = [41.75, 41.95] ## Esashi Tide Gage
    # plotaxes.xlimits = [139.35, 139.6] ## Okushiri Island
    # plotaxes.ylimits = [42.0, 42.25]   ## Okushiri Island
    # plotaxes.xlimits = [139.43, 139.48] ## Aonae peninsula
    # plotaxes.ylimits = [42.03, 42.06]   ## Aonae peninsula
    # plotaxes.xlimits = [139.41, 139.43] ## Monai
    # plotaxes.ylimits = [42.08, 42.15]   ## Monai
    # plotaxes.xlimits = [139.41385190, 139.42639510] ## MB05 Monai grid
    # plotaxes.ylimits = [42.09458550, 42.10343920]   ## MB05 Monai grid
    plotaxes.xlimits = [139.0, 140.0]  ## Okushiri Island
    plotaxes.ylimits = [41.5, 42.5]  ## Okushiri Island

    # dx = 0.00005
    # dy = 0.00005
    # plotaxes.xlimits = [139.423714744650-dx, 139.423714744650+dx] ## Station 8, Monai valley
    # plotaxes.ylimits = [ 42.100414145210-dy,  42.100414145210+dy] ## Station 8, Monai valley

    def fixup(current_data):
        import pylab

        addgauges(current_data)
        t = current_data.t
        pylab.title("Surface at %4.2f seconds" % t, fontsize=20)
        # t = t / 60.  # minutes
        # pylab.title('Surface at %4.2f minutes' % t, fontsize=20)

    #       pylab.plot([139.7],[35.6],'wo',markersize=10)
    #       pylab.text(138.2,35.9,'Tokyo',color='w',fontsize=25)
    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_cmap = colormaps.blue_white_red
    plotitem.pcolor_cmin = -5.0
    plotitem.pcolor_cmax = 5.0
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]  ##Levels of refinement
    plotitem.gridedges_show = 1

    # add contour lines of bathy if desired:
    plotitem = plotaxes.new_plotitem(plot_type="2d_contour")
    plotitem.show = True
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = linspace(-1000, 100, 11)
    plotitem.amr_contour_colors = ["y"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid", "linewidths": 2}
    plotitem.amr_contour_show = [1, 0, 0]
    plotitem.gridlines_show = 1
    plotitem.gridedges_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 = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.gridedges_show = 1

    # add contour lines of land if desired:
    plotitem = plotaxes.new_plotitem(plot_type="2d_contour")
    plotitem.show = True
    plotitem.plot_var = geoplot.land
    plotitem.contour_levels = linspace(0, 100, 10)
    plotitem.amr_contour_colors = ["y"]  # color on each level
    plotitem.kwargs = {"linestyles": "solid", "linewidths": 2}
    plotitem.amr_contour_show = [0, 0, 0]
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

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

    plotfigure = plotdata.new_plotfigure(name="Surface & topo", figno=2, type="each_gauge")
    plotfigure.clf_each_gauge = False  # Switch gauge figures on or off

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = "auto"
    # plotaxes.ylimits = 'auto'
    plotaxes.ylimits = [-20.0, 20.0]
    plotaxes.title = "Surface"

    # Plot surface as blue curve:
    plotitem = plotaxes.new_plotitem(plot_type="1d_plot")
    plotitem.plot_var = 3
    plotitem.plotstyle = "b-"
    plotitem.kwargs = {"linewidth": 2}

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

    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, xlim

        t = current_data.t
        dtaxis = 60.0  # Set the axis time increment, in seconds
        # t = t/dtaxis
        tmax = t.max()
        # print "tmax = ",tmax
        legend(("surface", "topography"), loc="lower left")
        plot([0, tmax], [0, 0], "k")
        n = int(floor(tmax) + 2)
        xticks([dtaxis * i for i in range(n)])
        xlim(0.0, tmax)

    plotaxes.afteraxes = add_zeroline

    def plot_TG(current_data):
        import pylab

        gaugeno = current_data.gaugeno
        if gaugeno == 5000:
            try:
                pylab.plot(Esashidata[:, 0], Esashidata[:, 1], "k")
                pylab.legend(["GeoClaw", "Esashi data"])
            except:
                pylab.legend(["GeoClaw"])
        if gaugeno == 6000:
            try:
                pylab.plot(Iwanaidata[:, 0], Iwanaidata[:, 1], "k")
                pylab.legend(["GeoClaw", "Iwanai data"])
            except:
                pylab.legend(["GeoClaw"])
        add_zeroline(current_data)

    plotaxes.afteraxes = plot_TG

    # Fixed grid plots:
    # -----------------

    if setplotfg is not None:

        # Repeat as desired for other fixed grids...
        otherfig = plotdata.new_otherfigure("Fixed Grid 1")
        fgno = 1
        sfgno = str(fgno).zfill(2)  # e.g. '01'
        otherfig.fname = "_PlotIndex_FixedGrid%s.html" % sfgno

        def make_fgplots(plotdata):
            fgdata = setplotfg(fgno, outdir=plotdata.outdir)
            fgdata.fg2html("all")

        otherfig.makefig = make_fgplots

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

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

    # Figure Printing
    plotdata.printfigs = True  # All figures printed
    # plotdata.printfigs = False             # No figures printed
    plotdata.print_format = "png"  # file format
    # Frame Printing
    plotdata.print_framenos = "all"  # All frame figures printed
    # plotdata.print_framenos = []               # No frame figures printed
    # plotdata.print_framenos = range(0,21)    # List of frame figures to print (n1:n2-1)
    # Gauge Printing
    # plotdata.print_gaugenos = 'all'        # All gauge figures printed
    plotdata.print_gaugenos = []  # No gauge figures printed
    # plotdata.print_gaugenos = range(201,210) # List of gauge figures to print range(n1,n2-1)

    # Print Figures (Both Frames and Gauges)
    plotdata.print_fignos = "all"  # list of figures to print

    # Create html or latex files
    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?

    # Specify Layout of Plots
    plotdata.latex_figsperline = 2  # layout of plots
    plotdata.latex_framesperline = 1  # layout of plots
    plotdata.latex_makepdf = False  # also run pdflatex?

    return plotdata
Beispiel #34
0
def setplot(plotdata):
    # --------------------------
    """
    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 pyclaw.plotters import colormaps, geoplot

    plotdata.clearfigures()  # clear any old figures,axes,items dat
    #   plotdata.format = "netcdf"

    try:
        tsudata = open(plotdata.outdir + '/settsunami.data').readlines()
        for line in tsudata:
            if 'sealevel' in line:
                sealevel = float(line.split()[0])
                print "sealevel = ", sealevel
    except:
        print "Could not read sealevel, setting to 0."
        sealevel = 0.

    #clim_ocean = 2.0
    #clim_CC = 2.0
    clim_ocean = 5.0
    clim_CC = 5.0

    cmax_ocean = clim_ocean + sealevel
    cmin_ocean = -clim_ocean + sealevel
    cmax_CC = clim_CC + sealevel
    cmin_CC = -clim_CC + sealevel

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

    def addgauges(current_data):
        from pyclaw.plotters import gaugetools
        gaugetools.plot_gauge_locations(current_data.plotdata, \
             gaugenos=[0], 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)

    def aframe(current_data):
        from pylab import figure, savefig

        if 0:
            tminutes = int(current_data.t / 60.)

            figure(0)
            fname = 'Pacific%s.png' % tminutes
            savefig(fname)
            print "Saved ", fname

            figure(11)
            fname = 'GraysHarbor%s.png' % tminutes
            savefig(fname)
            print "Saved ", fname

            figure(12)
            fname = 'Westport%s.png' % tminutes
            savefig(fname)
            print "Saved ", fname

            figure(13)
            fname = 'Ocosta%s.png' % tminutes
            savefig(fname)
            print "Saved ", fname

    plotdata.afterframe = aframe

    #-----------------------------------------
    # Figure for big area
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Pacific', figno=0)
    plotfigure.kwargs = {'figsize': (10, 6)}
    #plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    #plotaxes.cmd = 'subplot(121)'
    plotaxes.title = 'Pacific'
    plotaxes.scaled = False

    # modified for debug:
    #plotaxes.xlimits = [231.5,236.5]
    #plotaxes.ylimits = [45,49]
    #plotaxes.xlimits = [235.8,236.2]
    #plotaxes.ylimits = [46.1,46.9]

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

    plotaxes.afteraxes = aa

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                     -0.5: [0.5,0.5,1.0], \
                                      0.0: [1.0,1.0,1.0], \
                                      0.5: [1.0,0.5,0.5], \
                                      1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = cmin_ocean
    plotitem.imshow_cmax = cmax_ocean
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]
    #plotaxes.afteraxes = addgauges

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

    # Add contour lines of topography:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = False
    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, 0,
                                 1]  # show contours only on finest level
    plotitem.gridlines_show = 0
    plotitem.gridedges_show = 0

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

    #plotfigure.show = False

    def eta_slice(current_data):
        from pylab import find, nan, array
        x = current_data.x
        y = current_data.y
        q = current_data.q
        j1 = find(y[0, :] > 47.5)
        if len(j1) == 0:
            x = eta = array([nan])
        else:
            j = min(j1)
            x = x[:, j]
            eta = q[:, j, 3]
        return x, eta

    def B_slice(current_data):
        from pylab import find, nan, array
        x = current_data.x
        y = current_data.y
        q = current_data.q
        j1 = find(y[0, :] > 47.5)
        if len(j1) == 0:
            x = B = array([nan])
        else:
            j = min(j1)
            x = x[:, j]
            eta = q[:, j, 3]
            h = q[:, j, 0]
            B = eta - h
        return x, B

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('line')
    plotaxes.axescmd = 'subplot(212)'
    plotaxes.title = 'Bathymetry'

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.show = False
    plotitem.map_2d_to_1d = eta_slice
    plotitem.color = 'b'
    plotitem.kwargs = {'linewidth': 2}

    # Topography
    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    #plotitem.show = False
    plotitem.map_2d_to_1d = B_slice
    plotitem.color = 'k'
    plotitem.plotstyle = 'o-'

    def aa(current_data):
        from pylab import ticklabel_format
        ticklabel_format(format='plain', useOffset=False)

    plotaxes.afteraxes = aa

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('linezoom')
    #plotaxes.show = False
    plotaxes.axescmd = 'subplot(211)'
    plotaxes.title = 'Surface'
    #plotaxes.xlimits = [-0.1,0.1]
    plotaxes.ylimits = [-4, 6]

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.map_2d_to_1d = eta_slice
    plotitem.color = 'b'
    plotitem.plotstyle = 'o-'
    plotitem.kwargs = {'linewidth': 2}

    #-----------------------------------------
    # Figure for zoom2
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name="Gray's Harbor", figno=11)
    plotfigure.show = False
    plotfigure.kwargs = {'figsize': (10, 9)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    #plotaxes.cmd = 'subplot(122)'
    plotaxes.title = "Gray's Harbor"
    plotaxes.scaled = False

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                      -0.5: [0.5,0.5,1.0], \
                                       0.0: [1.0,1.0,1.0], \
                                       0.5: [1.0,0.5,0.5], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = cmin_CC
    plotitem.imshow_cmax = cmax_CC
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [0]
    plotaxes.xlimits = [235.8, 236.2]
    plotaxes.ylimits = [46.75, 47.1]

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, savefig
        #addgauges(current_data)
        title_hours(current_data)
        ticklabel_format(format='plain', useOffset=False)
        xticks(rotation=20)
        a = gca()
        a.set_aspect(1. / cos(46.86 * pi / 180.))

    plotaxes.afteraxes = aa

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

    #-----------------------------------------
    # Figure for zoom
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Washington', figno=10)
    plotfigure.show = False

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                      -0.1: [0.5,0.5,1.0], \
                                       0.0: [1.0,1.0,1.0], \
                                       0.1: [1.0,0.5,0.5], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = cmin_ocean
    plotitem.imshow_cmax = cmax_ocean
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]
    plotaxes.xlimits = [235, 236.5]
    plotaxes.ylimits = [46, 49]
    plotaxes.afteraxes = aa

    #-----------------------------------------
    # Figure for zoom3
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Long Beach', figno=12)
    plotfigure.show = False
    plotfigure.kwargs = {'figsize': (8, 7)}

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    #plotitem.show = False
    plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({-1.0: [0.0,0.0,1.0], \
                                      -0.5: [0.5,0.5,1.0], \
                                       0.0: [1.0,1.0,1.0], \
                                       0.5: [1.0,0.5,0.5], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = cmin_ocean
    plotitem.imshow_cmax = cmax_ocean
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.land
    #plotitem.plot_var = 3
    land_cmap = colormaps.make_colormap({0.0: [0.0,0.0,1.0], \
                                       0.5: [1.0,0.0,0.0], \
                                       1.0: [0.0,1.0,0.0]})
    plotitem.imshow_cmap = geoplot.land_colors
    #plotitem.imshow_cmap = land_cmap
    plotitem.imshow_cmin = 0.
    plotitem.imshow_cmax = 10.
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [0]
    plotaxes.xlimits = [235.90, 235.98]
    plotaxes.ylimits = [46.30, 46.39]

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, imshow, \
                    savefig, plot
        from pyclaw.plotters.plottools import plotbox
        #addgauges(current_data)
        title_hours(current_data)
        ticklabel_format(format='plain', useOffset=False)
        xticks(rotation=20)
        a = gca()
        #a.set_aspect(1./cos(46.86*pi/180.))
        a.set_aspect(1. / cos(46.349 * pi / 180.))
        plot([235.9499], [46.3490], 'wo')
        #extent = (235.8756, 235.9116, 46.854, 46.8756)
        #plotbox(extent)
        #imshow(OcostaGE,extent=extent, alpha=0.5)
        #extent = (235.81, 235.95, 46.85, 46.95)
        #imshow(WestportGE,extent=extent, alpha=0.8)

    plotaxes.afteraxes = aa

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

    #-----------------------------------------
    # Figure for zoom4
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Berm', figno=13)
    plotfigure.show = False
    plotfigure.kwargs = {'figsize': (12, 8)}

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    #plotitem.show=False
    plotitem.plot_var = geoplot.depth
    #plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({0.0: [1.0,1.0,1.0], \
                                       0.5: [1.0,0.8,0.0], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = 0.
    plotitem.imshow_cmax = 3.
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    #plotitem.show=False
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 20.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    #plotaxes.xlimits = [235.88, 235.905]
    #plotaxes.ylimits = [46.855, 46.87]
    plotaxes.xlimits = [235.947, 235.951]
    plotaxes.ylimits = [46.347, 46.35]

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, imshow, \
                    savefig, plot
        addgauges(current_data)
        title_hours(current_data)
        ticklabel_format(format='plain', useOffset=False)
        xticks(rotation=20)
        plot([235.9499], [46.3490], 'wo')
        #extent = (235.8756, 235.9116, 46.854, 46.8756)
        #imshow(OcostaGE,extent=extent, alpha=0.5)
        a = gca()
        a.set_aspect(1. / cos(46.349 * pi / 180.))
        #extent = (235.81, 235.95, 46.85, 46.95)
        #imshow(WestportGE,extent=extent, alpha=0.8)

    plotaxes.afteraxes = aa

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

    #-----------------------------------------
    # Figure for zoom4 speed
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Ocosta speed', figno=14)
    plotfigure.show = False
    plotfigure.kwargs = {'figsize': (12, 8)}

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')

    #plotitem.show=False
    def speed(current_data):
        from numpy import sqrt, where
        q = current_data.q
        h = q[:, :, 0]
        hu = q[:, :, 1]
        hv = q[:, :, 2]
        u = where(h > 0.01, hu / h, 0.)
        v = where(h > 0.01, hv / h, 0.)
        speed = sqrt(u**2 + v**2)
        return v

    plotitem.plot_var = speed
    #plotitem.plot_var = geoplot.surface_or_depth
    my_cmap = colormaps.make_colormap({0.0: [0.0,0.0,1.0], \
                                       0.5: [1.0,1.0,1.0], \
                                       1.0: [1.0,0.0,0.0]})
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = -3.
    plotitem.imshow_cmax = 3.
    plotitem.add_colorbar = True
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    #plotitem.show=False
    plotitem.plot_var = geoplot.land
    plotitem.imshow_cmap = geoplot.land_colors
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 20.0
    plotitem.add_colorbar = False
    plotitem.amr_gridlines_show = [0, 0, 0]
    plotitem.amr_gridedges_show = [1]

    #plotaxes.xlimits = [235.88, 235.905]
    #plotaxes.ylimits = [46.855, 46.87]
    plotaxes.xlimits = [235.88, 235.935]
    plotaxes.ylimits = [46.845, 46.875]

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, imshow, savefig
        addgauges(current_data)
        title_hours(current_data)
        ticklabel_format(format='plain', useOffset=False)
        xticks(rotation=20)
        #extent = (235.8756, 235.9116, 46.854, 46.8756)
        #imshow(OcostaGE,extent=extent, alpha=0.5)
        a = gca()
        a.set_aspect(1. / cos(46.86 * pi / 180.))
        #extent = (235.81, 235.95, 46.85, 46.95)
        #imshow(WestportGE,extent=extent, alpha=0.8)

    plotaxes.afteraxes = aa

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

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.ylimits = [-1, 10]
    plotaxes.xlimits = [-1, 10]
    plotaxes.title = 'Surface'

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

    def axes_gauge(current_data):
        from pylab import plot, legend, xticks, floor,\
            yticks,xlabel,savefig,xlim,ylim,xlabel,ylabel
        t = current_data.t
        gaugeno = current_data.gaugeno
        xticks(linspace(0, 1, 7), [str(i) for i in range(0, 7, 10)])
        xlabel('time (minutes) after quake', fontsize=15)
        ylabel('meters', fontsize=15)
        ylim(-1, 10)

    plotaxes.afteraxes = axes_gauge

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

    # 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_fignos = 'all'  # list of figures to print
    plotdata.print_gaugenos = 'all'  # list of gauges 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?

    return plotdata