示例#1
0
def test_tesseroid_vs_spherical_shell():
    "gravmag.tesseroid equal analytical solution of spherical shell to 0.1%"
    density = 1000.
    top = 1000
    bottom = 0
    model = TesseroidMesh((0, 360, -90, 90, top, bottom), (1, 6, 12))
    model.addprop('density', density*np.ones(model.size))
    h = 10000
    lon, lat, height = gridder.regular((0, model.dims[0], 0, model.dims[1]),
                                       (10, 10), z=h)
    funcs = ['potential', 'gx', 'gy', 'gz', 'gxx', 'gxy', 'gxz', 'gyy', 'gyz',
             'gzz']
    shellvalues = calc_shell_effect(h, top, bottom, density)
    for f in funcs:
        shell = shellvalues[f]
        tess = getattr(tesseroid, f)(lon, lat, height, model)
        diff = np.abs(shell - tess)
        # gz gy and the off-diagonal gradients should be zero so I can't
        # calculate a relative error (in %).
        # To do that, I'll use the gz and gzz shell values to calculate the
        # percentage.
        if f in 'gx gy'.split():
            shell = shellvalues['gz']
        elif f in 'gxy gxz gyz'.split():
            shell = shellvalues['gzz']
        diff = 100*diff/np.abs(shell)
        assert diff.max() < 0.1, "diff > 0.1% for {}: {}".format(
            f, diff.max())
示例#2
0
def test_numba_vs_python():
    "gravmag.tesseroid numba and pure python implementations give same result"
    model = TesseroidMesh((0, 1, 0, 2, 1000, 0), (2, 2, 1))
    model.addprop('density', -200*np.ones(model.size))
    lon, lat, height = gridder.regular((0, 1, 0, 2), (20, 20), z=250e3)
    for f in 'potential gx gy gz gxx gxy gxz gyy gyz gzz'.split():
        func = getattr(tesseroid, f)
        py = func(lon, lat, height, model, engine='numpy')
        nb = func(lon, lat, height, model, engine='numba')
        assert_allclose(nb, py, err_msg="Mismatch for {}".format(f))
示例#3
0
def test_serial_vs_parallel():
    "gravmag.tesseroid serial and parallel execution give same result"
    model = TesseroidMesh((-1, 1.5, -2, 2, 0, -10e3), (3, 2, 1))
    model.addprop('density', 500*np.ones(model.size))
    lon, lat, height = gridder.regular((-1, 1.5, -2, 2), (15, 21), z=150e3)
    njobs = 3
    for f in 'potential gx gy gz gxx gxy gxz gyy gyz gzz'.split():
        func = getattr(tesseroid, f)
        serial = func(lon, lat, height, model, njobs=1)
        parallel = func(lon, lat, height, model, njobs=njobs)
        assert_allclose(serial, parallel, err_msg="Mismatch for {}".format(f))