Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 3
0
data = [
    polyprism.gxx(xp, yp, zp, model),
    polyprism.gxy(xp, yp, zp, model),
    polyprism.gxz(xp, yp, zp, model),
    polyprism.gyy(xp, yp, zp, model),
    polyprism.gyz(xp, yp, zp, model),
    polyprism.gzz(xp, yp, zp, model)
]
# and plot it
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
mpl.figure()
mpl.axis('scaled')
mpl.suptitle("Gravity tensor produced by prism model (Eotvos)")
for i in xrange(len(data)):
    mpl.subplot(3, 2, i + 1)
    mpl.title(titles[i])
    mpl.contourf(yp, xp, data[i], 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, 'density')
myv.axes(myv.outline(bounds), ranges=[i * 0.001 for i in bounds])
myv.wall_north(bounds)
myv.wall_bottom(bounds)
myv.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()
def data(x, y):
    return (utils.gaussian2d(x, y, -0.6, -1)
            - utils.gaussian2d(x, y, 1.5, 1.5))
z = data(x, y)

shape = (100, 100)

# First, we need to know the real data at the grid points
grdx, grdy = gridder.regular(area, shape)
grdz = data(grdx, grdy)
mpl.figure()
mpl.subplot(2, 2, 1)
mpl.axis('scaled')
mpl.title("True grid data")
mpl.plot(x, y, '.k', label='Data points')
mpl.contourf(grdx, grdy, grdz, shape, 50)
mpl.colorbar()
mpl.legend(loc='lower right', numpoints=1)

# Use the default interpolation (cubic)
grdx, grdy, grdz = gridder.interp(x, y, z, shape)
mpl.subplot(2, 2, 2)
mpl.axis('scaled')
mpl.title("Interpolated using cubic minimum-curvature")
mpl.plot(x, y, '.k', label='Data points')
mpl.contourf(grdx, grdy, grdz, shape, 50)
mpl.colorbar()
mpl.legend(loc='lower right', numpoints=1)

# Use the nearest neighbors interpolation
grdx, grdy, grdz = gridder.interp(x, y, z, shape, algorithm='nn')
lons, lats, heights = gridder.regular(area, shape, z=250000)

# Divide the model into nproc slices and calculate them in parallel
log.info('Calculating...')
def calculate(chunk):
    return gravmag.tesseroid.gz(lons, lats, heights, chunk)
def split(model, nproc):
    chunksize = len(model)/nproc
    for i in xrange(nproc - 1):
        yield model[i*chunksize : (i + 1)*chunksize]
    yield model[(nproc - 1)*chunksize : ]    
start = time.time()
nproc = 8
pool = Pool(processes=nproc)
gz = sum(pool.map(calculate, split(model, nproc)))
pool.close()
print "Time it took: %s" % (utils.sec2hms(time.time() - start))

log.info('Plotting...')
mpl.figure(figsize=(10, 4))
mpl.title('Crust gravity signal at 250km height')
bm = mpl.basemap(area, 'robin')
mpl.contourf(lons, lats, gz, shape, 35, basemap=bm)
cb = mpl.colorbar()
cb.set_label('mGal')
bm.drawcoastlines()
bm.drawmapboundary()
bm.drawparallels(range(-90, 90, 45), labels=[0, 1, 0, 0])
bm.drawmeridians(range(-180, 180, 60), labels=[0, 0, 0, 1])
mpl.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()
Ejemplo n.º 8
0
baselevel = 10
# Convert from nanoTesla to Tesla because euler and derivatives require things
# in SI
tf = (utils.nt2si(prism.tf(xp, yp, zp, model, inc, dec)) + baselevel)
# Calculate the derivatives using FFT
xderiv = fourier.derivx(xp, yp, tf, shape)
yderiv = fourier.derivy(xp, yp, tf, shape)
zderiv = fourier.derivz(xp, yp, tf, shape)

mpl.figure()
titles = ['Total field', 'x derivative', 'y derivative', 'z derivative']
for i, f in enumerate([tf, xderiv, yderiv, zderiv]):
    mpl.subplot(2, 2, i + 1)
    mpl.title(titles[i])
    mpl.axis('scaled')
    mpl.contourf(yp, xp, f, shape, 50)
    mpl.colorbar()
    mpl.m2km()
mpl.show()

# Run the Euler deconvolution on the whole dataset
euler = Classic(xp, yp, zp, tf, xderiv, yderiv, zderiv, 3).fit()
print "Base level used: %g" % (baselevel)
print "Estimated:"
print "  Base level:             %g" % (euler.baselevel_)
print "  Source location:        %s" % (str(euler.estimate_))

myv.figure()
myv.points([euler.estimate_], size=100.)
myv.prisms(model, 'magnetization', opacity=0.5)
axes = myv.axes(myv.outline(extent=bounds))
Ejemplo n.º 9
0
log.info(logger.header())

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

# Inversion setup
# Create a mesh
mesh = PrismMesh(bounds, (25, 25, 25))
# Wrap the data so that harvester can use it
data = [gm.harvester.Gz(xp, yp, zp, gz)]
# Make the seed
seeds = gm.harvester.sow([[500, 500, 450, {'density':1000}]], mesh)
# Run the inversioin
estimate, predicted = gm.harvester.harvest(data, seeds, mesh,
"""
Gridding: Load a Surfer ASCII grid file
"""
from fatiando import datasets, gridder
from fatiando.vis import mpl

# Fetching Bouguer anomaly model data (Surfer ASCII grid file)"
# Will download the archive and save it with the default name
archive = datasets.fetch_bouguer_alps_egm()

# Load the GRD file and convert in three numpy-arrays (y, x, bouguer)
y, x, bouguer, shape = gridder.load_surfer(archive, fmt='ascii')

mpl.figure()
mpl.axis('scaled')
mpl.title("Data loaded from a Surfer ASCII grid file")
mpl.contourf(y, x, bouguer, shape, 15)
cb = mpl.colorbar()
cb.set_label('mGal')
mpl.xlabel('y points to East (km)')
mpl.ylabel('x points to North (km)')
mpl.m2km()
mpl.show()
Ejemplo n.º 11
0
        -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 = gravmag.prism.tf(xp, yp, zp, prisms, 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()
mpl.show()
# Show the prisms
myv.figure()
myv.prisms(prisms, 'magnetization')
myv.axes(myv.outline(bounds), ranges=[i * 0.001 for i in bounds])
myv.wall_north(bounds)
myv.wall_bottom(bounds)
myv.show()
Ejemplo n.º 12
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()
Ejemplo n.º 13
0
from fatiando import mesher, gridder, utils, gravmag
from fatiando.vis import mpl

prisms = [mesher.Prism(-100, 100, -100, 100, 0, 2000, {'magnetization': 10})]
area = (-5000, 5000, -5000, 5000)
shape = (100, 100)
z0 = -500
xp, yp, zp = gridder.regular(area, shape, z=z0)
inc, dec = -30, 0
tf = utils.contaminate(gravmag.prism.tf(xp, yp, zp, prisms, inc, dec),
                       0.001,
                       percent=True)

# Need to convert gz to SI units so that the result is also in SI
ansig = gravmag.fourier.ansig(xp, yp, utils.nt2si(tf), shape)

mpl.figure()
mpl.subplot(1, 2, 1)
mpl.title("Original total field anomaly")
mpl.axis('scaled')
mpl.contourf(yp, xp, tf, shape, 30)
mpl.colorbar(orientation='horizontal')
mpl.m2km()
mpl.subplot(1, 2, 2)
mpl.title("Analytic signal")
mpl.axis('scaled')
mpl.contourf(yp, xp, ansig, shape, 30)
mpl.colorbar(orientation='horizontal')
mpl.m2km()
mpl.show()
Ejemplo n.º 14
0
xp, yp, zp = gridder.regular(area, shape, z=z0)
gz = utils.contaminate(prism.gz(xp, yp, zp, model), 0.001)

# Need to convert gz to SI units so that the result can be converted to Eotvos
gxz = utils.si2eotvos(transform.derivx(xp, yp, utils.mgal2si(gz), shape))
gyz = utils.si2eotvos(transform.derivy(xp, yp, utils.mgal2si(gz), shape))
gzz = utils.si2eotvos(transform.derivz(xp, yp, utils.mgal2si(gz), shape))

gxz_true = prism.gxz(xp, yp, zp, model)
gyz_true = prism.gyz(xp, yp, zp, model)
gzz_true = prism.gzz(xp, yp, zp, model)

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')
Ejemplo n.º 15
0
"""
Vis: Plot a map using the Orthographic map projection and filled contours
"""
from fatiando import gridder, utils
from fatiando.vis import mpl

# Generate some data to plot
area = (-40, 0, 10, -50)
shape = (100, 100)
lon, lat = gridder.regular(area, shape)
data = utils.gaussian2d(lon, lat, 10, 20, -20, -20, angle=-45)

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

# And now plot everything passing the basemap to the plotting functions
mpl.figure()
bm.bluemarble()
mpl.contourf(lon, lat, data, shape, 12, basemap=bm)
mpl.colorbar()
mpl.show()
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
"""
from fatiando import mesher, gridder, utils, gravmag
from fatiando.vis import mpl

spheres = [mesher.Sphere(0, 0, 2000, 1000, {'density': 1000})]
# Create a set of points at 100m height
area = (-5000, 5000, -5000, 5000)
xp, yp, zp = gridder.scatter(area, 500, z=-100)
# Calculate the anomaly
gz = utils.contaminate(gravmag.sphere.gz(xp, yp, zp, spheres), 0.1)
gzz = utils.contaminate(gravmag.sphere.gzz(xp, yp, zp, spheres), 5.0)
# Plot
shape = (100, 100)
mpl.figure()
mpl.title("gz (mGal)")
mpl.axis('scaled')
mpl.plot(yp * 0.001, xp * 0.001, '.k')
mpl.contourf(yp * 0.001, xp * 0.001, gz, shape, 15, interp=True)
mpl.colorbar()
mpl.xlabel('East y (km)')
mpl.ylabel('North x (km)')
mpl.figure()
mpl.title("gzz (Eotvos)")
mpl.axis('scaled')
mpl.plot(yp * 0.001, xp * 0.001, '.k')
mpl.contourf(yp * 0.001, xp * 0.001, gzz, shape, 15, interp=True)
mpl.colorbar()
mpl.xlabel('East y (km)')
mpl.ylabel('North x (km)')
mpl.show()
Ejemplo n.º 18
0
            utils.gaussian2d(x, y, 1.5, 1.5))


z = data(x, y)

shape = (100, 100)

# First, we need to know the real data at the grid points
grdx, grdy = gridder.regular(area, shape)
grdz = data(grdx, grdy)
mpl.figure()
mpl.subplot(2, 2, 1)
mpl.axis('scaled')
mpl.title("True grid data")
mpl.plot(x, y, '.k', label='Data points')
mpl.contourf(grdx, grdy, grdz, shape, 50)
mpl.colorbar()
mpl.legend(loc='lower right', numpoints=1)

# Use the default interpolation (cubic)
grdx, grdy, grdz = gridder.interp(x, y, z, shape)
mpl.subplot(2, 2, 2)
mpl.axis('scaled')
mpl.title("Interpolated using cubic minimum-curvature")
mpl.plot(x, y, '.k', label='Data points')
mpl.contourf(grdx, grdy, grdz, shape, 50)
mpl.colorbar()
mpl.legend(loc='lower right', numpoints=1)

# Use the nearest neighbors interpolation
grdx, grdy, grdz = gridder.interp(x, y, z, shape, algorithm='nn')
tensor = [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)]
# 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
Ejemplo n.º 20
0
"""
Gridding: Generate and plot irregular grids (scatter)
"""
from fatiando import gridder, utils
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)

mpl.axis('scaled')
mpl.title("Irregular grid")
mpl.plot(x, y, '.k', label='Grid points')
# Make a filled contour plot and tell the function to automatically interpolate
# the data on a 100x100 grid
mpl.contourf(x, y, z, (100, 100), 50, interp=True)
mpl.colorbar()
mpl.legend(loc='lower right', numpoints=1)
mpl.show()
from fatiando import mesher, gridder, utils
from fatiando.gravmag import prism, fourier
from fatiando.vis import mpl

model = [mesher.Prism(-100,100,-100,100,0,2000,{'magnetization':10})]
area = (-5000, 5000, -5000, 5000)
shape = (100, 100)
z0 = -500
xp, yp, zp = gridder.regular(area, shape, z=z0)
inc, dec = -30, 0
tf = utils.contaminate(prism.tf(xp, yp, zp, model, inc, dec), 0.001,
                       percent=True)

    # Need to convert gz to SI units so that the result is also in SI
ansig = fourier.ansig(xp, yp, utils.nt2si(tf), shape)

mpl.figure()
mpl.subplot(1, 2, 1)
mpl.title("Original total field anomaly")
mpl.axis('scaled')
mpl.contourf(yp, xp, tf, shape, 30)
mpl.colorbar(orientation='horizontal')
mpl.m2km()
mpl.subplot(1, 2, 2)
mpl.title("Analytic signal")
mpl.axis('scaled')
mpl.contourf(yp, xp, ansig, shape, 30)
mpl.colorbar(orientation='horizontal')
mpl.m2km()
mpl.show()
Ejemplo n.º 22
0
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)
x, y, z = gridder.regular(grid.area, shape, z=0)
gz = gravmag.sphere.gz(x, y, z, grid)
tf = gravmag.sphere.tf(x, y, z, grid, inc, dec)
mpl.figure()
mpl.subplot(2, 1, 1)
mpl.axis('scaled')
mpl.title('Gravity anomaly')
mpl.contourf(y, x, gz, shape, 30)
mpl.colorbar()
mpl.subplot(2, 1, 2)
mpl.axis('scaled')
mpl.title('Magnetic total field anomaly')
mpl.contourf(y, x, tf, shape, 30)
mpl.colorbar()
mpl.show()
Ejemplo n.º 23
0
from fatiando import mesher, gridder, utils
from fatiando.gravmag import prism, transform
from fatiando.vis import mpl

model = [mesher.Prism(-100, 100, -100, 100, 0, 2000, {'magnetization': 10})]
area = (-5000, 5000, -5000, 5000)
shape = (100, 100)
z0 = -500
x, y, z = gridder.regular(area, shape, z=z0)
inc, dec = -30, 0
tf = utils.contaminate(prism.tf(x, y, z, model, inc, dec), 0.001,
                       percent=True)

# Need to convert gz to SI units so that the result is also in SI
total_grad_amp = transform.tga(x, y, utils.nt2si(tf), shape)

mpl.figure()
mpl.subplot(1, 2, 1)
mpl.title("Original total field anomaly")
mpl.axis('scaled')
mpl.contourf(y, x, tf, shape, 30, cmap=mpl.cm.RdBu_r)
mpl.colorbar(orientation='horizontal').set_label('nT')
mpl.m2km()
mpl.subplot(1, 2, 2)
mpl.title("Total Gradient Amplitude")
mpl.axis('scaled')
mpl.contourf(y, x, total_grad_amp, shape, 30, cmap=mpl.cm.RdBu_r)
mpl.colorbar(orientation='horizontal').set_label('nT/m')
mpl.m2km()
mpl.show()
Ejemplo n.º 24
0
"""
from fatiando import gridder, utils
from fatiando.vis import mpl

# Generate some data to plot
area = (-40, 0, 10, -50)
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)
Ejemplo n.º 25
0
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')
mpl.m2km()
mpl.sca(axes[1])
mpl.title("True value at pole")
mpl.contourf(y, x, true, shape, 30, cmap=mpl.cm.RdBu_r)
mpl.colorbar(pad=0).set_label('nT')
mpl.m2km()
mpl.sca(axes[2])
mpl.title("Reduced to the pole")
mpl.contourf(y, x, pole, shape, 30, cmap=mpl.cm.RdBu_r)
mpl.colorbar(pad=0).set_label('nT')
mpl.m2km()
mpl.tight_layout()
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()
noise = 0.5
gxx = utils.contaminate(gm.prism.gxx(xp, yp, zp, model), noise)
gxy = utils.contaminate(gm.prism.gxy(xp, yp, zp, model), noise)
gxz = utils.contaminate(gm.prism.gxz(xp, yp, zp, model), noise)
gyy = utils.contaminate(gm.prism.gyy(xp, yp, zp, model), noise)
gyz = utils.contaminate(gm.prism.gyz(xp, yp, zp, model), noise)
gzz = utils.contaminate(gm.prism.gzz(xp, yp, zp, model), noise)
tensor = [gxx, gxy, gxz, gyy, gyz, gzz]
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
# plot the data
mpl.figure()
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, 30)
    mpl.colorbar()
    mpl.xlabel('y (km)')
    mpl.ylabel('x (km)')
    mpl.m2km()
mpl.show()

# Inversion setup
# Create a mesh
mesh = PrismMesh(bounds, (30, 30, 30))
# Wrap the data so that harvester can use it
data = [gm.harvester.Gxx(xp, yp, zp, gxx),
        gm.harvester.Gxy(xp, yp, zp, gxy),
        gm.harvester.Gxz(xp, yp, zp, gxz),
        gm.harvester.Gyy(xp, yp, zp, gyy),
        gm.harvester.Gyz(xp, yp, zp, gyz),
Ejemplo n.º 28
0
shape = (50, 50)
lons, lats, heights = gridder.regular(area, shape, z=250000)

start = time.time()
fields = [
    gravmag.tesseroid.potential(lons, lats, heights, model),
    gravmag.tesseroid.gx(lons, lats, heights, model),
    gravmag.tesseroid.gy(lons, lats, heights, model),
    gravmag.tesseroid.gz(lons, lats, heights, model),
    gravmag.tesseroid.gxx(lons, lats, heights, model),
    gravmag.tesseroid.gxy(lons, lats, heights, model),
    gravmag.tesseroid.gxz(lons, lats, heights, model),
    gravmag.tesseroid.gyy(lons, lats, heights, model),
    gravmag.tesseroid.gyz(lons, lats, heights, model),
    gravmag.tesseroid.gzz(lons, lats, heights, model)
]
print "Time it took: %s" % (utils.sec2hms(time.time() - start))

titles = [
    'potential', 'gx', 'gy', 'gz', 'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'
]
mpl.figure()
bm = mpl.basemap(area, 'ortho')
for i, field in enumerate(fields):
    mpl.subplot(4, 3, i + 3)
    mpl.title(titles[i])
    mpl.contourf(lons, lats, field, shape, 15, basemap=bm)
    bm.drawcoastlines()
    mpl.colorbar()
mpl.show()
Ejemplo n.º 29
0
    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()
mpl.show()
# Show the prisms
myv.figure()
myv.prisms(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()
xp, yp, zp = gridder.regular(dataarea, shape, z=-500)
tensor = [
    gravmag.polyprism.gxx(xp, yp, zp, prisms),
    gravmag.polyprism.gxy(xp, yp, zp, prisms),
    gravmag.polyprism.gxz(xp, yp, zp, prisms),
    gravmag.polyprism.gyy(xp, yp, zp, prisms),
    gravmag.polyprism.gyz(xp, yp, zp, prisms),
    gravmag.polyprism.gzz(xp, yp, zp, prisms)
]
# Calculate the 3 invariants
invariants = gravmag.tensor.invariants(tensor)
data = tensor + invariants
# and plot it
mpl.figure()
mpl.axis('scaled')
mpl.suptitle("Tensor and invariants produced by prism model (Eotvos)")
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz', 'I1', 'I2', 'I']
for i in xrange(len(data)):
    mpl.subplot(3, 3, i + 1)
    mpl.title(titles[i])
    levels = 20
    if i == 8:
        levels = numpy.linspace(0, 1, levels)
    mpl.contourf(yp, xp, data[i], shape, levels)
    mpl.colorbar()
    for p in prisms:
        mpl.polygon(p, '.-k', xy2ne=True)
    mpl.set_area(dataarea)
    mpl.m2km()
mpl.show()
xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-150)
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)
Ejemplo n.º 32
0
    gravmag.prism.gxz(xp, yp, zp, prisms),
    gravmag.prism.gyy(xp, yp, zp, prisms),
    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)
Ejemplo n.º 33
0
# and generate synthetic data from it
shape = (20, 20)
area = bounds[0:4]
xp, yp, zp = gridder.regular(area, shape, z=-1)
noise = 0.1  # 0.1 mGal noise
gz = utils.contaminate(gm.polyprism.gz(xp, yp, zp, model), noise)

# Create a mesh
mesh = PrismMesh(bounds, (25, 50, 50))
# Wrap the data so that harvester can read it
data = [gm.harvester.Gz(xp, yp, zp, gz)]
# Plot the data and pick the location of the seeds
mpl.figure()
mpl.suptitle("Pick the seeds (polygon is the true source)")
mpl.axis('scaled')
levels = mpl.contourf(yp, xp, gz, shape, 12)
mpl.colorbar()
mpl.polygon(model[0], xy2ne=True)
mpl.xlabel('Horizontal coordinate y (km)')
mpl.ylabel('Horizontal coordinate x (km)')
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 = gm.harvester.sow(locations, mesh)
# Run the inversion
estimate, predicted = gm.harvester.harvest(data,
                                           seeds,
                                           mesh,
                                           compactness=0.05,
xp, yp, zp = gridder.regular(area, shape, z=-500)
data = [
    polyprism.gxx(xp, yp, zp, model),
    polyprism.gxy(xp, yp, zp, model),
    polyprism.gxz(xp, yp, zp, model),
    polyprism.gyy(xp, yp, zp, model),
    polyprism.gyz(xp, yp, zp, model),
    polyprism.gzz(xp, yp, zp, model)]
# and plot it
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
mpl.figure()
mpl.axis('scaled')
mpl.suptitle("Gravity tensor produced by prism model (Eotvos)")
for i in xrange(len(data)):
    mpl.subplot(3, 2, i + 1)
    mpl.title(titles[i])
    mpl.contourf(yp, xp, data[i], 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, 'density')
myv.axes(myv.outline(bounds), ranges=[i * 0.001 for i in bounds])
myv.wall_north(bounds)
myv.wall_bottom(bounds)
myv.show()
Ejemplo n.º 35
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()
Ejemplo n.º 36
0
"""
GravMag: Forward modeling of the gravity anomaly using spheres (calculate on
random points)
"""
from fatiando import logger, mesher, gridder, utils, gravmag
from fatiando.vis import mpl

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

spheres = [mesher.Sphere(0, 0, -2000, 1000, {'density':1000})]
# Create a set of points at 100m height
area = (-5000, 5000, -5000, 5000)
xp, yp, zp = gridder.scatter(area, 500, z=-100)
# Calculate the anomaly
gz = utils.contaminate(gravmag.sphere.gz(xp, yp, zp, spheres), 0.1)
# Plot
shape = (100, 100)
mpl.figure()
mpl.title("gz (mGal)")
mpl.axis('scaled')
mpl.plot(yp*0.001, xp*0.001, '.k')
mpl.contourf(yp*0.001, xp*0.001, gz, shape, 15, interp=True)
mpl.colorbar()
mpl.xlabel('East y (km)')
mpl.ylabel('North x (km)')
mpl.show()
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
area = (-80, -30, -40, 10)
shape = (50, 50)
lons, lats, heights = gridder.regular(area, shape, z=250000)

start = time.time()
fields = [
    gravmag.tesseroid.potential(lons, lats, heights, model),
    gravmag.tesseroid.gx(lons, lats, heights, model),
    gravmag.tesseroid.gy(lons, lats, heights, model),
    gravmag.tesseroid.gz(lons, lats, heights, model),
    gravmag.tesseroid.gxx(lons, lats, heights, model),
    gravmag.tesseroid.gxy(lons, lats, heights, model),
    gravmag.tesseroid.gxz(lons, lats, heights, model),
    gravmag.tesseroid.gyy(lons, lats, heights, model),
    gravmag.tesseroid.gyz(lons, lats, heights, model),
    gravmag.tesseroid.gzz(lons, lats, heights, model)]
print "Time it took: %s" % (utils.sec2hms(time.time() - start))

titles = ['potential', 'gx', 'gy', 'gz',
          'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
mpl.figure()
bm = mpl.basemap(area, 'ortho')
for i, field in enumerate(fields):
    mpl.subplot(4, 3, i + 3)
    mpl.title(titles[i])
    mpl.contourf(lons, lats, field, shape, 15, basemap=bm)
    bm.drawcoastlines()
    mpl.colorbar()
mpl.show()

Ejemplo n.º 39
0
"""
Gridding: Load a Surfer ASCII grid file
"""
from fatiando import datasets, gridder
from fatiando.vis import mpl

# Fetching Bouguer anomaly model data (Surfer ASCII grid file)"
# Will download the archive and save it with the default name
archive = datasets.fetch_bouguer_alps_egm()

# Load the GRD file and convert in three numpy-arrays (x, y, bouguer)
x, y, bouguer, shape = gridder.load_surfer(archive, fmt='ascii')

mpl.figure()
mpl.axis('scaled')
mpl.title("Data loaded from a Surfer ASCII grid file")
mpl.contourf(y, x, bouguer, shape, 15, cmap=mpl.cm.RdBu_r)
cb = mpl.colorbar()
cb.set_label('mGal')
mpl.xlabel('y points to East (km)')
mpl.ylabel('x points to North (km)')
mpl.m2km()
mpl.show()
Ejemplo n.º 40
0
from fatiando import mesher, gridder, gravmag
from fatiando.vis import mpl

spheres = [mesher.Sphere(0, 0, 2000, 1000, {'density':1000})]
area = (-5000, 5000, -5000, 5000)
shape = (100, 100)
x, y, z = gridder.regular(area, shape, z=-100)
gz = gravmag.sphere.gz(x, y, z, spheres)
tensor = [gravmag.sphere.gxx(x, y, z, spheres),
          gravmag.sphere.gxy(x, y, z, spheres),
          gravmag.sphere.gxz(x, y, z, spheres),
          gravmag.sphere.gyy(x, y, z, spheres),
          gravmag.sphere.gyz(x, y, z, spheres),
          gravmag.sphere.gzz(x, y, z, spheres)]
mpl.figure()
mpl.axis('scaled')
mpl.title('gz')
mpl.contourf(y, x, gz, shape, 15)
mpl.colorbar()
mpl.m2km()
mpl.figure()
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
for i, field in enumerate(tensor):
    mpl.subplot(2, 3, i + 1)
    mpl.axis('scaled')
    mpl.title(titles[i])
    levels = mpl.contourf(y, x, field, shape, 15)
    mpl.colorbar()
    mpl.m2km()
mpl.show()
Ejemplo n.º 41
0
# Generate random points
x, y = gridder.scatter((-2, 2, -2, 2), n=300, seed=1)
# And calculate 2D Gaussians on these points as sample data
def data(x, y):
    return (utils.gaussian2d(x, y, -0.6, -1)
            - utils.gaussian2d(x, y, 1.5, 1.5))


d = data(x, y)

# Extract a profile along the diagonal
p1, p2 = [-1.5, 0], [1.5, 1.5]
xp, yp, distance, dp = gridder.profile(x, y, d, p1, p2, 100)
dp_true = data(xp, yp)

mpl.figure()
mpl.subplot(2, 1, 2)
mpl.title("Irregular grid")
mpl.plot(xp, yp, '-k', label='Profile', linewidth=2)
mpl.contourf(x, y, d, (100, 100), 50, interp=True)
mpl.colorbar(orientation='horizontal')
mpl.legend(loc='lower right')
mpl.subplot(2, 1, 1)
mpl.title('Profile')
mpl.plot(distance, dp, '.b', label='Extracted')
mpl.plot(distance, dp_true, '-k', label='True')
mpl.xlim(distance.min(), distance.max())
mpl.legend(loc='lower right')
mpl.show()
Ejemplo n.º 42
0
    tesseroid.gy(lons, lats, heights, model),
    tesseroid.gz(lons, lats, heights, model),
    tesseroid.gxx(lons, lats, heights, model),
    tesseroid.gxy(lons, lats, heights, model),
    tesseroid.gxz(lons, lats, heights, model),
    tesseroid.gyy(lons, lats, heights, model),
    tesseroid.gyz(lons, lats, heights, model),
    tesseroid.gzz(lons, lats, heights, model)]
print "Time it took: %s" % (utils.sec2hms(time.time() - start))

titles = ['potential', 'gx', 'gy', 'gz',
          'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
bm = mpl.basemap(area, 'merc')
mpl.figure()
mpl.title(titles[0])
mpl.contourf(lons, lats, fields[0], shape, 40, basemap=bm)
bm.drawcoastlines()
mpl.colorbar()
mpl.figure()
for i, field in enumerate(fields[1:4]):
    mpl.subplot(1, 3, i + 1)
    mpl.title(titles[i + 1])
    mpl.contourf(lons, lats, field, shape, 40, basemap=bm)
    bm.drawcoastlines()
    mpl.colorbar()
mpl.figure()
for i, field in enumerate(fields[4:]):
    mpl.subplot(2, 3, i + 1)
    mpl.title(titles[i + 4])
    mpl.contourf(lons, lats, field, shape, 40, basemap=bm)
    bm.drawcoastlines()
    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()
Ejemplo n.º 44
0
                                        compactness=1., threshold=0.0001)

# 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()
(simple example)
"""
from fatiando import gridder, mesher
from fatiando.gravmag import prism, imaging
from fatiando.vis import mpl, myv

# Make some synthetic gravity data from a simple prism model
model = [mesher.Prism(-1000,1000,-2000,2000,2000,4000,{'density':500})]
shape = (25, 25)
xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-10)
gz = prism.gz(xp, yp, zp, model)

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

mesh = imaging.sandwich(xp, yp, zp, gz, shape, 0, 10000, 25)

# Plot the results
myv.figure()
myv.prisms(model, 'density', style='wireframe', linewidth=2)
myv.prisms(mesh, 'density', edges=False)
axes = myv.axes(myv.outline())
myv.wall_bottom(axes.axes.bounds)
myv.wall_north(axes.axes.bounds)
mpl.points(src, '*y')
initial = mpl.pick_points(area, mpl.gca(), marker='*', color='b')
if len(initial) > 1:
    print "Don't be greedy! Pick only one point"
    sys.exit()
# Fit using many different solvers
levmarq = [e for e in solver.levmarq(initial=initial[0], iterate=True)]
steepest = [e for e in  solver.steepest(initial=initial[0], iterate=True)]
newton = [e for e in  solver.newton(initial=initial[0], iterate=True)]
ACO_R = [e for e in  solver.acor(bounds=area, maxit=100, iterate=True)]
# Make a map of the objective function
shape = (100, 100)
xs, ys = gridder.regular(area, shape)
obj = [solver.value(numpy.array([x, y])) for x, y in zip(xs, ys)]
mpl.figure()
mpl.title('Epicenter + %d recording stations' % (len(recs)))
mpl.axis('scaled')
mpl.contourf(xs, ys, obj, shape, 60)
mpl.points(recs, '^r')
mpl.points(initial, '*w')
mpl.points(levmarq, '.-k', label="Levemeber-Marquardt")
mpl.points(newton, '.-r', label="Newton")
mpl.points(steepest, '.-m', label="Steepest descent")
mpl.points(ACO_R, '.-c', label="Ant Colony")
mpl.points(src, '*y')
mpl.set_area(area)
mpl.legend(loc='lower right', shadow=True, numpoints=1, prop={'size':12})
mpl.xlabel("X")
mpl.ylabel("Y")
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()
Ejemplo n.º 48
0
plt.subplot(2, 1, 2)
plt.title("Original data")
plt.plot(xx, yy, '-k', label='Profile', linewidth=2)
scale = np.abs([gz.min(), gz.max()]).max()
plt.tricontourf(xp, yp, gz, 50, cmap='RdBu_r', vmin=-scale, vmax=scale)
plt.colorbar(orientation='horizontal', aspect=50)
plt.legend(loc='lower right')
plt.tight_layout()
plt.show()
#plt.suptitle(strname + '_ztop' + str(za) +'_zbot'+ str(zb), fontsize=15)
#plt.savefig(pathFig+ strname + '_ExempleFig_prof' + str(za) + str(zb) + '.png')

# ------------------------------- Plot the data
plt.figure()
plt.axis('scaled')
mpl.contourf(yp, xp, gz, shape, 30)
plt.colorbar()
plt.xlabel('East (km)')
plt.ylabel('North (km)')
mpl.m2km()
plt.show()
#plt.title(strname +'ztop' + str(za) +'_zbot'+ str(zb) + '_data', fontsize=20)
#plt.savefig(pathFig+strname + '_ExempleFig_z' + str(za) + str(zb) + '_data' + '.png')

#x1, x2, y1, y2, z1, z2 = np.array(model[0].get_bounds())
square([y1, y2, x1, x2])

# %% ------------------------------- derivatives

xderiv = transform.derivx(xp, yp, gz, shape, order=1)
yderiv = transform.derivy(xp, yp, gz, shape)
Ejemplo n.º 49
0
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()
shape = (100, 100)
xp, yp, zp = gridder.regular(dataarea, shape, z=-500)
data = [
    polyprism.gxx(xp, yp, zp, model),
    polyprism.gxy(xp, yp, zp, model),
    polyprism.gxz(xp, yp, zp, model),
    polyprism.gyy(xp, yp, zp, model),
    polyprism.gyz(xp, yp, zp, model),
    polyprism.gzz(xp, yp, zp, model)]
# Calculate the 3 invariants
invariants = tensor.invariants(data)
data = data + invariants
# and plot it
mpl.figure()
mpl.axis('scaled')
mpl.suptitle("Tensor and invariants produced by prism model (Eotvos)")
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz', 'I1', 'I2', 'I']
for i in xrange(len(data)):
    mpl.subplot(3, 3, i + 1)
    mpl.title(titles[i])
    levels = 20
    if i == 8:
        levels = numpy.linspace(0, 1, levels)
    mpl.contourf(yp, xp, data[i], shape, levels)
    mpl.colorbar()
    for p in model:
        mpl.polygon(p, '.-k', xy2ne=True)
    mpl.set_area(dataarea)
    mpl.m2km()
mpl.show()
Ejemplo n.º 51
0
from fatiando.vis import mpl, myv

# Make some synthetic gravity data from a simple prism model
model = [
    mesher.Prism(-4000, -1000, -4000, -2000, 2000, 5000, {'density': 800}),
    mesher.Prism(-1000, 1000, -1000, 1000, 1000, 6000, {'density': -800}),
    mesher.Prism(2000, 4000, 3000, 4000, 0, 4000, {'density': 600})
]
shape = (25, 25)
xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-10)
gz = utils.contaminate(prism.gz(xp, yp, zp, model), 0.1)

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

# Run the Generalized Inverse
mesh = imaging.geninv(xp, yp, zp, gz, shape, 0, 10000, 25)

# Plot the results
myv.figure()
myv.prisms(model, 'density', style='wireframe')
myv.prisms(mesh, 'density', edges=False, linewidth=5)
axes = myv.axes(myv.outline())
myv.wall_bottom(axes.axes.bounds)
Ejemplo n.º 52
0
xp, yp, zp = gridder.regular(area, shape, z=-500)
tensor = [
    gravmag.polyprism.gxx(xp, yp, zp, prisms),
    gravmag.polyprism.gxy(xp, yp, zp, prisms),
    gravmag.polyprism.gxz(xp, yp, zp, prisms),
    gravmag.polyprism.gyy(xp, yp, zp, prisms),
    gravmag.polyprism.gyz(xp, yp, zp, prisms),
    gravmag.polyprism.gzz(xp, yp, zp, prisms)]
# and plot it
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
mpl.figure()
mpl.axis('scaled')
mpl.suptitle("Gravity tensor produced by prism model (Eotvos)")
for i in xrange(len(tensor)):
    mpl.subplot(3, 2, i + 1)
    mpl.title(titles[i])
    mpl.contourf(yp, xp, tensor[i], shape, 20)
    mpl.colorbar()
    for p in prisms:
        mpl.polygon(p, '.-k', xy2ne=True)
    mpl.set_area(area)
    mpl.m2km()
mpl.show()
# Show the prisms
myv.figure()
myv.polyprisms(prisms, 'density')
myv.axes(myv.outline(bounds), ranges=[i*0.001 for i in bounds])
myv.wall_north(bounds)
myv.wall_bottom(bounds)
myv.show()
Ejemplo n.º 53
0
# Make some synthetic gravity data from a simple prism model
model = [
    mesher.Prism(-4000, 0, -4000, -2000, 2000, 5000, {'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=-10)
gz = utils.contaminate(prism.gz(xp, yp, zp, model), 0.1)

# 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()

mesh = imaging.migrate(xp, yp, zp, gz, 0, 10000, (30, 30, 30), power=0.8)

# Plot the results
myv.figure()
myv.prisms(model, 'density', style='wireframe', linewidth=2)
myv.prisms(mesh, 'density', edges=False)
axes = myv.axes(myv.outline())
myv.wall_bottom(axes.axes.bounds)
Ejemplo n.º 54
0
baselevel = 10
# Convert from nanoTesla to Tesla because euler and derivatives require things
# in SI
tf = (utils.nt2si(gravmag.prism.tf(xp, yp, zp, model, inc, dec)) + baselevel)
# Calculate the derivatives using FFT
xderiv = gravmag.fourier.derivx(xp, yp, tf, shape)
yderiv = gravmag.fourier.derivy(xp, yp, tf, shape)
zderiv = gravmag.fourier.derivz(xp, yp, tf, shape)

mpl.figure()
titles = ['Total field', 'x derivative', 'y derivative', 'z derivative']
for i, f in enumerate([tf, xderiv, yderiv, zderiv]):
    mpl.subplot(2, 2, i + 1)
    mpl.title(titles[i])
    mpl.axis('scaled')
    mpl.contourf(yp, xp, f, shape, 50)
    mpl.colorbar()
    mpl.m2km()
mpl.show()

# Run the euler deconvolution on a single window
# Structural index is 3
results = gravmag.euler.classic(xp, yp, zp, tf, xderiv, yderiv, zderiv, 3)
print "Base level used: %g" % (baselevel)
print "Estimated base level: %g" % (results['baselevel'])

myv.figure()
myv.points([results['point']], size=300.)
myv.prisms(model, 'magnetization', opacity=0.5)
axes = myv.axes(myv.outline(extent=bounds))
myv.wall_bottom(axes.axes.bounds, opacity=0.2)
tensor = [
    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)
Ejemplo n.º 56
0
from fatiando.vis import mpl

area = [-5000, 5000, -5000, 5000]
model = [Prism(-3000, 3000, -1000, 1000, 0, 1000, {'density': 1000})]
shape = (100, 100)
xp, yp, zp = gridder.regular(area, shape, z=-500)
data = [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)]
# Calculate the 3 invariants
invariants = tensor.invariants(data)
data = data + invariants
# and plot it
mpl.figure()
mpl.axis('scaled')
mpl.suptitle("Tensor and invariants (Eotvos)")
titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz', 'I1', 'I2', 'I']
for i in xrange(len(data)):
    mpl.subplot(3, 3, i + 1)
    mpl.title(titles[i])
    levels = 20
    if i == 8:
        levels = numpy.linspace(0, 1, levels)
    mpl.contourf(yp, xp, data[i], shape, levels, cmap=mpl.cm.RdBu_r)
    mpl.colorbar()
    mpl.m2km()
mpl.show()
Ejemplo n.º 57
0
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)
x, y, z = gridder.regular(grid.area, shape, z=0)
gz = gravmag.sphere.gz(x, y, z, grid)
tf = gravmag.sphere.tf(x, y, z, grid, inc, dec)
mpl.figure()
mpl.subplot(2, 1, 1)
mpl.axis('scaled')
mpl.title('Gravity anomaly')
mpl.contourf(y, x, gz, shape, 30)
mpl.colorbar()
mpl.subplot(2, 1, 2)
mpl.axis('scaled')
mpl.title('Magnetic total field anomaly')
mpl.contourf(y, x, tf, shape, 30)
mpl.colorbar()
mpl.show()

Ejemplo n.º 58
0
    #-----Drawing-----
    #Plot the model
    myv.figure()
    myv.prisms(lModel, 'density', style='surface')
    axes = myv.axes(myv.outline())
    myv.wall_bottom(axes.axes.bounds)
    myv.wall_north(axes.axes.bounds)
    myv.title("Geological Model")

    # Plot the forward modelled signal
    mpl.figure(figsize=(16, 5))
    mpl.subplot(121)
    mpl.title("Original signal")
    mpl.axis('scaled')
    mpl.contourf(aYGridCoords, aXGridCoords, aObservedSignal, tSignalSize,
                 50)  #last arg is number of contours
    mpl.colorbar()
    mpl.xlabel('East (km)')
    mpl.ylabel('North (km)')
    mpl.m2km()

    mpl.subplot(122)
    mpl.title("Forward modelled signal")
    mpl.axis('scaled')
    mpl.contourf(aYGridCoords, aXGridCoords, aCalcSignal, tSignalSize,
                 50)  #last arg is number of contours
    mpl.colorbar()
    mpl.xlabel('East (km)')
    mpl.ylabel('North (km)')
    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()
    compactness=1., threshold=0.0001)

# 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()