def test_pel_polereduce(): "PELTotalField can reduce data to the pole" # Use remanent magnetization sinc, sdec = -70, 30 model = [Prism(-100, 100, -500, 500, 0, 100, {'magnetization': utils.ang2vec(5, sinc, sdec)})] inc, dec = -60, -15 shape = (40, 40) area = [-2000, 2000, -2000, 2000] x, y, z = gridder.regular(area, shape, z=-100) data = prism.tf(x, y, z, model, inc, dec) true = prism.tf(x, y, z, model, -90, 0, pmag=utils.ang2vec(5, -90, 0)) layer = PointGrid(area, 100, shape) windows = (20, 20) degree = 3 pel = PELTotalField(x, y, z, data, inc, dec, layer, windows, degree, sinc, sdec) eql = pel + 1e-25*PELSmoothness(layer, windows, degree) eql.fit() assert_array_almost_equal(eql[0].predicted(), data, decimal=1) layer.addprop('magnetization', utils.ang2vec(eql.estimate_, inc=-90, dec=0)) calc = sphere.tf(x, y, z, layer, inc=-90, dec=0) assert_allclose(calc, true, atol=10, rtol=0.05)
def test_pelgrav_prism_interp(): "PELGravity can interpolate data from a prism" model = [Prism(-300, 300, -500, 500, 100, 600, {'density': 400})] shape = (40, 40) n = shape[0]*shape[1] area = [-2000, 2000, -2000, 2000] x, y, z = gridder.scatter(area, n, z=-100, seed=42) data = prism.gz(x, y, z, model) layer = PointGrid(area, 100, shape) windows = (20, 20) degree = 1 eql = (PELGravity(x, y, z, data, layer, windows, degree) + 5e-22*PELSmoothness(layer, windows, degree)) eql.fit() layer.addprop('density', eql.estimate_) assert_allclose(eql[0].predicted(), data, rtol=0.01) xp, yp, zp = gridder.regular(area, shape, z=-100) true = prism.gz(xp, yp, zp, model) calc = sphere.gz(xp, yp, zp, layer) assert_allclose(calc, true, atol=0.001, rtol=0.05)
# Make synthetic data props = {'density': 1000} model = [mesher.Prism(-500, 500, -1000, 1000, 500, 4000, props)] shape = (50, 50) x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=0) gz = utils.contaminate(prism.gz(x, y, z, model), 0.1, seed=0) # Setup the layer layer = mesher.PointGrid([-5000, 5000, -5000, 5000], 200, (100, 100)) # Estimate the density using the PEL (it is faster and more memory efficient # than the traditional equivalent layer). windows = (20, 20) degree = 1 misfit = PELGravity(x, y, z, gz, layer, windows, degree) # Apply a smoothness constraint to the borders of the equivalent layer windows # to avoid gaps in the physical property distribution solver = misfit + 1e-18 * PELSmoothness(layer, windows, degree) solver.fit() # Add the estimated density distribution to the layer object for plotting and # forward modeling 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))
# Make synthetic data inc, dec = -60, 23 props = {'magnetization': 10} model = [mesher.Prism(-500, 500, -1000, 1000, 500, 4000, props)] shape = (50, 50) x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=-150) tf = utils.contaminate(prism.tf(x, y, z, model, inc, dec), 5, seed=0) # Setup the layer layer = mesher.PointGrid([-5000, 5000, -5000, 5000], 200, (100, 100)) # Estimate the density using the PEL (it is faster and more memory efficient # than the traditional equivalent layer). windows = (20, 20) degree = 1 misfit = PELTotalField(x, y, z, tf, inc, dec, layer, windows, degree) regul = PELSmoothness(layer, windows, degree) # Use an L-curve analysis to find the best regularization parameter solver = LCurve(misfit, regul, [10 ** i for i in range(-20, -10)]).fit() layer.addprop('magnetization', solver.estimate_) residuals = solver.residuals() print "Residuals:" print "mean:", residuals.mean() print "stddev:", residuals.std() # 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')