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