def test_bx(): "gravmag.sphere.bx python vs cython implementation" py = _sphere_numpy.bx(xp, yp, zp, model) cy = sphere.bx(xp, yp, zp, model) diff = np.abs(py - cy) assert np.all(diff <= lower_precision), \ 'max diff: %g python: %g cython %g' \ % (max(diff), py[diff == max(diff)][0], cy[diff == max(diff)][0])
z=2e3, radius=1.5e3, props={'magnetization': utils.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) fields = [ ['Total field Anomaly (nt)', sphere.tf(x, y, z, model, inc, dec)], ['Bx (nT)', sphere.bx(x, y, z, model)], ['By (nT)', sphere.by(x, y, z, model)], ['Bz (nT)', sphere.bz(x, y, z, model)], ] # Make maps of all fields calculated fig = plt.figure(figsize=(7, 6)) plt.rcParams['font.size'] = 10 X, Y = x.reshape(shape) / 1000, y.reshape(shape) / 1000 for i, tmp in enumerate(fields): ax = plt.subplot(2, 2, i + 1) field, data = tmp scale = np.abs([data.min(), data.max()]).max() ax.set_title(field) plot = ax.pcolormesh(Y, X,
out = np.array([yi, xi, zi, predict]) out = out.T np.savetxt('data\predict_' + str(lambida) + '.dat', out, delimiter=' ', fmt='%1.3f') out = None # Compute the transformed matrix Tx = np.empty((N, M), dtype=float) Ty = np.empty((N, M), dtype=float) Tz = np.empty((N, M), dtype=float) for i, c in enumerate(layer): Tx[:, i] = sphere.bx(xi, yi, zi, [c], pmag=F) Ty[:, i] = sphere.by(xi, yi, zi, [c], pmag=F) Tz[:, i] = sphere.bz(xi, yi, zi, [c], pmag=F) # compute the components Bx_eq = np.dot(Tx, p) By_eq = np.dot(Ty, p) Bz_eq = np.dot(Tz, p) Tx = None Ty = None Tz = None p = None #Amplitude of the magnetic anomaly vector B_eq = np.sqrt(Bx_eq * Bx_eq + By_eq * By_eq + Bz_eq * Bz_eq)
model = [ mesher.Sphere(x=10e3, y=10e3, z=2e3, radius=1.5e3, props={'magnetization': utils.ang2vec(1, inc=50, dec=-30)}), mesher.Sphere(x=20e3, y=20e3, z=2e3, radius=1.5e3, props={'magnetization': utils.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) fields = [ ['Total field Anomaly (nt)', sphere.tf(x, y, z, model, inc, dec)], ['Bx (nT)', sphere.bx(x, y, z, model)], ['By (nT)', sphere.by(x, y, z, model)], ['Bz (nT)', sphere.bz(x, y, z, model)], ] # Make maps of all fields calculated fig = plt.figure(figsize=(7, 6)) plt.rcParams['font.size'] = 10 X, Y = x.reshape(shape)/1000, y.reshape(shape)/1000 for i, tmp in enumerate(fields): ax = plt.subplot(2, 2, i + 1) field, data = tmp scale = np.abs([data.min(), data.max()]).max() ax.set_title(field) plot = ax.pcolormesh(Y, X, data.reshape(shape), cmap='RdBu_r', vmin=-scale, vmax=scale)