Example #1
0
def test_bz():
    "gravmag.sphere.bz python vs cython implementation"
    py = _sphere_numpy.bz(xp, yp, zp, model)
    cy = sphere.bz(xp, yp, zp, model)
    diff = np.abs(py - cy)
    assert np.all(diff <= lower_precision), \
        'max diff: %g python: %g cython %g' \
        % (max(diff), py[diff == max(diff)][0], cy[diff == max(diff)][0])
Example #2
0
def test_bz():
    "gravmag.sphere.bz python vs cython implementation"
    py = _sphere_numpy.bz(xp, yp, zp, model)
    cy = sphere.bz(xp, yp, zp, model)
    diff = np.abs(py - cy)
    assert np.all(diff <= lower_precision), \
        'max diff: %g python: %g cython %g' \
        % (max(diff), py[diff == max(diff)][0], cy[diff == max(diff)][0])
    out = out.T
    np.savetxt('data\predict_' + str(lambida) + '.dat',
               out,
               delimiter=' ',
               fmt='%1.3f')

    out = None

    # Compute the transformed matrix
    Tx = np.empty((N, M), dtype=float)
    Ty = np.empty((N, M), dtype=float)
    Tz = np.empty((N, M), dtype=float)
    for i, c in enumerate(layer):
        Tx[:, i] = sphere.bx(xi, yi, zi, [c], pmag=F)
        Ty[:, i] = sphere.by(xi, yi, zi, [c], pmag=F)
        Tz[:, i] = sphere.bz(xi, yi, zi, [c], pmag=F)

    # compute the components
    Bx_eq = np.dot(Tx, p)
    By_eq = np.dot(Ty, p)
    Bz_eq = np.dot(Tz, p)

    Tx = None
    Ty = None
    Tz = None
    p = None

    #Amplitude of the magnetic anomaly vector
    B_eq = np.sqrt(Bx_eq * Bx_eq + By_eq * By_eq + Bz_eq * Bz_eq)

    Bx_eq = None
                  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)],
]

# Make maps of all fields calculated
fig = plt.figure(figsize=(7, 6))
plt.rcParams['font.size'] = 10
X, Y = x.reshape(shape) / 1000, y.reshape(shape) / 1000
for i, tmp in enumerate(fields):
    ax = plt.subplot(2, 2, i + 1)
    field, data = tmp
    scale = np.abs([data.min(), data.max()]).max()
    ax.set_title(field)
    plot = ax.pcolormesh(Y,
                         X,
                         data.reshape(shape),
                         cmap='RdBu_r',
Example #5
0
def magnetic_data(x, y, z, model, alpha, eff_area = None, grains = None):
    '''
    Calculates the magnetic indution on the plane alpha
    located around the sample.
    
    input
    
    x, y, z: numpy arrays - Cartesian coordinates (in m) of 
             the points on which the magnetic field is calculated.
    model: list - geometrical elements of the Fatiando a Terra 
           class mesher - interpretation model.
    grains: None or list - if not None, is a list of geometrical elements 
            of the Fatiando a Terra class mesher - randomly magnetized grains.
    alpha: int - index of the plane on which the data are calculated.
    eff_area: None or tuple of floats - effective area of the simulated sensor.
              If None, calculates the field at the points x, y, z.
              If not None, eff_area = (lx, ly), where lx and ly
              are the side lengths (in microns) of the effective area of the sensor
              along the x and y axes.
    ns: None or tuple of ints - number of points on which the field is
        averaged within the effective area of the sensor.
        Is None if eff_area is none.
        If effe_area is not None, ns = (nsx,nsy), where nsx and nsy are
        the number of points on which the filed is averaged within the
        the effective area of the sensor along the x and y axes.
    
    output
    
    B: numpy array - magnetic data
    '''
    
    assert (alpha == 0) or (alpha == 1) or (alpha == 2) or (alpha == 3), \
           'alpha must be equal to 0, 1, 2 or 3'
           
    if eff_area is not None:
        
        ns = 7
        
        xg, yg, zg = point2grid(x, y, eff_area, ns, z)
            
        if (alpha == 0) or (alpha == 2):
            B = np.mean(np.reshape(prism.bz(xg, yg, zg, model), (x.size, ns*ns)), axis=1)
            if grains is not None:
                B += np.mean(np.reshape(sphere.bz(xg, yg, zg, grains), (x.size, ns*ns)), axis=1)

        if (alpha == 1) or (alpha == 3):
            B = np.mean(np.reshape(prism.by(xg, yg, zg, model), (x.size, ns*ns)), axis=1)
            if grains is not None:
                B += np.mean(np.reshape(sphere.by(xg, yg, zg, grains), (x.size, ns*ns)), axis=1)
        
    else:
        if (alpha == 0) or (alpha == 2):
            B = prism.bz(x, y, z, model)
            if grains is not None:
                B += sphere.bz(x, y, z, grains)
        if (alpha == 1) or (alpha == 3):
            B = prism.by(x, y, z, model)
            if grains is not None:
                B += sphere.by(x, y, z, grains)

    return B
                  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)],
]

# Make maps of all fields calculated
fig = plt.figure(figsize=(7, 6))
plt.rcParams['font.size'] = 10
X, Y = x.reshape(shape)/1000, y.reshape(shape)/1000
for i, tmp in enumerate(fields):
    ax = plt.subplot(2, 2, i + 1)
    field, data = tmp
    scale = np.abs([data.min(), data.max()]).max()
    ax.set_title(field)
    plot = ax.pcolormesh(Y, X, data.reshape(shape), cmap='RdBu_r',
                         vmin=-scale, vmax=scale)
    plt.colorbar(plot, ax=ax, aspect=30, pad=0)
    ax.set_xlabel('y (km)')