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()
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()
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()
""" 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()
""" 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()
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: 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()
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()
""" 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()
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()
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()
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()
""" 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.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()
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.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()
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()
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()
""" 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()
# 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()
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()
""" 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()