def test_general(): """ General test of the class SRTomo, as it is in the docs of this class. """ model = SquareMesh((0, 10, 0, 10), shape=(2, 1), props={'vp': [2., 5.]}) src = (5, 0) srcs = [src, src] recs = [(0, 0), (5, 10)] ttimes = ttime2d.straight(model, 'vp', srcs, recs) mesh = SquareMesh((0, 10, 0, 10), shape=(2, 1)) tomo = srtomo.SRTomo(ttimes, srcs, recs, mesh) assert_array_almost_equal(tomo.fit().estimate_, np.array([2., 5.]), 9)
def test_jacobian(): """ srtomo.SRTomo.jacobian return the jacobian of the model provided. In this simple model, the jacobian can be easily calculated. """ model = SquareMesh((0, 10, 0, 10), shape=(2, 1), props={'vp': [2., 5.]}) src = (5, 0) srcs = [src, src] recs = [(0, 0), (5, 10)] ttimes = ttime2d.straight(model, 'vp', srcs, recs) mesh = SquareMesh((0, 10, 0, 10), shape=(2, 1)) tomo = srtomo.SRTomo(ttimes, srcs, recs, mesh) assert_array_almost_equal(tomo.jacobian().todense(), np.array([[5., 0.], [5., 5.]]), 9)
def test_predicted(): """ Test to verify srtomo.SRTomo.predicted function. Given the correct parameters, this function must return the result of the forward data. """ model = SquareMesh((0, 10, 0, 10), shape=(2, 1), props={'vp': [2., 5.]}) src = (5, 0) srcs = [src, src] recs = [(0, 0), (5, 10)] ttimes = ttime2d.straight(model, 'vp', srcs, recs) mesh = SquareMesh((0, 10, 0, 10), shape=(2, 1)) tomo = srtomo.SRTomo(ttimes, srcs, recs, mesh) # The parameter used inside the class is slowness, so 1/vp. tomo.p_ = np.array([1. / 2., 1. / 5.]) assert_array_almost_equal(tomo.predicted(), ttimes, 9)
""" 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
refraction (Snell's Law). Results can be significantly distorted, particularly on highly heterogeneous media. """ 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)
""" 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
Seismic: 2D straight-ray tomography using damping regularization Uses synthetic data and a model generated from an image file. """ import urllib import time import numpy from fatiando.mesher import SquareMesh from fatiando.seismic import ttime2d, srtomo from fatiando.inversion.regularization import Damping from fatiando.vis import mpl from fatiando import utils area = (0, 500000, 0, 500000) shape = (30, 30) model = SquareMesh(area, shape) # Fetch the image from the online docs urllib.urlretrieve( 'http://fatiando.readthedocs.org/en/latest/_static/logo.png', 'logo.png') model.img2prop('logo.png', 4000, 10000, 'vp') # 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
This simple tomography is implemented in the :class:`~fatiando.seismic.srtomo.SRTomo` class. The example below uses 3 forms of regularization to invert a synthetic data-set. """ 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]
regularization Uses synthetic data and a model generated from an image file. """ import urllib from os import path import numpy from fatiando.mesher import SquareMesh from fatiando.seismic import ttime2d, srtomo from fatiando.inversion.regularization import TotalVariation2D from fatiando.vis import mpl from fatiando import utils area = (0, 100000, 0, 100000) shape = (20, 20) model = SquareMesh(area, shape) # Fetch the image from the online docs urllib.urlretrieve( 'http://fatiando.readthedocs.org/en/latest/_static/logo.png', 'logo.png') vmin, vmax = 4000, 10000 model.img2prop('logo.png', vmin, vmax, 'vp') # 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)