Esempio n. 1
0
    def fill_with_cmap(current_data):
        from clawpack.visclaw.colormaps import make_colormap
        import string
        x = current_data.x
        h = current_data.q[0,:]
        u = current_data.q[1,:] / h
        tracer = current_data.q[2,:]
        X = vstack((x,x))
        Y = vstack((0*x, h))
        c = 0.*x
        i1 = array([mod(int(12*tracer[i]),2) for i in range(len(x))])
        c = where((i1==0) & (tracer>0), 1, c)
        c = where((i1==0) & (tracer<0), -1, c)
        c = where((i1==1) & (tracer<0), -0.5, c)
        c = where((i1==1) & (tracer>0), 0.5, c)
        cmin = -1.0
        cmax = 1.0
        cmid = 0.5*(cmin+cmax)
        cmap = make_colormap({-1: [0.9,0.9,1.0], \
                              -0.001:[0.0,0.0,1.0], \
                               0.001:[1.0,0.4,0.4], \
                              1.0:[1.0,0.9,0.9]})
        cmap = make_colormap({cmin: [1.0,0.0,0.0], -0.5:[1.,.8,.8],
                    cmid:[.8,1,1.], cmax:[0.,0.,1]})

        C = vstack((c,c))
        pcolor(X,Y,C,cmap=cmap)
        outdir = current_data.plotdata.outdir
        frameno = string.zfill(current_data.frameno,4)
        #plot_approx_Rsoln(current_data)
        ylim([0,3.5])
        xticks(fontsize=20)
        yticks(fontsize=20)
        title("Depth and tracer at t = %6.3f" % current_data.t, fontsize=30)
Esempio n. 2
0
def plot_masked_Z(topo, pt_chosen, ax=None, zmin=-10000., zmax=40.):

    import clawpack.visclaw.colormaps as colormaps

    fgmax_mgrid = {}

    land_cmap = colormaps.make_colormap({
        0.0: [0.1, 0.4, 0.0],
        0.25: [0.0, 1.0, 0.0],
        0.5: [0.8, 1.0, 0.5],
        1.0: [0.8, 0.5, 0.2]
    })

    sea_cmap = colormaps.make_colormap({0.0: [0, 0, 1], 1.: [.8, .8, 1]})

    cmap, norm = colormaps.add_colormaps((land_cmap, sea_cmap),
                                         data_limits=(zmin, zmax),
                                         data_break=0.)

    mask = logical_not(pt_chosen)
    Z = ma.masked_array(topo.Z, mask)
    if ax is None:
        figure()
        ax = subplot(111)
    pc = pcolormesh(topo.X, topo.Y, Z, cmap=cmap, norm=norm)
    cb = colorbar(pc)
    cb.set_label('meters')
    gca().set_aspect(1. / cos(48 * pi / 180.))
    ticklabel_format(useOffset=False)
    xticks(rotation=20)
Esempio n. 3
0
def setplotfg(fgno=1, outdir='_output'):
    from clawpack.visclaw import plotfg, colormaps, geoplot
    from numpy import arange

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

    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
Esempio n. 4
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)
Esempio n. 5
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_pcolor')
        # 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.pcolor_cmin = bounds[0]
            plotitem.pcolor_cmax = bounds[1]
        # plotitem.pcolor_cmap = geoplot.tsunami_colormap
        plotitem.pcolor_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
        plotitem.add_colorbar = True
        plotitem.amr_celledges_show = [0,0,0]
        plotitem.amr_patchedges_show = [0,0,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_celledges_show = [0,0,0]
        plotitem.amr_patchedges_show = [1,1,1]
        plotitem.amr_contour_colors = 'k'

    else:
        raise NotImplementedError("Plot type %s not implemented" % plot_type)
Esempio n. 6
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_celledges_show = [0, 0, 0]
         plotitem.amr_patchedges_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_celledges_show = [0, 0, 0]
         plotitem.amr_patchedges_show = [1, 1, 1]
         plotitem.amr_contour_colors = 'k'
Esempio n. 7
0
def add_land(plotaxes,plot_type='pcolor',topo_min=-10,topo_max=10.0):
    if plot_type == 'pcolor':
        plotitem = plotaxes.new_plotitem(name='land',plot_type='2d_pcolor')
        plotitem.show = True
        cmap = colormaps.make_colormap({-1:[0.3,0.2,0.1],
                                       -0.00001:[0.95,0.9,0.7],
                                       0.00001:[.5,.7,0],
                                       1:[.2,.5,.2]})
        # color_norm = colors.Normalize(topo_min,topo_max,clip=True)
        plotitem.plot_var = geoplot.land
        # plotitem.pcolor_cmap = geoplot.land_colors
        plotitem.pcolor_cmap = cmap
        plotitem.pcolor_cmin = topo_min
        plotitem.pcolor_cmax = topo_max
        plotitem.add_colorbar = False
        plotitem.amr_celledges_show = [0,0,0,0,0,0,0]
        plotitem.amr_patchedges_show = [1,1,1,1,1,0,0]
    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_patch_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']
        plotitem.celledges_show = 0
        plotitem.patchedges_show = 0   
Esempio n. 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_pcolor")
        # 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.pcolor_cmin = bounds[0]
            plotitem.pcolor_cmax = bounds[1]
        # plotitem.pcolor_cmap = geoplot.tsunami_colormap
        plotitem.pcolor_cmap = colormaps.make_colormap({1.0: "r", 0.5: "w", 0.0: "b"})
        plotitem.add_colorbar = True
        plotitem.amr_celledges_show = [0, 0, 0]
        plotitem.amr_patchedges_show = [0, 0, 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_celledges_show = [0, 0, 0]
        plotitem.amr_patchedges_show = [1, 1, 1]
        plotitem.amr_contour_colors = "k"

    else:
        raise NotImplementedError("Plot type %s not implemented" % plot_type)
Esempio n. 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)
Esempio n. 10
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_pcolor')
        # 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.pcolor_cmin = bounds[0]
            plotitem.pcolor_cmax = bounds[1]
        # plotitem.pcolor_cmap = geoplot.tsunami_colormap
        plotitem.pcolor_cmap = colormaps.make_colormap({
            1.0: 'r',
            0.5: 'w',
            0.0: 'b'
        })
        plotitem.add_colorbar = True
        plotitem.amr_celledges_show = [0, 0, 0]
        plotitem.amr_patchedges_show = [0, 0, 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_celledges_show = [0, 0, 0]
        plotitem.amr_patchedges_show = [1, 1, 1]
        plotitem.amr_contour_colors = 'k'

    else:
        raise NotImplementedError("Plot type %s not implemented" % plot_type)
Esempio n. 11
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_celledges_show = [0, 0, 0]
         plotitem.amr_patchedges_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_celledges_show = [0, 0, 0]
         plotitem.amr_patchedges_show = [1, 1, 1]
         plotitem.amr_contour_colors = "k"
Esempio n. 12
0
def add_surface_elevation(plotaxes,bounds=None,plot_type='pcolor',shrink=1.0):
    if plot_type == 'pcolor' or plot_type == 'imshow':            
        plotitem = plotaxes.new_plotitem(name='surface',plot_type='2d_pcolor')
        plotitem.plot_var = geoplot.surface_or_depth
        # plotitem.plot_var = geoplot.surface
        plotitem.pcolor_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
        # plotitem.pcolor_cmap = geoplot.tsunami_colormap
        if bounds is not None:
            plotitem.pcolor_cmin = bounds[0]
            plotitem.pcolor_cmax = bounds[1]
        plotitem.add_colorbar = True
        plotitem.colorbar_shrink = shrink
        plotitem.colorbar_label = "Surface Height (m)"
        plotitem.amr_celledges_show = [0,0,0,0,0,0,0]
        plotitem.amr_patchedges_show = [1,1,1,1,1,0,0]
    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_celledges_show = [0,0,0,0,0,0,0]
        plotitem.amr_patchedges_show = [1,1,1,1,0,0,0]
        plotitem.amr_contour_colors = 'k'
Esempio n. 13
0
def add_land(plotaxes, plot_type='pcolor', topo_min=-10, topo_max=10.0):
    if plot_type == 'pcolor':
        plotitem = plotaxes.new_plotitem(name='land', plot_type='2d_pcolor')
        plotitem.show = True
        cmap = colormaps.make_colormap({
            -1: [0.3, 0.2, 0.1],
            -0.00001: [0.95, 0.9, 0.7],
            0.00001: [.5, .7, 0],
            1: [.2, .5, .2]
        })
        # color_norm = colors.Normalize(topo_min,topo_max,clip=True)
        plotitem.plot_var = geoplot.land
        # plotitem.pcolor_cmap = geoplot.land_colors
        plotitem.pcolor_cmap = cmap
        plotitem.pcolor_cmin = topo_min
        plotitem.pcolor_cmax = topo_max
        plotitem.add_colorbar = False
        plotitem.amr_celledges_show = [0, 0, 0, 0, 0, 0, 0]
        plotitem.amr_patchedges_show = [1, 1, 1, 1, 1, 0, 0]
    elif plot_type == 'contour':
        plotitem = plotaxes.new_plotitem(name="land", 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_patch_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']
        plotitem.celledges_show = 0
        plotitem.patchedges_show = 0
Esempio n. 14
0
    def plot(self, axes=None, region_extent=None, contours=None, 
                    coastlines=True, limits=None, cmap=plt.get_cmap('terrain')):
        r"""
        Plot the topography
        """

        # Create axes if needed
        if axes is None:
            fig = plt.figure()
            axes = fig.add_subplot(111)
        
        # Turn off annoying offset
        axes.ticklabel_format(format="plain", useOffset=False)

        # Generate limits if need be
        if region_extent is None:
            region_extent = ( numpy.min(self.X), numpy.max(self.X),
                              numpy.min(self.Y), numpy.max(self.Y) )
        mean_lat = 0.5 * (region_extent[3] - region_extent[2])
        axes.set_aspect(1.0 / numpy.cos(numpy.pi / 180.0 * mean_lat))
        if limits is None:
            depth_extent = (numpy.min(self.Z),numpy.max(self.Z))
        else:
            depth_extent = limits

        # Create color map
        cmap = colormaps.make_colormap({-1:[0.3,0.2,0.1],
                                           -0.00001:[0.95,0.9,0.7],
                                           0.00001:[.5,.7,0],
                                           1:[.2,.5,.2]})
        color_norm = colors.Normalize(depth_extent[0],depth_extent[1],clip=True)

        # Plot data
        if contours is not None:
            plot = axes.contourf(self.X, self.Y, self.Z, contours,cmap=cmap)
        elif isinstance(self.Z, numpy.ma.MaskedArray):
            plot = axes.pcolor(self.X, self.Y, self.Z, vmin=depth_extent[0], 
                                                       vmax=depth_extent[1],
                                                       cmap=cmap, 
                                                       norm=color_norm)
        else:
            plot = axes.imshow(self.Z, vmin=depth_extent[0], 
                                       vmax=depth_extent[1],
                                       extent=region_extent, 
                                       cmap=cmap, 
                                       norm=color_norm)
        cbar = plt.colorbar(plot, ax=axes)
        cbar.set_label("Depth (m)")
        # levels = range(0,int(-numpy.min(Z)),500)

        # Plot coastlines
        if coastlines:
            axes.contour(self.X, self.Y, self.Z, levels=[0.0],colors='r')

        axes.set_xlim(region_extent[0:2])
        axes.set_ylim(region_extent[2:])

        return axes
Esempio n. 15
0
def add_inundation(plotaxes, surface, bounds=None, plot_type='pcolor'):
    if plot_type == 'pcolor' or plot_type == 'imshow':
        plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
        plotitem.plot_var = inundated(surface)
        if bounds is not None:
            plotitem.pcolor_cmin = bounds[0]
            plotitem.pcolor_cmax = bounds[1]
        plotitem.pcolor_cmap = colormaps.make_colormap({1.0: 'c', 0.0: 'w'})
        plotitem.add_colorbar = True
        plotitem.amr_celledges_show = [0, 0, 0]
        plotitem.amr_patchedges_show = [0, 0, 0]
Esempio n. 16
0
def add_inundation(plotaxes,surface,bounds=None,plot_type='pcolor'):
    if plot_type == 'pcolor' or plot_type == 'imshow':
        plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
        plotitem.plot_var = inundated(surface)        
        if bounds is not None:                
            plotitem.pcolor_cmin = bounds[0]
            plotitem.pcolor_cmax = bounds[1]
        plotitem.pcolor_cmap = colormaps.make_colormap({1.0:'c',0.0:'w'})
        plotitem.add_colorbar = True
        plotitem.amr_celledges_show = [0,0,0]
        plotitem.amr_patchedges_show = [0,0,0]
Esempio n. 17
0
    def fill_with_cmap(current_data):
        from clawpack.visclaw.colormaps import make_colormap
        import string
        x = current_data.x
        h = current_data.q[0, :]
        u = current_data.q[1, :] / h
        tracer = current_data.q[2, :]
        X = vstack((x, x))
        Y = vstack((0 * x, h))
        c = 0. * x
        i1 = array([mod(int(12 * tracer[i]), 2) for i in range(len(x))])
        c = where((i1 == 0) & (tracer > 0), 1, c)
        c = where((i1 == 0) & (tracer < 0), -1, c)
        c = where((i1 == 1) & (tracer < 0), -0.5, c)
        c = where((i1 == 1) & (tracer > 0), 0.5, c)
        cmin = -1.0
        cmax = 1.0
        cmid = 0.5 * (cmin + cmax)
        cmap = make_colormap({-1: [0.9,0.9,1.0], \
                              -0.001:[0.0,0.0,1.0], \
                               0.001:[1.0,0.4,0.4], \
                              1.0:[1.0,0.9,0.9]})
        cmap = make_colormap({
            cmin: [1.0, 0.0, 0.0],
            -0.5: [1., .8, .8],
            cmid: [.8, 1, 1.],
            cmax: [0., 0., 1]
        })

        C = vstack((c, c))
        pcolor(X, Y, C, cmap=cmap)
        outdir = current_data.plotdata.outdir
        frameno = string.zfill(current_data.frameno, 4)
        #plot_approx_Rsoln(current_data)
        ylim([0, 3.5])
        xticks(fontsize=20)
        yticks(fontsize=20)
        title("Depth and tracer at t = %6.3f" % current_data.t, fontsize=30)
Esempio n. 18
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_celledges_show = [0,0,0]
        plotitem.amr_patchedges_show = [1,1,1]
Esempio n. 19
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_celledges_show = [0, 0, 0]
        plotitem.amr_patchedges_show = [1, 1, 1]
Esempio n. 20
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_celledges_show = [0, 0, 0]
        plotitem.amr_patchedges_show = [1, 1, 1]
Esempio n. 21
0
def setplot(plotdata):
    #--------------------------
    """ 
    Specify what is to be plotted at each frame.
    Input:  plotdata, an instance of clawpack.visclaw.data.ClawPlotData.
    Output: a modified version of plotdata.
    
    """

    from clawpack.visclaw import colormaps

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

    # Plot outline of interface withut mapping
    def aa(current_data):
        from pylab import linspace, plot, annotate, text
        from pylab import title, xlabel, ylabel, xticks, yticks, colorbar
        # Plot interface
        rout = 0.015
        rinn = 0.010
        x = [-rout, -rout, rout, rout]
        y = [0.0, rout, rout, 0.0]
        plot(x, y, 'k', linewidth=4.0)
        # Chage title
        t = current_data.t
        tmicros = 1000000 * t
        title(r"Pressure at time t = %10.2f $\mu s$" % tmicros, fontsize=16)
        # Change axes
        xlabel(r"$cm$", fontsize='16')
        ylabel(r"$cm$", fontsize='16')
        # Change ticks on axes (WATCHOUT IF DOMAIN OF SIMULATION IS CHANGED)
        xxticks = np.arange(-0.05, 0.05, 0.00999)
        labelsx = range(xxticks.size)
        labelsx[:] = [x - 5 for x in labelsx]
        xticks(xxticks, labelsx)
        yyticks = np.arange(0.0, 0.03, 0.00999)
        labelsy = range(yyticks.size)
        labelsy[:] = [y for y in labelsy]
        yticks(yyticks, labelsy)

    # Plot outline of interface
    def aa1DPSIcm(current_data):
        from pylab import linspace, plot, annotate, text, xlabel, ylabel
        #gcs = 2.0/200.0
        x = [-1.5, -1.5, 1.5, 1.5]
        y = [-100, 100, 100, -100]
        #y[:] = [xx - gcs for xx in y]
        plot(x, y, 'k', linewidth=2.0)
        xlabel('cm', fontsize='16')
        ylabel('psi', fontsize='16')
        xcav = [-3.0, 3.0]
        ycav = [
            -14.334351113, -14.334351113
        ]  #Water vapour pressure for cavitation at room temp in 1atm=0 ref system
        plot(xcav, ycav, 'b--')
        #plot(-8.0, 180000, 'vk', markersize=10)
        #plot(-2.0, 180000, 'vk', markersize=10)
        #plot(0.0, 180000, 'vk', markersize=10)
        #plot(2.0, 180000, 'vk', markersize=10)
        text(-0.75, 27, 'Water', fontweight='bold', fontsize=20)
        #text(-0.8,285000,'PS',fontweight='bold',fontsize=20)
        text(-2.9, 27, 'Air', fontweight='bold', fontsize=20)
        text(1.6, 27, 'Air', fontweight='bold', fontsize=20)
        text(-1.45, -13, 'Vapor pressure', fontsize=15, color='blue')

    # Function to calculate pressure when using Tammann EOS
    def Pressure(current_data):
        q = current_data.q  # solution when this function called
        aux = current_data.aux
        gamma = aux[0, :, :]
        gamma1 = aux[0, :, :] - 1.0
        pinf = aux[1, :, :]
        omega = aux[2, :, :]
        rho = q[0, :, :]  # density
        momx = q[1, :, :]  # momentum x
        momy = q[2, :, :]  # momentum y
        ene = q[3, :, :]  # energy
        P = gamma1 * (ene - 0.5 * (momx * momx + momy * momy) / rho)
        P = P - gamma * pinf
        return P

    # Figure for Density
    # -------------------

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

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

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = 0
    plotitem.pcolor_cmap = colormaps.yellow_red_blue
    #plotitem.pcolor_cmin = 0.8
    #plotitem.pcolor_cmax = 3.0
    plotitem.add_colorbar = True
    plotitem.pcolor_cmin = 1.0
    plotitem.pcolor_cmax = 2.0
    plotitem.show = True  # show on plot?
    plotitem.MappedGrid = False

    plotaxes.afteraxes = aa

    # Figure for momentum x
    # -------------------

    plotfigure = plotdata.new_plotfigure(name='Momentum x', figno=1)

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

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = 1
    plotitem.pcolor_cmap = colormaps.yellow_red_blue
    plotitem.add_colorbar = True
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 160.0
    plotitem.show = True  # show on plot?
    plotitem.MappedGrid = False

    plotaxes.afteraxes = aa

    # Figure for momentum y
    # -------------------

    plotfigure = plotdata.new_plotfigure(name='Momentum y', figno=2)

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

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = 2
    plotitem.pcolor_cmap = colormaps.yellow_red_blue
    plotitem.add_colorbar = True
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 160.0
    plotitem.show = True  # show on plot?
    plotitem.MappedGrid = False

    plotaxes.afteraxes = aa

    # Figure for Energy
    # -------------------

    plotfigure = plotdata.new_plotfigure(name='Energy', figno=3)

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

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = 3
    plotitem.pcolor_cmap = colormaps.yellow_red_blue
    plotitem.add_colorbar = True
    plotitem.show = True  # show on plot?
    plotitem.pcolor_cmin = 200000
    plotitem.pcolor_cmax = 400000
    plotitem.MappedGrid = False

    plotaxes.afteraxes = aa

    # Figure for Pressure
    # -------------------
    plotfigure = plotdata.new_plotfigure(name='Pressure', figno=4)
    plotfigure.kwargs = {'figsize': [8, 3.7], 'tight_layout': True}
    #plotfigure.kwargs = {'figsize':[8,8], 'tight_layout':True} # For colorbar output

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

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.pcolor_cmin = 90000
    plotitem.pcolor_cmax = 230000
    #plotitem.pcolor_cmap = colormaps.white_blue
    #white_green_cmap = colormaps.make_colormap({0.:'w', 0.35: '#54ED96', 0.7: '#31BCBC', 1.:'#005F8B'}) #5CDAE3
    #white_green_cmap = colormaps.make_colormap({0.:'w', 0.35: '#60E9D0', 0.7: '#3174B7', 1.:'#0B357F'}) #5CDAE3
    white_green_cmap = colormaps.make_colormap({
        0.: 'w',
        0.35: '#AAFFEF',
        0.7: '#62B4E7',
        1.: '#4584F0'
    })
    plotitem.pcolor_cmap = white_green_cmap
    #plotitem.add_colorbar = True
    plotitem.plot_var = Pressure  # defined above
    #plotitem.plotstyle = '-o'
    #plotitem.color = 'r'
    # For AMR patches and cell edges (# REMEMBER TO CHANGE amr_contour_show TOO)
    plotitem.amr_patchedges_show = [0, 0, 0, 1]  #[0,0,0,0,1] #[0,0,0,0,0,1]
    plotitem.amr_celledges_show = [1, 1, 1, 0]  #[1,1,0,0,0] #[1,1,1,1,0,0]
    plotitem.MappedGrid = True
    plotitem.MappedGrid = False

    # Add contours as well
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.plot_var = Pressure
    plotitem.contour_levels = np.linspace(90000, 230000, 30)
    #plotitem.contour_nlevels = 10
    #plotitem.contour_min = 91000.0
    #plotitem.contour_max = 290000.0
    #plotitem.amr_patchedges_show = [0,0,1]
    #plotitem.amr_celledges_show = [1,1,0]
    plotitem.MappedGrid = False
    plotitem.show = True
    plotitem.amr_contour_colors = ['b', '#3C3C3C', 'k']
    plotitem.amr_contour_show = [0, 0, 0, 1]

    plotaxes.afteraxes = aa

    # Figure for Pressure (Schlieren)
    plotfigure = plotdata.new_plotfigure(name='Pressure schlieren', figno=9)
    plotfigure.kwargs = {'figsize': [8, 3.7], 'tight_layout': True}
    #plotfigure.kwargs = {'figsize':[8,8], 'tight_layout':True} # For colorbar output

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

    plotitem = plotaxes.new_plotitem(plot_type='2d_schlieren')
    plotitem.schlieren_cmin = 500  #2000 #500 #20
    plotitem.schlieren_cmax = 30000  #3500 #25000 #30000
    plotitem.add_colorbar = True
    plotitem.plot_var = Pressure  # defined above
    # For AMR
    plotitem.amr_patchedges_show = [0, 0, 0, 0, 1]
    plotitem.amr_celledges_show = [0, 0, 0, 0, 0]
    plotitem.MappedGrid = True
    plotitem.MappedGrid = False

    plotaxes.afteraxes = aa

    # Figure for Pressure slice
    # -------------------

    plotfigure = plotdata.new_plotfigure(name='Pressure slice', figno=6)
    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    # Axes for m vs Pa or cm vs PSI
    #plotaxes.xlimits = [-0.03,0.03] #[-3,3] #[-8.5,16] #'auto' -16
    #plotaxes.ylimits = [0.00000,300000]
    plotaxes.xlimits = [-3.0, 3.0]
    plotaxes.ylimits = [-20, 30]
    plotaxes.title = 'Pressure slice'
    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')

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

        ij = find((y <= dy / 2.) & (y > -dy / 2.))
        x_slice = ravel(x)[ij]
        gamma_slice = ravel(aux[0, :, :])[ij]
        pinf_slice = ravel(aux[1, :, :])[ij]
        rho_slice = ravel(q[0, :, :])[ij]
        momx_slice = ravel(q[1, :, :])[ij]
        momy_slice = ravel(q[2, :, :])[ij]
        ene_slice = ravel(q[3, :, :])[ij]
        P_slice = (gamma_slice -
                   1.0) * (ene_slice - 0.5 *
                           (momx_slice**2 + momy_slice**2) / rho_slice)
        P_slice = P_slice - gamma_slice * pinf_slice
        # Convert to Psi and centimeters
        P_slice = P_slice * 0.000145038 - 14.6959488
        x_slice = 100 * x_slice
        return x_slice, P_slice

    plotitem.map_2d_to_1d = xsec
    plotitem.plotstyle = '-kx'
    plotitem.kwargs = {'markersize': 3}

    plotaxes.afteraxes = aa1DPSIcm

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

    plotdata.printfigs = True  # print figures
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = [
        34, 70, 78, 86, 110, 143
    ]  # list of frames to print 'all' for all frames
    plotdata.print_fignos = [4]  #'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
Esempio n. 22
0
def setplot(plotdata):
    r"""Setplot function for surge plotting"""
    
    if plotdata is None:
        from clawpack.visclaw.data import ClawPlotData
        plotdata = ClawPlotData()


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

    fig_num_counter = surgeplot.figure_counter()

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

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

    # Calculate landfall time, off by a day, maybe leap year issue?
    landfall_dt = datetime.datetime(2008, 8, 1, 12) - datetime.datetime(2008,1,1,0)
    landfall = landfall_dt.days * 24.0 * 60**2 + landfall_dt.seconds

    # Set afteraxes function
    surge_afteraxes = lambda cd: surgeplot.surge_afteraxes(cd, 
                                        track, landfall, plot_direction=False)

    # Limits for plots
    full_xlimits = [clawdata.lower[0], clawdata.upper[0]]
    full_ylimits = [clawdata.lower[1], clawdata.upper[1]]

    # Color limits
    surface_range = 1.0
    speed_range = 2.0

    xlimits = full_xlimits
    ylimits = full_ylimits
    eta = physics.sea_level
    if not isinstance(eta,list):
        eta = [eta]
    surface_limits = [eta[0]-surface_range,eta[0]+surface_range]
    speed_limits = [0.0,speed_range]
    
    wind_limits = [0,55]
    pressure_limits = [966,1013]

    ref_lines = []


    # ==========================================================================
    #  Generic helper functions
    # ==========================================================================
    def pcolor_afteraxes(current_data):
        surge_afteraxes(current_data)
        # surgeplot.gauge_locations(current_data)
        
    def contour_afteraxes(current_data):
        surge_afteraxes(current_data)
        
    def bathy_ref_lines(current_data):
        pass
    #     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)

    
    # ==========================================================================
    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # ==========================================================================

    # ========================================================================
    #  Surface Elevations - Entire Domain
    # ========================================================================
    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

    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes,topo_min=-10.0,topo_max=5.0)


    # ========================================================================
    #  Water Speed - Entire Domain
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='speed', figno=1)
    plotfigure.show = True

    # 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
    surgeplot.add_speed(plotaxes,bounds=speed_limits)

    # Land
    surgeplot.add_land(plotaxes)


    # ========================================================================
    # Hurricane forcing - Entire Domain
    # ========================================================================
    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure', figno=2)
    plotfigure.show = surge_data.pressure_forcing
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    
    surgeplot.add_pressure(plotaxes,bounds=pressure_limits)
    # add_pressure(plotaxes)
    surgeplot.add_land(plotaxes)
    
    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed',figno=4)
    plotfigure.show = surge_data.wind_forcing
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    
    surgeplot.add_wind(plotaxes,bounds=wind_limits,plot_type='imshow')
    # add_wind(plotaxes,bounds=wind_limits,plot_type='contour')
    # add_wind(plotaxes,bounds=wind_limits,plot_type='quiver')
    surgeplot.add_land(plotaxes)
    
    # Wind field components
    plotfigure = plotdata.new_plotfigure(name='Wind Components',figno=5)
    plotfigure.show = surge_data.wind_forcing and False
    plotfigure.kwargs = {'figsize':(16,6)}
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(121)"
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "X-Component of Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = surgeplot.wind_x
    plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.imshow_cmin = -wind_limits[1]
    plotitem.imshow_cmax = wind_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1]
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(122)"
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Y-Component of Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = surgeplot.wind_y
    plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.imshow_cmin = -wind_limits[1]
    plotitem.imshow_cmax = wind_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1]

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    # plotaxes.xlimits = [0.0,amrdata.tfinal]
    # plotaxes.ylimits = [0,150.0]
    plotaxes.ylimits = surface_limits
    plotaxes.title = 'Surface'
    plotaxes.afteraxes = surgeplot.gauge_afteraxes

    # Plot surface as blue curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 3
    plotitem.plotstyle = 'r-'
    
    # =================
    #  Plot bathymetry
    # =================
    plotfigure = plotdata.new_plotfigure(name='Bathymetry', figno=301)
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Bathymetry"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type="2d_pcolor")
    plotitem.plot_var = geoplot.topo
    # plotitem.pcolor_cmap = geoplot.seafloor_colormap
    plotitem.pcolor_cmin = -3000.0
    plotitem.pcolor_cmax = 300.0
    plotitem.add_colorbar = True

    surgeplot.add_land(plotaxes)


    #-----------------------------------------
    # Figures for gauges
    #-----------------------------------------
    # plotfigure = plotdata.new_plotfigure(name='Surface & topo', figno=300, \
    #                 type='each_gauge')
    # plotfigure.clf_each_gauge = True
    # 
    # # Set up for axes in this figure:
    # plotaxes = plotfigure.new_plotaxes()
    # plotaxes.xlimits = 'auto'
    # plotaxes.ylimits = '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 = int(floor(t.max()/3600.) + 2)
    #     xticks([3600*i for i in range(n)])
    # 
    # plotaxes.afteraxes = add_zeroline


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

    plotdata.printfigs = True                # print figures
    plotdata.print_format = 'png'            # file format
    plotdata.print_framenos = 'all'          # list of frames to print
    # plotdata.print_framenos = [45,46,47,48]
    plotdata.print_gaugenos = 'all'          # list of gauges to print
    plotdata.print_fignos = 'all'            # list of figures to print
    plotdata.html = True                     # create html files of plots?
    plotdata.html_homelink = '../README.html'   # pointer for top of index
    plotdata.latex = True                    # create latex file of plots?
    plotdata.latex_figsperline = 2           # layout of plots
    plotdata.latex_framesperline = 1         # layout of plots
    plotdata.latex_makepdf = False           # also run pdflatex?

    return plotdata
Esempio n. 23
0
def plot_bathy(paths,
               region_path,
               patch_edges=True,
               patch_names=True,
               names=None,
               plot_coastline=True):
    r"""Plot the bathymetry files specified in paths and region_path."""

    # Setup region figure
    region_fig = plt.figure(1)
    region_axes = region_fig.add_subplot(111)

    # Setup patch figure
    patch_fig = plt.figure(2)
    columns = 3
    rows = np.ceil(len(paths) / float(columns))
    patch_axes = [
        patch_fig.add_subplot(rows, columns, i) for i in xrange(len(paths))
    ]

    # Read in region bathymetry
    X, Y, Z = bathy.read_topo(region_path)
    region_extent = (np.min(X), np.max(X), np.min(Y), np.max(Y))
    depth_extent = (np.min(Z), np.max(Z))

    # Create color map
    cmap = colormaps.make_colormap({
        -1: [0.3, 0.2, 0.1],
        -0.00001: [0.95, 0.9, 0.7],
        0.00001: [.5, .7, 0],
        1: [.2, .5, .2]
    })
    color_norm = colors.Normalize(depth_extent[0], depth_extent[1], clip=True)

    # Plot region data
    region_plot = region_axes.imshow(Z,
                                     vmin=depth_extent[0],
                                     vmax=depth_extent[1],
                                     extent=region_extent)  #,
    # cmap=cmap,norm=color_norm)

    if plot_coastline:
        region_axes.contour(X, Y, Z, levels=[0.0], colors='r')

    # Read in and plot each patch
    for (i, patch_path) in enumerate(paths):
        X, Y, Z = bathy.read_topo(patch_path)
        extent = (np.min(X), np.max(X), np.min(Y), np.max(Y))

        # Plot on region figure
        region_axes.imshow(Z,
                           vmin=depth_extent[0],
                           vmax=depth_extent[1],
                           extent=extent)  #,cmap=cmap,norm=color_norm)

        # Plot boundaries of local bathy on region plot
        if patch_edges:
            # Bottom boundary
            region_axes.plot((extent[0], extent[1]), (extent[2], extent[2]),
                             'k')
            # Upper boundary
            region_axes.plot((extent[0], extent[1]), (extent[3], extent[3]),
                             'k')
            # Left boundary
            region_axes.plot((extent[0], extent[0]), (extent[2], extent[3]),
                             'k')
            # Right boundary
            region_axes.plot((extent[1], extent[1]), (extent[2], extent[3]),
                             'k')

        # Write name near edge
        if names is None:
            file_name = os.path.splitext(patch_path)[0]
        else:
            file_name = names[i]
        if patch_names:
            delta = X[0, 0] - X[1, 0]
            region_axes.text(extent[0] + delta,
                             extent[2] + delta,
                             file_name,
                             color='m')

        # Plot on local bathy
        patch_axes[i].imshow(Z,
                             vmin=depth_extent[0],
                             vmax=depth_extent[1],
                             extent=extent)  #,cmap=cmap,norm=color_norm)
        patch_axes[i].contour(X, Y, Z, levels=[0.0], colors='r')
        patch_axes[i].set_title(file_name)
        patch_axes[i].set_xlim(extent[0:2])
        patch_axes[i].set_ylim(extent[2:])
        patch_axes[i].set_xlabel('longitude')
        patch_axes[i].set_ylabel('latitude')

        # Output extents
        print "Region %s: %s" % (file_name, extent)

    # Fix up figures
    region_axes.set_xlim(region_extent[0:2])
    region_axes.set_ylim(region_extent[2:])
    region_axes.set_title('Region')
    # region_fig.colorbar(region_plot)

    # patch_fig.colorbar(region_plot)

    return region_fig, patch_fig
Esempio n. 24
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,
Esempio n. 25
0
from __future__ import absolute_import
from __future__ import print_function
from six.moves import range

import os

import numpy
import matplotlib.pyplot as plt
import matplotlib.colors as colors

import clawpack.visclaw.colormaps as colormaps
import clawpack.clawutil.data as data
from clawpack.geoclaw import topotools
import clawpack.geoclaw.geoplot as geoplot

surface_cmap = colormaps.make_colormap({1.0: 'r', 0.5: 'w', 0.0: 'b'})
speed_cmap = plt.get_cmap('PuBu')
friction_cmap = plt.get_cmap('YlOrRd')
wind_cmap = plt.get_cmap('PuBu')
pressure_cmap = plt.get_cmap('PuBu')
land_cmap = geoplot.land_colors

# Contruct lake mask for plotting
init_region = [86.910814, 86.951576, 27.883193, 27.912485]
cutouts = []


def lake_mask(x, y):
    region = numpy.where((init_region[0] <= x) * (x <= init_region[1]) *
                         (init_region[2] <= y) * (y <= init_region[3]), True,
                         False)
Esempio n. 26
0
def setplot(plotdata=None):
    #--------------------------
    """ 
    Specify what is to be plotted at each frame.
    Input:  plotdata, an instance of pyclaw.plotters.data.ClawPlotData.
    Output: a modified version of plotdata.
    
    """

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

    from clawpack.visclaw import colormaps, geoplot

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

    plotdata.format = 'ascii'  # Format of output

    # plotdata.format = 'netcdf'

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

    plotdata.beforeframe = set_drytol

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

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

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

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

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

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.land
    plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 2.0
    plotitem.add_colorbar = False
    plotaxes.xlimits = [-1, 1]
    plotaxes.ylimits = [-1, 1]

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

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

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

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


    from clawpack.visclaw import colormaps
    from matplotlib import cm

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

    # Figure for density
    # -------------------

    plotfigure = plotdata.new_plotfigure(name='Density', figno=0)
    plotfigure.kwargs = {'figsize':(16,5)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'Density'
    plotaxes.scaled = True      # so aspect ratio is 1
    plotaxes.afteraxes = label_axes

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_schlieren')
    plotitem.schlieren_cmin = 0.0
    plotitem.schlieren_cmax = 1.0
    plotitem.plot_var = 0
    plotitem.add_colorbar = False
    plotitem.colorbar_shrink = 0.7
    plotitem.show = True       # show on plot?
    plotitem.amr_patchedges_show = [0]
    

    plotfigure = plotdata.new_plotfigure(name='Tracer', figno=1)
    plotfigure.kwargs = {'figsize':(16,5)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'Tracer'
    plotaxes.scaled = True      # so aspect ratio is 1

    def aa(current_data):
        label_axes(current_data)
        addgauges(current_data)
    plotaxes.afteraxes = aa

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.pcolor_cmin = 0.
    plotitem.pcolor_cmax=1.0
    plotitem.plot_var = 4
    plotitem.pcolor_cmap = colormaps.yellow_red_blue
    plotitem.add_colorbar = False
    plotitem.colorbar_shrink = 0.7
    plotitem.show = True       # show on plot?
    plotitem.amr_patchedges_show = [0]
    

    plotfigure = plotdata.new_plotfigure(name='Pressure', figno=2)
    plotfigure.kwargs = {'figsize':(16,5)}


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

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.pcolor_cmin = 1.
    plotitem.pcolor_cmax = 6.
    plotitem.plot_var = pressure
    cmap = colormaps.make_colormap({0.:'w', 0.5:'y', 0.8: 'b', 
                0.9:'#ffaaaa', 1.:'#ff0000'})
    plotitem.pcolor_cmap = cmap
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = 0.7
    plotitem.show = True       # show on plot?
    plotitem.amr_patchedges_show = [0]
    

    plotfigure = plotdata.new_plotfigure(name='u-velocity', figno=3)
    plotfigure.show = False
    plotfigure.kwargs = {'figsize':(16,5)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'u-velocity'
    plotaxes.scaled = True      # so aspect ratio is 1
    plotaxes.afteraxes = label_axes

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.pcolor_cmin = 1.
    plotitem.pcolor_cmax = 2.
    def u(current_data):
        q = current_data.q
        rho = q[0,:,:]
        u = q[1,:,:] / rho
        return u
    plotitem.plot_var = u
    #cmap = colormaps.make_colormap({0.:'w', 0.5:'y', 0.8: 'b', 
    #            0.9:'#ffaaaa', 1.:'#ff0000'})
    #plotitem.pcolor_cmap = cmap
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = 0.7
    plotitem.show = True       # show on plot?
    plotitem.amr_patchedges_show = [0]

    # Figure for grid cells
    plotfigure = plotdata.new_plotfigure(name='cells', figno=4)
    plotfigure.kwargs = {'figsize':(16,5)}


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

    # Set up for item on these axes:
    plotitem = plotaxes.new_plotitem(plot_type='2d_patch')
    linecolors, bgcolors = colormaps.make_amrcolors(nlevels=4)
    #plotitem.amr_patch_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee', 'w']
    plotitem.amr_patch_bgcolor = bgcolors
    plotitem.amr_patchedges_color = linecolors
    plotitem.amr_celledges_show = [1,0]
    plotitem.amr_patchedges_show = [1]



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

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(2,2,2)'
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'x-momentum'
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 1
    plotitem.plotstyle = 'b-'

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(2,2,3)'
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'Energy'
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 3
    plotitem.plotstyle = 'b-'

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(2,2,4)'
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'Tracer'
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 4
    plotitem.plotstyle = 'b-'




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

    plotdata.printfigs = True                # print figures
    plotdata.print_format = 'png'            # file format
    plotdata.print_framenos = 'all'          # list of frames to print
    plotdata.print_fignos = 'all'            # list of figures to print
    plotdata.html = True                     # create html files of plots?
    plotdata.html_homelink = '../README.html'   # 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
Esempio n. 28
0
def add_surface_elevation(plotaxes,
                          plot_type='pcolor',
                          bounds=None,
                          contours=None,
                          shrink=1.0):
    if plot_type == 'pcolor' or plot_type == 'imshow':
        plotitem = plotaxes.new_plotitem(name='surface', plot_type='2d_pcolor')
        plotitem.plot_var = geoplot.surface_or_depth

        if bounds is not None:
            if bounds[0] == 0.0:
                plotitem.pcolor_cmap = plt.get_cmap('OrRd')
            else:
                plotitem.pcolor_cmap = \
                              colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
            plotitem.pcolor_cmin = bounds[0]
            plotitem.pcolor_cmax = bounds[1]
        plotitem.add_colorbar = True
        plotitem.colorbar_shrink = shrink
        plotitem.colorbar_label = "Surface Height (m)"
        plotitem.amr_celledges_show = [0, 0, 0, 0, 0, 0, 0]
        plotitem.amr_patchedges_show = [1, 1, 1, 0, 0, 0, 0]

    elif plot_type == 'contour':
        plotitem = plotaxes.new_plotitem(name='surface',
                                         plot_type='2d_contour')
        if bounds is None:
            plotitem.contour_levels = [-2.5, -1.5, -0.5, 0.5, 1.5, 2.5]

        plotitem.plot_var = geoplot.surface_or_depth
        # plotitem.contour_nlevels = 21
        # plotitem.contour_min = -2.0
        # plotitem.contour_max = 2.0
        # plotitem.kwargs = {''}
        plotitem.amr_contour_show = [1, 1, 1, 1, 1, 1, 1]
        plotitem.amr_celledges_show = [0, 0, 0, 0, 0, 0, 0]
        plotitem.amr_patchedges_show = [1, 1, 1, 1, 0, 0, 0]
        plotitem.amr_contour_colors = 'k'
        # plotitem.amr_contour_colors = ['r','k','b']  # color on each level
        # plotitem.amr_grid_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']

    elif plot_type == 'contourf':
        plotitem = plotaxes.new_plotitem(name='surface',
                                         plot_type='2d_contourf')
        plotitem.plot_var = geoplot.surface_or_depth
        if bounds is not None:
            contours = numpy.linspace(bounds[0], bounds[1], 11)
            plotitem.contour_levels = contours
            plotitem.fill_cmin = bounds[0]
            plotitem.fill_cmax = bounds[1]
        elif contours is not None:
            plotitem.contour_levels = contours
            plotitem.fill_cmin = min(contours)
            plotitem.fill_cmax = max(contours)

        plotitem.add_colorbar = True
        plotitem.fill_cmap = geoplot.tsunami_colormap
        plotitem.colorbar_shrink = shrink
        plotitem.colorbar_label = "Surface Height (m)"
        plotitem.fill_cmap = plt.get_cmap('OrRd')
        if any((value < 0 for value in plotitem.contour_levels)):
            plotitem.fill_cmap = \
                            colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})

        plotitem.amr_contour_show = [1, 1, 1, 1, 1, 1, 1]
        plotitem.amr_celledges_show = [0, 0, 0, 0, 0, 0, 0]
        plotitem.amr_patchedges_show = [1, 1, 1, 1, 0, 0, 0]
        plotitem.amr_contour_colors = 'k'
Esempio n. 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 clawpack.visclaw import colormaps, geoplot
    from numpy import linspace

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


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

    def addgauges(current_data):
        from clawpack.visclaw import gaugetools
        gaugetools.plot_gauge_locations(current_data.plotdata, \
             gaugenos='all', format_string='ko', add_labels=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)
        pylab.ticklabel_format(format='plain',useOffset=False)
        mean_lat = 19.7
        pylab.gca().set_aspect(1.0 / pylab.cos(pylab.pi / 180.0 * mean_lat))
        #pylab.xticks(fontsize=15)
        #pylab.yticks(fontsize=15)


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

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

    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 = -0.2
    plotitem.imshow_cmax = 0.2
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.patchedges_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_celledges_show = [0,0,0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [135,210]
    plotaxes.ylimits = [9,53]

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


    #-----------------------------------------
    # Figure for zoom plot
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Hawaii', figno=20)
    #plotfigure.show = False

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

    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 = -0.2
    plotitem.imshow_cmax = 0.2
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.patchedges_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_celledges_show = [0,0,0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [200., 208.]
    plotaxes.ylimits = [17, 25]



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

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

    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 = -0.2
    plotitem.imshow_cmax = 0.2
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.patchedges_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_celledges_show = [0,0,0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [204.8, 205.]
    plotaxes.ylimits = [19.7, 19.9]


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

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

    plotaxes.afteraxes = fixup


    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    #plotitem.show = False
    # plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.imshow_cmap = geoplot.tsunami_colormap
    plotitem.imshow_cmin = -0.5
    plotitem.imshow_cmax = 0.5
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.patchedges_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_celledges_show = [0,0,0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [204.9, 204.96]
    plotaxes.ylimits = [19.72, 19.76]


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

    #-----------------------------------------
    # Figure for speed
    #-----------------------------------------

    plotfigure = plotdata.new_plotfigure(name='speed1', figno=4)
    plotfigure.show = False

    def speed(current_data):
        from numpy import ma, where, sqrt
        drytol = 1e-3
        q = current_data.q
        h = q[0,:,:]
        hu = q[1,:,:]
        hv = q[2,:,:]
        speed = where(h > drytol, sqrt(hu**2 + hv**2)/h**2, 0.)
        speed = ma.masked_where(h<=drytol, speed)
        return speed

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

    def fixup(current_data):
        import pylab
        #addgauges(current_data)
        t = current_data.t
        t = t / 3600.  # hours
        pylab.title('Speed at %4.2f hours' % t, fontsize=20)
        pylab.ticklabel_format(format='plain',useOffset=False)
        mean_lat = 19.7
        pylab.gca().set_aspect(1.0 / pylab.cos(pylab.pi / 180.0 * mean_lat))

    plotaxes.afteraxes = fixup

    # Water (contourf not working)
    plotitem = plotaxes.new_plotitem(plot_type='2d_contourf')
    plotitem.show = False
    plotitem.plot_var = speed
    clines = [0, 0.01, 0.02, 0.04, 0.06, 0.08, 0.1, 0.2]
    plotitem.contour_levels = clines
    from clawpack.geoclaw.geoplot import discrete_cmap_1
    plotitem.fill_colors = discrete_cmap_1(clines)
    plotitem.kwargs = {'extend':'max'}
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = 0
    plotitem.patchedges_show = 0

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = speed
    plotitem.imshow_cmap = geoplot.tsunami_colormap
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 0.3
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.patchedges_show = 0

    # 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 = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [204.9, 204.96]
    plotaxes.ylimits = [19.72, 19.76]


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

    #-----------------------------------------
    # Figure for velocity plot
    #-----------------------------------------
    
    plotfigure = plotdata.new_plotfigure(name='Speed', figno=10)
    #plotfigure.show = False

    # Set up for axes for velocity
    plotaxes = plotfigure.new_plotaxes()
    #plotaxes.axescmd = 'subplot(212)'
    plotaxes.title = 'Speed'
    plotaxes.scaled = True

    def fixup(current_data):
        import pylab
        addgauges(current_data)
        t = current_data.t
        t = t / 3600.  # hours
        pylab.title('Speed at %4.2f hours' % t, fontsize=20)
        pylab.ticklabel_format(format='plain',useOffset=False)
        mean_lat = 19.7
        pylab.gca().set_aspect(1.0 / pylab.cos(pylab.pi / 180.0 * mean_lat))
        pylab.xticks(rotation=20)
    plotaxes.afteraxes = fixup
    plotaxes.xlimits = [204.9, 204.96]
    plotaxes.ylimits = [19.72, 19.76]

    def speed(current_data):
        from pylab import where,sqrt
        q = current_data.q
        h = q[0,:,:]
        dry_tol = 0.001
        u = where(h>dry_tol, q[1,:,:]/h, 0.)
        v = where(h>dry_tol, q[2,:,:]/h, 0.)
        s = sqrt(u**2 + v**2)
        return s


    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = speed
    #plotitem.imshow_cmap = colormaps.white_red
    #plotitem.imshow_cmap = colormaps.yellow_red_blue
    plotitem.imshow_cmap = \
           colormaps.make_colormap({0:[1,1,1],0.5:[0.1,0.1,1],1:[1,0.1,0.1]})
    plotitem.imshow_cmin = 0.
    plotitem.imshow_cmax = 1.0
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = 0.6
    plotitem.amr_celledges_show = [0]
    plotitem.amr_patchedges_show = [0]


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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    #plotaxes.axescmd = 'subplot(2,1,1)'
    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 = 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, xlim,ylim
        t = current_data.t
        #legend(('surface','topography'),loc='lower left')
        plot(t, 0*t, 'k')
        n = int(floor(t.max()/1800.)) + 2
        xticks([1800*i for i in range(n)],[str(0.5*i) for i in range(n)])
        xlim(25000,t.max())
        #ylim(-0.5,0.5)
        print "+++ gaugeno = ",current_data.gaugeno

    #plotaxes.ylimits = [-0.5, 0.5]
    plotaxes.afteraxes = add_zeroline


    plotfigure = plotdata.new_plotfigure(name='Velocities', figno=301, \
                    type='each_gauge')
    plotfigure.clf_each_gauge = True

    plotaxes = plotfigure.new_plotaxes()
    #plotaxes.axescmd = 'subplot(2,1,2)'
    plotaxes.title = 'Velocities'
    #plotaxes.afteraxes = add_zeroline

    # Plot velocity as red curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.show = False
    def speed(current_data):
        from numpy import where, sqrt
        h = current_data.q[0,:]
        h = where(h>0.01, h, 1.e6)
        u = 100. * current_data.q[1,:] / h
        v = 100. * current_data.q[2,:] / h
        s = sqrt(u**2 + v**2)
        return s
    plotitem.plot_var = speed
    plotitem.plotstyle = 'k-'

    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    def uvel(current_data):
        from numpy import where, sqrt
        h = current_data.q[0,:]
        h = where(h>0.01, h, 1.e6)
        u = 100. * current_data.q[1,:] / h
        return u
    plotitem.plot_var = uvel
    plotitem.plotstyle = 'r-'
    plotitem.kwargs = {'linewidth':2}

    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    def vvel(current_data):
        from numpy import where, sqrt
        h = current_data.q[0,:]
        h = where(h>0.01, h, 1.e6)
        v = 100. * current_data.q[2,:] / h
        return v
    plotitem.plot_var = vvel
    plotitem.plotstyle = 'g-'
    plotitem.kwargs = {'linewidth':2}

    def add_legend(current_data):
        from pylab import legend
        legend(['u','v'],'upper left')
        #legend(['Speed','u','v'],'upper left')
        add_zeroline(current_data)
    plotaxes.ylimits = [-50,50]
    plotaxes.afteraxes = add_legend



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

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

    return plotdata
Esempio n. 30
0
def topo2kmz(topo,
             zlim=(-20, 20),
             mask_outside_zlim=True,
             sea_level=0.,
             name='topo',
             force_dry=None,
             close_figs=True):
    """
    Create kmz file showing onshore and offshore topography as separate layers.
    Currently not very flexible but is useful in quickly creating kmz files
    to open on Google Earth showing the onshore topography and offshore
    bathymetry as two separate layers.  Constant colors on rectangular grid
    cells should be properly rendered to ease exploration of DEMs.
    A colorbar png file is also created and included in the kmz file. 

    :Input:
     - *topo* should be a topotools.Topography object,
     - *zlim* is the elevation z limits for choosing the color map
     - *mask_outside_zlim* if True, suppress plotting outsize `zlim`
     - *sea_level* is the break between water and land colors
     - *name* is used in the kml menu and file name
     - *force_dry* is currently not used 
     - *close_figs* to close the pyplot figures after making png files

    :Future:
    If `force_dry` is an array of the same shape as `topo.Z` then another png
    and kml file are created for land that is below `sea_level` but where
    `force_dry = True`.

    """

    import os, glob
    import numpy
    from numpy import ma
    from clawpack.visclaw import colormaps
    import zipfile
    import matplotlib.pyplot as plt

    assert force_dry is None, 'force_dry not yet implemented'

    cmap_land = colormaps.make_colormap({
        0.0: [0.1, 0.4, 0.0],
        0.25: [0.0, 1.0, 0.0],
        0.5: [0.8, 1.0, 0.5],
        1.0: [0.8, 0.5, 0.2]
    })

    cmap_water = colormaps.make_colormap({0.0: [0, 0, 1], 1.: [.8, .8, 1]})

    cmap_topo, norm_topo = colormaps.add_colormaps(
        (cmap_land, cmap_water),
        data_limits=(zlim[0], zlim[1]),
        data_break=sea_level)

    cmap_force_dry = colormaps.make_colormap({
        0.0: [1.0, 0.7, 0.7],
        1.: [1.0, 0.7, 0.7]
    })
    cmap_dry, norm_dry = colormaps.add_colormaps(
        (cmap_land, cmap_force_dry),
        data_limits=(zlim[0], zlim[1]),
        data_break=sea_level)

    if mask_outside_zlim:
        Z = ma.masked_where(
            numpy.logical_or(topo.Z < zlim[0], topo.Z > zlim[1]), topo.Z)
        cbar_extend = 'neither'
    else:
        Z = topo.Z
        cbar_extend = 'both'

    kml_dir = 'kmlfiles_%s' % name
    os.system('mkdir -p %s' % kml_dir)
    print('Will put png and kml files in %s' % kml_dir)

    Z_land = ma.masked_where(Z < sea_level, Z)
    png_filename = '%s/%s_land.png' % (kml_dir, name)
    fig, ax, png_extent, kml_dpi = pcolorcells_for_kml(
        topo.X,
        topo.Y,
        Z_land,
        png_filename=png_filename,
        dpc=2,
        cmap=cmap_topo,
        norm=norm_topo)
    if close_figs:
        plt.close(fig)

    Z_water = ma.masked_where(Z >= sea_level, Z)
    png_filename = '%s/%s_water.png' % (kml_dir, name)
    fig, ax, png_extent, kml_dpi = pcolorcells_for_kml(
        topo.X,
        topo.Y,
        Z_water,
        png_filename=png_filename,
        dpc=2,
        cmap=cmap_topo,
        norm=norm_topo)

    if close_figs:
        plt.close(fig)

    kml_build_colorbar('%s/colorbar.png' % kml_dir,
                       cmap_topo,
                       cmin=zlim[0],
                       cmax=zlim[1],
                       label='meters',
                       title='topo',
                       extend=cbar_extend,
                       close_figs=close_figs)

    png_files = ['%s_water.png' % name, '%s_land.png' % name]
    png_names = ['%s_water' % name, '%s_land' % name]
    cb_files = ['colorbar.png']
    cb_names = ['colorbar_topo']

    name = '%s_topo' % name
    fname = os.path.join(kml_dir, name + '.kml')
    png2kml(png_extent,
            png_files=png_files,
            png_names=png_names,
            name=name,
            fname=fname,
            radio_style=False,
            cb_files=cb_files,
            cb_names=cb_names)

    savedir = os.getcwd()
    os.chdir(kml_dir)
    files = glob.glob('*.kml') + glob.glob('*.png')
    print('kmz file will include:')
    for file in files:
        print('    %s' % os.path.split(file)[-1])

    fname_kmz = 'topo_%s.kmz' % name
    with zipfile.ZipFile(fname_kmz, 'w') as zip:
        for file in files:
            zip.write(file)
        print('Created %s' % os.path.abspath(fname_kmz))
    os.chdir(savedir)
Esempio n. 31
0
def setplot(plotdata):
    r"""Setplot function for surge plotting"""

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

    # Load data from output
    amrdata = Data(os.path.join(plotdata.outdir, 'amr2ez.data'))
    physics = Data(os.path.join(plotdata.outdir, 'physics.data'))
    surge_data = Data(os.path.join(plotdata.outdir, 'surge.data'))

    # Limits for plots
    full_xlimits = [amrdata.xlower, amrdata.xupper]
    full_ylimits = [amrdata.ylower, amrdata.yupper]

    # Color limits
    surface_range = 1.0
    speed_range = 2.0

    xlimits = full_xlimits
    ylimits = full_ylimits
    eta = physics.eta_init
    if not isinstance(eta, list):
        eta = [eta]
    surface_limits = [eta[0] - surface_range, eta[0] + surface_range]
    speed_limits = [0.0, speed_range]

    # ==========================================================================
    # Gauge functions
    # ==========================================================================
    def gauge_locations(current_data, gaugenos='all'):
        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 (hours)')
        plt.ylabel('m')
        locs, labels = plt.xticks()
        labels = np.trunc(locs / 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)

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

    # ==========================================================================
    #  Generic helper functions
    # ==========================================================================
    def pcolor_afteraxes(current_data):
        surge_afteraxes(current_data)
        gauge_locations(current_data)

    def contour_afteraxes(current_data):
        surge_afteraxes(current_data)

    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 hours_figure_title(current_data):
        t = current_data.t / (60**2)
        title = current_data.plotaxes.title
        plt.title('%s at hour %3.2f' % (title, t))

    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)

    # ========================================================================
    #  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.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):
        return extract_velocity(cd.q[0, :, :], cd.q[1, :, :])

    def water_v(cd):
        return extract_velocity(cd.q[0, :, :], cd.q[2, :, :])

    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)

    # ========================================================================
    #  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_celledges_show = [0, 0, 0]
            plotitem.amr_patchedges_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_celledges_show = [0, 0, 0]
            plotitem.amr_patchedges_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_celledges_show = [0, 0, 0]
            plotitem.amr_patchedges_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_celledges_show = [0, 0, 0]
            plotitem.amr_patchedges_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_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_celledges_show = [0, 0, 0]
            plotitem.amr_patchedges_show = [1, 1, 1]
        elif plot_type == 'contour':
            plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
            plotitem.plot_var = wind_speed
            plotitem.contour_nlevels = len(surge_data.wind_refine)
            plotitem.countour_min = surge_data.wind_refine[0]
            plotitem.patchedges_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_pressure(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 = pressure
            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_celledges_show = [0, 0, 0]
            plotitem.amr_patchedges_show = [1]
        elif plot_type == 'contour':
            pass

    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_celledges_show = [0, 0, 0]
            plotitem.amr_patchedges_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_celledges_show = [0, 0, 0]
            plotitem.amr_patchedges_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_patch_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']
            plotitem.celledges_show = 0
            plotitem.patchedges_show = 0

    # ==========================================================================
    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # ==========================================================================

    # ========================================================================
    #  Surface Elevations - Entire Gulf
    # ========================================================================
    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 - Entire Gulf
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='speed', figno=1)
    plotfigure.show = True

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

    # ========================================================================
    # Hurricane forcing - Entire gulf
    # ========================================================================
    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure', figno=2)
    plotfigure.show = surge_data.pressure_forcing

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    add_pressure(plotaxes, bounds=pressure_limits)
    # add_pressure(plotaxes)
    add_land(plotaxes)

    # Pressure gradient
    dp = 1.0
    plotfigure = plotdata.new_plotfigure(name='Pressure Gradient', figno=3)
    plotfigure.show = surge_data.pressure_forcing
    plotfigure.kwargs = {'figsize': (16, 6)}

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(121)"
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "X-Component of Pressure Gradient"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = pressure_gradient_x
    plotitem.imshow_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.imshow_cmin = -dp
    plotitem.imshow_cmax = dp
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1]

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(122)"
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Y-Component of Pressure Gradient"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = pressure_gradient_y
    plotitem.imshow_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.imshow_cmin = -dp
    plotitem.imshow_cmax = dp
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1]

    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed', figno=4)
    plotfigure.show = surge_data.wind_forcing

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    add_wind(plotaxes, bounds=wind_limits, plot_type='imshow')
    # add_wind(plotaxes,bounds=wind_limits,plot_type='contour')
    # add_wind(plotaxes,bounds=wind_limits,plot_type='quiver')
    add_land(plotaxes)

    # Wind field components
    plotfigure = plotdata.new_plotfigure(name='Wind Components', figno=5)
    plotfigure.show = surge_data.wind_forcing
    plotfigure.kwargs = {'figsize': (16, 6)}

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(121)"
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "X-Component of Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = wind_x
    plotitem.imshow_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.imshow_cmin = -wind_limits[1]
    plotitem.imshow_cmax = wind_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1]

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(122)"
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Y-Component of Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = wind_y
    plotitem.imshow_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.imshow_cmin = -wind_limits[1]
    plotitem.imshow_cmax = wind_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1]

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    # plotaxes.xlimits = [0.0,amrdata.tfinal]
    # plotaxes.ylimits = [0,150.0]
    plotaxes.ylimits = surface_limits
    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-'

    #-----------------------------------------
    # Figures for gauges
    #-----------------------------------------
    # plotfigure = plotdata.new_plotfigure(name='Surface & topo', figno=300, \
    #                 type='each_gauge')
    # plotfigure.clf_each_gauge = True
    #
    # # Set up for axes in this figure:
    # plotaxes = plotfigure.new_plotaxes()
    # plotaxes.xlimits = 'auto'
    # plotaxes.ylimits = '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 = int(floor(t.max()/3600.) + 2)
    #     xticks([3600*i for i in range(n)])
    #
    # plotaxes.afteraxes = add_zeroline

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

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

    plotdata.printfigs = True  # print figures
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = 'all'  # list of frames to print
    # plotdata.print_framenos = [45,46,47,48]
    plotdata.print_gaugenos = 'all'  # list of gauges to print
    plotdata.print_fignos = 'all'  # list of figures to print
    plotdata.html = True  # create html files of plots?
    plotdata.html_homelink = '../README.html'  # pointer for top of index
    plotdata.latex = True  # create latex file of plots?
    plotdata.latex_figsperline = 2  # layout of plots
    plotdata.latex_framesperline = 1  # layout of plots
    plotdata.latex_makepdf = False  # also run pdflatex?

    return plotdata
Esempio n. 32
0
def setplot(plotdata):
    r"""Setplot function for surge plotting"""

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

    # Load data from output
    amrdata = Data(os.path.join(plotdata.outdir, 'amr2ez.data'))
    physics = Data(os.path.join(plotdata.outdir, 'physics.data'))
    surge_data = Data(os.path.join(plotdata.outdir, 'surge.data'))

    # Load storm track
    track = surge.plot.track_data(os.path.join(plotdata.outdir, 'fort.track'))
    surge_afteraxes = lambda cd: surge.plot.surge_afteraxes(cd, track)

    # Limits for plots
    full_xlimits = [-92.0, -45.0]
    full_ylimits = [13.0, 41.0]

    # Color limits
    surface_range = 1.0
    speed_range = 2.0

    xlimits = full_xlimits
    ylimits = full_ylimits
    eta = physics.eta_init
    if not isinstance(eta, list):
        eta = [eta]
    surface_limits = [eta[0] - surface_range, eta[0] + surface_range]
    speed_limits = [0.0, speed_range]

    wind_limits = [0, 55]
    pressure_limits = [966, 1013]
    vorticity_limits = [-1.e-2, 1.e-2]

    def pcolor_afteraxes(current_data):
        surge_afteraxes(current_data)
        surge.plot.gauge_locations(current_data)

    def contour_afteraxes(current_data):
        surge_afteraxes(current_data)

    # ==========================================================================
    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # ==========================================================================

    # ========================================================================
    #  Surface Elevations - Entire Atlantic
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface - Atlantic', 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

    surge.plot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surge.plot.add_land(plotaxes)

    # ========================================================================
    #  Water Speed - Entire Atlantic
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Currents - Atlantic', figno=1)
    plotfigure.show = True

    # 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
    surge.plot.add_speed(plotaxes, bounds=speed_limits)

    # Land
    surge.plot.add_land(plotaxes)

    # ========================================================================
    # Hurricane forcing - Entire Atlantic
    # ========================================================================
    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure', figno=2)
    plotfigure.show = surge_data.pressure_forcing

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surge.plot.add_pressure(plotaxes, bounds=pressure_limits)
    # surge.plot.add_pressure(plotaxes)
    surge.plot.add_land(plotaxes)

    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed', figno=3)
    plotfigure.show = surge_data.wind_forcing

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surge.plot.add_wind(plotaxes, bounds=wind_limits, plot_type='imshow')
    # surge.plot.add_wind(plotaxes,bounds=wind_limits,plot_type='contour')
    # surge.plot.add_wind(plotaxes,bounds=wind_limits,plot_type='quiver')
    surge.plot.add_land(plotaxes)

    # Wind field components
    plotfigure = plotdata.new_plotfigure(name='Wind Components', figno=4)
    plotfigure.show = surge_data.wind_forcing

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(121)"
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "X-Component of Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = surge.plot.wind_x
    plotitem.imshow_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.imshow_cmin = -wind_limits[1]
    plotitem.imshow_cmax = wind_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1]

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(122)"
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Y-Component of Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = surge.plot.wind_y
    plotitem.imshow_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.imshow_cmin = -wind_limits[1]
    plotitem.imshow_cmax = wind_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1]

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    try:
        plotaxes.xlimits = [amrdata.t0, amrdata.tfinal]
    except:
        pass
    plotaxes.ylimits = surface_limits
    plotaxes.title = 'Surface'
    plotaxes.afteraxes = surge.plot.gauge_afteraxes

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

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

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

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

    return plotdata
Esempio n. 33
0
def plot_bathy(bathy_file,coarse_factor=5,topo_type=3):
    r"""docstring for plot_bathy"""

    # Geometry
    num_cells = [0,0]
    x_range = [0.0,0.0]
    y_range = [0.0,0.0]
    delta = 0.0
    no_data_value = 0
    
    if abs(topo_type) == 1:
        # Load in data
        file_data = np.loadtxt(bathy_file)
        x = file_data[:,0]
        y = file_data[:,1]
        bathy = file_data[:,2]
        
        # Figure out extents of domain
        lower_corner = [np.min(x),np.min(y)]
    elif abs(topo_type) == 3:
        # Parse header
        bathy_file_handle = open(bathy_file,'r')
        num_cells[0] = int(bathy_file_handle.readline().split()[0])
        num_cells[1] = int(bathy_file_handle.readline().split()[0])
        x_range[0] = float(bathy_file_handle.readline().split()[0])
        y_range[0] = float(bathy_file_handle.readline().split()[0])
        delta = float(bathy_file_handle.readline().split()[0])
        no_data_value = int(bathy_file_handle.readline().split()[0])
            
        bathy_file_handle.close()
            
        # Calculate additional geometry
        x_range[1] = x_range[0] + num_cells[0] * delta
        y_range[1] = y_range[0] + num_cells[1] * delta
            
        # Load in bathymetry
        bathy = np.flipud(np.loadtxt(bathy_file,skiprows=6))
        X,Y = np.meshgrid(np.linspace(x_range[0],x_range[1],num_cells[0]),
                          np.linspace(y_range[0],y_range[1],num_cells[1]))

    else:
        raise NotImplemented("Topography type %s has not been implemented." % topo_type)
    if topo_type < 0:
        bathy = -bathy
    
    # Plot bathymetry
    fig = plt.figure()
    axes = fig.add_subplot(111)
    nan_array = np.nan * np.empty(bathy.shape)
    land = ma.masked_where(bathy > 0.0,nan_array)
    sea_floor = ma.masked_where(bathy <= 0.0,nan_array)
    max_elevation = np.max(bathy)
    max_depth = np.min(bathy)
    land_cmap = colormaps.make_colormap({0:[.5,.7,0],max_elevation:[.2,.5,.2]})
    sea_cmap = colormaps.make_colormap({max_depth:[0.3,0.2,0.1],0:[0.95,0.9,0.7]})
    
    plot = axes.pcolor(X[0:-1:coarse_factor,0:-1:coarse_factor],
                       Y[0:-1:coarse_factor,0:-1:coarse_factor],
                       land[0:-1:coarse_factor,0:-1:coarse_factor],
                       cmap=land_cmap,vmin=0.0,vmax=max_elevation)
    plot = axes.pcolor(X[0:-1:coarse_factor,0:-1:coarse_factor],
                       Y[0:-1:coarse_factor,0:-1:coarse_factor],
                       sea_floor[0:-1:coarse_factor,0:-1:coarse_factor],
                       cmap=sea_cmap,vmin=max_depth,vmax=0.0)
        
    axes.set_xlim(x_range)
    axes.set_ylim(y_range)
    axes.set_xlabel('Latitude')
    axes.set_ylabel('Longitude')
    
    fig.colorbar(plot)
    
    plt.show()
Esempio n. 34
0
def setplot(plotdata):
    r"""Setplot function for surge plotting"""
    

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

    # Load data from output
    amrdata = clawdata.AmrclawInputData(2)
    amrdata.read(os.path.join(plotdata.outdir,'amrclaw.data'))
    physics = clawdata.GeoclawInputData(2)
    physics.read(os.path.join(plotdata.outdir,'geoclaw.data'))
    surge_data = surge.data.SurgeData()
    surge_data.read(os.path.join(plotdata.outdir,'surge.data'))

    # Limits for plots
    full_xlimits = [amrdata.lower[0],amrdata.upper[0]]
    full_ylimits = [amrdata.lower[1],amrdata.upper[1]]

    # Color limits
    surface_range = 1.0
    speed_range = 1.0e-3

    xlimits = full_xlimits
    ylimits = full_ylimits
    eta = physics.sea_level
    if not isinstance(eta,list):
        eta = [eta]
    surface_limits = [eta[0]-surface_range,eta[0]+surface_range]
    speed_limits = [0.0,speed_range]
    # surface_limits = None
    # speed_limits = None
    
    wind_limits = [0,1]

    # ==========================================================================
    #  Generic helper functions
    # ==========================================================================
    def pcolor_afteraxes(current_data):
        surge_afteraxes(current_data)
        
    def contour_afteraxes(current_data):
        surge_afteraxes(current_data)


    # ========================================================================
    #  Surge related helper functions
    # ========================================================================
    def surge_afteraxes(current_data):
        surge.plot.days_figure_title(current_data)
        m_to_km_labels(current_data)


    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)

    
    # ==========================================================================
    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # ==========================================================================

    # ========================================================================
    #  Surface Elevations
    # ========================================================================
    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
    
    surge.plot.add_surface_elevation(plotaxes,bounds=surface_limits)
    surge.plot.add_land(plotaxes)


    # ========================================================================
    #  Water Speed
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='speed', figno=1)
    plotfigure.show = True

    # 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
    surge.plot.add_speed(plotaxes,bounds=speed_limits)

    # Land
    surge.plot.add_land(plotaxes)


    # ========================================================================
    # Wind field
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Wind Speed',figno=4)
    plotfigure.show = surge_data.wind_forcing
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    
    surge.plot.add_wind(plotaxes,bounds=wind_limits,plot_type='imshow')
    surge.plot.add_land(plotaxes)
    
    # Wind field components
    plotfigure = plotdata.new_plotfigure(name='Wind Components',figno=5)
    plotfigure.show = surge_data.wind_forcing
    plotfigure.kwargs = {'figsize':(16,6)}
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(121)"
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "X-Component of Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = surge.plot.wind_x
    plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.imshow_cmin = -wind_limits[1]
    plotitem.imshow_cmax = wind_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1]
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(122)"
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Y-Component of Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = surge.plot.wind_y
    plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.imshow_cmin = -wind_limits[1]
    plotitem.imshow_cmax = wind_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1]

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

    plotdata.printfigs = True                # print figures
    plotdata.print_format = 'png'            # file format
    plotdata.print_framenos = 'all'          # list of frames to print
    # plotdata.print_framenos = [45,46,47,48]
    plotdata.print_gaugenos = 'all'          # list of gauges to print
    plotdata.print_fignos = 'all'            # list of figures to print
    plotdata.html = True                     # create html files of plots?
    plotdata.html_homelink = '../README.html'   # pointer for top of index
    plotdata.latex = True                    # create latex file of plots?
    plotdata.latex_figsperline = 2           # layout of plots
    plotdata.latex_framesperline = 1         # layout of plots
    plotdata.latex_makepdf = False           # also run pdflatex?

    return plotdata
Esempio n. 35
0
import os,sys
from clawpack.visclaw import colormaps, plottools
from clawpack.geoclaw import fgmax_tools, topotools

#from clawpack.visclaw.plottools import pcolorcells # to appear in 5.7.0
from matplotlib.pyplot import pcolormesh as pcolorcells # for now


# In[3]:


zmin = -60.
zmax = 40.

land_cmap = colormaps.make_colormap({ 0.0:[0.1,0.4,0.0],
                                     0.25:[0.0,1.0,0.0],
                                      0.5:[0.8,1.0,0.5],
                                      1.0:[0.8,0.5,0.2]})

sea_cmap = colormaps.make_colormap({ 0.0:[0,0,1], 1.:[.8,.8,1]})

cmap, norm = colormaps.add_colormaps((land_cmap, sea_cmap),
                                     data_limits=(zmin,zmax),
                                     data_break=0.)
                                     
sea_cmap_dry = colormaps.make_colormap({ 0.0:[1.0,0.7,0.7], 1.:[1.0,0.7,0.7]})
cmap_dry, norm_dry = colormaps.add_colormaps((land_cmap, sea_cmap_dry),
                                     data_limits=(zmin,zmax),
                                     data_break=0.)


# ## Run script to generate topo files
Esempio n. 36
0
def setplot(plotdata):
    r"""Setplot function for surge plotting"""
    

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

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

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

    # Calculate landfall time, off by a day, maybe leap year issue?
    landfall_dt = datetime.datetime(2008, 8, 1, 12) - datetime.datetime(2008,1,1,0)
    landfall = landfall_dt.days * 24.0 * 60**2 + landfall_dt.seconds

    # Set afteraxes function
    surge_afteraxes = lambda cd: surge.surge_afteraxes(cd, 
                                        track, landfall, plot_direction=False)

    # Limits for plots
    full_xlimits = [amrdata.lower[0],amrdata.upper[0]]
    full_ylimits = [amrdata.lower[1],amrdata.upper[1]]

    # Color limits
    surface_range = 1.0
    speed_range = 2.0

    xlimits = full_xlimits
    ylimits = full_ylimits
    eta = physics.sea_level
    if not isinstance(eta,list):
        eta = [eta]
    surface_limits = [eta[0]-surface_range,eta[0]+surface_range]
    speed_limits = [0.0,speed_range]
    
    wind_limits = [0,55]
    pressure_limits = [966,1013]

    ref_lines = []


    # ==========================================================================
    #  Generic helper functions
    # ==========================================================================
    def pcolor_afteraxes(current_data):
        surge_afteraxes(current_data)
        surge.gauge_locations(current_data)
        
    def contour_afteraxes(current_data):
        surge_afteraxes(current_data)
        
    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)

    
    # ==========================================================================
    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # ==========================================================================

    # ========================================================================
    #  Surface Elevations - Entire Ocean
    # ========================================================================
    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
    
    surge.add_surface_elevation(plotaxes,bounds=surface_limits)
    surge.add_land(plotaxes)


    # ========================================================================
    #  Water Speed - Entire Gulf
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='speed', figno=1)
    plotfigure.show = True

    # 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
    surge.add_speed(plotaxes,bounds=speed_limits)

    # Land
    surge.add_land(plotaxes)


    # ========================================================================
    # Hurricane forcing - Entire gulf
    # ========================================================================
    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure', figno=2)
    plotfigure.show = surge_data.pressure_forcing
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    
    surge.add_pressure(plotaxes,bounds=pressure_limits)
    # add_pressure(plotaxes)
    surge.add_land(plotaxes)
    
    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed',figno=4)
    plotfigure.show = surge_data.wind_forcing
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    
    surge.add_wind(plotaxes,bounds=wind_limits,plot_type='imshow')
    # add_wind(plotaxes,bounds=wind_limits,plot_type='contour')
    # add_wind(plotaxes,bounds=wind_limits,plot_type='quiver')
    surge.add_land(plotaxes)
    
    # Wind field components
    plotfigure = plotdata.new_plotfigure(name='Wind Components',figno=5)
    plotfigure.show = surge_data.wind_forcing
    plotfigure.kwargs = {'figsize':(16,6)}
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(121)"
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "X-Component of Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = surge.wind_x
    plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.imshow_cmin = -wind_limits[1]
    plotitem.imshow_cmax = wind_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1]
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(122)"
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Y-Component of Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = surge.wind_y
    plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.imshow_cmin = -wind_limits[1]
    plotitem.imshow_cmax = wind_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1]

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    # plotaxes.xlimits = [0.0,amrdata.tfinal]
    # plotaxes.ylimits = [0,150.0]
    plotaxes.ylimits = surface_limits
    plotaxes.title = 'Surface'
    plotaxes.afteraxes = surge.gauge_afteraxes

    # Plot surface as blue curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 3
    plotitem.plotstyle = 'r-'
    
    # =================
    #  Plot bathymetry
    # =================
    plotfigure = plotdata.new_plotfigure(name='Bathymetry', figno=301)
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Bathymetry"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type="2d_pcolor")
    plotitem.plot_var = geoplot.topo
    # plotitem.pcolor_cmap = geoplot.seafloor_colormap
    plotitem.pcolor_cmin = topo_data.basin_depth
    plotitem.pcolor_cmax = 300.0
    plotitem.add_colorbar = True

    surge.add_land(plotaxes)


    #-----------------------------------------
    # Figures for gauges
    #-----------------------------------------
    # plotfigure = plotdata.new_plotfigure(name='Surface & topo', figno=300, \
    #                 type='each_gauge')
    # plotfigure.clf_each_gauge = True
    # 
    # # Set up for axes in this figure:
    # plotaxes = plotfigure.new_plotaxes()
    # plotaxes.xlimits = 'auto'
    # plotaxes.ylimits = '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 = int(floor(t.max()/3600.) + 2)
    #     xticks([3600*i for i in range(n)])
    # 
    # plotaxes.afteraxes = add_zeroline


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

    plotdata.printfigs = True                # print figures
    plotdata.print_format = 'png'            # file format
    plotdata.print_framenos = 'all'          # list of frames to print
    # plotdata.print_framenos = [45,46,47,48]
    plotdata.print_gaugenos = 'all'          # list of gauges to print
    plotdata.print_fignos = 'all'            # list of figures to print
    plotdata.html = True                     # create html files of plots?
    plotdata.html_homelink = '../README.html'   # pointer for top of index
    plotdata.latex = True                    # create latex file of plots?
    plotdata.latex_figsperline = 2           # layout of plots
    plotdata.latex_framesperline = 1         # layout of plots
    plotdata.latex_makepdf = False           # also run pdflatex?

    return plotdata
Esempio n. 37
0
def setplot(plotdata):
    r"""Setplot function for surge plotting"""
    

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

    fig_num_counter = surgeplot.figure_counter()

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

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

    # Calculate landfall time, off by a day, maybe leap year issue?
    landfall_dt = datetime.datetime(2008,9,13,7) - datetime.datetime(2008,1,1,0)
    landfall = (landfall_dt.days - 1.0) * 24.0 * 60**2 + landfall_dt.seconds

    # Set afteraxes function
    surge_afteraxes = lambda cd: surgeplot.surge_afteraxes(cd,
                                        track, landfall, plot_direction=False)

    # Color limits
    surface_range = 5.0
    speed_range = 3.0
    eta = physics.sea_level
    if not isinstance(eta,list):
        eta = [eta]
    surface_limits = [eta[0]-surface_range,eta[0]+surface_range]
    # surface_contours = numpy.linspace(-surface_range, surface_range,11)
    surface_contours = [-5,-4.5,-4,-3.5,-3,-2.5,-2,-1.5,-1,-0.5,0.5,1,1.5,2,2.5,3,3.5,4,4.5,5]
    surface_ticks = [-5,-4,-3,-2,-1,0,1,2,3,4,5]
    surface_labels = [str(value) for value in surface_ticks]
    speed_limits = [0.0,speed_range]
    speed_contours = numpy.linspace(0.0,speed_range,13)
    speed_ticks = [0,1,2,3]
    speed_labels = [str(value) for value in speed_ticks]
    
    wind_limits = [0,64]
    # wind_limits = [-0.002,0.002]
    pressure_limits = [935,1013]
    friction_bounds = [0.01,0.04]
    # vorticity_limits = [-1.e-2,1.e-2]

    # def pcolor_afteraxes(current_data):
    #     surge_afteraxes(current_data)
    #     surge.plot.gauge_locations(current_data,gaugenos=[6])
    
    def contour_afteraxes(current_data):
        surge_afteraxes(current_data)

    def add_custom_colorbar_ticks_to_axes(axes, item_name, ticks, tick_labels=None):
        axes.plotitem_dict[item_name].colorbar_ticks = ticks
        axes.plotitem_dict[item_name].colorbar_tick_labels = tick_labels

    # ==========================================================================
    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # ==========================================================================

    # ========================================================================
    #  Entire Gulf
    # ========================================================================
    gulf_xlimits = [clawdata.lower[0],clawdata.upper[0]]
    gulf_ylimits = [clawdata.lower[1],clawdata.upper[1]]
    gulf_shrink = 0.9
    def gulf_after_axes(cd):
        plt.subplots_adjust(left=0.08, bottom=0.04, right=0.97, top=0.96)
        surge_afteraxes(cd)
    #
    #  Surface
    #
    plotfigure = plotdata.new_plotfigure(name='Surface - Entire Domain', 
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.afteraxes = gulf_after_axes

    surgeplot.add_surface_elevation(plotaxes, plot_type='contourf',
                                               contours=surface_contours,
                                               shrink=gulf_shrink)
    surgeplot.add_land(plotaxes,topo_min=-10.0,topo_max=5.0)
    # surge.plot.add_bathy_contours(plotaxes)
    if article:
        plotaxes.plotitem_dict['surface'].add_colorbar = False
    else:
        add_custom_colorbar_ticks_to_axes(plotaxes, 'surface', surface_ticks, surface_labels)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [1,1,1,1,1,1,1,1]

    #
    #  Water Speed
    #
    plotfigure = plotdata.new_plotfigure(name='Currents - Entire Domain',  
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True

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

    # Speed
    surgeplot.add_speed(plotaxes, plot_type='contourf',
                                   contours=speed_contours,
                                   shrink=gulf_shrink)
    if article:
        plotaxes.plotitem_dict['speed'].add_colorbar = False
    else:
        add_custom_colorbar_ticks_to_axes(plotaxes, 'speed', speed_ticks, speed_labels)

    # Land
    surgeplot.add_land(plotaxes)
    surgeplot.add_bathy_contours(plotaxes)

    #
    # Friction field
    #
    plotfigure = plotdata.new_plotfigure(name='Friction',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = friction_data.variable_friction and True

    def friction_after_axes(cd):
        plt.subplots_adjust(left=0.08, bottom=0.04, right=0.97, top=0.96)
        plt.title(r"Manning's $n$ Coefficient")
        # surge_afteraxes(cd)

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    # plotaxes.title = "Manning's N Coefficient"
    plotaxes.afteraxes = friction_after_axes
    plotaxes.scaled = True

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


    # ========================================================================
    #  LaTex Shelf
    # ========================================================================
    latex_xlimits = [-97.5,-88.5]
    latex_ylimits = [27.5,30.5]
    latex_shrink = 1.0
    def latex_after_axes(cd):
        if article:
            plt.subplots_adjust(left=0.07, bottom=0.14, right=1.0, top=0.86)
        else:
            plt.subplots_adjust(right=1.0)
        surge_afteraxes(cd)

    #
    # Surface
    #
    plotfigure = plotdata.new_plotfigure(name='Surface - LaTex Shelf', 
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True
    if article:
        plotfigure.kwargs = {'figsize':(8,2.7), 'facecolor':'none'}
    else:
        plotfigure.kwargs = {'figsize':(9,2.7), 'facecolor':'none'}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = latex_xlimits
    plotaxes.ylimits = latex_ylimits
    plotaxes.afteraxes = latex_after_axes
    surgeplot.add_surface_elevation(plotaxes, plot_type='contourf',
                                               contours=surface_contours,
                                               shrink=latex_shrink)

    if article:
        plotaxes.plotitem_dict['surface'].add_colorbar = False
        # plotaxes.afteraxes = lambda cd: article_latex_after_axes(cd, landfall)
    else:
        add_custom_colorbar_ticks_to_axes(plotaxes, 'surface', [-5,-2.5,0,2.5,5.0], 
                                    ["-5.0","-2.5"," 0"," 2.5"," 5.0"])
    # plotaxes.plotitem_dict['surface'].contour_cmap = plt.get_cmap('OrRd')
    # surge.plot.add_surface_elevation(plotaxes,plot_type='contour')
    surgeplot.add_land(plotaxes)
    # plotaxes.plotitem_dict['surface'].amr_patchedges_show = [1,1,1,0,0,0,0]
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0,0,0,0,0,0,0]
    # plotaxes.plotitem_dict['land'].amr_patchedges_show = [1,1,1,0,0,0,0]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0,0,0,0,0,0,0]

    # Plot using jet and 0.0 to 5.0 to match figgen generated ADCIRC results
    # plotaxes.plotitem_dict['surface'].pcolor_cmin = 0.0
    # plotaxes.plotitem_dict['surface'].pcolor_cmax = 5.0
    # plotaxes.plotitem_dict['surface'].pcolor_cmap = plt.get_cmap('jet')

    #
    # Water Speed
    #
    plotfigure = plotdata.new_plotfigure(name='Currents - LaTex Shelf',  
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True
    if article:
        plotfigure.kwargs = {'figsize':(8,2.7), 'facecolor':'none'}
    else:
        plotfigure.kwargs = {'figsize':(9,2.7), 'facecolor':'none'}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Currents'
    plotaxes.scaled = True
    plotaxes.xlimits = latex_xlimits
    plotaxes.ylimits = latex_ylimits
    plotaxes.afteraxes = latex_after_axes
    surgeplot.add_speed(plotaxes, plot_type='contourf',
                                   contours=speed_contours,
                                   shrink=latex_shrink)

    if article:
        plotaxes.plotitem_dict['speed'].add_colorbar = False
    else:
        add_custom_colorbar_ticks_to_axes(plotaxes, 'speed', speed_ticks, speed_labels)
    # surge.plot.add_surface_elevation(plotaxes,plot_type='contour')
    surgeplot.add_land(plotaxes)
    # plotaxes.plotitem_dict['speed'].amr_patchedges_show = [1,1,0,0,0,0,0]
    # plotaxes.plotitem_dict['land'].amr_patchedges_show = [1,1,1,0,0,0,0]
    plotaxes.plotitem_dict['speed'].amr_patchedges_show = [0,0,0,0,0,0,0]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0,0,0,0,0,0,0]



    # ========================================================================
    #  Houston/Galveston
    # ========================================================================
    houston_xlimits = [-(95.0 + 26.0 / 60.0), -(94.0 + 25.0 / 60.0)]
    houston_ylimits = [29.1, 29.0 + 55.0 / 60.0]
    houston_shrink = 0.9
    def houston_after_axes(cd):
        if article:
            plt.subplots_adjust(left=0.05, bottom=0.07, right=0.99, top=0.92)
        else:
            plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        # surge.plot.gauge_locations(cd)
    
    #
    # Surface Elevations
    #
    plotfigure = plotdata.new_plotfigure(name='Surface - Houston/Galveston',  
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True
    # if article:
    #     plotfigure.kwargs['figsize'] = 

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = houston_xlimits
    plotaxes.ylimits = houston_ylimits
    plotaxes.afteraxes = houston_after_axes
    surgeplot.add_surface_elevation(plotaxes, plot_type='contourf',
                                               contours=surface_contours,
                                               shrink=houston_shrink)
    
    if article:
        plotaxes.plotitem_dict['surface'].add_colorbar = False
    else:
        add_custom_colorbar_ticks_to_axes(plotaxes, 'surface', surface_ticks, surface_labels)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0,0,0,0,0,0,0]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0,0,0,0,0,0,0]
    # surge.plot.add_bathy_contours(plotaxes)

    # Plot using jet and 0.0 to 5.0 to match figgen generated ADCIRC results
    # plotaxes.plotitem_dict['surface'].pcolor_cmin = 0.0
    # plotaxes.plotitem_dict['surface'].pcolor_cmax = 5.0
    # plotaxes.plotitem_dict['surface'].pcolor_cmap = plt.get_cmap('jet')

    #
    # Water Speed
    #
    plotfigure = plotdata.new_plotfigure(name='Currents - Houston/Galveston',  
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Currents'
    plotaxes.scaled = True
    plotaxes.xlimits = houston_xlimits
    plotaxes.ylimits = houston_ylimits
    plotaxes.afteraxes = houston_after_axes
    surgeplot.add_speed(plotaxes, plot_type='contourf',
                                   contours=speed_contours,
                                   shrink=houston_shrink)
    
    if article:
        plotaxes.plotitem_dict['speed'].add_colorbar = False
    else:
        add_custom_colorbar_ticks_to_axes(plotaxes, 'speed', speed_ticks, speed_labels)
    surgeplot.add_land(plotaxes)
    # surge.plot.add_bathy_contours(plotaxes)
    # plotaxes.plotitem_dict['speed'].amr_patchedges_show = [1,1,1,1,1,1,1,1]
    # plotaxes.plotitem_dict['land'].amr_patchedges_show = [1,1,1,1,1,1,1,1]
    plotaxes.plotitem_dict['speed'].amr_patchedges_show = [0,0,0,0,0,0,0]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0,0,0,0,0,0,0]

    # ==========================
    #  Hurricane Forcing fields
    # ==========================
    
    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure',  
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = surge_data.pressure_forcing and True
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = gulf_after_axes
    plotaxes.scaled = True
    surgeplot.add_pressure(plotaxes, bounds=pressure_limits, shrink=gulf_shrink)
    surgeplot.add_land(plotaxes)

    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed', 
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = surge_data.wind_forcing and True
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = gulf_after_axes
    plotaxes.scaled = True
    surgeplot.add_wind(plotaxes, bounds=wind_limits, plot_type='pcolor',
                                  shrink=gulf_shrink)
    surgeplot.add_land(plotaxes)

    # ========================================================================
    #  Figures for gauges
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface & topo', figno=300, \
                    type='each_gauge')
    plotfigure.show = True
    plotfigure.clf_each_gauge = True
    # plotfigure.kwargs['figsize'] = (16,10)

    def gauge_after_axes(cd):

        if cd.gaugeno in [1,2,3,4]:
            axes = plt.gca()
            # # Add Kennedy gauge data
            # kennedy_gauge = kennedy_gauges[gauge_name_trans[cd.gaugeno]]
            # axes.plot(kennedy_gauge['t'] - seconds2days(date2seconds(gauge_landfall[0])), 
            #          kennedy_gauge['mean_water'] + kennedy_gauge['depth'], 'k-', 
            #          label='Gauge Data')

            # Add GeoClaw gauge data
            geoclaw_gauge = cd.gaugesoln
            axes.plot(seconds2days(geoclaw_gauge.t - date2seconds(gauge_landfall[1])),
                  geoclaw_gauge.q[3,:] + gauge_surface_offset[0], 'b--', 
                  label="GeoClaw")

            # Add ADCIRC gauge data
            # ADCIRC_gauge = ADCIRC_gauges[kennedy_gauge['gauge_no']]
            # axes.plot(seconds2days(ADCIRC_gauge[:,0] - gauge_landfall[2]), 
            #          ADCIRC_gauge[:,1] + gauge_surface_offset[1], 'r-.', label="ADCIRC")

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

            plt.hold(False)

        # surge.plot.gauge_afteraxes(cd)


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

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

    # =====================
    #  Gauge Location Plot
    # =====================
    gauge_xlimits = [-95.5, -94]
    gauge_ylimits = [29.0, 30.0]
    gauge_location_shrink = 0.75
    def gauge_after_axes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        surgeplot.gauge_locations(cd, gaugenos=[1, 2, 3, 4])
        plt.title("Gauge Locations")

    plotfigure = plotdata.new_plotfigure(name='Gauge Locations',  
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = gauge_xlimits
    plotaxes.ylimits = gauge_ylimits
    plotaxes.afteraxes = gauge_after_axes
    surgeplot.add_surface_elevation(plotaxes, plot_type='contourf',
                                               contours=surface_contours,
                                               shrink=gauge_location_shrink)
    # surge.plot.add_surface_elevation(plotaxes, plot_type="contourf")
    add_custom_colorbar_ticks_to_axes(plotaxes, 'surface', surface_ticks, surface_labels)
    surgeplot.add_land(plotaxes)
    # plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0,0,0,0,0,0,0]
    # plotaxes.plotitem_dict['surface'].add_colorbar = False
    # plotaxes.plotitem_dict['surface'].pcolor_cmap = plt.get_cmap('jet')
    # plotaxes.plotitem_dict['surface'].pcolor_cmap = plt.get_cmap('gist_yarg')
    # plotaxes.plotitem_dict['surface'].pcolor_cmin = 0.0
    # plotaxes.plotitem_dict['surface'].pcolor_cmax = 5.0
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0,0,0,0,0,0,0]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0,0,0,0,0,0,0]
    
    # ==============================================================
    #  Debugging Plots, only really work if using interactive plots
    # ==============================================================
    #
    # Water Velocity Components
    #
    plotfigure = plotdata.new_plotfigure(name='Velocity Components - Entire Domain',  
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = False

    # X-Component
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(121)"
    plotaxes.title = 'Velocity, X-Component'
    plotaxes.scaled = True
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.afteraxes = gulf_after_axes

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surgeplot.water_u
    plotitem.pcolor_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.pcolor_cmin = -speed_limits[1]
    plotitem.pcolor_cmax = speed_limits[1]
    plotitem.colorbar_shrink = gulf_shrink
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1]

    surgeplot.add_land(plotaxes)

    # Y-Component
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(122)"
    plotaxes.title = 'Velocity, Y-Component'
    plotaxes.scaled = True
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.afteraxes = gulf_after_axes

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surgeplot.water_v
    plotitem.pcolor_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.pcolor_cmin = -speed_limits[1]
    plotitem.pcolor_cmax = speed_limits[1]
    plotitem.colorbar_shrink = gulf_shrink
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1]
    surgeplot.add_land(plotaxes)

    # 
    # Depth
    # 
    plotfigure = plotdata.new_plotfigure(name='Depth - Entire Domain', 
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'depth'
    plotaxes.scaled = True
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.afteraxes = gulf_after_axes

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = 0
    plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.imshow_cmin = 0
    plotitem.imshow_cmax = 100
    plotitem.colorbar_shrink = gulf_shrink
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1,1,1,1,1,1,1]
    
    # Surge field
    plotfigure = plotdata.new_plotfigure(name='Surge Field', 
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = ((surge_data.wind_forcing or surge_data.pressure_forcing) 
                        and False)
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.title = "Storm Surge Source Term S"
    plotaxes.afteraxes = gulf_after_axes
    plotaxes.scaled = True
    
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surgeplot.pressure_field + 1
    plotitem.pcolor_cmap = plt.get_cmap('PuBu')
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 1e-3
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = gulf_shrink
    plotitem.colorbar_label = "Source Strength"
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1,1,1,0,0]
    surgeplot.add_land(plotaxes)

    plotfigure = plotdata.new_plotfigure(name='Friction/Coriolis Source', 
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = False
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.title = "Friction/Coriolis Source"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surgeplot.pressure_field + 2
    plotitem.pcolor_cmap = plt.get_cmap('PuBu')
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 1e-3
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = gulf_shrink
    plotitem.colorbar_label = "Source Strength"
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1,1,1,0,0]
    surgeplot.add_land(plotaxes)

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

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

    if article:
        plotdata.printfigs = True                # print figures
        plotdata.print_format = 'png'            # file format
        plotdata.print_framenos = [54,60,66,72,78,84]            # list of frames to print
        plotdata.print_gaugenos = [1,2,3,4]          # list of gauges to print
        plotdata.print_fignos = [4,5,6,7,10,3,300]            # list of figures to print
        plotdata.html = True                     # create html files of plots?
        plotdata.html_homelink = '../README.html'   # pointer for top of index
        plotdata.latex = False                    # create latex file of plots?
        plotdata.latex_figsperline = 2           # layout of plots
        plotdata.latex_framesperline = 1         # layout of plots
        plotdata.latex_makepdf = False           # also run pdflatex?

    else:
        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,4]          # 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
Esempio n. 38
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.
    
    """

    amrdata = clawdata.ClawInputData(2)
    amrdata.read(os.path.join(plotdata.outdir, 'claw.data'))

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

        # # Square island
        # current_data.user['island_x'] = [-52e3, -52e3, 52e3, 52e3, -52e3]
        # current_data.user['island_y'] = [-52e3, 52e3, 52e3, -52e3, -52e3]

        # Strip island
        current_data.user['island_x'] = [-52e3, -52e3, 52e3, 52e3, -52e3]
        current_data.user['island_y'] = [-102e3, 102e3, 102e3, -102e3, -102e3]

    plotdata.beforeframe = set_drytol

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

    # surface_range = 1e-4
    # speed_max = 1.e-5

    surface_range = 1e-2
    speed_max = 1.e-2

    xlimits = [amrdata.lower[0], amrdata.upper[0]]
    ylimits = [amrdata.lower[1], amrdata.upper[1]]
    surface_limits = [-surface_range, surface_range]
    speed_limits = [0.0, speed_max]

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

    def after_axes(cd):
        surge.days_figure_title(cd)
        addgauges(cd)
        plt.plot(cd.user['island_x'], cd.user['island_y'], 'k--')

    def after_axes_slice(cd, y_bounds=[-1, 1]):
        surge.days_figure_title(cd)
        for x in cd.user['island_x']:
            plt.plot([x, x], y_bounds, 'k--')

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

    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits
    plotaxes.afteraxes = after_axes

    surge.add_surface_elevation(plotaxes, bounds=surface_limits)
    surge.add_land(plotaxes)
    # plotaxes.plotitem_dict['surface'].amr_celledges_show = [1,1,1,1]
    # plotaxes.plotitem_dict['land'].amr_celledges_show = [1,1,1,1]

    # Speed
    plotfigure = plotdata.new_plotfigure(name='Speed', figno=1)

    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.title = 'Currents'
    plotaxes.scaled = True
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits
    plotaxes.afteraxes = after_axes

    surge.add_speed(plotaxes, bounds=speed_limits)
    surge.add_land(plotaxes)
    # plotaxes.plotitem_dict['speed'].amr_celledges_show = [1,1,1,1]
    # plotaxes.plotitem_dict['land'].amr_celledges_show = [1,1,1,1]

    # ========================================================================
    #  Water Velocity Components - Entire Gulf
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(
        name='Velocity Components - Entire Domain', figno=2)
    plotfigure.kwargs['figsize'] = (16, 6)
    plotfigure.show = False

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

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surge.water_u
    plotitem.pcolor_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.pcolor_cmin = -speed_limits[1]
    plotitem.pcolor_cmax = speed_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [0, 0, 0]

    surge.add_land(plotaxes)

    # Y-Component
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(122)"
    plotaxes.title = 'Velocity, Y-Component'
    plotaxes.scaled = True
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits
    plotaxes.afteraxes = after_axes

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surge.water_v
    plotitem.pcolor_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.pcolor_cmin = -speed_limits[1]
    plotitem.pcolor_cmax = speed_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [0, 0, 0]

    surge.add_land(plotaxes)

    # ========================================================================
    #  Water Momenta Components
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(
        name='Momentum Components - Entire Domain', figno=3)
    plotfigure.kwargs['figsize'] = (16, 6)
    plotfigure.show = False

    # X-Component
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(121)"
    plotaxes.title = 'Momentum, X-Component'
    plotaxes.scaled = True
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits
    plotaxes.afteraxes = after_axes

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = 1
    plotitem.pcolor_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.pcolor_cmin = -speed_limits[1] * 100.0
    plotitem.pcolor_cmax = speed_limits[1] * 100.0
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [0, 0, 0]

    surge.add_land(plotaxes)

    # Y-Component
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(122)"
    plotaxes.title = 'Momentum, Y-Component'
    plotaxes.scaled = True
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits
    plotaxes.afteraxes = after_axes

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = 2
    plotitem.pcolor_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.pcolor_cmin = -speed_limits[1] * 100.0
    plotitem.pcolor_cmax = speed_limits[1] * 100.0
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [0, 0, 0]

    surge.add_land(plotaxes)

    # ============
    #  Topography
    # ============
    plotfigure = plotdata.new_plotfigure(name="Topography")
    plotfigure.show = False
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = "Topography"
    plotaxes.scaled = True
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.topo
    cmap = colormaps.make_colormap({
        -1: [0.3, 0.2, 0.1],
        -0.00001: [0.95, 0.9, 0.7],
        0.00001: [.5, .7, 0],
        1: [.2, .5, .2]
    })
    plotitem.pcolor_cmap = cmap
    plotitem.pcolor_cmin = -100.0
    plotitem.pcolor_cmax = 0.0
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [0, 0, 0]

    # =====================
    #  Slice through y = 0
    # =====================
    slice_index = 3

    def slice_surface(cd):
        return cd.x[:, slice_index], cd.q[3, :, slice_index]

    def slice_momentum(cd):
        return cd.x[:, slice_index], cd.q[1, :, slice_index]

    def slice_velocity(cd):
        u = cd.q[1, :, slice_index] / cd.q[0, :, slice_index]
        return cd.x[:, slice_index], u

    plotfigure = plotdata.new_plotfigure(name="Slice eta, y=0")
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = "Surface Slice y = 0"
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = surface_range
    plotaxes.afteraxes = lambda cd: after_axes_slice(cd, surface_limits)

    plotitem = plotaxes.new_plotitem(plot_type="1d_from_2d_data")
    plotitem.map_2d_to_1d = slice_surface
    plotitem.plot_var = 3
    plotitem.plotstyle = 'k-o'
    plotitem.show = True

    plotfigure = plotdata.new_plotfigure(name="Slice u, y=0")
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = "Velocity-x Slice y = 0"
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = [-speed_limits[1], speed_limits[1]]
    plotaxes.afteraxes = lambda cd: after_axes_slice(
        cd, [-speed_limits[1], speed_limits[1]])

    plotitem = plotaxes.new_plotitem(plot_type="1d_from_2d_data")
    plotitem.map_2d_to_1d = slice_velocity
    plotitem.plot_var = 1
    plotitem.plotstyle = 'k-o'
    plotitem.show = True

    plotfigure = plotdata.new_plotfigure(name="Slice hu, y=0")
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = "hu Slice y = 0"
    plotaxes.xlimits = xlimits
    momentum_limits = [-speed_limits[1] * 1000.0, speed_limits[1] * 1000.0]
    plotaxes.ylimits = momentum_limits
    plotaxes.afteraxes = lambda cd: after_axes_slice(cd, momentum_limits)

    plotitem = plotaxes.new_plotitem(plot_type="1d_from_2d_data")
    plotitem.map_2d_to_1d = slice_momentum
    plotitem.plot_var = 1
    plotitem.plotstyle = 'k-o'
    plotitem.show = True

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

    def gauge_afteraxes(cd, label=None):
        surge.gauge_afteraxes(cd)
        plt.ylabel(label)

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

    # Surface
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.afteraxes = lambda cd: gauge_afteraxes(cd,
                                                    label='Surface Height (m)')
    plotaxes.title = 'Surface'
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 3
    plotitem.plotstyle = 'b-'
    try:
        plotaxes.xlimits = [amrdata.t0, amrdata.tfinal]
    except:
        pass

    # Momenta
    plotfigure = plotdata.new_plotfigure(name='Gauge X-Momentum', figno=301, \
                    type='each_gauge')
    plotfigure.clf_each_gauge = True
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.afteraxes = lambda cd: gauge_afteraxes(
        cd, label=r'X-Momentum ($m/s^2$)')
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'X Momentum'
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.show = True
    plotitem.plot_var = 1
    try:
        plotaxes.xlimits = [amrdata.t0, amrdata.tfinal]
    except:
        pass

    plotfigure = plotdata.new_plotfigure(name='Gauge Y-Momentum', figno=302, \
                    type='each_gauge')
    plotfigure.clf_each_gauge = True
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.afteraxes = lambda cd: gauge_afteraxes(
        cd, label=r'Y-Momentum ($m/s^2$)')
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'Y Momentum'
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.show = True
    plotitem.plot_var = 2
    try:
        plotaxes.xlimits = [amrdata.t0, amrdata.tfinal]
    except:
        pass

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

    # 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 = range(0, 36, 4)  # list of frames to print
    plotdata.print_gaugenos = [1, 2, 3]  # list of gauges to print
    plotdata.print_fignos = 'all'  # list of figures to print
    plotdata.html = True  # create html files of plots?
    plotdata.html_homelink = '../README.html'  # pointer for top of index
    plotdata.latex = True  # create latex file of plots?
    plotdata.latex_figsperline = 2  # layout of plots
    plotdata.latex_framesperline = 1  # layout of plots
    plotdata.latex_makepdf = False  # also run pdflatex?
    plotdata.format = 'ascii'  # Format of output
    # plotdata.format = 'netcdf'

    return plotdata
Esempio n. 39
0
transparent = [0.0, 0.0, 0.0,0.0]
blue_a = [0.0,0.0,1.0,1.0];
red_a = [1.0,0.0,0.0,1.0]
light_green_a = [0.0,1.0,1.0,1.0];
white_a = [1.0,1.0,1.0,1.0]

#Colors taken from Google Earth
biscay = '#203469'   # Dark blue
lightblue = '#4E6498'


# Colormaps
TSUNAMI_MAX_AMPLITUDE = 0.6
googleearth_lightblue = colormaps.make_colormap({-TSUNAMI_MAX_AMPLITUDE:blue_a,
                                                 0.0:lightblue,
                                                 TSUNAMI_MAX_AMPLITUDE:red_a})

googleearth_darkblue = colormaps.make_colormap({-TSUNAMI_MAX_AMPLITUDE:blue_a,
                                                0.0:biscay,
                                                TSUNAMI_MAX_AMPLITUDE:red_a})


googleearth_white = colormaps.make_colormap({-TSUNAMI_MAX_AMPLITUDE:blue_a,
                                                0.0:white_a,
                                                TSUNAMI_MAX_AMPLITUDE:red_a})


googleearth_transparent = colormaps.make_colormap({-1.0:light_green_a,
                                                   0.0:transparent,
                                                   1.0:red_a})
Esempio n. 40
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 clawpack.visclaw import colormaps, geoplot

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

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

    plotdata.beforeframe = set_drytol

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

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

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

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

    cmap = colormaps.make_colormap({0:[0.5,1,0.5],0.01:[0,1,1], \
                                    0.2:[0,0,1], 0.5:[1,1,0],  0.8:[1,0,0], \
                                    1.:[0.2,0,0]})

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.imshow_cmap = cmap
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 0.2
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0]
    plotitem.amr_patchedges_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 = 0.3
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0]
    plotaxes.xlimits = [0,45]
    plotaxes.ylimits = [-14,14]

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

    #-----------------------------------------
    # Figure for zoom plot
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='zoom', figno=2)
    plotfigure.kwargs = {'figsize':(14,10)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('surface')
    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 = cmap
    plotitem.imshow_cmin = 0.
    plotitem.imshow_cmax = 0.2
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0]
    plotitem.amr_patchedges_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 = 0.3
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0]
    plotaxes.xlimits = [32,42]
    plotaxes.ylimits = [-6,3]

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

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

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

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

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

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


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

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

    def xsec_s(current_data):
        # Return x value and speed at this point, along y=0
        from pylab import find,ravel,where,sqrt
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q
        h = q[0,:]
        dry_tol = 0.001
        u = where(h>dry_tol, q[1,:]/h, 0.)
        v = where(h>dry_tol, q[2,:]/h, 0.)
        s = sqrt(u**2 + v**2)
        s = s / sqrt(9.81/0.97)  # so comparable to eta

        ij = find((y <= dy/2.) & (y > -dy/2.))
        x_slice = ravel(x)[ij]
        s_slice = ravel(s)[ij]
        return x_slice, s_slice

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

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

    def xsec_B(current_data):
        # Return x value and B at this point, along y=0
        from pylab import find,ravel,where,sqrt
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q
        h = q[0,:]
        eta = q[3,:]
        B = eta - h

        ij = find((y <= dy/2.) & (y > -dy/2.))
        x_slice = ravel(x)[ij]
        B_slice = ravel(B)[ij]
        return x_slice, B_slice

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


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

    plotfigure.clf_each_gauge = True

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

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

    # Plot speed as red curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    def speed(current_data):
        from pylab import where,sqrt
        q = current_data.q
        h = q[0,:]
        dry_tol = 0.001
        u = where(h>dry_tol, q[1,:]/h, 0.)
        v = where(h>dry_tol, q[2,:]/h, 0.)
        s = sqrt(u**2 + v**2)
        #s = s / sqrt(9.81/0.97)  # so comparable to eta
        s = s / 10.  # as in Figure 5 of paper
        return s

    plotitem.plot_var = speed
    plotitem.plotstyle = 'r-'

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

    plotaxes.afteraxes = add_zeroline


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

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

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

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

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

    return plotdata
Esempio n. 41
0
def plot_topo_file(topoplotdata):
    """
    Read in a topo or bathy file and produce a pcolor map.
    """

    deprecation_msg = "This function is being deprecated in favor of the " + \
                      "Topography class in clawpack.geoclaw.topotools and " + \
                      "plotting tools associated with it."
    warnings.filterwarnings('default', category=DeprecationWarning)
    warnings.warn(deprecation_msg, DeprecationWarning, stacklevel=2)
    warnings.resetwarnings()

    import os
    import pylab
    from clawpack.clawutil.data import ClawData

    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
    cmap = topoplotdata.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 cmap is None:
        cmap = colormaps.make_colormap({
            -1: [0.3, 0.2, 0.1],
            -0.00001: [0.95, 0.9, 0.7],
            0.00001: [.5, .7, 0],
            1: [.2, .5, .2]
        })
        #cmap = colormaps.make_colormap({-1:[0,0,1],0:[1,1,1],1:[1,0,0]})

    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)
        #pylab.clim([cmin,cmax])
        if addcolorbar:
            pylab.colorbar()
    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')

    patchedges_show = True
    if patchedges_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 = ClawData()
    topodata.x = x
    topodata.y = y
    topodata.topo = topo

    return topodata
Esempio n. 42
0
#!/usr/bin/env python

import sys
import os

import numpy
import matplotlib.pyplot as plt

import clawpack.geoclaw.topotools as topotools
import clawpack.visclaw.colormaps as colormaps

land_cmap = colormaps.make_colormap({
    0.0: [0.1, 0.4, 0.0],
    0.25: [0.0, 1.0, 0.0],
    0.5: [0.8, 1.0, 0.5],
    1.0: [0.8, 0.5, 0.2]
})

locations = {
    'imja': [{
        'path': 'ASTGTM2_everest_mosaic.tif',
        'out_path': 'everest.tt3',
        'strip_zeros': True,
        'contours': (4730, 4740, 5000),
        'limits': (4700, 4800)
    }],
    'barun': [{
        'path': 'ASTGTM2_everest_mosaic.tif',
        'out_path': 'everest.tt3',
        'strip_zeros': False,
        'contours': (4730, 4740, 5000),
Esempio n. 43
0

        
Esempio n. 44
0
def plot_topo_file(topoplotdata):
    """
    Read in a topo or bathy file and produce a pcolor map.
    """

    deprecation_msg = "This function is being deprecated in favor of the " + \
                      "Topography class in clawpack.geoclaw.topotools and " + \
                      "plotting tools associated with it."
    warnings.filterwarnings('default', category=DeprecationWarning)
    warnings.warn(deprecation_msg, DeprecationWarning, stacklevel=2)
    warnings.resetwarnings()

    import os
    import pylab
    from clawpack.clawutil.data import ClawData

    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
    cmap = topoplotdata.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 cmap is None:
        cmap = colormaps.make_colormap({-1:[0.3,0.2,0.1],
                                           -0.00001:[0.95,0.9,0.7],
                                           0.00001:[.5,.7,0],
                                           1:[.2,.5,.2]})
        #cmap = colormaps.make_colormap({-1:[0,0,1],0:[1,1,1],1:[1,0,0]})

    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)
            #pylab.clim([cmin,cmax])
            if addcolorbar:
                pylab.colorbar()
    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')

    patchedges_show = True
    if patchedges_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 = ClawData()
    topodata.x = x
    topodata.y = y
    topodata.topo = topo

    return topodata
Esempio n. 45
0
def plot_bathy(paths, region_path, patch_edges=True, patch_names=True, names=None, plot_coastline=True):
    r"""Plot the bathymetry files specified in paths and region_path."""

    # Setup region figure
    region_fig = plt.figure(1)
    region_axes = region_fig.add_subplot(111)

    # Setup patch figure
    patch_fig = plt.figure(2)
    columns = 3
    rows = np.ceil(len(paths) / float(columns))
    patch_axes = [patch_fig.add_subplot(rows, columns, i) for i in xrange(len(paths))]

    # Read in region bathymetry
    X, Y, Z = bathy.read_topo(region_path)
    region_extent = (np.min(X), np.max(X), np.min(Y), np.max(Y))
    depth_extent = (np.min(Z), np.max(Z))

    # Create color map
    cmap = colormaps.make_colormap(
        {-1: [0.3, 0.2, 0.1], -0.00001: [0.95, 0.9, 0.7], 0.00001: [0.5, 0.7, 0], 1: [0.2, 0.5, 0.2]}
    )
    color_norm = colors.Normalize(depth_extent[0], depth_extent[1], clip=True)

    # Plot region data
    region_plot = region_axes.imshow(Z, vmin=depth_extent[0], vmax=depth_extent[1], extent=region_extent)  # ,
    # cmap=cmap,norm=color_norm)

    if plot_coastline:
        region_axes.contour(X, Y, Z, levels=[0.0], colors="r")

    # Read in and plot each patch
    for (i, patch_path) in enumerate(paths):
        X, Y, Z = bathy.read_topo(patch_path)
        extent = (np.min(X), np.max(X), np.min(Y), np.max(Y))

        # Plot on region figure
        region_axes.imshow(Z, vmin=depth_extent[0], vmax=depth_extent[1], extent=extent)  # ,cmap=cmap,norm=color_norm)

        # Plot boundaries of local bathy on region plot
        if patch_edges:
            # Bottom boundary
            region_axes.plot((extent[0], extent[1]), (extent[2], extent[2]), "k")
            # Upper boundary
            region_axes.plot((extent[0], extent[1]), (extent[3], extent[3]), "k")
            # Left boundary
            region_axes.plot((extent[0], extent[0]), (extent[2], extent[3]), "k")
            # Right boundary
            region_axes.plot((extent[1], extent[1]), (extent[2], extent[3]), "k")

        # Write name near edge
        if names is None:
            file_name = os.path.splitext(patch_path)[0]
        else:
            file_name = names[i]
        if patch_names:
            delta = X[0, 0] - X[1, 0]
            region_axes.text(extent[0] + delta, extent[2] + delta, file_name, color="m")

        # Plot on local bathy
        patch_axes[i].imshow(
            Z, vmin=depth_extent[0], vmax=depth_extent[1], extent=extent
        )  # ,cmap=cmap,norm=color_norm)
        patch_axes[i].contour(X, Y, Z, levels=[0.0], colors="r")
        patch_axes[i].set_title(file_name)
        patch_axes[i].set_xlim(extent[0:2])
        patch_axes[i].set_ylim(extent[2:])
        patch_axes[i].set_xlabel("longitude")
        patch_axes[i].set_ylabel("latitude")

        # Output extents
        print "Region %s: %s" % (file_name, extent)

    # Fix up figures
    region_axes.set_xlim(region_extent[0:2])
    region_axes.set_ylim(region_extent[2:])
    region_axes.set_title("Region")
    # region_fig.colorbar(region_plot)

    # patch_fig.colorbar(region_plot)

    return region_fig, patch_fig
Esempio n. 46
0
transparent = [0.0, 0.0, 0.0, 0.0]
blue_a = [0.0, 0.0, 1.0, 1.0]
red_a = [1.0, 0.0, 0.0, 1.0]
light_green_a = [0.0, 1.0, 1.0, 1.0]
white_a = [1.0, 1.0, 1.0, 1.0]

#Colors taken from Google Earth
biscay = '#203469'  # Dark blue
lightblue = '#4E6498'

# Colormaps
TSUNAMI_MAX_AMPLITUDE = 0.6
googleearth_lightblue = colormaps.make_colormap({
    -TSUNAMI_MAX_AMPLITUDE: blue_a,
    0.0: lightblue,
    TSUNAMI_MAX_AMPLITUDE: red_a
})

googleearth_darkblue = colormaps.make_colormap({
    -TSUNAMI_MAX_AMPLITUDE: blue_a,
    0.0: biscay,
    TSUNAMI_MAX_AMPLITUDE: red_a
})

googleearth_white = colormaps.make_colormap({
    -TSUNAMI_MAX_AMPLITUDE: blue_a,
    0.0: white_a,
    TSUNAMI_MAX_AMPLITUDE: red_a
})
Esempio n. 47
0
def setplot(plotdata=None):
    #--------------------------
    """ 
    Specify what is to be plotted at each frame.
    Input:  plotdata, an instance of pyclaw.plotters.data.ClawPlotData.
    Output: a modified version of plotdata.
    
    """

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

    from clawpack.visclaw import colormaps, geoplot

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

    plotdata.format = 'ascii'  # Format of output

    print('Reading all gauges...')
    gauge_solutions = particle_tools.read_gauges(gaugenos='all',
                                                 outdir=plotdata.outdir)

    gaugenos_lagrangian = [k for k in gauge_solutions.keys() \
                if gauge_solutions[k].gtype=='lagrangian']
    gaugenos_stationary = [k for k in gauge_solutions.keys() \
                if gauge_solutions[k].gtype=='stationary']

    print('+++ gaugenos_lagrangian: ', gaugenos_lagrangian)

    def add_particles(current_data):
        t = current_data.t

        # plot recent path:
        t_path_length = 10.  # length of path trailing particle
        kwargs_plot_path = {'linewidth': 1, 'color': 'k'}
        particle_tools.plot_paths(gauge_solutions,
                                  t1=t - t_path_length,
                                  t2=t,
                                  gaugenos=gaugenos_lagrangian,
                                  kwargs_plot=kwargs_plot_path)

        # plot current location:
        kwargs_plot_point = {'marker': 'o', 'markersize': 3, 'color': 'k'}
        particle_tools.plot_particles(gauge_solutions,
                                      t,
                                      gaugenos=gaugenos_lagrangian,
                                      kwargs_plot=kwargs_plot_point)

        # plot any stationary gauges:
        gaugetools.plot_gauge_locations(current_data.plotdata, \
             gaugenos=gaugenos_stationary, format_string='kx', add_labels=False)
        kwargs = {'loc': 'upper left'}
        legend_tools.add_legend(['Lagrangian particle', 'Stationary gauge'],
                                linestyles=['', ''],
                                markers=['o', 'x'],
                                loc='lower right',
                                framealpha=0.5,
                                fontsize=10)

    def speed(current_data):
        from pylab import sqrt, where, zeros
        from numpy.ma import masked_where, allequal
        q = current_data.q
        h = q[0, :, :]
        hs = sqrt(q[1, :, :]**2 + q[2, :, :]**2)
        s = where(h > 1e-3, hs / h, 0.)
        s = masked_where(h < 1e-3, s)
        s = s * 1.94384  # convert to knots
        return s

    speed_cmap = colormaps.make_colormap({
        0: [0, 1, 1],
        0.5: [1, 1, 0],
        1: [1, 0, 0]
    })

    #-----------------------------------------
    # Figure for pcolor plot
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='pcolor', figno=0)
    plotfigure.kwargs = {'figsize': (9, 4)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.title = 'Speed'
    plotaxes.scaled = True
    plotaxes.xlimits = [0, 80]
    plotaxes.ylimits = [0, 50]
    plotaxes.afteraxes = add_particles

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.plot_var = geoplot.surface
    #plotitem.plot_var = geoplot.surface_or_depth
    plotitem.plot_var = speed
    #plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmap = speed_cmap

    plotitem.pcolor_cmin = 0.
    plotitem.pcolor_cmax = 20
    plotitem.add_colorbar = True
    plotitem.colorbar_label = 'knots'
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1]
    plotitem.amr_patchedges_color = ['m', 'g', 'w']

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.show = False
    plotitem.plot_var = geoplot.land
    plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0, 0, 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(-75, 75, 10)
    #plotitem.contour_nlevels = 10
    plotitem.amr_contour_colors = ['g']  # color on each level
    plotitem.kwargs = {'linestyles': 'solid'}
    plotitem.amr_contour_show = [1, 1, 1]  # show contours only on finest level
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0

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

    plotfigure.clf_each_gauge = True

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

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

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

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

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

    def add_zeroline(current_data):
        from pylab import plot, legend
        t = current_data.t
        legend(('surface', 'topography'), loc='lower left')
        plot(t, 0 * t, 'k')

    plotaxes.afteraxes = add_zeroline

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

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

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

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

    from clawpack.visclaw import colormaps, geoplot

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

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

    clim_ocean = 0.3
    clim_CC = 0.5

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

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

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

    def timeformat(t):
        from numpy import mod
        hours = int(t/3600.)
        tmin = mod(t,3600.)
        min = int(tmin/60.)
        sec = int(mod(tmin,60.))
        timestr = '%s:%s:%s' % (hours,str(min).zfill(2),str(sec).zfill(2))
        return timestr
        
    def title(current_data):
        from pylab import title
        title('Surface Height', fontsize = 28)
    
    def title_innerproduct(current_data):
        from pylab import title
        title('Inner Product', fontsize = 28)

    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': (11,5)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'axes([0.03,0.13,0.45,0.75])'
    plotaxes.title = 'Pacific'
    plotaxes.scaled = True

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, yticks
        plotcc(current_data)
        title(current_data)
        ticklabel_format(format='plain',useOffset=False)
        xticks([180, 200, 220, 240], rotation=20, fontsize = 28)
        yticks(fontsize = 28)
        a = gca()
        a.set_aspect(1./cos(41.75*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 = False
    plotitem.colorbar_shrink = 0.7
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [0]
    plotaxes.xlimits = [180,240] 
    plotaxes.ylimits = [10,62]

    # 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.celledges_show = 0
    plotitem.patchedges_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.celledges_show = 0
    plotitem.patchedges_show = 0

    # Adding inner product plot

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Inner Product'
    plotaxes.axescmd = 'axes([0.45,0.13,0.6,0.75])'
    plotaxes.scaled = True
    def aa_innerprod(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, yticks
        plotcc(current_data)
        title_innerproduct(current_data)
        ticklabel_format(format='plain',useOffset=False)
        xticks([180, 200, 220, 240], rotation=20, fontsize = 28)
        pylab.tick_params(axis='y', labelleft='off')
        a = gca()
        a.set_aspect(1./cos(41.75*pi/180.))
    plotaxes.afteraxes = aa_innerprod
    
    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = 4
    plotitem.imshow_cmap = colormaps.white_red
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 0.05
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [0]
    plotaxes.xlimits = [180,240]
    plotaxes.ylimits = [10,62]


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

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = cmin_ocean
    plotitem.imshow_cmax = cmax_ocean
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [0]
    plotaxes.xlimits = [235.5,236]
    plotaxes.ylimits = [41.6,41.8]
    plotaxes.afteraxes = addgauges

    # add contour lines of bathy if desired:
    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':'solid','linewidths':2}
    plotitem.amr_contour_show = [0,0,0,0,0,1]
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0

    #-----------------------------------------
    # Figures for gauges
    #-----------------------------------------
    
    def fix_gauge(current_data):
        from pylab import plot, legend, xticks, floor, yticks,xlabel,savefig, title
        t = current_data.t
        gaugeno = current_data.gaugeno
        xticks([18000, 21600, 25200, 28800, 32400, 36000],\
               [str(180/36), str(216/36), str(252/36), str(288/36), \
                str(324/36), str(360/36)], fontsize=17)
        yticks(fontsize=17)
        title('Surface at gauge ' + str(gaugeno), fontsize=17)
        xlabel(' ')

    plotfigure = plotdata.new_plotfigure(name='gauge plot', figno=300, \
                    type='each_gauge')
    plotfigure.kwargs = {'figsize': (10.5,5)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'axes([0.12,0.12,0.79,0.79])'
    plotaxes.title = 'Surface'
    plotaxes.xlimits = [15000, 39600]
    plotaxes.afteraxes = fix_gauge

    # Plot surface as blue curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 3
    plotitem.plotstyle = 'b-'
    
    # Uncomment these lines if you want to compare the adjoint-flagging
    # run with either of the two surface-flagging runs
    
    # Plot q[0] from previous run as red line:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 3
    plotitem.plotstyle = 'r-'
    plotitem.outdir = '../_output_sflag_14'
    
    # Plot q[0] from previous run as red line:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 3
    plotitem.plotstyle = 'g-'
    plotitem.outdir = '../_output_sflag_09'

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

    plotdata.printfigs = True                # print figures
    plotdata.print_format = 'png'            # file format
    plotdata.print_framenos = 'all'          # list of frames to print
    plotdata.print_fignos = 'all'            # list of figures to print
    plotdata.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?
    plotdata.html_movie = 'JSAnimation'      # new style, or "4.x" for old style


    return plotdata
Esempio n. 49
0
    def plot(self,
             axes=None,
             region_extent=None,
             contours=None,
             coastlines=True,
             limits=None,
             cmap=plt.get_cmap('terrain')):
        r"""
        Plot the topography
        """

        # Create axes if needed
        if axes is None:
            fig = plt.figure()
            axes = fig.add_subplot(111)

        # Turn off annoying offset
        axes.ticklabel_format(format="plain", useOffset=False)

        # Generate limits if need be
        if region_extent is None:
            region_extent = (numpy.min(self.X), numpy.max(self.X),
                             numpy.min(self.Y), numpy.max(self.Y))
        mean_lat = 0.5 * (region_extent[3] - region_extent[2])
        axes.set_aspect(1.0 / numpy.cos(numpy.pi / 180.0 * mean_lat))
        if limits is None:
            depth_extent = (numpy.min(self.Z), numpy.max(self.Z))
        else:
            depth_extent = limits

        # Create color map
        cmap = colormaps.make_colormap({
            -1: [0.3, 0.2, 0.1],
            -0.00001: [0.95, 0.9, 0.7],
            0.00001: [.5, .7, 0],
            1: [.2, .5, .2]
        })
        color_norm = colors.Normalize(depth_extent[0],
                                      depth_extent[1],
                                      clip=True)

        # Plot data
        if contours is not None:
            plot = axes.contourf(self.X, self.Y, self.Z, contours, cmap=cmap)
        elif isinstance(self.Z, numpy.ma.MaskedArray):
            plot = axes.pcolor(self.X,
                               self.Y,
                               self.Z,
                               vmin=depth_extent[0],
                               vmax=depth_extent[1],
                               cmap=cmap,
                               norm=color_norm)
        else:
            plot = axes.imshow(self.Z,
                               vmin=depth_extent[0],
                               vmax=depth_extent[1],
                               extent=region_extent,
                               cmap=cmap,
                               norm=color_norm)
        cbar = plt.colorbar(plot, ax=axes)
        cbar.set_label("Depth (m)")
        # levels = range(0,int(-numpy.min(Z)),500)

        # Plot coastlines
        if coastlines:
            axes.contour(self.X, self.Y, self.Z, levels=[0.0], colors='r')

        axes.set_xlim(region_extent[0:2])
        axes.set_ylim(region_extent[2:])

        return axes
Esempio n. 50
0
def add_surface_elevation(plotaxes, plot_type='pcolor', bounds=None, 
                                    contours=None, shrink=1.0):
    if plot_type == 'pcolor' or plot_type == 'imshow':            
        plotitem = plotaxes.new_plotitem(name='surface',plot_type='2d_pcolor')
        plotitem.plot_var = geoplot.surface_or_depth

        if bounds is not None:
            if bounds[0] == 0.0:
                plotitem.pcolor_cmap = plt.get_cmap('OrRd')
            else:
                plotitem.pcolor_cmap = \
                              colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
            plotitem.pcolor_cmin = bounds[0]
            plotitem.pcolor_cmax = bounds[1]
        plotitem.add_colorbar = True
        plotitem.colorbar_shrink = shrink
        plotitem.colorbar_label = "Surface Height (m)"
        plotitem.amr_celledges_show = [0,0,0,0,0,0,0]
        plotitem.amr_patchedges_show = [1,1,1,0,0,0,0]

    elif plot_type == 'contour':
        plotitem = plotaxes.new_plotitem(name='surface', plot_type='2d_contour')
        if bounds is None:
            plotitem.contour_levels = [-2.5,-1.5,-0.5,0.5,1.5,2.5]

        plotitem.plot_var = geoplot.surface
        # plotitem.contour_nlevels = 21
        # plotitem.contour_min = -2.0
        # plotitem.contour_max = 2.0
        # plotitem.kwargs = {''}
        plotitem.amr_contour_show = [1,1,1,1,1,1,1]
        plotitem.amr_celledges_show = [0,0,0,0,0,0,0]
        plotitem.amr_patchedges_show = [1,1,1,1,0,0,0]
        plotitem.amr_contour_colors = 'k'
        # plotitem.amr_contour_colors = ['r','k','b']  # color on each level
        # plotitem.amr_grid_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']

    elif plot_type == 'contourf':
        plotitem = plotaxes.new_plotitem(name='surface', plot_type='2d_contourf')
        plotitem.plot_var = geoplot.surface
        if bounds is not None:
            contours = numpy.linspace(bounds[0],bounds[1],11)
            plotitem.contour_levels = contours
            plotitem.fill_cmin = bounds[0]
            plotitem.fill_cmax = bounds[1]
        elif contours is not None:
            plotitem.contour_levels = contours
            plotitem.fill_cmin = min(contours)
            plotitem.fill_cmax = max(contours)

        plotitem.add_colorbar = True
        plotitem.fill_cmap = geoplot.tsunami_colormap
        plotitem.colorbar_shrink = shrink
        plotitem.colorbar_label = "Surface Height (m)"
        plotitem.fill_cmap = plt.get_cmap('OrRd')
        if any((value < 0 for value in plotitem.contour_levels)):
            plotitem.fill_cmap = \
                            colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})

        plotitem.amr_contour_show = [1,1,1,1,1,1,1]
        plotitem.amr_celledges_show = [0,0,0,0,0,0,0]
        plotitem.amr_patchedges_show = [1,1,1,1,0,0,0]
        plotitem.amr_contour_colors = 'k'
Esempio n. 51
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 clawpack.visclaw import colormaps
    from clawpack.geoclaw import geoplot

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

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


    clim_ocean = 0.5
    clim_CC = 0.5

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


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

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

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

    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 = False

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

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi
        #plotcc(current_data)
        title_hours(current_data)
        ticklabel_format(format='plain',useOffset=False)
        xticks(rotation=20)
        a = gca()
        a.set_aspect(1./cos(41.75*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 = -0.5
    plotitem.imshow_cmax = 0.5
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [0]
    #plotaxes.xlimits = [228,238] 
    #plotaxes.ylimits = [34,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.celledges_show = 0
    plotitem.patchedges_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.celledges_show = 0
    plotitem.patchedges_show = 0


    # =====

    plotfigure = plotdata.new_plotfigure(name='Tahiti', figno=20)
    #plotfigure.kwargs = {'figsize': (16,4)}
    #plotfigure.show = False

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

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi
        #plotcc(current_data)
        title_hours(current_data)
        ticklabel_format(format='plain',useOffset=False)
        xticks(rotation=20)
        a = gca()
        a.set_aspect(1./cos(41.75*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 = -0.5
    plotitem.imshow_cmax = 0.5
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [0]
    plotaxes.xlimits = [215.5,217.5] 
    plotaxes.ylimits = [-18,-15.5]
    #plotaxes.afteraxes = addgauges

    # =====
    # Transects:
    latitude = -16.65
    longitude = 216.42

    plotfigure = plotdata.new_plotfigure(name='x-transect', figno=41)
    #plotfigure.show = False
    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(211)'
    plotaxes.title = 'Transect in x at latitude y = %s' % latitude

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

    def slice_x(current_data):
        from pylab import find,ravel
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q
        ij = find((y <= latitude+dy/2.) & (y > latitude-dy/2.))
        x_slice = ravel(x)[ij]
        eta_slice = ravel(q[3,:,:])[ij]
        print "+++ min eta = ",eta_slice.min()
        return x_slice, eta_slice

    plotitem.map_2d_to_1d = slice_x

    def slice_xp(current_data):
        from pylab import find,ravel
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q
        ij = find((y <= latitude+dy+dy/2.) & (y > latitude+dy-dy/2.))
        x_slice = ravel(x)[ij]
        eta_slice = ravel(q[3,:,:])[ij]
        return x_slice, eta_slice

    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.map_2d_to_1d = slice_xp
    plotitem.color = 'r'


    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(212)'
    plotaxes.title = ''



    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.map_2d_to_1d = slice_x
    plotitem.plotstyle = 'bo'

    def B_x(current_data):
        from pylab import find,ravel
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q
        ij = find((y <= latitude+dy/2.) & (y > latitude-dy/2.))
        x_slice = ravel(x)[ij]
        eta_slice = ravel(q[3,:,:])[ij]
        h_slice = ravel(q[0,:,:])[ij]
        B_slice = eta_slice - h_slice
        return x_slice, B_slice

    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.map_2d_to_1d = B_x
    plotitem.color = 'g'

    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.map_2d_to_1d = slice_xp
    plotitem.color = 'r'

    def B_x(current_data):
        from pylab import find,ravel
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q
        ij = find((y <= latitude+dy+dy/2.) & (y > latitude+dy-dy/2.))
        x_slice = ravel(x)[ij]
        eta_slice = ravel(q[3,:,:])[ij]
        h_slice = ravel(q[0,:,:])[ij]
        B_slice = eta_slice - h_slice
        return x_slice, B_slice

    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.map_2d_to_1d = B_x
    plotitem.color = 'r'
        
    plotfigure = plotdata.new_plotfigure(name='y-transect', figno=22)
    #plotfigure.show = False
    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(211)'
    plotaxes.title = 'Transect in y at longitude x = %s' % longitude

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

    def slice_y(current_data):
        from pylab import find,ravel
        x = current_data.x
        y = current_data.y
        dx = current_data.dx
        q = current_data.q
        ij = find((x <= longitude+dx/2.) & (x > longitude-dx/2.))
        y_slice = ravel(y)[ij]
        eta_slice = ravel(q[3,:,:])[ij]
        return y_slice, eta_slice

    plotitem.map_2d_to_1d = slice_y

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(212)'
    plotaxes.title = ''
    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.map_2d_to_1d = slice_y
    plotitem.color = 'b'

    def B_y(current_data):
        from pylab import find,ravel
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q
        dx = current_data.dx
        q = current_data.q
        ij = find((x <= longitude+dx/2.) & (x > longitude-dx/2.))
        y_slice = ravel(y)[ij]
        eta_slice = ravel(q[3,:,:])[ij]
        h_slice = ravel(q[0,:,:])[ij]
        B_slice = eta_slice - h_slice
        return y_slice, B_slice

    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.map_2d_to_1d = B_y
    plotitem.color = 'g'
        
        
    plotfigure = plotdata.new_plotfigure(name='x-velocity', figno=23)
    #plotfigure.show = False
    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(211)'
    plotaxes.title = 'u in x at latitude y = %s' % latitude

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

    def slice_x(current_data):
        from pylab import find,ravel,where
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q
        ij = find((y <= latitude+dy/2.) & (y > latitude-dy/2.))
        x_slice = ravel(x)[ij]
        eta_slice = ravel(q[3,:,:])[ij]
        h_slice = ravel(q[0,:,:])[ij]
        hu_slice = ravel(q[1,:,:])[ij]
        u_slice = where(h_slice>0, hu_slice/h_slice, 0.)
        return x_slice, u_slice

    plotitem.map_2d_to_1d = slice_x

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(212)'
    plotaxes.title = 'hu'


    def slice_x(current_data):
        from pylab import find,ravel
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q
        ij = find((y <= latitude+dy/2.) & (y > latitude-dy/2.))
        x_slice = ravel(x)[ij]
        eta_slice = ravel(q[3,:,:])[ij]
        h_slice = ravel(q[0,:,:])[ij]
        hu_slice = ravel(q[1,:,:])[ij]
        return x_slice, hu_slice

    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.map_2d_to_1d = slice_x
    plotitem.color = 'b'
        

    plotfigure = plotdata.new_plotfigure(name='v-transect', figno=24)
    #plotfigure.show = False
    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(211)'
    plotaxes.title = 'v in y at longitude x = %s' % longitude

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

    def slice_y(current_data):
        from pylab import find,ravel,where
        x = current_data.x
        y = current_data.y
        dx = current_data.dx
        q = current_data.q
        ij = find((x <= longitude+dx/2.) & (x > longitude-dx/2.))
        y_slice = ravel(y)[ij]
        eta_slice = ravel(q[3,:,:])[ij]
        h_slice = ravel(q[0,:,:])[ij]
        hv_slice = ravel(q[2,:,:])[ij]
        v_slice = where(h_slice>0, hv_slice/h_slice, 0.)
        return y_slice, v_slice

    plotitem.map_2d_to_1d = slice_y

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(212)'
    plotaxes.title = 'hv'


    def slice_y(current_data):
        from pylab import find,ravel,where
        x = current_data.x
        y = current_data.y
        dx = current_data.dx
        q = current_data.q
        ij = find((x <= longitude+dx/2.) & (x > longitude-dx/2.))
        y_slice = ravel(y)[ij]
        eta_slice = ravel(q[3,:,:])[ij]
        h_slice = ravel(q[0,:,:])[ij]
        hv_slice = ravel(q[2,:,:])[ij]
        v_slice = where(h_slice>0, hv_slice/h_slice, 0.)
        return y_slice, hv_slice

        
    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    plotitem.map_2d_to_1d = slice_y
    plotitem.color = 'b'


    #-----------------------------------------
    # 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
    plotaxes.afteraxes = aa

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = cmin_ocean
    plotitem.imshow_cmax = cmax_ocean
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1]
    plotaxes.xlimits = [232,237] 
    plotaxes.ylimits = [39,44]
    plotaxes.afteraxes = aa

    
 
    #-----------------------------------------
    # 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
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = cmin_CC
    plotitem.imshow_cmax = cmax_CC
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1]
    plotaxes.xlimits = [235.76,235.84] 
    plotaxes.ylimits = [41.72,41.78]
    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi
        addgauges(current_data)
        title_hours(current_data)
        ticklabel_format(format='plain',useOffset=False)
        xticks(rotation=20)
        a = gca()
        a.set_aspect(1./cos(41.75*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,0,1]
    plotitem.celledges_show = 0
    plotitem.patchedges_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 = 'auto'
    plotaxes.title = 'Surface'

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


    def fix_gauge(current_data):
        from pylab import plot, legend, xticks, floor, yticks,xlabel,savefig
        t = current_data.t
        gaugeno = current_data.gaugeno
        n = int(floor(t.max()/1800.) + 2)
        xticks([1800*i for i in range(n)],[str(i/2.) for i in range(n)],\
          fontsize=15)
        yticks(fontsize=15)
        xlabel("Hours")

    #plotaxes.afteraxes = fix_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'  # range(0,50,2)
    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
Esempio n. 52
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
Esempio n. 53
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 clawpack.visclaw import colormaps, geoplot

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

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

    plotdata.beforeframe = set_drytol

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

    def addgauges(current_data):
        from clawpack.visclaw import gaugetools
        gaugetools.plot_gauge_locations(current_data.plotdata, \
             gaugenos='all', format_string='ko', add_labels=True, fontsize=8)
    
    #-----------------------------------------
    # Figure for imshow plot
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='surface', figno=0)
    plotfigure.kwargs = {'figsize':(14,10)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('surface')
    plotaxes.axescmd = 'subplot(311)'
    #plotaxes.axescmd = 'axes([.1,.7,.8,.2])'
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = [0,9.5]

    cmap = colormaps.make_colormap({0:[0.5,1,0.5],0.01:[0,1,1], \
                                    0.2:[0,0,1], 0.5:[1,1,0],  0.8:[1,0,0], \
                                    1.:[0.2,0,0]})

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.imshow_cmap = cmap
    plotitem.imshow_cmin = -0.003
    plotitem.imshow_cmax = 0.003
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = 0.6
    plotitem.amr_celledges_show = [0]
    plotitem.amr_patchedges_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 = [-0.05, -0.01]
    plotitem.amr_contour_colors = ['k']  # color on each level
    plotitem.kwargs = {'linestyles':'solid'}
    plotitem.amr_contour_show = [0,1]
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0
    plotitem.show = True

    #-----------------------------------------
    # Figure for cross section
    #-----------------------------------------
    #plotfigure = plotdata.new_plotfigure(name='cross-section', figno=1)
    #plotfigure.show = False
    #plotfigure.kwargs = {'figsize':(14,7)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(312)'
    plotaxes.xlimits = [0,12]
    plotaxes.ylimits = [-0.03,0.01]
    plotaxes.title = 'Cross section of surface at y=0.76'

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

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

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


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

    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')
    #plotitem.show = False

    def xsec_B(current_data):
        # Return x value and B at this point, along y=0
        from pylab import find,ravel,where,sqrt
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q
        h = q[0,:]
        eta = q[3,:]
        B = eta - h

        ij = find((y <= 0.76+dy/2.) & (y > 0.76-dy/2.))
        x_slice = ravel(x)[ij]
        B_slice = ravel(B)[ij]
        return x_slice, B_slice

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


    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(313)'
    plotaxes.xlimits = [0,12]
    plotaxes.ylimits = [-0.2,0.3]
    plotaxes.title = 'u-velocity'
    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')

    def xsec_s(current_data):
        # Return x value and speed at this point, along y=0
        from pylab import find,ravel,where,sqrt
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q
        h = q[0,:]
        dry_tol = 0.001
        u = where(h>dry_tol, q[1,:]/h, 0.)
        v = where(h>dry_tol, q[2,:]/h, 0.)
        #s = sqrt(u**2 + v**2)
        #s = s / sqrt(9.81/0.97)  # so comparable to eta

        ij = find((y <= 0.76+dy/2.) & (y > 0.76-dy/2.))
        x_slice = ravel(x)[ij]
        #s_slice = ravel(s)[ij]
        u_slice = ravel(u)[ij]
        return x_slice, u_slice

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


    plotaxes = plotfigure.new_plotaxes()
    plotaxes.show = False
    plotaxes.axescmd = 'subplot(414)'
    plotaxes.xlimits = [0,12]
    plotaxes.ylimits = [0.004,0.008]
    plotaxes.title = 'discharge'
    plotitem = plotaxes.new_plotitem(plot_type='1d_from_2d_data')

    def xsec_hu(current_data):
        # Return x value and discharge at this point, along y=0
        from pylab import find,ravel,where,sqrt
        x = current_data.x
        y = current_data.y
        dy = current_data.dy
        q = current_data.q
        hu = q[1,:]
        ij = find((y <= 0.76+dy/2.) & (y > 0.76-dy/2.))
        x_slice = ravel(x)[ij]
        hu_slice = ravel(hu)[ij]
        return x_slice, hu_slice

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






    #-----------------------------------------
    # Figure for quiver plot
    #-----------------------------------------

    plotfigure = plotdata.new_plotfigure(name='quiver', figno=8)
    plotfigure.show = False
    plotfigure.kwargs = {'figsize':(14,8)}

    def speed(current_data):
        from pylab import where,sqrt
        q = current_data.q
        h = q[0,:]
        dry_tol = 0.001
        u = where(h>dry_tol, q[1,:]/h, 0.)
        v = where(h>dry_tol, q[2,:]/h, 0.)
        s = sqrt(u**2 + v**2)
        return s

    def plot_quiver(current_data):
        from pylab import where,sqrt,quiver,contour
        if current_data.level < 2:
            return
        q = current_data.q
        x = current_data.x
        y = current_data.y
        h = q[0,:,:]
        dry_tol = 0.001
        u = where(h>dry_tol, q[1,:,:]/h, 0.) #  - 0.115 # for relative vel.
        v = where(h>dry_tol, q[2,:,:]/h, 0.)
        c = 8  # coarsening factor
        quiver(x[::c,::c],y[::c,::c],u[::c,::c],v[::c,::c],scale=10)
        B = q[3,:,:] - h
        contour(x,y,B,[-0.05,-0.01],colors='b',linestyles='solid',linewidths=2)
        #print "+++ B: ",B.min(), B.max()
        if h.min() < 0.003:
            print "+++ h.min: ",h.min()



    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Velocity'
    plotaxes.scaled = True
    plotaxes.xlimits = [4.5,7.5]

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = speed
    #plotitem.imshow_cmap = colormaps.white_red
    #plotitem.imshow_cmap = colormaps.yellow_red_blue
    plotitem.imshow_cmap = \
           colormaps.make_colormap({0:[1,1,1],0.5:[0.5,0.5,1],1:[1,0.3,0.3]})
    plotitem.imshow_cmin = 0.
    plotitem.imshow_cmax = 0.23
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0]
    plotitem.amr_patchedges_show = [0]
    plotitem.afterpatch = plot_quiver




    #-----------------------------------------
    # Figure for vorticity plot
    #-----------------------------------------

    plotfigure = plotdata.new_plotfigure(name='vorticity', figno=9)
    #plotfigure.show = False
    #plotfigure.kwargs = {'figsize':(16,6)}
    plotfigure.kwargs = {'figsize':(16,12)}


    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(211)'
    plotaxes.title = 'Vorticity'
    plotaxes.scaled = True
    plotaxes.xlimits = [4.5,9.5]

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = 4
    plotitem.imshow_cmap = colormaps.blue_white_red
    plotitem.imshow_cmin = -0.5
    plotitem.imshow_cmax = 0.5
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = 0.6
    plotitem.amr_celledges_show = [0]
    plotitem.amr_patchedges_show = [0]
    #plotitem.afterpatch = plot_quiver

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

    # Set up for axes for velocity
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(212)'
    plotaxes.title = 'Velocity'
    plotaxes.scaled = True
    plotaxes.xlimits = [4.5,9.5]

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = speed
    #plotitem.imshow_cmap = colormaps.white_red
    #plotitem.imshow_cmap = colormaps.yellow_red_blue
    plotitem.imshow_cmap = \
           colormaps.make_colormap({0:[1,1,1],0.5:[0.5,0.5,1],1:[1,0.3,0.3]})
    plotitem.imshow_cmin = 0.
    plotitem.imshow_cmax = 0.115 * 2
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = 0.6
    plotitem.amr_celledges_show = [0]
    plotitem.amr_patchedges_show = [0]
    plotitem.afterpatch = plot_quiver



    #-----------------------------------------
    # Figure for zoom plot
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='zoom', figno=2)
    plotfigure.show = False
    plotfigure.kwargs = {'figsize':(14,10)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('surface')
    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 = cmap
    plotitem.imshow_cmin = 0.
    plotitem.imshow_cmax = 0.2
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0]
    plotitem.amr_patchedges_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 = 0.3
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0]
    plotaxes.xlimits = [32,42]
    plotaxes.ylimits = [-6,3]

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



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

    def add_zeroline(current_data):
        from pylab import plot, legend
        t = current_data.t
        plot(t, 0*t, 'k')

    plotfigure = plotdata.new_plotfigure(name='Surface & topo', figno=300, \
                    type='each_gauge')

    plotfigure.kwargs = {'figsize':(14,9)}
    plotfigure.clf_each_gauge = True

    # Set up for axes in this figure:

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(3,1,1)'
    #plotaxes.ylimits = [-0.1, 0.2]
    plotaxes.title = 'Surface'
    plotaxes.afteraxes = add_zeroline

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

    # u-velocity
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(3,1,2)'
    #plotaxes.ylimits = [-0.1, 0.2]
    plotaxes.title = 'u-velocity'

    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    def u(current_data):
        from pylab import where,sqrt
        q = current_data.q
        h = q[0,:]
        dry_tol = 0.001
        u = where(h>dry_tol, q[1,:]/h, 0.)
        v = where(h>dry_tol, q[2,:]/h, 0.)
        return u

    plotitem.plot_var = u
    plotitem.plotstyle = 'b-'


    # v-velocity
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(3,1,3)'
    #plotaxes.ylimits = [-0.1, 0.2]
    plotaxes.title = 'v-velocity'

    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    def v(current_data):
        from pylab import where,sqrt
        q = current_data.q
        h = q[0,:]
        dry_tol = 0.001
        u = where(h>dry_tol, q[1,:]/h, 0.)
        v = where(h>dry_tol, q[2,:]/h, 0.)
        return v

    plotitem.plot_var = v
    plotitem.plotstyle = 'b-'


    plotaxes.afteraxes = add_zeroline


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

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

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

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

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

    return plotdata
Esempio n. 54
0
def setplot(plotdata):
    r"""Setplot function for surge plotting"""

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

    fig_num_counter = surge.figure_counter()

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

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

    # Calculate landfall time, off by a day, maybe leap year issue?
    landfall_dt = datetime.datetime(2008, 9, 13, 7) - datetime.datetime(
        2008, 1, 1, 0)
    landfall = (landfall_dt.days - 1.0) * 24.0 * 60**2 + landfall_dt.seconds

    # Set afteraxes function
    surge_afteraxes = lambda cd: surge.surge_afteraxes(
        cd, track, landfall, plot_direction=False)

    # Color limits
    surface_range = 5.0
    speed_range = 3.0
    eta = physics.sea_level
    if not isinstance(eta, list):
        eta = [eta]
    surface_limits = [eta[0] - surface_range, eta[0] + surface_range]
    # surface_contours = numpy.linspace(-surface_range, surface_range,11)
    surface_contours = [
        -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5, 0.5, 1, 1.5, 2, 2.5,
        3, 3.5, 4, 4.5, 5
    ]
    surface_ticks = [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
    surface_labels = [str(value) for value in surface_ticks]
    speed_limits = [0.0, speed_range]
    speed_contours = numpy.linspace(0.0, speed_range, 13)
    speed_ticks = [0, 1, 2, 3]
    speed_labels = [str(value) for value in speed_ticks]

    wind_limits = [0, 64]
    # wind_limits = [-0.002,0.002]
    pressure_limits = [935, 1013]
    friction_bounds = [0.01, 0.04]

    # vorticity_limits = [-1.e-2,1.e-2]

    # def pcolor_afteraxes(current_data):
    #     surge_afteraxes(current_data)
    #     surge.gauge_locations(current_data,gaugenos=[6])

    def contour_afteraxes(current_data):
        surge_afteraxes(current_data)

    def add_custom_colorbar_ticks_to_axes(axes,
                                          item_name,
                                          ticks,
                                          tick_labels=None):
        axes.plotitem_dict[item_name].colorbar_ticks = ticks
        axes.plotitem_dict[item_name].colorbar_tick_labels = tick_labels

    # ==========================================================================
    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # ==========================================================================

    # ========================================================================
    #  Entire Gulf
    # ========================================================================
    gulf_xlimits = [clawdata.lower[0], clawdata.upper[0]]
    gulf_ylimits = [clawdata.lower[1], clawdata.upper[1]]
    gulf_shrink = 0.9

    def gulf_after_axes(cd):
        if article:
            plt.subplots_adjust(left=0.08, bottom=0.04, right=0.97, top=0.96)
        else:
            plt.subplots_adjust(left=0.05, bottom=0.07, right=1.00, top=0.93)
        surge_afteraxes(cd)

    #
    #  Surface
    #
    plotfigure = plotdata.new_plotfigure(name='Surface - Entire Domain',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.afteraxes = gulf_after_axes

    surge.add_surface_elevation(plotaxes,
                                plot_type='contourf',
                                contours=surface_contours,
                                shrink=gulf_shrink)
    surge.add_land(plotaxes, topo_min=-10.0, topo_max=5.0)
    # surge.add_bathy_contours(plotaxes)
    if article:
        plotaxes.plotitem_dict['surface'].add_colorbar = False
    else:
        add_custom_colorbar_ticks_to_axes(plotaxes, 'surface', surface_ticks,
                                          surface_labels)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [
        1, 1, 1, 1, 1, 1, 1, 1
    ]

    #
    #  Water Speed
    #
    plotfigure = plotdata.new_plotfigure(name='Currents - Entire Domain',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True

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

    # Speed
    surge.add_speed(plotaxes,
                    plot_type='contourf',
                    contours=speed_contours,
                    shrink=gulf_shrink)
    if article:
        plotaxes.plotitem_dict['speed'].add_colorbar = False
    else:
        add_custom_colorbar_ticks_to_axes(plotaxes, 'speed', speed_ticks,
                                          speed_labels)

    # Land
    surge.add_land(plotaxes)
    surge.add_bathy_contours(plotaxes)

    #
    # Friction field
    #
    plotfigure = plotdata.new_plotfigure(name='Friction',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = friction_data.variable_friction and True

    def friction_after_axes(cd):
        plt.subplots_adjust(left=0.08, bottom=0.04, right=0.97, top=0.96)
        plt.title(r"Manning's $n$ Coefficient")
        # surge_afteraxes(cd)

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    # plotaxes.title = "Manning's N Coefficient"
    plotaxes.afteraxes = friction_after_axes
    plotaxes.scaled = True

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

    # ========================================================================
    #  LaTex Shelf
    # ========================================================================
    latex_xlimits = [-97.5, -88.5]
    latex_ylimits = [27.5, 30.5]
    latex_shrink = 1.0

    def latex_after_axes(cd):
        if article:
            plt.subplots_adjust(left=0.07, bottom=0.14, right=1.0, top=0.86)
        # else:
        # plt.subplots_adjust(right=1.0)
        surge_afteraxes(cd)

    #
    # Surface
    #
    plotfigure = plotdata.new_plotfigure(name='Surface - LaTex Shelf',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True
    if article:
        plotfigure.kwargs = {'figsize': (8, 2.7)}  #, 'facecolor':'none'}
    else:
        plotfigure.kwargs = {'figsize': (9, 2.7)}  #, 'facecolor':'none'}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = latex_xlimits
    plotaxes.ylimits = latex_ylimits
    plotaxes.afteraxes = latex_after_axes

    surge.add_surface_elevation(plotaxes,
                                plot_type='contourf',
                                contours=surface_contours,
                                shrink=latex_shrink)

    if article:
        plotaxes.plotitem_dict['surface'].add_colorbar = False
        # plotaxes.afteraxes = lambda cd: article_latex_after_axes(cd, landfall)
    else:
        add_custom_colorbar_ticks_to_axes(
            plotaxes, 'surface', [-5, -2.5, 0, 2.5, 5.0],
            ["-5.0", "-2.5", " 0", " 2.5", " 5.0"])
    # plotaxes.plotitem_dict['surface'].contour_cmap = plt.get_cmap('OrRd')
    # surge.add_surface_elevation(plotaxes,plot_type='contour')
    surge.add_land(plotaxes)
    # plotaxes.plotitem_dict['surface'].amr_patchedges_show = [1,1,1,0,0,0,0]
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [
        0, 0, 0, 0, 0, 0, 0
    ]
    # plotaxes.plotitem_dict['land'].amr_patchedges_show = [1,1,1,0,0,0,0]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0, 0, 0, 0, 0, 0, 0]

    # Plot using jet and 0.0 to 5.0 to match figgen generated ADCIRC results
    # plotaxes.plotitem_dict['surface'].pcolor_cmin = 0.0
    # plotaxes.plotitem_dict['surface'].pcolor_cmax = 5.0
    # plotaxes.plotitem_dict['surface'].pcolor_cmap = plt.get_cmap('jet')

    #
    # Water Speed
    #
    plotfigure = plotdata.new_plotfigure(name='Currents - LaTex Shelf',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True
    if article:
        plotfigure.kwargs = {'figsize': (8, 2.7)}  #, 'facecolor':'none'}
    else:
        plotfigure.kwargs = {'figsize': (9, 2.7)}  #, 'facecolor':'none'}

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

    surge.add_speed(plotaxes,
                    plot_type='contourf',
                    contours=speed_contours,
                    shrink=latex_shrink)

    if article:
        plotaxes.plotitem_dict['speed'].add_colorbar = False
    else:
        add_custom_colorbar_ticks_to_axes(plotaxes, 'speed', speed_ticks,
                                          speed_labels)
    # surge.add_surface_elevation(plotaxes,plot_type='contour')
    surge.add_land(plotaxes)
    # plotaxes.plotitem_dict['speed'].amr_patchedges_show = [1,1,0,0,0,0,0]
    # plotaxes.plotitem_dict['land'].amr_patchedges_show = [1,1,1,0,0,0,0]
    plotaxes.plotitem_dict['speed'].amr_patchedges_show = [0, 0, 0, 0, 0, 0, 0]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0, 0, 0, 0, 0, 0, 0]

    # ========================================================================
    #  Houston/Galveston
    # ========================================================================
    houston_xlimits = [-(95.0 + 26.0 / 60.0), -(94.0 + 25.0 / 60.0)]
    houston_ylimits = [29.1, 29.0 + 55.0 / 60.0]
    houston_shrink = 0.9

    def houston_after_axes(cd):
        if article:
            plt.subplots_adjust(left=0.05, bottom=0.07, right=0.99, top=0.92)
        else:
            plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        # surge.gauge_locations(cd)

    #
    # Surface Elevations
    #
    plotfigure = plotdata.new_plotfigure(name='Surface - Houston/Galveston',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True
    # if article:
    #     plotfigure.kwargs['figsize'] =

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = houston_xlimits
    plotaxes.ylimits = houston_ylimits
    plotaxes.afteraxes = houston_after_axes

    surge.add_surface_elevation(plotaxes,
                                plot_type='contourf',
                                contours=surface_contours,
                                shrink=houston_shrink)

    if article:
        plotaxes.plotitem_dict['surface'].add_colorbar = False
    else:
        add_custom_colorbar_ticks_to_axes(plotaxes, 'surface', surface_ticks,
                                          surface_labels)
    surge.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [
        0, 0, 0, 0, 0, 0, 0
    ]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0, 0, 0, 0, 0, 0, 0]
    # surge.add_bathy_contours(plotaxes)

    # Plot using jet and 0.0 to 5.0 to match figgen generated ADCIRC results
    # plotaxes.plotitem_dict['surface'].pcolor_cmin = 0.0
    # plotaxes.plotitem_dict['surface'].pcolor_cmax = 5.0
    # plotaxes.plotitem_dict['surface'].pcolor_cmap = plt.get_cmap('jet')

    #
    # Water Speed
    #
    plotfigure = plotdata.new_plotfigure(name='Currents - Houston/Galveston',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True

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

    surge.add_speed(plotaxes,
                    plot_type='contourf',
                    contours=speed_contours,
                    shrink=houston_shrink)

    if article:
        plotaxes.plotitem_dict['speed'].add_colorbar = False
    else:
        add_custom_colorbar_ticks_to_axes(plotaxes, 'speed', speed_ticks,
                                          speed_labels)
    surge.add_land(plotaxes)
    # surge.add_bathy_contours(plotaxes)
    # plotaxes.plotitem_dict['speed'].amr_patchedges_show = [1,1,1,1,1,1,1,1]
    # plotaxes.plotitem_dict['land'].amr_patchedges_show = [1,1,1,1,1,1,1,1]
    plotaxes.plotitem_dict['speed'].amr_patchedges_show = [0, 0, 0, 0, 0, 0, 0]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0, 0, 0, 0, 0, 0, 0]

    # ==========================
    #  Hurricane Forcing fields
    # ==========================

    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = surge_data.pressure_forcing and True

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = gulf_after_axes
    plotaxes.scaled = True

    surge.add_pressure(plotaxes, bounds=pressure_limits, shrink=gulf_shrink)
    surge.add_land(plotaxes)

    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = surge_data.wind_forcing and True

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = gulf_after_axes
    plotaxes.scaled = True

    surge.add_wind(plotaxes,
                   bounds=wind_limits,
                   plot_type='pcolor',
                   shrink=gulf_shrink)
    surge.add_land(plotaxes)

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

    # plotfigure.kwargs['figsize'] = (16,10)

    def gauge_after_axes(cd):

        if cd.gaugeno in [1, 2, 3, 4]:
            axes = plt.gca()
            # Add Kennedy gauge data
            kennedy_gauge = kennedy_gauges[gauge_name_trans[cd.gaugeno]]
            axes.plot(kennedy_gauge['t'] -
                      seconds2days(date2seconds(gauge_landfall[0])),
                      kennedy_gauge['mean_water'] + kennedy_gauge['depth'],
                      'k-',
                      label='Gauge Data')

            # Add GeoClaw gauge data
            geoclaw_gauge = cd.gaugesoln
            axes.plot(seconds2days(geoclaw_gauge.t -
                                   date2seconds(gauge_landfall[1])),
                      geoclaw_gauge.q[3, :] + gauge_surface_offset[0],
                      'b--',
                      label="GeoClaw")

            # Add ADCIRC gauge data
            ADCIRC_gauge = ADCIRC_gauges[kennedy_gauge['gauge_no']]
            axes.plot(seconds2days(ADCIRC_gauge[:, 0] - gauge_landfall[2]),
                      ADCIRC_gauge[:, 1] + gauge_surface_offset[1],
                      'r-.',
                      label="ADCIRC")

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

            plt.hold(False)

        # surge.gauge_afteraxes(cd)

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

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

    # =====================
    #  Gauge Location Plot
    # =====================
    gauge_xlimits = [-95.5, -94]
    gauge_ylimits = [29.0, 30.0]
    gauge_location_shrink = 0.75

    def gauge_after_axes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        surge.gauge_locations(cd, gaugenos=[1, 2, 3, 4])
        plt.title("Gauge Locations")

    plotfigure = plotdata.new_plotfigure(name='Gauge Locations',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = gauge_xlimits
    plotaxes.ylimits = gauge_ylimits
    plotaxes.afteraxes = gauge_after_axes

    surge.add_surface_elevation(plotaxes,
                                plot_type='contourf',
                                contours=surface_contours,
                                shrink=gauge_location_shrink)
    # surge.add_surface_elevation(plotaxes, plot_type="contourf")
    add_custom_colorbar_ticks_to_axes(plotaxes, 'surface', surface_ticks,
                                      surface_labels)
    surge.add_land(plotaxes)
    # plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0,0,0,0,0,0,0]
    # plotaxes.plotitem_dict['surface'].add_colorbar = False
    # plotaxes.plotitem_dict['surface'].pcolor_cmap = plt.get_cmap('jet')
    # plotaxes.plotitem_dict['surface'].pcolor_cmap = plt.get_cmap('gist_yarg')
    # plotaxes.plotitem_dict['surface'].pcolor_cmin = 0.0
    # plotaxes.plotitem_dict['surface'].pcolor_cmax = 5.0
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [
        0, 0, 0, 0, 0, 0, 0
    ]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0, 0, 0, 0, 0, 0, 0]

    # ==============================================================
    #  Debugging Plots, only really work if using interactive plots
    # ==============================================================
    #
    # Water Velocity Components
    #
    plotfigure = plotdata.new_plotfigure(
        name='Velocity Components - Entire Domain',
        figno=fig_num_counter.get_counter())
    plotfigure.show = False

    # X-Component
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(121)"
    plotaxes.title = 'Velocity, X-Component'
    plotaxes.scaled = True
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.afteraxes = gulf_after_axes

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surge.water_u
    plotitem.pcolor_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.pcolor_cmin = -speed_limits[1]
    plotitem.pcolor_cmax = speed_limits[1]
    plotitem.colorbar_shrink = gulf_shrink
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1]

    surge.add_land(plotaxes)

    # Y-Component
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(122)"
    plotaxes.title = 'Velocity, Y-Component'
    plotaxes.scaled = True
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.afteraxes = gulf_after_axes

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surge.water_v
    plotitem.pcolor_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.pcolor_cmin = -speed_limits[1]
    plotitem.pcolor_cmax = speed_limits[1]
    plotitem.colorbar_shrink = gulf_shrink
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1]

    surge.add_land(plotaxes)

    #
    # Depth
    #
    plotfigure = plotdata.new_plotfigure(name='Depth - Entire Domain',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = False

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'depth'
    plotaxes.scaled = True
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.afteraxes = gulf_after_axes

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = 0
    plotitem.imshow_cmap = colormaps.make_colormap({
        1.0: 'r',
        0.5: 'w',
        0.0: 'b'
    })
    plotitem.imshow_cmin = 0
    plotitem.imshow_cmax = 100
    plotitem.colorbar_shrink = gulf_shrink
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1, 1, 1, 1, 1, 1, 1]

    # Surge field
    plotfigure = plotdata.new_plotfigure(name='Surge Field',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = ((surge_data.wind_forcing or surge_data.pressure_forcing)
                       and False)

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.title = "Storm Surge Source Term S"
    plotaxes.afteraxes = gulf_after_axes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surge.pressure_field + 1
    plotitem.pcolor_cmap = plt.get_cmap('PuBu')
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 1e-3
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = gulf_shrink
    plotitem.colorbar_label = "Source Strength"
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1, 1, 1, 0, 0]

    surge.add_land(plotaxes)

    plotfigure = plotdata.new_plotfigure(name='Friction/Coriolis Source',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = False

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = gulf_xlimits
    plotaxes.ylimits = gulf_ylimits
    plotaxes.title = "Friction/Coriolis Source"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surge.pressure_field + 2
    plotitem.pcolor_cmap = plt.get_cmap('PuBu')
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 1e-3
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = gulf_shrink
    plotitem.colorbar_label = "Source Strength"
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1, 1, 1, 0, 0]

    surge.add_land(plotaxes)

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

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

    if article:
        plotdata.printfigs = True  # print figures
        plotdata.print_format = 'png'  # file format
        plotdata.print_framenos = [54, 60, 66, 72, 78,
                                   84]  # list of frames to print
        plotdata.print_gaugenos = [1, 2, 3, 4]  # list of gauges to print
        plotdata.print_fignos = [4, 5, 6, 7, 10, 3,
                                 300]  # list of figures to print
        plotdata.html = True  # create html files of plots?
        plotdata.html_homelink = '../README.html'  # pointer for top of index
        plotdata.latex = False  # create latex file of plots?
        plotdata.latex_figsperline = 2  # layout of plots
        plotdata.latex_framesperline = 1  # layout of plots
        plotdata.latex_makepdf = False  # also run pdflatex?

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


    from clawpack.visclaw import colormaps, geoplot

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

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

    clim_ocean = 2.5
    clim_CC = 2.5

    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 clawpack.visclaw import gaugetools
        gaugetools.plot_gauge_locations(current_data.plotdata, \
             gaugenos='all', format_string='ko', add_labels=True)

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

    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 = False

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

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

    plotaxes.xlimits = [220,238] 
    plotaxes.ylimits = [35,55]

    # 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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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.celledges_show = 0
    plotitem.patchedges_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.celledges_show = 0
    plotitem.patchedges_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
    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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1]
    plotaxes.xlimits = [230,237] 
    plotaxes.ylimits = [38,44]
    plotaxes.afteraxes = aa

    
 
    #-----------------------------------------
    # Figure for zoom2
    #-----------------------------------------
    plotfigure = plotdata.new_plotfigure(name='Crescent City', figno=11)
    plotfigure.show = True

    # 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 = cmin_CC
    plotitem.imshow_cmax = cmax_CC
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1]
    plotaxes.xlimits = [235.50,235.86] 
    plotaxes.ylimits = [41.60,41.78]
    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi
        addgauges(current_data)
        title_hours(current_data)
        ticklabel_format(format='plain',useOffset=False)
        xticks(rotation=20)
        a = gca()
        a.set_aspect(1./cos(41.75*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,0,1]
    plotitem.celledges_show = 0
    plotitem.patchedges_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 = 'auto'
    plotaxes.title = 'Surface'

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


    def fix_gauge(current_data):
        from pylab import plot, legend, xticks, floor, yticks,xlabel,savefig
        t = current_data.t
        gaugeno = current_data.gaugeno
        n = int(floor(t.max()/1800.) + 2)
        xticks([1800*i for i in range(n)],[str(i/2.) for i in range(n)],\
          fontsize=15)
        yticks(fontsize=15)
        xlabel("Hours")

    #plotaxes.afteraxes = fix_gauge




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

    plotdata.printfigs = True                # print figures
    plotdata.print_format = 'png'            # file format
    plotdata.print_framenos = 'all'          # list of frames to print
    plotdata.print_fignos = 'all'            # list of figures to print
    plotdata.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
Esempio n. 56
0
def setplot(plotdata):
    r"""Setplot function for surge plotting"""
    

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

    fig_num_counter = surge.plot.figure_counter()

    # Load data from output
    amrdata = clawdata.AmrclawInputData(2)
    amrdata.read(os.path.join(plotdata.outdir,'amrclaw.data'))
    physics = clawdata.GeoclawInputData(2)
    physics.read(os.path.join(plotdata.outdir,'geoclaw.data'))
    surge_data = surge.data.SurgeData()
    surge_data.read(os.path.join(plotdata.outdir,'surge.data'))
    friction_data = surge.data.FrictionData()
    friction_data.read(os.path.join(plotdata.outdir,'friction.data'))

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

    # Calculate landfall time, off by a day, maybe leap year issue?
    landfall_dt = datetime.datetime(2005,8,29,6) - datetime.datetime(2005,1,1,0)
    landfall = (landfall_dt.days - 1.0) * 24.0 * 60**2 + landfall_dt.seconds

    # Set afteraxes function
    surge_afteraxes = lambda cd: surge.plot.surge_afteraxes(cd, 
                                        track, landfall, plot_direction=False)

    # Limits for plots
    full_xlimits = [-99.0,-50.0]
    full_ylimits = [8.0,32.0]
    full_shrink = 0.5

    # Color limits
    surface_range = 5.0
    speed_range = 3.0

    xlimits = full_xlimits
    ylimits = full_ylimits
    eta = physics.sea_level
    if not isinstance(eta,list):
        eta = [eta]
    surface_limits = [eta[0]-surface_range,eta[0]+surface_range]
    speed_limits = [0.0,speed_range]
    
    wind_limits = [0,40]
    # wind_limits = [-0.002,0.002]
    pressure_limits = [966,1013]
    friction_bounds = [0.01,0.04]
    # vorticity_limits = [-1.e-2,1.e-2]

    def pcolor_afteraxes(current_data):
        surge_afteraxes(current_data)
        surge.plot.gauge_locations(current_data,gaugenos=[6])
    
    def contour_afteraxes(current_data):
        surge_afteraxes(current_data)

    # ==========================================================================
    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # ==========================================================================

    # ========================================================================
    #  Surface Elevations - Entire Gulf
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface - Entire Domain', 
                                         figno=fig_num_counter.get_counter())
    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 = surge_afteraxes

    surge.plot.add_surface_elevation(plotaxes,bounds=surface_limits,shrink=full_shrink)
    surge.plot.add_land(plotaxes,topo_min=-10.0,topo_max=5.0)
    surge.plot.add_bathy_contours(plotaxes)


    # ========================================================================
    #  Water Speed - Entire Gulf
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Currents - Entire Domain',  
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True

    # 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 = surge_afteraxes

    # Speed
    surge.plot.add_speed(plotaxes,bounds=speed_limits,shrink=full_shrink)

    # Land
    surge.plot.add_land(plotaxes)
    surge.plot.add_bathy_contours(plotaxes)    

    # ========================================================================
    # Hurricane forcing - Entire gulf
    # ========================================================================
    # Friction field
    plotfigure = plotdata.new_plotfigure(name='Friction',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = friction_data.variable_friction and False

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Manning's N Coefficients"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surge.plot.add_friction(plotaxes,bounds=friction_bounds)

    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure',  
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = surge_data.pressure_forcing and True
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    
    surge.plot.add_pressure(plotaxes,bounds=pressure_limits)
    # add_pressure(plotaxes)
    surge.plot.add_land(plotaxes)
    
    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed', 
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = surge_data.wind_forcing and True
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    
    surge.plot.add_wind(plotaxes,bounds=wind_limits,plot_type='imshow')
    # add_wind(plotaxes,bounds=wind_limits,plot_type='contour')
    # add_wind(plotaxes,bounds=wind_limits,plot_type='quiver')
    surge.plot.add_land(plotaxes)
    
    # Surge field
    plotfigure = plotdata.new_plotfigure(name='Surge Field', 
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = ((surge_data.wind_forcing or surge_data.pressure_forcing) 
                        and True)
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Storm Surge Source Term S"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surge.plot.pressure_field + 1
    plotitem.pcolor_cmap = plt.get_cmap('PuBu')
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 1e-3
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = 0.5
    plotitem.colorbar_label = "Source Strength"
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1,1,1,0,0]
    
    surge.plot.add_land(plotaxes)

    plotfigure = plotdata.new_plotfigure(name='Friction/Coriolis Source', 
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = True
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = full_xlimits
    plotaxes.ylimits = full_ylimits
    plotaxes.title = "Friction/Coriolis Source"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surge.plot.pressure_field + 2
    plotitem.pcolor_cmap = plt.get_cmap('PuBu')
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 1e-3
    plotitem.add_colorbar = True
    plotitem.colorbar_shrink = 0.5
    plotitem.colorbar_label = "Source Strength"
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1,1,1,0,0]
    
    surge.plot.add_land(plotaxes)

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    # try:
        # plotaxes.xlimits = [amrdata.t0,amrdata.tfinal]
    # except:
        # pass
    # plotaxes.ylimits = [0,150.0]
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'Surface'
    plotaxes.afteraxes = surge.plot.gauge_afteraxes

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

    # ========================================================================
    #  Water Velocity Components - Entire Gulf
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Velocity Components - Entire Domain',  
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = False

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

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surge.plot.water_u
    plotitem.pcolor_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.pcolor_cmin = -speed_limits[1]
    plotitem.pcolor_cmax = speed_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1]

    surge.plot.add_land(plotaxes)

    # Y-Component
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = "subplot(122)"
    plotaxes.title = 'Velocity, Y-Component'
    plotaxes.scaled = True
    plotaxes.xlimits = xlimits
    plotaxes.ylimits = ylimits
    plotaxes.afteraxes = surge_afteraxes

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = surge.plot.water_v
    plotitem.pcolor_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.pcolor_cmin = -speed_limits[1]
    plotitem.pcolor_cmax = speed_limits[1]
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1]
    
    surge.plot.add_land(plotaxes)

    # ==========================================================================
    #  Depth
    # ==========================================================================
    plotfigure = plotdata.new_plotfigure(name='Depth - Entire Domain', 
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = False

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

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = 0
    plotitem.imshow_cmap = colormaps.make_colormap({1.0:'r',0.5:'w',0.0:'b'})
    plotitem.imshow_cmin = 0
    plotitem.imshow_cmax = 100
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1,1,1,1,1,1,1]


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

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

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

    from clawpack.visclaw import colormaps, geoplot

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

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

    clim_ocean = 0.3
    clim_CC = 0.5

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

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

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

    def timeformat(t):
        from numpy import mod
        hours = int(t/3600.)
        tmin = mod(t,3600.)
        min = int(tmin/60.)
        sec = int(mod(tmin,60.))
        timestr = '%s:%s:%s' % (hours,str(min).zfill(2),str(sec).zfill(2))
        return timestr
        
    def title(current_data):
        from pylab import title
        title('Surface Height', fontsize = 28)
    
    def title_innerproduct(current_data):
        from pylab import title
        title('Inner Product', fontsize = 28)

    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': (11,5)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'axes([0.03,0.13,0.45,0.75])'
    plotaxes.title = 'Pacific'
    plotaxes.scaled = True

    def aa(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, yticks
        plotcc(current_data)
        title(current_data)
        ticklabel_format(format='plain',useOffset=False)
        xticks([180, 200, 220, 240], rotation=20, fontsize = 28)
        yticks(fontsize = 28)
        a = gca()
        a.set_aspect(1./cos(41.75*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 = False
    plotitem.colorbar_shrink = 0.7
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [0]
    plotaxes.xlimits = [180,240] 
    plotaxes.ylimits = [10,62]

    # 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.celledges_show = 0
    plotitem.patchedges_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.celledges_show = 0
    plotitem.patchedges_show = 0

    # Adding inner product plot

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Inner Product'
    plotaxes.axescmd = 'axes([0.45,0.13,0.6,0.75])'
    plotaxes.scaled = True
    def aa_innerprod(current_data):
        from pylab import ticklabel_format, xticks, gca, cos, pi, yticks
        plotcc(current_data)
        title_innerproduct(current_data)
        ticklabel_format(format='plain',useOffset=False)
        xticks([180, 200, 220, 240], rotation=20, fontsize = 28)
        pylab.tick_params(axis='y', labelleft='off')
        a = gca()
        a.set_aspect(1./cos(41.75*pi/180.))
    plotaxes.afteraxes = aa_innerprod
    
    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = 4
    plotitem.imshow_cmap = colormaps.white_red
    plotitem.imshow_cmin = 0.0
    plotitem.imshow_cmax = 0.05
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [0]
    plotitem.amr_data_show = [1,0,0,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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [0]
    plotaxes.xlimits = [180,240]
    plotaxes.ylimits = [10,62]


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

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

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.imshow_cmap = my_cmap
    plotitem.imshow_cmin = cmin_ocean
    plotitem.imshow_cmax = cmax_ocean
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_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_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [0]
    plotaxes.xlimits = [235.5,236]
    plotaxes.ylimits = [41.6,41.8]
    plotaxes.afteraxes = addgauges

    # add contour lines of bathy if desired:
    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':'solid','linewidths':2}
    plotitem.amr_contour_show = [0,0,0,0,0,1]
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0

    #-----------------------------------------
    # Figures for gauges
    #-----------------------------------------
    
    def fix_gauge(current_data):
        from pylab import plot, legend, xticks, floor, yticks,xlabel,savefig, title
        t = current_data.t
        gaugeno = current_data.gaugeno
        xticks([18000, 21600, 25200, 28800, 32400, 36000],\
               [str(180/36), str(216/36), str(252/36), str(288/36), \
                str(324/36), str(360/36)], fontsize=17)
        yticks(fontsize=17)
        title('Surface at gauge ' + str(gaugeno), fontsize=17)
        xlabel(' ')

    plotfigure = plotdata.new_plotfigure(name='gauge plot', figno=300, \
                    type='each_gauge')
    plotfigure.kwargs = {'figsize': (10.5,5)}

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'axes([0.12,0.12,0.79,0.79])'
    plotaxes.title = 'Surface'
    plotaxes.xlimits = [15000, 39600]
    plotaxes.afteraxes = fix_gauge

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

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

    plotdata.printfigs = True                # print figures
    plotdata.print_format = 'png'            # file format
    plotdata.print_framenos = 'all'          # list of frames to print
    plotdata.print_fignos = 'all'            # list of figures to print
    plotdata.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?
    plotdata.html_movie = 'JSAnimation'      # new style, or "4.x" for old style


    return plotdata