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