Пример #1
0
def test_upcontinue():
    "gravmag.transform upward continuation matches analytical solution"
    model = [Prism(-1000, 1000, -500, 500, 0, 1000,
                   {'density': 1000,
                    'magnetization': utils.ang2vec(5, 20, -30)})]
    shape = (100, 100)
    inc, dec = -10, 15
    x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=-500)
    dz = 10
    fields = 'potential gx gy gz gxx gxy gxz gyy gyz gzz'.split()
    accuracy = [0.002, 0.2, 0.2, 0.3, 2, 2, 4, 4, 4, 6]
    for f, atol in zip(fields, accuracy):
        func = getattr(prism, f)
        data = func(x, y, z, model)
        analytical = func(x, y, z + dz, model)
        up = transform.upcontinue(x, y, data, shape, dz)
        diff = np.abs(up - analytical)
        check = diff <= atol
        assert np.all(check), \
            'Failed for {} (mismatch {:.2f}%)'.format(
            f, 100*(check.size - check.sum())/check.size)
    data = prism.tf(x, y, z, model, inc, dec)
    analytical = prism.tf(x, y, z + dz, model, inc, dec)
    up = transform.upcontinue(x, y, data, shape, dz)
    diff = np.abs(up - analytical)
    check = diff <= 15
    assert np.all(check), \
        'Failed for tf (mismatch {:.2f}%)'.format(
        100*(check.size - check.sum())/check.size)
Пример #2
0
def test_upcontinue():
    "gravmag.transform upward continuation matches analytical solution"
    model = [
        Prism(-1000, 1000, -500, 500, 0, 1000, {
            'density': 1000,
            'magnetization': utils.ang2vec(5, 20, -30)
        })
    ]
    shape = (100, 100)
    inc, dec = -10, 15
    x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=-500)
    dz = 10
    fields = 'potential gx gy gz gxx gxy gxz gyy gyz gzz'.split()
    accuracy = [0.002, 0.2, 0.2, 0.3, 2, 2, 4, 4, 4, 6]
    for f, atol in zip(fields, accuracy):
        func = getattr(prism, f)
        data = func(x, y, z, model)
        analytical = func(x, y, z + dz, model)
        up = transform.upcontinue(x, y, data, shape, dz)
        diff = np.abs(up - analytical)
        check = diff <= atol
        assert np.all(check), \
            'Failed for {} (mismatch {:.2f}%)'.format(
            f, 100*(check.size - check.sum())/check.size)
    data = prism.tf(x, y, z, model, inc, dec)
    analytical = prism.tf(x, y, z + dz, model, inc, dec)
    up = transform.upcontinue(x, y, data, shape, dz)
    diff = np.abs(up - analytical)
    check = diff <= 15
    assert np.all(check), \
        'Failed for tf (mismatch {:.2f}%)'.format(
        100*(check.size - check.sum())/check.size)
Пример #3
0
def test_upcontinue_warning():
    "gravmag.transform upward continuation raises warning if height <= 0"
    model = [Prism(-1000, 1000, -500, 500, 0, 1000, {'density': 1000})]
    shape = (100, 100)
    x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=-500)
    data = prism.gz(x, y, z, model)
    with pytest.warns(UserWarning):
        up = transform.upcontinue(x, y, data, shape, height=0)
    with pytest.warns(UserWarning):
        up = transform.upcontinue(x, y, data, shape, height=-100)
Пример #4
0
def test_upcontinue_warning():
    "gravmag.transform upward continuation raises warning if height <= 0"
    model = [Prism(-1000, 1000, -500, 500, 0, 1000, {'density': 1000})]
    shape = (100, 100)
    x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=-500)
    data = prism.gz(x, y, z, model)
    with pytest.warns(UserWarning):
        up = transform.upcontinue(x, y, data, shape, height=0)
    with pytest.warns(UserWarning):
        up = transform.upcontinue(x, y, data, shape, height=-100)
Пример #5
0
mesh = _makemesh(xp, yp, shape, zmin=0, zmax=maxdepth, nlayers=nlayers)
# This way, if z is not an array, it is now
zp = zp * np.ones_like(xp)

depths = mesh.get_zs()[:-1]
density = []

up_f_sec = []
up_f_d1_sec = []
up_f_d2_sec = []

for depth in depths - zp[0]:

    # continued field calculation
    up_f = transform.upcontinue(xp, yp, gz, shape, depth)
    xx, yy, distance, p_up_f = gridder.profile(xp, yp, up_f, p1, p2, 1000)
    up_f_sec = np.concatenate([up_f_sec, p_up_f])

    # 1st vertical derivate of the continued field
    up_f_d1 = transform.derivz(xp, yp, up_f, shape, order=1)
    xx, yy, distance, p_up_f_d1 = gridder.profile(xp, yp, up_f_d1, p1, p2,
                                                  1000)
    up_f_d1_sec = np.concatenate([up_f_d1_sec, p_up_f_d1])

    # 2nd vertical derivate of the continued field
    up_f_d2 = transform.derivz(xp, yp, up_f, shape, order=2)
    xx, yy, distance, p_up_f_d2 = gridder.profile(xp, yp, up_f_d2, p1, p2,
                                                  1000)
    up_f_d2_sec = np.concatenate([up_f_d2_sec, p_up_f_d2])
from fatiando.gravmag import prism, transform
from fatiando.vis import mpl

model = [mesher.Prism(-3000,-2000,-3000,-2000,500,2000,{'density':1000}),
         mesher.Prism(-1000,1000,-1000,1000,0,2000,{'density':-800}),
         mesher.Prism(1000,3000,2000,3000,0,1000,{'density':500})]
area = (-5000, 5000, -5000, 5000)
shape = (50, 50)
z0 = -100
xp, yp, zp = gridder.regular(area, shape, z=z0)
gz = utils.contaminate(prism.gz(xp, yp, zp, model), 0.5)

# Now do the upward continuation using the analytical formula
height = 2000
dims = gridder.spacing(area, shape)
gzcont = transform.upcontinue(gz, height, xp, yp, dims)

gztrue = prism.gz(xp, yp, zp - height, model)

mpl.figure(figsize=(14,6))
mpl.subplot(1, 2, 1)
mpl.title("Original")
mpl.axis('scaled')
mpl.contourf(xp, yp, gz, shape, 15)
mpl.contour(xp, yp, gz, shape, 15)
mpl.subplot(1, 2, 2)
mpl.title("Continued + true")
mpl.axis('scaled')
levels = mpl.contour(xp, yp, gzcont, shape, 12, color='b',
    label='Continued', style='dashed')
mpl.contour(xp, yp, gztrue, shape, levels, color='r', label='True',
Пример #7
0
from fatiando.vis import mpl
import numpy as np

model = [
    mesher.Prism(-3000, -2000, -3000, -2000, 500, 2000, {'density': 1000}),
    mesher.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'density': -800}),
    mesher.Prism(1000, 3000, 2000, 3000, 0, 1000, {'density': 900})
]
area = (-5000, 5000, -5000, 5000)
shape = (50, 50)
z0 = -100
x, y, z = gridder.regular(area, shape, z=z0)
gz = utils.contaminate(prism.gz(x, y, z, model), 0.5, seed=0)

height = 1000  # How much higher to go
gzcontf = transform.upcontinue(x, y, gz, shape, height)

# Compute the true value at the new height for comparison
gztrue = prism.gz(x, y, z - height, model)

args = dict(shape=shape, levels=20, cmap=mpl.cm.RdBu_r)
fig, axes = mpl.subplots(1, 3, figsize=(12, 3.5))
axes = axes.ravel()
mpl.sca(axes[0])
mpl.title("Original")
mpl.axis('scaled')
mpl.contourf(x, y, gz, **args)
mpl.colorbar(pad=0).set_label('mGal')
mpl.m2km()
mpl.sca(axes[1])
mpl.title('True higher')
from fatiando.gravmag import prism, transform
from fatiando.vis import mpl
import numpy as np

model = [
    mesher.Prism(-3000, -2000, -3000, -2000, 500, 2000, {'density': 1000}),
    mesher.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'density': -800}),
    mesher.Prism(1000, 3000, 2000, 3000, 0, 1000, {'density': 900})]
area = (-5000, 5000, -5000, 5000)
shape = (50, 50)
z0 = -100
x, y, z = gridder.regular(area, shape, z=z0)
gz = utils.contaminate(prism.gz(x, y, z, model), 0.5, seed=0)

height = 1000  # How much higher to go
gzcontf = transform.upcontinue(x, y, gz, shape, height)

# Compute the true value at the new height for comparison
gztrue = prism.gz(x, y, z - height, model)

args = dict(shape=shape, levels=20, cmap=mpl.cm.RdBu_r)
fig, axes = mpl.subplots(1, 3, figsize=(12, 3.5))
axes = axes.ravel()
mpl.sca(axes[0])
mpl.title("Original")
mpl.axis('scaled')
mpl.contourf(x, y, gz, **args)
mpl.colorbar(pad=0).set_label('mGal')
mpl.m2km()
mpl.sca(axes[1])
mpl.title('True higher')