示例#1
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
示例#2
0
文件: setplot.py 项目: see-on/apps
def setplot(plotdata):
    r"""Setplot function for surge plotting"""

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

    # Load data from output
    clawdata = clawpack.clawutil.data.ClawInputData(2)
    clawdata.read(os.path.join(plotdata.outdir, 'claw.data'))
    physics = clawpack.geoclaw.data.GeoClawData()
    physics.read(os.path.join(plotdata.outdir, 'geoclaw.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 track32
    track = surge.track_data(os.path.join(plotdata.outdir, 'fort.track'))

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

    # Limits for plots
    dx = 0.5
    dy = 0.5
    regions = [{
        "name":
        "Full Domain",
        "limits": [[clawdata.lower[0], clawdata.upper[0]],
                   [clawdata.lower[1], clawdata.upper[1]]]
    }, {
        "name": "New Orleans",
        "limits": [[-92.5, -87.5], [27.5, 31.5]]
    }]

    # Color limits
    surface_limits = [physics.sea_level - 5.0, physics.sea_level + 5.0]
    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, 3.0]
    speed_ticks = [0, 1, 2, 3]
    speed_labels = [str(value) for value in speed_ticks]
    wind_limits = [15, 40]
    pressure_limits = [966, 1013]
    friction_bounds = [0.01, 0.04]

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

    # Loop over region specifications ploting both surface and speeds
    for region in regions:
        name = region['name']
        xlimits = region['limits'][0]
        ylimits = region['limits'][1]
        # ======================================================================
        #  Surface Elevations
        # ======================================================================
        plotfigure = plotdata.new_plotfigure(name='Surface - %s' % name)
        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.add_surface_elevation(plotaxes, bounds=surface_limits)
        plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
        surge.add_land(plotaxes)
        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

        # ======================================================================
        #  Water Speed
        # ======================================================================
        plotfigure = plotdata.new_plotfigure(name='Currents - %s' % name)
        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

        surge.add_speed(plotaxes, bounds=speed_limits)
        plotaxes.plotitem_dict['speed'].amr_patchedges_show = [0] * 10
        surge.add_land(plotaxes)
        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    # Only plot hurricane forcing in the full domain
    region = regions[0]
    name = region['name']
    xlimits = region['limits'][0]
    ylimits = region['limits'][1]
    # ======================================================================
    #  Wind Field
    # ======================================================================
    plotfigure = plotdata.new_plotfigure(name='Wind Speed - %s' % name)
    plotfigure.show = surge_data.wind_forcing

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

    surge.add_wind(plotaxes, bounds=wind_limits)
    plotaxes.plotitem_dict['wind'].amr_patchedges_show = [0] * 10
    surge.add_land(plotaxes)
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    # ========================================================================
    # Hurricane forcing
    # ========================================================================

    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure - %s' % name)
    plotfigure.show = surge_data.pressure_forcing

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

    surge.add_pressure(plotaxes, bounds=pressure_limits)
    plotaxes.plotitem_dict['pressure'].amr_patchedges_show = [0] * 10
    surge.add_land(plotaxes)
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    stations = [('8761724', 'Grand Isle, LA'),
                ('8760922', 'Pilots Station East, SW Pass, LA'),
                ('8735180', 'Dauphin Island, AL')]

    landfall_time = np.datetime64('2005-08-29T11:10')
    begin_date = datetime.datetime(2005, 8, 26)
    end_date = datetime.datetime(2005, 8, 31)

    def get_actual_water_levels(station_id):
        # Fetch water levels and tide predictions for given station
        date_time, water_level, tide = fetch_noaa_tide_data(
            station_id, begin_date, end_date)

        # Calculate times relative to landfall
        secs_rel_landfall = (date_time - landfall_time) / np.timedelta64(
            1, 's')

        # Subtract tide predictions from measured water levels
        water_level -= tide

        return secs_rel_landfall, water_level

    def gauge_afteraxes(cd):

        station_id, station_name = stations[cd.gaugeno - 1]
        # secs_rel_landfall, actual_level = get_actual_water_levels(station_id)

        axes = plt.gca()
        # axes.plot(secs_rel_landfall, actual_level, 'g')

        # Fix up plot - in particular fix time labels
        axes.set_title(station_name)
        axes.set_xlabel('Days relative to landfall')
        axes.set_ylabel('Surface (m)')
        axes.set_xlim(np.array([-2, 1]) * 86400)
        axes.set_ylim([-0.5, 2.5])
        axes.set_xticks(np.linspace(-2, 1, 4) * 86400)
        axes.set_xticklabels([r"$-2$", r"$-1$", r"$0$", r"$1$"])
        axes.grid(True)

        # Plot wind speed using second scale
        # wind_speed = np.linalg.norm(cd.gaugesoln.q[8:10, :], axis=0)
        # axes2 = axes.twinx()
        # axes2.plot(cd.gaugesoln.t, wind_speed, 'r.', markersize=0.3)
        # axes2.set_ylabel('Wind Speed (m/s)')
        # axes2.set_ylim([-2.5, 52.5])

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

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

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

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge Locations'
    plotaxes.scaled = True
    plotaxes.xlimits = [-91.5, -87.5]
    plotaxes.ylimits = [28.0, 31.0]
    plotaxes.afteraxes = gauge_location_afteraxes

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

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

    # 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
示例#3
0
def setplot(plotdata):
    r"""Setplot function for surge plotting"""

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

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

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

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

    def plot_coastline(cd):
        """Load fine coastline for plotting around NYC"""
        try:
            # Assumes that at path theres a fine topography file in NetCDF file format
            path = "/Users/mandli/Dropbox/research/data/topography/atlantic/sandy_bathy/ny_area.nc"
            topo_file = topotools.Topography(path, topo_type=4)
            topo_file.read(nc_params={
                "x_var": "lon",
                "y_var": "lat",
                "z_var": "Band1"
            })

            axes = plt.gca()
            axes.contour(topo_file.X,
                         topo_file.Y,
                         topo_file.Z,
                         levels=[-0.001, 0.001],
                         colors='k',
                         linestyles='-')
        except:
            pass

        surge_afteraxes(cd)

    # Color limits
    surface_range = 4.5
    speed_range = 1.0
    # speed_range = 1.e-2

    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]
    friction_bounds = [0.01, 0.04]
    vorticity_limits = [-1.e-2, 1.e-2]
    land_bounds = [-10, 50]

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # Limits for plots
    regions = {
        'Full Domain': {
            "xlimits": [claw_data.lower[0], claw_data.upper[0]],
            "ylimits": [claw_data.lower[1], claw_data.upper[1]],
            "shrink": 1.0,
            "figsize": [6.4, 4.8]
        },
        'Tri-State Region': {
            "xlimits": [-74.5, -71.0],
            "ylimits": [40.0, 41.5],
            "shrink": 1.0,
            "figsize": [6.4, 4.8]
        },
        'NYC': {
            "xlimits": [-74.2, -73.7],
            "ylimits": [40.4, 40.85],
            "shrink": 1.0,
            "figsize": [6.4, 4.8]
        }
    }

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

    for (name, region_dict) in regions.items():
        # ========================================================================
        #  Surface Elevations
        # ========================================================================
        plotfigure = plotdata.new_plotfigure(name='Surface - %s' % name)
        plotfigure.show = True

        # Set up for axes in this figure:
        plotaxes = plotfigure.new_plotaxes()
        plotaxes.title = 'Surface'
        plotaxes.scaled = True
        plotaxes.xlimits = region_dict['xlimits']
        plotaxes.ylimits = region_dict['ylimits']
        plotaxes.afteraxes = plot_coastline
        # plotaxes.afteraxes = surge_afteraxes
        # plotaxes.afteraxes = gauge_location_afteraxes

        surgeplot.add_surface_elevation(plotaxes,
                                        bounds=surface_limits,
                                        shrink=region_dict['shrink'])
        surgeplot.add_land(plotaxes, bounds=land_bounds)

        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0, 0, 0]
        plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0, 0, 0]

        # ========================================================================
        #  Water Speed
        # ========================================================================
        plotfigure = plotdata.new_plotfigure(name='Currents - %s' % name)
        plotfigure.show = True

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

        surgeplot.add_speed(plotaxes,
                            bounds=speed_limits,
                            shrink=region_dict['shrink'])
        surgeplot.add_land(plotaxes, bounds=land_bounds)

        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0, 0, 0]
        plotaxes.plotitem_dict['speed'].amr_patchedges_show = [0, 0, 0]

    # ========================================================================
    # Hurricane forcing - Entire Atlantic
    # ========================================================================
    # Friction field
    plotfigure = plotdata.new_plotfigure(name='Friction')
    plotfigure.show = False

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Full Domain']['xlimits']
    plotaxes.ylimits = regions['Full Domain']['ylimits']
    plotaxes.title = "Manning's N Coefficients"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surgeplot.add_friction(plotaxes, bounds=friction_bounds)

    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure')
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Full Domain']['xlimits']
    plotaxes.ylimits = regions['Full Domain']['ylimits']
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surgeplot.add_pressure(plotaxes, bounds=pressure_limits)
    surgeplot.add_land(plotaxes, bounds=[-10, 500])

    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed')
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes()

    plotaxes.xlimits = regions['Full Domain']['xlimits']
    plotaxes.ylimits = regions['Full Domain']['ylimits']
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surgeplot.add_wind(plotaxes, bounds=wind_limits, plot_type='imshow')
    surgeplot.add_land(plotaxes, bounds=[-10, 500])
    # ========================================================================
    #  Figures for gauges
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface & topo', figno=300, \
                    type='each_gauge')
    plotfigure.show = True
    plotfigure.clf_each_gauge = True

    stations = [('8518750', 'The Battery, NY'), ('8516945', 'Kings Point, NY'),
                ('8519483', 'Bergen Point West Reach, NY')]
    #('8531680','Sandy Hook, NY'),
    #('n03020','Narrows,NY')]

    landfall_time = np.datetime64('2012-10-29T23:30')
    begin_date = datetime.datetime(2012, 10, 28)
    end_date = datetime.datetime(
        2012,
        10,
        31,
    )

    def get_actual_water_levels(station_id):
        # Fetch water levels and tide predictions for given station
        date_time, water_level, tide = fetch_noaa_tide_data(
            station_id, begin_date, end_date)

        # Calculate times relative to landfall
        seconds_rel_landfall = (date_time - landfall_time) / np.timedelta64(
            1, 's')
        # Subtract tide predictions from measured water levels
        water_level -= tide

        return seconds_rel_landfall, water_level

    def gauge_afteraxes(cd):
        station_id, station_name = stations[cd.gaugeno - 1]
        seconds_rel_landfall, actual_level = get_actual_water_levels(
            station_id)

        axes = plt.gca()
        #surgeplot.plot_landfall_gauge(cd.gaugesoln, axes, landfall=landfall)
        axes.plot(seconds_rel_landfall, actual_level, 'g')

        # Fix up plot - in particular fix time labels
        axes.set_title(station_name)
        axes.set_xlabel('Seconds relative to landfall')
        axes.set_ylabel('Surface (m)')
        axes.set_xlim([days2seconds(-2), days2seconds(1)])
        axes.set_ylim([0, 4])
        axes.set_xticks(
            [days2seconds(-2),
             days2seconds(-1), 0,
             days2seconds(1)])
        #axes.set_xticklabels([r"$-3$", r"$-2$", r"$-1$", r"$0$", r"$1$"])
        #axes.grid(True)

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

    # 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 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
示例#4
0
文件: setplot.py 项目: erdc-cm/apps
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
    physics = clawpack.geoclaw.data.GeoClawData()
    physics.read(os.path.join(plotdata.outdir,'geoclaw.data'))
    surge_data = clawpack.geoclaw.surge.data.SurgeData()
    surge_data.read(os.path.join(plotdata.outdir,'surge.data'))
    friction_data = clawpack.geoclaw.surge.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(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.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.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.add_surface_elevation(plotaxes,bounds=surface_limits,shrink=full_shrink)
    surge.add_land(plotaxes,topo_min=-10.0,topo_max=5.0)
    surge.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.add_speed(plotaxes,bounds=speed_limits,shrink=full_shrink)

    # Land
    surge.add_land(plotaxes)
    surge.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.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.add_pressure(plotaxes,bounds=pressure_limits)
    # add_pressure(plotaxes)
    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 = 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)
    
    # 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.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.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.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.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.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.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.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.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.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
示例#5
0
def setplot(plotdata=None):
    """"""

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

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

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

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

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

    # Color limits
    surface_limits = [-5.0, 5.0]
    speed_limits = [0.0, 3.0]
    wind_limits = [0, 100]
    pressure_limits = [935, 1013]
    friction_bounds = [0.01, 0.04]

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

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    regions = {
        "Atlantic": {
            "xlimits": (clawdata.lower[0], clawdata.upper[0]),
            "ylimits": (clawdata.lower[1], clawdata.upper[1]),
            "figsize": (6.4, 4.8)
        },
        "United Kingdom": {
            "xlimits": (-10.5, 0),
            "ylimits": (51.5, 60.0),
            "figsize": (8, 6)
        }
    }

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

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

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

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

        surgeplot.add_speed(plotaxes, bounds=speed_limits)
        surgeplot.add_land(plotaxes)
        plotaxes.plotitem_dict['speed'].amr_patchedges_show = [0] * 10
        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

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

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

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

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

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

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

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

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

    # -------- Failed attempt at comparing data on Clawpack ----------
    #def get_actual_water_levels(gaugeno):
    #    heights = open("surge_"+str(gaugeno)+".txt", "r")
    #    surge = []
    #    for height in heights:
    #        line = height.strip()
    #        line = line.split(",")
    #        line = float(line[0])
    #        surge.append(line)
    #
    #    t = np.arange(-172800, 172800, 3600, dtype='float')
    #
    #    return t, surge

    def gauge_afteraxes(cd):

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

        #t, surge = get_actual_water_levels(cd.gaugeno)
        #axes.plot(t, surge, color="g", label="Observed")

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

    plotaxes.afteraxes = gauge_afteraxes

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

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

    #
    # Gauge Location Plot
    #

    # --------- For only one plot for location of all four gauges, uncomment -------
    # def gauge_location_afteraxes(cd):
    #     plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
    #     surge_afteraxes(cd)
    #     gaugetools.plot_gauge_locations(cd.plotdata, gaugenos='all',
    #                                     format_string='ko', add_labels=True)
    #
    # plotfigure = plotdata.new_plotfigure(name="Gauge Locations")
    # plotfigure.show = True
    #
    # # Set up for axes in this figure:
    # plotaxes = plotfigure.new_plotaxes()
    # plotaxes.title = 'Gauge Locations'
    # plotaxes.scaled = True
    # plotaxes.xlimits = [-7.0, -4.8]
    # plotaxes.ylimits = [55.0, 58.2]
    # plotaxes.afteraxes = gauge_location_afteraxes
    # surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    # surgeplot.add_land(plotaxes)
    # plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    # plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    # individual gauge plots
    def gauge_1_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[1],
                                        format_string='ko',
                                        add_labels=True)

    def gauge_2_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[2],
                                        format_string='ko',
                                        add_labels=True)

    def gauge_3_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[3],
                                        format_string='ko',
                                        add_labels=True)

    def gauge_4_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[4],
                                        format_string='ko',
                                        add_labels=True)

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 1'
    plotaxes.scaled = True
    plotaxes.xlimits = [-7.0, -6.0]
    plotaxes.ylimits = [55.0, 56.0]
    plotaxes.afteraxes = gauge_1_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 2'
    plotaxes.scaled = True
    plotaxes.xlimits = [-6.5, -5.5]
    plotaxes.ylimits = [56.0, 57.0]
    plotaxes.afteraxes = gauge_2_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 3'
    plotaxes.scaled = True
    plotaxes.xlimits = [-6.0, -5.0]
    plotaxes.ylimits = [57.5, 58.5]
    plotaxes.afteraxes = gauge_3_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 4'
    plotaxes.scaled = True
    plotaxes.xlimits = [-6.0, -5.0]
    plotaxes.ylimits = [58.0, 59.0]
    plotaxes.afteraxes = gauge_4_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    plotdata.printfigs = True  # print figures
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = 'all'  # list of frames to print
    plotdata.print_gaugenos = [1, 2, 3, 4]  # list of gauges to print
    plotdata.print_fignos = 'all'  # list of figures to print
    plotdata.html = True  # create html files of plots?
    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  # parallel plotting

    return plotdata
示例#6
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 = clawpack.clawutil.data.ClawInputData(2)
    clawdata.read('claw.data')
    physics = clawpack.geoclaw.data.GeoClawData()
    physics.read(os.path.join(plotdata.outdir, 'geoclaw.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(2011, 8, 27, 7, 30) - datetime.datetime(
        2011, 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 = [clawdata.lower[0], clawdata.upper[0]]
    full_ylimits = [clawdata.lower[1], clawdata.upper[1]]
    full_shrink = 0.8
    newyork_xlimits = [-74.2, -73.7]
    newyork_ylimits = [40.4, 40.85]
    newyork_shrink = 1.0

    # Color limits
    surface_range = 1.5
    speed_range = 1.0
    # speed_range = 1.e-2

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

    def contour_afteraxes(current_data):
        surge_afteraxes(current_data)

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

    # ========================================================================
    #  Surface Elevations - Entire Atlantic
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface - Atlantic', figno=100)
    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,
                                shrink=full_shrink)
    surge.add_land(plotaxes)

    # ========================================================================
    #  Water Speed - Entire Atlantic
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Currents - Atlantic', figno=200)
    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, shrink=full_shrink)

    # Land
    surge.add_land(plotaxes)

    # ========================================================================
    #  Surface Elevations - New York Area
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface - New York', figno=300)
    plotfigure.show = True

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

    def after_with_gauges(cd):
        surge_afteraxes(cd)
        surge.gauge_locations(cd)

    plotaxes.afteraxes = after_with_gauges

    surge.add_surface_elevation(plotaxes,
                                bounds=surface_limits,
                                shrink=newyork_shrink)
    surge.add_land(plotaxes)

    # ========================================================================
    #  Currents Elevations - New York Area
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Currents - New York', figno=400)
    plotfigure.show = True

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

    def after_with_gauges(cd):
        surge_afteraxes(cd)
        surge.gauge_locations(cd)

    plotaxes.afteraxes = after_with_gauges

    surge.add_speed(plotaxes, bounds=speed_limits, shrink=newyork_shrink)
    surge.add_land(plotaxes)

    # ========================================================================
    # Hurricane forcing - Entire Atlantic
    # ========================================================================
    # Friction field
    plotfigure = plotdata.new_plotfigure(name='Friction', figno=500)
    plotfigure.show = friction_data.variable_friction and True

    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.add_friction(plotaxes, bounds=friction_bounds)

    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure', figno=600)
    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.add_pressure(plotaxes, bounds=pressure_limits)
    # add_pressure(plotaxes)
    surge.add_land(plotaxes)

    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed', figno=700)
    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.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)

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

    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.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.add_land(plotaxes)

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

    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.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.add_land(plotaxes)

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Topography'
    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_cmin = 0
    plotitem.imshow_cmax = 200
    plotitem.imshow_cmap = plt.get_cmap("terrain")
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1, 1, 1, 1, 1, 1, 1]

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

    stations = [('8518750', 'The Battery, NY'), ('8516945', 'Kings Point, NY'),
                ('8519483', 'Bergen Point West Reach, NY')]
    #('8531680','Sandy Hook, NY'),
    #('n03020','Narrows,NY')]

    landfall_time = np.datetime64('2011-08-27T11:30')
    begin_date = datetime.datetime(2011, 8, 24)
    end_date = datetime.datetime(2011, 8, 28)

    # need to uncomment this function if you want to compare with real data from NOAA
    #    def get_actual_water_levels(station_id):
    #        # Fetch water levels and tide predictions for given station
    #        date_time, water_level, tide = fetch_noaa_tide_data(station_id,
    #                begin_date, end_date)

    # Calculate times relative to landfall
    #        seconds_rel_landfall = (date_time - landfall_time) / np.timedelta64(1, 's')
    # Subtract tide predictions from measured water levels
    #        water_level -= tide

    #       return seconds_rel_landfall, water_level

    def gauge_afteraxes(cd):
        station_id, station_name = stations[cd.gaugeno - 1]
        # uncomment the next line to plot against real NOAA data
        #        seconds_rel_landfall, actual_level = get_actual_water_levels(station_id)

        axes = plt.gca()
        #surgeplot.plot_landfall_gauge(cd.gaugesoln, axes, landfall=landfall)
        # uncomment the next line to plot against real NOAA data
        #       axes.plot(seconds_rel_landfall, actual_level, 'g')

        # Fix up plot - in particular fix time labels
        axes.set_title(station_name)
        axes.set_xlabel('Seconds relative to landfall')
        axes.set_ylabel('Surface (m)')
        axes.set_ylim([0, 4])
#        axes.set_xticks([ days2seconds(-2), days2seconds(-1), 0, days2seconds(1)])
#axes.set_xticklabels([r"$-3$", r"$-2$", r"$-1$", r"$0$", r"$1$"])
#axes.grid(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 = gauge_afteraxes

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

    # # Speeds
    # plotaxes = plotfigure.new_plotaxes()
    # plotaxes.axescmd = 'subplot(122)'
    # try:
    #     plotaxes.xlimits = [amrdata.t0,amrdata.tfinal]
    # except:
    #     pass
    # plotaxes.ylimits = surface_limits
    # plotaxes.title = 'Momenta'
    # plotaxes.afteraxes = surge.gauge_afteraxes

    # plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    # plotitem.plot_var = 1
    # plotitem.plotstyle = 'r-'
    # plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    # plotitem.plot_var = 2
    # plotitem.plotstyle = 'b-'

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

    # 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
示例#7
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
    from numpy import linspace

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

    # Load data from output
    clawdata = clawutil.ClawInputData(2)
    clawdata.read(os.path.join(plotdata.outdir, 'claw.data'))

    ocean_xlimits = [clawdata.lower[0], clawdata.upper[0]]
    ocean_ylimits = [clawdata.lower[1], clawdata.upper[1]]

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

    probdata = clawutil.ClawData()

    #probdata.read('setprob.data', force=True)
    #theta_island = probdata.theta_island

    # 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 mynewafteraxes(current_data):
        addgauges(current_data)
        bigfont(current_data)

    #-----------------------------------------
    # Some global KML settings
    #-----------------------------------------
    #plotdata.kml_publish = 'http://math.boisestate.edu/~calhoun/visclaw/GoogleEarth/kmz/' #public html
    plotdata.kml_publish = None
    plotdata.kml_name = "NYC Asteroid"  # name appears in Google Earth display only
    plotdata.kml_index_fname = "NYC_Asteroid"  # name for .kmz and .kml files ["_GoogleEarth"]

    # specify beginning of slider time. if not used, assumes Jan. 1 1970
    plotdata.kml_starttime = [2115, 4, 29, 7, 32,
                              0]  # Asteroid hits at 1:32AM, 4/29/2115 (UTC)
    plotdata.kml_tz_offset = 6  # off set to UTC
    # for todays date as the default use

    kml_cmin = -0.005  #colorbar min and max
    kml_cmax = 0.005
    kml_dpi = 400  # only used if individual figures dpi not set
    kml_cmap = geoplot.googleearth_lightblue

    #    kml_cmap = geoplot.googleearth_darkblue
    #    kml_cmap = geoplot.googleearth_transparent
    #    kml_cmap = geoplot.googleearth_white

    def kml_colorbar(filename):
        #cmin = -0.01
        #cmax = 0.01
        geoplot.kml_build_colorbar(filename, kml_cmap, kml_cmin, kml_cmax)

    #-----------------------------------------
    # Figure for pcolor plot for surface
    #-----------------------------------------
    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
    #plotaxes.afteraxes = addgauges

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    #plotitem.plot_var = 0/1/2 or plot that entry into q instead of a function
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = -.8
    plotitem.pcolor_cmax = .8
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [0, 0, 0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.land
    plotitem.show = True
    # plotitem.pcolor_cmap = colormaps.all_white  # to print better in B&W
    plotitem.pcolor_cmap = geoplot.land_colors
    #plotitem.pcolor_cmap = geoplot.googleearth_transparent
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0, 0, 0, 0, 0]
    #plotitem.patchedges_show = 1
    plotitem.amr_patchedges_show = [0, 0, 0]
    #plotaxes.xlimits = [-85,-55]
    #plotaxes.ylimits = [25,45]
    plotaxes.xlimits = ocean_xlimits
    plotaxes.ylimits = ocean_ylimits
    #plotaxes.xlimits = [-75,-70]
    #plotaxes.ylimits = [38,43]

    # add contour lines of bathy if desired:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = True
    plotitem.plot_var = geoplot.topo
    #plotitem.contour_levels = [-500,-250,-100, -50, 0, 50]
    plotitem.contour_levels = linspace(-1000, -400, 3)
    plotitem.amr_contour_colors = ['g']  # color on each level
    #plotitem.kwargs = {'linestyles':'dashed','linewidths':2,'colors' : 'red' }
    plotitem.kwargs = {
        'linestyles': 'dashed',
        'linewidths': 1,
        'colors': 'magenta'
    }
    plotitem.amr_contour_show = [1, 1, 1]
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0

    #-----------------------------------------------------------
    # Figure for KML files - Sea Surface Height
    #----------------------------------------------------------
    #plotfigure = plotdata.new_plotfigure(name='Sea Surface',figno=1)
    #plotfigure.show = True

    #plotfigure.use_for_kml = True
    #plotfigure.kml_use_for_initial_view = True

    # These overide any values set in the plotitems below
    #plotfigure.kml_xlimits = [-80,-55]
    #plotfigure.kml_ylimits = [25, 45]

    # Resolution
    #plotfigure.kml_dpi = 300
    #plotfigure.kml_tile_images = False

    def kml_colorbar_transparent(filename):
        #cmin = -0.01
        #cmax = 0.01
        geoplot.kml_build_colorbar(filename, geoplot.googleearth_transparent,
                                   kml_cmin, kml_cmax)

    #plotfigure.kml_colorbar = kml_colorbar_transparent

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

    # Water
    #plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.show = True
    #plotitem.plot_var = geoplot.surface_or_depth
    #plotitem.pcolor_cmap = geoplot.googleearth_transparent
    #plotitem.pcolor_cmin = kml_cmin
    #plotitem.pcolor_cmax = kml_cmax
    #plotitem.amr_celledges_show = [0,0,0]
    #plotitem.patchedges_show = 0

    #plotfigure.kml_colorbar = kml_colorbar

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    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.xticks(fontsize=15)
    #    pylab.yticks(fontsize=15)
    #plotaxes.afteraxes = fixup

    def speed(current_data):
        from pylab import where, sqrt
        q = current_data.q
        h = q[0, :]
        dry_tol = 0.001
        u = q[1, :]  # this is just to initialize
        v = q[2, :]  # to correct size
        s = 0 * q[2, :]  # to correct size

        nq = len(q[1, :])
        [n, m] = h.shape
        for ii in range(0, n):
            for jj in range(0, m):
                if h[ii, jj] > dry_tol:
                    u[ii, jj] = q[1, ii, jj] / h[ii, jj]
                    v[ii, jj] = q[2, ii, jj] / h[ii, jj]
                    s[ii,
                      jj] = sqrt(u[ii, jj] * u[ii, jj] + v[ii, jj] * v[ii, jj])
                else:
                    u[ii, jj] = 0.
                    v[ii, jj] = 0.
                    s[ii, jj] = 0
        #print("max of u = " + str(max(u)))

        #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 = sqrt(u*2+v*v) #try not dividing or using where
        return s

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = False
    plotitem.plot_var = speed
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    #plotitem.pcolor_cmap = \
    #       colormaps.make_colormap({0:[1,1,1],0.5:[0.5,0.5,1],1:[1,0.3,0.3]})
    plotitem.pcolor_cmin = 0.
    plotitem.pcolor_cmax = .10
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    #plotitem.patchedges_show = 1
    plotitem.amr_patchedges_show = [0, 0, 0]

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

    #-----------------------------------------
    # Figure for zoom around NYC
    #-----------------------------------------
    zoomWanted = True
    if zoomWanted:
        plotfigure = plotdata.new_plotfigure(name='Zoom1', figno=7)

        # add another figure
        #plotfigure.use_for_kml = True
        #plotfigure.kml_use_for_initial_view = False

        # These overide any values set in the plotitems below
        #plotfigure.kml_xlimits =  [-74.5, -73.5]
        #plotfigure.kml_ylimits = [40.4,40.9]

        # Resolution
        #plotfigure.kml_dpi = 300
        #plotfigure.kml_tile_images = True

        #plotfigure.kml_colorbar = kml_colorbar   # defined above

        # Set up for axes in this figure:
        plotaxes = plotfigure.new_plotaxes('zoom on nyc')
        plotaxes.title = 'Surface elevation'
        plotaxes.scaled = True
        manhattan_island = -73.5
        xisland, yisland = latlong(1600e3, manhattan_island, 40., Rearth)
        #plotaxes.xlimits = [xisland-0.6, xisland+0.6]
        #plotaxes.xlimits = [manhattan_island-1, manhattan_island+1]
        #plotaxes.ylimits = [40.15,41.5]
        plotaxes.xlimits = [-74.5, -72.5]  # really zoom in on lower manhattan]
        plotaxes.ylimits = [40.25, 41.5]
        plotaxes.afteraxes = addgauges

        def bigfont(current_data):
            import pylab
            t = current_data.t
            pylab.title("Surface at t = %8.1f" % t, fontsize=20)
            pylab.xticks(fontsize=15)
            pylab.yticks(fontsize=15)

        #plotaxes.afteraxes = bigfont
        #plotaxes.afteraxes = mynewafteraxes   # after axes functions mess with GE plots

        # Water
        plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
        plotitem.show = False
        #plotitem.plot_var = geoplot.surface
        plotitem.plot_var = geoplot.surface_or_depth
        #plotitem.pcolor_cmap = geoplot.tsunami_colormap
        plotitem.pcolor_cmap = kml_cmap
        #plotitem.pcolor_cmin = kml_cmin   # same as above
        #plotitem.pcolor_cmax = kml_cmax
        plotitem.pcolor_cmin = -.2
        plotitem.pcolor_cmax = .2
        plotitem.add_colorbar = True
        plotitem.amr_celledges_show = [0, 0, 0]
        plotitem.patchedges_show = 0

        # Land
        plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
        plotitem.show = False
        plotitem.plot_var = geoplot.land
        # plotitem.pcolor_cmap = colormaps.all_white  # to print better in B&W
        plotitem.pcolor_cmap = geoplot.land_colors
        plotitem.pcolor_cmin = 0.0
        plotitem.pcolor_cmax = 100.0
        plotitem.add_colorbar = False
        plotitem.amr_celledges_show = [0, 0, 0, 0, 0]
        plotitem.patchedges_show = 0

        # contour lines:
        plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
        plotitem.show = False
        plotitem.plot_var = geoplot.surface
        plotitem.contour_levels = [-0.8, -0.4, 0.4, 0.8]
        plotitem.amr_contour_colors = ['k']  # color on each level
        plotitem.kwargs = {'linewidths': 1}
        plotitem.amr_contour_show = [0, 0, 0, 1, 1]
        plotitem.celledges_show = 0
        plotitem.patchedges_show = 0

        # add contour lines of bathy if desired:
        plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
        plotitem.show = False
        plotitem.plot_var = geoplot.topo
        plotitem.contour_levels = linspace(-30, -10, 3)
        plotitem.amr_contour_colors = ['m']  # color on each level
        plotitem.kwargs = {'linestyles': 'dashed', 'linewidths': 1}
        plotitem.amr_contour_show = [1, 1, 1]
        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 = [0000, 6500]
    #plotaxes.ylimits = [-.10, .15]
    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')

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

    def gaugedpress(current_data):
        q = current_data.q
        #dpress = (q[4,:] - 101300)/101300
        dpress = q[4, :]  # already output as relative:  dp/amb_pr
        return dpress

    def gs(current_data):
        q = current_data.q
        # different than speed function because q is function of time, not
        # x,y at the gauges.
        from numpy import where, sqrt
        h = q[0, :]
        #print('shape of h ' +  str(h.shape))
        dry_tol = 0.001
        u = where(h > dry_tol, q[1, :] / h, 0.)
        v = where(h > dry_tol, q[2, :] / h, 0.)
        ssq = sqrt(u * u + v * v)
        #s = sqrt(u**2 + v**2)
        s = sqrt(ssq)
        return ssq

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

    # Plot relative delta pressure as red curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = gaugedpress
    plotitem.plotstyle = 'r-'

    # add speed to this plot since cant get new one going
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = gs
    plotitem.plotstyle = 'g-'

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

    plotaxes.afteraxes = add_zeroline

    # -------------------------------
    # Figure for speed at gauges
    #--------------------------------

    #    plotfigure = plotdata.new_plotfigure(name='Speed at gauges', figno=310, \
    #                    type='each_gauge')
    #

    #
    #    # Set up for axes in this figure:
    #    plotaxes = plotfigure.new_plotaxes()
    #    plotaxes.xlimits = 'auto'
    #    plotaxes.ylimits = 'auto'
    #    #plotaxes.xlimits = [0000, 7000]
    #    #plotaxes.ylimits = 'auto'
    #    plotaxes.title = 'Speed'
    #
    #    # Plot surface as blue curve:
    #    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    #    #plotitem.plot_var = speed
    #    plotitem.plot_var = gs  #gauge_speed
    #    plotitem.plotstyle = 'b-'
    #
    #    plotfigure.show = True
    #

    #-----------------------------------------
    # Figure for bathy alone
    #-----------------------------------------
    def bathy(current_data):
        return current_data.aux[0, :, :]

    plotfigure = plotdata.new_plotfigure(name='bathymetry', figno=3)
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.title = 'Bathymetry'
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = bathy
    plotitem.pcolor_cmin = -3000.00
    plotitem.pcolor_cmax = 500
    plotitem.add_colorbar = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = False
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = linspace(-2000, 2000, 21)
    plotitem.amr_contour_colors = ['k']  # color on each level

    #plotitem.contour_levels = [-1000 -500,-250,-100, -5, 5]

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

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

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

    def normalized_pressure(current_data):
        pressure_index = 6  #7 in fortran, but python is 0 based
        return current_data.aux[
            pressure_index, :, :] / surge_data.ambient_pressure

    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure', figno=33)
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes('normalized_pressure')
    plotaxes.xlimits = ocean_xlimits
    plotaxes.ylimits = ocean_ylimits
    plotaxes.title = 'Pressure Field'
    plotaxes.scaled = True
    plotaxes.afteraxes = addgauges

    pressure_limits = [.99, 1.10]
    #pressure_limits = [.999*surge_data.ambient_pressure / 100.0,
    #                   1.001 * surge_data.ambient_pressure / 100.0]
    #pressure_limits = [-.000001*surge_data.ambient_pressure,
    #                   .000001 * surge_data.ambient_pressure]

    surgeplot.add_pressure(plotaxes, bounds=pressure_limits)
    surgeplot.add_land(plotaxes)

    #plotitem = plotaxes.new_plotitem(plot_type='2d_patch')
    plotitem = plotaxes.plotitem_dict['pressure']
    plotitem.show = False
    plotitem.plot_var = normalized_pressure
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [0, 0, 0]

    plotaxes.plotitem_dict['land'].amr_celledges_show = [0, 0, 0]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0, 0, 0]

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

    # 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_framenos = [30,50,70]          # list of frames to print
    #plotdata.print_framenos = [1]          # list of frames to print
    plotdata.print_gaugenos = 'all'  # list of gauges to print
    #plotdata.print_fignos = [0,7,10,33,300]  # list of figures to print
    #plotdata.print_fignos = [0,7,10,300]  # list of figures to print
    plotdata.print_fignos = [0, 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 = 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.kml = False

    return plotdata
def setplot(plotdata=None):
    """"""

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

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

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

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

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

    # Color limits

    surface_limits = [-4.0, 4.0]
    speed_limits = [0.0, 3.0]
    wind_limits = [0, 64]
    pressure_limits = [935, 1013]
    friction_bounds = [0.01, 0.04]
    '''
    surface_limits = [-2.0, 2.0]
    speed_limits = [0.0, 3.0]
    wind_limits = [0, 70]
    pressure_limits = [990, 1010]
    friction_bounds = [0.01, 0.04]
    '''

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

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # surface region
    regions = {
        "Gulf": {
            "xlimits": (clawdata.lower[0], clawdata.upper[0]),
            "ylimits": (clawdata.lower[1], clawdata.upper[1]),
            "figsize": (6.4, 3.2)
        },
        "LaTex Shelf": {
            "xlimits": (-94.5, -86),
            "ylimits": (27, 32),
            "figsize": (10, 5)
        }
    }

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

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

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

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

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Gulf']['xlimits']
    plotaxes.ylimits = regions['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] * 10
    plotaxes.plotitem_dict['friction'].colorbar_label = "$n$"

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

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

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Gulf']['xlimits']
    plotaxes.ylimits = regions['Gulf']['ylimits']
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    surgeplot.add_wind(plotaxes, bounds=wind_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['wind'].amr_patchedges_show = [0] * 10  # added

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

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

    def gauge_afteraxes(cd):
        axes = plt.gca()
        surgeplot.plot_landfall_gauge(cd.gaugesoln, axes)
        gauge_id = ['8770822', '8768094', '8764227', '8761305', '8760922']
        gauge_title = [
            'Texas Point, Sabine Pass, TX', 'Calcasieu Pass, LA',
            'LAWMA, Amerada Pass, LA', 'Shell Beach, LA',
            'Pilots Station East, S.W. Pass, LA'
        ]
        if (cd.gaugeno < 6):
            realData = util.fetch_noaa_tide_data(gauge_id[cd.gaugeno - 1],
                                                 datetime.datetime(2019,
                                                                   7,
                                                                   10,
                                                                   hour=12),
                                                 datetime.datetime(2019,
                                                                   7,
                                                                   16,
                                                                   hour=12),
                                                 datum='MLLW')
            values = realData[1] - realData[2]
            times = []
            for time in realData[0]:
                times.append(
                    (time - numpy.datetime64("2019-07-13T15:00")).astype(float)
                    / 1440)
        plt.plot(times, values, color='orange', label='real')

        axes.set_title('Gauge %s: %s' %
                       (cd.gaugeno,
                        gauge_title[cd.gaugeno - 1]))  # i for i in gauge_title
        axes.set_xlabel('Days relative to landfall')
        axes.set_ylabel('Surface (m)')
        axes.set_xlim([-2, 1])
        axes.set_ylim([-1.0, 2.5])
        axes.set_xticks([-2, -1, 0, 1])
        axes.set_xticklabels([r"$-2$", r"$-1$", r"$0$", r"$1$"])
        axes.grid(True)

    plotaxes.afteraxes = gauge_afteraxes

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

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

    #
    #  Gauge Location Plot
    #

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

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge Locations'
    plotaxes.scaled = True
    plotaxes.xlimits = [-95, -88.5]
    plotaxes.ylimits = [28, 31]
    plotaxes.afteraxes = gauge_location_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    # Gauge 01: Texas Point, Sabine Pass, TX [8770822]
    def gauge_location_afteraxes1(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[1],
                                        format_string='ko',
                                        add_labels=True)

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 01 Location'
    plotaxes.scaled = True
    plotaxes.xlimits = [-93.84 - 0.2, -93.84 + 0.2]
    plotaxes.ylimits = [29.69 - 0.2, 29.69 + 0.2]
    plotaxes.afteraxes = gauge_location_afteraxes1
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    # Gauge 02: Calcasieu Pass, LA [8768094]
    def gauge_location_afteraxes2(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[2],
                                        format_string='ko',
                                        add_labels=True)

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 02 Location'
    plotaxes.scaled = True
    plotaxes.xlimits = [-93.34 - 0.2, -93.34 + 0.2]
    plotaxes.ylimits = [29.77 - 0.2, 29.77 + 0.2]
    plotaxes.afteraxes = gauge_location_afteraxes2
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    # Gauge 03: LAWMA, Amerada Pass, LA [8764227]
    def gauge_location_afteraxes3(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[3],
                                        format_string='ko',
                                        add_labels=True)

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 03 Location'
    plotaxes.scaled = True
    plotaxes.xlimits = [-91.34 - 0.2, -91.34 + 0.2]
    plotaxes.ylimits = [29.45 - 0.2, 29.45 + 0.2]
    plotaxes.afteraxes = gauge_location_afteraxes3
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    # Gauge 04: Shell Beach, LA [8761305]
    def gauge_location_afteraxes4(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[4],
                                        format_string='ko',
                                        add_labels=True)

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 04 Location'
    plotaxes.scaled = True
    plotaxes.xlimits = [-89.67 - 0.2, -89.67 + 0.2]
    plotaxes.ylimits = [29.87 - 0.2, 29.87 + 0.2]
    plotaxes.afteraxes = gauge_location_afteraxes4
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    # Gauge 05: Pilots Station East, S.W. Pass, LA [8760922]
    def gauge_location_afteraxes5(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[5],
                                        format_string='ko',
                                        add_labels=True)

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 05 Location'
    plotaxes.scaled = True
    plotaxes.xlimits = [-89.41 - 0.2, -89.41 + 0.2]
    plotaxes.ylimits = [28.93 - 0.2, 28.93 + 0.2]
    plotaxes.afteraxes = gauge_location_afteraxes5
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    plotdata.printfigs = True  # print figures
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = 'all'  # list of frames to print
    plotdata.print_gaugenos = [1, 2, 3, 4, 5]  # list of gauges to print
    plotdata.print_fignos = 'all'  # list of figures to print
    plotdata.html = True  # create html files of plots?
    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  # parallel plotting

    return plotdata
示例#9
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'))

    # 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(2016,6,20-1,0) - datetime.datetime(2016,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]
    # 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 Domain
    # ========================================================================
    entire_domain_xlimits = [clawdata.lower[0],clawdata.upper[0]]
    entire_domain_ylimits = [clawdata.lower[1],clawdata.upper[1]]
    entire_domain_shrink = 0.9
    def entire_domain_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 = entire_domain_xlimits
    plotaxes.ylimits = entire_domain_ylimits
    plotaxes.afteraxes = entire_domain_after_axes

    surge.add_surface_elevation(plotaxes, plot_type='contourf', 
                                               contours=surface_contours,
                                               shrink=entire_domain_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 = entire_domain_xlimits
    plotaxes.ylimits = entire_domain_ylimits
    plotaxes.afteraxes = entire_domain_after_axes

    # Speed
    surge.add_speed(plotaxes, plot_type='contourf', 
                                   contours=speed_contours, 
                                   shrink=entire_domain_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)    

    # ==========================
    #  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 = entire_domain_xlimits
    plotaxes.ylimits = entire_domain_ylimits
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = entire_domain_after_axes
    plotaxes.scaled = True
    
    surge.add_pressure(plotaxes, bounds=pressure_limits, shrink=entire_domain_shrink)
    surge.add_land(plotaxes)
    plotaxes.plotitem_dict['pressure'].amr_patchedges_show = [0,0,0,0,0,0,0]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0,0,0,0,0,0,0]
    
    # 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 = entire_domain_xlimits
    plotaxes.ylimits = entire_domain_ylimits
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = entire_domain_after_axes
    plotaxes.scaled = True
    
    surge.add_wind(plotaxes, bounds=wind_limits, plot_type='pcolor',
                                  shrink=entire_domain_shrink)
    surge.add_land(plotaxes)
    # plotaxes.plotitem_dict['wind'].amr_patchedges_show = [0,0,0,0,0,0,0]
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0,0,0,0,0,0,0]

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

    # 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 = []          # 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 = []          # 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
示例#10
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'
    plotdata.format = 'ascii'

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

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

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

    # Color limits
    surface_range = 4.5
    speed_range = 1.0
    # speed_range = 1.e-2

    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]
    friction_bounds = [0.01, 0.04]
    vorticity_limits = [-1.e-2, 1.e-2]
    land_bounds = [-10, 50]

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # Limits for plots
    regions = {
        'Full Domain': {
            "xlimits": [claw_data.lower[0], claw_data.upper[0]],
            "ylimits": [claw_data.lower[1], claw_data.upper[1]],
            "shrink": 1.0,
            "figsize": [6.4, 4.8]
        },
        'Mumbai Region': {
            "xlimits": [70, 75],
            "ylimits": [17, 22],
            "shrink": 1.0,
            "figsize": [6.4, 4.8]
        },
        'Mumbai': {
            "xlimits": [72.6, 73.15],
            "ylimits": [18.80, 19.25],
            "shrink": 1.0,
            "figsize": [6.4, 4.8]
        }
    }

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

    for (name, region_dict) in regions.items():
        # ========================================================================
        #  Surface Elevations
        # ========================================================================
        plotfigure = plotdata.new_plotfigure(name='Surface - %s' % name)
        plotfigure.show = True

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

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

        surgeplot.add_surface_elevation(plotaxes,
                                        bounds=surface_limits,
                                        shrink=region_dict['shrink'])
        surgeplot.add_land(plotaxes, bounds=land_bounds)

        plotaxes.plotitem_dict['land'].amr_patchedges_show = [1, 0, 0]
        plotaxes.plotitem_dict['surface'].amr_patchedges_show = [1, 0, 0]

        # ========================================================================
        #  Water Speed
        # ========================================================================
        plotfigure = plotdata.new_plotfigure(name='Currents - %s' % name)
        plotfigure.show = True

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

        surgeplot.add_speed(plotaxes,
                            bounds=speed_limits,
                            shrink=region_dict['shrink'])
        surgeplot.add_land(plotaxes, bounds=land_bounds)

    # ========================================================================
    # Hurricane forcing - Entire Atlantic
    # ========================================================================
    # Friction field
    plotfigure = plotdata.new_plotfigure(name='Friction')
    plotfigure.show = False

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Full Domain']['xlimits']
    plotaxes.ylimits = regions['Full Domain']['ylimits']
    plotaxes.title = "Manning's N Coefficients"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surgeplot.add_friction(plotaxes, bounds=friction_bounds)

    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure')
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Full Domain']['xlimits']
    plotaxes.ylimits = regions['Full Domain']['ylimits']
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surgeplot.add_pressure(plotaxes, bounds=pressure_limits)
    surgeplot.add_land(plotaxes, bounds=[-10, 500])

    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed')
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes()

    plotaxes.xlimits = regions['Full Domain']['xlimits']
    plotaxes.ylimits = regions['Full Domain']['ylimits']
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surgeplot.add_wind(plotaxes, bounds=wind_limits, plot_type='imshow')
    surgeplot.add_land(plotaxes, bounds=[-10, 500])
    # ========================================================================
    #  Figures for gauges
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface & topo', figno=300, \
                    type='each_gauge')
    plotfigure.show = True
    plotfigure.clf_each_gauge = True

    def gauge_afteraxes(cd):

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

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

#    def gauge_afteraxes(cd):
#        station_id, station_name = stations[cd.gaugeno-1]
#        seconds_rel_landfall, actual_level = get_actual_water_levels(station_id)
#
#        axes = plt.gca()
#        #surgeplot.plot_landfall_gauge(cd.gaugesoln, axes, landfall=landfall)
#        axes.plot(seconds_rel_landfall, actual_level, 'g')
#
#        # Fix up plot - in particular fix time labels
#        axes.set_title(station_name)
#        axes.set_xlabel('Seconds relative to landfall')
#        axes.set_ylabel('Surface (m)')
#        axes.set_xlim([days2seconds(-2), days2seconds(1)])
#        axes.set_ylim([0, 4])
#        axes.set_xticks([ days2seconds(-2), days2seconds(-1), 0,
#days2seconds(1)])
#axes.set_xticklabels([r"$-3$", r"$-2$", r"$-1$", r"$0$", r"$1$"])
#axes.grid(True)

#     def current_afterxes(cd):
#         station_id, station_name = stations[cd.gaugeno-1]
#         if len(station_id)==6:
#             seconds_rel_landfall, currents = get_actual_currents(station_id)
#
#             axes = plt.gca()
#             #surgeplot.plot_landfall_gauge(cd.gaugesoln, axes,
#             landfall=landfall)
#             axes.plot(seconds_rel_landfall, currents, 'g')
#
#             # Fix up plot - in particular fix time labels
#             axes.set_title(station_name)
#             axes.set_xlabel('Seconds relative to landfall')
#             axes.set_ylabel('Surface (m)')
#             axes.set_xlim([days2seconds(-2), days2seconds(1)])
#             axes.set_xticks([ days2seconds(-2), days2seconds(-1), 0,
#             days2seconds(1)])
#             #axes.set_xticklabels([r"$-3$", r"$-2$", r"$-1$", r"$0$", r"$1$"])
#             #axes.grid(True)

# Set up for axes in this figure:

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.afteraxes = gauge_afteraxes

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

    # Speeds

    #    plotfigure = plotdata.new_plotfigure(name='Currents', figno=400, \
    #                        type='each_gauge')
    #    plotfigure.show = True
    #    plotfigure.clf_each_gauge = True

    #    plotaxes = plotfigure.new_plotaxes()
    #plotaxes.afteraxes = current_afterxes
    # plotaxes.axescmd = 'subplot(122)'
    # try:
    #     plotaxes.xlimits = [amrdata.t0, amrdata.tfinal]
    # except:
    #     pass
    # plotaxes.ylimits = surface_limits
    #plotaxes.title = 'Momenta'
    # plotaxes.afteraxes = surge.gauge_afteraxes

    #    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    #    plotitem.plot_var = calc_currents
    #    plotitem.plotstyle = 'r-.'
    #plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    #plotitem.plot_var = 2
    #plotitem.plotstyle = 'b-'

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

    # 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
示例#11
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
示例#12
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?
    if storm_num == 1:
        # Storm 1
        landfall_dt = datetime.datetime(1997, 11, 15, 3) - datetime.datetime(
            1997, 1, 1, 0)
    elif storm_num == 2:
        # Storm 2
        landfall_dt = datetime.datetime(2008, 12, 17, 0) - 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)

    # Color limits
    surface_range = 5.0
    speed_range = 3.0
    eta = physics.sea_level
    if not isinstance(eta, list):
        eta = [eta]
    surface_limits = [-5.0, 5.0]
    # 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, 50]
    # 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 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
    # ==========================================================================
    # ==========================================================================
    regions = {
        "Full Domain (Grids)": [[clawdata.lower[0], clawdata.upper[0]],
                                [clawdata.lower[1], clawdata.upper[1]],
                                [1, 1, 1, 1, 1, 1, 1]],
        "Mumbai Regio (Grids)": [[70, 75], [17, 22], [1, 1, 1, 1, 1, 1, 1]],
        "Mumbai (Grids)": [[72.6, 73.15], [18.80, 19.25],
                           [1, 1, 1, 1, 1, 1, 1]],
        "Full Domain (No Grids)": [[clawdata.lower[0], clawdata.upper[0]],
                                   [clawdata.lower[1], clawdata.upper[1]],
                                   [0, 0, 0, 0, 0, 0, 0]],
        "Mumbai Region (No Grids)": [[70, 75], [17, 22], [0, 0, 0, 0, 0, 0,
                                                          0]],
        "Mumbai (No Grids)": [[72.6, 73.15], [18.80, 19.25],
                              [0, 0, 0, 0, 0, 0, 0]]
    }
    full_xlimits = regions['Full Domain (Grids)'][0]
    full_ylimits = regions['Full Domain (Grids)'][1]

    for (name, region_data) in regions.iteritems():

        #
        #  Surface
        #
        plotfigure = plotdata.new_plotfigure(
            name='Surface - %s' % name, 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 = region_data[0]
        plotaxes.ylimits = region_data[1]
        plotaxes.afteraxes = afteraxes

        surge.add_surface_elevation(plotaxes,
                                    plot_type='pcolor',
                                    bounds=surface_limits)
        # surge.add_surface_elevation(plotaxes, plot_type='contourf',
        #                                        contours=surface_contours)
        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['land'].amr_patchedges_show = region_data[2]
        plotaxes.plotitem_dict['surface'].amr_patchedges_show = region_data[2]

        #
        #  Water Speed
        #
        plotfigure = plotdata.new_plotfigure(
            name='Currents - %s' % name, 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 = region_data[0]
        plotaxes.ylimits = region_data[1]
        plotaxes.afteraxes = afteraxes

        # Speed
        surge.add_speed(plotaxes, plot_type='pcolor', bounds=speed_limits)
        # surge.add_speed(plotaxes, plot_type='contourf', contours=speed_contours)
        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, topo_min=-10.0, topo_max=5.0)

        plotaxes.plotitem_dict['speed'].amr_patchedges_show = region_data[2]
        plotaxes.plotitem_dict['land'].amr_patchedges_show = region_data[2]

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

    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 = full_xlimits
    plotaxes.ylimits = full_ylimits
    # plotaxes.title = "Manning's N Coefficient"
    plotaxes.afteraxes = friction_after_axes
    plotaxes.scaled = True

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

    # ==========================
    #  Hurricane Forcing fields
    # ==========================
    grids = [[0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1]]
    label = ["(No Grids)", "(Grids)"]
    for i in xrange(2):
        # Pressure field
        plotfigure = plotdata.new_plotfigure(
            name='Pressure %s' % label[i], 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 = afteraxes
        plotaxes.scaled = True

        surge.add_pressure(plotaxes, bounds=pressure_limits)
        surge.add_land(plotaxes)
        plotaxes.plotitem_dict['pressure'].amr_patchedges_show = grids[i]
        plotaxes.plotitem_dict['land'].amr_patchedges_show = grids[i]

        # Wind field
        plotfigure = plotdata.new_plotfigure(
            name='Wind Speed %s' % label[i],
            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 = afteraxes
        plotaxes.scaled = True

        surge.add_wind(plotaxes, bounds=wind_limits, plot_type='pcolor')
        surge.add_land(plotaxes)
        plotaxes.plotitem_dict['wind'].amr_patchedges_show = grids[i]
        plotaxes.plotitem_dict['land'].amr_patchedges_show = grids[i]

    # =====================
    #  Gauge Location Plot
    # =====================
    gauge_xlimits = regions["Mumbai (Grids)"][0]
    gauge_ylimits = regions["Mumbai (Grids)"][1]

    # 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)
        # import pdb; pdb.set_trace()
        surge.gauge_locations(cd, gaugenos=[1, 2, 3])
        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='pcolor',
                                bounds=surface_limits)
    # surge.plot.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]

    # ========================================================================
    #  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]:
            axes = plt.gca()

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

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

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

    # 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]  # 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]  # 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
示例#13
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(2013,10,5,0) - datetime.datetime(2013,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):
        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

    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]


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

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

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

    # 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
示例#14
0
def setplot(plotdata=None):
    """"""

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

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

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

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

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

    # Color limits
    surface_limits = [physics.sea_level - 5.0, physics.sea_level + 5.0]
    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, 3.0]
    speed_ticks = [0, 1, 2, 3]
    speed_labels = [str(value) for value in speed_ticks]
    wind_limits = [0, 66]
    pressure_limits = [909, 1013]
    friction_bounds = [0.01, 0.04]

    def add_custom_colorbar_ticks_to_axes(axes,
                                          item_name,
                                          ticks,
                                          tick_labels=None):
        """Adjust colorbar ticks and labels"""
        axes.plotitem_dict[item_name].colorbar_ticks = ticks
        axes.plotitem_dict[item_name].colorbar_tick_labels = tick_labels

    def gulf_after_axes(cd):
        # plt.subplots_adjust(left=0.08, bottom=0.04, right=0.97, top=0.96)
        surge_afteraxes(cd)

    def latex_after_axes(cd):
        # plt.subplot_adjust()
        surge_afteraxes(cd)

    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)

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    regions = {
        "Coast": {
            "xlimits": (clawdata.lower[0], clawdata.upper[0]),
            "ylimits": (clawdata.lower[1], clawdata.upper[1]),
            "figsize": (8, 7.5)
        },
        "Zhapo Station": {
            "xlimits": (111.71666667, 111.91666667),
            "ylimits": (21.48333333, 21.68333333),
            "figsize": (6, 6)
        },
        "Landfall": {
            "xlimits": (112.26, 112.86),
            "ylimits": (21.3, 21.7),
            "figsize": (6, 4)
        },
        "Quarry Bay": {
            "xlimits": (114.11333333, 114.31333333),
            "ylimits": (22.19111111, 22.39111111),
            "figsize": (6, 6)
        }
    }

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

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

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

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

        surgeplot.add_speed(plotaxes, bounds=speed_limits)
        surgeplot.add_land(plotaxes)
        plotaxes.plotitem_dict['speed'].amr_patchedges_show = [0] * 10
        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10
        add_custom_colorbar_ticks_to_axes(plotaxes, 'speed', speed_ticks,
                                          speed_labels)

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

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

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

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

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

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

    def gauge_afteraxes(cd):

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

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

    plotaxes.afteraxes = gauge_afteraxes

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

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

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

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

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

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

    plotdata.printfigs = True  # print figures
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = 'all'  # list of frames to print
    plotdata.print_gaugenos = [1, 2]  # list of gauges to print
    plotdata.print_fignos = 'all'  # list of figures to print
    plotdata.html = True  # create html files of plots?
    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  # parallel plotting

    return plotdata
示例#15
0
def setplot(plotdata):
    r"""Setplot function for surge plotting"""
    

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

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

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

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

    # Color limits
    surface_range = 1.5
    speed_range = 1.0
    # speed_range = 1.e-2

    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]
    friction_bounds = [0.01, 0.04]
    vorticity_limits = [-1.e-2, 1.e-2]
    land_bounds = [-10, 50]
    
    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # Limits for plots
    regions = {'Full Domain': {"xlimits": [clawdata.lower[0], clawdata.upper[0]],
                               "ylimits": [clawdata.lower[1], clawdata.upper[1]],
                               "shrink": 1.0, 
                               "figsize": [6.4, 4.8]},
               'Tri-State Region': {"xlimits": [-74.5,-71.0], 
                                    "ylimits": [40.0,41.5], 
                                    "shrink": 1.0,
                                    "figsize": [6.4, 4.8]},
                'NYC': {"xlimits": [-74.2,-73.8], 
                        "ylimits": [40.55,40.85], 
                        "shrink": 1.0, 
                        "figsize": [6.4, 4.8]}
               }
    
    for (name, region_dict) in regions.items():
        # ========================================================================
        #  Surface Elevations
        # ========================================================================
        plotfigure = plotdata.new_plotfigure(name='Surface - %s' % name)
        plotfigure.show = True

        # Set up for axes in this figure:
        plotaxes = plotfigure.new_plotaxes()
        plotaxes.title = 'Surface'
        plotaxes.scaled = True
        plotaxes.xlimits = region_dict['xlimits']
        plotaxes.ylimits = region_dict['ylimits']
        plotaxes.afteraxes = surge_afteraxes
    
        surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits, 
                                    shrink=region_dict['shrink'])
        surgeplot.add_land(plotaxes, bounds=land_bounds)
        
        # plotaxes.plotitem_dict['land'].amr_patchedges_show = 
        # plotaxes.plotitem_dict['surface'].amr_patchedges_show = 


        # ========================================================================
        #  Water Speed
        # ========================================================================
        plotfigure = plotdata.new_plotfigure(name='Currents - %s' % name)
        plotfigure.show = True

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

        surgeplot.add_speed(plotaxes, bounds=speed_limits, 
                        shrink=region_dict['shrink'])
        surgeplot.add_land(plotaxes, bounds=land_bounds)


    # ========================================================================
    # Hurricane forcing - Entire Atlantic
    # ========================================================================
    # Friction field
    plotfigure = plotdata.new_plotfigure(name='Friction')
    plotfigure.show = False

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Full Domain']['xlimits']
    plotaxes.ylimits = regions['Full Domain']['ylimits']
    plotaxes.title = "Manning's N Coefficients"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surgeplot.add_friction(plotaxes,bounds=friction_bounds)

    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure')
    plotfigure.show = True
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Full Domain']['xlimits']
    plotaxes.ylimits = regions['Full Domain']['ylimits']
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    
    surgeplot.add_pressure(plotaxes,bounds=pressure_limits)
    surgeplot.add_land(plotaxes, bounds=[-10, 500])
    
    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed')
    plotfigure.show = True
    
    plotaxes = plotfigure.new_plotaxes()

    plotaxes.xlimits = regions['Full Domain']['xlimits']
    plotaxes.ylimits = regions['Full Domain']['ylimits']
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    
    surgeplot.add_wind(plotaxes,bounds=wind_limits,plot_type='imshow')
    surgeplot.add_land(plotaxes, bounds=[-10, 500])

    # ========================================================================
    #  Figures for gauges
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface, Speeds',
                                         type='each_gauge')
    plotfigure.show = True
    plotfigure.clf_each_gauge = True

    # Surface and Topography
    plotaxes = plotfigure.new_plotaxes()
    # plotaxes.axescmd = 'subplot(121)'
    try:
        plotaxes.xlimits = [amrdata.t0, amrdata.tfinal]
    except:
        pass
    plotaxes.ylimits = surface_limits
    plotaxes.title = 'Surface'
    # plotaxes.afteraxes = surgeplot.gauge_afteraxes
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 3
    plotitem.plotstyle = 'b-'

    # Speeds
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.axescmd = 'subplot(122)'
    try:
        plotaxes.xlimits = [amrdata.t0, amrdata.tfinal]
    except:
        pass
    plotaxes.ylimits = surface_limits
    plotaxes.title = 'Momenta'
    # plotaxes.afteraxes = surge.gauge_afteraxes

    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 1
    plotitem.plotstyle = 'r-'
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 2
    plotitem.plotstyle = 'b-'

    #-----------------------------------------
    
    # 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
示例#16
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 = clawpack.clawutil.data.ClawInputData(2)
    clawdata.read('claw.data')
    physics = clawpack.geoclaw.data.GeoClawData()
    physics.read(os.path.join(plotdata.outdir,'geoclaw.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(2011,8,27,7,30) - datetime.datetime(2011,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 = [clawdata.lower[0],clawdata.upper[0]]
    full_ylimits = [clawdata.lower[1],clawdata.upper[1]]
    full_shrink = 0.8
    newyork_xlimits = [-74.2,-73.7]
    newyork_ylimits = [40.4,40.85]
    newyork_shrink = 1.0

    # Color limits
    surface_range = 1.5
    speed_range = 1.0
    # speed_range = 1.e-2

    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]
    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)
    
    def contour_afteraxes(current_data):
        surge_afteraxes(current_data)

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

    # ========================================================================
    #  Surface Elevations - Entire Atlantic
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface - Atlantic',  
                                         figno=100)
    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,shrink=full_shrink)
    surge.add_land(plotaxes)


    # ========================================================================
    #  Water Speed - Entire Atlantic
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Currents - Atlantic',  
                                         figno=200)
    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,shrink=full_shrink)

    # Land
    surge.add_land(plotaxes)

    # ========================================================================
    #  Surface Elevations - New York Area
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface - New York',  
                                         figno=300)
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Surface'
    plotaxes.scaled = True
    plotaxes.xlimits = newyork_xlimits
    plotaxes.ylimits = newyork_ylimits
    def after_with_gauges(cd):
        surge_afteraxes(cd)
        surge.gauge_locations(cd)
    plotaxes.afteraxes = after_with_gauges
    
    surge.add_surface_elevation(plotaxes,bounds=surface_limits,shrink=newyork_shrink)
    surge.add_land(plotaxes)

    # ========================================================================
    #  Currents Elevations - New York Area
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Currents - New York',  
                                         figno=400)
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Currents'
    plotaxes.scaled = True
    plotaxes.xlimits = newyork_xlimits
    plotaxes.ylimits = newyork_ylimits
    def after_with_gauges(cd):
        surge_afteraxes(cd)
        surge.gauge_locations(cd)
    plotaxes.afteraxes = after_with_gauges
    
    surge.add_speed(plotaxes,bounds=speed_limits,shrink=newyork_shrink)
    surge.add_land(plotaxes)


    # ========================================================================
    # Hurricane forcing - Entire Atlantic
    # ========================================================================
    # Friction field
    plotfigure = plotdata.new_plotfigure(name='Friction',
                                         figno=500)
    plotfigure.show = friction_data.variable_friction and True

    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.add_friction(plotaxes,bounds=friction_bounds)

    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure',  
                                         figno=600)
    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.add_pressure(plotaxes,bounds=pressure_limits)
    # add_pressure(plotaxes)
    surge.add_land(plotaxes)
    
    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed', 
                                         figno=700)
    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.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)
    
    # Surge field
    plotfigure = plotdata.new_plotfigure(name='Surge Field', 
                                         figno=800)
    plotfigure.show = ((surge_data.wind_forcing or surge_data.pressure_forcing) 
                        and False)
    
    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.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.add_land(plotaxes)

    plotfigure = plotdata.new_plotfigure(name='Friction/Coriolis Source', 
                                         figno=900)
    plotfigure.show = False
    
    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.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.add_land(plotaxes)

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Topography'
    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_cmin = 0
    plotitem.imshow_cmax = 200
    plotitem.imshow_cmap = plt.get_cmap("terrain")
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1,1,1,1,1,1,1]

    # ========================================================================
    #  Figures for gauges
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface',   
                                         figno=250,type='each_gauge')
    plotfigure.show = True
    plotfigure.clf_each_gauge = True
 
    stations = [('8518750', 'The Battery, NY'),
                ('8516945', 'Kings Point, NY'),
                ('8519483', 'Bergen Point West Reach, NY')]
                #('8531680','Sandy Hook, NY'),
                #('n03020','Narrows,NY')]
  
    landfall_time = np.datetime64('2011-08-27T11:30')
    begin_date = datetime.datetime(2011, 8, 24 )
    end_date = datetime.datetime(2011, 8, 28)

# need to uncomment this function if you want to compare with real data from NOAA
#    def get_actual_water_levels(station_id):
#        # Fetch water levels and tide predictions for given station
#        date_time, water_level, tide = fetch_noaa_tide_data(station_id,
#                begin_date, end_date)

        # Calculate times relative to landfall
#        seconds_rel_landfall = (date_time - landfall_time) / np.timedelta64(1, 's')
        # Subtract tide predictions from measured water levels
#        water_level -= tide

 #       return seconds_rel_landfall, water_level

 
    def gauge_afteraxes(cd):
        station_id, station_name = stations[cd.gaugeno-1]
# uncomment the next line to plot against real NOAA data
#        seconds_rel_landfall, actual_level = get_actual_water_levels(station_id)

        axes = plt.gca()
        #surgeplot.plot_landfall_gauge(cd.gaugesoln, axes, landfall=landfall)
# uncomment the next line to plot against real NOAA data 
#       axes.plot(seconds_rel_landfall, actual_level, 'g')

        # Fix up plot - in particular fix time labels
        axes.set_title(station_name)
        axes.set_xlabel('Seconds relative to landfall')
        axes.set_ylabel('Surface (m)')
        axes.set_ylim([0, 4])
#        axes.set_xticks([ days2seconds(-2), days2seconds(-1), 0, days2seconds(1)])
        #axes.set_xticklabels([r"$-3$", r"$-2$", r"$-1$", r"$0$", r"$1$"])
        #axes.grid(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 = gauge_afteraxes

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

    # # Speeds
    # plotaxes = plotfigure.new_plotaxes()
    # plotaxes.axescmd = 'subplot(122)'
    # try:
    #     plotaxes.xlimits = [amrdata.t0,amrdata.tfinal]
    # except:
    #     pass
    # plotaxes.ylimits = surface_limits
    # plotaxes.title = 'Momenta'
    # plotaxes.afteraxes = surge.gauge_afteraxes

    # plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    # plotitem.plot_var = 1
    # plotitem.plotstyle = 'r-'
    # plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    # plotitem.plot_var = 2
    # plotitem.plotstyle = 'b-'




    #-----------------------------------------
    
    # 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
示例#17
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(2013, 10, 5, 0) - datetime.datetime(
        2013, 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):
        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

    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]

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

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

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

    # 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
示例#18
0
def setplot(plotdata):
    r"""Setplot function for surge plotting"""


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

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

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

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

    # Color limits
    surface_range = 1.0
    speed_range = 1.0
    # speed_range = 1.e-2

    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]
    friction_bounds = [0.01, 0.04]
    vorticity_limits = [-1.e-2, 1.e-2]
    land_bounds = [-10, 50]


    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # Limits for plots
    regions = {'Full Domain': {"xlimits": [claw_data.lower[0], claw_data.upper[0]],
                               "ylimits": [claw_data.lower[1], claw_data.upper[1]],
                               "shrink": 1.0,
                               "figsize": [6.4, 4.8]}
               }
    def gauge_location_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata, gaugenos='all',
                                        format_string='ko', add_labels=True)

    for (name, region_dict) in regions.items():
        # ========================================================================
        #  Surface Elevations
        # ========================================================================
        plotfigure = plotdata.new_plotfigure(name='Surface - %s' % name)
        plotfigure.show = True

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

        surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits,
                                    shrink=region_dict['shrink'])
        surgeplot.add_land(plotaxes, bounds=land_bounds)

        plotaxes.plotitem_dict['land'].amr_patchedges_show = [1,0,0]
        plotaxes.plotitem_dict['surface'].amr_patchedges_show = [1,0,0]


        # ========================================================================
        #  Water Speed
        # ========================================================================
        plotfigure = plotdata.new_plotfigure(name='Currents - %s' % name)
        plotfigure.show = True

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

        surgeplot.add_speed(plotaxes, bounds=speed_limits,
                        shrink=region_dict['shrink'])
        surgeplot.add_land(plotaxes, bounds=land_bounds)



    # ========================================================================
    # Hurricane forcing - Entire Atlantic
    # ========================================================================
    # Friction field
    plotfigure = plotdata.new_plotfigure(name='Friction')
    plotfigure.show = False

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Full Domain']['xlimits']
    plotaxes.ylimits = regions['Full Domain']['ylimits']
    plotaxes.title = "Manning's N Coefficients"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surgeplot.add_friction(plotaxes,bounds=friction_bounds)

    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure')
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Full Domain']['xlimits']
    plotaxes.ylimits = regions['Full Domain']['ylimits']
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surgeplot.add_pressure(plotaxes,bounds=pressure_limits)
    surgeplot.add_land(plotaxes, bounds=[-10, 500])

    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed')
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes()

    plotaxes.xlimits = regions['Full Domain']['xlimits']
    plotaxes.ylimits = regions['Full Domain']['ylimits']
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surgeplot.add_wind(plotaxes,bounds=wind_limits,plot_type='imshow')
    surgeplot.add_land(plotaxes, bounds=[-10, 500])
    # ========================================================================
    #  Figures for gauges
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface & topo', figno=300, \
                    type='each_gauge')
    plotfigure.show = True
    plotfigure.clf_each_gauge = True

    stations = [('8518750', 'The Battery, NY'),
                ('8516945', 'Kings Point, NY'),
                ('8519483', 'Bergen Point West Reach, NY')]
                #('8531680','Sandy Hook, NY'),
                #('n03020','Narrows,NY')]

    landfall_time = np.datetime64('2012-10-29T23:30')
    begin_date = datetime.datetime(2012, 10, 28)
    end_date = datetime.datetime(2012, 10, 31,)

    def get_actual_water_levels(station_id):
        # Fetch water levels and tide predictions for given station
        date_time, water_level, tide = fetch_noaa_tide_data(station_id,
                begin_date, end_date)

        # Calculate times relative to landfall
        seconds_rel_landfall = (date_time - landfall_time) / np.timedelta64(1, 's')
        # Subtract tide predictions from measured water levels
        water_level -= tide

        return seconds_rel_landfall, water_level

    # def get_actual_current(station_id):
    #     # Fetch currents for given station_name
    #     date_time, water_level, tide, currents = fetch_noaa_tide_data(station_id,
    #             begin_date, end_date)
    #
    #     # calculate times relative to landfall_time
    #     secs_rel_landfall = (date_time - landfall_time) / np.timedelta64(1, 's')
    #     return secs_rel_landfall, currents
    #
    # def calc_currents(cd):
    #     height = cd.q[0,:]
    #     where_zero = np.where(height == 0)[0]
    #     for index in where_zero:
    #         height[index] = 1
    #     vel_magnitude = (cd.q[1,:]/height)**2 + (cd.q[2,:]/height)**2
    #     vel_magnitude = vel_magnitude**0.5
    #     return vel_magnitude

    def gauge_afteraxes(cd):
        station_id, station_name = stations[cd.gaugeno-1]
        seconds_rel_landfall, actual_level = get_actual_water_levels(station_id)

        axes = plt.gca()
        #surgeplot.plot_landfall_gauge(cd.gaugesoln, axes, landfall=landfall)
        axes.plot(seconds_rel_landfall, actual_level, 'g')

        # Fix up plot - in particular fix time labels
        axes.set_title(station_name)
        axes.set_xlabel('Seconds relative to landfall')
        axes.set_ylabel('Surface (m)')
        axes.set_xlim([days2seconds(-2), days2seconds(1)])
        axes.set_ylim([0, 4])
        axes.set_xticks([ days2seconds(-2), days2seconds(-1), 0, days2seconds(1)])
        #axes.set_xticklabels([r"$-3$", r"$-2$", r"$-1$", r"$0$", r"$1$"])
        #axes.grid(True)

    # def current_afterxes(cd):
    #     station_id, station_name = stations[cd.gaugeno-1]
    #     if len(station_id)==6:
    #         seconds_rel_landfall, currents = get_actual_currents(station_id)
    #
    #         axes = plt.gca()
    #         #surgeplot.plot_landfall_gauge(cd.gaugesoln, axes, landfall=landfall)
    #         axes.plot(seconds_rel_landfall, currents, 'g')
    #
    #         # Fix up plot - in particular fix time labels
    #         axes.set_title(station_name)
    #         axes.set_xlabel('Seconds relative to landfall')
    #         axes.set_ylabel('Surface (m)')
    #         axes.set_xlim([days2seconds(-2), days2seconds(1)])
    #         axes.set_xticks([ days2seconds(-2), days2seconds(-1), 0, days2seconds(1)])
    #         #axes.set_xticklabels([r"$-3$", r"$-2$", r"$-1$", r"$0$", r"$1$"])
    #         #axes.grid(True)
    #
    #


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

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


    # Speeds

#    plotfigure = plotdata.new_plotfigure(name='Currents', figno=400, \
#                        type='each_gauge')
#    plotfigure.show = True
#    plotfigure.clf_each_gauge = True

#    plotaxes = plotfigure.new_plotaxes()
    #plotaxes.afteraxes = current_afterxes
   # plotaxes.axescmd = 'subplot(122)'
   # try:
   #     plotaxes.xlimits = [amrdata.t0, amrdata.tfinal]
   # except:
   #     pass
   # plotaxes.ylimits = surface_limits
    #plotaxes.title = 'Momenta'
    # plotaxes.afteraxes = surge.gauge_afteraxes

#    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
#    plotitem.plot_var = calc_currents
#    plotitem.plotstyle = 'r-.'
    #plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    #plotitem.plot_var = 2
    #plotitem.plotstyle = 'b-'

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

    # 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
示例#19
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
    from numpy import linspace

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

    # Load data from output
    clawdata = clawutil.ClawInputData(2)
    clawdata.read(os.path.join(plotdata.outdir,'claw.data'))

    ocean_xlimits = [clawdata.lower[0],clawdata.upper[0]]
    ocean_ylimits = [clawdata.lower[1],clawdata.upper[1]]

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

    probdata = clawutil.ClawData()
    #probdata.read('setprob.data', force=True)
    #theta_island = probdata.theta_island


    # 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 mynewafteraxes(current_data):
        addgauges(current_data)
        bigfont(current_data)



    #-----------------------------------------
    # Some global KML settings
    #-----------------------------------------
    #plotdata.kml_publish = 'http://math.boisestate.edu/~calhoun/visclaw/GoogleEarth/kmz/' #public html
    plotdata.kml_publish = None
    plotdata.kml_name = "NYC Asteroid" # name appears in Google Earth display only
    plotdata.kml_index_fname = "NYC_Asteroid" # name for .kmz and .kml files ["_GoogleEarth"]

    # specify beginning of slider time. if not used, assumes Jan. 1 1970
    plotdata.kml_starttime = [2115,4,29,7,32,0]   # Asteroid hits at 1:32AM, 4/29/2115 (UTC)
    plotdata.kml_tz_offset = 6   # off set to UTC
    # for todays date as the default use 

    kml_cmin = -0.005   #colorbar min and max
    kml_cmax = 0.005
    kml_dpi = 400       # only used if individual figures dpi not set
    kml_cmap = geoplot.googleearth_lightblue
#    kml_cmap = geoplot.googleearth_darkblue
#    kml_cmap = geoplot.googleearth_transparent
#    kml_cmap = geoplot.googleearth_white

    def kml_colorbar(filename):
        #cmin = -0.01
        #cmax = 0.01
        geoplot.kml_build_colorbar(filename,
                                   kml_cmap,
                                   kml_cmin,kml_cmax)

    #-----------------------------------------
    # Figure for pcolor plot for surface
    #-----------------------------------------
    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
    plotaxes.afteraxes = addgauges

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    #plotitem.plot_var = 0/1/2 or plot that entry into q instead of a function
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmin = -8.
    plotitem.pcolor_cmax = 8.
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [0,0,0]
    #amr_data_show=[True,False,False,False]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.land
    plotitem.show = True
    # plotitem.pcolor_cmap = colormaps.all_white  # to print better in B&W
    plotitem.pcolor_cmap = geoplot.land_colors
    #plotitem.pcolor_cmap = geoplot.googleearth_transparent
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0,0,0,0,0]
    #plotitem.patchedges_show = 1
    plotitem.amr_patchedges_show = [0,0,0]
    #plotaxes.xlimits = [-85,-55]
    #plotaxes.ylimits = [25,45]
    plotaxes.xlimits = ocean_xlimits
    plotaxes.ylimits = ocean_ylimits
    #amr_data_show=[True,False,False,False]
    #plotaxes.xlimits = [-75,-70]
    #plotaxes.ylimits = [38,43]


    # add contour lines of bathy if desired:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = True
    plotitem.plot_var = geoplot.topo
    #plotitem.contour_levels = [-500,-250,-100, -50, 0, 50]
    plotitem.contour_levels = linspace(-1000,-100,10)
    plotitem.amr_contour_colors = ['g']  # color on each level
    #plotitem.kwargs = {'linestyles':'dashed','linewidths':2,'colors' : 'red' }
    plotitem.kwargs = {'linestyles':'solid','linewidths':.25,'colors' : 'black' }
    plotitem.amr_contour_show = [1,1,1]
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0


    #-----------------------------------------------------------
    # Figure for KML files - Sea Surface Height
    #----------------------------------------------------------
    #plotfigure = plotdata.new_plotfigure(name='Sea Surface',figno=1)
    #plotfigure.show = True 

    #plotfigure.use_for_kml = True
    #plotfigure.kml_use_for_initial_view = True

    # These overide any values set in the plotitems below
    #plotfigure.kml_xlimits = [-80,-55]
    #plotfigure.kml_ylimits = [25, 45]

    # Resolution
    #plotfigure.kml_dpi = 300
    #plotfigure.kml_tile_images = False

    def kml_colorbar_transparent(filename):
        #cmin = -0.01
        #cmax = 0.01
        geoplot.kml_build_colorbar(filename,
                                   geoplot.googleearth_transparent,
                                   kml_cmin,kml_cmax)

    #plotfigure.kml_colorbar = kml_colorbar_transparent

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

    # Water
    #plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.show = True
    #plotitem.plot_var = geoplot.surface_or_depth
    #plotitem.pcolor_cmap = geoplot.googleearth_transparent
    #plotitem.pcolor_cmin = kml_cmin
    #plotitem.pcolor_cmax = kml_cmax
    #plotitem.amr_celledges_show = [0,0,0]
    #plotitem.patchedges_show = 0

    #plotfigure.kml_colorbar = kml_colorbar


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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    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.xticks(fontsize=15)
    #    pylab.yticks(fontsize=15)
    #plotaxes.afteraxes = fixup

    def speed(current_data):
        from pylab import where,sqrt
        q = current_data.q
        h = q[0,:]
        dry_tol = 0.001
        u = q[1,:] # this is just to initialize
        v = q[2,:] # to correct size
        s = 0*q[2,:] # to correct size

        nq = len(q[1,:])
        [n,m] = h.shape
        for ii in range(0,n):
           for jj in range(0,m):
             if h[ii,jj] > dry_tol:
                u[ii,jj] = q[1,ii,jj]/h[ii,jj]
                v[ii,jj] = q[2,ii,jj]/h[ii,jj]
                s[ii,jj] = sqrt(u[ii,jj]* u[ii,jj] + v[ii,jj]*v[ii,jj])
             else:
                u[ii,jj] = 0.
                v[ii,jj] = 0.
                s[ii,jj] = 0
        #print("max of u = " + str(max(u)))

        #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 = sqrt(u*2+v*v) #try not dividing or using where
        return s

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.show = True 
    plotitem.plot_var = speed
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    #amr_data_show=[True,False,False,False]
    #plotitem.pcolor_cmap = \
    #       colormaps.make_colormap({0:[1,1,1],0.5:[0.5,0.5,1],1:[1,0.3,0.3]})
    plotitem.pcolor_cmin = 0.
    plotitem.pcolor_cmax = .10
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    #plotitem.patchedges_show = 1
    plotitem.amr_patchedges_show = [0,1,0]

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.land
    plotitem.pcolor_cmap = geoplot.land_colors
    plotitem.pcolor_cmin = 0.0
    plotitem.pcolor_cmax = 100.0
    plotitem.add_colorbar = False
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.patchedges_show = 0
    plotaxes.xlimits = ocean_xlimits
    plotaxes.ylimits = ocean_ylimits
    #amr_data_show=[True,False,False,False]


    #-----------------------------------------
    # Figure for zoom around NYC
    #-----------------------------------------
    zoomWanted = True 
    if zoomWanted:
        plotfigure = plotdata.new_plotfigure(name='Zoom1', figno=7)

        # add another figure
        #plotfigure.use_for_kml = True
        #plotfigure.kml_use_for_initial_view = False

        # These overide any values set in the plotitems below
        #plotfigure.kml_xlimits =  [-74.5, -73.5]
        #plotfigure.kml_ylimits = [40.4,40.9]

        # Resolution
        #plotfigure.kml_dpi = 300
        #plotfigure.kml_tile_images = True


        #plotfigure.kml_colorbar = kml_colorbar   # defined above


        # Set up for axes in this figure:
        plotaxes = plotfigure.new_plotaxes('zoom on blast')
        plotaxes.title = 'Surface elevation'
        plotaxes.scaled = True
        #manhattan_island = -73.5
        #xisland,yisland = latlong(1600e3, manhattan_island, 40., Rearth)
        #plotaxes.xlimits = [xisland-0.6, xisland+0.6]
        #plotaxes.xlimits = [manhattan_island-1, manhattan_island+1]
        #plotaxes.ylimits = [40.15,41.5]
        plotaxes.xlimits = [114.50, 116.02]  # really zoom in on lower manhattan]
        plotaxes.ylimits = [12.80,13.86]
        plotaxes.afteraxes = addgauges
        def bigfont(current_data):
            import pylab
            t = current_data.t
            pylab.title("Surface at t = %8.1f" % t, fontsize=20)
            pylab.xticks(fontsize=15)
            pylab.yticks(fontsize=15)
        #plotaxes.afteraxes = bigfont
        #plotaxes.afteraxes = mynewafteraxes   # after axes functions mess with GE plots

        # Water
        plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
        plotitem.show = True
        #plotitem.plot_var = geoplot.surface
        plotitem.plot_var = geoplot.surface_or_depth
        #plotitem.pcolor_cmap = geoplot.tsunami_colormap
        plotitem.pcolor_cmap = kml_cmap
        #plotitem.pcolor_cmin = kml_cmin   # same as above
        #plotitem.pcolor_cmax = kml_cmax
        plotitem.pcolor_cmin = -200.  
        plotitem.pcolor_cmax =  200.
        plotitem.add_colorbar = True 
        plotitem.amr_celledges_show = [0,0,0]
        plotitem.patchedges_show = 1

        # Land
        plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
        plotitem.show = True 
        plotitem.plot_var = geoplot.land
        # plotitem.pcolor_cmap = colormaps.all_white  # to print better in B&W
        plotitem.pcolor_cmap = geoplot.land_colors
        plotitem.pcolor_cmin = 0.0
        plotitem.pcolor_cmax = 100.0
        plotitem.add_colorbar = False
        plotitem.amr_celledges_show = [0,0,0,0,0]
        plotitem.patchedges_show = 0

        # contour lines:
        plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
        #plotitem.show = True 
        plotitem.show = False
        plotitem.plot_var = geoplot.surface
        plotitem.contour_levels = [-0.8, -0.4, 0.4, 0.8]
        plotitem.amr_contour_colors = ['k']  # color on each level
        plotitem.kwargs = {'linewidths':1}
        plotitem.amr_contour_show = [0,0,0,1,1]
        plotitem.celledges_show = 0
        plotitem.patchedges_show = 0

        # add contour lines of bathy if desired:
        plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
        plotitem.show = False
        plotitem.plot_var = geoplot.topo
        plotitem.contour_levels = linspace(-30, -10,3)
        plotitem.amr_contour_colors = ['m']  # color on each level
        plotitem.kwargs = {'linestyles':'dashed','linewidths':1}
        plotitem.amr_contour_show = [1,1,1]
        plotitem.celledges_show = 0
        plotitem.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.xlimits = [0000, 6500]
    #plotaxes.ylimits = [-.10, .15]
    plotaxes.xlimits = 'auto'
    plotaxes.ylimits = 'auto'
    plotaxes.title = 'Surface'

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

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

    def gaugewaveheight(current_data):
        q = current_data.q
        h = q[0,:]
        eta = q[3,:]
        sealevel = 0
        waveheight = eta - sealevel
        return waveheight

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

    def gaugedpress(current_data):
        q = current_data.q
        #dpress = (q[4,:] - 101300)/101300
        dpress = q[4,:]  # already output as relative:  dp/amb_pr
        return dpress

    def gs(current_data):
        q = current_data.q
        # different than speed function because q is function of time, not
        # x,y at the gauges.
        from numpy import where, sqrt
        h = q[0,:]
        #print('shape of h ' +  str(h.shape))
        dry_tol = 0.001
        u = where(h>dry_tol, q[1,:]/h, 0.)
        v = where(h>dry_tol, q[2,:]/h, 0.)
        ssq = sqrt(u*u+v*v)
        #s = sqrt(u**2 + v**2)
        s = sqrt(ssq)
        return ssq

    plotitem.plot_var = gaugewaveheight
    #plotitem.plot_var = gaugetopo
    plotitem.plotstyle = 'b-'

    # Plot relative delta pressure as red curve:
    #plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    #plotitem.plot_var = gaugedpress
    #plotitem.plotstyle = 'r-'

    # add speed to this plot since cant get new one going
    #plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    #plotitem.plot_var = gs
    #plotitem.plotstyle = 'g-'

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

    plotaxes.afteraxes = add_zeroline

    # -------------------------------
    # Figure for speed at gauges
    #--------------------------------

    plotfigure = plotdata.new_plotfigure(name='Speed at gauges', figno=310, \
                    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.xlimits = [0000, 7000]
    #plotaxes.ylimits = 'auto'
    plotaxes.title = 'Speed'
#
#    # Plot surface as blue curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
#    #plotitem.plot_var = speed
    plotitem.plot_var = gs  #gauge_speed
    plotitem.plotstyle = 'g-'
#
    def add_zeroline2(current_data):
        from pylab import plot, legend
        t = current_data.t
        legend(('speed (m/s)','zero'))
        #plot(t, 0*t, 'k')

    plotfigure.show = True
    plotaxes.afteraxes = add_zeroline2

    #-----------------------------------------
    # Figure for bathy alone
    #-----------------------------------------
    def bathy(current_data):
        return current_data.aux[0,:,:]

    plotfigure = plotdata.new_plotfigure(name='bathymetry', figno=3)
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.title = 'Bathymetry'
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = bathy
    plotitem.pcolor_cmin = -3000.00
    plotitem.pcolor_cmax = 500
    plotitem.add_colorbar = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show =  False
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = linspace(-2000,2000,11)
    plotitem.amr_contour_colors = ['k']  # color on each level
    #plotitem.contour_levels = [-1000 -500,-250,-100, -5, 5]

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

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

    # Set up for item on these axes:
    #plotitem = plotaxes.new_plotitem(plot_type='2d_patch')
    #plotitem.amr_patch_bgcolor = ['#ffeeee', '#eeeeff', '#eeffee']
    #plotitem.amr_celledges_show = [0,0,0]
    #plotitem.amr_patchedges_show = [0,0,0]
    
    def normalized_pressure(current_data):
        pressure_index = 6  #7 in fortran, but python is 0 based
        return current_data.aux[pressure_index,:,:]/surge_data.ambient_pressure

    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure',figno=33)
    plotfigure.show = True

    plotaxes = plotfigure.new_plotaxes('normalized_pressure')
    plotaxes.xlimits = ocean_xlimits
    plotaxes.ylimits = ocean_ylimits
    plotaxes.title = 'Pressure Field'
    plotaxes.scaled = True
    plotaxes.afteraxes = addgauges

    pressure_limits = [.99,1.10]
    #pressure_limits = [.999*surge_data.ambient_pressure / 100.0,
    #                   1.001 * surge_data.ambient_pressure / 100.0]
    #pressure_limits = [-.000001*surge_data.ambient_pressure,
    #                   .000001 * surge_data.ambient_pressure]

    surgeplot.add_pressure(plotaxes, bounds=pressure_limits)
    surgeplot.add_land(plotaxes)

    #plotitem = plotaxes.new_plotitem(plot_type='2d_patch')
    plotitem = plotaxes.plotitem_dict['pressure']
    plotitem.show = False
    plotitem.plot_var = normalized_pressure
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [0,0,0]

    plotaxes.plotitem_dict['land'].amr_celledges_show=[0,0,0]
    plotaxes.plotitem_dict['land'].amr_patchedges_show=[0,0,0]

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

    # 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_framenos = [31,32,33]          # list of frames to print
    plotdata.print_gaugenos = 'all'          # list of gauges to print
    #plotdata.print_gaugenos = [7]          # list of gauges to print
    plotdata.print_fignos = [7]  # list of figures to print
    #plotdata.print_fignos = 'all'  # list of figures to print
    #plotdata.print_fignos = [0,7,10,33,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 = 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.kml = False

    return plotdata
示例#20
0
def setplot(plotdata=None):
    """"""

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

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

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

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

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

    # Color limits
    surface_limits = [-5.0, 5.0]
    speed_limits = [0.0, 3.0]
    wind_limits = [0, 64]
    pressure_limits = [935, 1013]
    friction_bounds = [0.01, 0.04]
    color_limits=[0,50]
    def friction_after_axes(cd):
        plt.title(r"Manning's $n$ Coefficient")

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    regions = {"Atlantic": {"xlimits": (clawdata.lower[0], clawdata.upper[0]),
                        "ylimits": (clawdata.lower[1], clawdata.upper[1]),
                        "figsize": (6.4, 4.8)},
	       "Atlantic City, NJ": {"xlimits": (-78, -74),
		       	"ylimits": (32,36),
			"figsize": (10.5, 11.5)},
           "ChesapeakeBay Shelf": {"xlimits": (-77, -75),
                               "ylimits": (36, 38),
                               "figsize": (5, 6)},
	       "Manhattan Shelf": {"xlimits": (-75,-73),
			       "ylimits": (38,40),
			       "figsize": (5,6)},
	       "Sandy Hook, NJ": {"xlimits": (-76,-73),
				"ylimits": (38,41),
				"figsize":(5,6)},
           "New Haven CT": {"xlimits": (-77,-73),
				"ylimits": (39,41),
				"figsize":(5,6)},
              "New London CT": {"xlimits": (-74,-70),
				"ylimits": (39,43),
				"figsize":(5,6)},
              "Boston MA": {"xlimits": (-72,-68),
				"ylimits": (40,44),
				"figsize":(5,6)}}

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

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

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

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

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

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

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

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

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

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

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

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [-3, 3]
    # plotaxes.xlabel = "Days from landfall"
    # plotaxes.ylabel = "Surface (m)"
    plotaxes.ylimits = [0,1.5]
    plotaxes.title = 'Surface'
    #Gauge Data from NOAA
    try:
        gauges = [np.loadtxt('gauge_data_1.txt'), 
	       np.loadtxt('gauge_data_2.txt'), 
	       np.loadtxt('gauge_data3.txt'), 
               np.loadtxt('gauge_data_4.txt'),
               np.loadtxt('gauge_data_5.txt'),
	       np.loadtxt('gauge_data_6.txt')]
        #Legend with Gauge Locations
        data_names = ["Duke Marine Lab, NC Data from NOAA",
                 "Kiptopeke Beach, NC Data from NOAA",
                 "Atlantic City, NJ Data from NOAA",
                 "Sandy Hook, NJ Data from NOAA",
                 "New London, CT Data from NOAA",
                 "Boston, MA Data from NOAA"]
    except:
        print("Add gauge files to directory")
    

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

        # Fix up plot - in particular fix time labels
        axes.set_title('Station %s' % cd.gaugeno)
        axes.set_xlabel('Days relative to landfall')
        axes.set_ylabel('Surface (m)')
        axes.set_xlim([-3, 3])
        axes.set_ylim([0,1.5])
        axes.set_xticks([-3, -2, -1, 0, 1, 2, 3])
        axes.set_xticklabels([r"$-3$",r"$-2$",r"$-1$", r"$0$", r"$1$", r"$2$", r"$3$"])
        axes.grid(True)
        
        
    try:
        gauge_data=gauges[cd.gaugeno-1]
        axes.plot(gauge_data[:,0], gauge_data[:,1], label=data_names[cd.gaugeno-1])
        axes.legend()
    except:
            print('Gauge Data Unavailable')
    plotaxes.afteraxes = gauge_afteraxes
        
    

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

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

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

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

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

    plotdata.printfigs = True                # print figures
    plotdata.print_format = 'png'            # file format
    plotdata.print_framenos = 'all'          # list of frames to print
    plotdata.print_gaugenos = [1, 2, 3, 4, 5, 6]   # list of gauges to print
    plotdata.print_fignos = 'all'            # list of figures to print
    plotdata.html = True                     # create html files of plots?
    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                 # parallel plotting

    return plotdata
示例#21
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 = clawpack.clawutil.data.ClawInputData(2)
    clawdata.read('claw.data')
    physics = clawpack.geoclaw.data.GeoClawData()
    physics.read(os.path.join(plotdata.outdir,'geoclaw.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(2012,10,29,8,0) - datetime.datetime(2012,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
    region_data = {'full':([clawdata.lower[0],clawdata.upper[0]],
                           [clawdata.lower[1],clawdata.upper[1]],
                           0.8),
                   'Region':([-74.5,-71.0], [40.0,41.5], 0.5),
                   'NYC':([-74.2,-73.8], [40.55,40.85], 0.5)
                  }

    # Color limits
    surface_range = 1.5
    speed_range = 1.0
    # speed_range = 1.e-2

    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]
    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)
    
    def contour_afteraxes(current_data):
        surge_afteraxes(current_data)

    
    # ==========================================================================
    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    # ==========================================================================
    for (region, values) in region_data.iteritems():
        # ========================================================================
        #  Surface Elevations
        # ========================================================================
        plotfigure = plotdata.new_plotfigure(name='Surface - %s' % region,  
                                         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 = values[0]
        plotaxes.ylimits = values[1]
        plotaxes.afteraxes = pcolor_afteraxes
    
        surge.add_surface_elevation(plotaxes,bounds=surface_limits,shrink=values[2])
        surge.add_land(plotaxes)


        # ========================================================================
        #  Water Speed
        # ========================================================================
        plotfigure = plotdata.new_plotfigure(name='Currents - %s' % region,  
                                         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 = values[0]
        plotaxes.ylimits = values[1]
        plotaxes.afteraxes = pcolor_afteraxes

        # Speed
        surge.add_speed(plotaxes,bounds=speed_limits,shrink=values[2])

        # Land
        surge.add_land(plotaxes)


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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = region_data['full'][0]
    plotaxes.ylimits = region_data['full'][1]
    plotaxes.title = "Manning's N Coefficients"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True

    surge.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 = region_data['full'][0]
    plotaxes.ylimits = region_data['full'][1]
    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=fig_num_counter.get_counter())
    plotfigure.show = surge_data.wind_forcing and True
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = region_data['full'][0]
    plotaxes.ylimits = region_data['full'][1]
    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)

    # ==========================================================================
    #  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 = 'Topography'
    plotaxes.scaled = True
    plotaxes.xlimits = region_data['full'][0]
    plotaxes.ylimits = region_data['full'][1]
    plotaxes.afteraxes = surge_afteraxes

    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = 0
    plotitem.imshow_cmin = 0
    plotitem.imshow_cmax = 200
    plotitem.imshow_cmap = plt.get_cmap("terrain")
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.amr_patchedges_show = [1,1,1,1,1,1,1,1,1]

    # ========================================================================
    #  Figures for gauges
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface, Speeds',   
                                         figno=fig_num_counter.get_counter(),
                                         type='each_gauge')
    plotfigure.show = True
    plotfigure.clf_each_gauge = True

    # Surface and Topography
    plotaxes = plotfigure.new_plotaxes()
    # plotaxes.axescmd = 'subplot(121)'
    try:
        plotaxes.xlimits = [amrdata.t0,amrdata.tfinal]
    except:
        pass
    plotaxes.ylimits = surface_limits
    plotaxes.title = 'Surface'
    plotaxes.afteraxes = surge.gauge_afteraxes
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = 3
    plotitem.plotstyle = 'b-'

    # # Speeds
    # plotaxes = plotfigure.new_plotaxes()
    # plotaxes.axescmd = 'subplot(122)'
    # try:
    #     plotaxes.xlimits = [amrdata.t0,amrdata.tfinal]
    # except:
    #     pass
    # plotaxes.ylimits = surface_limits
    # plotaxes.title = 'Momenta'
    # plotaxes.afteraxes = surge.gauge_afteraxes

    # plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    # plotitem.plot_var = 1
    # plotitem.plotstyle = 'r-'
    # plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    # plotitem.plot_var = 2
    # plotitem.plotstyle = 'b-'




    #-----------------------------------------
    
    # 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
示例#22
0
def setplot(plotdata):
    r"""Setplot function for surge plotting"""
    

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

    # Load data from output
    clawdata = clawpack.clawutil.data.ClawInputData(2)
    clawdata.read(os.path.join(plotdata.outdir,'claw.data'))
    physics = clawpack.geoclaw.data.GeoClawData()
    physics.read(os.path.join(plotdata.outdir,'geoclaw.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 track32
    track = surge.track_data(os.path.join(plotdata.outdir,'fort.track'))

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

    # Limits for plots
    dx = 0.5
    dy = 0.5
    regions = [{"name": "Full Domain",
                "limits": [[clawdata.lower[0], clawdata.upper[0]],
                           [clawdata.lower[1], clawdata.upper[1]]]},
               {"name": "New Orleans",
                "limits": [[-92.5, -87.5], [27.5, 31.5]]},
               {"name": "Grand Isle",
                "limits": [[-89.41 - dx, -89.41 + dx],
                           [29.26 - dx, 29.26 + dx]]},
               {"name": "Pilots Station East",
                "limits": [[-89.41 - dx, -89.41 + dx],
                           [28.93 - dy, 28.93 + dy]]},
               {"name": "Dauphin Island",
                "limits": [[-88.08 - dx, -88.08 + dx],
                           [30.25 - dy, 30.25 + dy]]}]

    # Color limits
    surface_limits = [physics.sea_level - 5.0, physics.sea_level + 5.0]
    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, 3.0]
    speed_ticks = [0, 1, 2, 3]
    speed_labels = [str(value) for value in speed_ticks]
    wind_limits = [15, 40]
    pressure_limits = [966,1013]
    friction_bounds = [0.01,0.04]

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

    # Loop over region specifications ploting both surface and speeds
    for region in regions:
        name = region['name']
        xlimits = region['limits'][0]
        ylimits = region['limits'][1]
        # ======================================================================
        #  Surface Elevations
        # ======================================================================
        plotfigure = plotdata.new_plotfigure(name='Surface - %s' % name)
        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.add_surface_elevation(plotaxes, bounds=surface_limits)
        plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
        surge.add_land(plotaxes)
        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

        # ======================================================================
        #  Water Speed
        # ======================================================================
        plotfigure = plotdata.new_plotfigure(name='Currents - %s' % name)
        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

        surge.add_speed(plotaxes, bounds=speed_limits)
        plotaxes.plotitem_dict['speed'].amr_patchedges_show = [0] * 10
        surge.add_land(plotaxes)
        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

        # ======================================================================
        #  Wind Field
        # ======================================================================
        plotfigure = plotdata.new_plotfigure(name='Wind Speed - %s' % name)
        plotfigure.show = surge_data.wind_forcing

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

        surge.add_wind(plotaxes, bounds=wind_limits)
        plotaxes.plotitem_dict['wind'].amr_patchedges_show = [0] * 10
        surge.add_land(plotaxes)
        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10


        # ========================================================================
        # Hurricane forcing
        # ========================================================================
        # Friction field
        plotfigure = plotdata.new_plotfigure(name='Friction - %s' % name)
        plotfigure.show = friction_data.variable_friction

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

        surge.add_friction(plotaxes, bounds=friction_bounds)

        # Pressure field
        plotfigure = plotdata.new_plotfigure(name='Pressure - %s' % name)
        plotfigure.show = surge_data.pressure_forcing

        plotaxes = plotfigure.new_plotaxes()
        plotaxes.title = "Pressure Field"
        plotaxes.scaled = True
        plotaxes.xlimits = xlimits
        plotaxes.ylimits = ylimits
        plotaxes.afteraxes = surge_afteraxes
    
        surge.add_pressure(plotaxes, bounds=pressure_limits)
        plotaxes.plotitem_dict['pressure'].amr_patchedges_show = [0] * 10
        surge.add_land(plotaxes)
        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10


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

    stations = [('8761724', 'Grand Isle, LA'),
                ('8760922', 'Pilots Station East, SW Pass, LA'),
                ('8735180', 'Dauphin Island, AL')]

    landfall_time = np.datetime64('2005-08-29T11:10')
    begin_date = datetime.datetime(2005, 8, 26)
    end_date = datetime.datetime(2005, 8, 31)

    def get_actual_water_levels(station_id):
        # Fetch water levels and tide predictions for given station
        date_time, water_level, tide = fetch_noaa_tide_data(station_id,
                begin_date, end_date)

        # Calculate times relative to landfall
        secs_rel_landfall = (date_time - landfall_time) / np.timedelta64(1, 's')

        # Subtract tide predictions from measured water levels
        water_level -= tide

        return secs_rel_landfall, water_level

    def gauge_afteraxes(cd):
        station_id, station_name = stations[cd.gaugeno - 1]
        secs_rel_landfall, actual_level = get_actual_water_levels(station_id)

        axes = plt.gca()
        axes.plot(secs_rel_landfall, actual_level, 'g')

        # Fix up plot - in particular fix time labels
        axes.set_title(station_name)
        axes.set_xlabel('Days relative to landfall')
        axes.set_ylabel('Surface (m)')
        axes.set_xlim(np.array([-3, 1]) * 86400)
        axes.set_ylim([-0.5, 2.5])
        axes.set_xticks(np.linspace(-3, 1, 5) * 86400)
        axes.set_xticklabels([r"$-3$", r"$-2$", r"$-1$", r"$0$", r"$1$"])
        axes.grid(True)

        # Plot wind speed using second scale
        wind_speed = np.linalg.norm(cd.gaugesoln.q[8:10, :], axis=0)
        axes2 = axes.twinx()
        axes2.plot(cd.gaugesoln.t, wind_speed, 'r.', markersize=0.3)
        axes2.set_ylabel('Wind Speed (m/s)')
        axes2.set_ylim([-2.5, 52.5])

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

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

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

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge Locations'
    plotaxes.scaled = True
    plotaxes.xlimits = [-91.5, -87.5]
    plotaxes.ylimits = [28.0, 31.0]
    plotaxes.afteraxes = gauge_location_afteraxes

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


    #-----------------------------------------
    
    # 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
示例#23
0
文件: setplot.py 项目: maojrs/apps
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
    physics = clawpack.geoclaw.data.GeoClawData()
    physics.read(os.path.join(plotdata.outdir, 'geoclaw.data'))
    surge_data = clawpack.geoclaw.surge.data.SurgeData()
    surge_data.read(os.path.join(plotdata.outdir, 'surge.data'))
    friction_data = clawpack.geoclaw.surge.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(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.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.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.add_surface_elevation(plotaxes,
                                bounds=surface_limits,
                                shrink=full_shrink)
    surge.add_land(plotaxes, topo_min=-10.0, topo_max=5.0)
    surge.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.add_speed(plotaxes, bounds=speed_limits, shrink=full_shrink)

    # Land
    surge.add_land(plotaxes)
    surge.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.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.add_pressure(plotaxes, bounds=pressure_limits)
    # add_pressure(plotaxes)
    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 = 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)

    # 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.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.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.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.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.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.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.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.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.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
示例#24
0
def setplot(plotdata=None):
    """"""

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

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

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

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

    # Calculate landfall time
    # Landfall for Ike in Houston was September 13th, at 7 UTC
    landfall_dt = datetime.datetime(2008, 9, 13, 7) - \
                  datetime.datetime(2008, 1, 1,  0)
    landfall = landfall_dt.days * 24.0 * 60**2 + landfall_dt.seconds

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

    # Color limits
    surface_limits = [-5.0, 5.0]
    speed_limits = [0.0, 3.0]
    wind_limits = [0, 64]
    pressure_limits = [935, 1013]
    friction_bounds = [0.01, 0.04]

    def gulf_after_axes(cd):
        # plt.subplots_adjust(left=0.08, bottom=0.04, right=0.97, top=0.96)
        surge_afteraxes(cd)

    def latex_after_axes(cd):
        # plt.subplot_adjust()
        surge_afteraxes(cd)

    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)

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    regions = {"Gulf": {"xlimits": (clawdata.lower[0], clawdata.upper[0]),
                        "ylimits": (clawdata.lower[1], clawdata.upper[1]),
                        "figsize": (6.4, 4.8)},
               "LaTex Shelf": {"xlimits": (-97.5, -88.5),
                               "ylimits": (27.5, 30.5),
                               "figsize": (8, 2.7)}}

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

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

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

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

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Gulf']['xlimits']
    plotaxes.ylimits = regions['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] * 10
    plotaxes.plotitem_dict['friction'].colorbar_label = "$n$"

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

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

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

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

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

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

    def gauge_afteraxes(cd):

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

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

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

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

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

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

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

    plotdata.printfigs = True                # print figures
    plotdata.print_format = 'png'            # file format
    plotdata.print_framenos = 'all'          # list of frames to print
    plotdata.print_gaugenos = [1, 2, 3, 4]   # list of gauges to print
    plotdata.print_fignos = 'all'            # list of figures to print
    plotdata.html = True                     # create html files of plots?
    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                 # parallel plotting

    return plotdata
示例#25
0
def setplot(plotdata=None):
    """"""

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

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

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

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

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

    # Color limits
    surface_limits = [-5.0, 5.0]
    speed_limits = [0.0, 3.0]
    wind_limits = [0, 64]
    pressure_limits = [935, 1013]
    friction_bounds = [0.01, 0.04]

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

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    regions = {
        "Gulf": {
            "xlimits": (clawdata.lower[0], clawdata.upper[0]),
            "ylimits": (clawdata.lower[1], clawdata.upper[1]),
            "figsize": (6.4, 4.8)
        },
        "Texas Gulf Coast": {
            "xlimits": (-99.2, -94.2),
            "ylimits": (26.4, 30.4),
            "figsize": (6, 6)
        }
    }

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

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

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

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

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Gulf']['xlimits']
    plotaxes.ylimits = regions['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] * 10
    plotaxes.plotitem_dict['friction'].colorbar_label = "$n$"

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

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

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

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

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

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

    #Time Conversions
    def days2seconds(days):
        return days * 60.0**2 * 24.0

    stations = [('8773037', 'Seadrift'), ('8773701', 'Port OConnor'),
                ('8774230', 'Aransas Wildlife Refuge'),
                ('8775237', 'Port Aransas'), ('8775296', 'USS Lexington')]

    landfall_time = numpy.datetime64('2017-08-25T10:00')
    begin_date = datetime.datetime(2017, 8, 24)
    end_date = datetime.datetime(2017, 8, 28)

    def get_actual_water_levels(station_id):
        # Fetch water levels and tide predictions for given station
        date_time, water_level, tide = fetch_noaa_tide_data(
            station_id, begin_date, end_date)

        # Calculate times relative to landfall
        seconds_rel_landfall = (date_time - landfall_time) / numpy.timedelta64(
            1, 's')
        # Subtract tide predictions from measured water levels
        water_level -= tide

        return seconds_rel_landfall, water_level

    def gauge_afteraxes(cd):

        station_id, station_name = stations[cd.gaugeno - 1]
        seconds_rel_landfall, actual_level = get_actual_water_levels(
            station_id)

        axes = plt.gca()
        surgeplot.plot_landfall_gauge(cd.gaugesoln, axes)
        axes.plot(seconds_rel_landfall, actual_level, 'g')

        # Fix up plot - in particular fix time labels
        axes.set_title(station_name)
        axes.set_xlabel('Seconds relative to landfall')
        axes.set_ylabel('Surface (m)')
        axes.set_xlim([days2seconds(-1), days2seconds(3)])
        axes.set_ylim([-1, 5])
        axes.set_xticks([
            -days2seconds(-1), 0,
            days2seconds(1),
            days2seconds(2),
            days2seconds(3)
        ])
        #axes.set_xticklabels([r"$-1$", r"$0$", r"$1$", r"$2$", r"$3$"])
        #axes.grid(True)

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

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

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

    #Plot for gauge location 1
    plotfigure = plotdata.new_plotfigure(name="Gauge Location 1")
    plotfigure.show = True

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

    #Plot for gauge location 2

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge Location 2'
    plotaxes.scaled = True
    plotaxes.xlimits = [-96.48, -96.28]
    plotaxes.ylimits = [28.40, 28.50]
    plotaxes.afteraxes = gauge_location_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    #Plot for gauge location 3

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge Location 3'
    plotaxes.scaled = True
    plotaxes.xlimits = [-96.85, -96.65]
    plotaxes.ylimits = [28.17, 28.27]
    plotaxes.afteraxes = gauge_location_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    #Plot for gauge location 4

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge Location 4'
    plotaxes.scaled = True
    plotaxes.xlimits = [-97.15, -96.95]
    plotaxes.ylimits = [27.79, 27.89]
    plotaxes.afteraxes = gauge_location_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    #Plot for gauge location 5

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge Location 5'
    plotaxes.scaled = True
    plotaxes.xlimits = [-97.48, -97.28]
    plotaxes.ylimits = [27.75, 27.85]
    plotaxes.afteraxes = gauge_location_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    plotdata.printfigs = True  # print figures
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = 'all'  # list of frames to print
    plotdata.print_gaugenos = [1, 2, 3, 4, 5]  # list of gauges to print
    plotdata.print_fignos = 'all'  # list of figures to print
    plotdata.html = True  # create html files of plots?
    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  # parallel plotting

    return plotdata
示例#26
0
def setplot(plotdata=None):
    """"""

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

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

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

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

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

    # Color limits
    surface_limits = [-4.0, 4.0]
    speed_limits = [0.0, 3.0]
    wind_limits = [0, 64]
    pressure_limits = [935, 1013]
    friction_bounds = [0.01, 0.04]
    color_limits = [0, 20]

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

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    regions = {"Atlantic": {"xlimits": (clawdata.lower[0], clawdata.upper[0]),
                        "ylimits": (clawdata.lower[1], clawdata.upper[1]),
                        "figsize": (6.4, 4.8)},
               "Bahamas": {"xlimits": (-81, -75),
                               "ylimits": (23.0, 26.0),
                               "figsize": (8, 4)},
               "Haiti": {"xlimits": (-73, -71),
                               "ylimits": (18.0, 20.0),
                               "figsize": (4, 4)},
               "Cuba": {"xlimits": (-80, -75),
                               "ylimits": (15.0, 25.0),
                               "figsize": (4 ,8)},
               "Florida": {"xlimits": (-82, -79),
                               "ylimits": (23.0, 26.0),
                               "figsize": (4 ,4)}}

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

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

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

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

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

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

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

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

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

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

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

    # ========================================================================
    #  Figures for gauges
    # ========================================================================

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

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

    try:
        # comparison water level files
        gauges = [np.loadtxt('gauge_data_1.txt'), np.loadtxt('gauge_data_2.txt'),
                  np.loadtxt('gauge_data_3.txt'), np.loadtxt('gauge_data_4.txt')]

        # origin of comparison data (for legend)
        data_names = ["Difference in Water level of Virginia Key, Biscanay Bay, Florida from NOAA",
                      "Difference in Water level of Key West, Florida from NOAA",
                      "Difference in Water level of Mona Island, Puerto Rico from NOAA",
                      "Difference in Water level of Magueyes Island, Puerto Rico from NOAA",
                      "Flood Height of Rum Cay, the Bahamas from local newspaper, Bahamas Press",
                      "Flood Height of Cat Island, the Bahamas from local newspaper, The Tribune"]

    except:
        pass

    def gauge_afteraxes(cd):

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

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

        try:

            # gauge 5 and 6 are in the Bahamas, and there's no water level data,
            # comparison data is estimate flood heights from newspapers
            if(cd.gaugeno == 5 or cd.gaugeno == 6):
                if(cd.gaugeno == 5):
            	    axes.axhline(y=4*0.3040, color = 'r', label = data_names[4]) # flood height was 4 feet
                else:
                    axes.axhline(y=5*0.3040, color = 'r', label = data_names[5]) # flood height was 5 feet

            # the rest have NOAA water level files
            else:
                # read water level data
                gauge_data = gauges[cd.gaugeno - 1]

                axes.plot(gauge_data[:, 1], gauge_data[:, 0], label = data_names[cd.gaugeno - 1])

            axes.legend()
        except:
            pass

    plotaxes.afteraxes = gauge_afteraxes

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

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

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

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

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

    plotdata.printfigs = True                # print figures
    plotdata.print_format = 'png'            # file format
    plotdata.print_framenos = 'all'          # list of frames to print
    plotdata.print_gaugenos = [1, 2, 3, 4, 5, 6]   # list of gauges to print
    plotdata.print_fignos = 'all'            # list of figures to print
    plotdata.html = True                     # create html files of plots?
    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                 # parallel plotting

    return plotdata
示例#27
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 = clawpack.clawutil.data.ClawInputData(2)
    clawdata.read('claw.data')
    physics = clawpack.geoclaw.data.GeoClawData()
    physics.read(os.path.join(plotdata.outdir, 'geoclaw.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(2011, 8, 27, 7, 30) - datetime.datetime(
        2011, 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 = [clawdata.lower[0], clawdata.upper[0]]
    full_ylimits = [clawdata.lower[1], clawdata.upper[1]]
    full_shrink = 0.8
    carolinas_xlimits = [-79.5, -74.5]
    carolinas_ylimits = [32.8, 36.3]
    carolinas_shrink = 1.0

    # Color limits
    surface_range = 3.0
    speed_range = 1.0
    # speed_range = 1.e-2

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

    def contour_afteraxes(current_data):
        surge_afteraxes(current_data)

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

    # ========================================================================
    #  Surface Elevations - Entire Atlantic
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface - Atlantic', figno=100)
    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,
                                shrink=full_shrink)
    surge.add_land(plotaxes)

    # ========================================================================
    #  Water Speed - Entire Atlantic
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Currents - Atlantic', figno=200)
    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, shrink=full_shrink)

    # Land
    surge.add_land(plotaxes)

    # ========================================================================
    #  Surface Elevations - North and South Carolina Area
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Surface - Carolinas', figno=300)
    plotfigure.show = True

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

    def after_with_gauges(cd):
        surge_afteraxes(cd)
        surge.gauge_locations(cd)

    plotaxes.afteraxes = after_with_gauges

    surge.add_surface_elevation(plotaxes,
                                bounds=surface_limits,
                                shrink=carolinas_shrink)
    surge.add_land(plotaxes)

    # ========================================================================
    #  Currents Elevations - North and South Carolina Area
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Currents - Carolinas',
                                         figno=400)
    plotfigure.show = True

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

    def after_with_gauges(cd):
        surge_afteraxes(cd)
        surge.gauge_locations(cd)

    plotaxes.afteraxes = after_with_gauges

    surge.add_speed(plotaxes, bounds=speed_limits, shrink=carolinas_shrink)
    surge.add_land(plotaxes)

    # ========================================================================
    # Hurricane forcing - Entire Atlantic
    # ========================================================================
    # Friction field
    plotfigure = plotdata.new_plotfigure(name='Friction', figno=500)
    plotfigure.show = friction_data.variable_friction and True

    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.add_friction(plotaxes, bounds=friction_bounds)

    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure', figno=600)
    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.add_pressure(plotaxes, bounds=pressure_limits)
    # add_pressure(plotaxes)
    surge.add_land(plotaxes)

    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed', figno=700)
    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.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)

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

    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.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.add_land(plotaxes)

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

    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.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.add_land(plotaxes)

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Topography'
    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_cmin = 0
    plotitem.imshow_cmax = 200
    plotitem.imshow_cmap = plt.get_cmap("terrain")
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0, 0, 0]
    plotitem.amr_patchedges_show = [1, 1, 1, 1, 1, 1, 1, 1, 1]

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

    stations = [('8661070', 'Springmaid Pier, SC', 'NOAA', None),
                ('8658120', 'Wilmington, NC', 'NOAA', None),
                ('8658163', 'Wrightsville Beach, NC', 'NOAA', None),
                ('8656483', 'Beaufort, NC', 'NOAA', None),
                ('8654467', 'Hatteras, NC', 'NOAA', None),
                ('8652587', 'Oregon Inlet Marina, NC', 'NOAA', None),
                ('02084472', 'Pamlico River, NC', 'USGS', '00065'),
                ('02092576', 'Trent River, NC', 'USGS', '62620')]

    landfall_time = np.datetime64('2018-09-14T07:15')
    begin_date = datetime.datetime(2018, 9, 12)
    end_date = datetime.datetime(2018, 9, 16)

    # modified fetch_noaa_tide_data function for current NOAA formatting
    def fetch_noaa_tide_data(station,
                             begin_date,
                             end_date,
                             time_zone='GMT',
                             datum='STND',
                             units='metric',
                             cache_dir=None,
                             verbose=True):
        """Fetch water levels and tide predictions at given NOAA tide station.
        
        The data is returned in 6 minute intervals between the specified begin and
        end dates/times.  A complete specification of the NOAA CO-OPS API for Data
        Retrieval used to fetch the data can be found at:
           
            https://tidesandcurrents.noaa.gov/api/
        
        By default, retrieved data is cached in the geoclaw scratch directory
        located at:
            
            $CLAW/geoclaw/scratch
        
        :Required Arguments:
        - station (string): 7 character station ID
        - begin_date (datetime): start of date/time range of retrieval
        - end_date (datetime): end of date/time range of retrieval
        
        :Optional Arguments:
        - time_zone (string): see NOAA API documentation for possible values
        - datum (string): see NOAA API documentation for possible values
        - units (string): see NOAA API documentation for possible values
        - cache_dir (string): alternative directory to use for caching data
        - verbose (bool): whether to output informational messages
        
        :Returns:
        - date_time (numpy.ndarray): times corresponding to retrieved data
        - water_level (numpy.ndarray): preliminary or verified water levels
        - prediction (numpy.ndarray): tide predictions
        """

        NOAA_API_URL = 'https://tidesandcurrents.noaa.gov/api/datagetter'

        # use geoclaw scratch directory for caching by default
        if cache_dir is None:
            if 'CLAW' not in os.environ:
                raise ValueError('CLAW environment variable not set')
            claw_dir = os.environ['CLAW']
            cache_dir = os.path.join(claw_dir, 'geoclaw', 'scratch')

        def fetch(product, expected_header, col_idx, col_types):
            noaa_params = get_noaa_params(product)
            cache_path = get_cache_path(product)

            # use cached data if available
            if os.path.exists(cache_path):
                if verbose:
                    print('Using cached {} data for station {}'.format(
                        product, station))
                return parse(cache_path, col_idx, col_types, header=True)

            # otherwise, retrieve data from NOAA and cache it
            if verbose:
                print('Fetching {} data from NOAA for station {}'.format(
                    product, station))
            full_url = '{}?{}'.format(NOAA_API_URL, urlencode(noaa_params))
            with urlopen(full_url) as response:
                text = response.read().decode('utf-8')
                with io.StringIO(text) as data:
                    # ensure that received header is correct
                    header = data.readline().strip()
                if header != expected_header or 'Error' in text:
                    # if not, response contains error message
                    raise ValueError(text)

                    # if there were no errors, then cache response
                    save_to_cache(cache_path, text)

                    return parse(data, col_idx, col_types, header=False)

        def get_noaa_params(product):
            noaa_date_fmt = '%Y%m%d %H:%M'
            noaa_params = {
                'product': product,
                'application': 'NOS.COOPS.TAC.WL',
                'format': 'csv',
                'station': station,
                'begin_date': begin_date.strftime(noaa_date_fmt),
                'end_date': end_date.strftime(noaa_date_fmt),
                'time_zone': time_zone,
                'datum': datum,
                'units': units
            }
            return noaa_params

        def get_cache_path(product):
            cache_date_fmt = '%Y%m%d%H%M'
            dates = '{}_{}'.format(begin_date.strftime(cache_date_fmt),
                                   end_date.strftime(cache_date_fmt))
            filename = '{}_{}_{}'.format(time_zone, datum, units)
            abs_cache_dir = os.path.abspath(cache_dir)
            return os.path.join(abs_cache_dir, product, station, dates,
                                filename)

        def save_to_cache(cache_path, data):
            # make parent directories if they do not exist
            parent_dir = os.path.dirname(cache_path)
            if not os.path.exists(parent_dir):
                os.makedirs(parent_dir)

            # write data to cache file
            with open(cache_path, 'w') as cache_file:
                cache_file.write(data)

        def parse(data, col_idx, col_types, header):
            # read data into structured array, skipping header row if present
            a = np.genfromtxt(data,
                              usecols=col_idx,
                              dtype=col_types,
                              skip_header=int(header),
                              delimiter=',',
                              missing_values='')

            # return tuple of columns
            return tuple(a[col] for col in a.dtype.names)

        # only need first two columns of data; first column contains date/time,
        # and second column contains corresponding value
        col_idx = (0, 1)
        col_types = 'datetime64[m], float'

        # fetch water levels and tide predictions
        date_time, water_level = fetch(
            'water_level',
            'Date Time, Water Level, Sigma, O or I (for verified), F, R, L, Quality',
            col_idx, col_types)
        date_time2, prediction = fetch('predictions', 'Date Time, Prediction',
                                       col_idx, col_types)

        # ensure that date/time ranges are the same
        if not np.array_equal(date_time, date_time2):
            raise ValueError('Received data for different times')

        return date_time, water_level, prediction

    def fetch_usgs_gauge_data(station,
                              begin_date,
                              end_date,
                              parameter,
                              cache_dir=None,
                              verbose=True):
        '''Fetch gauge water levels at given USGS site.

        More details about the USGS web service and parameter filters 
        can be found here: 
            
            https://waterservices.usgs.gov/rest/IV-Service.html

        A complete list of parameter codes and descriptions can be found
        here:
            
            https://help.waterdata.usgs.gov/parameter_cd?group_cd=PHY

        Retrieved data is cached in the Geoclaw scratch directory by default,
        located at:
            
            $CLAW/geoclaw/scratch

        :Required Arguments:
            - station (string): site ID (length may vary)
            - begin_date (datetime): start of date/time range of retrieval
            - end_date (datetime): end of date/time range of retrieval
            - parameter (string): 5-character parameter code
        
        :Optional Arguments:
            - cache_dir (string): alternative directory to use for caching data
            - verbose (bool): whether to ouput informational messages

        :Returns:
            - date_time (tuple): times corresponding to retrieved data
            - water_level (tuple): water level at each time
        '''

        feet2meters = lambda feet: feet * 0.3048

        #use geoclaw scratch directory for caching by default
        if cache_dir is None:
            if 'CLAW' not in os.environ:
                raise ValueError('CLAW environment variable not set')
            claw_dir = os.environ['CLAW']
            cache_dir = os.path.join(claw_dir, 'geoclaw', 'scratch')

        def fetch(parameter):
            usgs_params = {
                'sites': station,
                'format': 'waterml,2.0',
                'startDT': begin_date.isoformat(),
                'endDT': end_date.isoformat(),
                'parameterCd': parameter  # parameter code
            }

            cache_path = get_cache_path(parameter)

            # use cached data if available
            if os.path.exists(cache_path):
                if verbose:
                    print('Using cached {} data for station {}'.format(
                        parameter, station))
                return parse(cache_path)

            # otherwise, retrieve data from USGS and cache it
            if verbose:
                print('Fetching {} data from USGS for station {}'.format(
                    parameter, station))
            params = urllib.parse.urlencode(usgs_params)
            full_url = 'http://waterservices.usgs.gov/nwis/iv/?%s' % params

            # create response object from url
            resp = requests.get(full_url)

            # check HTTP status code and raise exception if unsuccessful
            resp.raise_for_status()

            xml_content = resp.content

            # cache response content
            save_to_cache(cache_path, xml_content)

            return parse(cache_path)

        def get_cache_path(parameter):
            cache_date_fmt = '%Y%m%d%H%M'
            filename = '{}_{}.xml'.format(begin_date.strftime(cache_date_fmt),
                                          end_date.strftime(cache_date_fmt))
            abs_cache_dir = os.path.abspath(cache_dir)

            return os.path.join(abs_cache_dir, 'USGS', parameter, station,
                                filename)

        def save_to_cache(cache_path, data):
            # make parent directories if they do not exist
            parent_dir = os.path.dirname(cache_path)
            if not os.path.exists(parent_dir):
                os.makedirs(parent_dir)

            # write data to cache file
            with open(cache_path, 'wb') as cache_file:
                cache_file.write(data)

        def parse(data):
            # create ElementTree object
            tree = ET.parse(data)

            namespaces = {'wm12': 'http://www.opengis.net/waterml/2.0'}

            # return root as Element object
            root = tree.getroot()

            times = []
            values = []

            # find data from subelements and store into lists
            for MeasurementTVP in root.findall('.//wm12:MeasurementTVP',
                                               namespaces):
                time = MeasurementTVP.find('wm12:time', namespaces).text
                date_time = np.datetime64(time[0:19])
                #seconds_rel_landfall = (date_time - landfall_time) / np.timedelta64(1, 's')
                times.append(date_time)

                value = MeasurementTVP.find('wm12:value', namespaces).text
                value_in_m = feet2meters(float(value))
                values.append(value_in_m)

            return tuple(times), tuple(values)

        # fetch with parameter code for surface height
        date_time, water_level = fetch(parameter)

        return date_time, water_level

# need to uncomment this function if you want to compare with real data from NOAA/USGS

    def get_actual_water_levels(station_id, gauge_source, parameter_code):
        # Fetch water levels and tide predictions for given station
        if gauge_source == 'NOAA':
            date_time, water_level, tide = fetch_noaa_tide_data(station_id,
                                                                begin_date,
                                                                end_date,
                                                                datum='NAVD')
            # Subtract tide predictions from measured water levels
            water_level -= tide

        elif gauge_source == 'USGS':
            date_time, water_level = fetch_usgs_gauge_data(
                station_id, begin_date, end_date, parameter_code)

        # Calculate times relative to landfall
        seconds_rel_landfall = (date_time - landfall_time) / np.timedelta64(
            1, 's')

        return seconds_rel_landfall, water_level

    def gauge_afteraxes(cd):
        station_id, station_name, gauge_source, parameter_code = stations[
            cd.gaugeno - 1]
        # uncomment the next line to plot against real NOAA/USGS data
        seconds_rel_landfall, actual_level = get_actual_water_levels(
            station_id, gauge_source, parameter_code)

        axes = plt.gca()
        #surgeplot.plot_landfall_gauge(cd.gaugesoln, axes, landfall=landfall)
        # uncomment the next line to plot against real NOAA/USGS data
        axes.plot(seconds_rel_landfall, actual_level, 'g', label='Observed')

        # Fix up plot - in particular fix time labels
        axes.set_title(station_name)
        axes.set_xlabel('Seconds relative to landfall')
        axes.set_ylabel('Surface (m)')
        axes.set_ylim([0, 4])
        #axes.set_xticks([ days2seconds(-2), days2seconds(-1), 0, days2seconds(1)])
        #axes.set_xticklabels([r"$-3$", r"$-2$", r"$-1$", r"$0$", r"$1$"])
        axes.grid(True)
        plt.legend(loc="upper left")

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

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

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

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge Locations (1-3)'
    plotaxes.scaled = True
    plotaxes.xlimits = [-78.9, -77.6]
    plotaxes.ylimits = [33.6, 34.4]
    plotaxes.afteraxes = gauge_location_afteraxes
    surge.add_surface_elevation(plotaxes, bounds=surface_limits)
    surge.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    # Gauges 4-6
    def gauge_location_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[4, 5, 6],
                                        format_string='ko',
                                        add_labels=True)

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge Locations (4-6)'
    plotaxes.scaled = True
    plotaxes.xlimits = [-76.85, -75.5]
    plotaxes.ylimits = [34.55, 35.9]
    plotaxes.afteraxes = gauge_location_afteraxes
    surge.add_surface_elevation(plotaxes, bounds=surface_limits)
    surge.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    # Gauges 7-8
    def gauge_location_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[7, 8],
                                        format_string='ko',
                                        add_labels=True)

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge Locations (7-8)'
    plotaxes.scaled = True
    plotaxes.xlimits = [-77.3, -76.5]
    plotaxes.ylimits = [34.7, 35.65]
    plotaxes.afteraxes = gauge_location_afteraxes
    surge.add_surface_elevation(plotaxes, bounds=surface_limits)
    surge.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

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

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

    return plotdata
示例#28
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?
    if storm_num == 1:
        # Storm 1
        landfall_dt = datetime.datetime(1997, 11, 15, 3) - datetime.datetime(1997, 1, 1, 0)
    elif storm_num == 2:
        # Storm 2
        landfall_dt = datetime.datetime(2008, 12, 17, 0) - 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)

    # Color limits
    surface_range = 5.0
    speed_range = 3.0
    eta = physics.sea_level
    if not isinstance(eta,list):
        eta = [eta]
    surface_limits = [-5.0, 5.0]
    # 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,50]
    # 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 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
    # ==========================================================================
    # ==========================================================================
    regions = {"Full Domain (Grids)": [[clawdata.lower[0], clawdata.upper[0]],
                               [clawdata.lower[1], clawdata.upper[1]], 
                               [1, 1, 1, 1, 1, 1, 1]],
               "Mumbai Regio (Grids)": [[70, 75], [17, 22], [1, 1, 1, 1, 1, 1, 1]],
               "Mumbai (Grids)": [[72.6, 73.15], [18.80, 19.25], [1, 1, 1, 1, 1, 1, 1]],
               "Full Domain (No Grids)": [[clawdata.lower[0], clawdata.upper[0]],
                               [clawdata.lower[1], clawdata.upper[1]], 
                               [0, 0, 0, 0, 0, 0, 0]],
               "Mumbai Region (No Grids)": [[70, 75], [17, 22], [0, 0, 0, 0, 0, 0, 0]],
               "Mumbai (No Grids)": [[72.6, 73.15], [18.80, 19.25], [0, 0, 0, 0, 0, 0, 0]]}
    full_xlimits = regions['Full Domain (Grids)'][0]
    full_ylimits = regions['Full Domain (Grids)'][1]

    for (name, region_data) in regions.iteritems():

        #
        #  Surface
        #
        plotfigure = plotdata.new_plotfigure(name='Surface - %s' % name, 
                                             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 = region_data[0]
        plotaxes.ylimits = region_data[1]
        plotaxes.afteraxes = afteraxes

        surge.add_surface_elevation(plotaxes, plot_type='pcolor', 
                                               bounds=surface_limits)
        # surge.add_surface_elevation(plotaxes, plot_type='contourf', 
        #                                        contours=surface_contours)
        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['land'].amr_patchedges_show = region_data[2]
        plotaxes.plotitem_dict['surface'].amr_patchedges_show = region_data[2]

        #
        #  Water Speed
        #
        plotfigure = plotdata.new_plotfigure(name='Currents - %s' % name,  
                                             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 = region_data[0]
        plotaxes.ylimits = region_data[1]
        plotaxes.afteraxes = afteraxes

        # Speed
        surge.add_speed(plotaxes, plot_type='pcolor', bounds=speed_limits)
        # surge.add_speed(plotaxes, plot_type='contourf', contours=speed_contours)
        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,topo_min=-10.0,topo_max=5.0)

        plotaxes.plotitem_dict['speed'].amr_patchedges_show = region_data[2]
        plotaxes.plotitem_dict['land'].amr_patchedges_show = region_data[2]
        
    #
    # Friction field
    #
    plotfigure = plotdata.new_plotfigure(name='Friction',
                                         figno=fig_num_counter.get_counter())
    plotfigure.show = friction_data.variable_friction and False

    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 = full_xlimits
    plotaxes.ylimits = full_ylimits
    # plotaxes.title = "Manning's N Coefficient"
    plotaxes.afteraxes = friction_after_axes
    plotaxes.scaled = True

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

    # ==========================
    #  Hurricane Forcing fields
    # ==========================
    grids = [[0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1]]
    label = ["(No Grids)", "(Grids)"]
    for i in xrange(2):
        # Pressure field
        plotfigure = plotdata.new_plotfigure(name='Pressure %s' % label[i],  
                                             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 = afteraxes
        plotaxes.scaled = True
        
        surge.add_pressure(plotaxes, bounds=pressure_limits)
        surge.add_land(plotaxes)
        plotaxes.plotitem_dict['pressure'].amr_patchedges_show = grids[i]
        plotaxes.plotitem_dict['land'].amr_patchedges_show = grids[i]
        
        # Wind field
        plotfigure = plotdata.new_plotfigure(name='Wind Speed %s' % label[i], 
                                             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 = afteraxes
        plotaxes.scaled = True
        
        surge.add_wind(plotaxes, bounds=wind_limits, plot_type='pcolor')
        surge.add_land(plotaxes)
        plotaxes.plotitem_dict['wind'].amr_patchedges_show = grids[i]
        plotaxes.plotitem_dict['land'].amr_patchedges_show = grids[i]

    # =====================
    #  Gauge Location Plot
    # =====================
    gauge_xlimits = regions["Mumbai (Grids)"][0]
    gauge_ylimits = regions["Mumbai (Grids)"][1]
    # 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)
        # import pdb; pdb.set_trace()
        surge.gauge_locations(cd, gaugenos=[1, 2, 3])
        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='pcolor',
                                               bounds=surface_limits)
    # surge.plot.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]

    # ========================================================================
    #  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]:
            axes = plt.gca()

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

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


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

    # 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]          # 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]          # 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
示例#29
0
def setplot(plotdata=None):
    """"""

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

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

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

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

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

    # Color limits
    surface_limits = [-5.0, 5.0]
    speed_limits = [0.0, 3.0]
    wind_limits = [0, 64]
    pressure_limits = [935, 1013]
    friction_bounds = [0.01, 0.04]

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

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    regions = {
        "Gulf": {
            "xlimits": (clawdata.lower[0], clawdata.upper[0]),
            "ylimits": (clawdata.lower[1], clawdata.upper[1]),
            "figsize": (6.4, 4.8)
        },
        "LaTex Shelf": {
            "xlimits": (-97.5, -88.5),
            "ylimits": (27.5, 30.5),
            "figsize": (8, 2.7)
        }
    }

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

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

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

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

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Gulf']['xlimits']
    plotaxes.ylimits = regions['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] * 10
    plotaxes.plotitem_dict['friction'].colorbar_label = "$n$"

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

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

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

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

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

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

    def gauge_afteraxes(cd):

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

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

    plotaxes.afteraxes = gauge_afteraxes

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

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

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

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

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

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

    plotdata.printfigs = True  # print figures
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = 'all'  # list of frames to print
    plotdata.print_gaugenos = [1, 2, 3, 4]  # list of gauges to print
    plotdata.print_fignos = 'all'  # list of figures to print
    plotdata.html = True  # create html files of plots?
    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  # parallel plotting

    return plotdata
示例#30
0
def setplot(plotdata=None):
    """"""

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    def gauge_afteraxes(cd):

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

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

    plotaxes.afteraxes = gauge_afteraxes

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

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

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

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

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

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

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

            fg.read_output(outdir=plotdata.outdir)

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

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

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

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

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

    return plotdata
示例#31
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
示例#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 = 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
示例#33
0
def setplot(plotdata=None):
    """"""

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

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

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

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

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

    # Color limits
    surface_limits = [-5.0, 5.0]
    speed_limits = [0.0, 3.0]
    wind_limits = [0, 64]
    pressure_limits = [935, 1013]
    friction_bounds = [0.01, 0.04]

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

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    regions = {
        "Gulf": {
            "xlimits": (clawdata.lower[0], clawdata.upper[0]),
            "ylimits": (clawdata.lower[1], clawdata.upper[1]),
            "figsize": (6.4, 4.8)
        },
        "Long Island": {
            "xlimits": (-74.5, -71.5),
            "ylimits": (40, 41.5),
            "figsize": (8, 2.7)
        }
    }

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

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

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

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

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

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Gulf']['xlimits']
    plotaxes.ylimits = regions['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] * 10
    plotaxes.plotitem_dict['friction'].colorbar_label = "$n$"

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

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

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

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

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

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

    def gauge_afteraxes(cd):

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

        # fetch real data
        noaaArr = [
            "8557380", "8639348", "8662245", "2695540", "8531680", "8510560"
        ]
        gaugeNumber = cd.gaugeno
        if (gaugeNumber < 7):
            # only looking at gauge 1-6 because rest of data not from NOAA Gauges
            realData = geoutil.fetch_noaa_tide_data(
                noaaArr[gaugeNumber - 1],
                datetime.datetime(2015, 9, 30, hour=12),
                datetime.datetime(2015, 10, 6, hour=6))
            values = realData[1] - realData[2]  # de-tide NOAA data
            times = []
            for time in realData[0]:
                times.append(
                    (time - numpy.datetime64("2015-10-02T12:00")).astype(float)
                    / 1440)

            plt.plot(times, values, color="g", label="real")

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

    plotaxes.afteraxes = gauge_afteraxes

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

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

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

    def gauge_2_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[2],
                                        format_string='ko',
                                        add_labels=True)

    def gauge_3_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[3],
                                        format_string='ko',
                                        add_labels=True)

    def gauge_4_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[4],
                                        format_string='ko',
                                        add_labels=True)

    def gauge_5_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[5],
                                        format_string='ko',
                                        add_labels=True)

    def gauge_6_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[6],
                                        format_string='ko',
                                        add_labels=True)

    def gauge_7_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[8],
                                        format_string='ko',
                                        add_labels=True)

    def gauge_8_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos=[9],
                                        format_string='ko',
                                        add_labels=True)

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 1'
    plotaxes.scaled = True
    plotaxes.xlimits = [-75.5, -74.75]
    plotaxes.ylimits = [38.25, 39.25]
    plotaxes.afteraxes = gauge_1_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 2'
    plotaxes.scaled = True
    plotaxes.xlimits = [-76.75, -75.5]
    plotaxes.ylimits = [36.5, 37.5]
    plotaxes.afteraxes = gauge_2_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 3'
    plotaxes.scaled = True
    plotaxes.xlimits = [-79.5, -79]
    plotaxes.ylimits = [33, 33.5]
    plotaxes.afteraxes = gauge_3_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 4'
    plotaxes.scaled = True
    plotaxes.xlimits = [-65.25, -64.25]
    plotaxes.ylimits = [31.75, 32.5]
    plotaxes.afteraxes = gauge_4_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 5'
    plotaxes.scaled = True
    plotaxes.xlimits = [-74.5, -73.5]
    plotaxes.ylimits = [40, 40.75]
    plotaxes.afteraxes = gauge_5_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 6'
    plotaxes.scaled = True
    plotaxes.xlimits = [-72.5, -71.5]
    plotaxes.ylimits = [40.5, 41.5]
    plotaxes.afteraxes = gauge_6_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 7'
    plotaxes.scaled = True
    plotaxes.xlimits = [-75.5, -74]
    plotaxes.ylimits = [23, 24.5]
    plotaxes.afteraxes = gauge_7_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge 8'
    plotaxes.scaled = True
    plotaxes.xlimits = [-74.75, -73.5]
    plotaxes.ylimits = [21.75, 23.25]
    plotaxes.afteraxes = gauge_8_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

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

    plotdata.printfigs = True  # print figures
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = 'all'  # list of frames to print
    plotdata.print_gaugenos = [1, 2, 3, 4, 5, 6, 7,
                               8]  # list of gauges to print
    plotdata.print_fignos = 'all'  # list of figures to print
    plotdata.html = True  # create html files of plots?
    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  # parallel plotting

    return plotdata
示例#34
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
    from numpy import linspace

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

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

    probdata = clawutil.ClawData()
    probdata.read('setprob.data', force=True)
    theta_island = probdata.theta_island


    # 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 for surface
    #-----------------------------------------
    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
    plotaxes.afteraxes = addgauges

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    #plotitem.plot_var = geoplot.surface
    plotitem.plot_var = geoplot.surface_or_depth
    #plotitem.plot_var = 0/1/2 or plot that entry into q instead of a function
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    #plotitem.pcolor_cmin = -1.0
    #plotitem.pcolor_cmax = 1.0
    plotitem.pcolor_cmin = -.005
    plotitem.pcolor_cmax = .005
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.patchedges_show = 1
    #plotitem.patchedges_show = 0

    # Land
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = geoplot.land
    # plotitem.pcolor_cmap = colormaps.all_white  # to print better in B&W
    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]
    #plotitem.patchedges_show = 1
    plotitem.patchedges_show = 0
    plotaxes.xlimits = [-20,20]
    plotaxes.ylimits = [20,60]
    #plotaxes.xlimits = [-5,5]
    #plotaxes.ylimits = [35,45]


    # add contour lines of bathy if desired:
    plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
    plotitem.show = True #False
    plotitem.plot_var = geoplot.topo
    plotitem.contour_levels = [-3500,-2500,-1500, -500, 0, 500]
    plotitem.amr_contour_colors = ['g']  # color on each level
    plotitem.kwargs = {'linestyles':'dashed','linewidths':2,'colors' : 'red' }
    plotitem.amr_contour_show = [0,0,0]  
    plotitem.celledges_show = 0
    plotitem.patchedges_show = 0

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

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes('pcolor')
    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.xticks(fontsize=15)
    #    pylab.yticks(fontsize=15)
    #plotaxes.afteraxes = fixup

    def speed(current_data):
        from pylab import where,sqrt
        q = current_data.q
        h = q[0,:]
        dry_tol = 0.001
        u = q[1,:] # this is just to initialize
        v = q[2,:] # to correct size
        s = 0*q[2,:] # to correct size

        nq = len(q[1,:])
        [n,m] = h.shape
        for ii in range(0,n):
           for jj in range(0,m):
             if h[ii,jj] > dry_tol:
                u[ii,jj] = q[1,ii,jj]/h[ii,jj]
                v[ii,jj] = q[2,ii,jj]/h[ii,jj]
                s[ii,jj] = sqrt(u[ii,jj]* u[ii,jj] + v[ii,jj]*v[ii,jj])
             else:
                u[ii,jj] = 0.
                v[ii,jj] = 0.
                s[ii,jj] = 0
        #print("max of u = " + str(max(u)))
              
        #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 = sqrt(u*2+v*v) #try not dividing or using where
        return s

    # Water
    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = speed
    plotitem.pcolor_cmap = geoplot.tsunami_colormap
    plotitem.pcolor_cmap = \
           colormaps.make_colormap({0:[1,1,1],0.5:[0.5,0.5,1],1:[1,0.3,0.3]})
    plotitem.pcolor_cmin = 0.
    plotitem.pcolor_cmax = .01
    plotitem.add_colorbar = True
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.patchedges_show = 1

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


    #-----------------------------------------
    # Figure for zoom at island
    #-----------------------------------------
    zoomWanted = True
    if zoomWanted:
        plotfigure = plotdata.new_plotfigure(name='Zoom1', figno=7)
        # Set up for axes in this figure:
        plotaxes = plotfigure.new_plotaxes('zoom on island')
        plotaxes.title = 'Surface elevation'
        plotaxes.scaled = True
        xisland,yisland = latlong(1600e3, theta_island, 40., Rearth)
        plotaxes.xlimits = [xisland-0.6, xisland+0.6]
        plotaxes.ylimits = [yisland-0.6, yisland+0.6]
        #plotaxes.afteraxes = addgauges
        def bigfont(current_data):
            import pylab
            t = current_data.t
            pylab.title("Surface at t = %8.1f" % t, fontsize=20)
            pylab.xticks(fontsize=15)
            pylab.yticks(fontsize=15)
        plotaxes.afteraxes = bigfont
        plotaxes.afteraxes = addgauges

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

        # Land
        plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
        plotitem.show = True
        plotitem.plot_var = geoplot.land
        # plotitem.pcolor_cmap = colormaps.all_white  # to print better in B&W
        plotitem.pcolor_cmap = geoplot.land_colors
        plotitem.pcolor_cmin = 0.0
        plotitem.pcolor_cmax = 100.0
        plotitem.add_colorbar = False
        plotitem.amr_celledges_show = [1,0,0,0,0]
        plotitem.patchedges_show = 1

        # contour lines:
        plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
        plotitem.show = True
        plotitem.plot_var = geoplot.surface
        plotitem.contour_levels = [-0.8, -0.4, 0.4, 0.8]
        plotitem.amr_contour_colors = ['k']  # color on each level
        plotitem.kwargs = {'linewidths':2}
        plotitem.amr_contour_show = [0,0,0,1,1]  
        plotitem.celledges_show = 0
        plotitem.patchedges_show = 0

        # add contour lines of bathy if desired:
        plotitem = plotaxes.new_plotitem(plot_type='2d_contour')
        plotitem.show = False
        plotitem.plot_var = geoplot.topo
        plotitem.contour_levels = linspace(-1000,-1000,1)
        plotitem.amr_contour_colors = ['g']  # color on each level
        plotitem.kwargs = {'linestyles':'dashed','linewidths':2}
        plotitem.amr_contour_show = [0,0,1]  
        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 = [0000, 5000]
    plotaxes.ylimits = [-.10, .10]
    #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')

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

    def gaugedpress(current_data):
        q = current_data.q
        #dpress = (q[4,:] - 101300)/101300
        dpress = q[4,:]  # already output as relative:  dp/amb_pr
        return dpress

    def gs(current_data):
        q = current_data.q
        # different than speed function because q is function of time, not
        # x,y at the gauges.
        from numpy import where, sqrt
        h = q[0,:]
        #print('shape of h ' +  str(h.shape))
        dry_tol = 0.001
        u = where(h>dry_tol, q[1,:]/h, 0.)
        v = where(h>dry_tol, q[2,:]/h, 0.)
        ssq = sqrt(u*u+v*v)
        #s = sqrt(u**2 + v**2)
        s = sqrt(ssq)
        return ssq
        
    #plotitem.plot_var = gaugetopo
    #plotitem.plotstyle = 'g-'

    # Plot relative delta pressure as red curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = gaugedpress
    plotitem.plotstyle = 'r-'

    # add speed to this plot since cant get new one going
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
    plotitem.plot_var = gs
    plotitem.plotstyle = 'g-'

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

    plotaxes.afteraxes = add_zeroline

    # -------------------------------
    # Figure for speed at gauges
    #--------------------------------

#    plotfigure = plotdata.new_plotfigure(name='Speed at gauges', figno=310, \
#                    type='each_gauge')
#

#
#    # Set up for axes in this figure:
#    plotaxes = plotfigure.new_plotaxes()
#    plotaxes.xlimits = 'auto'
#    plotaxes.ylimits = 'auto'
#    #plotaxes.xlimits = [0000, 7000]
#    #plotaxes.ylimits = 'auto'
#    plotaxes.title = 'Speed'
#
#    # Plot surface as blue curve:
#    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')
#    #plotitem.plot_var = speed
#    plotitem.plot_var = gs  #gauge_speed
#    plotitem.plotstyle = 'b-'
#
#    plotfigure.show = True 
#

    #-----------------------------------------
    # Figure for bathy alone
    #-----------------------------------------
    def bathy(current_data):
        return current_data.aux[0,:,:]

    plotfigure = plotdata.new_plotfigure(name='bathymetry', figno=3)
    plotaxes = plotfigure.new_plotaxes('pcolor')
    plotaxes.title = 'Bathymetry'
    plotaxes.scaled = True

    plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
    plotitem.plot_var = bathy
    plotitem.pcolor_cmin = -4000.00
    plotitem.pcolor_cmax = 100
    plotitem.add_colorbar = True



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

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

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

    
    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure')
    plotfigure.show = True
    
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [-20,20]
    plotaxes.ylimits = [20,60]
    #plotaxes.xlimits = [-5,5]
    #plotaxes.ylimits = [35,45]
    plotaxes.title = "Pressure Field"
    # plotaxes.afteraxes = gulf_after_axes
    plotaxes.scaled = True
    
    #pressure_limits = [surge_data.ambient_pressure / 100.0, 
    #                   2.0 * surge_data.ambient_pressure / 100.0]
    pressure_limits = [.999*surge_data.ambient_pressure / 100.0, 
                       1.001 * surge_data.ambient_pressure / 100.0]
    #pressure_limits = [-.000001*surge_data.ambient_pressure, 
    #                   .000001 * surge_data.ambient_pressure]
    surgeplot.add_pressure(plotaxes, bounds=pressure_limits)
    surgeplot.add_land(plotaxes)

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