from geoist.inversion import geometry
from geoist.vis import giplt

# Create a model using geometric objects from fatiando.mesher
# Each model element has a dictionary with its physical properties.
# The spheres have different total magnetization vectors (total = induced +
# remanent + any other effects). Notice that the magnetization has to be a
# vector. Function utils.ang2vec converts intensity, inclination, and
# declination into a 3 component vector for easier handling.
model = [
    geometry.Sphere(
        x=10e3,
        y=10e3,
        z=2e3,
        radius=1.5e3,
        props={'magnetization': giutils.ang2vec(1, inc=50, dec=-30)}),
    geometry.Sphere(
        x=20e3,
        y=20e3,
        z=2e3,
        radius=1.5e3,
        props={'magnetization': giutils.ang2vec(1, inc=-70, dec=30)})
]

# Set the inclination and declination of the geomagnetic field.
inc, dec = -10, 13
# Create a regular grid at a constant height
shape = (300, 300)
area = [0, 30e3, 0, 30e3]
x, y, z = gridder.regular(area, shape, z=-10)
Exemple #2
0
for p in mesh:
    prisms.append(p)
print('kernel')
inc, dec = 30, -4
kernelgz = prism.gz_kernel(xp, yp, zp, prisms)
for i, layer in enumerate(mesh.layers()):
    for j, p in enumerate(layer):
        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]))
Exemple #3
0
using the FFT and allows using a magnetization direction that is different from
the geomagnetic field direction. This example shows how to use it in this case.
Use ``sinc=inc`` and ``sdec=dec`` if there is only induced magnetization.

"""
import matplotlib.pyplot as plt
from geoist.pfm import prism, pftrans, giutils
from geoist.inversion.geometry import Prism
from geoist import gridder

# Create some synthetic magnetic data with a total magnetization that is
# different from the geomagnetic field (so there is remanent magnetization or
# some demagnetizing effect)
inc, dec = -60, 23  # Geomagnetic field direction
sinc, sdec = -30, -20  # Source magnetization direction
mag = giutils.ang2vec(1, sinc, sdec)
model = [Prism(-1500, 1500, -500, 500, 0, 2000, {'magnetization': mag})]
area = (-7e3, 7e3, -7e3, 7e3)
shape = (100, 100)
x, y, z = gridder.regular(area, shape, z=-300)
data = prism.tf(x, y, z, model, inc, dec)

# Reduce to the pole
data_at_pole = pftrans.reduce_to_pole(x, y, data, shape, inc, dec, sinc, sdec)

# Make some plots
plt.figure(figsize=(8, 6))

ax = plt.subplot(1, 2, 1)
ax.set_title('Original data')
ax.set_aspect('equal')
Exemple #4
0
"""
GravMag: 3D forward modeling of total-field magnetic anomaly using rectangular
prisms (model with induced and remanent magnetization)
"""
import matplotlib.pyplot as plt
from geoist import gridder
from geoist.inversion import geometry
from geoist.pfm import prism, giutils
from geoist.vis import giplt

# The regional field
inc, dec = 30, -15
bounds = [-5000, 5000, -5000, 5000, 0, 5000]
model = [
    geometry.Prism(-4000, -3000, -4000, -3000, 0, 2000,
                   {'magnetization': giutils.ang2vec(1, inc, dec)}),
    geometry.Prism(-1000, 1000, -1000, 1000, 0, 2000,
                   {'magnetization': giutils.ang2vec(1, inc, dec)}),
    # This prism will have magnetization in a different direction
    geometry.Prism(2000, 4000, 3000, 4000, 0, 2000,
                   {'magnetization': giutils.ang2vec(3, -10, 45)})
]
# Create a regular grid at 100m height
shape = (200, 200)
area = bounds[:4]
xp, yp, zp = gridder.regular(area, shape, z=-500)
# Calculate the anomaly for a given regional field

tf = prism.tf(xp, yp, zp, model, inc, dec)
# Plot
plt.figure()
"""
GravMag: Reduction to the pole 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

# 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])
from geoist.pfm import sphere, pftrans, euler, giutils
from geoist import gridder
from geoist.inversion import geometry
from geoist.vis import giplt
import matplotlib.pyplot as plt

# Make some synthetic magnetic data to test our Euler deconvolution.
# The regional field
inc, dec = -45, 0
# Make a model of two spheres magnetized by induction only
model = [
    geometry.Sphere(x=-1000,
                    y=-1000,
                    z=1500,
                    radius=1000,
                    props={'magnetization': giutils.ang2vec(2, inc, dec)}),
    geometry.Sphere(x=1000,
                    y=1500,
                    z=1000,
                    radius=1000,
                    props={'magnetization': giutils.ang2vec(1, inc, dec)})
]

print("Centers of the model spheres:")
print(model[0].center)
print(model[1].center)

# Generate some magnetic data from the model
shape = (100, 100)
area = [-5000, 5000, -5000, 5000]
x, y, z = gridder.regular(area, shape, z=-150)
Exemple #7
0
data is already reduced to the pole. You can use
:func:`fatiando.gravmag.transform.reduce_to_pole` to reduce your data.

The zero contour of the tilt is said to outline the body so we've plotted it as
a dashed line on the tilt map.
"""

import matplotlib.pyplot as plt
from geoist.pfm import prism, pftrans, giutils
from geoist.inversion.geometry import Prism
from geoist import gridder

# Create some synthetic magnetic data. We'll assume the data is already reduced
# to the pole.
inc, dec = 90, 0
mag = giutils.ang2vec(1, inc, dec)
model = [Prism(-1500, 1500, -500, 500, 0, 2000, {'magnetization': mag})]
area = (-7e3, 7e3, -7e3, 7e3)
shape = (100, 100)
x, y, z = gridder.regular(area, shape, z=-300)
data_at_pole = prism.tf(x, y, z, model, inc, dec)

# Calculate the tilt
tilt = pftrans.tilt(x, y, data_at_pole, shape)

# Make some plots
plt.figure(figsize=(8, 6))

ax = plt.subplot(1, 2, 1)
ax.set_title('Original data at the pole')
ax.set_aspect('equal')
# 3rd imports
import numpy as np
import matplotlib.pyplot as plt
# local imports
from geoist import gridder
from geoist.inversion import geometry
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)')