def test_eqlayer_polereduce(): "EQLTotalField can reduce data to the pole" # Use remanent magnetization sinc, sdec = -70, 30 model = [Prism(-100, 100, -500, 500, 0, 100, {'magnetization': utils.ang2vec(5, sinc, sdec)})] inc, dec = -60, -15 shape = (50, 50) area = [-2000, 2000, -2000, 2000] x, y, z = gridder.regular(area, shape, z=-100) data = prism.tf(x, y, z, model, inc, dec) true = prism.tf(x, y, z, model, -90, 0, pmag=utils.ang2vec(5, -90, 0)) layer = PointGrid(area, 200, shape) eql = (EQLTotalField(x, y, z, data, inc, dec, layer, sinc, sdec) + 1e-24*Damping(layer.size)) eql.fit() assert_allclose(eql[0].predicted(), data, rtol=0.01) layer.addprop('magnetization', utils.ang2vec(eql.estimate_, inc=-90, dec=0)) calc = sphere.tf(x, y, z, layer, inc=-90, dec=0) assert_allclose(calc, true, atol=10, rtol=0.05)
def test_pel_polereduce(): "PELTotalField can reduce data to the pole" # Use remanent magnetization sinc, sdec = -70, 30 model = [Prism(-100, 100, -500, 500, 0, 100, {'magnetization': utils.ang2vec(5, sinc, sdec)})] inc, dec = -60, -15 shape = (40, 40) area = [-2000, 2000, -2000, 2000] x, y, z = gridder.regular(area, shape, z=-100) data = prism.tf(x, y, z, model, inc, dec) true = prism.tf(x, y, z, model, -90, 0, pmag=utils.ang2vec(5, -90, 0)) layer = PointGrid(area, 100, shape) windows = (20, 20) degree = 3 pel = PELTotalField(x, y, z, data, inc, dec, layer, windows, degree, sinc, sdec) eql = pel + 1e-25*PELSmoothness(layer, windows, degree) eql.fit() assert_array_almost_equal(eql[0].predicted(), data, decimal=1) layer.addprop('magnetization', utils.ang2vec(eql.estimate_, inc=-90, dec=0)) calc = sphere.tf(x, y, z, layer, inc=-90, dec=0) assert_allclose(calc, true, atol=10, rtol=0.05)
def test_upcontinue(): "gravmag.transform upward continuation matches analytical solution" model = [Prism(-1000, 1000, -500, 500, 0, 1000, {'density': 1000, 'magnetization': utils.ang2vec(5, 20, -30)})] shape = (100, 100) inc, dec = -10, 15 x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=-500) dz = 10 fields = 'potential gx gy gz gxx gxy gxz gyy gyz gzz'.split() accuracy = [0.002, 0.2, 0.2, 0.3, 2, 2, 4, 4, 4, 6] for f, atol in zip(fields, accuracy): func = getattr(prism, f) data = func(x, y, z, model) analytical = func(x, y, z + dz, model) up = transform.upcontinue(x, y, data, shape, dz) diff = np.abs(up - analytical) check = diff <= atol assert np.all(check), \ 'Failed for {} (mismatch {:.2f}%)'.format( f, 100*(check.size - check.sum())/check.size) data = prism.tf(x, y, z, model, inc, dec) analytical = prism.tf(x, y, z + dz, model, inc, dec) up = transform.upcontinue(x, y, data, shape, dz) diff = np.abs(up - analytical) check = diff <= 15 assert np.all(check), \ 'Failed for tf (mismatch {:.2f}%)'.format( 100*(check.size - check.sum())/check.size)
def test_upcontinue(): "gravmag.transform upward continuation matches analytical solution" model = [ Prism(-1000, 1000, -500, 500, 0, 1000, { 'density': 1000, 'magnetization': utils.ang2vec(5, 20, -30) }) ] shape = (100, 100) inc, dec = -10, 15 x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=-500) dz = 10 fields = 'potential gx gy gz gxx gxy gxz gyy gyz gzz'.split() accuracy = [0.002, 0.2, 0.2, 0.3, 2, 2, 4, 4, 4, 6] for f, atol in zip(fields, accuracy): func = getattr(prism, f) data = func(x, y, z, model) analytical = func(x, y, z + dz, model) up = transform.upcontinue(x, y, data, shape, dz) diff = np.abs(up - analytical) check = diff <= atol assert np.all(check), \ 'Failed for {} (mismatch {:.2f}%)'.format( f, 100*(check.size - check.sum())/check.size) data = prism.tf(x, y, z, model, inc, dec) analytical = prism.tf(x, y, z + dz, model, inc, dec) up = transform.upcontinue(x, y, data, shape, dz) diff = np.abs(up - analytical) check = diff <= 15 assert np.all(check), \ 'Failed for tf (mismatch {:.2f}%)'.format( 100*(check.size - check.sum())/check.size)
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)
def test_pole_reduce(): "gravmag.transform pole reduction matches analytical solution" # Use remanent magnetization sinc, sdec = -70, 30 model = [Prism(-100, 100, -500, 500, 0, 100, {'density': 1000, 'magnetization': utils.ang2vec(5, sinc, sdec)})] # Use low latitudes to make sure that there are no problems with FFT # instability. inc, dec = -60, -15 shape = (50, 50) x, y, z = gridder.regular([-2000, 2000, -2000, 2000], shape, z=-100) data = prism.tf(x, y, z, model, inc, dec) pole = transform.reduce_to_pole(x, y, data, shape, inc, dec, sinc, sdec) pole_true = prism.tf(x, y, z, model, -90, 0, pmag=utils.ang2vec(5, -90, 0)) npt.assert_allclose(pole, pole_true, atol=10, rtol=0.01)
def test_tf(): "polyprism.tf against prism" resprism = prism.tf(xp, yp, zp, prismmodel, inc, dec) respoly = polyprism.tf(xp, yp, zp, model, inc, dec) diff = np.abs(resprism - respoly) errormsg = 'max diff: %g | max polyprism: %g | max prism: %g' % ( max(diff), max(respoly), max(resprism)) assert np.all(diff <= precision_mag), errormsg
def test_tf(): "gravmag.prism.tf python vs cython implementation" py = _prism_numpy.tf(xp, yp, zp, model, inc, dec) cy = prism.tf(xp, yp, zp, model, inc, dec) diff = np.abs(py - cy) # Lower precison because python calculates using Blakely and cython using # the gravity kernels assert np.all(diff <= 10**-9), 'max diff: %g' % (max(diff))
def test_pole_reduce(): "gravmag.transform pole reduction matches analytical solution" # Use remanent magnetization sinc, sdec = -70, 30 model = [ Prism(-100, 100, -500, 500, 0, 100, { 'density': 1000, 'magnetization': utils.ang2vec(5, sinc, sdec) }) ] # Use low latitudes to make sure that there are no problems with FFT # instability. inc, dec = -60, -15 shape = (50, 50) x, y, z = gridder.regular([-2000, 2000, -2000, 2000], shape, z=-100) data = prism.tf(x, y, z, model, inc, dec) pole = transform.reduce_to_pole(x, y, data, shape, inc, dec, sinc, sdec) pole_true = prism.tf(x, y, z, model, -90, 0, pmag=utils.ang2vec(5, -90, 0)) npt.assert_allclose(pole, pole_true, atol=10, rtol=0.01)
def test_tilt_sane_values(): "gravmag.transform tilt returns sane values, between -90 and 90 degrees" inc, dec = 90, 0 mag = utils.ang2vec(200, inc, dec) model = [Prism(-500, 500, -500, 500, 0, 2000, {'magnetization': mag})] shape = (300, 300) x, y, z = gridder.regular([-10000, 10000, -10000, 10000], shape, z=-100) data = prism.tf(x, y, z, model, inc, dec) tilt = np.degrees(transform.tilt(x, y, data, shape)) assert tilt.max() < 90, \ "Maximum tilt greater than 90: {}".format(tilt.max()) assert tilt.min > -90, \ "Minimum tilt less than -90: {}".format(tilt.min())
def syn_data(inc, dec,syn_bounds,area,depth=-300,magnetization = 5,cel=200): # Build the synthetic Anomaly mag = utils.ang2vec(magnetization, inc, dec) model = [] for i in range(len(syn_bounds)): model.append(Prism(syn_bounds[i][0], syn_bounds[i][1], syn_bounds[i][2], syn_bounds[i][3], syn_bounds[i][4], syn_bounds[i][5], {'magnetization': mag})) numcols, numrows = int((area[1] - area[0])/cel), int((area[3] - area[2])/cel) x, y, z = gridder.regular(area[:4], (numcols, numrows), z=depth) #Calculate the Total Magnetic Field in nT mag = prism.tf(x, y, z, model, inc, dec) return x,y,mag,model
def euler_deconv(inc, dec,syn_bounds,area,depth=-300,magnetization = 0.5,si=1.0,size = (1000, 1000),windows=(10, 10),proc_data='None'): # IN PROGRESSING ##### mag = utils.ang2vec(magnetization, inc, dec) model = [] for i in range(len(syn_bounds)): model.append(Prism(syn_bounds[i][0], syn_bounds[i][1], syn_bounds[i][2], syn_bounds[i][3], syn_bounds[i][4], syn_bounds[i][5], {'magnetization': mag})) #model = [Prism(syn_bounds[0]-1000, syn_bounds[1]-1000, syn_bounds[2]-1000, syn_bounds[3]-1000, syn_bounds[4], syn_bounds[5], {'magnetization': mag}),Prism(syn_bounds[0]+1000, syn_bounds[1]+1000, syn_bounds[2]+1000, syn_bounds[3]+1000, syn_bounds[4], syn_bounds[5], {'magnetization': mag})] cel = 200 numcols, numrows = int((area[1] - area[0])/cel), int((area[3] - area[2])/cel) x, y, z = gridder.regular(area[:4], (numcols, numrows), z=depth) mag = prism.tf(x, y, z, model, inc, dec) #derivatives deriv_x = transform.derivx(x, y, mag, (numcols, numrows)) deriv_y = transform.derivy(x, y, mag, (numcols, numrows)) deriv_z = transform.derivz(x, y, mag, (numcols, numrows)) #label = 'Total Magnetic Intensity (nT)' solver = euler.EulerDeconvMW(x, y, z, mag, deriv_x, deriv_y, deriv_z, structural_index=si, windows=windows, size=size) solver_expand = euler.EulerDeconvEW(x, y, z, mag, deriv_x, deriv_y, deriv_z, structural_index=si, center = (-1250,0),sizes=np.linspace(300, 7000, 20)) solver.fit() solver_expand.fit() #print('Kept Euler solutions after the moving window scheme:') #print(solver_expand.estimate_) return solver,solver_expand
""" GravMag: Calculate the analytic signal of a total field anomaly using FFT """ from fatiando import mesher, gridder, utils from fatiando.gravmag import prism, transform from fatiando.vis import mpl model = [mesher.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 = utils.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 = transform.tga(x, y, utils.nt2si(tf), shape) mpl.figure() mpl.subplot(1, 2, 1) mpl.title("Original total field anomaly") mpl.axis('scaled') mpl.contourf(y, x, tf, shape, 30, cmap=mpl.cm.RdBu_r) mpl.colorbar(orientation='horizontal').set_label('nT') mpl.m2km() mpl.subplot(1, 2, 2) mpl.title("Total Gradient Amplitude") mpl.axis('scaled') mpl.contourf(y, x, total_grad_amp, shape, 30, cmap=mpl.cm.RdBu_r) mpl.colorbar(orientation='horizontal').set_label('nT/m')
# The regional field inc, dec = -45, 0 # Make a model bounds = [-5000, 5000, -5000, 5000, 0, 5000] model = [ 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(prism.tf(xp, yp, zp, model, inc, dec)) + baselevel) # Calculate the derivatives using FFT xderiv = fourier.derivx(xp, yp, tf, shape) yderiv = fourier.derivy(xp, yp, tf, shape) zderiv = 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]) mpl.axis('scaled') mpl.contourf(yp, xp, f, shape, 50) mpl.colorbar() mpl.m2km() mpl.show()
""" GravMag: Calculate the analytic signal of a total field anomaly using FFT """ from fatiando import mesher, gridder, utils from fatiando.gravmag import prism, fourier from fatiando.vis import mpl model = [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(prism.tf(xp, yp, zp, model, inc, dec), 0.001, percent=True) # Need to convert gz to SI units so that the result is also in SI ansig = 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: Use an equivalent layer to reduce a magnetic total field anomaly to the pole """ from fatiando.gravmag import prism, sphere from fatiando.gravmag.eqlayer import EQLTotalField from fatiando.inversion.regularization import Damping, LCurve from fatiando import gridder, utils, mesher from fatiando.vis import mpl # Make synthetic data inc, dec = -60, 23 props = {'magnetization': 10} model = [mesher.Prism(-500, 500, -1000, 1000, 500, 4000, props)] shape = (25, 25) x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=0) tf = utils.contaminate(prism.tf(x, y, z, model, inc, dec), 5, seed=0) # Setup the layer layer = mesher.PointGrid([-7000, 7000, -7000, 7000], 700, (50, 50)) # Estimate the magnetization intensity # Need to apply regularization so that won't try to fit the error as well misfit = EQLTotalField(x, y, z, tf, inc, dec, layer) regul = Damping(layer.size) # Use an L-curve analysis to find the best regularization parameter solver = LCurve(misfit, regul, [10 ** i for i in range(-30, -15)]).fit() residuals = solver.residuals() layer.addprop('magnetization', solver.estimate_) print "Residuals:" print "mean:", residuals.mean() print "stddev:", residuals.std() # Now I can forward model the layer at the south pole and check against the
def test_tf(): "gravmag.prism.tf python vs cython implementation" py = _prism_numpy.tf(xp, yp, zp, model, inc, dec) cy = prism.tf(xp, yp, zp, model, inc, dec) diff = np.abs(py - cy) assert np.all(diff <= precision), 'max diff: %g' % (max(diff))
""" from __future__ import division, print_function import matplotlib.pyplot as plt from fatiando.gravmag import prism, transform from fatiando.mesher import Prism from fatiando import gridder, utils # Create some synthetic magnetic data. We'll assume the data is already reduced # to the pole. inc, dec = 90, 0 mag = utils.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 = transform.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') tmp = ax.tricontourf(y/1000, x/1000, data_at_pole, 30, cmap='RdBu_r') plt.colorbar(tmp, pad=0.1, aspect=30, orientation='horizontal').set_label('nT') ax.set_xlabel('y (km)') ax.set_ylabel('x (km)') ax.set_xlim(area[2]/1000, area[3]/1000)
inc, dec = 30, -15 bounds = [-5000, 5000, -5000, 5000, 0, 5000] model = [ 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 = 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) mpl.colorbar() mpl.xlabel('East y (km)') mpl.ylabel('North x (km)') mpl.m2km() mpl.show() # Show the prisms myv.figure() myv.prisms(model, 'magnetization') myv.axes(myv.outline(bounds), ranges=[i * 0.001 for i in bounds]) myv.wall_north(bounds)
from fatiando.vis import mpl, myv # The regional field inc, dec = -45, 0 # Make a model bounds = [-5000, 5000, -5000, 5000, 0, 5000] model = [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(prism.tf(xp, yp, zp, model, inc, dec)) + baselevel) # Calculate the derivatives using FFT xderiv = transform.derivx(xp, yp, tf, shape) yderiv = transform.derivy(xp, yp, tf, shape) zderiv = transform.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]) mpl.axis('scaled') mpl.contourf(yp, xp, f, shape, 50) mpl.colorbar() mpl.m2km() mpl.show()
""" from __future__ import division, print_function import matplotlib.pyplot as plt from fatiando.gravmag import prism, transform from fatiando.mesher import Prism from fatiando import gridder, utils # Create some synthetic magnetic data. We'll assume the data is already reduced # to the pole. inc, dec = 90, 0 mag = utils.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 = transform.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') tmp = ax.tricontourf(y / 1000, x / 1000, data_at_pole, 30, cmap='RdBu_r') plt.colorbar(tmp, pad=0.1, aspect=30, orientation='horizontal').set_label('nT') ax.set_xlabel('y (km)') ax.set_ylabel('x (km)') ax.set_xlim(area[2] / 1000, area[3] / 1000)
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)) eql.fit() # Print some statistics of how well the estimated layer fits the data residuals = eql[0].residuals() print("Residuals:") print(" mean:", residuals.mean(), 'nT') print(" stddev:", residuals.std(), 'nT')
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) mpl.colorbar() mpl.xlabel('East y (km)') mpl.ylabel('North x (km)') mpl.m2km() mpl.show() # Show the prisms myv.figure() myv.prisms(model, 'magnetization') myv.axes(myv.outline(bounds), ranges=[i * 0.001 for i in bounds]) myv.wall_north(bounds)
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) mpl.colorbar(pad=0).set_label('nT') mpl.m2km()
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) mpl.colorbar(pad=0).set_label('nT') mpl.m2km() mpl.sca(axes[1])
mesher.Prism(x1, x2, y1m[34], y2m[34], zo_t[34], zo_b[34], {'magnetization': utils.ang2vec(mag_m, inc_s, dec_s)}), mesher.Prism(x1, x2, y1m[35], y2m[35], zo_t[35], zo_b[35], {'magnetization': utils.ang2vec(mag_m, inc_s, dec_s)}), mesher.Prism(x1, x2, y1m[36], y2m[36], zo_t[36], zo_b[36], {'magnetization': utils.ang2vec(mag_m, inc_s, dec_s)}), mesher.Prism(x1, x2, y1m[37], y2m[37], zo_t[37], zo_b[37], {'magnetization': utils.ang2vec(mag_m, inc_s, dec_s)}), mesher.Prism(x1, x2, y1m[38], y2m[38], zo_t[38], zo_b[38], {'magnetization': utils.ang2vec(mag_m, inc_s, dec_s)}), mesher.Prism(x1, x2, y1m[39], y2m[39], zo_t[39], zo_b[39], {'magnetization': utils.ang2vec(mag_m, inc_s, dec_s)}) ] #total field from Fatiando a Terra tf, stdv = utils.contaminate(prism.tf(xi, yi, zi, model_mag, inc_o, dec_o), 1, percent=False, return_stddev=True) print stdv #save for the plot out = np.array([yi, xi, zi, tf]) out = out.T np.savetxt('input_mag.dat', out, delimiter=' ', fmt='%1.8f') out = None tf_noise_free = prism.tf(xi, yi, zi, model_mag, inc_o, dec_o) out = np.array([yi, xi, zi, tf_noise_free]) out = out.T
import matplotlib.pyplot as plt from fatiando.gravmag import prism, transform from fatiando.mesher import Prism from fatiando import gridder, utils # 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 = utils.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 = transform.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') tmp = ax.tricontourf(y / 1000, x / 1000, data, 30, cmap='RdBu_r') plt.colorbar(tmp, pad=0.1, aspect=30, orientation='horizontal').set_label('nT') ax.set_xlabel('y (km)') ax.set_ylabel('x (km)')
""" GravMag: Calculate the analytic signal of a total field anomaly using FFT """ from fatiando import mesher, gridder, utils from fatiando.gravmag import prism, transform from fatiando.vis import mpl model = [mesher.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 = utils.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 = transform.tga(x, y, utils.nt2si(tf), shape) mpl.figure() mpl.subplot(1, 2, 1) mpl.title("Original total field anomaly") mpl.axis('scaled') mpl.contourf(y, x, tf, shape, 30, cmap=mpl.cm.RdBu_r) mpl.colorbar(orientation='horizontal').set_label('nT') mpl.m2km() mpl.subplot(1, 2, 2) mpl.title("Total Gradient Amplitude") mpl.axis('scaled') mpl.contourf(y, x, total_grad_amp, shape, 30, cmap=mpl.cm.RdBu_r) mpl.colorbar(orientation='horizontal').set_label('nT/m') mpl.m2km()
""" GravMag: Use the Polynomial Equivalent Layer to reduce a magnetic total field anomaly to the pole """ from fatiando.gravmag import prism, sphere from fatiando.gravmag.eqlayer import PELTotalField, PELSmoothness from fatiando import gridder, utils, mesher from fatiando.vis import mpl # Make synthetic data inc, dec = -60, 23 props = {'magnetization':10} model = [mesher.Prism(-500, 500, -1000, 1000, 500, 4000, props)] shape = (50, 50) x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=-150) tf = utils.contaminate(prism.tf(x, y, z, model, inc, dec), 5) # 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 solver = (PELTotalField(x, y, z, tf, inc, dec, layer, windows, degree) + 10**-21*PELSmoothness(layer, windows, degree)).fit() layer.addprop('magnetization', solver.estimate_) residuals = solver.residuals() print "Residuals:" print "mean:", residuals.mean() print "stddev:", residuals.std() # Plot the layer and the fit mpl.figure(figsize=(15, 4))
# 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 data_cont = data + b out = np.array([xi, yi, zi, data_cont]) out = out.T.astype(np.float) np.savetxt('synthetic_data.dat', out, delimiter=' ', fmt='%1.3f')
import matplotlib.pyplot as plt from fatiando.gravmag import prism, transform from fatiando.mesher import Prism from fatiando import gridder, utils # 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 = utils.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 = transform.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') tmp = ax.tricontourf(y/1000, x/1000, data, 30, cmap='RdBu_r') plt.colorbar(tmp, pad=0.1, aspect=30, orientation='horizontal').set_label('nT') ax.set_xlabel('y (km)') ax.set_ylabel('x (km)')