def test_utils_random_points():
    "utils.random_points return diff sequence"
    area = [-1000, 1200, -40, 200]
    size = 1300
    for i in xrange(20):
        x1, y1 = utils.random_points(area, size).T
        x2, y2 = utils.random_points(area, size).T
        assert numpy.all(x1 != x2) and numpy.all(y1 != y2)
def test_utils_random_points_seed():
    "utils.random_points 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 = utils.random_points(area, size, seed=seed).T
        x2, y2 = utils.random_points(area, size, seed=seed).T
        assert numpy.all(x1 == x2) and numpy.all(y1 == y2)
Esempio n. 3
0
def test_utils_random_points_seed():
    "utils.random_points 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 = utils.random_points(area, size, seed=seed).T
        x2, y2 = utils.random_points(area, size, seed=seed).T
        assert numpy.all(x1 == x2) and numpy.all(y1 == y2)
Esempio n. 4
0
def test_utils_random_points():
    "utils.random_points return diff sequence"
    area = [-1000, 1200, -40, 200]
    size = 1300
    for i in xrange(20):
        x1, y1 = utils.random_points(area, size).T
        x2, y2 = utils.random_points(area, size).T
        assert numpy.all(x1 != x2) and numpy.all(y1 != y2)
def test_utils_random_points_seed_noseed():
    "utils.random_points returns diff sequence after using random seed"
    area = [0, 1000, 0, 1000]
    size = 1000
    seed = 1242
    x1, y1 = utils.random_points(area, size, seed=seed).T
    x2, y2 = utils.random_points(area, size, seed=seed).T
    assert numpy.all(x1 == x2) and numpy.all(y1 == y2)
    x3, y3 = utils.random_points(area, size).T
    assert numpy.all(x1 != x3) and numpy.all(y1 != y3)
Esempio n. 6
0
def test_utils_random_points_seed_noseed():
    "utils.random_points returns diff sequence after using random seed"
    area = [0, 1000, 0, 1000]
    size = 1000
    seed = 1242
    x1, y1 = utils.random_points(area, size, seed=seed).T
    x2, y2 = utils.random_points(area, size, seed=seed).T
    assert numpy.all(x1 == x2) and numpy.all(y1 == y2)
    x3, y3 = utils.random_points(area, size).T
    assert numpy.all(x1 != x3) and numpy.all(y1 != y3)
Esempio n. 7
0
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
tomo = LCurve(misfit,
from fatiando import logger, mesher, utils, seismic, vis

log = logger.get()
log.info(logger.header())
log.info(__doc__)

area = (0, 500000, 0, 500000)
shape = (30, 30)
model = mesher.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
log.info("Generating synthetic travel-time data")
src_loc = utils.random_points(area, 80)
rec_loc = utils.circular_points(area, 30, random=True)
srcs, recs = utils.connect_points(src_loc, rec_loc)
start = time.time()
tts = seismic.ttime2d.straight(model, "vp", srcs, recs, par=True)
log.info("  time: %s" % (utils.sec2hms(time.time() - start)))
tts, error = utils.contaminate(tts, 0.01, percent=True, return_stddev=True)
# Make the mesh
mesh = mesher.SquareMesh(area, shape)
# and run the inversion
estimate, residuals = seismic.srtomo.run(tts, srcs, recs, mesh, damping=10 ** 9)
# Convert the slowness estimate to velocities and add it the mesh
mesh.addprop("vp", seismic.srtomo.slowness2vel(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
import urllib
from os import path
import numpy
from fatiando import mesher, utils, seismic, vis

area = (0, 500000, 0, 500000)
shape = (30, 30)
model = mesher.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 = seismic.ttime2d.straight(model, 'vp', srcs, recs, par=True)
tts, error = utils.contaminate(tts, 0.01, percent=True, return_stddev=True)
# Make the mesh
mesh = mesher.SquareMesh(area, shape)
# and run the inversion
estimate, residuals = seismic.srtomo.run(tts, srcs, recs, mesh, smooth=2*10**9)
# Convert the slowness estimate to velocities and add it the mesh
mesh.addprop('vp', seismic.srtomo.slowness2vel(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))
"""
import urllib
from os import path
import numpy
from fatiando import mesher, utils, seismic, vis, inversion

area = (0, 100000, 0, 100000)
shape = (100, 100)
model = mesher.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
src_loc = utils.random_points(area, 200)
rec_loc = utils.circular_points(area, 80, random=True)
srcs, recs = utils.connect_points(src_loc, rec_loc)
ttimes = seismic.ttime2d.straight(model, 'vp', srcs, recs, par=True)
ttimes, error = utils.contaminate(ttimes, 0.01, percent=True,
    return_stddev=True)
# Make the mesh
mesh = mesher.SquareMesh(area, shape)
# Since the matrices are big, use the Steepest Descent solver to avoid dealing
# with Hessian matrices. It needs a starting guess, so start with 1000
inversion.gradient.use_sparse()
solver = inversion.gradient.steepest(1000*numpy.ones(mesh.size))
# and run the inversion
estimate, residuals = seismic.srtomo.run(ttimes, srcs, recs, mesh, sparse=True,
    solver=solver, smooth=0.01)
# Convert the slowness estimate to velocities and add it the mesh
Esempio n. 11
0
from matplotlib import pyplot
import numpy
from fatiando.mesher.dd import SquareMesh
from fatiando.seismic import traveltime
from fatiando import vis, logger, utils, inversion
import cPickle as pickle

params = __import__('exercicio1_entrada')

imgfile = params.imagem
area = (0, 5, 0, 5)
shape = params.tamanho
model = SquareMesh(area, shape)
model.img2prop(imgfile, params.vmin, params.vmax, 'vp')

src_loc = utils.random_points(area, params.epicentros)
rec_loc = utils.circular_points(area, params.sismometros, random=True)
srcs, recs = utils.connect_points(src_loc, rec_loc)
tts, error = utils.contaminate(traveltime.straight_ray_2d(
    model, 'vp', srcs, recs),
                               params.ruido,
                               percent=True,
                               return_stddev=True)

with open(params.dados, 'w') as f:
    data = [model, src_loc, rec_loc, tts, error]
    pickle.dump(data, f)

pyplot.figure(figsize=(7, 5))
pyplot.axis('scaled')
pyplot.title('Modelo de velocidades')
Esempio n. 12
0
from matplotlib import pyplot
import numpy
from fatiando.mesher.dd import SquareMesh
from fatiando.seismic import traveltime
from fatiando import vis, logger, utils, inversion
import cPickle as pickle

params = __import__('exercicio1_entrada')

imgfile = params.imagem
area = (0, 5, 0, 5)
shape = params.tamanho
model = SquareMesh(area, shape)
model.img2prop(imgfile, params.vmin, params.vmax, 'vp')

src_loc = utils.random_points(area, params.epicentros)
rec_loc = utils.circular_points(area, params.sismometros, random=True)
srcs, recs = utils.connect_points(src_loc, rec_loc)
tts, error = utils.contaminate(
    traveltime.straight_ray_2d(model, 'vp', srcs, recs), params.ruido, percent=True,
    return_stddev=True)

with open(params.dados, 'w') as f:
    data = [model, src_loc, rec_loc, tts, error]
    pickle.dump(data, f)

pyplot.figure(figsize=(7, 5))
pyplot.axis('scaled')
pyplot.title('Modelo de velocidades')
vis.map.squaremesh(model, model.props['vp'], cmap=pyplot.cm.seismic)
cb = pyplot.colorbar()