예제 #1
0
    def setUp(self):

        super(DTopoTests, self).setUp()

        # Make topography
        h0 = 1000.0
        topo_func = lambda x,y: -h0*(1 + 0.5 * numpy.cos(x - y))
        topo = topotools.Topography(topo_func=topo_func)
        topo.topo_type = 2
        topo.x = numpy.linspace(-10.0, 10.0, 201)
        topo.y = numpy.linspace(-10.0, 10.0, 201)
        topo.write(os.path.join(self.temp_path, "topo1.topotype2"))

        h0 = 1000.0
        topo_func = lambda x,y: -h0*(1. + numpy.exp(x+y))
        topo = topotools.Topography(topo_func=topo_func)
        topo.topo_type = 2
        topo.x = numpy.linspace(-0.5, -0.3, 21)
        topo.y = numpy.linspace(-0.1, 0.4, 51)
        topo.write(os.path.join(self.temp_path, "topo2.topotype2"))

        # Make dtopography
        subfault_path = os.path.join(self.test_path, "dtopo1.csv")
        input_units = {'slip': 'm', 'depth': 'km', 'length': 'km', 'width': 'km'}
        fault = dtopotools.CSVFault()
        fault.read(subfault_path, input_units=input_units, 
                coordinate_specification="top center")
        fault.rupture_type = 'dynamic'
        times = numpy.linspace(0.0, 1.0, 25)
        x = numpy.linspace(-0.4,0.6,151)
        y = numpy.linspace(-0.4,0.4,121)
        dtopo = fault.create_dtopography(x,y,times=times)
        dtopo.write(os.path.join(self.temp_path, "dtopo1.tt3"), dtopo_type=3)

        subfault_path = os.path.join(self.test_path, "dtopo2.csv")
        input_units = {'slip': 'm', 'depth': 'km', 'length': 'km', 'width': 'km'}
        fault = dtopotools.CSVFault()
        fault.read(subfault_path, input_units=input_units, 
                    coordinate_specification="top center")
        fault.rupture_type = 'dynamic'
        times = numpy.linspace(0.5, 1.2, 25)
        x = numpy.linspace(-0.9,0.1,201)
        y = numpy.linspace(-0.4,0.4,161)
        dtopo = fault.create_dtopography(x,y,times=times)
        dtopo.write(os.path.join(self.temp_path, "dtopo2.tt3"), dtopo_type=3)

        # copy existing file:
        shutil.copy(os.path.join(self.test_path, "dtopo3.tt1"),
                                 self.temp_path)
예제 #2
0
def test_read_csv_make_dtopo(save=False):
    r"""Test reading and making of a CSV subfault speficied dtopo."""

    subfault_path = os.path.join(testdir, 'data', 'alaska1964.csv')
    input_units = {
        "length": "km",
        "width": "km",
        "depth": "km",
        "slip": "m",
        "mu": "dyne/cm^2"
    }
    fault = dtopotools.CSVFault()
    fault.read(subfault_path,
               input_units=input_units,
               coordinate_specification="noaa sift")

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

    xlower = 203
    xupper = 214.  # approximate - adjusted below
    ylower = 55
    yupper = 60.  # approximate - adjusted below

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

    dtopo = fault.create_dtopography(x, y, times=[1.])

    test_data_path = os.path.join(testdir, "data", "alaska1964_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)
예제 #3
0
def read_fault(fname_subfaults, plotfig=None):
    """
    Test data
    """

    input_units = {'slip': 'm', 'depth': 'km', 'length': 'km', 'width': 'km'}

    fault = dtopotools.CSVFault()
    fault.read(fname_subfaults, input_units=input_units, 
                coordinate_specification="top center")
    fault.rupture_type = 'dynamic'
                    
    if plotfig:
        plt.figure(plotfig)
        fault.plot_subfaults(slip_color=True,plot_rake=True)
        
    return fault
예제 #4
0
def test_vs_old_dtopo():
    r"""Test new dtopotools with old version from 5.2"""

    raise nose.SkipTest("Skipping comparison with old tools.")

    from . import old_dtopotools

    temp_path = tempfile.mkdtemp()
    try:
        subfault_path = os.path.join(testdir, 'data', 'alaska1964.csv')
        old_dtopo_file = os.path.join(temp_path, 'old_alaska.tt1')
        old_dtopotools.builddynamicdeffile(subfault_path, subfault_path,
                                           old_dtopo_file)

        input_units = {
            "length": "km",
            "width": "km",
            "depth": "km",
            "slip": "m",
            "mu": "dyne/cm^2"
        }
        fault = dtopotools.CSVFault()
        fault.read(subfault_path,
                   input_units=input_units,
                   coordinate_specification="noaa sift")
        new_dtopo = fault.create_dtopography()

        X, Y, dZ = old_dtopotools.read_dtopo_old(old_dtopo_file,
                                                 deftype='dynamic',
                                                 only_last=False)

        assert numpy.allclose(X, new_dtopo.X), \
               "X values do not agree between old and new dtopotools."

        assert numpy.allclose(Y, new_dtopo.Y), \
               "Y values do not agree between old and new dtopotools."

        assert numpy.allclose(dZ, new_dtopo.dZ), \
               "dZ values do not agree between old and new dtopotools."

    except AssertionError as e:
        shutil.copy(temp_path, )
        raise e
    finally:
        shutil.rmtree(temp_path)
예제 #5
0
def test_geometry():
    r"""Test subfault geometry calculation."""

    from . import old_dtopotools

    subfault_path = os.path.join(testdir, 'data', 'alaska1964.csv')
    input_units = {
        "length": "km",
        "width": "km",
        "depth": "km",
        "slip": "m",
        "mu": "dyne/cm^2"
    }
    specifications = ['top center', 'centroid', 'bottom center', 'noaa sift']

    for specification in specifications:
        fault = dtopotools.CSVFault()
        fault.read(subfault_path,
                   input_units=input_units,
                   coordinate_specification=specification)

        # Subfault 10 is chosen at random, maybe do all?
        subfault = fault.subfaults[10]
        geometry = old_dtopotools.set_geometry(subfault)

        coord_tests = {
            "top center": {
                'test':
                [geometry['x_top'], geometry['y_top'], geometry['depth_top']],
                'computed':
                subfault.centers[0]
            },
            "centroid": {
                'test': [geometry['x_centroid'], geometry['y_centroid']],
                'computed': subfault.centers[1][:2]
            },
            "bottom center": {
                "test": [
                    geometry['x_bottom'], geometry['y_bottom'],
                    geometry['depth_bottom']
                ],
                "computed":
                subfault.centers[2]
            },
            "Corner A": {
                "test": [geometry["x_corners"][2], geometry["y_corners"][2]],
                "computed": subfault.corners[0][:2]
            },
            "Corner B": {
                "test": [geometry["x_corners"][3], geometry["y_corners"][3]],
                "computed": subfault.corners[1][:2]
            },
            "Corner C": {
                "test": [geometry["x_corners"][0], geometry["y_corners"][0]],
                "computed": subfault.corners[2][:2]
            },
            "Corner D": {
                "test": [geometry["x_corners"][1], geometry["y_corners"][1]],
                "computed": subfault.corners[3][:2]
            }
        }

        for (values, coord_test) in six.iteritems(coord_tests):
            assert numpy.allclose(coord_test['test'], coord_test['computed']), \
                   "Specification = %s, coords= %s:\n%s !=\n%s" % (
                                                         specification,
                                                         values,
                                                         coord_test['test'],
                                                         coord_test['computed'])