Esempio n. 1
0
def test_tilt_analytical_derivatives():
    "gravmag.transform tilt returns same values given analytical derivatives"
    model = [Prism(-100, 100, -100, 100, 0, 100, {'density': 1000})]
    shape = (400, 400)
    x, y, z = gridder.regular([-10000, 10000, -10000, 10000], shape, z=-100)
    data = utils.mgal2si(prism.gz(x, y, z, model))
    dx = utils.eotvos2si(prism.gxz(x, y, z, model))
    dy = utils.eotvos2si(prism.gyz(x, y, z, model))
    dz = utils.eotvos2si(prism.gzz(x, y, z, model))
    tilt_analytical = transform.tilt(x, y, data, shape, dx, dy, dz)
    tilt_numerical = transform.tilt(x, y, data, shape)
    npt.assert_allclose(tilt_numerical, tilt_analytical, rtol=0.10)
def setup():
    global model, xp, yp, zp, inc, dec, prismmodel
    inc, dec = -30, 50
    mag = utils.dircos(25, -10)
    props1 = {'density':2., 'magnetization':mag}
    props2 = {'density':3., 'magnetization':1}
    model = [PolygonalPrism([
                 [100, -100],
                 [100, 100],
                 [-100, 100],
                 [-100, -100]], 100, 300, props1),
             PolygonalPrism([
                 [400, -100],
                 [600, -100],
                 [600, 100],
                 [400, 100]], 100, 300, props2)]
    prismmodel = [Prism(-100, 100, -100, 100, 100, 300, props1),
                  Prism(400, 600, -100, 100, 100, 300, props2)]
    tmp = np.linspace(-500, 1000, 50)
    xp, yp = [i.ravel() for i in np.meshgrid(tmp, tmp)]
    zp = -1*np.ones_like(xp)
Esempio n. 3
0
def test_derivatives_uneven_shape():
    "gravmag.transform FFT derivatives work if grid spacing is uneven"
    model = [Prism(-1000, 1000, -500, 500, 0, 2000, {'density': 100})]
    shape = (150, 300)
    x, y, z = gridder.regular([-10000, 10000, -10000, 10000], shape, z=-100)
    grav = utils.mgal2si(prism.gz(x, y, z, model))
    analytical = prism.gzz(x, y, z, model)
    calculated = utils.si2eotvos(
        transform.derivz(x, y, grav, shape, method='fft'))
    diff = _trim(np.abs(analytical - calculated), shape)
    assert np.all(diff <= 0.005*np.abs(analytical).max()), \
        "Failed for gzz"
Esempio n. 4
0
def test_tilt_sane_values():
    "gravmag.transform tilt returns sane values, between -90 and 90 degrees"
    inc, dec = 90, 0
    mag = utils.ang2vec(200, inc, dec)
    model = [Prism(-500, 500, -500, 500, 0, 2000, {'magnetization': mag})]
    shape = (300, 300)
    x, y, z = gridder.regular([-10000, 10000, -10000, 10000], shape, z=-100)
    data = prism.tf(x, y, z, model, inc, dec)
    tilt = np.degrees(transform.tilt(x, y, data, shape))
    assert tilt.max() < 90, \
        "Maximum tilt greater than 90: {}".format(tilt.max())
    assert tilt.min > -90, \
        "Minimum tilt less than -90: {}".format(tilt.min())
Esempio n. 5
0
def test_force_physical_property():
    'gravmag.prism gives correct results when passed a property value as arg'
    inc, dec = 10, 0
    model = [Prism(-6000, -2000, 2000, 4000, 0, 3000,
                   {'density': 1000,
                    'magnetization': utils.ang2vec(10, inc, dec)}),
             Prism(2000, 6000, 2000, 4000, 0, 1000,
                   {'density': -1000,
                    'magnetization': utils.ang2vec(15, inc, dec)})]
    density = -500
    mag = utils.ang2vec(-5, -30, 15)
    reference = [
        Prism(-6000, -2000, 2000, 4000, 0, 3000,
              {'density': density, 'magnetization': mag}),
        Prism(2000, 6000, 2000, 4000, 0, 1000,
              {'density': density, 'magnetization': mag})]
    area = [-10000, 10000, -5000, 5000]
    x, y, z = gridder.regular(area, (51, 101), z=-1)
    for mod in [prism, _prism_numpy]:
        # Test gravity functions
        funcs = ['potential', 'gx', 'gy', 'gz',
                 'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
        for f in funcs:
            forced = getattr(mod, f)(x, y, z, model, dens=density)
            ref = getattr(mod, f)(x, y, z, reference)
            precision = 10
            assert_almost(forced, ref, precision, 'Field = %s' % (f))
        # Test magnetic functions
        funcs = ['tf', 'bx', 'by', 'bz']
        for f in funcs:
            if f == 'tf':
                forced = getattr(mod, f)(x, y, z, model, inc, dec, pmag=mag)
                ref = getattr(mod, f)(x, y, z, reference, inc, dec)
            else:
                forced = getattr(mod, f)(x, y, z, model, pmag=mag)
                ref = getattr(mod, f)(x, y, z, reference)
            precision = 10
            assert_almost(forced, ref, precision, 'Field = %s' % (f))
Esempio n. 6
0
def syn_data(inc, dec,syn_bounds,area,depth=-300,magnetization = 5,cel=200):
    # Build the synthetic Anomaly
    mag = utils.ang2vec(magnetization, inc, dec)
    model = []
    for i in range(len(syn_bounds)):
        model.append(Prism(syn_bounds[i][0], syn_bounds[i][1], syn_bounds[i][2], syn_bounds[i][3], syn_bounds[i][4], syn_bounds[i][5], {'magnetization': mag}))
    
    numcols, numrows = int((area[1] - area[0])/cel), int((area[3] - area[2])/cel)
    x, y, z = gridder.regular(area[:4], (numcols, numrows), z=depth)

    #Calculate the Total Magnetic Field in nT
    mag = prism.tf(x, y, z, model, inc, dec)
    
    return x,y,mag,model
Esempio n. 7
0
def test_cython_agains_numpy():
    "gravmag.prism numpy and cython implementations give same result"
    inc, dec = -30, 50
    model = [
        Prism(100, 300, -100, 100, 0, 400,
              {'density': -1000,
               'magnetization': utils.ang2vec(-2, inc, dec)}),
        Prism(-300, -100, -100, 100, 0, 200,
              {'density': 2000, 'magnetization': utils.ang2vec(5, 25, -10)})]
    tmp = np.linspace(-500, 500, 101)
    xp, yp = [i.ravel() for i in np.meshgrid(tmp, tmp)]
    zp = -1 * np.ones_like(xp)
    kernels = ['xx', 'xy', 'xz', 'yy', 'yz', 'zz']
    for comp in kernels:
        for p in model:
            py = getattr(_prism_numpy, 'kernel' + comp)(xp, yp, zp, p)
            cy = getattr(prism, 'kernel' + comp)(xp, yp, zp, p)
            assert_almost(py, cy, 10,
                          'Kernel = %s, max field %.15g max diff %.15g'
                          % (comp, np.abs(cy).max(), np.abs(py - cy).max()))
    funcs = ['potential', 'gx', 'gy', 'gz',
             'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz',
             'bx', 'by', 'bz', 'tf']
    for f in funcs:
        if f == 'tf':
            py = getattr(_prism_numpy, f)(xp, yp, zp, model, inc, dec)
            cy = getattr(prism, f)(xp, yp, zp, model, inc, dec)
        else:
            py = getattr(_prism_numpy, f)(xp, yp, zp, model)
            cy = getattr(prism, f)(xp, yp, zp, model)
        if f in ['bx', 'by', 'bz', 'tf']:
            precision = 8
        else:
            precision = 10
        assert_almost(py, cy, precision,
                      'Field = %s, max field %.15g max diff %.15g'
                      % (f, np.abs(cy).max(), np.abs(py - cy).max()))
Esempio n. 8
0
def test_horizontal_derivatives_fd():
    "gravmag.transform 1st xy derivatives by finite diff against analytical"
    model = [Prism(-1000, 1000, -500, 500, 0, 2000, {'density': 100})]
    shape = (300, 300)
    x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=-200)
    derivatives = 'x y'.split()
    grav = utils.mgal2si(prism.gz(x, y, z, model))
    for deriv in derivatives:
        analytical = getattr(prism, 'g{}z'.format(deriv))(x, y, z, model)
        func = getattr(transform, 'deriv' + deriv)
        calculated = utils.si2eotvos(func(x, y, grav, shape, method='fd'))
        diff = np.abs(analytical - calculated)
        assert np.all(diff <= 0.005*np.abs(analytical).max()), \
            "Failed for g{}. Max: {} Mean: {} STD: {}".format(
                deriv, diff.max(), diff.mean(), diff.std())
Esempio n. 9
0
def test_laplace_from_potential():
    "gravmag.transform 2nd derivatives of potential obey the Laplace equation"
    model = [Prism(-1000, 1000, -500, 500, 0, 2000, {'density': 200})]
    shape = (300, 300)
    x, y, z = gridder.regular([-10000, 10000, -10000, 10000], shape, z=-100)
    potential = prism.potential(x, y, z, model)
    gxx = utils.si2eotvos(
        transform.derivx(x, y, potential, shape, order=2, method='fft'))
    gyy = utils.si2eotvos(
        transform.derivy(x, y, potential, shape, order=2, method='fft'))
    gzz = utils.si2eotvos(transform.derivz(x, y, potential, shape, order=2))
    laplace = _trim(gxx + gyy + gzz, shape)
    assert np.all(np.abs(laplace) <= 1e-10), \
        "Max: {} Mean: {} STD: {}".format(
            laplace.max(), laplace.mean(), laplace.std())
Esempio n. 10
0
def test_second_horizontal_derivatives_fd():
    "gravmag.transform 2nd xy derivatives by finite diff against analytical"
    model = [Prism(-1000, 1000, -500, 500, 0, 2000, {'density': 100})]
    shape = (300, 300)
    x, y, z = gridder.regular([-10000, 10000, -10000, 10000], shape, z=-500)
    derivatives = 'xx yy'.split()
    grav = prism.potential(x, y, z, model)
    for deriv in derivatives:
        analytical = getattr(prism, 'g{}'.format(deriv))(x, y, z, model)
        func = getattr(transform, 'deriv' + deriv[0])
        calculated = utils.si2eotvos(
            func(x, y, grav, shape, method='fd', order=2))
        diff = np.abs(analytical - calculated)
        assert np.all(diff/np.abs(analytical).max() <= 0.01), \
            "Failed for g{}. Max: {} Mean: {} STD: {}".format(
                deriv, diff.max(), diff.mean(), diff.std())
Esempio n. 11
0
def test_gx_derivatives():
    "gravmag.transform FFT 1st derivatives of gx against analytical solutions"
    model = [Prism(-1000, 1000, -500, 500, 0, 2000, {'density': 100})]
    shape = (300, 300)
    x, y, z = gridder.regular([-10000, 10000, -10000, 10000], shape, z=-100)
    derivatives = 'x y z'.split()
    grav = utils.mgal2si(prism.gx(x, y, z, model))
    for deriv in derivatives:
        analytical = getattr(prism, 'gx{}'.format(deriv))(x, y, z, model)
        calculated = utils.si2eotvos(
            getattr(transform, 'deriv' + deriv)(x,
                                                y,
                                                grav,
                                                shape,
                                                method='fft'))
        diff = _trim(np.abs(analytical - calculated), shape)
        assert np.all(diff <= 0.005*np.abs(analytical).max()), \
            "Failed for gx{}".format(deriv)
Esempio n. 12
0
def test_pole_reduce():
    "gravmag.transform pole reduction matches analytical solution"
    # Use remanent magnetization
    sinc, sdec = -70, 30
    model = [
        Prism(-100, 100, -500, 500, 0, 100, {
            'density': 1000,
            'magnetization': utils.ang2vec(5, sinc, sdec)
        })
    ]
    # Use low latitudes to make sure that there are no problems with FFT
    # instability.
    inc, dec = -60, -15
    shape = (50, 50)
    x, y, z = gridder.regular([-2000, 2000, -2000, 2000], shape, z=-100)
    data = prism.tf(x, y, z, model, inc, dec)
    pole = transform.reduce_to_pole(x, y, data, shape, inc, dec, sinc, sdec)
    pole_true = prism.tf(x, y, z, model, -90, 0, pmag=utils.ang2vec(5, -90, 0))
    npt.assert_allclose(pole, pole_true, atol=10, rtol=0.01)
Esempio n. 13
0
def test_eqlgrav_prism_interp():
    "EQLGravity can interpolate data from a prism"
    model = [Prism(-300, 300, -500, 500, 100, 600, {'density': 400})]
    shape = (30, 30)
    n = shape[0]*shape[1]
    area = [-2000, 2000, -2000, 2000]
    x, y, z = gridder.scatter(area,  n, z=-100, seed=42)
    data = prism.gz(x, y, z, model)
    layer = PointGrid(area, 200, shape)
    eql = EQLGravity(x, y, z, data, layer) + 1e-23*Damping(layer.size)
    eql.fit()
    layer.addprop('density', eql.estimate_)

    assert_allclose(eql[0].predicted(), data, rtol=0.01)

    xp, yp, zp = gridder.regular(area, shape, z=-100)
    true = prism.gz(xp, yp, zp, model)
    calc = sphere.gz(xp, yp, zp, layer)

    assert_allclose(calc, true, rtol=0.05)
Esempio n. 14
0
def test_second_derivatives():
    "gravmag.transform FFT second derivatives against analytical solutions"
    model = [Prism(-1000, 1000, -500, 500, 0, 2000, {'density': -200})]
    shape = (300, 300)
    x, y, z = gridder.regular([-10000, 10000, -10000, 10000], shape, z=-100)
    derivatives = 'xx yy zz'.split()
    pot = prism.potential(x, y, z, model)
    for deriv in derivatives:
        analytical = getattr(prism, 'g{}'.format(deriv))(x, y, z, model)
        calculated = utils.si2eotvos(
            getattr(transform, 'deriv' + deriv[0])(x,
                                                   y,
                                                   pot,
                                                   shape,
                                                   order=2,
                                                   method='fft'))
        diff = _trim(np.abs(analytical - calculated), shape)
        assert np.all(diff <= 0.005*np.abs(analytical).max()), \
            "Failed for g{}. Max: {} Mean: {} STD: {}".format(
                deriv, diff.max(), diff.mean(), diff.std())
Esempio n. 15
0
def euler_deconv(inc, dec,syn_bounds,area,depth=-300,magnetization = 0.5,si=1.0,size = (1000, 1000),windows=(10, 10),proc_data='None'):
    
    # IN PROGRESSING #####
    
    
    mag = utils.ang2vec(magnetization, inc, dec)
    model = []
    for i in range(len(syn_bounds)):
        model.append(Prism(syn_bounds[i][0], syn_bounds[i][1], syn_bounds[i][2], syn_bounds[i][3], syn_bounds[i][4], syn_bounds[i][5], {'magnetization': mag}))
    #model = [Prism(syn_bounds[0]-1000, syn_bounds[1]-1000, syn_bounds[2]-1000, syn_bounds[3]-1000, syn_bounds[4], syn_bounds[5], {'magnetization': mag}),Prism(syn_bounds[0]+1000, syn_bounds[1]+1000, syn_bounds[2]+1000, syn_bounds[3]+1000, syn_bounds[4], syn_bounds[5], {'magnetization': mag})]
    
    
    cel = 200
    numcols, numrows = int((area[1] - area[0])/cel), int((area[3] - area[2])/cel)
    x, y, z = gridder.regular(area[:4], (numcols, numrows), z=depth)
    
    
    mag = prism.tf(x, y, z, model, inc, dec)
    #derivatives
    deriv_x = transform.derivx(x, y, mag, (numcols, numrows))
    deriv_y = transform.derivy(x, y, mag, (numcols, numrows))
    deriv_z = transform.derivz(x, y, mag, (numcols, numrows))
    #label = 'Total Magnetic Intensity (nT)'
    
    solver = euler.EulerDeconvMW(x, y, z, mag, deriv_x, deriv_y, deriv_z,
                             structural_index=si, windows=windows,
                             size=size)
    
    
    solver_expand = euler.EulerDeconvEW(x, y, z, mag, deriv_x, deriv_y, deriv_z,
                             structural_index=si, center = (-1250,0),sizes=np.linspace(300, 7000, 20))
    
    solver.fit()
    solver_expand.fit()
    #print('Kept Euler solutions after the moving window scheme:')
    #print(solver_expand.estimate_)
    return solver,solver_expand
Esempio n. 16
0
def test_pelgrav_prism_interp():
    "PELGravity can interpolate data from a prism"
    model = [Prism(-300, 300, -500, 500, 100, 600, {'density': 400})]
    shape = (40, 40)
    n = shape[0]*shape[1]
    area = [-2000, 2000, -2000, 2000]
    x, y, z = gridder.scatter(area,  n, z=-100, seed=42)
    data = prism.gz(x, y, z, model)

    layer = PointGrid(area, 100, shape)
    windows = (20, 20)
    degree = 1
    eql = (PELGravity(x, y, z, data, layer, windows, degree)
           + 5e-22*PELSmoothness(layer, windows, degree))
    eql.fit()
    layer.addprop('density', eql.estimate_)

    assert_allclose(eql[0].predicted(), data, rtol=0.01)

    xp, yp, zp = gridder.regular(area, shape, z=-100)
    true = prism.gz(xp, yp, zp, model)
    calc = sphere.gz(xp, yp, zp, layer)

    assert_allclose(calc, true, atol=0.001, rtol=0.05)
Esempio n. 17
0
"""
Vis: Exaggerate the vertical dimension of 3D plots
"""
from fatiando.mesher import Prism, PolygonalPrism
from fatiando.vis import myv

prism = Prism(0, 1000, 0, 1000, 0, 10)
poly = PolygonalPrism([[-2000, -2000], [-1000, -1000], [-2000, -1000]], 0, 10)
bounds = (-3000, 3000, -3000, 3000, 0, 20)
myv.figure()
myv.prisms([prism])
myv.polyprisms([poly])
myv.axes(myv.outline(bounds))
myv.wall_north(bounds)
myv.wall_bottom(bounds)
myv.title('No exaggeration')
scale = (1, 1, 50)  # Exaggerate 50x the z axis
myv.figure()
myv.prisms([prism], scale=scale)
myv.polyprisms([poly], scale=scale)
myv.axes(myv.outline(bounds, scale=scale), ranges=bounds)
myv.wall_north(bounds, scale=scale)
myv.wall_bottom(bounds, scale=scale)
myv.title('50x exaggeration')
myv.show()
Esempio n. 18
0
"""
Vis: Set the colors in figures, prisms, polygonal prisms and tesseroids.
"""
from fatiando.mesher import Prism, PolygonalPrism, Tesseroid
from fatiando.vis import myv

prism = Prism(1, 2, 1, 2, 0, 1, {'density': 1})
polyprism = PolygonalPrism([[3, 1], [4, 2], [5, 1]], -1, 2, {'density': 2})
tesseroid = Tesseroid(10, 20, 50, 60, 10**6, 0)

red, green, blue = (1, 0, 0), (0, 1, 0), (0, 0, 1)
white, black = (1, 1, 1), (0, 0, 0),

myv.figure()
# Make the prism red with blue edges, despite its density
myv.prisms([prism], 'density', color=red, edgecolor=blue)
# and the polyprism green with blue edges
myv.title('Body + edge colors')

myv.figure()
# For wireframes, color is usually set by the density.
# Overwrite this by setting *color*
# *edgecolor* is ignored
myv.polyprisms([polyprism],
               'density',
               style='wireframe',
               color=green,
               edgecolor=red,
               linewidth=2)
myv.title('Wireframe colors')
Esempio n. 19
0
GravMag: Classic 3D Euler deconvolution of magnetic data using an
expanding window
"""
import numpy as np
from fatiando.mesher import Prism
from fatiando import gridder, utils
from fatiando.gravmag import prism, transform
from fatiando.gravmag.euler import Classic, ExpandingWindow
from fatiando.vis import mpl, myv

# The regional field
inc, dec = -45, 0
# Make a model
bounds = [-5000, 5000, -5000, 5000, 0, 5000]
model = [
    Prism(-1500, -500, -1500, -500, 1000, 2000, {'magnetization': 2}),
    Prism(500, 1500, 1000, 2000, 1000, 2000, {'magnetization': 2})
]
# Generate some data from the model
shape = (100, 100)
area = bounds[0:4]
xp, yp, zp = gridder.regular(area, shape, z=-1)
# Add a constant baselevel
baselevel = 10
# Convert from nanoTesla to Tesla because euler and derivatives require things
# in SI
tf = (utils.nt2si(prism.tf(xp, yp, zp, model, inc, dec)) + baselevel)
# Calculate the derivatives using FFT
xderiv = transform.derivx(xp, yp, tf, shape)
yderiv = transform.derivy(xp, yp, tf, shape)
zderiv = transform.derivz(xp, yp, tf, shape)
Esempio n. 20
0
def test_around():
    "gravmag.prism gravitational results are consistent around the prism"
    funcs = ['potential', 'gx', 'gy', 'gz',
             'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
    model = [Prism(-300, 300, -300, 300, -300, 300, {'density': 1000})]
    # Make the computation points surround the prism
    shape = (101, 101)
    area = [-600, 600, -600, 600]
    distance = 310
    grids = [gridder.regular(area, shape, z=-distance),
             gridder.regular(area, shape, z=distance),
             gridder.regular(area, shape, z=distance)[::-1],
             gridder.regular(area, shape, z=-distance)[::-1],
             np.array(gridder.regular(area, shape, z=distance))[[0, 2, 1]],
             np.array(gridder.regular(area, shape, z=-distance))[[0, 2, 1]]]
    xp, yp, zp = grids[0]
    # Test if each component is consistent
    # POTENTIAL
    face = [prism.potential(x, y, z, model) for x, y, z in grids]
    for i in range(6):
        for j in range(i + 1, 6):
            assert_almost(face[i], face[j], 10,
                          'Failed potential, faces %d and %d' % (i, j))
    # GX
    top, bottom, north, south, east, west = [prism.gx(x, y, z, model)
                                             for x, y, z in grids]
    assert_almost(top, bottom, 10, 'Failed gx, top and bottom')
    assert_almost(north, -south, 10, 'Failed gx, north and south')
    assert_almost(east, west, 10, 'Failed gx, east and west')
    assert_almost(east, top, 10, 'Failed gx, east and top')
    assert_almost(north, -prism.gz(xp, yp, zp, model), 10,
                  'Failed gx, north and gz')
    assert_almost(south, prism.gz(xp, yp, zp, model), 10,
                  'Failed gx, south and gz')
    # GY
    top, bottom, north, south, east, west = [prism.gy(x, y, z, model)
                                             for x, y, z in grids]
    assert_almost(top, bottom, 10, 'Failed gy, top and bottom')
    assert_almost(north, south, 10, 'Failed gy, north and south')
    assert_almost(east, -west, 10, 'Failed gy, east and west')
    assert_almost(north, top, 10, 'Failed gy, north and top')
    assert_almost(east, -prism.gz(xp, yp, zp, model), 10,
                  'Failed gy, east and gz')
    assert_almost(west, prism.gz(xp, yp, zp, model), 10,
                  'Failed gy, west and gz')
    # GZ
    top, bottom, north, south, east, west = [prism.gz(x, y, z, model)
                                             for x, y, z in grids]
    assert_almost(top, -bottom, 10, 'Failed gz, top and bottom')
    assert_almost(north, south, 10, 'Failed gz, north and south')
    assert_almost(east, west, 10, 'Failed gz, east and west')
    assert_almost(north, prism.gx(xp, yp, zp, model), 10,
                  'Failed gz, north and gx')
    assert_almost(south, prism.gx(xp, yp, zp, model), 10,
                  'Failed gz, south and gx')
    assert_almost(east, prism.gy(xp, yp, zp, model), 10,
                  'Failed gz, east and gy')
    assert_almost(west, prism.gy(xp, yp, zp, model), 10,
                  'Failed gz, west and gy')
    # GXX
    top, bottom, north, south, east, west = [prism.gxx(x, y, z, model)
                                             for x, y, z in grids]
    assert_almost(top, bottom, 10, 'Failed gxx, top and bottom')
    assert_almost(north, south, 10, 'Failed gxx, north and south')
    assert_almost(east, west, 10, 'Failed gxx, east and west')
    assert_almost(east, top, 10, 'Failed gxx, east and top')
    assert_almost(north, prism.gzz(xp, yp, zp, model), 10,
                  'Failed gxx, north and gzz')
    assert_almost(south, prism.gzz(xp, yp, zp, model), 10,
                  'Failed gxx, south and gzz')
    # GXY
    top, bottom, north, south, east, west = [prism.gxy(x, y, z, model)
                                             for x, y, z in grids]
    assert_almost(top, bottom, 4, 'Failed gxy, top and bottom')
    assert_almost(north, -south, 10, 'Failed gxy, north and south')
    assert_almost(east, -west, 10, 'Failed gxy, east and west')
    assert_almost(north, -prism.gyz(xp, yp, zp, model), 10,
                  'Failed gxy, north and gyz')
    assert_almost(south, prism.gyz(xp, yp, zp, model), 10,
                  'Failed gxy, south and gyz')
    # GXZ
    top, bottom, north, south, east, west = [prism.gxz(x, y, z, model)
                                             for x, y, z in grids]
    assert_almost(top, -bottom, 10, 'Failed gxz, top and bottom')
    assert_almost(north, -south, 10, 'Failed gxz, north and south')
    assert_almost(east, west, 4, 'Failed gxz, east and west')
    assert_almost(bottom, north, 10, 'Failed gxz, bottom and north')
    assert_almost(top, south, 10, 'Failed gxz, top and south')
    assert_almost(east, prism.gxy(xp, yp, zp, model), 4,
                  'Failed gxz, east and gxy')
    assert_almost(west, prism.gxy(xp, yp, zp, model), 10,
                  'Failed gxz, west and gxy')
    # GYY
    top, bottom, north, south, east, west = [prism.gyy(x, y, z, model)
                                             for x, y, z in grids]
    assert_almost(top, bottom, 10, 'Failed gyy, top and bottom')
    assert_almost(north, south, 10, 'Failed gyy, north and south')
    assert_almost(east, west, 10, 'Failed gyy, east and west')
    assert_almost(top, north, 10, 'Failed gyy, top and north')
    assert_almost(east, prism.gzz(xp, yp, zp, model), 10,
                  'Failed gyy, east and gzz')
    assert_almost(west, prism.gzz(xp, yp, zp, model), 10,
                  'Failed gyy, west and gzz')
    # GYZ
    top, bottom, north, south, east, west = [prism.gyz(x, y, z, model)
                                             for x, y, z in grids]
    assert_almost(top, -bottom, 10, 'Failed gyz, top and bottom')
    assert_almost(north, south, 4, 'Failed gyz, north and south')
    assert_almost(east, -west, 10, 'Failed gyz, east and west')
    assert_almost(top, west, 10, 'Failed gyz, top and west')
    assert_almost(bottom, east, 10, 'Failed gyz, bottom and east')
    assert_almost(north, prism.gxy(xp, yp, zp, model), 4,
                  'Failed gyz, north and gxy')
    assert_almost(south, prism.gxy(xp, yp, zp, model), 10,
                  'Failed gyz, south and gxy')
    # GZZ
    top, bottom, north, south, east, west = [prism.gzz(x, y, z, model)
                                             for x, y, z in grids]
    assert_almost(top, bottom, 10, 'Failed gzz, top and bottom')
    assert_almost(north, south, 10, 'Failed gzz, north and south')
    assert_almost(east, west, 10, 'Failed gzz, east and west')
    assert_almost(north, prism.gxx(xp, yp, zp, model), 10,
                  'Failed gzz, north and gxx')
    assert_almost(south, prism.gxx(xp, yp, zp, model), 10,
                  'Failed gzz, south and gxx')
    assert_almost(east, prism.gyy(xp, yp, zp, model), 10,
                  'Failed gzz, east and gyy')
    assert_almost(west, prism.gyy(xp, yp, zp, model), 10,
                  'Failed gzz, west and gyy')
Esempio n. 21
0
def test_fails_if_shape_mismatch():
    'gravmag.prism fails if given computation points with different shapes'
    inc, dec = 10, 0
    model = [Prism(-6000, -2000, 2000, 4000, 0, 3000,
                   {'density': 1000,
                    'magnetization': utils.ang2vec(10, inc, dec)})]
    area = [-5000, 5000, -10000, 10000]
    x, y, z = gridder.regular(area, (101, 51), z=-1)

    raises(ValueError, prism.potential, x[:-2], y, z, model)
    raises(ValueError, prism.potential, x, y[:-2], z, model)
    raises(ValueError, prism.potential, x, y, z[:-2], model)
    raises(ValueError, prism.potential, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.gx, x[:-2], y, z, model)
    raises(ValueError, prism.gx, x, y[:-2], z, model)
    raises(ValueError, prism.gx, x, y, z[:-2], model)
    raises(ValueError, prism.gx, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.gy, x[:-2], y, z, model)
    raises(ValueError, prism.gy, x, y[:-2], z, model)
    raises(ValueError, prism.gy, x, y, z[:-2], model)
    raises(ValueError, prism.gy, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.gz, x[:-2], y, z, model)
    raises(ValueError, prism.gz, x, y[:-2], z, model)
    raises(ValueError, prism.gz, x, y, z[:-2], model)
    raises(ValueError, prism.gz, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.gxx, x[:-2], y, z, model)
    raises(ValueError, prism.gxx, x, y[:-2], z, model)
    raises(ValueError, prism.gxx, x, y, z[:-2], model)
    raises(ValueError, prism.gxx, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.gxy, x[:-2], y, z, model)
    raises(ValueError, prism.gxy, x, y[:-2], z, model)
    raises(ValueError, prism.gxy, x, y, z[:-2], model)
    raises(ValueError, prism.gxy, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.gxz, x[:-2], y, z, model)
    raises(ValueError, prism.gxz, x, y[:-2], z, model)
    raises(ValueError, prism.gxz, x, y, z[:-2], model)
    raises(ValueError, prism.gxz, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.gyy, x[:-2], y, z, model)
    raises(ValueError, prism.gyy, x, y[:-2], z, model)
    raises(ValueError, prism.gyy, x, y, z[:-2], model)
    raises(ValueError, prism.gyy, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.gyz, x[:-2], y, z, model)
    raises(ValueError, prism.gyz, x, y[:-2], z, model)
    raises(ValueError, prism.gyz, x, y, z[:-2], model)
    raises(ValueError, prism.gyz, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.gzz, x[:-2], y, z, model)
    raises(ValueError, prism.gzz, x, y[:-2], z, model)
    raises(ValueError, prism.gzz, x, y, z[:-2], model)
    raises(ValueError, prism.gzz, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.bx, x[:-2], y, z, model)
    raises(ValueError, prism.bx, x, y[:-2], z, model)
    raises(ValueError, prism.bx, x, y, z[:-2], model)
    raises(ValueError, prism.bx, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.by, x[:-2], y, z, model)
    raises(ValueError, prism.by, x, y[:-2], z, model)
    raises(ValueError, prism.by, x, y, z[:-2], model)
    raises(ValueError, prism.by, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.bz, x[:-2], y, z, model)
    raises(ValueError, prism.bz, x, y[:-2], z, model)
    raises(ValueError, prism.bz, x, y, z[:-2], model)
    raises(ValueError, prism.bz, x[:-5], y, z[:-2], model)

    raises(ValueError, prism.tf, x[:-2], y, z, model, inc, dec)
    raises(ValueError, prism.tf, x, y[:-2], z, model, inc, dec)
    raises(ValueError, prism.tf, x, y, z[:-2], model, inc, dec)
    raises(ValueError, prism.tf, x[:-5], y, z[:-2], model, inc, dec)

    raises(ValueError, prism.kernelxx, x[:-2], y, z, model[0])
    raises(ValueError, prism.kernelxx, x, y[:-2], z, model[0])
    raises(ValueError, prism.kernelxx, x, y, z[:-2], model[0])
    raises(ValueError, prism.kernelxx, x[:-5], y, z[:-2], model[0])

    raises(ValueError, prism.kernelxy, x[:-2], y, z, model[0])
    raises(ValueError, prism.kernelxy, x, y[:-2], z, model[0])
    raises(ValueError, prism.kernelxy, x, y, z[:-2], model[0])
    raises(ValueError, prism.kernelxy, x[:-5], y, z[:-2], model[0])

    raises(ValueError, prism.kernelxz, x[:-2], y, z, model[0])
    raises(ValueError, prism.kernelxz, x, y[:-2], z, model[0])
    raises(ValueError, prism.kernelxz, x, y, z[:-2], model[0])
    raises(ValueError, prism.kernelxz, x[:-5], y, z[:-2], model[0])

    raises(ValueError, prism.kernelyy, x[:-2], y, z, model[0])
    raises(ValueError, prism.kernelyy, x, y[:-2], z, model[0])
    raises(ValueError, prism.kernelyy, x, y, z[:-2], model[0])
    raises(ValueError, prism.kernelyy, x[:-5], y, z[:-2], model[0])

    raises(ValueError, prism.kernelyz, x[:-2], y, z, model[0])
    raises(ValueError, prism.kernelyz, x, y[:-2], z, model[0])
    raises(ValueError, prism.kernelyz, x, y, z[:-2], model[0])
    raises(ValueError, prism.kernelyz, x[:-5], y, z[:-2], model[0])

    raises(ValueError, prism.kernelzz, x[:-2], y, z, model[0])
    raises(ValueError, prism.kernelzz, x, y[:-2], z, model[0])
    raises(ValueError, prism.kernelzz, x, y, z[:-2], model[0])
    raises(ValueError, prism.kernelzz, x[:-5], y, z[:-2], model[0])
Esempio n. 22
0
"""
GravMag: Classic 3D Euler deconvolution of magnetic data (single window)
"""
from fatiando.mesher import Prism
from fatiando import gridder, utils
from fatiando.gravmag import prism, transform
from fatiando.gravmag.euler import Classic
from fatiando.vis import mpl, myv

# The regional field
inc, dec = -45, 0
# Make a model
bounds = [-5000, 5000, -5000, 5000, 0, 5000]
model = [Prism(-1500, -500, -500, 500, 1000, 2000, {'magnetization': 2})]
# Generate some data from the model
shape = (200, 200)
area = bounds[0:4]
xp, yp, zp = gridder.regular(area, shape, z=-1)
# Add a constant baselevel
baselevel = 10
# Convert from nanoTesla to Tesla because euler and derivatives require things
# in SI
tf = (utils.nt2si(prism.tf(xp, yp, zp, model, inc, dec)) + baselevel)
# Calculate the derivatives using FFT
xderiv = transform.derivx(xp, yp, tf, shape)
yderiv = transform.derivy(xp, yp, tf, shape)
zderiv = transform.derivz(xp, yp, tf, shape)

mpl.figure()
titles = ['Total field', 'x derivative', 'y derivative', 'z derivative']
for i, f in enumerate([tf, xderiv, yderiv, zderiv]):
Esempio n. 23
0
"""
GravMag: 3D gravity gradient inversion by planting anomalous densities using
``harvester`` (with non-targeted sources)
"""
from fatiando import gridder, utils
from fatiando.gravmag import prism, harvester
from fatiando.mesher import Prism, PrismMesh, vremove
from fatiando.vis import mpl, myv

# Generate a synthetic model
bounds = [0, 5000, 0, 5000, 0, 1500]
model = [Prism(500, 4500, 3000, 3500, 200, 700, {'density': 1200}),
         Prism(3000, 4500, 1800, 2300, 200, 700, {'density': 1200}),
         Prism(500, 1500, 500, 1500, 0, 800, {'density': 600}),
         Prism(0, 800, 1800, 2300, 0, 200, {'density': 600}),
         Prism(4000, 4800, 100, 900, 0, 300, {'density': 600}),
         Prism(0, 2000, 4500, 5000, 0, 200, {'density': 600}),
         Prism(3000, 4200, 2500, 2800, 200, 700, {'density': -1000}),
         Prism(300, 2500, 1800, 2700, 500, 1000, {'density': -1000}),
         Prism(4000, 4500, 500, 1500, 400, 1000, {'density': -1000}),
         Prism(1800, 3700, 500, 1500, 300, 1300, {'density': -1000}),
         Prism(500, 4500, 4000, 4500, 400, 1300, {'density': -1000})]
# show it
myv.figure()
myv.prisms(model, 'density')
myv.axes(myv.outline(bounds), ranges=[i * 0.001 for i in bounds],
         fmt='%.1f', nlabels=6)
myv.wall_bottom(bounds)
myv.wall_north(bounds)
myv.show()
# and use it to generate some tensor data
Esempio n. 24
0
"""
GravMag: 3D gravity inversion by planting anomalous densities using
``harvester`` (simple example)
"""
from fatiando import gridder, utils
from fatiando import gravmag as gm
from fatiando.mesher import Prism, PrismMesh, vremove
from fatiando.vis import mpl, myv

# Create a synthetic model
model = [Prism(250, 750, 250, 750, 200, 700, {'density': 1000})]
# and generate synthetic data from it
shape = (25, 25)
bounds = [0, 1000, 0, 1000, 0, 1000]
area = bounds[0:4]
xp, yp, zp = gridder.regular(area, shape, z=-1)
noise = 0.1  # 0.1 mGal noise
gz = utils.contaminate(gm.prism.gz(xp, yp, zp, model), noise)
# plot the data
mpl.figure()
mpl.title("Synthetic gravity anomaly (mGal)")
mpl.axis('scaled')
levels = mpl.contourf(yp, xp, gz, shape, 12)
mpl.colorbar()
mpl.xlabel('Horizontal coordinate y (km)')
mpl.ylabel('Horizontal coordinate x (km)')
mpl.m2km()
mpl.show()

# Inversion setup
# Create a mesh
"""
GravMag: 3D gravity gradient inversion by planting anomalous densities using
``harvester`` (dipping example)
"""
from fatiando import gridder, utils
from fatiando import gravmag as gm
from fatiando.mesher import Prism, PrismMesh, vremove
from fatiando.vis import mpl, myv

# Create a synthetic model
props = {'density': 1000}
model = [
    Prism(400, 600, 300, 500, 200, 400, props),
    Prism(400, 600, 400, 600, 400, 600, props),
    Prism(400, 600, 500, 700, 600, 800, props)
]
# and generate synthetic data from it
shape = (51, 51)
bounds = [0, 1000, 0, 1000, 0, 1000]
area = bounds[0:4]
xp, yp, zp = gridder.regular(area, shape, z=-150)
noise = 0.5
gxx = utils.contaminate(gm.prism.gxx(xp, yp, zp, model), noise)
gxy = utils.contaminate(gm.prism.gxy(xp, yp, zp, model), noise)
gxz = utils.contaminate(gm.prism.gxz(xp, yp, zp, model), noise)
gyy = utils.contaminate(gm.prism.gyy(xp, yp, zp, model), noise)
gyz = utils.contaminate(gm.prism.gyz(xp, yp, zp, model), noise)
gzz = utils.contaminate(gm.prism.gzz(xp, yp, zp, model), noise)
tensor = [gxx, gxy, gxz, gyy, gyz, gzz]
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
# plot the data
Esempio n. 26
0
Exaggerate a dimension in 3D plots
----------------------------------

Sometimes things are too small on one dimension to plot properly. On the Earth,
this is usually the vertical dimension. The functions in
:mod:`fatiando.vis.myv` have a ``scale`` attribute to control how much
exaggeration should  be placed in each dimension of your plot.

"""
import copy
from fatiando.vis import myv
from fatiando.mesher import Prism


# Make two objects that are very thin.
model = [Prism(0, 1000, 0, 1000, 0, 10, props={'density': 300}),
         Prism(-2500, -1000, -2000, -500, 0, 5, props={'density': -300})]

bounds = [-3000, 3000, -3000, 3000, 0, 20]

# The scale argument is by how much each dimension (being x, y, and z) will be
# multiplied. This means 300x in the z dimension.
scale = (1, 1, 300)

# Pass "scale" along to all plot functions
myv.figure()
myv.prisms(model, prop='density', scale=scale)
myv.axes(myv.outline(bounds, scale=scale), ranges=bounds)
myv.wall_north(bounds, scale=scale)
myv.wall_bottom(bounds, scale=scale)
# Note: the tittle can't be the first thing on the plot.
Esempio n. 27
0
:func:`fatiando.gravmag.transform.reduce_to_pole` to reduce your data.

The zero contour of the tilt is said to outline the body so we've plotted it as
a dashed line on the tilt map.
"""
from __future__ import division, print_function
import matplotlib.pyplot as plt
from fatiando.gravmag import prism, transform
from fatiando.mesher import Prism
from fatiando import gridder, utils

# Create some synthetic magnetic data. We'll assume the data is already reduced
# to the pole.
inc, dec = 90, 0
mag = utils.ang2vec(1, inc, dec)
model = [Prism(-1500, 1500, -500, 500, 0, 2000, {'magnetization': mag})]
area = (-7e3, 7e3, -7e3, 7e3)
shape = (100, 100)
x, y, z = gridder.regular(area, shape, z=-300)
data_at_pole = prism.tf(x, y, z, model, inc, dec)

# Calculate the tilt
tilt = transform.tilt(x, y, data_at_pole, shape)

# Make some plots
plt.figure(figsize=(8, 6))

ax = plt.subplot(1, 2, 1)
ax.set_title('Original data at the pole')
ax.set_aspect('equal')
tmp = ax.tricontourf(y / 1000, x / 1000, data_at_pole, 30, cmap='RdBu_r')
"""
GravMag: Classic 3D Euler deconvolution of magnetic data using a
moving window
"""
from fatiando.mesher import Prism
from fatiando import gridder, utils
from fatiando.gravmag import prism, transform
from fatiando.gravmag.euler import Classic, MovingWindow
from fatiando.vis import mpl, myv

# Make a model
bounds = [-5000, 5000, -5000, 5000, 0, 5000]
model = [
    Prism(-1500, -500, -1500, -500, 500, 1500, {'density': 1000}),
    Prism(500, 1500, 1000, 2000, 500, 1500, {'density': 1000})
]
# Generate some data from the model
shape = (100, 100)
area = bounds[0:4]
xp, yp, zp = gridder.regular(area, shape, z=-1)
# Add a constant baselevel
baselevel = 10
# Convert the data from mGal to SI because Euler and FFT derivation require
# data in SI
gz = utils.mgal2si(prism.gz(xp, yp, zp, model)) + baselevel
xderiv = transform.derivx(xp, yp, gz, shape)
yderiv = transform.derivy(xp, yp, gz, shape)
zderiv = transform.derivz(xp, yp, gz, shape)

mpl.figure()
titles = ['Gravity anomaly', 'x derivative', 'y derivative', 'z derivative']
Esempio n. 29
0
 def __init__(self, i, location, prism, props):
     Prism.__init__(self, prism.x1, prism.x2, prism.y1, prism.y2, prism.z1,
         prism.z2, props=props)
     self.i = i
     self.seed = i
     self.x, self.y, self.z = location
Esempio n. 30
0
"""
GravMag: Iterate through a 3D gravity inversion by planting anomalous densities
"""
from fatiando import gridder, gravmag
from fatiando.mesher import Prism, PrismMesh
from fatiando.vis import myv

model = [Prism(200, 800, 400, 600, 200, 400, {'density': 1000})]
shape = (20, 20)
bounds = [0, 1000, 0, 1000, 0, 1000]
area = bounds[0:4]
x, y, z = gridder.regular(area, shape, z=-1)
gz = gravmag.prism.gz(x, y, z, model)
mesh = PrismMesh(bounds, (10, 10, 10))
data = [gravmag.harvester.Gz(x, y, z, gz)]
seeds = gravmag.harvester.sow([[500, 500, 250, {'density': 1000}]], mesh)

fig = myv.figure(size=(700, 700))
plot = myv.prisms(model, style='wireframe', linewidth=4)
plot.actor.mapper.scalar_visibility = False
myv.prisms(seeds, 'density')
myv.outline(bounds)
myv.wall_bottom(bounds)
myv.wall_east(bounds)
for update in gravmag.harvester.iharvest(data,
                                         seeds,
                                         mesh,
                                         compactness=0.5,
                                         threshold=0.001):
    best, neighborhood = update[2:4]
    if best is not None: