コード例 #1
0
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,
              regularization, [10**i for i in np.arange(0, 10, 1)],
              jobs=8).fit()
コード例 #2
0
import sys
from matplotlib import pyplot
import numpy
from fatiando.mesher.dd import Square
from fatiando.seismic import epicenter, traveltime
from fatiando import vis, logger, utils, inversion, gridder, ui
import cPickle as pickle

area = (0, 10, 0, 10)
vp, vs = 2, 1
model = [Square(area, props={'vp': vp, 'vs': vs})]

with open('dados.pickle') as f:
    src, rec_points, ttr, error, ttr_true = pickle.load(f)

srcs, recs = utils.connect_points(src, rec_points)

shape = (50, 50)
xs, ys = gridder.regular(area, shape)
goals = epicenter.mapgoal(xs, ys, ttr, recs, vp, vs)

pyplot.figure()
ax = pyplot.subplot(1, 1, 1)
pyplot.axis('scaled')
pyplot.suptitle("Escolha a estimativa inicial")
vis.map.contourf(xs, ys, goals, shape, 50)
vis.map.points(rec_points, '^r')
vis.map.points(src, '*y')
initial = ui.picker.points(area, ax, marker='*', color='k')
if len(initial) > 1:
    log.error("Don't be greedy! Pick only one initial estimate")
コード例 #3
0
# Pick the locations of the receivers
mpl.figure()
mpl.axis('scaled')
mpl.suptitle("Choose the location of the receivers")
rec_points = mpl.pick_points(area, mpl.gca(), marker='^', color='r')
# and the source
mpl.figure()
mpl.axis('scaled')
mpl.suptitle("Choose the location of the source")
mpl.points(rec_points, '^r')
src = mpl.pick_points(area, mpl.gca(), marker='*', color='y')
if len(src) > 1:
    print "Don't be greedy! Pick only one point as the source"
    sys.exit()
# Calculate the P and S wave traveltimes
srcs, recs = utils.connect_points(src, rec_points)
ptime = ttime2d.straight(model, 'vp', srcs, recs)
stime = ttime2d.straight(model, 'vs', srcs, recs)
# Calculate the residual time (S - P) with added noise
traveltime, error = utils.contaminate(stime - ptime, 0.05, percent=True,
                                      return_stddev=True)
solver = Homogeneous(traveltime, recs, vp, vs)
# Pick the initial estimate and fit
mpl.figure()
mpl.axis('scaled')
mpl.suptitle("Choose the initial estimate")
mpl.points(rec_points, '^r')
mpl.points(src, '*y')
initial = mpl.pick_points(area, mpl.gca(), marker='*', color='b')
if len(initial) > 1:
    print "Don't be greedy! Pick only one point"
コード例 #4
0
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
log.info("Assumed error: %g" % (error))
log.info("Standard deviation of residuals: %g" % (numpy.std(residuals)))
コード例 #5
0
"""
Seismic: 2D epicenter estimation on a flat Earth using equality constraints
"""
import sys
import numpy
from fatiando import mesher, seismic, utils, gridder, vis, inversion

area = (0, 10, 0, 10)
vp, vs = 2, 1
model = [mesher.Square(area, props={'vp': vp, 'vs': vs})]

src = (8, 7)
stations = 10
srcs, recs = utils.connect_points([src], [(4, 6), (5, 5.9), (6, 6)])
ptime = seismic.ttime2d.straight(model, 'vp', srcs, recs)
stime = seismic.ttime2d.straight(model, 'vs', srcs, recs)
error_level = 0.05
ttr_true = stime - ptime
ttr, error = utils.contaminate(ttr_true,
                               error_level,
                               percent=True,
                               return_stddev=True)

vis.mpl.figure()
ax = vis.mpl.subplot(1, 1, 1)
vis.mpl.axis('scaled')
vis.mpl.suptitle("Choose the initial estimate for the gradient solvers")
vis.mpl.points(recs, '^r')
vis.mpl.points(srcs, '*y')
initial = vis.mpl.pick_points(area, ax, marker='*', color='k')
if len(initial) > 1:
コード例 #6
0
"""
Seismic: 2D epicenter estimation on a flat Earth using equality constraints
"""
import sys
import numpy
from fatiando import mesher, seismic, utils, gridder, vis, inversion

area = (0, 10, 0, 10)
vp, vs = 2, 1
model = [mesher.Square(area, props={'vp':vp, 'vs':vs})]

src = (8, 7)
stations = 10
srcs, recs = utils.connect_points([src], [(4, 6), (5, 5.9), (6, 6)])
ptime = seismic.ttime2d.straight(model, 'vp', srcs, recs)
stime = seismic.ttime2d.straight(model, 'vs', srcs, recs)
error_level = 0.05
ttr_true = stime - ptime
ttr, error = utils.contaminate(ttr_true, error_level, percent=True,
                               return_stddev=True)

vis.mpl.figure()
ax = vis.mpl.subplot(1, 1, 1)
vis.mpl.axis('scaled')
vis.mpl.suptitle("Choose the initial estimate for the gradient solvers")
vis.mpl.points(recs, '^r')
vis.mpl.points(srcs, '*y')
initial = vis.mpl.pick_points(area, ax, marker='*', color='k')
if len(initial) > 1:
    print "Don't be greedy! Pick only one initial estimate"
    sys.exit()
コード例 #7
0
pyplot.figure(figsize=(14, 6))
pyplot.suptitle("Escolha o epicentro")
ax = pyplot.subplot(1, 2, 1)
pyplot.axis('scaled')
vis.map.points(recs, '^r', label="Stations")
ax2 = pyplot.subplot(1, 2, 2)
pyplot.title('Tempos de chegada')
s = numpy.arange(len(ttr)) + 1
width = 0.2
pyplot.bar(s - width, ttr, width, color='r')
ax2.set_xticks(s)
pyplot.xlabel("Estacao")
pyplot.ylabel("Tempo de chegada")
src_model = ui.picker.points(area, ax, marker='*', color='y')

srcs, recs = utils.connect_points(src_model, recs)
ptime = traveltime.straight_ray_2d(model, 'vp', srcs, recs)
stime = traveltime.straight_ray_2d(model, 'vs', srcs, recs)
ttr_model = stime - ptime

with open('exercicio2-modelo.pickle', 'w') as f:
    data = {'ttr': ttr_model, 'recs': recs, 'src': src_model}
    pickle.dump(data, f)

pyplot.figure(figsize=(14, 6))
pyplot.subplot(1, 2, 1)
pyplot.title('Epicentros')
pyplot.axis('scaled')
vis.map.points(recs, '^r', label="Estacao")
vis.map.points(src_model, '*y', label="Epicentro")
vis.map.set_area(area)
コード例 #8
0
pyplot.figure(figsize=(14, 6))
pyplot.suptitle("Escolha o epicentro")
ax = pyplot.subplot(1, 2, 1)
pyplot.axis("scaled")
vis.map.points(recs, "^r", label="Stations")
ax2 = pyplot.subplot(1, 2, 2)
pyplot.title("Tempos de chegada")
s = numpy.arange(len(ttr)) + 1
width = 0.2
pyplot.bar(s - width, ttr, width, color="r", yerr=error)
ax2.set_xticks(s)
pyplot.xlabel("Estacao")
pyplot.ylabel("Tempo de chegada")
src_model = ui.picker.points(area, ax, marker="*", color="y")

srcs, recs = utils.connect_points(src_model, recs)
ptime = traveltime.straight_ray_2d(model, "vp", srcs, recs)
stime = traveltime.straight_ray_2d(model, "vs", srcs, recs)
ttr_model = stime - ptime

with open("exercicio3-modelo.pickle", "w") as f:
    data = {"ttr": ttr_model, "recs": recs, "src": src_model}
    pickle.dump(data, f)

pyplot.figure(figsize=(14, 6))
pyplot.subplot(1, 2, 1)
pyplot.title("Epicentros")
pyplot.axis("scaled")
vis.map.points(recs, "^r", label="Estacao")
vis.map.points(src_model, "*y", label="Epicentro")
vis.map.set_area(area)