Пример #1
0
def test_gridder_circular_scatter_num_point():
    "gridder.circular_scatter returns a specified ``n`` number of points."
    area = [0, 1000, 0, 1000]
    size = 1000
    x, y = gridder.circular_scatter(area, size, random=False)
    assert x.size == size and y.size == size
    x, y = gridder.circular_scatter(area, size, random=True)
    assert x.size == size and y.size == size
Пример #2
0
def test_gridder_circular_scatter():
    "gridder.circular_scatter return diff sequence"
    area = [-1000, 1200, -40, 200]
    size = 1300
    for i in xrange(20):
        x1, y1 = gridder.circular_scatter(area, size, random=True)
        x2, y2 = gridder.circular_scatter(area, size, random=True)
        assert numpy.all(x1 != x2) and numpy.all(y1 != y2)
Пример #3
0
def test_gridder_circular_scatter_seed():
    "gridder.circular_scatter returns same sequence using same random seed"
    area = [0, 1000, 0, 1000]
    size = 1000
    for seed in numpy.random.randint(low=0, high=10000, size=20):
        x1, y1 = gridder.circular_scatter(area, size, random=True, seed=seed)
        x2, y2 = gridder.circular_scatter(area, size, random=True, seed=seed)
        assert numpy.all(x1 == x2) and numpy.all(y1 == y2)
Пример #4
0
def test_gridder_circular_scatter_constant():
    """
    gridder.circular_scatter must return points with the distance between
    consecutive ones with a constant value, when ``random = False``.
    """
    area = [0, 1000, 0, 1000]
    size = 1000
    x, y = gridder.circular_scatter(area, size, random=False)
    distances = numpy.sqrt((x[1:] - x[:-1])**2 + (y[1:] - y[:-1])**2)
    assert_allclose(distances, distances[0] * numpy.ones(size - 1), rtol=1e-09)
Пример #5
0
def test_gridder_circular_scatter_seed_noseed():
    "gridder.circular_scatter returns diff sequence after using random seed"
    area = [0, 1000, 0, 1000]
    z = 20
    size = 1000
    seed = 1242
    x1, y1, z1 = gridder.circular_scatter(area,
                                          size,
                                          z,
                                          random=True,
                                          seed=seed)
    x2, y2, z2 = gridder.circular_scatter(area,
                                          size,
                                          z,
                                          random=True,
                                          seed=seed)
    assert numpy.all(x1 == x2) and numpy.all(y1 == y2)
    assert numpy.all(z1 == z2)
    x3, y3, z3 = gridder.circular_scatter(area, size, z, random=True)
    assert numpy.all(x1 != x3) and numpy.all(y1 != y3)
    assert numpy.all(z1 == z3)
    x4, y4, z4 = gridder.circular_scatter(area, size, z, random=False)
    assert numpy.all(x1 != x4) and numpy.all(y1 != y4)
Пример #6
0
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)

# Make a mesh for the inversion. The inversion will estimate the velocity in
# each square of the mesh. To make things simpler, we'll use a mesh that is the
# same as our original model.
mesh = SquareMesh(area, shape)

# Create solvers for each type of regularization and fit the synthetic data to
# obtain an estimated velocity model
solver = srtomo.SRTomo(tts, srcs, recs, mesh)
Пример #7
0
from fatiando.vis import mpl
from fatiando import utils, gridder

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 everythime
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)
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
tomo = (srtomo.SRTomo(tts, srcs, recs, mesh) +
        30 * TotalVariation2D(1e-10, mesh.shape))