Beispiel #1
0
def fwd_grav_fatiando():
    """
    GravMag: 3D imaging using the migration method on synthetic gravity data
    (more complex model + noisy data)
    """

    # Make some synthetic gravity data from a simple prism model
    za = 5000
    zb = 7000
    model = [mesher.Prism(-4000, 0, -4000, -2000, za, zb,
                          {'density': 1200})]  #,
    #         mesher.Prism(-1000, 1000, -1000, 1000, 1000, 7000, {'density': -800}),
    #         mesher.Prism(2000, 4000, 3000, 4000, 0, 2000, {'density': 600})]
    # Calculate on a scatter of points to show that migration doesn't need gridded
    # data
    # xp, yp, zp = gridder.scatter((-6000, 6000, -6000, 6000), 1000, z=0)
    shape = (25, 25)
    xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=0)

    #gz = utils.contaminate(prism.gz(xp, yp, zp, model), 0.1)
    gz = prism.gz(xp, yp, zp, model)

    # Plot the data
    shape = (50, 50)
    mpl.figure()
    mpl.axis('scaled')
    mpl.contourf(yp, xp, gz, shape, 30, interp=True)
    mpl.colorbar()
    mpl.plot(yp, xp, '.k')
    mpl.xlabel('East (km)')
    mpl.ylabel('North (km)')
    mpl.m2km()
    mpl.show()

    return xp, yp, zp, gz, shape, model
Beispiel #2
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()
area = bounds[:4]
axis = mpl.figure().gca()
mpl.axis('scaled')
model = [
    mesher.PolygonalPrism(
        mpl.draw_polygon(area, axis, xy2ne=True),
        # Use only induced magnetization
        0, 2000, {'magnetization':2})]
# Calculate the effect
shape = (100, 100)
xp, yp, zp = gridder.regular(area, shape, z=-500)
tf = polyprism.tf(xp, yp, zp, model, inc, dec)
# and plot it
mpl.figure()
mpl.axis('scaled')
mpl.title("Total field anomalyproduced by prism model (nT)")
mpl.contourf(yp, xp, tf, shape, 20)
mpl.colorbar()
for p in model:
    mpl.polygon(p, '.-k', xy2ne=True)
mpl.set_area(area)
mpl.m2km()
mpl.show()
# Show the prisms
myv.figure()
myv.polyprisms(model, 'magnetization')
myv.axes(myv.outline(bounds), ranges=[i*0.001 for i in bounds])
myv.wall_north(bounds)
myv.wall_bottom(bounds)
myv.show()
Beispiel #4
0
# Calculate and print the standard deviation of the residuals
# Should be close to the data error if the inversion was able to fit the data
residuals = tomo.residuals()
print "Assumed error: %g" % (error)
print "Standard deviation of residuals: %g" % (np.std(residuals))

mpl.figure(figsize=(14, 5))
mpl.subplot(1, 2, 1)
mpl.axis('scaled')
mpl.title('Vp model')
mpl.squaremesh(model, prop='vp', cmap=mpl.cm.seismic)
cb = mpl.colorbar()
cb.set_label('Velocity')
mpl.points(src_loc, '*y', label="Sources")
mpl.points(rec_loc, '^r', label="Receivers")
mpl.legend(loc='lower left', shadow=True, numpoints=1, prop={'size': 10})
mpl.m2km()
mpl.subplot(1, 2, 2)
mpl.axis('scaled')
mpl.title('Tomography result')
mpl.squaremesh(mesh, prop='vp', vmin=4000, vmax=10000, cmap=mpl.cm.seismic)
cb = mpl.colorbar()
cb.set_label('Velocity')
mpl.m2km()
mpl.figure()
mpl.grid()
mpl.title('Residuals (data with %.4f s error)' % (error))
mpl.hist(residuals, color='gray', bins=10)
mpl.xlabel("seconds")
mpl.show()
Beispiel #5
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()
Beispiel #6
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()
Beispiel #7
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()