def test_tilt_analytical_derivatives(): "gravmag.transform tilt returns same values given analytical derivatives" model = [Prism(-100, 100, -100, 100, 0, 100, {'density': 1000})] shape = (400, 400) x, y, z = gridder.regular([-10000, 10000, -10000, 10000], shape, z=-100) data = utils.mgal2si(prism.gz(x, y, z, model)) dx = utils.eotvos2si(prism.gxz(x, y, z, model)) dy = utils.eotvos2si(prism.gyz(x, y, z, model)) dz = utils.eotvos2si(prism.gzz(x, y, z, model)) tilt_analytical = transform.tilt(x, y, data, shape, dx, dy, dz) tilt_numerical = transform.tilt(x, y, data, shape) npt.assert_allclose(tilt_numerical, tilt_analytical, rtol=0.10)
def test_derivatives_uneven_shape(): "gravmag.transform FFT derivatives work if grid spacing is uneven" model = [Prism(-1000, 1000, -500, 500, 0, 2000, {'density': 100})] shape = (150, 300) x, y, z = gridder.regular([-10000, 10000, -10000, 10000], shape, z=-100) grav = utils.mgal2si(prism.gz(x, y, z, model)) analytical = prism.gzz(x, y, z, model) calculated = utils.si2eotvos( transform.derivz(x, y, grav, shape, method='fft')) diff = _trim(np.abs(analytical - calculated), shape) assert np.all(diff <= 0.005*np.abs(analytical).max()), \ "Failed for gzz"
def test_derivatives_uneven_shape(): "gravmag.transform FFT derivatives work if grid spacing is uneven" model = [Prism(-1000, 1000, -500, 500, 0, 2000, {'density': 100})] shape = (150, 300) x, y, z = gridder.regular([-10000, 10000, -10000, 10000], shape, z=-100) grav = utils.mgal2si(prism.gz(x, y, z, model)) analytical = prism.gzz(x, y, z, model) calculated = utils.si2eotvos(transform.derivz(x, y, grav, shape, method='fft')) diff = _trim(np.abs(analytical - calculated), shape) assert np.all(diff <= 0.005*np.abs(analytical).max()), \ "Failed for gzz"
def test_horizontal_derivatives_fd(): "gravmag.transform 1st xy derivatives by finite diff against analytical" model = [Prism(-1000, 1000, -500, 500, 0, 2000, {'density': 100})] shape = (300, 300) x, y, z = gridder.regular([-5000, 5000, -5000, 5000], shape, z=-200) derivatives = 'x y'.split() grav = utils.mgal2si(prism.gz(x, y, z, model)) for deriv in derivatives: analytical = getattr(prism, 'g{}z'.format(deriv))(x, y, z, model) func = getattr(transform, 'deriv' + deriv) calculated = utils.si2eotvos(func(x, y, grav, shape, method='fd')) diff = np.abs(analytical - calculated) assert np.all(diff <= 0.005*np.abs(analytical).max()), \ "Failed for g{}. Max: {} Mean: {} STD: {}".format( deriv, diff.max(), diff.mean(), diff.std())
def test_gx_derivatives(): "gravmag.transform FFT 1st derivatives of gx against analytical solutions" model = [Prism(-1000, 1000, -500, 500, 0, 2000, {'density': 100})] shape = (300, 300) x, y, z = gridder.regular([-10000, 10000, -10000, 10000], shape, z=-100) derivatives = 'x y z'.split() grav = utils.mgal2si(prism.gx(x, y, z, model)) for deriv in derivatives: analytical = getattr(prism, 'gx{}'.format(deriv))(x, y, z, model) calculated = utils.si2eotvos( getattr(transform, 'deriv' + deriv)(x, y, grav, shape, method='fft')) diff = _trim(np.abs(analytical - calculated), shape) assert np.all(diff <= 0.005*np.abs(analytical).max()), \ "Failed for gx{}".format(deriv)
def anomaly_calculation(x, y, w, t, rho): from fatiando import utils from fatiando.mesher import Prism from fatiando.gravmag import prism ny, nx = np.shape(x) prismas = [] for i in xrange(ny-1): for j in xrange(nx-1): prisma = Prism(y[i][j], y[i+1][j+1], x[i][j], x[i+1][j+1], t, t + (w[i][j] + w[i+1][j] + w[i][j+1] + w[i+1][j+1])/4.) prismas.append(prisma) gz = -prism.gz(y.ravel(),x.ravel(),np.zeros(nx*ny),prismas,dens=rho) gz = utils.mgal2si(np.reshape(gz,(ny,nx))) return gz
from fatiando.vis import mpl, myv # Make a model bounds = [-5000, 5000, -5000, 5000, 0, 5000] model = [ Prism(-1500, -500, -1500, -500, 500, 1500, {'density': 1000}), Prism(500, 1500, 1000, 2000, 500, 1500, {'density': 1000})] # Generate some data from the model shape = (100, 100) area = bounds[0:4] xp, yp, zp = gridder.regular(area, shape, z=-1) # Add a constant baselevel baselevel = 10 # Convert the data from mGal to SI because Euler and FFT derivation require # data in SI gz = utils.mgal2si(prism.gz(xp, yp, zp, model)) + baselevel xderiv = transform.derivx(xp, yp, gz, shape) yderiv = transform.derivy(xp, yp, gz, shape) zderiv = transform.derivz(xp, yp, gz, shape) mpl.figure() titles = ['Gravity anomaly', 'x derivative', 'y derivative', 'z derivative'] for i, f in enumerate([gz, 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: 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))
# Make a model bounds = [-5000, 5000, -5000, 5000, 0, 5000] model = [ Prism(-1500, -500, -1500, -500, 500, 1500, {'density': 1000}), Prism(500, 1500, 1000, 2000, 500, 1500, {'density': 1000}) ] # Generate some data from the model shape = (100, 100) area = bounds[0:4] xp, yp, zp = gridder.regular(area, shape, z=-1) # Add a constant baselevel baselevel = 10 # Convert the data from mGal to SI because Euler and FFT derivation require # data in SI gz = utils.mgal2si(prism.gz(xp, yp, zp, model)) + baselevel xderiv = transform.derivx(xp, yp, gz, shape) yderiv = transform.derivy(xp, yp, gz, shape) zderiv = transform.derivz(xp, yp, gz, shape) mpl.figure() titles = ['Gravity anomaly', 'x derivative', 'y derivative', 'z derivative'] for i, f in enumerate([gz, 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: Calculating the derivatives of the gravity anomaly using FFT """ from fatiando import mesher, gridder, utils, gravmag from fatiando.vis import mpl prisms = [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(gravmag.prism.gz(xp, yp, zp, prisms), 0.001) # Need to convert gz to SI units so that the result can be converted to Eotvos gxz = utils.si2eotvos( gravmag.fourier.derivx(xp, yp, utils.mgal2si(gz), shape)) gyz = utils.si2eotvos( gravmag.fourier.derivy(xp, yp, utils.mgal2si(gz), shape)) gzz = utils.si2eotvos( gravmag.fourier.derivz(xp, yp, utils.mgal2si(gz), shape)) gxz_true = gravmag.prism.gxz(xp, yp, zp, prisms) gyz_true = gravmag.prism.gyz(xp, yp, zp, prisms) gzz_true = gravmag.prism.gzz(xp, yp, zp, prisms) mpl.figure() mpl.title("Original gravity anomaly") mpl.axis('scaled') mpl.contourf(xp, yp, gz, shape, 15) mpl.colorbar(shrink=0.7) mpl.m2km()
""" GravMag: Calculating the derivatives of the gravity anomaly using FFT """ from fatiando import mesher, gridder, utils, gravmag from fatiando.vis import mpl prisms = [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(gravmag.prism.gz(xp, yp, zp, prisms), 0.001) # Need to convert gz to SI units so that the result can be converted to Eotvos gxz = utils.si2eotvos(gravmag.fourier.derivx(xp, yp, utils.mgal2si(gz), shape)) gyz = utils.si2eotvos(gravmag.fourier.derivy(xp, yp, utils.mgal2si(gz), shape)) gzz = utils.si2eotvos(gravmag.fourier.derivz(xp, yp, utils.mgal2si(gz), shape)) gxz_true = gravmag.prism.gxz(xp, yp, zp, prisms) gyz_true = gravmag.prism.gyz(xp, yp, zp, prisms) gzz_true = gravmag.prism.gzz(xp, yp, zp, prisms) 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)) mpl.subplots_adjust(top=0.95, left=0.05, right=0.95)
""" GravMag: Calculating the derivatives of the gravity anomaly using FFT """ from fatiando import mesher, gridder, utils from fatiando.gravmag import prism, fourier 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(fourier.derivx(xp, yp, utils.mgal2si(gz), shape)) gyz = utils.si2eotvos(fourier.derivy(xp, yp, utils.mgal2si(gz), shape)) gzz = utils.si2eotvos(fourier.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))