Пример #1
0
        x1 = mesh.get_layer(i)[j].x1
        x2 = mesh.get_layer(i)[j].x2
        y1 = mesh.get_layer(i)[j].y1
        y2 = mesh.get_layer(i)[j].y2
        z1 = mesh.get_layer(i)[j].z1
        z2 = mesh.get_layer(i)[j].z2
        den = mesh.get_layer(i)[j].props
        model=[geometry.Prism(x1, x2, y1, y2, z1, z2, 
                              {'magnetization': giutils.ang2vec(1, inc, dec)})]
        field = prism.tf(xp, yp, zp, model, inc, dec)
        kernel.append(field)       
     
kk=np.transpose(kernel)  #kernel matrix for inversion, 500 cells * 400 points
field_mag=np.mat(kk)*np.transpose(np.mat(mag1.ravel()))
field_gra=np.mat(kernelgz)*np.transpose(np.mat(rho1.ravel()))
field_mag1 = giutils.contaminate(np.array(field_mag).ravel(), 0.05, percent = True)
field_gra1 = giutils.contaminate(np.array(field_gra).ravel(), 0.05, percent = True)

#保存正演异常
with open(graoutfile, 'w') as f:
    f.write('! model 2 gravity anomlay (mGal)\n')
    f.write('{}\n'.format(len(field_gra)))
    for i in range(len(field_gra)):
        f.write('{} {} {} {}\n'.format(yp[i],xp[i],zp[i],np.array(field_gra[i]).ravel()[0]))
        
with open(magoutfile, 'w') as f:
    f.write('! model 2 magtotal-field magnetic anomaly (nT)\n')
    f.write('{}\n'.format(len(field_mag)))
    for i in range(len(field_mag)):
        f.write('{} {} {} {}\n'.format(yp[i],xp[i],zp[i],np.array(field_mag[i]).ravel()[0]))
    
Пример #2
0
"""
GravMag: Calculating the derivatives of the gravity anomaly using FFT
"""
import matplotlib.pyplot as plt
from geoist import gridder
from geoist.inversion import geometry
from geoist.pfm import prism, pftrans, giutils
from geoist.vis import giplt

model = [geometry.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'density': 100})]
area = (-5000, 5000, -5000, 5000)
shape = (51, 51)
z0 = -500
xp, yp, zp = gridder.regular(area, shape, z=z0)
gz = giutils.contaminate(prism.gz(xp, yp, zp, model), 0.001)

# Need to convert gz to SI units so that the result can be converted to Eotvos
gxz = giutils.si2eotvos(pftrans.derivx(xp, yp, giutils.mgal2si(gz), shape))
gyz = giutils.si2eotvos(pftrans.derivy(xp, yp, giutils.mgal2si(gz), shape))
gzz = giutils.si2eotvos(pftrans.derivz(xp, yp, giutils.mgal2si(gz), shape))

gxz_true = prism.gxz(xp, yp, zp, model)
gyz_true = prism.gyz(xp, yp, zp, model)
gzz_true = prism.gzz(xp, yp, zp, model)

plt.figure()
plt.title("Original gravity anomaly")
plt.axis('scaled')
giplt.contourf(xp, yp, gz, shape, 15)
plt.colorbar(shrink=0.7)
giplt.m2km()
Пример #3
0
        x1 = mesh.get_layer(i)[j].x1
        x2 = mesh.get_layer(i)[j].x2
        y1 = mesh.get_layer(i)[j].y1
        y2 = mesh.get_layer(i)[j].y2
        z1 = mesh.get_layer(i)[j].z1
        z2 = mesh.get_layer(i)[j].z2
        den = mesh.get_layer(i)[j].props
        model=[geometry.Prism(x1, x2, y1, y2, z1, z2, {'density': 1000.})]
        field = prism.gz(xp, yp, zp, model)
        kernel.append(field)       
        depthz.append((z1+z2)/2.0)
kk=np.array(kernel)        
kk=np.transpose(kernel)  #kernel matrix for inversion, 500 cells * 400 points
field0=np.mat(kk)*np.transpose(np.mat(density.ravel()))

field = giutils.contaminate(np.array(field0).ravel(), 0.05, percent = True)

#零均值
print(field.mean())
#field = field + 300. # field.mean()
#画图

plt.figure(figsize=(16, 8))
plt.subplot(1, 2, 1)
plt.title('gravity anomlay')
plt.axis('scaled')
levels = giplt.contourf(yp * 0.001, xp * 0.001, field0, nshape, 15)
cb = plt.colorbar(orientation='horizontal')
giplt.contour(yp * 0.001, xp * 0.001, field0, nshape,
                levels, clabel=False, linewidth=0.1)
plt.subplot(1, 2, 2)
Пример #4
0
# local imports
from geoist import gridder
from geoist.inversion import geometry
from geoist.pfm import prism, pftrans, giutils
from geoist.vis import giplt

model = [
    geometry.Prism(-3000, -2000, -3000, -2000, 500, 2000, {'density': 1000}),
    geometry.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'density': -800}),
    geometry.Prism(1000, 3000, 2000, 3000, 0, 1000, {'density': 900})
]
area = (-5000, 5000, -5000, 5000)
shape = (50, 50)
z0 = -100
x, y, z = gridder.regular(area, shape, z=z0)
gz = giutils.contaminate(prism.gz(x, y, z, model), 0.5, seed=0)

height = 1000  # How much higher to go
gzcontf = pftrans.upcontinue(x, y, gz, shape, height)

# Compute the true value at the new height for comparison
gztrue = prism.gz(x, y, z - height, model)

args = dict(shape=shape, levels=20, cmap=plt.cm.RdBu_r)
fig, axes = plt.subplots(1, 3, figsize=(12, 3.5))
axes = axes.ravel()
plt.sca(axes[0])
plt.title("Original")
plt.axis('scaled')
giplt.contourf(x, y, gz, **args)
plt.colorbar(pad=0).set_label('mGal')
Пример #5
0
from geoist.inversion import geometry
from geoist.pfm import prism, pftrans, giutils
from geoist.vis import giplt

# Direction of the Geomagnetic field
inc, dec = -60, 0
# Make a model with only induced magnetization
model = [
    geometry.Prism(-100, 100, -100, 100, 0, 2000,
                   {'magnetization': giutils.ang2vec(10, inc, dec)})
]
area = (-5000, 5000, -5000, 5000)
shape = (100, 100)
z0 = -500
x, y, z = gridder.regular(area, shape, z=z0)
tf = giutils.contaminate(prism.tf(x, y, z, model, inc, dec), 1, seed=0)
# Reduce to the pole using FFT. Since there is only induced magnetization, the
# magnetization direction (sinc and sdec) is the same as the geomagnetic field
pole = pftrans.reduce_to_pole(x, y, tf, shape, inc, dec, sinc=inc, sdec=dec)
# Calculate the true value at the pole for comparison
true = prism.tf(x, y, z, model, 90, 0, pmag=giutils.ang2vec(10, 90, 0))

fig, axes = plt.subplots(1, 3, figsize=(14, 4))
for ax in axes:
    ax.set_aspect('equal')
plt.sca(axes[0])
plt.title("Original total field anomaly")
giplt.contourf(y, x, tf, shape, 30, cmap=plt.cm.RdBu_r)
plt.colorbar(pad=0).set_label('nT')
giplt.m2km()
plt.sca(axes[1])
Пример #6
0
from geoist.pfm import giutils as utils
import numpy as np
import matplotlib.pyplot as plt

# Make some synthetic data to test the inversion
# The model will be a polygon.
# Reverse x because vertices must be clockwise.
xs = np.linspace(0, 100000, 100)[::-1]
depths = (-1e-15 * (xs - 50000)**4 + 8000 - 3000 * np.exp(-(xs - 70000)**2 /
                                                          (10000**2)))
depths -= depths.min()  # Reduce depths to zero
props = {'density': -300}
model = Polygon(np.transpose([xs, depths]), props)
x = np.linspace(0, 100000, 100)
z = -100 * np.ones_like(x)
data = utils.contaminate(talwani.gz(x, z, [model]), 0.5, seed=0)

# Make the solver using smoothness regularization and run the inversion
misfit = PolygonalBasinGravity(x, z, data, 50, props, top=0)
regul = Smoothness1D(misfit.nparams)
solver = misfit + 1e-4 * regul
# This is a non-linear problem so we need to pick an initial estimate
initial = 3000 * np.ones(misfit.nparams)
solver.config('levmarq', initial=initial).fit()
plt.figure()
plt.subplot(2, 1, 1)
plt.plot(x, data, 'ok', label='observed')
plt.plot(x, solver[0].predicted(), '-r', linewidth=2, label='predicted')
plt.legend()
ax = plt.subplot(2, 1, 2)
giplt.polygon(model, fill='gray', alpha=0.5, label='True')
Пример #7
0
"""
# 3rd imports
import matplotlib.pyplot as plt
# local imports
from geoist import gridder
from geoist.inversion import geometry
from geoist.pfm import prism, giutils
from geoist.vis import giplt


model = [geometry.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'density': 1000})]
shape = (100, 100)
xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-200)
components = [prism.gxx, prism.gxy, prism.gxz,
              prism.gyy, prism.gyz, prism.gzz]
print("Calculate the tensor components and contaminate with 5 Eotvos noise")
ftg = [giutils.contaminate(comp(xp, yp, zp, model), 5.0) for comp in components]

print("Plotting...")
plt.figure(figsize=(14, 6))
plt.suptitle("Contaminated FTG data")
names = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz']
for i, data in enumerate(ftg):
    plt.subplot(2, 3, i + 1)
    plt.title(names[i])
    plt.axis('scaled')
    levels = giplt.contourf(xp * 0.001, yp * 0.001, data, (100, 100), 12)
    plt.colorbar()
    giplt.contour(xp * 0.001, yp * 0.001, data, shape, levels, clabel=False)
plt.show()
Пример #8
0
from geoist.inversion import geometry
from geoist.pfm import prism
from geoist.vis import giplt

model = [
    geometry.Prism(-4000, -3000, -4000, -3000, 0, 2000, {'density': 1000}),
    geometry.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'density': -900}),
    geometry.Prism(2000, 4000, 3000, 4000, 0, 2000, {'density': 1300})
]
shape = (100, 100)
xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-150)

field0 = prism.potential(xp, yp, zp, model)

from geoist.pfm import giutils
field0 = giutils.contaminate(field0, 0.05, percent=True)

fields = [
    prism.gx(xp, yp, zp, model),
    prism.gy(xp, yp, zp, model),
    prism.gz(xp, yp, zp, model),
    prism.gxx(xp, yp, zp, model),
    prism.gxy(xp, yp, zp, model),
    prism.gxz(xp, yp, zp, model),
    prism.gyy(xp, yp, zp, model),
    prism.gyz(xp, yp, zp, model),
    prism.gzz(xp, yp, zp, model)
]
titles = [
    'potential', 'gx', 'gy', 'gz', 'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'
]
Пример #9
0
area = (0, 2, 0, 2)
shape = (10, 10)
model = SquareMesh(area, shape)
vp = 4*np.ones(shape)
vp[3:7,3:7] = 10
print(vp)

model.addprop('vp', vp.ravel())
src_loc_x, src_loc_y = scatter(area, 30, seed=0)
src_loc = np.transpose([src_loc_x, src_loc_y])
rec_loc_x, rec_loc_y = circular_scatter(area, 20, random=True, seed=0)
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 = giutils.contaminate(tts, 0.01, percent=True, seed=0)

# Now we can setup a tomography by creating the necessary data misfit
# (``SRTomo``) and regularization (``Smoothness2D``) objects. We'll normalize
# the data misfit by the number of data points to make the scale of the
# regularization parameter more tractable.

mesh = SquareMesh(area, shape)
datamisfit = (1./tts.size)*SRTomo(tts, srcs, recs, mesh)
regul = Smoothness2D(mesh.shape)

# The tomography solver will be the ``LCurve`` solver. It works by calling
# ``fit()`` and accessing ``estimate_``, exactly like any other solver:

regul_params = [10**i for i in range(-10, -2, 1)]
tomo = LCurve(datamisfit, regul, regul_params)
Пример #10
0
# Make a velocity model to calculate traveltimes
area = (0, 10, 0, 10)
vp, vs = 2, 1
model = [Square(area, props={'vp': vp, 'vs': vs})]

src = (5, 5)
srcs = [src, src, src, src]
recs = [(1, 2), (3, 6), (4, 7), (2, 8)]

#giutils.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 = giutils.contaminate(stime - ptime,
                                        0.05,
                                        percent=True,
                                        return_stddev=True)
solver = Homogeneous(traveltime, recs, vp, vs)

initial = (1, 1)
estimate = solver.config('levmarq', initial=initial).fit().estimate_

plt.figure(figsize=(10, 4))
plt.subplot(1, 2, 1)
plt.title('Epicenter + %d recording stations' % (len(recs)))
plt.axis('scaled')
giplt.points(src, '*y', label="True")
giplt.points(recs, '^r', label="Stations")
giplt.points(initial, '*b', label="Initial")
giplt.points([estimate], '*g', label="Estimate")
giplt.set_area(area)
Пример #11
0
"""
GravMag: Calculate the analytic signal of a total field anomaly using FFT
"""
import matplotlib.pyplot as plt
from geoist import gridder
from geoist.inversion import geometry
from geoist.pfm import prism, pftrans, giutils
from geoist.vis import giplt

model = [geometry.Prism(-100, 100, -100, 100, 0, 2000, {'magnetization': 10})]
area = (-5000, 5000, -5000, 5000)
shape = (100, 100)
z0 = -500
x, y, z = gridder.regular(area, shape, z=z0)
inc, dec = -30, 0
tf = giutils.contaminate(prism.tf(x, y, z, model, inc, dec), 0.001,
                       percent=True)

# Need to convert gz to SI units so that the result is also in SI
total_grad_amp = pftrans.tga(x, y, giutils.nt2si(tf), shape)

plt.figure()
plt.subplot(1, 2, 1)
plt.title("Original total field anomaly")
plt.axis('scaled')
giplt.contourf(y, x, tf, shape, 30, cmap=plt.cm.RdBu_r)
plt.colorbar(orientation='horizontal').set_label('nT')
giplt.m2km()
plt.subplot(1, 2, 2)
plt.title("Total Gradient Amplitude")
plt.axis('scaled')
giplt.contourf(y, x, total_grad_amp, shape, 30, cmap=plt.cm.RdBu_r)
Пример #12
0
from geoist.pfm.giutils import ang2vec, contaminate
from geoist.pfm import sphere
from geoist.pfm.magdir import DipoleMagDir
from geoist.vis import giplt

# Make noise-corrupted synthetic data
inc, dec = -10.0, -15.0  # inclination and declination of the Geomagnetic Field
model = [
    geometry.Sphere(3000, 3000, 1000, 1000,
                    {'magnetization': ang2vec(6.0, -20.0, -10.0)}),
    geometry.Sphere(7000, 7000, 1000, 1000,
                    {'magnetization': ang2vec(10.0, 3.0, -67.0)})
]
area = (0, 10000, 0, 10000)
x, y, z = gridder.scatter(area, 1000, z=-150, seed=0)
tf = contaminate(sphere.tf(x, y, z, model, inc, dec), 5.0, seed=0)

# Give the centers of the dipoles
centers = [[3000, 3000, 1000], [7000, 7000, 1000]]

# Estimate the magnetization vectors
solver = DipoleMagDir(x, y, z, tf, inc, dec, centers).fit()

# Print the estimated and true dipole monents, inclinations and declinations
print('Estimated magnetization (intensity, inclination, declination)')
for e in solver.estimate_:
    print(e)

# Plot the fit and the normalized histogram of the residuals
plt.figure(figsize=(14, 5))
plt.subplot(1, 2, 1)