def sample(Lx,Ly,Lz,P,m=None,inc=None,dec=None): ''' Define the interpretation model as a 1D array of rectangular prisms along the x-axis. input Lx: float - side length of all prisms along x (m). Ly: float - side length of all prisms along x (m). Lz: float - side length of all prisms along x (m). P: int - number of prisms m: list - magnetization intensity (A/m) of each prism. inc: list - magnetization inclination (graus) of each prism. dec: list - magnetization declination (graus) of each prism. output model: list of geometrical elements mesher class of the Fatiando a Terra package - interpretation model. ''' sizex = Lx sizey = Ly sizez = Lz L = P*sizex a = -0.5*L model = [] if ((m is not None) & (inc is not None) & (dec is not None)): intensity = np.array(m) inclinacao = np.array(inc) declinacao = np.array(dec) mag = [] for i in range(P): mag.append(ang2vec(intensity[i],inclinacao[i],declinacao[i])) for i in range(P): model.append(mesher.Prism(a+i*sizex, a+(i+1)*sizex, \ -0.5*sizey, 0.5*sizey, \ -0.5*sizez, 0.5*sizez, \ {'magnetization': mag[i]})) else: for i in range(P): model.append(mesher.Prism(a+i*sizex, a+(i+1)*sizex, \ -0.5*sizey, 0.5*sizey, \ -0.5*sizez, 0.5*sizez)) return model
def fwd_grav_fatiando(): """ GravMag: 3D imaging using the migration method on synthetic gravity data (more complex model + noisy data) """ # Make some synthetic gravity data from a simple prism model za = 5000 zb = 7000 model = [mesher.Prism(-4000, 0, -4000, -2000, za, zb, {'density': 1200})] #, # mesher.Prism(-1000, 1000, -1000, 1000, 1000, 7000, {'density': -800}), # mesher.Prism(2000, 4000, 3000, 4000, 0, 2000, {'density': 600})] # Calculate on a scatter of points to show that migration doesn't need gridded # data # xp, yp, zp = gridder.scatter((-6000, 6000, -6000, 6000), 1000, z=0) shape = (25, 25) xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=0) #gz = utils.contaminate(prism.gz(xp, yp, zp, model), 0.1) gz = prism.gz(xp, yp, zp, model) # Plot the data shape = (50, 50) mpl.figure() mpl.axis('scaled') mpl.contourf(yp, xp, gz, shape, 30, interp=True) mpl.colorbar() mpl.plot(yp, xp, '.k') mpl.xlabel('East (km)') mpl.ylabel('North (km)') mpl.m2km() mpl.show() return xp, yp, zp, gz, shape, model
def test_gz_prism(): ''' This test compare the results obtained by both function that calculates the vertical gravitational attraction due to a rectangular prism. The model has the same dimensions and same value for the density. We use the function from Fatiando a Terra in order to compare with our function. ''' density = 2600. # Modelo para o Fatiando xp, yp, zp = gridder.regular((-1000, 1000, -1000, 1000), (200, 200), z=-345.) model = [ mesher.Prism(-200., 200., -250., 180., 120., 1000., {'density': density}) ] gz = prism.gz(xp, yp, zp, model) gz = gz.reshape(200, 200) # Modelo para minha funcao x, y = numpy.meshgrid(numpy.linspace(-1000., 1000., 200), numpy.linspace(-1000., 1000., 200)) z = -345. * numpy.ones((200, 200)) mymodel = [-200., 200., -250., 180., 120., 1000., density] mygz = prism_gz(y, x, z, mymodel) assert_almost_equal(gz, mygz, decimal=5)
def test_totalfield_prism(): ''' This test compare the results obtained by both function that calculates the total field anomaly due to a rectangular prism. The model has the same dimensions, magnetization intensity and also the same pair for inclination and declination. We use the function from Fatiando a Terra in order to compare with our function. ''' incf = 30. decf = 30. incs = 60. decs = 45. magnetization = 3. # Modelo para o Fatiando xp, yp, zp = gridder.regular((-1000, 1000, -1000, 1000), (200, 200), z=-345.) model = [ mesher.Prism( -200., 200., -250., 180., 120., 1000., {'magnetization': utils.ang2vec(magnetization, incs, decs)}) ] tf = prism.tf(xp, yp, zp, model, incf, decf) tf = tf.reshape(200, 200) # Modelo para minha funcao x, y = numpy.meshgrid(numpy.linspace(-1000., 1000., 200), numpy.linspace(-1000., 1000., 200)) z = -345. * numpy.ones((200, 200)) mymodel = [-200., 200., -250., 180., 120., 1000., magnetization] mytf = prism_tf(y, x, z, mymodel, incf, decf, incs, decs) assert_almost_equal(tf, mytf, decimal=5)
""" GravMag: Classic 3D Euler deconvolution of magnetic data (single window) """ from fatiando import mesher, gridder, utils, gravmag from fatiando.vis import mpl, myv # The regional field inc, dec = -45, 0 # Make a model bounds = [-5000, 5000, -5000, 5000, 0, 5000] model = [ mesher.Prism(-1500, -500, -500, 500, 1000, 2000, {'magnetization':2})] # Generate some data from the model shape = (200, 200) area = bounds[0:4] xp, yp, zp = gridder.regular(area, shape, z=-1) # Add a constant baselevel baselevel = 10 # Convert from nanoTesla to Tesla because euler and derivatives require things # in SI tf = (utils.nt2si(gravmag.prism.tf(xp, yp, zp, model, inc, dec)) + baselevel) # Calculate the derivatives using FFT xderiv = gravmag.fourier.derivx(xp, yp, tf, shape) yderiv = gravmag.fourier.derivy(xp, yp, tf, shape) zderiv = gravmag.fourier.derivz(xp, yp, tf, shape) mpl.figure() titles = ['Total field', 'x derivative', 'y derivative', 'z derivative'] for i, f in enumerate([tf, xderiv, yderiv, zderiv]): mpl.subplot(2, 2, i + 1) mpl.title(titles[i])
usually require more configuration. """ from __future__ import division, print_function import matplotlib.pyplot as plt import numpy as np from fatiando.gravmag import prism, sphere from fatiando.gravmag.eqlayer import EQLTotalField from fatiando.inversion import Damping from fatiando import gridder, utils, mesher # First thing to do is make some synthetic data to test the method. We'll use a # single prism with only induced magnetization to keep it simple inc, dec = -5, 23 props = {'magnetization': utils.ang2vec(5, inc, dec)} model = [mesher.Prism(-2000, 2000, -200, 200, 100, 4000, props)] # The synthetic data will be generated on a regular grid area = [-8000, 8000, -5000, 5000] shape = (40, 40) x, y, z = gridder.regular(area, shape, z=-150) # Generate some noisy data from our model data = utils.contaminate(prism.tf(x, y, z, model, inc, dec), 5, seed=0) # Now for the equivalent layer. We must setup a layer of dipoles where we'll # estimate a magnetization intensity distribution that fits our synthetic data. # Notice that we only estimate the intensity. We must provide the magnetization # direction of the layer through the sinc and sdec parameters. layer = mesher.PointGrid(area, 700, shape) eql = (EQLTotalField(x, y, z, data, inc, dec, layer, sinc=inc, sdec=dec) + 1e-15*Damping(layer.size))
""" GravMag: Center of mass estimation using the first eigenvector of the gravity gradient tensor (large flat slab model) """ from fatiando.vis import mpl, myv from fatiando import mesher, gridder, utils, gravmag # Generate some synthetic data prisms = [mesher.Prism(-3000, 3000, -3000, 3000, 500, 1000, {'density': 1000})] shape = (100, 100) xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-150) noise = 1 tensor = [ utils.contaminate(gravmag.prism.gxx(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gzz(xp, yp, zp, prisms), noise) ] # Plot the data titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] mpl.figure() for i, title in enumerate(titles): mpl.subplot(3, 2, i + 1) mpl.title(title) mpl.axis('scaled') levels = mpl.contourf(yp, xp, tensor[i], shape, 10) mpl.contour(yp, xp, tensor[i], shape, levels) mpl.m2km() mpl.show()
""" GravMag: Forward modeling of the gravitational potential and its derivatives using 3D prisms """ from fatiando import mesher, gridder, gravmag from fatiando.vis import mpl, myv prisms = [ mesher.Prism(-4000, -3000, -4000, -3000, 0, 2000, {'density': 1000}), mesher.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'density': -900}), mesher.Prism(2000, 4000, 3000, 4000, 0, 2000, {'density': 1300}) ] shape = (100, 100) xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-150) fields = [ gravmag.prism.potential(xp, yp, zp, prisms), gravmag.prism.gx(xp, yp, zp, prisms), gravmag.prism.gy(xp, yp, zp, prisms), gravmag.prism.gz(xp, yp, zp, prisms), gravmag.prism.gxx(xp, yp, zp, prisms), gravmag.prism.gxy(xp, yp, zp, prisms), gravmag.prism.gxz(xp, yp, zp, prisms), gravmag.prism.gyy(xp, yp, zp, prisms), gravmag.prism.gyz(xp, yp, zp, prisms), gravmag.prism.gzz(xp, yp, zp, prisms) ] titles = [ 'potential', 'gx', 'gy', 'gz', 'gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz' ] mpl.figure(figsize=(8, 9)) mpl.subplots_adjust(left=0.03, right=0.95, bottom=0.05, top=0.92, hspace=0.3)
""" GravMag: Using data weights in 3D inversion using :mod:`harvester` """ from fatiando import gravmag, utils, gridder, mesher from fatiando.vis import mpl, myv # Generate some synthetic total field anomaly data bounds = [0, 10000, 0, 10000, 0, 5000] props = {'density': 500} props2 = {'density': 1000} model = [ mesher.Prism(4000, 6000, 4000, 6000, 500, 2500, props), mesher.Prism(2000, 2500, 2000, 2500, 500, 1000, props2), mesher.Prism(7500, 8000, 5500, 6500, 500, 1000, props2), mesher.Prism(1500, 2000, 4000, 5000, 500, 1000, props2) ] area = bounds[:4] shape = (50, 50) x, y, z = gridder.regular(area, shape, z=-1) gz = utils.contaminate(gravmag.prism.gz(x, y, z, model), 0.1) mesh = mesher.PrismMesh(bounds, (20, 40, 40)) seeds = gravmag.harvester.sow([[5000, 5000, 1000, props]], mesh) # Run the inversion without using weights data = [gravmag.harvester.Gz(x, y, z, gz)] estimate, predicted = gravmag.harvester.harvest(data, seeds, mesh, compactness=1.5, threshold=0.001) mesh.addprop('density', estimate['density'])
""" GravMag: 3D forward modeling of total-field magnetic anomaly using rectangular prisms (model with induced and remanent magnetization) """ from fatiando import mesher, gridder, utils from fatiando.gravmag import prism from fatiando.vis import mpl, myv # The regional field inc, dec = 30, -15 bounds = [-5000, 5000, -5000, 5000, 0, 5000] model = [ mesher.Prism(-4000, -3000, -4000, -3000, 0, 2000, {'magnetization': utils.ang2vec(1, inc, dec)}), mesher.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'magnetization': utils.ang2vec(1, inc, dec)}), # This prism will have magnetization in a different direction mesher.Prism(2000, 4000, 3000, 4000, 0, 2000, {'magnetization': utils.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 mpl.figure() mpl.title("Total-field anomaly (nT)") mpl.axis('scaled') mpl.contourf(yp, xp, tf, shape, 15)
""" GravMag: Calculate the analytic signal of a total field anomaly using FFT """ from fatiando import mesher, gridder, utils, gravmag from fatiando.vis import mpl prisms = [mesher.Prism(-100, 100, -100, 100, 0, 2000, {'magnetization': 10})] area = (-5000, 5000, -5000, 5000) shape = (100, 100) z0 = -500 xp, yp, zp = gridder.regular(area, shape, z=z0) inc, dec = -30, 0 tf = utils.contaminate(gravmag.prism.tf(xp, yp, zp, prisms, inc, dec), 0.001, percent=True) # Need to convert gz to SI units so that the result is also in SI ansig = gravmag.fourier.ansig(xp, yp, utils.nt2si(tf), shape) mpl.figure() mpl.subplot(1, 2, 1) mpl.title("Original total field anomaly") mpl.axis('scaled') mpl.contourf(yp, xp, tf, shape, 30) mpl.colorbar(orientation='horizontal') mpl.m2km() mpl.subplot(1, 2, 2) mpl.title("Analytic signal") mpl.axis('scaled') mpl.contourf(yp, xp, ansig, shape, 30) mpl.colorbar(orientation='horizontal')
""" GravMag: Center of mass estimation using the first eigenvector of the gravity gradient tensor (2 sources with expanding windows) """ from fatiando import mesher, gridder, utils, gravmag from fatiando.vis import mpl, myv # Generate some synthetic data prisms = [ mesher.Prism(-2500, -500, -1000, 1000, 500, 2500, {'density': 1000}), mesher.Prism(500, 2500, -1000, 1000, 500, 2500, {'density': 1000}) ] shape = (100, 100) area = (-5000, 5000, -5000, 5000) xp, yp, zp = gridder.regular(area, shape, z=-150) noise = 2 tensor = [ utils.contaminate(gravmag.prism.gxx(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gzz(xp, yp, zp, prisms), noise) ] # Get the eigenvectors from the tensor data eigenvals, eigenvecs = gravmag.tensor.eigen(tensor) # Plot the data titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] mpl.figure() for i, title in enumerate(titles): mpl.subplot(3, 2, i + 1)
""" GravMag: 3D imaging using the sandwich model method on synthetic gravity data (simple example) """ from fatiando import gridder, mesher from fatiando.gravmag import prism, imaging from fatiando.vis import mpl, myv # Make some synthetic gravity data from a simple prism model model = [mesher.Prism(-1000, 1000, -2000, 2000, 2000, 4000, {'density': 500})] shape = (25, 25) xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-10) gz = prism.gz(xp, yp, zp, model) # Plot the data mpl.figure() mpl.axis('scaled') mpl.contourf(yp, xp, gz, shape, 30) mpl.colorbar() mpl.xlabel('East (km)') mpl.ylabel('North (km)') mpl.m2km() mpl.show() mesh = imaging.sandwich(xp, yp, zp, gz, shape, 0, 10000, 25) # Plot the results myv.figure() myv.prisms(model, 'density', style='wireframe', linewidth=2) myv.prisms(mesh, 'density', edges=False) axes = myv.axes(myv.outline())
""" GravMag: Calculating the derivatives of the gravity anomaly using FFT """ from fatiando import mesher, gridder, utils from fatiando.gravmag import prism, transform from fatiando.vis import mpl model = [mesher.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 = utils.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 = utils.si2eotvos(transform.derivx(xp, yp, utils.mgal2si(gz), shape)) gyz = utils.si2eotvos(transform.derivy(xp, yp, utils.mgal2si(gz), shape)) gzz = utils.si2eotvos(transform.derivz(xp, yp, utils.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) mpl.figure() mpl.title("Original gravity anomaly") mpl.axis('scaled') mpl.contourf(xp, yp, gz, shape, 15) mpl.colorbar(shrink=0.7) mpl.m2km() mpl.figure(figsize=(14, 10))
""" GravMag: Generate synthetic gravity data on an irregular grid """ from fatiando import mesher, gridder, gravmag from fatiando.vis import mpl prisms = [mesher.Prism(-2000, 2000, -2000, 2000, 0, 2000, {'density': 1000})] xp, yp, zp = gridder.scatter((-5000, 5000, -5000, 5000), n=100, z=-100) gz = gravmag.prism.gz(xp, yp, zp, prisms) shape = (100, 100) mpl.axis('scaled') mpl.title("gz produced by prism model on an irregular grid (mGal)") mpl.plot(xp, yp, '.k', label='Grid points') levels = mpl.contourf(xp, yp, gz, shape, 12, interp=True) mpl.contour(xp, yp, gz, shape, levels, interp=True) mpl.legend(loc='lower right', numpoints=1) mpl.m2km() mpl.show()
""" GravMag: Upward continuation of noisy gz data """ from fatiando import mesher, gridder, utils from fatiando.gravmag import prism, transform from fatiando.vis import mpl import numpy as np model = [ mesher.Prism(-3000, -2000, -3000, -2000, 500, 2000, {'density': 1000}), mesher.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'density': -800}), mesher.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 = utils.contaminate(prism.gz(x, y, z, model), 0.5, seed=0) height = 1000 # How much higher to go gzcontf = transform.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=mpl.cm.RdBu_r) fig, axes = mpl.subplots(1, 3, figsize=(12, 3.5)) axes = axes.ravel() mpl.sca(axes[0]) mpl.title("Original") mpl.axis('scaled')
""" GravMag: Center of mass estimation using the first eigenvector of the gravity gradient tensor (simple model) """ from fatiando.vis import mpl, myv from fatiando import mesher, gridder, utils, gravmag # Generate some synthetic data prisms = [ mesher.Prism(-1000, 1000, -1000, 1000, 1000, 3000, {'density': 1000}) ] shape = (100, 100) xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-150) noise = 2 tensor = [ utils.contaminate(gravmag.prism.gxx(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gzz(xp, yp, zp, prisms), noise) ] # Plot the data titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] mpl.figure() for i, title in enumerate(titles): mpl.subplot(3, 2, i + 1) mpl.title(title) mpl.axis('scaled') levels = mpl.contourf(yp, xp, tensor[i], shape, 10) mpl.contour(yp, xp, tensor[i], shape, levels)
#create initial model - array of prisms lModel = [] for i in range(len(aDepths)): iXStart = tSignalBorders[0] + (i % iXNrPrisms) * iXPrismSpacing iXEnd = tSignalBorders[0] + iXPrismSpacing + (i % iXNrPrisms) * iXPrismSpacing iYStart = tSignalBorders[2] + (np.floor(i / iYNrPrisms)) * iYPrismSpacing iYEnd = tSignalBorders[2] + iYPrismSpacing + (np.floor( i / iYNrPrisms)) * iYPrismSpacing iZStart = 0 iZEnd = aDepths[i] dProperties = {'density': iDensity, 'depth': iZEnd} lModel.append( mesher.Prism(iXStart, iXEnd, iYStart, iYEnd, iZStart, iZEnd, dProperties)) #create grid for signal aXGridCoords, aYGridCoords, aZGridCoords = gridder.regular(tSignalBorders, tSignalSize, z=iReferenceHeight) #---Plot the Original Signal--- #mpl.figure(figsize=(8,7)) #mpl.contourf(aYGridCoords, aXGridCoords, aObservedSignal, tSignalSize, 50) #last arg is number of contours #mpl.show() oTimeAfterSetup = datetime.now() print("-----Setup Time", oTimeAfterSetup - oTimeBeforeSetup) oTimeBeginTot = datetime.now()
""" GravMag: Reduction to the pole of a total field anomaly using FFT """ from fatiando import mesher, gridder, utils from fatiando.gravmag import prism, transform from fatiando.vis import mpl # Direction of the Geomagnetic field inc, dec = -60, 0 # Make a model with only induced magnetization model = [ mesher.Prism(-100, 100, -100, 100, 0, 2000, {'magnetization': utils.ang2vec(10, inc, dec)}) ] area = (-5000, 5000, -5000, 5000) shape = (100, 100) z0 = -500 x, y, z = gridder.regular(area, shape, z=z0) tf = utils.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 = transform.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=utils.ang2vec(10, 90, 0)) fig, axes = mpl.subplots(1, 3, figsize=(14, 4)) for ax in axes: ax.set_aspect('equal') mpl.sca(axes[0]) mpl.title("Original total field anomaly") mpl.contourf(y, x, tf, shape, 30, cmap=mpl.cm.RdBu_r)
""" GravMag: Center of mass estimation using the first eigenvector of the gravity gradient tensor (flat slab model) """ from fatiando.vis import mpl, myv from fatiando import mesher, gridder, utils, gravmag # Generate some synthetic data prisms = [mesher.Prism(-1000, 1000, -1000, 1000, 500, 700, {'density': 1000})] shape = (100, 100) xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-150) noise = 1 tensor = [ utils.contaminate(gravmag.prism.gxx(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gzz(xp, yp, zp, prisms), noise) ] # Plot the data titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] mpl.figure() for i, title in enumerate(titles): mpl.subplot(3, 2, i + 1) mpl.title(title) mpl.axis('scaled') levels = mpl.contourf(yp, xp, tensor[i], shape, 10) mpl.contour(yp, xp, tensor[i], shape, levels) mpl.m2km() mpl.show()
""" GravMag: 3D imaging using the migration method on synthetic gravity data (more complex model + noisy data) """ from fatiando import gridder, mesher, utils from fatiando.gravmag import prism, imaging from fatiando.vis import mpl, myv # Make some synthetic gravity data from a simple prism model model = [ mesher.Prism(-4000, 0, -4000, -2000, 2000, 5000, {'density': 1200}), mesher.Prism(-1000, 1000, -1000, 1000, 1000, 7000, {'density': -800}), mesher.Prism(2000, 4000, 3000, 4000, 0, 2000, {'density': 600}) ] # Calculate on a scatter of points to show that migration doesn't need gridded # data xp, yp, zp = gridder.scatter((-6000, 6000, -6000, 6000), 1000, z=-10) gz = utils.contaminate(prism.gz(xp, yp, zp, model), 0.1) # Plot the data shape = (50, 50) mpl.figure() mpl.axis('scaled') mpl.contourf(yp, xp, gz, shape, 30, interp=True) mpl.colorbar() mpl.plot(yp, xp, '.k') mpl.xlabel('East (km)') mpl.ylabel('North (km)') mpl.m2km() mpl.show()
""" GravMag: 3D forward modeling of total-field magnetic anomaly using rectangular prisms (model with induced and remanent magnetization) """ from fatiando import mesher, gridder, gravmag, utils from fatiando.vis import mpl, myv # The regional field inc, dec = 30, -15 bounds = [-5000, 5000, -5000, 5000, 0, 5000] prisms = [ mesher.Prism( -4000, -3000, -4000, -3000, 0, 2000, {'magnetization': 2}), # a scalar magnetization means only induced mesher.Prism(-1000, 1000, -1000, 1000, 0, 2000, {'magnetization': 1}), # This prism will have magnetization in a different direction mesher.Prism(2000, 4000, 3000, 4000, 0, 2000, {'magnetization': utils.ang2vec(3, -10, 45)}) ] # induced + remanent # 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 = gravmag.prism.tf(xp, yp, zp, prisms, inc, dec) # Plot mpl.figure() mpl.title("Total-field anomaly (nT)") mpl.axis('scaled') mpl.contourf(yp, xp, tf, shape, 15) mpl.colorbar()
""" GravMag: 3D imaging using the Generalized Inverse method on synthetic gravity data (more complex model + noisy data) """ from fatiando import gridder, mesher, gravmag, utils from fatiando.vis import mpl, myv # Make some synthetic gravity data from a simple prism model prisms = [mesher.Prism(-4000,-1000,-4000,-2000,2000,5000,{'density':800}), mesher.Prism(-1000,1000,-1000,1000,1000,6000,{'density':-800}), mesher.Prism(2000,4000,3000,4000,0,4000,{'density':600})] shape = (25, 25) xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-10) gz = utils.contaminate(gravmag.prism.gz(xp, yp, zp, prisms), 0.1) # Plot the data mpl.figure() mpl.axis('scaled') mpl.contourf(yp, xp, gz, shape, 30) mpl.colorbar() mpl.xlabel('East (km)') mpl.ylabel('North (km)') mpl.m2km() mpl.show() # Run the Generalized Inverse mesh = gravmag.imaging.geninv(xp, yp, zp, gz, shape, 0, 10000, 25) # Plot the results myv.figure()
""" GravMag: Use the polynomial equivalent layer to upward continue gravity data """ from fatiando.gravmag import prism, sphere from fatiando.gravmag.eqlayer import PELGravity, PELSmoothness from fatiando import gridder, utils, mesher from fatiando.vis import mpl # Make synthetic data props = {'density': 1000} model = [mesher.Prism(-500, 500, -1000, 1000, 500, 4000, props)] shape = (50, 50) x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=0) gz = utils.contaminate(prism.gz(x, y, z, model), 0.1, seed=0) # Setup the layer layer = mesher.PointGrid([-5000, 5000, -5000, 5000], 200, (100, 100)) # Estimate the density using the PEL (it is faster and more memory efficient # than the traditional equivalent layer). windows = (20, 20) degree = 1 misfit = PELGravity(x, y, z, gz, layer, windows, degree) # Apply a smoothness constraint to the borders of the equivalent layer windows # to avoid gaps in the physical property distribution solver = misfit + 1e-18 * PELSmoothness(layer, windows, degree) solver.fit() # Add the estimated density distribution to the layer object for plotting and # forward modeling layer.addprop('density', solver.estimate_) residuals = solver[0].residuals() print("Residuals:") print("mean:", residuals.mean())
""" import numpy as np from fatiando.gravmag import prism from fatiando import mesher, gridder, utils # Make some synthetic magnetic data to test our Euler deconvolution. # The regional field inc, dec = 59, 10 #order of the prism -> SI 3, 2,1 #needed to increase the intensity of magnetization of some sources because #they were modeled as spheres to the paper and now they are modeled as prisms model = [ mesher.Prism(24500, 25500, 14500, 15500, 1000, 2000, {'magnetization': utils.ang2vec(3, 9, -32)}), mesher.Prism(44800, 45200, 14800, 15200, 2000, 1000000, {'magnetization': utils.ang2vec(12, inc, dec)}), mesher.Prism(15000, 94000, 34900, 35100, 1800, 3000e3, {'magnetization': utils.ang2vec(5, inc, dec)}) ] # Generate some magnetic data from the model shape = (325, 249) area = [0, 64800, 0, 49800] hvoo = 0 xi, yi, zi = gridder.regular(area, shape, z=hvoo) data = utils.contaminate(prism.tf(xi, yi, zi, model, inc, dec), 0.1, seed=0) #linear base-level b = 47500
#vertical prism x1_cr, x2_cr = 4000, 6000 y1_cr, y2_cr = 14000, 16000 z1_cr, z2_cr = 200, 5000 #Magnetization intensity mag_cr = 1.5 inc_cr = 60. dec_cr = 60. #From Fatiando a Terra # Compute the cosine directions of the main geomagetic field (F) F = utils.ang2vec(1, inc_o, dec_o) #Generate a model From Fatiando a Terra model_mag = [ mesher.Prism(x1_cr, x2_cr, y1_cr, y2_cr, z1_cr, z2_cr, {'magnetization': utils.ang2vec(mag_cr, inc_cr, dec_cr)}), mesher.Prism(x1_c, x2_c, y1_c, y2_c, z1_c, z2_c, {'magnetization': utils.ang2vec(mag_c, inc_c, dec_c)}), mesher.Prism(x3_c, x4_c, y3_c, y4_c, z3_c, z4_c, {'magnetization': utils.ang2vec(mag_c, inc_c, dec_c)}), mesher.Prism(x3_c, x4_c, y5_c, y6_c, z3_c, z4_c, {'magnetization': utils.ang2vec(mag_c, inc_c, dec_c)}), mesher.Prism(x1_L, x2_L, y1_L, y2_L, z1_L, z2_L, {'magnetization': utils.ang2vec(mag_L, inc_s, dec_s)}), mesher.Prism(x3_L, x4_L, y3_L, y4_L, z3_L, z4_L, {'magnetization': utils.ang2vec(mag_L, inc_s, dec_s)}), mesher.Prism(x1, x2, y1m[0], y2m[0], zo_t[0], zo_b[0], {'magnetization': utils.ang2vec(mag_m, inc_s, dec_s)}), mesher.Prism(x1, x2, y1m[1], y2m[1], zo_t[1], zo_b[1], {'magnetization': utils.ang2vec(mag_m, inc_s, dec_s)}), mesher.Prism(x1, x2, y1m[2], y2m[2], zo_t[2], zo_b[2],
# ------------------------------- Model za = 3000 zb = 3500 dens = 1200 l = 500 offset = 3000 simname = 'za' + str(za) + '_zb' + str(zb) + '_l' + str(l) + '_ofs' + str( offset) + '_dens' + str(dens) # model = [mesher.Prism(-l-offset, l-offset, -l-offset/20, l-offset, za, zb, {'density': dens})] # simname= 'mod_asy_rect_z3.2km_rectArea' simname = 'sym_square_z3.2km_rectArea' # model = [mesher.Prism(-4000, 0, -4000, -3500, za, zb, {'density': 1200})] model = [mesher.Prism(-1000, 1000, -1000, 1000, za, zb, {'density': 1200})] shape = (200, 200) #xp, yp, zp = gridder.scatter((-6000, 6000, -6000, 6000), shape[0]*shape[1], z=0) xp, yp, zp = gridder.regular((-12000, 12000, -6000, 6000), shape, z=0) # gz = utils.contaminate(prism.gz(xp, yp, zp, model), 0.1) gz = prism.gz(xp, yp, zp, model) x1, x2, y1, y2, z1, z2 = np.array(model[0].get_bounds()) import pickle d = {"xyzg": [xp, yp, zp, gz], "shape": shape, "model": model, "density": dens} afile = open(simname + '.pkl', 'wb') pickle.dump(d, afile) afile.close()
""" GravMag: Center of mass estimation using the first eigenvector of the gravity gradient tensor (elongated model) """ from fatiando.vis import mpl, myv from fatiando import mesher, gridder, utils, gravmag # Generate some synthetic data prisms = [mesher.Prism(-4000, 4000, -500, 500, 500, 1000, {'density': 1000})] shape = (100, 100) xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-150) noise = 2 tensor = [ utils.contaminate(gravmag.prism.gxx(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gzz(xp, yp, zp, prisms), noise) ] # Plot the data titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] mpl.figure() for i, title in enumerate(titles): mpl.subplot(3, 2, i + 1) mpl.title(title) mpl.axis('scaled') levels = mpl.contourf(yp, xp, tensor[i], shape, 10) mpl.contour(yp, xp, tensor[i], shape, levels) mpl.m2km() mpl.show()
""" GravMag: Center of mass estimation using the first eigenvector of the gravity gradient tensor (pyramid model) """ from fatiando.vis import mpl, myv from fatiando import mesher, gridder, utils, gravmag # Generate some synthetic data prisms = [ mesher.Prism(-500, 500, -500, 500, 500, 1000, {'density': 1000}), mesher.Prism(-1000, 1000, -1000, 1000, 1000, 1500, {'density': 1000}), mesher.Prism(-2000, 2000, -2000, 2000, 1500, 2000, {'density': 1000}) ] shape = (100, 100) xp, yp, zp = gridder.regular((-5000, 5000, -5000, 5000), shape, z=-150) noise = 1 tensor = [ utils.contaminate(gravmag.prism.gxx(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gxz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyy(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gyz(xp, yp, zp, prisms), noise), utils.contaminate(gravmag.prism.gzz(xp, yp, zp, prisms), noise) ] # Plot the data titles = ['gxx', 'gxy', 'gxz', 'gyy', 'gyz', 'gzz'] mpl.figure() for i, title in enumerate(titles): mpl.subplot(3, 2, i + 1) mpl.title(title) mpl.axis('scaled')