def run(title):
    if title == 'Migration':
        result = gravmag.imaging.migrate(xp, yp, zp, gz, bounds[-2], bounds[-1],
            meshshape, power=0.5)
    elif title == 'Generalized Inverse':
        result = gravmag.imaging.geninv(xp, yp, zp, gz, meshshape[1:],
            bounds[-2], bounds[-1], meshshape[0])
    elif title == 'Sandwich':
        result = gravmag.imaging.sandwich(xp, yp, zp, gz, meshshape[1:],
            bounds[-2], bounds[-1], meshshape[0], power=0.5)
    # Plot the results
    myv.figure()
    myv.polyprisms(prisms, 'density', style='wireframe', linewidth=2)
    myv.prisms(result, 'density', edges=False)
    axes = myv.axes(myv.outline(), ranges=[b*0.001 for b in bounds],
        fmt='%.0f')
    myv.wall_bottom(axes.axes.bounds)
    myv.wall_north(axes.axes.bounds)
    myv.title(title)
    myv.show()
        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()
    oTimeEndIteration = datetime.now()
    print("-----Iteration number:", iIter,
          oTimeEndIteration - oTimeBeginIteration)
    #--- end iterations

    oTimeEndTot = datetime.now()
    oTimeEndIteration = datetime.now()
    print("~~~~~~~~~~Total Time:", oTimeEndTot - oTimeBeginTot)

    oTimeBeforePlotting = datetime.now()

    #-----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)')
    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()
    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')
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.figure()
myv.prisms(model, 'density', style='wireframe')
myv.prisms(vremove(0, 'density', mesh), '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()
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)
myv.show()
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()
        -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()
mpl.figure()
titles = ['Gravity anomaly', 'x derivative', 'y derivative', 'z derivative']
for i, f in enumerate([gz, 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 moving windows to produce a set of solutions
euler = Classic(xp, yp, zp, gz, xderiv, yderiv, zderiv, 2)
solver = MovingWindow(euler, windows=(10, 10), size=(2000, 2000)).fit()

mpl.figure()
mpl.axis('scaled')
mpl.title('Moving window centers')
mpl.contourf(yp, xp, gz, shape, 50)
mpl.points(solver.window_centers)
mpl.show()

myv.figure()
myv.points(solver.estimate_, size=100.)
myv.prisms(model, opacity=0.5)
axes = myv.axes(myv.outline(bounds), ranges=[b * 0.001 for b in bounds])
myv.wall_bottom(bounds)
myv.wall_north(bounds)
myv.title('Euler solutions')
myv.show()
Example #10
0
Sometimes things are too small on one dimension to plot properly. On the Earth,
this is usually the vertical dimension. The functions in
:mod:`fatiando.vis.myv` have a ``scale`` attribute to control how much
exaggeration should  be placed in each dimension of your plot.

"""
import copy
from fatiando.vis import myv
from fatiando.mesher import Prism


# Make two objects that are very thin.
model = [Prism(0, 1000, 0, 1000, 0, 10, props={'density': 300}),
         Prism(-2500, -1000, -2000, -500, 0, 5, props={'density': -300})]

bounds = [-3000, 3000, -3000, 3000, 0, 20]

# The scale argument is by how much each dimension (being x, y, and z) will be
# multiplied. This means 300x in the z dimension.
scale = (1, 1, 300)

# Pass "scale" along to all plot functions
myv.figure()
myv.prisms(model, prop='density', scale=scale)
myv.axes(myv.outline(bounds, scale=scale), ranges=bounds)
myv.wall_north(bounds, scale=scale)
myv.wall_bottom(bounds, scale=scale)
# Note: the tittle can't be the first thing on the plot.
myv.title('{}x vertical exaggeration'.format(scale[-1]))
myv.show()
Example #11
0
from fatiando import gridder, gravmag
from fatiando.mesher import Prism, PrismMesh
from fatiando.vis import myv

model = [Prism(200, 800, 400, 600, 200, 400, {'density': 1000})]
shape = (20, 20)
bounds = [0, 1000, 0, 1000, 0, 1000]
area = bounds[0:4]
x, y, z = gridder.regular(area, shape, z=-1)
gz = gravmag.prism.gz(x, y, z, model)
mesh = PrismMesh(bounds, (10, 10, 10))
data = [gravmag.harvester.Gz(x, y, z, gz)]
seeds = gravmag.harvester.sow([[500, 500, 250, {'density': 1000}]], mesh)

fig = myv.figure(size=(700, 700))
plot = myv.prisms(model, style='wireframe', linewidth=4)
plot.actor.mapper.scalar_visibility = False
myv.prisms(seeds, 'density')
myv.outline(bounds)
myv.wall_bottom(bounds)
myv.wall_east(bounds)
for update in gravmag.harvester.iharvest(data,
                                         seeds,
                                         mesh,
                                         compactness=0.5,
                                         threshold=0.001):
    best, neighborhood = update[2:4]
    if best is not None:
        myv.prisms([mesh[best.i]])
        plot = myv.prisms(
            [mesh[n] for neighbors in neighborhood for n in neighbors],
Example #12
0
"""
from fatiando.mesher import Prism
from fatiando.vis import myv

# Models in Fatiando are basically sequences of geometric elements from
# fatiando.mesher
# Each element can have as many physical properties as you want.
# Here, we'll give the prisms a density and a magnetization vector.
model = [
    Prism(-1500, -500, -1500, -500, 1000, 2000, {
        'magnetization': [3, 5, 4],
        'density': 500
    }),
    Prism(500, 1500, 1000, 2000, 500, 1500, {
        'magnetization': [10, 2, 1],
        'density': -250
    })
]

# Create a 3D figure in Mayavi
myv.figure()
# Give it some prisms to plot. The color will be decided by the density.
myv.prisms(model, prop='density')
# It's useful to plot axes and a bounding box about the prism
bounds = [-2500, 2500, -2500, 2500, 0, 2500]
myv.axes(myv.outline(bounds))
myv.wall_north(bounds)
myv.wall_bottom(bounds)
myv.show()
Example #13
0
from fatiando.vis import mpl, myv
from fatiando.mesher import Prism

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

bounds = [0, 5000, 0, 5000, -500, 1000]
model = [
    Prism(600, 1200, 200, 4200, 400, 900, {'density': 1000}),
    Prism(3000, 4000, 1000, 2000, 200, 800, {'density': 500}),
    Prism(2700, 3200, 3700, 4200, 0, 900, {'density': 1500})
]
# show it
myv.figure()
myv.prisms(model, '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()
# Generate the data grid
shape = (25, 25)
area = bounds[0:4]
x, y = gridder.regular(area, shape)
# Generate synthetic topography
height = (
    300 * utils.gaussian2d(x, y, 1000, 3000, x0=500, y0=1000, angle=-60) +
    1000 * utils.gaussian2d(x, y, 500, 2000, x0=3000, y0=3000))
# Make some synthetic gravity data from a simple prism model
prisms = [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(gravmag.prism.gz(xp, yp, zp, prisms), 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 = gravmag.imaging.geninv(xp, yp, zp, gz, shape,
    0, 10000, 25)

# Plot the results
myv.figure()
myv.prisms(prisms, 'density', style='wireframe')
myv.prisms(mesh, 'density', edges=False, linewidth=5)
axes = myv.axes(myv.outline())
myv.wall_bottom(axes.axes.bounds)
myv.wall_north(axes.axes.bounds)
myv.show()
from fatiando.gravmag import prism, harvester
from fatiando.mesher import Prism, PrismMesh
from fatiando.vis import myv

model = [Prism(200, 800, 400, 600, 200, 400, {'density': 1000})]
shape = (20, 20)
bounds = [0, 1000, 0, 1000, 0, 1000]
area = bounds[0:4]
x, y, z = gridder.regular(area, shape, z=-1)
gz = prism.gz(x, y, z, model)
mesh = PrismMesh(bounds, (10, 10, 10))
data = [harvester.Gz(x, y, z, gz)]
seeds = harvester.sow([[500, 500, 250, {'density': 1000}]], mesh)

fig = myv.figure(size=(700, 700))
plot = myv.prisms(model, style='wireframe', linewidth=4)
plot.actor.mapper.scalar_visibility = False
myv.prisms(seeds, 'density')
myv.outline(bounds)
myv.wall_bottom(bounds)
myv.wall_east(bounds)
for update in harvester.iharvest(data, seeds, mesh, compactness=0.5,
                                 threshold=0.001):
    best, neighborhood = update[2:4]
    if best is not None:
        myv.prisms([mesh[best.i]])
        plot = myv.prisms(
            [mesh[n] for neighbors in neighborhood for n in neighbors],
            style='wireframe')
        plot.actor.mapper.scalar_visibility = False
myv.show()
Example #16
0
    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()
                                                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)]
estimate, predicted = gravmag.harvester.harvest(data,
                                                seeds,
                                                mesh,
                                                compactness=1.5,
                                                threshold=0.001)
            compactness=1, threshold=0.0001)
#Put the estimated magnetization vector in the mesh
mesh.addprop('magnetization', estimate['magnetization'])

# Plot the adjustment
mpl.figure()
mpl.title("True: color | Inversion: contour")
mpl.axis('scaled')
levels = mpl.contourf(yp, xp, tf, 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()
residuals = tf - predicted[0]
mpl.figure()
mpl.title('Residuals: mean=%g stddev=%g' % (residuals.mean(), residuals.std()))
mpl.hist(residuals, bins=10)
mpl.xlabel('Residuals (nT)')
mpl.ylabel('# of')
mpl.show()
# Plot the result
myv.figure()
myv.prisms(model, 'magnetization', style='wireframe')
myv.prisms(vremove(0, 'magnetization', mesh), 'magnetization')
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 #19
0
from fatiando.mesher import PrismMesh
from fatiando.vis import myv

mesh = PrismMesh(bounds=(0, 100, 0, 200, 0, 150), shape=(5, 6, 7))
# We'll give each prism a density value corresponding to it's index on the
# mesh. Notice that meshes take lists/arrays as their property values
mesh.addprop('density', list(range(mesh.size)))

# You can iterate over meshes like lists of elements
for p in mesh:
    print(p.props['density'], end=' ')

scene = myv.figure(size=(600, 600))
# Because you can iterate over a mesh, you can pass it anywhere a list of
# prisms is accepted
plot = myv.prisms(mesh, prop='density')
# The code below enables and configures the color bar. This will be automated
# on a function in the future (write to the mailing list if you'd like to help
# out!)
plot.module_manager.scalar_lut_manager.show_scalar_bar = True
plot.module_manager.scalar_lut_manager.lut_mode = 'Greens'
plot.module_manager.scalar_lut_manager.reverse_lut = True
plot.module_manager.scalar_lut_manager.label_text_property.color = (0, 0, 0)
plot.module_manager.scalar_lut_manager.title_text_property.color = (0, 0, 0)
plot.module_manager.scalar_lut_manager.scalar_bar_representation.position = \
    [0.9, 0.4]
plot.module_manager.scalar_lut_manager.scalar_bar_representation.position2 = \
    [0.1, 0.6]

myv.axes(myv.outline(), fmt='%.1f')
myv.show()
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, 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([mesh[s.i] for s in 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()
# 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))
myv.wall_bottom(axes.axes.bounds, opacity=0.2)
myv.wall_north(axes.axes.bounds)
myv.show()
import fatiando.gravmag as gm
from fatiando.mesher import Prism, PrismMesh, vremove
from fatiando.vis import mpl, myv

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

# Generate a synthetic model
bounds = [0, 5000, 0, 5000, -500, 2000]
model = [Prism(600, 1200, 200, 4200, 400, 900, {'density':1500}),
         Prism(3000, 4000, 1000, 2000, 200, 800, {'density':1000}),
         Prism(2700, 3200, 3700, 4200, 0, 900, {'density':800})]
# show it
myv.figure()
myv.prisms(model, '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()
# and use it to generate some tensor data
shape = (25, 25)
area = bounds[0:4]
x, y, z = gridder.regular(area, shape, z=-650)
gxy = utils.contaminate(gm.prism.gxy(x, y, z, model), 1)
gzz = utils.contaminate(gm.prism.gzz(x, y, z, model), 1)

# Wrap the data so that harvester can use it
data = [gm.harvester.Gxy(x, y, z, gxy),
        gm.harvester.Gzz(x, y, z, gzz)]
Example #23
0
"""
Vis: Exaggerate the vertical dimension of 3D plots
"""
from fatiando.mesher import Prism, PolygonalPrism
from fatiando.vis import myv

prism = Prism(0, 1000, 0, 1000, 0, 10)
poly = PolygonalPrism([[-2000, -2000], [-1000, -1000], [-2000, -1000]], 0, 10)
bounds = (-3000, 3000, -3000, 3000, 0, 20)
myv.figure()
myv.prisms([prism])
myv.polyprisms([poly])
myv.axes(myv.outline(bounds))
myv.wall_north(bounds)
myv.wall_bottom(bounds)
myv.title('No exaggeration')
scale = (1, 1, 50)  # Exaggerate 50x the z axis
myv.figure()
myv.prisms([prism], scale=scale)
myv.polyprisms([poly], scale=scale)
myv.axes(myv.outline(bounds, scale=scale), ranges=bounds)
myv.wall_north(bounds, scale=scale)
myv.wall_bottom(bounds, scale=scale)
myv.title('50x exaggeration')
myv.show()
    oTimeEndIteration = datetime.now()
    print("-----Iteration number:", iIter, oTimeEndIteration-oTimeBeginIteration)
    #--- end iterations
    

    oTimeEndTot = datetime.now()
    oTimeEndIteration = datetime.now()
    print("~~~~~~~~~~Total Time:", oTimeEndTot-oTimeBeginTot)

    oTimeBeforePlotting = datetime.now()


    #-----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)')
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()
"""
Meshing: Filter prisms from a 3D prism mesh based on their physical properties
"""
from fatiando import gridder, mesher
from fatiando.vis import myv

shape = (5, 20, 10)
bounds = (0, 100, 0, 200, 0, 50)
mesh = mesher.PrismMesh(bounds, shape)
# Fill the even prisms with 1 and odd with -1


def fill(i):
    if i % 2 == 0:
        return 1
    return -1


mesh.addprop('density', [fill(i) for i in xrange(mesh.size)])

# Separate even and odd prisms
odd = mesher.vfilter(-1, 0, 'density', mesh)
even = mesher.vfilter(0, 1, 'density', mesh)

myv.figure()
myv.prisms(odd, prop='density', vmin=-1, vmax=1)
myv.prisms(even, prop='density', style='wireframe', vmin=-1, vmax=1)
myv.axes(myv.outline(bounds))
myv.show()
Example #27
0
"""
Meshing: Make and plot a 3D prism mesh with topography
"""

from fatiando import gridder, utils, mesher
from fatiando.vis import myv

x1, x2 = -100, 100
y1, y2 = -200, 200
bounds = (x1, x2, y1, y2, -200, 0)

x, y = gridder.regular((x1, x2, y1, y2), (50, 50))
height = (100 +
          -50 * utils.gaussian2d(x, y, 100, 200, x0=-50, y0=-100, angle=-60) +
          100 * utils.gaussian2d(x, y, 50, 100, x0=80, y0=170))

mesh = mesher.PrismMesh(bounds, (20, 40, 20))
mesh.carvetopo(x, y, height)

myv.figure()
myv.prisms(mesh)
myv.axes(myv.outline(bounds), fmt='%.0f')
myv.wall_north(bounds)
myv.show()
    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 = 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()
# Generate a synthetic model
bounds = [0, 5000, 0, 5000, 0, 1500]
model = [Prism(500, 4500, 3000, 3500, 200, 700, {'density':1200}),
         Prism(3000, 4500, 1800, 2300, 200, 700, {'density':1200}),
         Prism(500, 1500, 500, 1500, 0, 800, {'density':600}),
         Prism(0, 800, 1800, 2300, 0, 200, {'density':600}),
         Prism(4000, 4800, 100, 900, 0, 300, {'density':600}),
         Prism(0, 2000, 4500, 5000, 0, 200, {'density':600}),
         Prism(3000, 4200, 2500, 2800, 200, 700, {'density':-1000}),
         Prism(300, 2500, 1800, 2700, 500, 1000, {'density':-1000}),
         Prism(4000, 4500, 500, 1500, 400, 1000, {'density':-1000}),
         Prism(1800, 3700, 500, 1500, 300, 1300, {'density':-1000}),
         Prism(500, 4500, 4000, 4500, 400, 1300, {'density':-1000})]
# show it
myv.figure()
myv.prisms(model, '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()
# and use it to generate some tensor data
shape = (51, 51)
area = bounds[0:4]
noise = 2
x, y, z = gridder.regular(area, shape, z=-150)
gyy = utils.contaminate(prism.gyy(x, y, z, model), noise)
gyz = utils.contaminate(prism.gyz(x, y, z, model), noise)
gzz = utils.contaminate(prism.gzz(x, y, z, model), noise)

# Set up the inversion:
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)]
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()
Example #31
0
estimate, predicted = gm.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()
"""
Meshing: Filter prisms from a 3D prism mesh based on their physical properties
"""
from fatiando import gridder, mesher
from fatiando.vis import myv

shape = (5, 20, 10)
bounds = (0, 100, 0, 200, 0, 50)
mesh = mesher.PrismMesh(bounds, shape)
# Fill the even prisms with 1 and odd with -1
def fill(i):
    if i%2 == 0:
        return 1
    return -1
mesh.addprop('density', [fill(i) for i in xrange(mesh.size)])

# Separate even and odd prisms
odd = mesher.vfilter(-1, 0, 'density', mesh)
even = mesher.vfilter(0, 1, 'density', mesh)

myv.figure()
myv.prisms(odd, prop='density', vmin=-1, vmax=1)
myv.prisms(even, prop='density', style='wireframe', vmin=-1, vmax=1)
myv.axes(myv.outline(bounds))
myv.show()
    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')
myv.prisms([mesh[s.i] for s in 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.figure()
myv.prisms(model, 'density', style='wireframe')
myv.prisms(vremove(0, 'density', mesh), '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()
Example #34
0
"""
Vis: Set the colors in figures, prisms, polygonal prisms and tesseroids.
"""
from fatiando.mesher import Prism, PolygonalPrism, Tesseroid
from fatiando.vis import myv

prism = Prism(1, 2, 1, 2, 0, 1, {'density': 1})
polyprism = PolygonalPrism([[3, 1], [4, 2], [5, 1]], -1, 2, {'density': 2})
tesseroid = Tesseroid(10, 20, 50, 60, 10**6, 0)

red, green, blue = (1, 0, 0), (0, 1, 0), (0, 0, 1)
white, black = (1, 1, 1), (0, 0, 0),

myv.figure()
# Make the prism red with blue edges, despite its density
myv.prisms([prism], 'density', color=red, edgecolor=blue)
# and the polyprism green with blue edges
myv.title('Body + edge colors')

myv.figure()
# For wireframes, color is usually set by the density.
# Overwrite this by setting *color*
# *edgecolor* is ignored
myv.polyprisms([polyprism],
               'density',
               style='wireframe',
               color=green,
               edgecolor=red,
               linewidth=2)
myv.title('Wireframe colors')
    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],
        windows=100, wcenter=center)
    cms.append(cm)
    print "Sigma = %g" % (sigma)

# Plot the prism and the estimated center of mass
# It won't work well because we're using only a single window
myv.figure()
myv.points(cms, size=200.)
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 #36
0
"""
Meshing: Generate a 3D prism model of the topography
"""
from fatiando import gridder, utils, mesher
from fatiando.vis import myv

area = (-150, 150, -300, 300)
shape = (100, 50)
x, y = gridder.regular(area, shape)
height = (-80*utils.gaussian2d(x, y, 100, 200, x0=-50, y0=-100, angle=-60) +
          100*utils.gaussian2d(x, y, 50, 100, x0=80, y0=170))

nodes = (x, y, -1*height) # -1 is to convert height to z coordinate
reference = 0 # z coordinate of the reference surface
relief = mesher.PrismRelief(reference, gridder.spacing(area, shape), nodes)
relief.addprop('density', (2670 for i in xrange(relief.size)))

myv.figure()
myv.prisms(relief, prop='density', edges=False)
axes = myv.axes(myv.outline())
myv.wall_bottom(axes.axes.bounds, opacity=0.2)
myv.wall_north(axes.axes.bounds)
myv.show()
"""
Meshing: Make a 3D prism mesh with depth-varying density
"""
from fatiando import gridder, mesher
from fatiando.vis import myv

shape = (10, 20, 10)
nz, ny, nx = shape
mesh = mesher.PrismMesh((0, 100, 0, 200, 0, 50), shape)


def fill(i):
    k = i / (nx * ny)
    return k
mesh.addprop('density', [fill(i) for i in xrange(mesh.size)])

myv.figure()
myv.prisms(mesh, prop='density')
myv.axes(myv.outline(), fmt='%.0f')
myv.show()
Example #38
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()
    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')
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.figure()
myv.prisms(model, 'density', style='wireframe')
myv.prisms(vremove(0, 'density', mesh), 'density')
myv.axes(myv.outline(bounds),
         ranges=[i * 0.001 for i in bounds],
         fmt='%.1f',
         nlabels=6)
myv.wall_bottom(bounds)
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()
import numpy
from fatiando import gravmag, logger, gridder, utils
from fatiando.vis import mpl, myv
from fatiando.mesher import Prism

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

bounds = [0, 5000, 0, 5000, -500, 1000]
model = [Prism(600, 1200, 200, 4200, 400, 900, {'density':1000}),
         Prism(3000, 4000, 1000, 2000, 200, 800, {'density':500}),
         Prism(2700, 3200, 3700, 4200, 0, 900, {'density':1500})]
# show it
myv.figure()
myv.prisms(model, '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()
# Generate the data grid
shape = (25, 25)
area = bounds[0:4]
x, y = gridder.regular(area, shape)
# Generate synthetic topography
height = (300*utils.gaussian2d(x, y, 1000, 3000, x0=500, y0=1000, angle=-60)
          + 1000*utils.gaussian2d(x, y, 500, 2000, x0=3000, y0=3000))
# Calculate the data
noise = 1
noisegz = 0.1
Example #42
0
relief.addprop('density', (2670 for i in xrange(relief.size)))

gridarea = (-80, 80, -220, 220)
gridshape = (100, 100)
xp, yp, zp = gridder.regular(gridarea, gridshape, z=-200)
gz = gravmag.prism.gz(xp, yp, zp, relief)

mpl.figure(figsize=(10,7))
mpl.subplot(1, 2, 1)
mpl.title("Synthetic topography")
mpl.axis('scaled')
mpl.pcolor(x, y, height, shape)
cb = mpl.colorbar()
cb.set_label("meters")
mpl.square(gridarea, label='Computation grid')
mpl.legend()
mpl.subplot(1, 2, 2)
mpl.title("Topographic effect")
mpl.axis('scaled')
mpl.pcolor(xp, yp, gz, gridshape)
cb = mpl.colorbar()
cb.set_label("mGal")
mpl.show()

myv.figure()
myv.prisms(relief, prop='density')
axes = myv.axes(myv.outline())
myv.wall_bottom(axes.axes.bounds, opacity=0.2)
myv.wall_north(axes.axes.bounds)
myv.show()
"""
Meshing: Make and plot a 3D prism mesh with topography
"""

from fatiando import gridder, utils, mesher
from fatiando.vis import myv

x1, x2 = -100, 100
y1, y2 = -200, 200
bounds = (x1, x2, y1, y2, -200, 0)

x, y = gridder.regular((x1, x2, y1, y2), (50,50))
height = (100 +
          -50*utils.gaussian2d(x, y, 100, 200, x0=-50, y0=-100, angle=-60) +
          100*utils.gaussian2d(x, y, 50, 100, x0=80, y0=170))

mesh = mesher.PrismMesh(bounds, (20,40,20))
mesh.carvetopo(x, y, height)

myv.figure()
myv.prisms(mesh)
myv.axes(myv.outline(bounds), fmt='%.0f')
myv.wall_north(bounds)
myv.show()
    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.0)
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()
relief.addprop('density', (2670 for i in xrange(relief.size)))

gridarea = (-80, 80, -220, 220)
gridshape = (100, 100)
xp, yp, zp = gridder.regular(gridarea, gridshape, z=-200)
gz = prism.gz(xp, yp, zp, relief)

mpl.figure(figsize=(10, 7))
mpl.subplot(1, 2, 1)
mpl.title("Synthetic topography")
mpl.axis('scaled')
mpl.pcolor(x, y, height, shape)
cb = mpl.colorbar()
cb.set_label("meters")
mpl.square(gridarea, label='Computation grid')
mpl.legend()
mpl.subplot(1, 2, 2)
mpl.title("Topographic effect")
mpl.axis('scaled')
mpl.pcolor(xp, yp, gz, gridshape)
cb = mpl.colorbar()
cb.set_label("mGal")
mpl.show()

myv.figure()
myv.prisms(relief, 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 #46
0
# Generate a synthetic model
bounds = [0, 5000, 0, 5000, 0, 1500]
model = [Prism(500, 4500, 3000, 3500, 200, 700, {'density': 1200}),
         Prism(3000, 4500, 1800, 2300, 200, 700, {'density': 1200}),
         Prism(500, 1500, 500, 1500, 0, 800, {'density': 600}),
         Prism(0, 800, 1800, 2300, 0, 200, {'density': 600}),
         Prism(4000, 4800, 100, 900, 0, 300, {'density': 600}),
         Prism(0, 2000, 4500, 5000, 0, 200, {'density': 600}),
         Prism(3000, 4200, 2500, 2800, 200, 700, {'density': -1000}),
         Prism(300, 2500, 1800, 2700, 500, 1000, {'density': -1000}),
         Prism(4000, 4500, 500, 1500, 400, 1000, {'density': -1000}),
         Prism(1800, 3700, 500, 1500, 300, 1300, {'density': -1000}),
         Prism(500, 4500, 4000, 4500, 400, 1300, {'density': -1000})]
# show it
myv.figure()
myv.prisms(model, '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()
# and use it to generate some tensor data
shape = (51, 51)
area = bounds[0:4]
noise = 2
x, y, z = gridder.regular(area, shape, z=-150)
gyy = utils.contaminate(prism.gyy(x, y, z, model), noise)
gyz = utils.contaminate(prism.gyz(x, y, z, model), noise)
gzz = utils.contaminate(prism.gzz(x, y, z, model), noise)

# Set up the inversion:
Example #47
0
    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)
myv.wall_north(axes.axes.bounds)
myv.show()
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, tf, shape, 50)
mpl.colorbar()
centers = mpl.pick_points(area, mpl.gca(), xy2ne=True)

# Run the euler deconvolution on an expanding window
# Structural index is 3
index = 3
results = []
for center in centers:
    results.append(
        gravmag.euler.expanding_window(xp, yp, zp, tf, xderiv, yderiv, zderiv,
            index, gravmag.euler.classic, center, 500, 5000))
    print "Base level used: %g" % (baselevel)
    print "Estimated base level: %g" % (results[-1]['baselevel'])
    print "Estimated source location: %s" % (str(results[-1]['point']))

myv.figure()
myv.points([r['point'] for r in results], size=300.)
myv.prisms(model, opacity=0.5)
axes = myv.axes(myv.outline(bounds), ranges=[b*0.001 for b in bounds])
myv.wall_bottom(bounds)
myv.wall_north(bounds)
myv.show()
    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()
fields = [gravmag.prism.potential(xp, yp, zp, prisms),
          gravmag.prism.gx(xp, yp, zp, prisms),
          gravmag.prism.gy(xp, yp, zp, prisms),
          gravmag.prism.gz(xp, yp, zp, prisms),
          gravmag.prism.gxx(xp, yp, zp, prisms),
          gravmag.prism.gxy(xp, yp, zp, prisms),
          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)
myv.show()
Example #51
0
"""
Meshing: Make and plot a 3D prism mesh
"""
from fatiando import mesher
from fatiando.vis import myv

mesh = mesher.PrismMesh(bounds=(-2, 2, -3, 3, 0, 1), shape=(4, 4, 4))

myv.figure()
plot = myv.prisms(mesh)
axes = myv.axes(plot)
myv.show()
Example #52
0
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)
myv.wall_north(axes.axes.bounds)
myv.show()
"""
Meshing: Make and plot a 3D prism mesh
"""
from fatiando import mesher
from fatiando.vis import myv

mesh = mesher.PrismMesh(bounds=(-2, 2, -3, 3, 0, 1), shape=(4,4,4))

myv.figure()
plot = myv.prisms(mesh)
axes = myv.axes(plot)
myv.show()
Example #54
0
                 {'magnetization': utils.ang2vec(1, inc, dec)}),
    mesher.Prism(-1000, 1000, -1000, 1000, 0, 2000,
                 {'magnetization': utils.ang2vec(1, inc, dec)}),
    # This prism will have magnetization in a different direction
    mesher.Prism(2000, 4000, 3000, 4000, 0, 2000,
                 {'magnetization': utils.ang2vec(3, -10, 45)})
]
# Create a regular grid at 100m height
shape = (200, 200)
area = bounds[:4]
xp, yp, zp = gridder.regular(area, shape, z=-500)
# Calculate the anomaly for a given regional field
tf = prism.tf(xp, yp, zp, model, inc, dec)
# Plot
mpl.figure()
mpl.title("Total-field anomaly (nT)")
mpl.axis('scaled')
mpl.contourf(yp, xp, tf, shape, 15)
mpl.colorbar()
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()