# Now I can forward model the layer at the south pole and check against the # true solution of the prism tfpole = prism.tf(x, y, z, model, -90, 0) tfreduced = sphere.tf(x, y, z, layer, -90, 0) mpl.figure() mpl.suptitle('L-curve') mpl.title("Estimated regularization parameter: %g" % (solver.regul_param_)) solver.plot_lcurve() mpl.grid() mpl.figure(figsize=(14, 4)) mpl.subplot(1, 3, 1) mpl.axis('scaled') mpl.title('Layer (A/m)') mpl.pcolor(layer.y, layer.x, layer.props['magnetization'], layer.shape) mpl.colorbar() mpl.m2km() mpl.subplot(1, 3, 2) mpl.axis('scaled') mpl.title('Fit (nT)') levels = mpl.contour(y, x, tf, shape, 15, color='r') mpl.contour(y, x, solver.predicted(), shape, levels, color='k') mpl.m2km() mpl.subplot(1, 3, 3) mpl.title('Residuals (nT)') mpl.hist(residuals, bins=10) mpl.figure() mpl.axis('scaled') mpl.title('True (red) | Reduced (black)')
200 * utils.gaussian2d(x, y, 50, 100, x0=80, y0=170)) nodes = (x, y, -1 * height) relief = mesher.PrismRelief(0, gridder.spacing(area, shape), nodes) 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())
# Now I can forward model the layer at the south pole and 500 m above the # original data. Check against the true solution of the prism tfpole = prism.tf(x, y, z - 500, model, -90, 0) tfreduced = sphere.tf(x, y, z - 500, layer, -90, 0) mpl.figure() mpl.suptitle('L-curve') mpl.title("Estimated regularization parameter: %g" % (solver.regul_param_)) solver.plot_lcurve() mpl.grid() mpl.figure(figsize=(15, 4)) mpl.subplot(1, 3, 1) mpl.axis('scaled') mpl.title('Layer (A/m)') mpl.pcolor(layer.y, layer.x, layer.props['magnetization'], layer.shape) mpl.colorbar() mpl.m2km() mpl.subplot(1, 3, 2) mpl.axis('scaled') mpl.title('Fit (nT)') levels = mpl.contour(y, x, tf, shape, 15, color='r') mpl.contour(y, x, solver.predicted(), shape, levels, color='k') mpl.m2km() mpl.subplot(1, 3, 3) mpl.title('Residuals (nT)') mpl.hist(residuals, bins=10) mpl.figure(figsize=(10, 4)) mpl.subplot(1, 2, 1) mpl.axis('scaled')
# Now I can forward model the layer at a greater height and check against the # true solution of the prism gz_true = prism.gz(x, y, z - 500, model) gz_up = sphere.gz(x, y, z - 500, layer) mpl.figure() mpl.suptitle('L-curve') mpl.title("Estimated regularization parameter: %g" % (solver.regul_param_)) solver.plot_lcurve() mpl.grid() mpl.figure(figsize=(14, 4)) mpl.subplot(1, 3, 1) mpl.axis('scaled') mpl.title('Layer (kg.m^-3)') mpl.pcolor(layer.y, layer.x, layer.props['density'], layer.shape) mpl.colorbar() mpl.m2km() mpl.subplot(1, 3, 2) mpl.axis('scaled') mpl.title('Fit (mGal)') levels = mpl.contour(y, x, gz, shape, 15, color='r') mpl.contour(y, x, solver.predicted(), shape, levels, color='k') mpl.m2km() mpl.subplot(1, 3, 3) mpl.title('Residuals (mGal)') mpl.hist(residuals, bins=10) mpl.figure() mpl.axis('scaled') mpl.title('True (red) | Layer (black)')
""" Gridding: Cut a section from a grid """ from fatiando import gridder, utils from fatiando.vis import mpl # Generate some synthetic data on a regular grid x, y = gridder.regular((-10, 10, -10, 10), (100,100)) # Using a 2D Gaussian z = utils.gaussian2d(x, y, 1, 1) subarea = [-2, 2, -3, 3] subx, suby, subscalar = gridder.cut(x, y, [z], subarea) mpl.figure(figsize=(12, 5)) mpl.subplot(1, 2, 1) mpl.title("Whole grid") mpl.axis('scaled') mpl.pcolor(x, y, z, (100,100)) mpl.square(subarea, 'k', linewidth=2, label='Cut this region') mpl.legend(loc='lower left') mpl.subplot(1, 2, 2) mpl.title("Cut grid") mpl.axis('scaled') mpl.pcolor(subx, suby, subscalar[0], (40,60), interp=True) mpl.show()
200*utils.gaussian2d(x, y, 50, 100, x0=80, y0=170)) nodes = (x, y, -1*height) relief = mesher.PrismRelief(0, gridder.spacing(area,shape), nodes) 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())
grid = mesher.PointGrid([0, 1000, 0, 2000], 500, (50, 50)) # Add some density to the grid grid.addprop( 'density', 1000000000 * utils.gaussian2d(grid.x, grid.y, 100, 500, x0=500, y0=1000, angle=-60)) # and some magnetization inc, dec = -45, 0 grid.addprop( 'magnetization', [d / 100. * utils.ang2vec(1, inc, dec) for d in grid.props['density']]) # plot the layer mpl.figure() 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()
""" Gridding: Cut a section from a grid """ from fatiando import gridder, utils from fatiando.vis import mpl # Generate some synthetic data on a regular grid x, y = gridder.regular((-10, 10, -10, 10), (100, 100)) # Using a 2D Gaussian z = utils.gaussian2d(x, y, 1, 1) subarea = [-2, 2, -3, 3] subx, suby, subscalar = gridder.cut(x, y, [z], subarea) mpl.figure(figsize=(12, 5)) mpl.subplot(1, 2, 1) mpl.title("Whole grid") mpl.axis('scaled') mpl.pcolor(x, y, z, (100, 100)) mpl.square(subarea, 'k', linewidth=2, label='Cut this region') mpl.legend(loc='lower left') mpl.subplot(1, 2, 2) mpl.title("Cut grid") mpl.axis('scaled') mpl.pcolor(subx, suby, subscalar[0], (40, 60), interp=True) mpl.show()
mpl.axis('scaled') levels = mpl.contourf(yp, xp, gyz_true, shape, 12) mpl.colorbar(shrink=0.7) mpl.contour(yp, xp, gyz, shape, 12, color='k') mpl.m2km() mpl.subplot(2, 3, 3) mpl.title("z deriv (contour) + true (color map)") mpl.axis('scaled') levels = mpl.contourf(yp, xp, gzz_true, shape, 8) mpl.colorbar(shrink=0.7) mpl.contour(yp, xp, gzz, shape, levels, color='k') mpl.m2km() mpl.subplot(2, 3, 4) mpl.title("Difference x deriv") mpl.axis('scaled') mpl.pcolor(yp, xp, (gxz_true - gxz), shape) mpl.colorbar(shrink=0.7) mpl.m2km() mpl.subplot(2, 3, 5) mpl.title("Difference y deriv") mpl.axis('scaled') mpl.pcolor(yp, xp, (gyz_true - gyz), shape) mpl.colorbar(shrink=0.7) mpl.m2km() mpl.subplot(2, 3, 6) mpl.title("Difference z deriv") mpl.axis('scaled') mpl.pcolor(yp, xp, (gzz_true - gzz), shape) mpl.colorbar(shrink=0.7) mpl.m2km() mpl.show()
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()
grid = mesher.PointGrid([-7000, 7000, -7000, 7000], 1000, (50, 50)) # Estimate the magnetization intensity data = [gravmag.eqlayer.TotalField(x, y, z, tf, inc, dec)] # Need to apply enough damping so that won't try to fit the error as well intensity, predicted = gravmag.eqlayer.classic(data, grid, damping=0.02) grid.addprop('magnetization', intensity) residuals = tf - predicted[0] print "Residuals:" print "mean:", residuals.mean() print "stddev:", residuals.std() # Plot the layer and the fit mpl.figure(figsize=(14,4)) mpl.subplot(1, 3, 1) mpl.axis('scaled') mpl.title('Layer (A/m)') mpl.pcolor(grid.y, grid.x, grid.props['magnetization'], grid.shape) mpl.subplot(1, 3, 2) mpl.axis('scaled') mpl.title('Fit (nT)') levels = mpl.contour(y, x, tf, shape, 15, color='r') mpl.contour(y, x, predicted[0], shape, levels, color='k') mpl.subplot(1, 3, 3) mpl.title('Residuals (nT)') mpl.hist(residuals, bins=10) mpl.show() # Now I can forward model the layer at the south pole and check against the # true solution of the prism tfpole = gravmag.prism.tf(x, y, z, model, -90, 0) tfreduced = gravmag.sphere.tf(x, y, z, grid, -90, 0) mpl.figure(figsize=(14,4)) mpl.subplot(1, 2, 1)
""" Vis: Plot a map using the Mercator map projection and pseudo-color """ from fatiando import gridder, utils from fatiando.vis import mpl # Generate some data to plot area = (-20, 40, 20, 80) shape = (100, 100) lon, lat = gridder.regular(area, shape) data = utils.gaussian2d(lon, lat, 10, 20, 10, 60, angle=45) # Now get a basemap to plot with some projection bm = mpl.basemap(area, 'merc') # And now plot everything passing the basemap to the plotting functions mpl.figure(figsize=(5, 8)) mpl.pcolor(lon, lat, data, shape, basemap=bm) mpl.colorbar() bm.drawcoastlines() bm.drawmapboundary() bm.drawcountries() mpl.draw_geolines(area, 10, 10, bm) mpl.show()
grid, (20, 20), degree=1, smoothness=10.**-2) grid.addprop('magnetization', intensity) # Compute the predicted data and the residuals predicted = gravmag.sphere.tf(x, y, z, grid, inc, dec) residuals = tf - predicted print "Residuals:" print "mean:", residuals.mean() print "stddev:", residuals.std() # Plot the layer and the fit mpl.figure(figsize=(15, 4)) mpl.subplot(1, 3, 1) mpl.axis('scaled') mpl.title('Layer (A/m)') mpl.pcolor(grid.y, grid.x, grid.props['magnetization'], grid.shape) mpl.colorbar() mpl.m2km() mpl.subplot(1, 3, 2) mpl.axis('scaled') mpl.title('Fit (nT)') levels = mpl.contour(y, x, tf, shape, 15, color='r') mpl.contour(y, x, predicted, shape, levels, color='k') mpl.m2km() mpl.subplot(1, 3, 3) mpl.title('Residuals (nT)') mpl.hist(residuals, bins=10) mpl.show() # Now I can forward model the layer at the south pole and 500 m above the # original data. Check against the true solution of the prism tfpole = gravmag.prism.tf(x, y, z - 500, model, -90, 0)
layer.addprop('density', solver.estimate_) residuals = solver[0].residuals() print("Residuals:") print("mean:", residuals.mean()) print("stddev:", residuals.std()) # Now I can forward model the layer at a greater height and check against the # true solution of the prism gz_true = prism.gz(x, y, z - 500, model) gz_up = sphere.gz(x, y, z - 500, layer) mpl.figure(figsize=(14, 4)) mpl.subplot(1, 3, 1) mpl.axis('scaled') mpl.title('Layer (kg.m^-3)') mpl.pcolor(layer.y, layer.x, layer.props['density'], layer.shape) mpl.colorbar() mpl.m2km() mpl.subplot(1, 3, 2) mpl.axis('scaled') mpl.title('Fit (mGal)') levels = mpl.contour(y, x, gz, shape, 15, color='r') mpl.contour(y, x, solver[0].predicted(), shape, levels, color='k') mpl.m2km() mpl.subplot(1, 3, 3) mpl.title('Residuals (mGal)') mpl.hist(residuals, bins=10) mpl.figure() mpl.axis('scaled') mpl.title('True (red) | Layer (black)')
from fatiando.vis import mpl grid = mesher.PointGrid([0, 1000, 0, 2000], 500, (50, 50)) # Add some density to the grid grid.addprop('density', 1000000000*utils.gaussian2d(grid.x, grid.y, 100, 500, x0=500, y0=1000, angle=-60)) # and some magnetization inc, dec = -45, 0 grid.addprop('magnetization', [d/100.*utils.ang2vec(1, inc, dec) for d in grid.props['density']]) # plot the layer mpl.figure() 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()