Example #1
0
def test_read_ucsb_make_dtopo(save=False):
    r"""Test reading and making of a UCSB subfault speficied dtopo."""

    subfault_path = os.path.join(testdir, 'data', 'tohoku_ucsb.txt')
    fault = dtopotools.UCSBFault()
    fault.read(subfault_path)

    assert abs(fault.Mw() -
               9.13957973) < 1e-4, "*** Mw is wrong: %g" % fault.Mw()

    xlower = 140.
    xupper = 146.
    ylower = 35.
    yupper = 41.

    # dtopo parameters:
    points_per_degree = 4  # 15 minute resolution
    dx = 1. / points_per_degree
    mx = int((xupper - xlower) / dx + 1)
    xupper = xlower + (mx - 1) * dx
    my = int((yupper - ylower) / dx + 1)
    yupper = ylower + (my - 1) * dx

    x = numpy.linspace(xlower, xupper, mx)
    y = numpy.linspace(ylower, yupper, my)

    tmax = 0.
    for s in fault.subfaults:
        tmax = max(tmax, s.rupture_time + s.rise_time + s.rise_time_ending)

    fault.rupture_type = 'dynamic'
    times = numpy.linspace(0, tmax, 10)
    dtopo = fault.create_dtopography(x, y, times)

    test_data_path = os.path.join(testdir, "data", "tohoku_test_data.tt3")
    if save:
        dtopo.write(test_data_path, dtopo_type=3)
    compare_data = dtopotools.DTopography(path=test_data_path)
    compare_data.read(path=test_data_path, dtopo_type=3)

    assert dtopo.dZ.shape == compare_data.dZ.shape, \
        "dtopo.dZ.shape is %s, should be %s" \
        % (dtopo.dZ.shape, compare_data.dZ.shape)

    assert numpy.allclose(compare_data.dZ, dtopo.dZ)
Example #2
0
#!/usr/bin/env python

from __future__ import print_function

import numpy
import matplotlib.pyplot as plt

import clawpack.geoclaw.dtopotools as dtopotools

# Comparison Fault System
UCSB_fault = dtopotools.UCSBFault('./UCSB_model3_subfault.txt')

# Use data from the reconstruced UCSB fault to setup our fault system
# Calculate average quantities across all subfaults
ave_rake = 0.0
ave_strike = 0.0
ave_slip = 0.0
for subfault in UCSB_fault.subfaults:
    ave_rake += subfault.rake
    ave_strike += subfault.strike
    ave_slip += subfault.slip

ave_rake /= len(UCSB_fault.subfaults)
ave_strike /= len(UCSB_fault.subfaults)
ave_slip /= len(UCSB_fault.subfaults)
print("Averages:")
print("  Rake   = %s" % ave_rake)
print("  Strike = %s" % ave_strike)
print("  Slip   = %s" % ave_slip)

# Base subfault - based on reconstruction by UCSB
Example #3
0
def test_dynamic_tohoku(verbose=False, plot=False):
    r"""Test dynamic faulting via a Tohoku example"""

    shoreline_fname = os.path.join(testdir, 'data',
                                   'tohoku_shoreline_1min.npy')
    shoreline_xy = numpy.load(shoreline_fname)

    subfault_fname = os.path.join(testdir, 'data', 'tohoku_ucsb.txt')
    fault = dtopotools.UCSBFault()
    fault.read(subfault_fname)
    fault.rupture_type = 'dynamic'

    if plot:
        import matplotlib.pyplot as plt

        fault.plot_subfaults(slip_color=True)  # plot final slip
        plt.show()

    # seafloor deformation:
    quick_test = True

    if quick_test:
        xlower = 140.
        xupper = 146.
        ylower = 35.
        yupper = 41.
        xylim = [xlower, xupper, ylower, yupper]

        # dtopo parameters for 4 min resolution:
        mx = int((xupper - xlower) * 15 + 1)
        my = int((yupper - ylower) * 15 + 1)
    else:
        xlower = 135.
        xupper = 150.
        ylower = 30.
        yupper = 45.
        xylim = [xlower, xupper, ylower, yupper]

        # dtopo parameters for 1 min resolution:
        mx = int((xupper - xlower) * 60 + 1)
        my = int((yupper - ylower) * 60 + 1)

    x = numpy.linspace(xlower, xupper, mx)
    y = numpy.linspace(ylower, yupper, my)

    tmax = 0.
    for s in fault.subfaults:
        tmax = max(tmax, s.rupture_time + s.rise_time + s.rise_time_ending)
    if verbose:
        print("rupture ends at time ", tmax)

    times = numpy.linspace(0, tmax, 10)
    dtopo = fault.create_dtopography(x, y, times, verbose=True)

    dz_final = dtopo.dZ[-1]
    dz_max = dz_final.max()

    if plot:
        # Incorporate this function in dtopotools to replace animate_dz_colors?
        def plot_subfaults_dz(t, fig=None):
            if fig is None:
                fig = plt.figure(figsize=(12, 5))
            else:
                fig.clf()
            ax1 = fig.add_subplot(121)
            ax2 = fig.add_subplot(122)
            fault.plot_subfaults(axes=ax1,
                                 slip_color=True,
                                 slip_time=t,
                                 xylim=xylim)
            dtopo.plot_dz_colors(axes=ax2, t=t, cmax_dz=dz_max)
            ax1.plot(shoreline_xy[:, 0], shoreline_xy[:, 1], 'g')
            ax2.plot(shoreline_xy[:, 0], shoreline_xy[:, 1], 'g')
            plt.axis(xylim)
            fig.show()
            return fig

        dtopo.plot_dz_colors(t=tmax)
        plt.show()

        fig = plt.figure(figsize=(12, 5))

        for t in list(numpy.linspace(0, 150, 16)) + [170, 200]:
            plot_subfaults_dz(t, fig)
            plt.draw()
            plt.show()
            time.sleep(1)

    temp_path = tempfile.mkdtemp()
    try:
        fname = os.path.join(temp_path, 'tohoku_ucsb_dynamic.tt3')
        dtopo.write(fname, 3)
    except Exception as e:
        test_name = inspect.stack()[1][-2][0][:-3]
        test_dump_path = os.path.join(os.getcwd(), test_name)
        shutil.mkdir(test_dump_path)
        shutil.copy(temp_path, test_dump_path)
        raise e
    finally:
        shutil.rmtree(temp_path)

    if verbose:
        print('Created ', fname)
Example #4
0
    def __init__(self, slips):
        r"""
        Initialize a FaultJob object.
        
        See :class:`FaultJob` for full documentation
        
        """

        super(FaultJob, self).__init__()

        # Create fault
        # Based on UCSB reconstruction and assumption of single subfault
        # Lengths are based on num_fault_segments * dx * m/km in each direction
        #
        # Top edge    Bottom edge
        #   a ----------- b          ^
        #   |             |          |         ^
        #   |             |          |         |
        #   |             |          |         | along-strike direction
        #   |             |          |         |
        #   0------1------2          | length  |
        #   |             |          |
        #   |             |          |
        #   |             |          |
        #   |             |          |
        #   d ----------- c          v
        #   <------------->
        #       width
        # <-- up dip direction
        #
        #  Given
        #      Long            Lat             Depth
        #  a = 144.56380       39.66720        7.50520
        #  b = 140.76530       36.15960       41.96770
        #  c = 142.43800       40.21080       41.96770
        #  d = 142.89110       35.61610        7.50520
        #  Computed
        #      Long            Lat             Depth
        #  0 = 143.72745       37.64165        7.50520
        # Comparison Fault System
        UCSB_fault = dtopotools.UCSBFault('./UCSB_model3_subfault.txt')

        # Use data from the reconstruced UCSB fault to setup our fault system
        # Calculate average quantities across all subfaults
        ave_rake = 0.0
        ave_strike = 0.0
        ave_slip = 0.0
        for subfault in UCSB_fault.subfaults:
            ave_rake = subfault.rake
            ave_strike = subfault.strike
            ave_slip = subfault.slip

        ave_rake /= len(UCSB_fault.subfaults)
        ave_strike /= len(UCSB_fault.subfaults)
        ave_slip /= len(UCSB_fault.subfaults)

        # Base subfault
        self.base_subfault = dtopotools.SubFault()
        self.base_subfault.strike = 198.0
        self.base_subfault.length = 19 * 25.0 * 1000.0
        self.base_subfault.width = 10 * 20.0 * 1000.0
        self.base_subfault.depth = 7.50520 * 1000.0
        self.base_subfault.slip = slip
        self.base_subfault.rake = 90.0
        self.base_subfault.dip = 10.0
        self.base_subfault.latitude = 37.64165
        self.base_subfault.longitude = 143.72745
        self.base_subfault.coordinate_specification = "top center"

        # Create base subdivided fault
        self.fault = dtopotools.SubdividedPlaneFault(self.base_subfault,
                                                     nstrike=3,
                                                     ndip=2)
        for (k, subfault) in enumerate(self.fault.subfaults):
            subfault.slip = slips[k]

        self.type = "tohoku"
        self.name = "okada-fault-PC-analysis"
        self.prefix = "fault_s%s" % (self.base_subfault.slip)
        self.executable = 'xgeoclaw'

        # Data objects
        import setrun
        self.rundata = setrun.setrun()

        # No variable friction for the time being
        self.rundata.friction_data.variable_friction = False

        # Replace dtopo file with our own
        self.dtopo_path = 'fault_s%s.tt3' % self.base_subfault.slip
        self.rundata.dtopo_data.dtopofiles = [[3, 4, 4, self.dtopo_path]]