コード例 #1
0
rec_loc = utils.circular_points(area, 30, random=True, seed=seed)
srcs, recs = utils.connect_points(src_loc, rec_loc)
tts = ttime2d.straight(model, 'vp', srcs, recs)
tts, error = utils.contaminate(tts,
                               0.02,
                               percent=True,
                               return_stddev=True,
                               seed=seed)
# Make the mesh
mesh = SquareMesh(area, shape)
# and run the inversion
misfit = srtomo.SRTomo(tts, srcs, recs, mesh)
regularization = Smoothness2D(mesh.shape)
# Will use the l-curve criterion to find the best regularization parameter
tomo = LCurve(misfit,
              regularization, [10**i for i in np.arange(0, 10, 1)],
              jobs=8).fit()
mesh.addprop('vp', tomo.estimate_)

# Plot the L-curve annd print the regularization parameter estimated
mpl.figure()
mpl.title('L-curve: triangle marks the best solution')
tomo.plot_lcurve()
print "Estimated regularization parameter: %g" % (tomo.regul_param_)

# Calculate and print the standard deviation of the residuals
# Should be close to the data error if the inversion was able to fit the data
residuals = tomo.residuals()
print "Assumed error: %g" % (error)
print "Standard deviation of residuals: %g" % (np.std(residuals))
コード例 #2
0
rec_loc = utils.circular_points(area, 30, random=True, seed=seed)
srcs, recs = utils.connect_points(src_loc, rec_loc)
tts = ttime2d.straight(model, 'vp', srcs, recs)
tts, error = utils.contaminate(tts,
                               0.01,
                               percent=True,
                               return_stddev=True,
                               seed=seed)
# Make the mesh
mesh = SquareMesh(area, shape)
# and run the inversion
misfit = srtomo.SRTomo(tts, srcs, recs, mesh)
regularization = Damping(mesh.size)
# Will use the l-curve criterion to find the best regularization parameter
tomo = LCurve(misfit,
              regularization, [8**i for i in np.arange(-8, 8, 1)],
              jobs=8).fit()
mesh.addprop('vp', tomo.estimate_)

# Plot the L-curve annd print the regularization parameter estimated
mpl.figure()
mpl.title('L-curve: triangle marks the best solution')
tomo.plot_lcurve()
print "Estimated regularization parameter: %g" % (tomo.regul_param_)

# Calculate and print the standard deviation of the residuals
# Should be close to the data error if the inversion was able to fit the data
residuals = tomo.residuals()
print "Assumed error: %g" % (error)
print "Standard deviation of residuals: %g" % (np.std(residuals))
コード例 #3
0
# Make synthetic data
inc, dec = -60, 23
props = {'magnetization': 10}
model = [mesher.Prism(-500, 500, -1000, 1000, 500, 4000, props)]
shape = (25, 25)
x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=0)
tf = utils.contaminate(prism.tf(x, y, z, model, inc, dec), 5, seed=0)
# Setup the layer
layer = mesher.PointGrid([-7000, 7000, -7000, 7000], 700, (50, 50))
# Estimate the magnetization intensity
# Need to apply regularization so that won't try to fit the error as well
misfit = EQLTotalField(x, y, z, tf, inc, dec, layer)
regul = Damping(layer.size)
# Use an L-curve analysis to find the best regularization parameter
solver = LCurve(misfit, regul, [10 ** i for i in range(-30, -15)]).fit()
residuals = solver.residuals()
layer.addprop('magnetization', solver.estimate_)
print "Residuals:"
print "mean:", residuals.mean()
print "stddev:", residuals.std()

# 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()
コード例 #4
0
# Reverse x because vertices must be clockwise.
xs = np.linspace(0, 100000, 100)[::-1]
depths = (-1e-15*(xs - 50000)**4 + 8000 -
          3000*np.exp(-(xs - 70000)**2/(10000**2)))
depths -= depths.min()  # Reduce depths to zero
props = {'density': -300}
model = Polygon(np.transpose([xs, depths]), props)
x = np.linspace(0, 100000, 100)
z = -100*np.ones_like(x)
data = utils.contaminate(talwani.gz(x, z, [model]), 0.5, seed=0)

# Make the solver and run the inversion
misfit = PolygonalBasinGravity(x, z, data, 50, props, top=0)
regul = Smoothness1D(misfit.nparams)
# Use an L-curve analysis to find the best regularization parameter
lc = LCurve(misfit, regul, [10**i for i in np.arange(-10, -5, 0.5)], jobs=4)
initial = 3000*np.ones(misfit.nparams)
lc.config('levmarq', initial=initial).fit()

mpl.figure()
mpl.subplot(2, 2, 1)
mpl.plot(x, data, 'ok', label='observed')
mpl.plot(x, lc.predicted(), '-r', linewidth=2, label='predicted')
mpl.legend()
ax = mpl.subplot(2, 2, 3)
mpl.polygon(model, fill='gray', alpha=0.5)
mpl.polygon(lc.estimate_, style='o-r')
ax.invert_yaxis()
mpl.subplot(1, 2, 2)
mpl.title('L-curve')
lc.plot_lcurve()