Beispiel #1
0
    def test_correlation_with_anxcor_data_scheme(self):
        tau=None
        starttime   = UTCDateTime("2017-10-01 06:00:00").timestamp
        starttime_utc = UTCDateTime("2017-10-01 06:00:00")
        endtime_utc = UTCDateTime("2017-10-01 06:10:00")
        anxcor_main = build_anxcor(tau)

        result          = anxcor_main.process([starttime])
        source_np_array = convert_xarray_to_np_array(result,variable='src:BB rec:Nodal')
        target_np_array = get_obspy_correlation(starttime_utc,endtime_utc)
        source_stream = numpy_2_stream(source_np_array)
        target_stream = numpy_2_stream(target_np_array)
        source_stream.normalize()
        target_stream.normalize()

        np.assert_allclose(source_stream[0].data, target_stream[0].data, atol=1e-5)
Beispiel #2
0
 def test_matrix_norms(self):
     # Not all of these are matrix norms in the most technical sense.
     np.random.seed(1234)
     for n, m in (1, 1), (1, 3), (3, 1), (4, 4), (4, 5), (5, 4):
         for t in np.single, np.double, np.csingle, np.cdouble, np.int64:
             A = 10 * np.random.randn(n, m).astype(t)
             if np.issubdtype(A.dtype, np.complexfloating):
                 A = (A + 10j * np.random.randn(n, m)).astype(t)
                 t_high = np.cdouble
             else:
                 t_high = np.double
             for order in (None, 'fro', 1, -1, 2, -2, np.inf, -np.inf):
                 actual = norm(A, ord=order)
                 desired = np.linalg.norm(A, ord=order)
                 # SciPy may return higher precision matrix norms.
                 # This is a consequence of using LAPACK.
                 if not np.allclose(actual, desired):
                     desired = np.linalg.norm(A.astype(t_high), ord=order)
                     np.assert_allclose(actual, desired)
Beispiel #3
0
def test_spherical_shell_three_dim_adaptive_discret():  # pylint: disable=too-many-locals
    "Compare numerical result with analytical solution for 3D adaptive discretization"
    # Define computation point located on the equator at 1km above mean Earth radius
    ellipsoid = get_ellipsoid()
    radius = ellipsoid.mean_radius + 1e3
    coordinates = [0, 0, radius]
    # Define shape of spherical shell model made of tesseroids
    shape = (6, 6)
    # Define a density for the shell
    density = 1000
    # Define different values for the spherical shell thickness
    thicknesses = np.logspace(1, 5, 5)
    for thickness in thicknesses:
        # Create list of tesseroids for the spherical shell model
        tesseroids = []
        # Define boundary coordinates of each tesseroid
        top = ellipsoid.mean_radius
        bottom = top - thickness
        longitude = np.linspace(0, 360, shape[0] + 1)
        latitude = np.linspace(-90, 90, shape[1] + 1)
        west, east = longitude[:-1], longitude[1:]
        south, north = latitude[:-1], latitude[1:]
        for w, e in zip(west, east):
            for s, n in zip(south, north):
                tesseroids.append([w, e, s, n, bottom, top])
        # Compute gravitational fields of the spherical shell
        numerical = {"potential": 0, "g_r": 0}
        for tesseroid in tesseroids:
            for field in numerical:
                numerical[field] += tesseroid_gravity(
                    coordinates,
                    tesseroid,
                    density,
                    field=field,
                    radial_adaptive_discretization=True,
                )
        # Get analytical solutions
        analytical = spherical_shell_analytical(top, bottom, density, radius)
        # Assert analytical and numerical solution are bellow the accuracy threshold
        for field in numerical:
            np.assert_allclose(
                analytical[field], numerical[field], rtol=accuracy_threshold
            )
Beispiel #4
0
 def test_matrix_norms(self):
     # Not all of these are matrix norms in the most technical sense.
     np.random.seed(1234)
     for n, m in (1, 1), (1, 3), (3, 1), (4, 4), (4, 5), (5, 4):
         for t in np.single, np.double, np.csingle, np.cdouble, np.int64:
             A = 10 * np.random.randn(n, m).astype(t)
             if np.issubdtype(A.dtype, np.complexfloating):
                 A = (A + 10j * np.random.randn(n, m)).astype(t)
                 t_high = np.cdouble
             else:
                 t_high = np.double
             for order in (None, 'fro', 1, -1, 2, -2, np.inf, -np.inf):
                 actual = norm(A, ord=order)
                 desired = np.linalg.norm(A, ord=order)
                 # SciPy may return higher precision matrix norms.
                 # This is a consequence of using LAPACK.
                 if not np.allclose(actual, desired):
                     desired = np.linalg.norm(A.astype(t_high), ord=order)
                     np.assert_allclose(actual, desired)