Example #1
0
def Plot_Onemap(x, y, data, shape, prism_projection, projection_style,
                line_width, model, figure_title, label_x, label_y, label_size,
                observations, point_style, point_size, unit):

    levels = mpl.contourf(y, x, data, shape, 20, interp=True)
    cbar = plt.colorbar()
    mpl.contour(y, x, data, shape, levels, clabel=False, interp=True)

    if observations is True:
        plt.plot(y, x, point_style, markersize=point_size)

    if unit is not None:
        cbar.set_label(unit, fontsize=label_size)

    ax = plt.gca()
    if prism_projection is True:
        for i, sq in enumerate(model):
            y1, y2, x1, x2 = sq
            xs_project = [x1, x1, x2, x2, x1]
            ys_project = [y1, y2, y2, y1, y1]
            ax.plot(xs_project,
                    ys_project,
                    projection_style,
                    linewidth=line_width)

    if label_x is not None:
        ax.set_xlabel(label_x, fontsize=label_size)

    if label_y is not None:
        ax.set_ylabel(label_y, fontsize=label_size)

    if figure_title is not None:
        ax.set_title(figure_title, fontsize=label_size)

    mpl.m2km()
          utils.contaminate(gravmag.prism.gxy(xp, yp, zp, prisms), noise),
          utils.contaminate(gravmag.prism.gxz(xp, yp, zp, prisms), noise),
          utils.contaminate(gravmag.prism.gyy(xp, yp, zp, prisms), noise),
          utils.contaminate(gravmag.prism.gyz(xp, yp, zp, prisms), noise),
          utils.contaminate(gravmag.prism.gzz(xp, yp, zp, prisms), noise)]
# Get the eigenvectors from the tensor data
eigenvals, eigenvecs = gravmag.tensor.eigen(tensor)
# Plot the data
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
mpl.figure()
for i, title in enumerate(titles):
    mpl.subplot(3, 2, i + 1)
    mpl.title(title)
    mpl.axis('scaled')
    levels = mpl.contourf(yp, xp, tensor[i], shape, 10)
    mpl.contour(yp, xp, tensor[i], shape, levels)
    mpl.m2km()
mpl.show()

# Pick the centers of the expanding windows
# The number of final solutions will be the number of points picked
mpl.figure()
mpl.suptitle('Pick the centers of the expanding windows')
mpl.axis('scaled')
mpl.contourf(yp, xp, tensor[-1], shape, 50)
mpl.colorbar()
centers = mpl.pick_points(area, mpl.gca(), xy2ne=True)
cms = []
for center in centers:
    # Use the first eigenvector to estimate the center of mass
    cm, sigma = gravmag.tensor.center_of_mass(xp, yp, zp, eigenvecs[0],
"""
GravMag: Generate noise-corrupted gravity gradient tensor data
"""
from fatiando import mesher, gridder, gravmag, utils
from fatiando.vis import mpl

prisms = [mesher.Prism(-1000,1000,-1000,1000,0,2000,{'density':1000})]
shape = (100,100)
xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-200)
components = [gravmag.prism.gxx, gravmag.prism.gxy, gravmag.prism.gxz,
              gravmag.prism.gyy, gravmag.prism.gyz, gravmag.prism.gzz]
print "Calculate the tensor components and contaminate with 5 Eotvos noise"
ftg = [utils.contaminate(comp(xp, yp, zp, prisms), 5.0) for comp in components]

print "Plotting..."
mpl.figure(figsize=(14,6))
mpl.suptitle("Contaminated FTG data")
names = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
for i, data in enumerate(ftg):
    mpl.subplot(2,3,i+1)
    mpl.title(names[i])
    mpl.axis('scaled')
    levels = mpl.contourf(xp*0.001, yp*0.001, data, (100,100), 12)
    mpl.colorbar()
    mpl.contour(xp*0.001, yp*0.001, data, shape, levels, clabel=False)
mpl.show()
mpl.figure()
mpl.suptitle('L-curve')
mpl.title("Estimated regularization parameter: %g" % (solver.regul_param_))
solver.plot_lcurve()
mpl.grid()

mpl.figure(figsize=(14, 4))
mpl.subplot(1, 3, 1)
mpl.axis('scaled')
mpl.title('Layer (kg.m^-3)')
mpl.pcolor(layer.y, layer.x, layer.props['density'], layer.shape)
mpl.colorbar()
mpl.m2km()
mpl.subplot(1, 3, 2)
mpl.axis('scaled')
mpl.title('Fit (mGal)')
levels = mpl.contour(y, x, gz, shape, 15, color='r')
mpl.contour(y, x, solver.predicted(), shape, levels, color='k')
mpl.m2km()
mpl.subplot(1, 3, 3)
mpl.title('Residuals (mGal)')
mpl.hist(residuals, bins=10)

mpl.figure()
mpl.axis('scaled')
mpl.title('True (red) | Layer (black)')
levels = mpl.contour(y, x, gz_true, shape, 12, color='r')
mpl.contour(y, x, gz_up, shape, levels, color='k')
mpl.m2km()
mpl.show()
# Insert the estimated density values into the mesh
mesh.addprop('density', estimate['density'])
# and get only the prisms corresponding to our estimate
density_model = vremove(0, 'density', mesh)
print "Accretions: %d" % (len(density_model) - len(seeds))

# Get the predicted data from the data modules
tensor = (gyy, gyz, gzz)
# plot it
for true, pred in zip(tensor, predicted):
    mpl.figure()
    mpl.title("True: color | Inversion: contour")
    mpl.axis('scaled')
    levels = mpl.contourf(y*0.001, x*0.001, true, shape, 12)
    mpl.colorbar()
    mpl.contour(y*0.001, x*0.001, pred, shape, levels, color='k')
    mpl.xlabel('Horizontal coordinate y (km)')
    mpl.ylabel('Horizontal coordinate x (km)')
mpl.show()

# Plot the inversion result
myv.figure()
myv.prisms(model, 'density', style='wireframe')
myv.prisms(density_model, 'density', vmin=0)
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()
Example #6
0
# Insert the estimated density values into the mesh
mesh.addprop('density', estimate['density'])
# and get only the prisms corresponding to our estimate
density_model = vremove(0, 'density', mesh)
print "Accretions: %d" % (len(density_model) - len(seeds))

# Get the predicted data from the data modules
tensor = (gyy, gyz, gzz)
# plot it
for true, pred in zip(tensor, predicted):
    mpl.figure()
    mpl.title("True: color | Inversion: contour")
    mpl.axis('scaled')
    levels = mpl.contourf(y * 0.001, x * 0.001, true, shape, 12)
    mpl.colorbar()
    mpl.contour(y * 0.001, x * 0.001, pred, shape, levels, color='k')
    mpl.xlabel('Horizontal coordinate y (km)')
    mpl.ylabel('Horizontal coordinate x (km)')
mpl.show()

# Plot the inversion result
myv.figure()
myv.prisms(model, 'density', style='wireframe')
myv.prisms(density_model, 'density', vmin=0)
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()
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_:
    print e

# Plot the fit and the normalized histogram of the residuals
mpl.figure(figsize=(14, 5))
mpl.subplot(1, 2, 1)
mpl.title("Total Field Anomaly (nT)", fontsize=14)
mpl.axis('scaled')
nlevels = mpl.contour(y,
                      x,
                      tf, (50, 50),
                      15,
                      interp=True,
                      color='r',
                      label='Observed',
                      linewidth=2.0)
mpl.contour(y,
            x,
            solver.predicted(), (50, 50),
            nlevels,
            interp=True,
            color='b',
            label='Predicted',
            style='dashed',
            linewidth=2.0)
mpl.legend(loc='upper left', shadow=True, prop={'size': 13})
mpl.xlabel('East y (m)', fontsize=14)
mpl.ylabel('North x (m)', fontsize=14)
# Run the inversioin
estimate, predicted = gm.harvester.harvest(data, seeds, mesh,
    compactness=0.5, threshold=0.001)
# Put the estimated density values in the mesh
mesh.addprop('density', estimate['density'])

# Plot the adjustment
mpl.figure()
mpl.suptitle("True: color | Inversion: contour")
for i in xrange(len(tensor)):
    mpl.subplot(2, 3, i + 1)
    mpl.title(titles[i])
    mpl.axis('scaled')
    levels = mpl.contourf(yp, xp, tensor[i], shape, 12)
    mpl.colorbar()
    mpl.contour(yp, xp, predicted[i], shape, levels, color='k')
    mpl.xlabel('y (km)')
    mpl.ylabel('x (km)')
    mpl.m2km()
mpl.figure()
mpl.suptitle("Residuals")
for i in xrange(len(tensor)):
    residuals = tensor[i] - predicted[i]
    mpl.subplot(2, 3, i + 1)
    mpl.title(titles[i] + ': stddev=%g' % (residuals.std()))
    mpl.hist(residuals, bins=10, color='gray')
    mpl.xlabel('Residuals (Eotvos)')
mpl.show()
# Plot the result
myv.figure()
myv.prisms(model, 'density', style='wireframe')
Example #9
0
def Plot_Onemap_Histog(x, y, data, shape, prism_projection, projection_style,
                       line_width, model, figure_title1, figure_title2,
                       label_x, label_y, label_size, observations, point_style,
                       point_size, unit):

    ax1 = plt.subplot(1, 2, 1)
    ax1.text(0.01,
             1.10,
             figure_title1,
             horizontalalignment='left',
             verticalalignment='top',
             fontsize=label_size,
             transform=ax1.transAxes)

    levels = mpl.contourf(y, x, data, shape, 20, interp=True)
    cbar = plt.colorbar()
    mpl.contour(y, x, data, shape, levels, clabel=False, interp=True)

    if observations is True:
        plt.plot(y, x, point_style, markersize=point_size)

    if unit is not None:
        cbar.set_label(unit, fontsize=label_size)

    ax1 = plt.gca()
    if prism_projection is True:
        for i, sq in enumerate(model):
            y1, y2, x1, x2 = sq
            xs_project = [x1, x1, x2, x2, x1]
            ys_project = [y1, y2, y2, y1, y1]
            ax1.plot(xs_project,
                     ys_project,
                     projection_style,
                     linewidth=line_width)

    if label_x is not None:
        ax1.set_xlabel(label_x, fontsize=label_size)

    if label_y is not None:
        ax1.set_ylabel(label_y, fontsize=label_size)

    mpl.m2km()

    ax2 = plt.subplot(1, 2, 2)
    ax2.text(0.01,
             1.10,
             figure_title2,
             horizontalalignment='left',
             verticalalignment='top',
             fontsize=label_size,
             transform=ax2.transAxes)

    (mu, sigma) = norm.fit(data)
    # the histogram of the difference between the true and the estimated RTP
    n_h, bins, patches = plt.hist(data,
                                  120,
                                  normed=1,
                                  facecolor='blue',
                                  alpha=0.75)
    # add a 'best fit' line
    y_histogram = mlab.normpdf(bins, mu, sigma)
    l_histogram = plt.plot(bins, y_histogram, 'r--', linewidth=2)
    if label_x is not None:
        ax2.set_xlabel('Residual', fontsize=label_size)

    if label_y is not None:
        ax2.set_ylabel('Probability', fontsize=label_size)

    if figure_title2 is not None:
        ax2.set_title(r'$ \mu=%.3f,\ \sigma=%.3f$' % (mu, sigma),
                      fontsize=label_size)

    plt.grid(True)

    mpl.m2km()
Example #10
0
def Plot_FTG(x, y, data_xx, data_xy, data_xz, data_yy, data_yz, data_zz, shape,
             prism_projection, projection_style, line_width, model, label_x,
             label_y, label_size, unit):

    #   $G_{xx}$
    ax1 = plt.subplot(3, 3, 1)
    ax1.text(0,
             1.10,
             '(a) $G_{xx}$',
             horizontalalignment='left',
             verticalalignment='top',
             transform=ax1.transAxes)

    levels = mpl.contourf(y, x, data_xx, shape, 12, interp=True, cmap='Greys')
    cbar = plt.colorbar()
    mpl.contour(y, x, data_xx, shape, levels, clabel=False, interp=True)
    cbar.set_label(unit)

    if prism_projection is True:
        for i, sq in enumerate(model):
            y1, y2, x1, x2 = sq
            xs_project = [x1, x1, x2, x2, x1]
            ys_project = [y1, y2, y2, y1, y1]
            ax1.plot(xs_project,
                     ys_project,
                     projection_style,
                     linewidth=line_width)

    if label_x is not None:
        ax1.set_xlabel(label_x, fontsize=label_size)

    if label_y is not None:
        ax1.set_ylabel(label_y, fontsize=label_size)

    mpl.m2km()

    #   $G_{xy}$

    ax2 = plt.subplot(3, 3, 2)
    ax2.text(0,
             1.10,
             '(b) $G_{xy}$',
             horizontalalignment='left',
             verticalalignment='top',
             transform=ax2.transAxes)

    levels = mpl.contourf(y, x, data_xy, shape, 12, interp=True, cmap='Greys')
    cbar = plt.colorbar()
    mpl.contour(y, x, data_xy, shape, levels, clabel=False, interp=True)
    cbar.set_label(unit)

    if prism_projection is True:
        for i, sq in enumerate(model):
            y1, y2, x1, x2 = sq
            xs_project = [x1, x1, x2, x2, x1]
            ys_project = [y1, y2, y2, y1, y1]
            ax2.plot(xs_project,
                     ys_project,
                     projection_style,
                     linewidth=line_width)

    mpl.m2km()

    #   $G_{xz}$

    ax3 = plt.subplot(3, 3, 3)
    ax3.text(0,
             1.10,
             '(c) $G_{xz}$',
             horizontalalignment='left',
             verticalalignment='top',
             transform=ax3.transAxes)

    levels = mpl.contourf(y, x, data_xz, shape, 12, interp=True, cmap='Greys')
    cbar = plt.colorbar()
    mpl.contour(y, x, data_xz, shape, levels, clabel=False, interp=True)
    cbar.set_label(unit)

    if prism_projection is True:
        for i, sq in enumerate(model):
            y1, y2, x1, x2 = sq
            xs_project = [x1, x1, x2, x2, x1]
            ys_project = [y1, y2, y2, y1, y1]
            ax3.plot(xs_project,
                     ys_project,
                     projection_style,
                     linewidth=line_width)
    mpl.m2km()

    #   $G_{yy}$
    ax4 = plt.subplot(3, 3, 5)
    ax4.text(0,
             1.10,
             '(d) $G_{yy}$',
             horizontalalignment='left',
             verticalalignment='top',
             transform=ax4.transAxes)

    levels = mpl.contourf(y, x, data_yy, shape, 12, interp=True, cmap='Greys')
    cbar = plt.colorbar()
    mpl.contour(y, x, data_yy, shape, levels, clabel=False, interp=True)
    cbar.set_label(unit)

    if prism_projection is True:
        for i, sq in enumerate(model):
            y1, y2, x1, x2 = sq
            xs_project = [x1, x1, x2, x2, x1]
            ys_project = [y1, y2, y2, y1, y1]
            ax4.plot(xs_project,
                     ys_project,
                     projection_style,
                     linewidth=line_width)

    if label_x is not None:
        ax4.set_xlabel(label_x, fontsize=label_size)

    if label_y is not None:
        ax4.set_ylabel(label_y, fontsize=label_size)

    mpl.m2km()

    #   $G_{yz}$
    ax5 = plt.subplot(3, 3, 6)
    ax5.text(0,
             1.10,
             '(e) $G_{yz}$',
             horizontalalignment='left',
             verticalalignment='top',
             transform=ax5.transAxes)

    levels = mpl.contourf(y, x, data_yz, shape, 12, interp=True, cmap='Greys')
    cbar = plt.colorbar()
    mpl.contour(y, x, data_yz, shape, levels, clabel=False, interp=True)
    cbar.set_label(unit)

    for i, sq in enumerate(model):
        y1, y2, x1, x2 = sq
        xs_project = [x1, x1, x2, x2, x1]
        ys_project = [y1, y2, y2, y1, y1]
        ax5.plot(xs_project, ys_project, projection_style, linewidth=1.0)

    #plt.xlabel('Easting coordinate y(km)')
    #plt.ylabel('Northing coordinate x(km)')
    mpl.m2km()

    #   $G_{zz}$
    ax6 = plt.subplot(3, 3, 9)
    ax6.text(0,
             1.10,
             '(f) $G_{zz}$',
             horizontalalignment='left',
             verticalalignment='top',
             transform=ax6.transAxes)

    levels = mpl.contourf(y, x, data_zz, shape, 12, interp=True, cmap='Greys')
    cbar = plt.colorbar()
    mpl.contour(y, x, data_zz, shape, levels, clabel=False, interp=True)
    cbar.set_label(unit)

    for i, sq in enumerate(model):
        y1, y2, x1, x2 = sq
        xs_project = [x1, x1, x2, x2, x1]
        ys_project = [y1, y2, y2, y1, y1]
        projection_style = '-r'
        ax6.plot(xs_project, ys_project, projection_style, linewidth=1.0)

    if label_x is not None:
        ax6.set_xlabel(label_x, fontsize=label_size)

    if label_y is not None:
        ax6.set_ylabel(label_y, fontsize=label_size)

    mpl.m2km()
Example #11
0
def Plot_Threemaps(x, y, data1, data2, data3, shape, prism_projection,
                   projection_style, line_width, model, figure_title1,
                   figure_title2, figure_title3, label_x, label_y, label_size,
                   observations, point_style, point_size, unit):

    ax1 = plt.subplot(1, 3, 1)
    ax1.text(0.01,
             1.05,
             figure_title1,
             horizontalalignment='left',
             verticalalignment='top',
             fontsize=label_size,
             transform=ax1.transAxes)

    levels = mpl.contourf(y, x, data1, shape, 20, interp=True)
    cbar = plt.colorbar()
    mpl.contour(y, x, data1, shape, levels, clabel=False, interp=True)

    if observations is True:
        plt.plot(y, x, point_style, markersize=point_size)

    if unit is not None:
        cbar.set_label(unit, fontsize=label_size)

    ax1 = plt.gca()
    if prism_projection is True:
        for i, sq in enumerate(model):
            y1, y2, x1, x2 = sq
            xs_project = [x1, x1, x2, x2, x1]
            ys_project = [y1, y2, y2, y1, y1]
            ax1.plot(xs_project,
                     ys_project,
                     projection_style,
                     linewidth=line_width)

    if label_x is not None:
        ax1.set_xlabel(label_x, fontsize=label_size)

    if label_y is not None:
        ax1.set_ylabel(label_y, fontsize=label_size)

    mpl.m2km()

    ax2 = plt.subplot(1, 3, 2)
    ax2.text(0.01,
             1.05,
             figure_title2,
             horizontalalignment='left',
             verticalalignment='top',
             fontsize=label_size,
             transform=ax2.transAxes)

    levels = mpl.contourf(y, x, data2, shape, 20, interp=True)
    cbar = plt.colorbar()
    mpl.contour(y, x, data2, shape, levels, clabel=False, interp=True)

    if observations is True:
        plt.plot(y, x, point_style, markersize=point_size)

    if unit is not None:
        cbar.set_label(unit, fontsize=label_size)

    ax2 = plt.gca()
    if prism_projection is True:
        for i, sq in enumerate(model):
            y1, y2, x1, x2 = sq
            xs_project = [x1, x1, x2, x2, x1]
            ys_project = [y1, y2, y2, y1, y1]
            ax2.plot(xs_project,
                     ys_project,
                     projection_style,
                     linewidth=line_width)

    if label_x is not None:
        ax2.set_xlabel(label_x, fontsize=label_size)

    if label_y is not None:
        ax2.set_ylabel(label_y, fontsize=label_size)

    mpl.m2km()

    ax3 = plt.subplot(1, 3, 3)
    ax3.text(0.01,
             1.05,
             figure_title3,
             horizontalalignment='left',
             verticalalignment='top',
             fontsize=label_size,
             transform=ax3.transAxes)

    levels = mpl.contourf(y, x, data3, shape, 20, interp=True)
    cbar = plt.colorbar()
    mpl.contour(y, x, data3, shape, levels, clabel=False, interp=True)

    if observations is True:
        plt.plot(y, x, point_style, markersize=point_size)

    if unit is not None:
        cbar.set_label(unit, fontsize=label_size)

    ax3 = plt.gca()
    if prism_projection is True:
        for i, sq in enumerate(model):
            y1, y2, x1, x2 = sq
            xs_project = [x1, x1, x2, x2, x1]
            ys_project = [y1, y2, y2, y1, y1]
            ax3.plot(xs_project,
                     ys_project,
                     projection_style,
                     linewidth=line_width)

    if label_x is not None:
        ax3.set_xlabel(label_x, fontsize=label_size)

    if label_y is not None:
        ax3.set_ylabel(label_y, fontsize=label_size)

    mpl.m2km()
Example #12
0
    utils.contaminate(gravmag.prism.gxx(x, y, z, model), noise),
    utils.contaminate(gravmag.prism.gxy(x, y, z, model), noise),
    utils.contaminate(gravmag.prism.gxz(x, y, z, model), noise),
    utils.contaminate(gravmag.prism.gyy(x, y, z, model), noise),
    utils.contaminate(gravmag.prism.gyz(x, y, z, model), noise),
    utils.contaminate(gravmag.prism.gzz(x, y, z, model), noise)
]
with open('data.txt', 'w') as f:
    f.write(logger.header(comment='#'))
    f.write("# Noise corrupted gz and tensor components:\n")
    f.write("#   noise = %g Eotvos\n" % (noise))
    f.write("#   noise = %g mGal\n" % (noisegz))
    f.write("#   coordinates are in meters\n")
    f.write("#   gz in mGal and tensor in Eotvos\n")
    f.write("# x   y   z   height   gz   gxx   gxy   gxz   gyy   gyz   gzz\n")
    numpy.savetxt(f, numpy.transpose(data))
# Show it
mpl.figure(figsize=(10, 9))
names = "z   height   gz   gxx   gxy   gxz   gyy   gyz   gzz".split()
for i, comp in enumerate(data[2:]):
    mpl.subplot(3, 3, i + 1)
    mpl.axis('scaled')
    mpl.title(names[i])
    levels = mpl.contourf(y * 0.001, x * 0.001, comp, shape, 8)
    mpl.contour(y * 0.001, x * 0.001, comp, shape, levels)
    if i == 3:
        mpl.ylabel('North = x (km)')
    if i == 7:
        mpl.xlabel('East = y (km)')
mpl.show()
Example #13
0
          mesher.Prism(-1000,1000,-1000,1000,0,2000,{'density':-800}),
          mesher.Prism(1000,3000,2000,3000,0,1000,{'density':500})]
area = (-5000, 5000, -5000, 5000)
shape = (50, 50)
z0 = -100
xp, yp, zp = gridder.regular(area, shape, z=z0)
gz = utils.contaminate(gravmag.prism.gz(xp, yp, zp, prisms), 0.5)

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

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

mpl.figure(figsize=(14,6))
mpl.subplot(1, 2, 1)
mpl.title("Original")
mpl.axis('scaled')
mpl.contourf(xp, yp, gz, shape, 15)
mpl.contour(xp, yp, gz, shape, 15)
mpl.subplot(1, 2, 2)
mpl.title("Continued + true")
mpl.axis('scaled')
levels = mpl.contour(xp, yp, gzcont, shape, 12, color='b',
    label='Continued', style='dashed')
mpl.contour(xp, yp, gztrue, shape, levels, color='r', label='True',
    style='solid')
mpl.legend()
mpl.show()
                                           mesh,
                                           compactness=0.5,
                                           threshold=0.001)
# Put the estimated density values in the mesh
mesh.addprop('density', estimate['density'])

# Plot the adjustment
mpl.figure()
mpl.suptitle("True: color | Inversion: contour")
for i in xrange(len(tensor)):
    mpl.subplot(2, 3, i + 1)
    mpl.title(titles[i])
    mpl.axis('scaled')
    levels = mpl.contourf(yp, xp, tensor[i], shape, 12)
    mpl.colorbar()
    mpl.contour(yp, xp, predicted[i], shape, levels, color='k')
    mpl.xlabel('y (km)')
    mpl.ylabel('x (km)')
    mpl.m2km()
mpl.figure()
mpl.suptitle("Residuals")
for i in xrange(len(tensor)):
    residuals = tensor[i] - predicted[i]
    mpl.subplot(2, 3, i + 1)
    mpl.title(titles[i] + ': stddev=%g' % (residuals.std()))
    mpl.hist(residuals, bins=10, color='gray')
    mpl.xlabel('Residuals (Eotvos)')
mpl.show()
# Plot the result
myv.figure()
myv.prisms(model, 'density', style='wireframe')
"""
GravMag: Generate synthetic gravity data on an irregular grid
"""
from fatiando import mesher, gridder, gravmag
from fatiando.vis import mpl

prisms = [mesher.Prism(-2000, 2000, -2000, 2000, 0, 2000, {'density': 1000})]
xp, yp, zp = gridder.scatter((-5000, 5000, -5000, 5000), n=100, z=-100)
gz = gravmag.prism.gz(xp, yp, zp, prisms)

shape = (100, 100)
mpl.axis('scaled')
mpl.title("gz produced by prism model on an irregular grid (mGal)")
mpl.plot(xp, yp, '.k', label='Grid points')
levels = mpl.contourf(xp, yp, gz, shape, 12, interp=True)
mpl.contour(xp, yp, gz, shape, levels, interp=True)
mpl.legend(loc='lower right', numpoints=1)
mpl.m2km()
mpl.show()
"""
GravMag: Generate synthetic gravity data on an irregular grid
"""
from fatiando import mesher, gridder, gravmag
from fatiando.vis import mpl

prisms = [mesher.Prism(-2000, 2000, -2000, 2000, 0, 2000, {'density':1000})]
xp, yp, zp = gridder.scatter((-5000, 5000, -5000, 5000), n=100, z=-100)
gz = gravmag.prism.gz(xp, yp, zp, prisms)

shape = (100,100)
mpl.axis('scaled')
mpl.title("gz produced by prism model on an irregular grid (mGal)")
mpl.plot(xp, yp, '.k', label='Grid points')
levels = mpl.contourf(xp, yp, gz, shape, 12, interp=True)
mpl.contour(xp, yp, gz, shape, levels, interp=True)
mpl.legend(loc='lower right', numpoints=1)
mpl.m2km()
mpl.show()
Example #17
0
    utils.contaminate(prism.gxx(xp, yp, zp, model), noise),
    utils.contaminate(prism.gxy(xp, yp, zp, model), noise),
    utils.contaminate(prism.gxz(xp, yp, zp, model), noise),
    utils.contaminate(prism.gyy(xp, yp, zp, model), noise),
    utils.contaminate(prism.gyz(xp, yp, zp, model), noise),
    utils.contaminate(prism.gzz(xp, yp, zp, model), noise)
]
# Plot the data
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
mpl.figure()
for i, title in enumerate(titles):
    mpl.subplot(3, 2, i + 1)
    mpl.title(title)
    mpl.axis('scaled')
    levels = mpl.contourf(yp, xp, data[i], shape, 10)
    mpl.contour(yp, xp, data[i], shape, levels)
    mpl.m2km()
mpl.show()
# Get the eigenvectors from the tensor data
eigenvals, eigenvecs = tensor.eigen(data)
# Use the first eigenvector to estimate the center of mass
cm = tensor.center_of_mass(xp, yp, zp, eigenvecs[0])

# Plot the prism and the estimated center of mass
myv.figure()
myv.points([cm], size=200.)
myv.prisms(model, prop='density', opacity=0.5)
axes = myv.axes(myv.outline(extent=[-5000, 5000, -5000, 5000, 0, 5000]))
myv.wall_bottom(axes.axes.bounds, opacity=0.2)
myv.wall_north(axes.axes.bounds)
myv.show()
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_:
    print e

# Plot the fit and the normalized histogram of the residuals
mpl.figure(figsize=(14, 5))
mpl.subplot(1, 2, 1)
mpl.title("Total Field Anomaly (nT)", fontsize=14)
mpl.axis('scaled')
nlevels = mpl.contour(y, x, tf, (50, 50), 15, interp=True, color='r',
                      label='Observed', linewidth=2.0)
mpl.contour(y, x, solver.predicted(), (50, 50), nlevels, interp=True,
            color='b', label='Predicted', style='dashed', linewidth=2.0)
mpl.legend(loc='upper left', shadow=True, prop={'size': 13})
mpl.xlabel('East y (m)', fontsize=14)
mpl.ylabel('North x (m)', fontsize=14)
mpl.subplot(1, 2, 2)
residuals_mean = numpy.mean(solver.residuals())
residuals_std = numpy.std(solver.residuals())
# Each residual is subtracted from the mean and the resulting
# difference is divided by the standard deviation
s = (solver.residuals() - residuals_mean) / residuals_std
mpl.hist(s, bins=21, range=None, normed=True, weights=None,
         cumulative=False, bottom=None, histtype='bar', align='mid',
         orientation='vertical', rwidth=None, log=False,
         color=None, label=None)
intensity, predicted = gravmag.eqlayer.classic(data, grid, damping=0.02)
grid.addprop('magnetization', intensity)
residuals = tf - predicted[0]
print "Residuals:"
print "mean:", residuals.mean()
print "stddev:", residuals.std()
# Plot the layer and the fit
mpl.figure(figsize=(14,4))
mpl.subplot(1, 3, 1)
mpl.axis('scaled')
mpl.title('Layer (A/m)')
mpl.pcolor(grid.y, grid.x, grid.props['magnetization'], grid.shape)
mpl.subplot(1, 3, 2)
mpl.axis('scaled')
mpl.title('Fit (nT)')
levels = mpl.contour(y, x, tf, shape, 15, color='r')
mpl.contour(y, x, predicted[0], shape, levels, color='k')
mpl.subplot(1, 3, 3)
mpl.title('Residuals (nT)')
mpl.hist(residuals, bins=10)
mpl.show()
# Now I can forward model the layer at the south pole and check against the
# true solution of the prism
tfpole = gravmag.prism.tf(x, y, z, model, -90, 0)
tfreduced = gravmag.sphere.tf(x, y, z, grid, -90, 0)
mpl.figure(figsize=(14,4))
mpl.subplot(1, 2, 1)
mpl.axis('scaled')
mpl.title('True (red) | Reduced (black)')
levels = mpl.contour(y, x, tfpole, shape, 12, color='r')
mpl.contour(y, x, tfreduced, shape, levels, color='k')
seedx, seedy = mpl.pick_points(area, mpl.gca(), xy2ne=True).T
# Set the right density and depth
locations = [[x, y, 1500, {"density": 1000}] for x, y in zip(seedx, seedy)]
mpl.show()
# Make the seed and set the compactness regularizing parameter mu
seeds = harvester.sow(locations, mesh)
# Run the inversion
estimate, predicted = harvester.harvest(data, seeds, mesh, compactness=0.05, threshold=0.0005)
# Put the estimated density values in the mesh
mesh.addprop("density", estimate["density"])
# Plot the adjustment and the result
mpl.figure()
mpl.title("True: color | Predicted: contour")
mpl.axis("scaled")
levels = mpl.contourf(yp, xp, gz, shape, 12)
mpl.colorbar()
mpl.contour(yp, xp, predicted[0], shape, levels, color="k")
mpl.xlabel("Horizontal coordinate y (km)")
mpl.ylabel("Horizontal coordinate x (km)")
mpl.m2km()
mpl.show()
# Plot the result
myv.figure()
myv.polyprisms(model, "density", opacity=0.6, linewidth=5)
myv.prisms(vremove(0, "density", mesh), "density")
myv.prisms(seeds, "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()
mpl.figure()
mpl.title("Original gravity anomaly")
mpl.axis('scaled')
mpl.contourf(xp, yp, gz, shape, 15)
mpl.colorbar(shrink=0.7)
mpl.m2km()

mpl.figure(figsize=(14, 10))
mpl.subplots_adjust(top=0.95, left=0.05, right=0.95)
mpl.subplot(2, 3, 1)
mpl.title("x deriv (contour) + true (color map)")
mpl.axis('scaled')
levels = mpl.contourf(yp, xp, gxz_true, shape, 12)
mpl.colorbar(shrink=0.7)
mpl.contour(yp, xp, gxz, shape, 12, color='k')
mpl.m2km()
mpl.subplot(2, 3, 2)
mpl.title("y deriv (contour) + true (color map)")
mpl.axis('scaled')
levels = mpl.contourf(yp, xp, gyz_true, shape, 12)
mpl.colorbar(shrink=0.7)
mpl.contour(yp, xp, gyz, shape, 12, color='k')
mpl.m2km()
mpl.subplot(2, 3, 3)
mpl.title("z deriv (contour) + true (color map)")
mpl.axis('scaled')
levels = mpl.contourf(yp, xp, gzz_true, shape, 8)
mpl.colorbar(shrink=0.7)
mpl.contour(yp, xp, gzz, shape, levels, color='k')
mpl.m2km()
Example #22
0
solver.plot_lcurve()
mpl.grid()

# Plot the layer and the fit
mpl.figure(figsize=(14, 4))
mpl.suptitle('Observed data (black) | Predicted by layer (red)')
mpl.subplot(1, 3, 1)
mpl.axis('scaled')
mpl.title('Layer (kg.m^-3)')
mpl.pcolor(layer.y, layer.x, layer.props['density'], layer.shape)
mpl.colorbar().set_label(r'Density $kg.m^{-3}$')
mpl.m2km()
mpl.subplot(1, 3, 2)
mpl.axis('scaled')
mpl.title('Fit gz (mGal)')
levels = mpl.contour(y1, x1, gz, shape, 15, color='k', interp=True)
mpl.contour(y1,
            x1,
            solver.predicted()[0],
            shape,
            levels,
            color='r',
            interp=True)
mpl.plot(y1, x1, 'xk', label='Data points')
mpl.legend()
mpl.m2km()
mpl.subplot(1, 3, 3)
mpl.axis('scaled')
mpl.title('Fit gzz (Eotvos)')
levels = mpl.contour(y2, x2, gzz, shape, 10, color='k', interp=True)
mpl.contour(y2,
Example #23
0
from fatiando.vis import mpl

# Generate random points
x, y = gridder.scatter((-2, 2, -2, 2), n=200)
# And calculate a 2D Gaussian on these points
z = utils.gaussian2d(x, y, 1, 1)

# Functions pcolor, contour and contourf take an interp argument
# If it is True, will interpolate the data before plotting using the specified
# grid shape
shape = (100, 100)
mpl.figure()
mpl.subplot(2, 2, 1)
mpl.axis('scaled')
mpl.title("contourf")
mpl.contourf(x, y, z, shape, 50, interp=True)
mpl.subplot(2, 2, 2)
mpl.axis('scaled')
mpl.title("contour")
mpl.contour(x, y, z, shape, 15, interp=True)
mpl.subplot(2, 2, 3)
mpl.axis('scaled')
mpl.title("pcolor")
mpl.pcolor(x, y, z, shape, interp=True)
# You can tell these functions to extrapolate the data to fill in the margins
mpl.subplot(2, 2, 4)
mpl.axis('scaled')
mpl.title("contourf extrapolate")
mpl.contourf(x, y, z, shape, 50, interp=True, extrapolate=True)
mpl.show()
noise = 2
data = [utils.contaminate(prism.gxx(xp, yp, zp, model), noise),
        utils.contaminate(prism.gxy(xp, yp, zp, model), noise),
        utils.contaminate(prism.gxz(xp, yp, zp, model), noise),
        utils.contaminate(prism.gyy(xp, yp, zp, model), noise),
        utils.contaminate(prism.gyz(xp, yp, zp, model), noise),
        utils.contaminate(prism.gzz(xp, yp, zp, model), noise)]
# Plot the data
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
mpl.figure()
for i, title in enumerate(titles):
    mpl.subplot(3, 2, i + 1)
    mpl.title(title)
    mpl.axis('scaled')
    levels = mpl.contourf(yp, xp, data[i], shape, 10)
    mpl.contour(yp, xp, data[i], shape, levels)
    mpl.m2km()
mpl.show()
# Get the eigenvectors from the tensor data
eigenvals, eigenvecs = tensor.eigen(data)
# Use the first eigenvector to estimate the center of mass
cm = tensor.center_of_mass(xp, yp, zp, eigenvecs[0])

# Plot the prism and the estimated center of mass
myv.figure()
myv.points([cm], size=200.)
myv.prisms(model, prop='density', opacity=0.5)
axes = myv.axes(
    myv.outline(extent=[-5000, 5000, -5000, 5000, 0, 5000]))
myv.wall_bottom(axes.axes.bounds, opacity=0.2)
myv.wall_north(axes.axes.bounds)
Example #25
0
"""
Vis: Plot a map using the Robinson map projection and contours
"""
from fatiando import gridder, utils
from fatiando.vis import mpl

# Generate some data to plot
area = (-180, 180, -80, 80)
shape = (100, 100)
lon, lat = gridder.regular(area, shape)
data = utils.gaussian2d(lon, lat, 30, 60, 10, 30, angle=-60)

# Now get a basemap to plot with some projection
bm = mpl.basemap(area, 'robin')

# And now plot everything passing the basemap to the plotting functions
mpl.figure()
mpl.contour(lon, lat, data, shape, 15, basemap=bm)
bm.drawcoastlines()
bm.drawmapboundary(fill_color='aqua')
bm.drawcountries()
bm.fillcontinents(color='coral')
mpl.draw_geolines((-180, 180, -90, 90), 60, 30, bm)
mpl.show()
"""
Vis: Plot a map using the Robinson map projection and contours
"""
from fatiando import gridder, utils
from fatiando.vis import mpl

# Generate some data to plot
area = (-180, 180, -80, 80)
shape = (100, 100)
lon, lat = gridder.regular(area, shape)
data = utils.gaussian2d(lon, lat, 30, 60, 10, 30, angle=-60)

# Now get a basemap to plot with some projection
bm = mpl.basemap(area, 'robin')

# And now plot everything passing the basemap to the plotting functions
mpl.figure()
mpl.contour(lon, lat, data, shape, 15, basemap=bm)
bm.drawcoastlines()
bm.drawmapboundary(fill_color='aqua')
bm.drawcountries()
bm.fillcontinents(color='coral')
mpl.draw_geolines((-180, 180, -90, 90), 60, 30, bm)
mpl.show()

Example #27
0
g, _ = gridder.pad_array(gz, padtype='OddReflectionTaper')
pads.append(g.flatten())

# Get coordinate vectors
N = gridder.pad_coords(xy, gz.shape, nps)

shapepad = g.shape

# Generate new meshgrid and plot results
yp = N[1]
xp = N[0]
titles = ['Original', 'Zero', 'Mean', 'Edge', 'Linear Taper', 'Reflection',
          'Odd Reflection', 'Odd Reflection/Taper']
mpl.figure(figsize=(17, 9))
mpl.suptitle('Padding algorithms for a 2D array')
for ii, p in enumerate(pads):
    mpl.subplot(2, 4, ii+2)
    mpl.axis('scaled')
    mpl.title(titles[ii+1])
    levels = mpl.contourf(yp*0.001, xp*0.001, p, shapepad, 15)
    cb = mpl.colorbar()
    mpl.contour(yp*0.001, xp*0.001, p, shapepad, levels, clabel=False,
                linewidth=0.1)
mpl.subplot(2, 4, 1)
mpl.axis('scaled')
mpl.title(titles[0])
levels = mpl.contourf(y*0.001, x*0.001, gz, shape, 15)
cb = mpl.colorbar()
mpl.contour(y*0.001, x*0.001, gz, shape, levels, clabel=False, linewidth=0.1)
mpl.show()
# Run the inversion without using weights
data = [gravmag.harvester.Gz(x, y, z, gz)]
estimate, predicted = gravmag.harvester.harvest(data,
                                                seeds,
                                                mesh,
                                                compactness=1.5,
                                                threshold=0.001)
mesh.addprop('density', estimate['density'])
bodies = mesher.vremove(0, 'density', mesh)
mpl.figure()
mpl.axis('scaled')
mpl.title('No weights: Observed (color) vs Predicted (black)')
levels = mpl.contourf(y, x, gz, shape, 17)
mpl.colorbar()
mpl.contour(y, x, predicted[0], shape, levels, color='k')
mpl.m2km()
mpl.xlabel('East (km)')
mpl.ylabel('North (km)')
myv.figure()
plot = myv.prisms(model, 'density', style='wireframe', linewidth=4)
plot.actor.mapper.scalar_visibility = False
myv.prisms(bodies, 'density')
myv.axes(myv.outline(bounds))
myv.wall_north(bounds)
myv.wall_bottom(bounds)
myv.title('No weights')

# Run the inversion again with weights
weights = gravmag.harvester.weights(x, y, seeds, [2000], decay=6)
data = [gravmag.harvester.Gz(x, y, z, gz, weights=weights)]
gz = utils.contaminate(gravmag.prism.gz(x, y, z, model), 0.1)
mesh = mesher.PrismMesh(bounds, (20, 40, 40))
seeds = gravmag.harvester.sow([[5000, 5000, 1000, props]], mesh)

# Run the inversion without using weights
data = [gravmag.harvester.Gz(x, y, z, gz)]
estimate, predicted = gravmag.harvester.harvest(data, seeds, mesh,
    compactness=1.5, threshold=0.001)
mesh.addprop('density', estimate['density'])
bodies = mesher.vremove(0, 'density', mesh)
mpl.figure()
mpl.axis('scaled')
mpl.title('No weights: Observed (color) vs Predicted (black)')
levels = mpl.contourf(y, x, gz, shape, 17)
mpl.colorbar()
mpl.contour(y, x, predicted[0], shape, levels, color='k')
mpl.m2km()
mpl.xlabel('East (km)')
mpl.ylabel('North (km)')
myv.figure()
plot = myv.prisms(model, 'density', style='wireframe', linewidth=4)
plot.actor.mapper.scalar_visibility = False
myv.prisms(bodies, 'density')
myv.axes(myv.outline(bounds))
myv.wall_north(bounds)
myv.wall_bottom(bounds)
myv.title('No weights')

# Run the inversion again with weights
weights = gravmag.harvester.weights(x, y, seeds, [2000], decay=6)
data = [gravmag.harvester.Gz(x, y, z, gz, weights=weights)]
Example #30
0
mpl.figure()
mpl.suptitle('L-curve')
mpl.title("Estimated regularization parameter: %g" % (solver.regul_param_))
solver.plot_lcurve()
mpl.grid()

mpl.figure(figsize=(14, 4))
mpl.subplot(1, 3, 1)
mpl.axis('scaled')
mpl.title('Layer (A/m)')
mpl.pcolor(layer.y, layer.x, layer.props['magnetization'], layer.shape)
mpl.colorbar()
mpl.m2km()
mpl.subplot(1, 3, 2)
mpl.axis('scaled')
mpl.title('Fit (nT)')
levels = mpl.contour(y, x, tf, shape, 15, color='r')
mpl.contour(y, x, solver.predicted(), shape, levels, color='k')
mpl.m2km()
mpl.subplot(1, 3, 3)
mpl.title('Residuals (nT)')
mpl.hist(residuals, bins=10)

mpl.figure()
mpl.axis('scaled')
mpl.title('True (red) | Reduced (black)')
levels = mpl.contour(y, x, tfpole, shape, 12, color='r')
mpl.contour(y, x, tfreduced, shape, levels, color='k')
mpl.m2km()
mpl.show()
Example #31
0
solver.plot_lcurve()
mpl.grid()

# Plot the layer and the fit
mpl.figure(figsize=(14, 4))
mpl.suptitle('Observed data (black) | Predicted by layer (red)')
mpl.subplot(1, 3, 1)
mpl.axis('scaled')
mpl.title('Layer (kg.m^-3)')
mpl.pcolor(layer.y, layer.x, layer.props['density'], layer.shape)
mpl.colorbar().set_label(r'Density $kg.m^{-3}$')
mpl.m2km()
mpl.subplot(1, 3, 2)
mpl.axis('scaled')
mpl.title('Fit gz (mGal)')
levels = mpl.contour(y1, x1, gz, shape, 15, color='k', interp=True)
mpl.contour(y1, x1, solver.predicted()[0], shape, levels, color='r',
            interp=True)
mpl.plot(y1, x1, 'xk', label='Data points')
mpl.legend()
mpl.m2km()
mpl.subplot(1, 3, 3)
mpl.axis('scaled')
mpl.title('Fit gzz (Eotvos)')
levels = mpl.contour(y2, x2, gzz, shape, 10, color='k', interp=True)
mpl.contour(y2, x2, solver.predicted()[1], shape, levels, color='r',
            interp=True)
mpl.plot(y2, x2, 'xk', label='Data points')
mpl.legend()
mpl.m2km()
    utils.contaminate(gravmag.prism.gz(x, y, z, model), noisegz),
    utils.contaminate(gravmag.prism.gxx(x, y, z, model), noise),
    utils.contaminate(gravmag.prism.gxy(x, y, z, model), noise),
    utils.contaminate(gravmag.prism.gxz(x, y, z, model), noise),
    utils.contaminate(gravmag.prism.gyy(x, y, z, model), noise),
    utils.contaminate(gravmag.prism.gyz(x, y, z, model), noise),
    utils.contaminate(gravmag.prism.gzz(x, y, z, model), noise)]
with open('data.txt', 'w') as f:
    f.write(logger.header(comment='#'))
    f.write("# Noise corrupted gz and tensor components:\n")
    f.write("#   noise = %g Eotvos\n" % (noise))
    f.write("#   noise = %g mGal\n" % (noisegz))
    f.write("#   coordinates are in meters\n")
    f.write("#   gz in mGal and tensor in Eotvos\n")
    f.write("# x   y   z   height   gz   gxx   gxy   gxz   gyy   gyz   gzz\n")
    numpy.savetxt(f, numpy.transpose(data))
# Show it
mpl.figure(figsize=(10, 9))
names = "z   height   gz   gxx   gxy   gxz   gyy   gyz   gzz".split()
for i, comp in enumerate(data[2:]):
    mpl.subplot(3, 3, i + 1)
    mpl.axis('scaled')
    mpl.title(names[i])
    levels = mpl.contourf(y*0.001, x*0.001, comp, shape, 8)
    mpl.contour(y*0.001, x*0.001, comp, shape, levels)
    if i == 3:
        mpl.ylabel('North = x (km)')
    if i == 7:
        mpl.xlabel('East = y (km)')
mpl.show()
Example #33
0
shape = (100, 100)
lon, lat = gridder.regular(area, shape)
data = utils.gaussian2d(lon, lat, 10, 20, -20, -20, angle=-45)

mpl.figure()

# Filled contour plot
mpl.subplot(221)
mpl.title('Filled contours')
mpl.contourf(lon, lat, data, shape, 50)
mpl.colorbar()

# Contour plot
mpl.subplot(222)
mpl.title('Line contours')
mpl.contour(lon, lat, data, shape, 10, color='r', style='dashed')

# Mix contour and contourf
# contour and contourf return a list of the contour values
mpl.subplot(223)
mpl.title('Filled contours + line contours')
levels = mpl.contourf(lon, lat, data, shape, 10)
mpl.colorbar()
# using "levels" tells contour to use the exact same values as contourf
mpl.contour(lon, lat, data, shape, levels)

# Limiting the scale of the data
mpl.subplot(224)
mpl.title('Using vmin and vmax')
mpl.contourf(lon, lat, data, shape, 50, vmin=0.5, vmax=0.8)
mpl.colorbar()
# Now I can forward model the layer at a greater height and check against the
# true solution of the prism
gz_true = prism.gz(x, y, z - 500, model)
gz_up = sphere.gz(x, y, z - 500, layer)

mpl.figure(figsize=(14, 4))
mpl.subplot(1, 3, 1)
mpl.axis('scaled')
mpl.title('Layer (kg.m^-3)')
mpl.pcolor(layer.y, layer.x, layer.props['density'], layer.shape)
mpl.colorbar()
mpl.m2km()
mpl.subplot(1, 3, 2)
mpl.axis('scaled')
mpl.title('Fit (mGal)')
levels = mpl.contour(y, x, gz, shape, 15, color='r')
mpl.contour(y, x, solver[0].predicted(), shape, levels, color='k')
mpl.m2km()
mpl.subplot(1, 3, 3)
mpl.title('Residuals (mGal)')
mpl.hist(residuals, bins=10)

mpl.figure()
mpl.axis('scaled')
mpl.title('True (red) | Layer (black)')
levels = mpl.contour(y, x, gz_true, shape, 12, color='r')
mpl.contour(y, x, gz_up, shape, levels, color='k')
mpl.m2km()
mpl.show()
         mesher.Prism(-1000,1000,-1000,1000,0,2000,{'density':-800}),
         mesher.Prism(1000,3000,2000,3000,0,1000,{'density':500})]
area = (-5000, 5000, -5000, 5000)
shape = (50, 50)
z0 = -100
xp, yp, zp = gridder.regular(area, shape, z=z0)
gz = utils.contaminate(prism.gz(xp, yp, zp, model), 0.5)

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

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

mpl.figure(figsize=(14,6))
mpl.subplot(1, 2, 1)
mpl.title("Original")
mpl.axis('scaled')
mpl.contourf(xp, yp, gz, shape, 15)
mpl.contour(xp, yp, gz, shape, 15)
mpl.subplot(1, 2, 2)
mpl.title("Continued + true")
mpl.axis('scaled')
levels = mpl.contour(xp, yp, gzcont, shape, 12, color='b',
    label='Continued', style='dashed')
mpl.contour(xp, yp, gztrue, shape, levels, color='r', label='True',
    style='solid')
mpl.legend()
mpl.show()
    utils.contaminate(gravmag.prism.gxx(xp, yp, zp, prisms), noise),
    utils.contaminate(gravmag.prism.gxy(xp, yp, zp, prisms), noise),
    utils.contaminate(gravmag.prism.gxz(xp, yp, zp, prisms), noise),
    utils.contaminate(gravmag.prism.gyy(xp, yp, zp, prisms), noise),
    utils.contaminate(gravmag.prism.gyz(xp, yp, zp, prisms), noise),
    utils.contaminate(gravmag.prism.gzz(xp, yp, zp, prisms), noise)
]
# Plot the data
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
mpl.figure()
for i, title in enumerate(titles):
    mpl.subplot(3, 2, i + 1)
    mpl.title(title)
    mpl.axis('scaled')
    levels = mpl.contourf(yp, xp, tensor[i], shape, 10)
    mpl.contour(yp, xp, tensor[i], shape, levels)
    mpl.m2km()
mpl.show()
# Get the eigenvectors from the tensor data
eigenvals, eigenvecs = gravmag.tensor.eigen(tensor)
# Use the first eigenvector to estimate the center of mass
cm, sigma = gravmag.tensor.center_of_mass(xp, yp, zp, eigenvecs[0])
print "Sigma = %g" % (sigma)
# Plot the prism and the estimated center of mass
myv.figure()
myv.points([cm], size=300.)
myv.prisms(prisms, prop='density', opacity=0.5)
axes = myv.axes(myv.outline(extent=[-5000, 5000, -5000, 5000, 0, 5000]))
myv.wall_bottom(axes.axes.bounds, opacity=0.2)
myv.wall_north(axes.axes.bounds)
myv.show()
Example #37
0
    gravmag.prism.gyz(xp, yp, zp, prisms),
    gravmag.prism.gzz(xp, yp, zp, prisms)
]
titles = [
    'potential', 'gx', 'gy', 'gz', 'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'
]
mpl.figure(figsize=(8, 9))
mpl.subplots_adjust(left=0.03, right=0.95, bottom=0.05, top=0.92, hspace=0.3)
mpl.suptitle("Potential fields produced by a 3 prism model")
for i, field in enumerate(fields):
    mpl.subplot(4, 3, i + 3)
    mpl.axis('scaled')
    mpl.title(titles[i])
    levels = mpl.contourf(yp * 0.001, xp * 0.001, field, shape, 15)
    cb = mpl.colorbar()
    mpl.contour(yp * 0.001,
                xp * 0.001,
                field,
                shape,
                levels,
                clabel=False,
                linewidth=0.1)
mpl.show()

myv.figure()
myv.prisms(prisms, prop='density')
axes = myv.axes(myv.outline())
myv.wall_bottom(axes.axes.bounds, opacity=0.2)
myv.wall_north(axes.axes.bounds)
myv.show()
fields = [prism.potential(xp, yp, zp, model),
          prism.gx(xp, yp, zp, model),
          prism.gy(xp, yp, zp, model),
          prism.gz(xp, yp, zp, model),
          prism.gxx(xp, yp, zp, model),
          prism.gxy(xp, yp, zp, model),
          prism.gxz(xp, yp, zp, model),
          prism.gyy(xp, yp, zp, model),
          prism.gyz(xp, yp, zp, model),
          prism.gzz(xp, yp, zp, model)]
titles = ['potential', 'gx', 'gy', 'gz',
          'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
mpl.figure(figsize=(8, 9))
mpl.subplots_adjust(left=0.03, right=0.95, bottom=0.05, top=0.92, hspace=0.3)
mpl.suptitle("Potential fields produced by a 3 prism model")
for i, field in enumerate(fields):
    mpl.subplot(4, 3, i + 3)
    mpl.axis('scaled')
    mpl.title(titles[i])
    levels = mpl.contourf(yp*0.001, xp*0.001, field, shape, 15)
    cb = mpl.colorbar()
    mpl.contour(yp*0.001, xp*0.001, field, shape, levels, clabel=False, linewidth=0.1)
mpl.show()

myv.figure()
myv.prisms(model, prop='density')
axes = myv.axes(myv.outline())
myv.wall_bottom(axes.axes.bounds, opacity=0.2)
myv.wall_north(axes.axes.bounds)
myv.show()
Example #39
0
"""
GravMag: Generate noise-corrupted gravity gradient tensor data
"""
from fatiando import mesher, gridder, utils
from fatiando.gravmag import prism
from fatiando.vis import mpl

model = [mesher.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'density': 1000})]
shape = (100, 100)
xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-200)
components = [prism.gxx, prism.gxy, prism.gxz, prism.gyy, prism.gyz, prism.gzz]
print "Calculate the tensor components and contaminate with 5 Eotvos noise"
ftg = [utils.contaminate(comp(xp, yp, zp, model), 5.0) for comp in components]

print "Plotting..."
mpl.figure(figsize=(14, 6))
mpl.suptitle("Contaminated FTG data")
names = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
for i, data in enumerate(ftg):
    mpl.subplot(2, 3, i + 1)
    mpl.title(names[i])
    mpl.axis('scaled')
    levels = mpl.contourf(xp * 0.001, yp * 0.001, data, (100, 100), 12)
    mpl.colorbar()
    mpl.contour(xp * 0.001, yp * 0.001, data, shape, levels, clabel=False)
mpl.show()