def sensitivity_mag(x, y, z, xs, ys, zs, sinc, sdec, inc, dec):
    '''
    Calculate the sensitivity matrix

    input

    return
    '''
    N = x.size  # number of data
    M = xs.size  # number of parameters

    #pM = p[:M] # magnetic moment of eqsources
    #inc,dec = p[M],p[M+1] # magnetization direction of eqsources

    A = np.empty((N, M))  # sensitivity matrix

    F0x, F0y, F0z = ang2vec(1., sinc, sdec)  # main field
    mx, my, mz = ang2vec(
        1., inc, dec)  # magnetization direction in Cartesian coordinates

    for i in range(N):
        phi_xx = kernelxx(x[i], y[i], z[i], xs, ys, zs)
        phi_yy = kernelyy(x[i], y[i], z[i], xs, ys, zs)
        phi_xy = kernelxy(x[i], y[i], z[i], xs, ys, zs)
        phi_xz = kernelxz(x[i], y[i], z[i], xs, ys, zs)
        phi_yz = kernelyz(x[i], y[i], z[i], xs, ys, zs)
        phi_zz = -phi_xx - phi_yy
        gi = (F0x*mx - F0z*mz)*phi_xx + (F0y*my - F0z*mz)*phi_yy + (F0x*my + F0y*mx)*phi_xy +\
             (F0x*mz + F0z*mx)*phi_xz + (F0y*mz + F0z*my)*phi_yz
        A[i, :] = gi

    A *= CM * T2NT
    return A
Exemple #2
0
def test_ignore_none_and_missing_properties():
    'gravmag.prism ignores None and prisms without the required property'
    inc, dec = 50, -30
    model = [None,
             Prism(-6000, -2000, 2000, 4000, 0, 3000,
                   {'density': 1000,
                    'magnetization': utils.ang2vec(10, inc, dec)}),
             Prism(2000, 6000, 2000, 4000, 0, 1000,
                   {'magnetization': utils.ang2vec(15, inc, dec)}),
             None,
             Prism(-6000, -2000, -4000, -2000, 500, 2000,
                   {'density': -1000})]
    area = [-10000, 10000, -5000, 5000]
    x, y, z = gridder.regular(area, (101, 51), 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:
            combined = getattr(mod, f)(x, y, z, model)
            separate = getattr(mod, f)(x, y, z, [model[1], model[4]])
            precision = 10
            assert_almost(separate, combined, precision, 'Field = %s' % (f))
        # Test magnetic functions
        funcs = ['tf', 'bx', 'by', 'bz']
        for f in funcs:
            mag_only = [model[1], model[2]]
            if f == 'tf':
                combined = getattr(mod, f)(x, y, z, model, inc, dec)
                separate = getattr(mod, f)(x, y, z, mag_only, inc, dec)
            else:
                combined = getattr(mod, f)(x, y, z, model)
                separate = getattr(mod, f)(x, y, z, mag_only)
            precision = 10
            assert_almost(separate, combined, precision, 'Field = %s' % (f))
Exemple #3
0
def test_pel_polereduce():
    "PELTotalField can reduce data to the pole"
    # Use remanent magnetization
    sinc, sdec = -70, 30
    model = [Prism(-100, 100, -500, 500, 0, 100,
                   {'magnetization': utils.ang2vec(5, sinc, sdec)})]
    inc, dec = -60, -15
    shape = (40, 40)
    area = [-2000, 2000, -2000, 2000]
    x, y, z = gridder.regular(area, shape, z=-100)
    data = prism.tf(x, y, z, model, inc, dec)
    true = prism.tf(x, y, z, model, -90, 0, pmag=utils.ang2vec(5, -90, 0))

    layer = PointGrid(area, 100, shape)
    windows = (20, 20)
    degree = 3
    pel = PELTotalField(x, y, z, data, inc, dec, layer, windows, degree,
                        sinc, sdec)
    eql = pel + 1e-25*PELSmoothness(layer, windows, degree)
    eql.fit()

    assert_array_almost_equal(eql[0].predicted(), data, decimal=1)

    layer.addprop('magnetization',
                  utils.ang2vec(eql.estimate_, inc=-90, dec=0))
    calc = sphere.tf(x, y, z, layer, inc=-90, dec=0)

    assert_allclose(calc, true, atol=10, rtol=0.05)
Exemple #4
0
def test_eqlayer_polereduce():
    "EQLTotalField can reduce data to the pole"
    # Use remanent magnetization
    sinc, sdec = -70, 30
    model = [Prism(-100, 100, -500, 500, 0, 100,
                   {'magnetization': utils.ang2vec(5, sinc, sdec)})]
    inc, dec = -60, -15
    shape = (50, 50)
    area = [-2000, 2000, -2000, 2000]
    x, y, z = gridder.regular(area, shape, z=-100)
    data = prism.tf(x, y, z, model, inc, dec)
    true = prism.tf(x, y, z, model, -90, 0, pmag=utils.ang2vec(5, -90, 0))

    layer = PointGrid(area, 200, shape)
    eql = (EQLTotalField(x, y, z, data, inc, dec, layer, sinc, sdec)
           + 1e-24*Damping(layer.size))
    eql.fit()

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

    layer.addprop('magnetization',
                  utils.ang2vec(eql.estimate_, inc=-90, dec=0))
    calc = sphere.tf(x, y, z, layer, inc=-90, dec=0)

    assert_allclose(calc, true, atol=10, rtol=0.05)
Exemple #5
0
def setup():
    global model, xp, yp, zp, inc, dec
    inc, dec = -30, 50
    reg_field = np.array(utils.dircos(inc, dec))
    model = [
        Sphere(500, 0, 1000, 1000,
               {'density': -1., 'magnetization': utils.ang2vec(-2, inc, dec)}),
        Sphere(-1000, 0, 700, 700,
               {'density': 2., 'magnetization': utils.ang2vec(5, 25, -10)})]
    xp, yp, zp = gridder.regular([-2000, 2000, -2000, 2000], (50, 50), z=-1)
def setup():
    global model, xp, yp, zp, inc, dec
    inc, dec = -30, 50
    reg_field = np.array(utils.dircos(inc, dec))
    model = [
        Sphere(500, 0, 1000, 1000,
               {'density': -1., 'magnetization': utils.ang2vec(-2, inc, dec)}),
        Sphere(-1000, 0, 700, 700,
               {'density': 2., 'magnetization': utils.ang2vec(5, 25, -10)})]
    xp, yp, zp = gridder.regular([-2000, 2000, -2000, 2000], (50, 50), z=-1)
def setup():
    global model, xp, yp, zp, inc, dec
    inc, dec = -30, 50
    reg_field = np.array(utils.dircos(inc, dec))
    model = [
        Prism(100, 300, -100, 100, 0, 400,
              {'density':-1., 'magnetization':utils.ang2vec(-2, inc, dec)}),
        Prism(-300, -100, -100, 100, 0, 200,
            {'density':2., 'magnetization':utils.ang2vec(5, 25, -10)})]
    tmp = np.linspace(-500, 500, 50)
    xp, yp = [i.ravel() for i in np.meshgrid(tmp, tmp)]
    zp = -1*np.ones_like(xp)
Exemple #8
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)
def test_totalfield_prism():
    '''
    This test compare the results obtained by both function that calculates the total field anomaly due to a rectangular prism. The model has the same dimensions, magnetization intensity and also the same pair for inclination and declination. We use the function from Fatiando a Terra in order to compare with our function.
    '''

    incf = 30.
    decf = 30.
    incs = 60.
    decs = 45.
    magnetization = 3.

    # Modelo para o Fatiando
    xp, yp, zp = gridder.regular((-1000, 1000, -1000, 1000), (200, 200),
                                 z=-345.)
    model = [
        mesher.Prism(
            -200., 200., -250., 180., 120., 1000.,
            {'magnetization': utils.ang2vec(magnetization, incs, decs)})
    ]
    tf = prism.tf(xp, yp, zp, model, incf, decf)
    tf = tf.reshape(200, 200)

    # Modelo para minha funcao
    x, y = numpy.meshgrid(numpy.linspace(-1000., 1000., 200),
                          numpy.linspace(-1000., 1000., 200))
    z = -345. * numpy.ones((200, 200))
    mymodel = [-200., 200., -250., 180., 120., 1000., magnetization]
    mytf = prism_tf(y, x, z, mymodel, incf, decf, incs, decs)

    assert_almost_equal(tf, mytf, decimal=5)
Exemple #10
0
def sensitivity_bx(x, y, z, xs, ys, zs, inc, dec):
    '''
    Calculate the sensitivity matrix

    input

    return
    '''
    N = x.size  # number of data
    M = xs.size  # number of parameters

    A = np.empty((N, M))  # sensitivity matrix

    mx, my, mz = ang2vec(
        1., inc, dec)  # magnetization direction in Cartesian coordinates

    for i in range(N):
        phi_xx = kernelxx(x[i], y[i], z[i], xs, ys, zs)
        phi_xy = kernelxy(x[i], y[i], z[i], xs, ys, zs)
        phi_xz = kernelxz(x[i], y[i], z[i], xs, ys, zs)
        gi = phi_xx * mx + phi_xy * my + phi_xz * mz

        A[i, :] = gi

    A *= CM * T2NT
    return A
Exemple #11
0
def by_layer(x, y, z, xs, ys, zs, p, inc, dec):
    '''
    Calculate the by produced by a layer

    input

    x,y,z : float - Cartesian coordinates (in m) of the i-th observation point
    xs,ys,zs : numpy arrays - Cartesian coordinates of equivalent sources
    p: numpy array - Vector composed by magnetic moment and magnetization direction of the
                     equivalent sources

    return
    by : numpy array - bz of the equivalent layer
    '''
    N = x.size

    by = np.empty(N, dtype=float)

    mx, my, mz = ang2vec(1., inc, dec)

    for i in range(N):
        phi_xy = kernelxy(x[i], y[i], z[i], xs, ys, zs)
        phi_yy = kernelyy(x[i], y[i], z[i], xs, ys, zs)
        phi_yz = kernelyz(x[i], y[i], z[i], xs, ys, zs)

        gi = phi_xy * mx + phi_yy * my + phi_yz * mz

        by[i] = np.dot(p.T, gi)

    by *= CM * T2NT
    return by
Exemple #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)
Exemple #13
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)
def sensitivity_dir(x, y, z, xs, ys, zs, sinc, sdec, p, inc, dec):
    '''
    Calculate the sensitivity matrix

    input

    return
    '''
    N = x.size  # number of data
    M = xs.size  # number of parameters

    F0x, F0y, F0z = ang2vec(1., sinc, sdec)  # main field
    mx, my, mz = ang2vec(
        1., inc, dec)  # magnetization direction in Cartesian coordinates

    dmx_I, dmy_I, dmz_I = derivative_inclination(1., inc, dec)
    dmx_D, dmy_D, dmz_D = derivative_declination(1., inc, dec)

    dgi_I = np.empty(N, dtype=float)
    for i in range(N):
        phi_xx = kernelxx(x[i], y[i], z[i], xs, ys, zs)
        phi_yy = kernelyy(x[i], y[i], z[i], xs, ys, zs)
        phi_xy = kernelxy(x[i], y[i], z[i], xs, ys, zs)
        phi_xz = kernelxz(x[i], y[i], z[i], xs, ys, zs)
        phi_yz = kernelyz(x[i], y[i], z[i], xs, ys, zs)
        phi_zz = -phi_xx - phi_yy
        gi = (F0x*dmx_I - F0z*dmz_I)*phi_xx + (F0y*dmy_I - F0z*dmz_I)*phi_yy + (F0x*dmy_I + F0y*dmx_I)*phi_xy +\
             (F0x*dmz_I + F0z*dmx_I)*phi_xz + (F0y*dmz_I + F0z*dmy_I)*phi_yz
        dgi_I[i] = np.dot(p.T, gi)

    dgi_D = np.empty(N, dtype=float)
    for i in range(N):
        phi_xx = kernelxx(x[i], y[i], z[i], xs, ys, zs)
        phi_yy = kernelyy(x[i], y[i], z[i], xs, ys, zs)
        phi_xy = kernelxy(x[i], y[i], z[i], xs, ys, zs)
        phi_xz = kernelxz(x[i], y[i], z[i], xs, ys, zs)
        phi_yz = kernelyz(x[i], y[i], z[i], xs, ys, zs)
        phi_zz = -phi_xx - phi_yy
        gi = (F0x*dmx_D - F0z*dmz_D)*phi_xx + (F0y*dmy_D - F0z*dmz_D)*phi_yy + (F0x*dmy_D + F0y*dmx_D)*phi_xy +\
             (F0x*dmz_D + F0z*dmx_D)*phi_xz + (F0y*dmz_D + F0z*dmy_D)*phi_yz
        dgi_D[i] = np.dot(p.T, gi)

    A = np.column_stack([dgi_I, dgi_D])
    A *= CM * T2NT

    return A
Exemple #15
0
def setup():
    global model, xp, yp, zp, inc, dec, prismmodel
    inc, dec = -30, 50
    props1 = {'density': 2., 'magnetization': utils.ang2vec(-20, 25, -10)}
    props2 = {'density': -3., 'magnetization': utils.ang2vec(10, inc, dec)}
    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)
Exemple #16
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)
def setup():
    global model, xp, yp, zp, inc, dec, prismmodel
    inc, dec = -30, 50
    props1 = {'density':2., 'magnetization':utils.ang2vec(-20, 25, -10)}
    props2 = {'density':-3., 'magnetization':utils.ang2vec(10, inc, dec)}
    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)
Exemple #18
0
def anomag_model(coords,radii=1.5e3,inc=50, dec=-30):
    
    model =[]
    for coord, radius in zip(coords, radii):
  
        model_tmp = mesher.Sphere(x=coord[0], y=coord[1], z=coord[2], radius=radius,
                      props={'magnetization': utils.ang2vec(1, inc=50, dec=-30)})
            
        model.append(model_tmp)
    
    return model
Exemple #19
0
def sample(Lx,Ly,Lz,P,m=None,inc=None,dec=None):
    '''
    Define the interpretation model as a 1D array of rectangular prisms
    along the x-axis.
    
    input
    
    Lx: float - side length of all prisms along x (m).
    
    Ly: float - side length of all prisms along x (m).
    
    Lz: float - side length of all prisms along x (m).
    
    P: int - number of prisms
    
    m: list - magnetization intensity (A/m) of each prism.
    inc: list - magnetization inclination (graus) of each prism.
    dec: list - magnetization declination (graus) of each prism.
    
    output
    
    model: list of geometrical elements mesher class of the 
        Fatiando a Terra package - interpretation model.
    '''
    
    sizex = Lx
    sizey = Ly
    sizez = Lz

    L = P*sizex
    a = -0.5*L
    
    model = []

    if ((m is not None) & (inc is not None) & (dec is not None)):
        intensity = np.array(m)
        inclinacao = np.array(inc)
        declinacao = np.array(dec)
        mag = []
        for i in range(P):
            mag.append(ang2vec(intensity[i],inclinacao[i],declinacao[i]))
    
        for i in range(P):
            model.append(mesher.Prism(a+i*sizex, a+(i+1)*sizex, \
                                      -0.5*sizey, 0.5*sizey, \
                                      -0.5*sizez, 0.5*sizez, \
                                      {'magnetization': mag[i]}))
    else:
        for i in range(P):
            model.append(mesher.Prism(a+i*sizex, a+(i+1)*sizex, \
                                      -0.5*sizey, 0.5*sizey, \
                                      -0.5*sizez, 0.5*sizez))
        
    return model
def test_regional2():
    '''
    In this test, we set a values for the field magnetization intensity. Then we compare the results obtained by the regional calculation function and the function ang2vec from Fatiando a Terra. In thes test we use a float values for the three parameters.
    '''
    intensity = 22458.25
    inclination = 33.67
    declination = 60.60

    regional_fatiando = utils.ang2vec(intensity, inclination, declination)
    regional_myresult = regional(intensity, inclination, declination)

    assert_almost_equal(regional_fatiando, regional_myresult, decimal=6)
Exemple #21
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())
Exemple #22
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())
def tfa_layer(x, y, z, xs, ys, zs, sinc, sdec, p, inc, dec):
    '''
    Calculate the Total Field Anomaly produced by a layer

    input

    x,y,z : float - Cartesian coordinates (in m) of the i-th observation point
    xs,ys,zs : numpy arrays - Cartesian coordinates of equivalent sources
    sinc,sdec: float - Main field direction
    p: numpy array - Vector composed by magnetic moment and magnetization direction of the
                     equivalent sources

    return
    tfa : numpy array - total field anomaly of the equivalent layer
    '''
    N = x.size
    M = xs.size

    tfa = np.empty(N, dtype=float)

    F0x, F0y, F0z = ang2vec(1., sinc, sdec)
    mx, my, mz = ang2vec(1., inc, dec)

    for i in range(N):
        phi_xx = kernelxx(x[i], y[i], z[i], xs, ys, zs)
        phi_yy = kernelyy(x[i], y[i], z[i], xs, ys, zs)
        phi_xy = kernelxy(x[i], y[i], z[i], xs, ys, zs)
        phi_xz = kernelxz(x[i], y[i], z[i], xs, ys, zs)
        phi_yz = kernelyz(x[i], y[i], z[i], xs, ys, zs)
        phi_zz = -phi_xx - phi_yy

        gi = (F0x*mx - F0z*mz)*phi_xx + (F0y*my - F0z*mz)*phi_yy + (F0x*my + F0y*mx)*phi_xy +\
             (F0x*mz + F0z*mx)*phi_xz + (F0y*mz + F0z*my)*phi_yz

        tfa[i] = np.dot(p.T, gi)

    tfa *= CM * T2NT
    return tfa
Exemple #24
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))
Exemple #25
0
def test_coordinate_transformation():
    'Test for calculation transformation coordinate'
    ### Directions in Spherical coordinates
    inc, dec = -60., 30.

    ### Generating a vector with ang2vec
    F = ang2vec(1., inc, dec)

    ### Generating a vector using a function within auxiliary function
    F_aux = fc.sph2cart(1., inc, dec)

    result = np.allclose(F, F_aux)

    assert_almost_equal(result, True)
Exemple #26
0
def test_eql_mag_jacobian():
    "EQLTotalField produces the right Jacobian matrix for single source"
    inc, dec = -30, 20
    model = PointGrid([-10, 10, -10, 10], 500, (2, 2))[0]
    model.addprop('magnetization', utils.ang2vec(1, inc, dec))
    n = 1000
    x, y, z = gridder.scatter([-10, 10, -10, 10], n, z=-100, seed=42)
    data = sphere.tf(x, y, z, [model], inc, dec)

    eql = EQLTotalField(x, y, z, data, inc, dec, [model])
    A = eql.jacobian(None)

    assert A.shape == (n, 1)
    assert_allclose(A[:, 0], data, rtol=0.01)
Exemple #27
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
Exemple #28
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()))
Exemple #29
0
def dipolesrand(N, seed,n,deg_dec,deg_inc,std,mag,raio,Lx,Ly,Lz):
    '''
    Generates a set of spheres randomly distribuited within the model
    
    input
    
    N: int - number of prisms
        
    s: int - seed value
    
    n: int - number of magnetized spheres
    
    deg_dec: float - mean value of the declination (degrees)
    
    deg_inc: float - mean value of inclination (degrees)
    
    std: float - standard deviation of the declination and inclination (degrees)
    
    mag: float - magnetization intensity of each sphere (A/m)
    
    raio: float - radius of each sphere (m)  
    
    Lx,Ly,Lz: int - prisms dimensions (m)
    
    return
    
    modelrand: list of geometrical objects using the library Fatiando a Terra.
    '''
    np.random.seed(seed=seed)
    sizex = Lx
    sizey = Ly
    sizez = Lz
    L = N*sizex
    R = raio
    Coordx = np.random.uniform(-0.5*L+R,+0.5*L-R,n) 
    Coordy = np.random.uniform(-0.5*sizey+R,+0.5*sizey-R,n) 
    Coordz = np.random.uniform(-0.5*sizez+R,+0.5*sizez-R,n)
    Dec_rand = np.random.normal(deg_dec, std,n)
    Inc_rand = np.random.normal(deg_inc, std,n)
    
    magrand = []
    for i in range(n):
        magrand.append(ang2vec(mag,Inc_rand[i],Dec_rand[i]))
    
    modelrand = []
    for i in range(n):
        modelrand.append(mesher.Sphere(Coordx[i], Coordy[i], Coordz[i], R , {'magnetization': magrand[i]})) 

    return modelrand,Coordx,Coordy,Coordz
def setup():
    global model, x, y, z, inc, dec, struct_ind, field, xderiv, yderiv, zderiv, base, pos
    inc, dec = -30, 50
    pos = np.array([1000, 1200, 200])
    model = Sphere(pos[0], pos[1], pos[2], 1, {"magnetization": utils.ang2vec(10000, inc, dec)})
    struct_ind = 3
    shape = (200, 200)
    x, y, z = gridder.regular((0, 3000, 0, 3000), shape, z=-100)
    base = 10
    field = sphere.tf(x, y, z, [model], inc, dec) + base
    # Use finite difference derivatives so that these tests don't depend on the
    # performance of the FFT derivatives.
    xderiv = (sphere.tf(x + 1, y, z, [model], inc, dec) - sphere.tf(x - 1, y, z, [model], inc, dec)) / 2
    yderiv = (sphere.tf(x, y + 1, z, [model], inc, dec) - sphere.tf(x, y - 1, z, [model], inc, dec)) / 2
    zderiv = (sphere.tf(x, y, z + 1, [model], inc, dec) - sphere.tf(x, y, z - 1, [model], inc, dec)) / 2
def setup():
    global model, x, y, z, inc, dec, struct_ind, field, xderiv, yderiv, \
        zderiv, base, pos
    inc, dec = -30, 50
    pos = np.array([1000, 1000, 200])
    model = Sphere(pos[0], pos[1], pos[2], 1,
                   {'magnetization': utils.ang2vec(10000, inc, dec)})
    struct_ind = 3
    shape = (128, 128)
    x, y, z = gridder.regular((0, 3000, 0, 3000), shape, z=-1)
    base = 10
    field = utils.nt2si(sphere.tf(x, y, z, [model], inc, dec)) + base
    xderiv = fourier.derivx(x, y, field, shape)
    yderiv = fourier.derivy(x, y, field, shape)
    zderiv = fourier.derivz(x, y, field, shape)
def test_triaxial_ellipsoid_force_prop():
    "Test the triaxial_ellipsoid code with an imposed physical property"

    # forced physical property
    pmag = utils.ang2vec(5, 43, -8)

    # magnetic field produced by the ellipsoids
    # with the forced physical property
    bx = triaxial_ellipsoid.bx(x, y, z, model,
                               F, inc, dec, demag=False, pmag=pmag)
    by = triaxial_ellipsoid.by(x, y, z, model,
                               F, inc, dec, demag=False, pmag=pmag)
    bz = triaxial_ellipsoid.bz(x, y, z, model,
                               F, inc, dec, demag=False, pmag=pmag)
    tf = triaxial_ellipsoid.tf(x, y, z, model,
                               F, inc, dec, demag=False, pmag=pmag)

    # constant factor
    f = 3.71768

    # magnetic field produced by the ellipsoids
    # with the forced physical property multiplied by the constant factor
    bx2 = triaxial_ellipsoid.bx(x, y, z, model,
                                F, inc, dec, demag=False, pmag=f*pmag)
    by2 = triaxial_ellipsoid.by(x, y, z, model,
                                F, inc, dec, demag=False, pmag=f*pmag)
    bz2 = triaxial_ellipsoid.bz(x, y, z, model,
                                F, inc, dec, demag=False, pmag=f*pmag)
    tf2 = triaxial_ellipsoid.tf(x, y, z, model,
                                F, inc, dec, demag=False, pmag=f*pmag)

    # the fields must be proportional
    assert_almost_equal(bx2, f*bx, decimal=12)
    assert_almost_equal(by2, f*by, decimal=12)
    assert_almost_equal(bz2, f*bz, decimal=12)
    assert_almost_equal(tf2, f*tf, decimal=12)

    # pmag not None requires demag not True
    raises(AssertionError, triaxial_ellipsoid.bx, x, y, z, model,
           F, inc, dec, demag=True, pmag=pmag)
    raises(AssertionError, triaxial_ellipsoid.by, x, y, z, model,
           F, inc, dec, demag=True, pmag=pmag)
    raises(AssertionError, triaxial_ellipsoid.bz, x, y, z, model,
           F, inc, dec, demag=True, pmag=pmag)
    raises(AssertionError, triaxial_ellipsoid.tf, x, y, z, model,
           F, inc, dec, demag=True, pmag=pmag)
Exemple #33
0
def setup():
    global model, x, y, z, inc, dec, struct_ind, field, dx, dy, dz, base, pos
    inc, dec = -30, 50
    pos = np.array([1000, 1200, 200])
    model = Sphere(pos[0], pos[1], pos[2], 1,
                   {'magnetization': utils.ang2vec(10000, inc, dec)})
    struct_ind = 3
    shape = (200, 200)
    x, y, z = gridder.regular((0, 3000, 0, 3000), shape, z=-100)
    base = 10
    field = sphere.tf(x, y, z, [model], inc, dec) + base
    # Use finite difference derivatives so that these tests don't depend on the
    # performance of the FFT derivatives.
    dx = (sphere.tf(x + 1, y, z, [model], inc, dec) -
          sphere.tf(x - 1, y, z, [model], inc, dec)) / 2
    dy = (sphere.tf(x, y + 1, z, [model], inc, dec) -
          sphere.tf(x, y - 1, z, [model], inc, dec)) / 2
    dz = (sphere.tf(x, y, z + 1, [model], inc, dec) -
          sphere.tf(x, y, z - 1, [model], inc, dec)) / 2
def test_triaxial_ellipsoid_ignore_none():
    "Triaxial ellipsoid ignores model elements that are None"

    # forced physical property
    pmag = utils.ang2vec(7, -52, 13)

    # copy of the original model
    model_none = deepcopy(model)

    # force an element of the copy to be None
    model_none[1] = None

    # magnetic field produced by the original model
    # without the removed element
    bx = triaxial_ellipsoid.bx(x, y, z, [model[0], model[2]],
                               F, inc, dec, demag=False, pmag=pmag)
    by = triaxial_ellipsoid.by(x, y, z, [model[0], model[2]],
                               F, inc, dec, demag=False, pmag=pmag)
    bz = triaxial_ellipsoid.bz(x, y, z, [model[0], model[2]],
                               F, inc, dec, demag=False, pmag=pmag)
    tf = triaxial_ellipsoid.tf(x, y, z, [model[0], model[2]],
                               F, inc, dec, demag=False, pmag=pmag)

    # magnetic field produced by the copy
    bx2 = triaxial_ellipsoid.bx(x, y, z, model_none,
                                F, inc, dec, demag=False, pmag=pmag)
    by2 = triaxial_ellipsoid.by(x, y, z, model_none,
                                F, inc, dec, demag=False, pmag=pmag)
    bz2 = triaxial_ellipsoid.bz(x, y, z, model_none,
                                F, inc, dec, demag=False, pmag=pmag)
    tf2 = triaxial_ellipsoid.tf(x, y, z, model_none,
                                F, inc, dec, demag=False, pmag=pmag)

    assert_almost_equal(bx2, bx, decimal=15)
    assert_almost_equal(by2, by, decimal=15)
    assert_almost_equal(bz2, bz, decimal=15)
    assert_almost_equal(tf2, tf, decimal=15)
Exemple #35
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
"""
Meshing: Making a grid of 3D point sources
"""
from fatiando import mesher, utils, gravmag, gridder
from fatiando.vis import mpl

grid = mesher.PointGrid([0, 1000, 0, 2000], 500, (50, 50))
# Add some density to the grid
grid.addprop('density', 1000000000*utils.gaussian2d(grid.x, grid.y, 100, 500,
    x0=500, y0=1000, angle=-60))
# and some magnetization
inc, dec = -45, 0
grid.addprop('magnetization', [d/100.*utils.ang2vec(1, inc, dec)
    for d in grid.props['density']])
# plot the layer
mpl.figure()
mpl.subplot(2, 1, 1)
mpl.axis('scaled')
mpl.title('Density (mass)')
mpl.pcolor(grid.y, grid.x, grid.props['density'], grid.shape)
mpl.colorbar()
mpl.subplot(2, 1, 2)
mpl.axis('scaled')
mpl.title('Magnetization intensity (dipole moment)')
mpl.pcolor(grid.y, grid.x, utils.vecnorm(grid.props['magnetization']),
    grid.shape)
mpl.colorbar()
mpl.show()

# Now do some calculations with the grid
shape = (100, 100)
in the module than the one we are showing here. They can be more efficient but
usually require more configuration.

"""
from __future__ import division, print_function
import matplotlib.pyplot as plt
import numpy as np
from fatiando.gravmag import prism, sphere
from fatiando.gravmag.eqlayer import EQLTotalField
from fatiando.inversion import Damping
from fatiando import gridder, utils, mesher

# First thing to do is make some synthetic data to test the method. We'll use a
# single prism with only induced magnetization to keep it simple
inc, dec = -5, 23
props = {'magnetization': utils.ang2vec(5, inc, dec)}
model = [mesher.Prism(-2000, 2000, -200, 200, 100, 4000, props)]

# The synthetic data will be generated on a regular grid
area = [-8000, 8000, -5000, 5000]
shape = (40, 40)
x, y, z = gridder.regular(area, shape, z=-150)
# Generate some noisy data from our model
data = utils.contaminate(prism.tf(x, y, z, model, inc, dec), 5, seed=0)

# Now for the equivalent layer. We must setup a layer of dipoles where we'll
# estimate a magnetization intensity distribution that fits our synthetic data.
# Notice that we only estimate the intensity. We must provide the magnetization
# direction of the layer through the sinc and sdec parameters.
layer = mesher.PointGrid(area, 700, shape)
eql = (EQLTotalField(x, y, z, data, inc, dec, layer, sinc=inc, sdec=dec)
Exemple #38
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])
Exemple #39
0
"""
GravMag: 3D forward modeling of total-field magnetic anomaly using rectangular
prisms (model with induced and remanent magnetization)
"""
from fatiando import mesher, gridder, utils
from fatiando.gravmag import prism
from fatiando.vis import mpl, myv

# The regional field
inc, dec = 30, -15
bounds = [-5000, 5000, -5000, 5000, 0, 5000]
model = [
    mesher.Prism(-4000, -3000, -4000, -3000, 0, 2000,
                 {'magnetization': utils.ang2vec(1, inc, dec)}),
    mesher.Prism(-1000, 1000, -1000, 1000, 0, 2000,
                 {'magnetization': utils.ang2vec(1, inc, dec)}),
    # This prism will have magnetization in a different direction
    mesher.Prism(2000, 4000, 3000, 4000, 0, 2000,
                 {'magnetization': utils.ang2vec(3, -10, 45)})]
# Create a regular grid at 100m height
shape = (200, 200)
area = bounds[:4]
xp, yp, zp = gridder.regular(area, shape, z=-500)
# Calculate the anomaly for a given regional field
tf = prism.tf(xp, yp, zp, model, inc, dec)
# Plot
mpl.figure()
mpl.title("Total-field anomaly (nT)")
mpl.axis('scaled')
mpl.contourf(yp, xp, tf, shape, 15)
mpl.colorbar()
"""
GravMag: 3D forward modeling of total-field magnetic anomaly using spheres
"""
from fatiando import mesher, gridder, utils
from fatiando.gravmag import sphere
from fatiando.vis import mpl

# Set the inclination and declination of the regional field
inc, dec = -30, 45
# Create a sphere model
model = [
    # One with induced magnetization
    mesher.Sphere(0, 2000, 600, 500, {'magnetization':5}),
    # and one with remanent
    mesher.Sphere(0, -2000, 600, 500,
        {'magnetization':utils.ang2vec(10, 70, -50)})] # induced + remanet
# Create a regular grid at 100m height
shape = (100, 100)
area = (-5000, 5000, -5000, 5000)
xp, yp, zp = gridder.regular(area, shape, z=-100)
# Calculate the anomaly for a given regional field
tf = sphere.tf(xp, yp, zp, model, inc, dec)
# Plot
mpl.figure()
mpl.title("Total-field anomaly (nT)")
mpl.axis('scaled')
mpl.contourf(yp, xp, tf, shape, 15)
mpl.colorbar()
mpl.xlabel('East y (km)')
mpl.ylabel('North x (km)')
mpl.m2km()
approach used in all industry software. This is implemented in
:class:`fatiando.gravmag.euler.EulerDeconvMW`.


"""
from __future__ import print_function
from fatiando.gravmag import sphere, transform, euler
from fatiando import gridder, utils, mesher
import matplotlib.pyplot as plt

# Make some synthetic magnetic data to test our Euler deconvolution.
# The regional field
inc, dec = -45, 0
# Make a model of two spheres magnetized by induction only
model = [
    mesher.Sphere(x=-1000, y=-1000, z=1500, radius=1000, props={"magnetization": utils.ang2vec(2, inc, dec)}),
    mesher.Sphere(x=1000, y=1500, z=1000, radius=1000, props={"magnetization": utils.ang2vec(1, inc, dec)}),
]

print("Centers of the model spheres:")
print(model[0].center)
print(model[1].center)

# Generate some magnetic data from the model
shape = (100, 100)
area = [-5000, 5000, -5000, 5000]
x, y, z = gridder.regular(area, shape, z=-150)
data = sphere.tf(x, y, z, model, inc, dec)

# We also need the derivatives of our data
xderiv = transform.derivx(x, y, data, shape)
GravMag: Use the DipoleMagDir class to estimate the magnetization direction
of dipoles with known centers
"""
import numpy

from fatiando import mesher, gridder
from fatiando.utils import ang2vec, vec2ang, contaminate
from fatiando.gravmag import sphere
from fatiando.vis import mpl
from fatiando.gravmag.magdir import DipoleMagDir
from fatiando.constants import CM

# Make noise-corrupted synthetic data
inc, dec = -10.0, -15.0  # inclination and declination of the Geomagnetic Field
model = [mesher.Sphere(3000, 3000, 1000, 1000,
                       {'magnetization': ang2vec(6.0, -20.0, -10.0)}),
         mesher.Sphere(7000, 7000, 1000, 1000,
                       {'magnetization': ang2vec(10.0, 3.0, -67.0)})]
area = (0, 10000, 0, 10000)
x, y, z = gridder.scatter(area, 1000, z=-150, seed=0)
tf = contaminate(sphere.tf(x, y, z, model, inc, dec), 5.0, seed=0)

# Give the centers of the dipoles
centers = [[3000, 3000, 1000], [7000, 7000, 1000]]

# Estimate the magnetization vectors
solver = DipoleMagDir(x, y, z, tf, inc, dec, centers).fit()

# Print the estimated and true dipole monents, inclinations and declinations
print 'Estimated magnetization (intensity, inclination, declination)'
for e in solver.estimate_:
of dipoles with known centers
"""

import numpy

from fatiando import mesher, gridder
from fatiando.utils import ang2vec, vec2ang, contaminate
from fatiando.gravmag import sphere
from fatiando.vis import mpl
from fatiando.gravmag.magdir import DipoleMagDir
from fatiando.constants import CM

# Make noise-corrupted synthetic data
inc, dec = -10.0, -15.0  # inclination and declination of the Geomagnetic Field
model = [mesher.Sphere(3000, 3000, 1000, 1000,
                       {'magnetization': ang2vec(6.0, -20.0, -10.0)}),
         mesher.Sphere(7000, 7000, 1000, 1000,
                       {'magnetization': ang2vec(10.0, 3.0, -67.0)})]
area = (0, 10000, 0, 10000)
x, y, z = gridder.scatter(area, 1000, z=-150, seed=0)
tf = contaminate(sphere.tf(x, y, z, model, inc, dec), 5.0)

# Give the centers of the dipoles
centers = [[3000, 3000, 1000], [7000, 7000, 1000]]

p_true = numpy.hstack((ang2vec(CM * (4. * numpy.pi / 3.) * 6.0 * 1000 ** 3, -20.0, -10.0),
                       ang2vec(CM * (4. * numpy.pi / 3.) * 10.0 * 1000 ** 3, 3.0, -67.0)))
estimate_true = [[CM * (4. * numpy.pi / 3.) * 6.0 * 1000 ** 3, -20.0, -10.0],
                 [CM * (4. * numpy.pi / 3.) * 10.0 * 1000 ** 3, 3.0, -67.0]]

# Estimate the magnetization vectors
mag_c = 1.5
inc_c = 45.
dec_c = 45.

#vertical prism
x1_cr, x2_cr = 4000, 6000
y1_cr, y2_cr = 14000, 16000
z1_cr, z2_cr = 200, 5000
#Magnetization intensity
mag_cr = 1.5
inc_cr = 60.
dec_cr = 60.

#From Fatiando a Terra
# Compute the cosine directions of the main geomagetic field (F)
F = utils.ang2vec(1, inc_o, dec_o)

#Generate a model From Fatiando a Terra
model_mag = [
    mesher.Prism(x1_cr, x2_cr, y1_cr, y2_cr, z1_cr, z2_cr,
                 {'magnetization': utils.ang2vec(mag_cr, inc_cr, dec_cr)}),
    mesher.Prism(x1_c, x2_c, y1_c, y2_c, z1_c, z2_c,
                 {'magnetization': utils.ang2vec(mag_c, inc_c, dec_c)}),
    mesher.Prism(x3_c, x4_c, y3_c, y4_c, z3_c, z4_c,
                 {'magnetization': utils.ang2vec(mag_c, inc_c, dec_c)}),
    mesher.Prism(x3_c, x4_c, y5_c, y6_c, z3_c, z4_c,
                 {'magnetization': utils.ang2vec(mag_c, inc_c, dec_c)}),
    mesher.Prism(x1_L, x2_L, y1_L, y2_L, z1_L, z2_L,
                 {'magnetization': utils.ang2vec(mag_L, inc_s, dec_s)}),
    mesher.Prism(x3_L, x4_L, y3_L, y4_L, z3_L, z4_L,
                 {'magnetization': utils.ang2vec(mag_L, inc_s, dec_s)}),
Exemple #45
0
data is already reduced to the pole. You can use
: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')
"""
from fatiando import mesher, gridder, utils
from fatiando.gravmag import prism
from fatiando.vis import mpl, myv

# The regional field
inc, dec = 30, -15
bounds = [-5000, 5000, -5000, 5000, 0, 5000]
model = [
    mesher.Prism(-4000, -3000, -4000, -3000, 0, 2000,
                 {'magnetization': 2}),  # a scalar magnetization means only induced
    mesher.Prism(-1000, 1000, -1000, 1000, 0, 2000,
                 {'magnetization': 1}),
    # This prism will have magnetization in a different direction
    mesher.Prism(2000, 4000, 3000, 4000, 0, 2000,
                 {'magnetization': utils.ang2vec(3, -10, 45)})]  # induced + remanent
# Create a regular grid at 100m height
shape = (200, 200)
area = bounds[:4]
xp, yp, zp = gridder.regular(area, shape, z=-500)
# Calculate the anomaly for a given regional field
tf = prism.tf(xp, yp, zp, model, inc, dec)
# Plot
mpl.figure()
mpl.title("Total-field anomaly (nT)")
mpl.axis('scaled')
mpl.contourf(yp, xp, tf, shape, 15)
mpl.colorbar()
mpl.xlabel('East y (km)')
mpl.ylabel('North x (km)')
mpl.m2km()
Exemple #47
0
the geomagnetic field direction. This example shows how to use it in this case.
Use ``sinc=inc`` and ``sdec=dec`` if there is only induced magnetization.

"""
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 with a total magnetization that is
# different from the geomagnetic field (so there is remanent magnetization or
# some demagnetizing effect)
inc, dec = -60, 23  # Geomagnetic field direction
sinc, sdec = -30, -20  # Source magnetization direction
mag = utils.ang2vec(1, sinc, sdec)
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 = prism.tf(x, y, z, model, inc, dec)

# Reduce to the pole
data_at_pole = transform.reduce_to_pole(x, y, data, shape, inc, dec, sinc,
                                        sdec)

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

ax = plt.subplot(1, 2, 1)
ax.set_title('Original data')
"""
GravMag: 3D forward modeling of total-field magnetic anomaly using spheres
"""
from fatiando import mesher, gridder, utils
from fatiando.gravmag import sphere
from fatiando.vis import mpl

# Set the inclination and declination of the regional field
inc, dec = -30, 45
# Create a sphere model
model = [
    # One with induced magnetization
    mesher.Sphere(0, 2000, 600, 500,
                  {'magnetization': utils.ang2vec(5, inc, dec)}),
    # and one with remanent
    mesher.Sphere(0, -2000, 600, 500,
                  {'magnetization': utils.ang2vec(10, 70, -50)})]
# Create a regular grid at 100m height
shape = (100, 100)
area = (-5000, 5000, -5000, 5000)
xp, yp, zp = gridder.regular(area, shape, z=-100)
# Calculate the anomaly for a given regional field
tf = sphere.tf(xp, yp, zp, model, inc, dec)
# Plot
mpl.figure()
mpl.title("Total-field anomaly (nT)")
mpl.axis('scaled')
mpl.contourf(yp, xp, tf, shape, 15)
mpl.colorbar()
mpl.xlabel('East y (km)')
mpl.ylabel('North x (km)')
"""
from __future__ import division, print_function
from fatiando import mesher, gridder, utils
from fatiando.gravmag import sphere
import matplotlib.pyplot as plt
import numpy as np

# Create a model using geometric objects from fatiando.mesher
# Each model element has a dictionary with its physical properties.
# The spheres have different total magnetization vectors (total = induced +
# remanent + any other effects). Notice that the magnetization has to be a
# vector. Function utils.ang2vec converts intensity, inclination, and
# declination into a 3 component vector for easier handling.
model = [
    mesher.Sphere(x=10e3, y=10e3, z=2e3, radius=1.5e3,
                  props={'magnetization': utils.ang2vec(1, inc=50, dec=-30)}),
    mesher.Sphere(x=20e3, y=20e3, z=2e3, radius=1.5e3,
                  props={'magnetization': utils.ang2vec(1, inc=-70, dec=30)})]

# Set the inclination and declination of the geomagnetic field.
inc, dec = -10, 13
# Create a regular grid at a constant height
shape = (300, 300)
area = [0, 30e3, 0, 30e3]
x, y, z = gridder.regular(area, shape, z=-10)

fields = [
    ['Total field Anomaly (nt)', sphere.tf(x, y, z, model, inc, dec)],
    ['Bx (nT)', sphere.bx(x, y, z, model)],
    ['By (nT)', sphere.by(x, y, z, model)],
    ['Bz (nT)', sphere.bz(x, y, z, model)],
:class:`fatiando.gravmag.euler.EulerDeconvEW`.

"""
from __future__ import print_function
from fatiando.gravmag import sphere, transform, euler
from fatiando import gridder, utils, mesher
import matplotlib.pyplot as plt
import numpy as np

# Make some synthetic magnetic data to test our Euler deconvolution.
# The regional field
inc, dec = -45, 0
# Make a model of two spheres magnetized by induction only
model = [
    mesher.Sphere(x=-1000, y=-1000, z=1500, radius=1000,
                  props={'magnetization': utils.ang2vec(2, inc, dec)}),
    mesher.Sphere(x=1000, y=1500, z=1000, radius=1000,
                  props={'magnetization': utils.ang2vec(1, inc, dec)}),
    ]
# Generate some magnetic data from the model
shape = (100, 100)
area = [-5000, 5000, -5000, 5000]
x, y, z = gridder.regular(area, shape, z=-150)
data = sphere.tf(x, y, z, model, inc, dec)

# We also need the derivatives of our data
xderiv = transform.derivx(x, y, data, shape)
yderiv = transform.derivy(x, y, data, shape)
zderiv = transform.derivz(x, y, data, shape)

# Now we can run our Euler deconv solver using expanding windows. We'll run 2
"""
GravMag: Reduction to the pole of a total field anomaly using FFT
"""
from fatiando import mesher, gridder, utils
from fatiando.gravmag import prism, transform
from fatiando.vis import mpl

# Direction of the Geomagnetic field
inc, dec = -60, 0
# Make a model with only induced magnetization
model = [
    mesher.Prism(-100, 100, -100, 100, 0, 2000,
                 {'magnetization': utils.ang2vec(10, inc, dec)})
]
area = (-5000, 5000, -5000, 5000)
shape = (100, 100)
z0 = -500
x, y, z = gridder.regular(area, shape, z=z0)
tf = utils.contaminate(prism.tf(x, y, z, model, inc, dec), 1, seed=0)
# Reduce to the pole using FFT. Since there is only induced magnetization, the
# magnetization direction (sinc and sdec) is the same as the geomagnetic field
pole = transform.reduce_to_pole(x, y, tf, shape, inc, dec, sinc=inc, sdec=dec)
# Calculate the true value at the pole for comparison
true = prism.tf(x, y, z, model, 90, 0, pmag=utils.ang2vec(10, 90, 0))

fig, axes = mpl.subplots(1, 3, figsize=(14, 4))
for ax in axes:
    ax.set_aspect('equal')
mpl.sca(axes[0])
mpl.title("Original total field anomaly")
mpl.contourf(y, x, tf, shape, 30, cmap=mpl.cm.RdBu_r)
"""
GravMag: 3D magnetic inversion by planting anomalous densities using
``harvester``
"""
from fatiando import logger, gridder, utils
from fatiando import gravmag as gm
from fatiando.mesher import Prism, PrismMesh, vremove
from fatiando.vis import mpl, myv

log = logger.get()
log.info(logger.header())

# The regional field
inc, dec = -10, 25
# Model with induced + remanent magnetization
mag = utils.ang2vec(10, 20, -15)
# Create a synthetic model
model = [Prism(250, 750, 250, 750, 200, 700, {'magnetization':mag})]
# 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 = 5
tf = utils.contaminate(gm.prism.tf(xp, yp, zp, model, inc, dec), noise)
# plot the data
mpl.figure()
mpl.title("Synthetic total field anomaly (nT)")
mpl.axis('scaled')
levels = mpl.contourf(yp, xp, tf, shape, 12)
mpl.colorbar()
"""
GravMag: Reduction to the pole of a total field anomaly using FFT
"""
from fatiando import mesher, gridder, utils
from fatiando.gravmag import prism, transform
from fatiando.vis import mpl

# Direction of the Geomagnetic field
inc, dec = -60, 0
# Make a model with only induced magnetization
model = [mesher.Prism(-100, 100, -100, 100, 0, 2000,
                      {'magnetization': utils.ang2vec(10, inc, dec)})]
area = (-5000, 5000, -5000, 5000)
shape = (100, 100)
z0 = -500
x, y, z = gridder.regular(area, shape, z=z0)
tf = utils.contaminate(prism.tf(x, y, z, model, inc, dec),
                       1, seed=0)
# Reduce to the pole using FFT. Since there is only induced magnetization, the
# magnetization direction (sinc and sdec) is the same as the geomagnetic field
pole = transform.reduce_to_pole(x, y, tf, shape, inc, dec, sinc=inc, sdec=dec)
# Calculate the true value at the pole for comparison
true = prism.tf(x, y, z, model, 90, 0, pmag=utils.ang2vec(10, 90, 0))

fig, axes = mpl.subplots(1, 3, figsize=(14, 4))
for ax in axes:
    ax.set_aspect('equal')
mpl.sca(axes[0])
mpl.title("Original total field anomaly")
mpl.contourf(y, x, tf, shape, 30, cmap=mpl.cm.RdBu_r)
mpl.colorbar(pad=0).set_label('nT')