""" Seismic: 2D straight-ray tomography using smoothness regularization """ import numpy as np from fatiando.mesher import SquareMesh from fatiando.seismic import ttime2d, srtomo from fatiando.inversion.regularization import Smoothness2D, LCurve from fatiando.vis import mpl from fatiando import utils area = (0, 500000, 0, 500000) shape = (30, 30) model = SquareMesh(area, shape) vel = 4000 * np.ones(shape) vel[5:25, 5:25] = 10000 model.addprop('vp', vel.ravel()) # Make some travel time data and add noise seed = 0 # Set the random seed so that points are the same every time src_loc = utils.random_points(area, 80, seed=seed) 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
""" import numpy as np import matplotlib.pyplot as plt from fatiando.mesher import SquareMesh from fatiando.seismic import ttime2d, srtomo from fatiando.inversion import Smoothness2D, Damping, TotalVariation2D from fatiando import utils, gridder # First, we'll create a simple model with a high velocity square in the middle area = (0, 500000, 0, 500000) shape = (30, 30) model = SquareMesh(area, shape) vel = 4000 * np.ones(shape) vel[5:25, 5:25] = 10000 model.addprop('vp', vel.ravel()) # Make some noisy travel time data using straight-rays # Set the random seed so that points are the same every time we run this script seed = 0 src_loc_x, src_loc_y = gridder.scatter(area, 80, seed=seed) src_loc = np.transpose([src_loc_x, src_loc_y]) rec_loc_x, rec_loc_y = gridder.circular_scatter(area, 30, random=True, seed=seed) rec_loc = np.transpose([rec_loc_x, rec_loc_y]) srcs = [src for src in src_loc for _ in rec_loc] recs = [rec for _ in src_loc for rec in rec_loc] tts = ttime2d.straight(model, 'vp', srcs, recs) # Use 2% random noise to corrupt the data tts = utils.contaminate(tts, 0.02, percent=True, seed=seed)
""" Seismic: 2D straight-ray tomography using smoothness regularization """ import numpy as np from fatiando.mesher import SquareMesh from fatiando.seismic import ttime2d, srtomo from fatiando.inversion.regularization import Smoothness2D, LCurve from fatiando.vis import mpl from fatiando import utils area = (0, 500000, 0, 500000) shape = (30, 30) model = SquareMesh(area, shape) vel = 4000 * np.ones(shape) vel[5:25, 5:25] = 10000 model.addprop('vp', vel.ravel()) # Make some travel time data and add noise seed = 0 # Set the random seed so that points are the same every time src_loc = utils.random_points(area, 80, seed=seed) 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
# Make some travel time data and add noise seed = 0 # Set the random seed so that points are the same everythime src_loc = utils.random_points(area, 80, seed=seed) 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) # Make the mesh mesh = SquareMesh(area, shape) # and run the inversion start = time.time() tomo = srtomo.SRTomo(tts, srcs, recs, mesh) + 10**6*Damping(mesh.size) estimate = tomo.fit().estimate_ residuals = tomo.residuals() print "time: %g s" % (time.time() - start) mesh.addprop('vp', estimate) # Calculate and print the standard deviation of the residuals # it should be close to the data error if the inversion was able to fit the data print "Assumed error: %g" % (error) print "Standard deviation of residuals: %g" % (numpy.std(residuals)) mpl.figure(figsize=(14, 5)) mpl.subplot(1, 2, 1) mpl.axis('scaled') mpl.title('Vp synthetic model of the Earth') mpl.squaremesh(model, prop='vp', cmap=mpl.cm.seismic) cb = mpl.colorbar() cb.set_label('Velocity') mpl.points(src_loc, '*y', label="Sources") mpl.points(rec_loc, '^r', label="Receivers")
""" import numpy as np import matplotlib.pyplot as plt from fatiando.mesher import SquareMesh from fatiando.seismic import ttime2d, srtomo from fatiando.inversion import Smoothness2D, Damping, TotalVariation2D from fatiando import utils, gridder # First, we'll create a simple model with a high velocity square in the middle area = (0, 500000, 0, 500000) shape = (30, 30) model = SquareMesh(area, shape) vel = 4000 * np.ones(shape) vel[5:25, 5:25] = 10000 model.addprop('vp', vel.ravel()) # Make some noisy travel time data using straight-rays # Set the random seed so that points are the same every time we run this script seed = 0 src_loc_x, src_loc_y = gridder.scatter(area, 80, seed=seed) src_loc = np.transpose([src_loc_x, src_loc_y]) rec_loc_x, rec_loc_y = gridder.circular_scatter(area, 30, random=True, seed=seed) rec_loc = np.transpose([rec_loc_x, rec_loc_y]) srcs = [src for src in src_loc for _ in rec_loc] recs = [rec for _ in src_loc for rec in rec_loc] tts = ttime2d.straight(model, 'vp', srcs, recs) # Use 2% random noise to corrupt the data
src_loc = utils.random_points(area, 80, seed=seed) 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) # Make the mesh mesh = SquareMesh(area, shape) # and run the inversion tomo = (srtomo.SRTomo(tts, srcs, recs, mesh) + 1*TotalVariation2D(10**-8, mesh.shape)) # Since Total Variation is a non-linear function, then the tomography becomes # non-linear. So we need to configure fit to use the Levemberg-Marquardt # algorithm, a gradient descent method, that requires an initial estimate tomo.config('levmarq', initial=0.0005*numpy.ones(mesh.size)).fit() residuals = tomo.residuals() mesh.addprop('vp', tomo.estimate_) # Calculate and print the standard deviation of the residuals # it should be close to the data error if the inversion was able to fit the data print "Assumed error: %f" % (error) print "Standard deviation of residuals: %f" % (numpy.std(residuals)) mpl.figure(figsize=(14, 5)) mpl.subplot(1, 2, 1) mpl.axis('scaled') mpl.title('Vp synthetic model of the Earth') mpl.squaremesh(model, prop='vp', vmin=vmin, vmax=vmax, cmap=mpl.cm.seismic) cb = mpl.colorbar() cb.set_label('Velocity') mpl.points(src_loc, '*y', label="Sources")