|
| 1 | +""" |
| 2 | +Total magnetic fields: Dipole and Pole sources |
| 3 | +============================================== |
| 4 | +
|
| 5 | +In this example, we plot anomalous total magnetic field |
| 6 | +from a magnetic dipole and pole targets. These targets are |
| 7 | +excited by Earth magnetic fields. |
| 8 | +We can vary the direction of the Earth magnetic field, and |
| 9 | +magnetic moment of the target. |
| 10 | +
|
| 11 | +:author: Seogi Kang (`@sgkang <https://github.com/sgkang>`_) |
| 12 | +:date: Aug 19, 2018 |
| 13 | +
|
| 14 | +""" |
| 15 | + |
| 16 | + |
| 17 | +import numpy as np |
| 18 | +import matplotlib.pyplot as plt |
| 19 | +from matplotlib.colors import LogNorm |
| 20 | +from scipy.constants import mu_0, epsilon_0 |
| 21 | + |
| 22 | +from geoana import utils, spatial |
| 23 | +from geoana.em import static |
| 24 | + |
| 25 | +############################################################################### |
| 26 | +# Setup |
| 27 | +# ----- |
| 28 | +# |
| 29 | +# define the location, orientation, and source, physical properties of the |
| 30 | +# wholespace and source parameters |
| 31 | + |
| 32 | +mu = mu_0 # permeability of free space (this is the default) |
| 33 | +location = np.r_[0., 0., -10.] # location of the dipole or pole |
| 34 | + |
| 35 | +# dipole parameters |
| 36 | +moment = 1 |
| 37 | +# inclination and declination (e.g. Vancouver) |
| 38 | +inclination, declination = 67., 0. |
| 39 | + |
| 40 | + |
| 41 | +############################################################################### |
| 42 | +# Magnetostatic Dipole and Loop |
| 43 | +# ----------------------------- |
| 44 | +# |
| 45 | +# Here, we build the geoana magnetic dipole and poie in a wholespace |
| 46 | +# using the parameters defined above. |
| 47 | + |
| 48 | +def id_to_cartesian(inclination, declination): |
| 49 | + ux = np.cos(inclination/180.*np.pi)*np.sin(declination/180.*np.pi) |
| 50 | + uy = np.cos(inclination/180.*np.pi)*np.cos(declination/180.*np.pi) |
| 51 | + uz = -np.sin(inclination/180.*np.pi) |
| 52 | + return np.r_[ux, uy, uz] |
| 53 | + |
| 54 | +orientation = id_to_cartesian(inclination, declination) |
| 55 | + |
| 56 | +dipole = static.MagneticDipoleWholeSpace( |
| 57 | + location=location, |
| 58 | + orientation=orientation, |
| 59 | + moment=moment |
| 60 | +) |
| 61 | + |
| 62 | +pole = static.MagneticPoleWholeSpace( |
| 63 | + location=location, |
| 64 | + orientation=orientation, |
| 65 | + moment=moment |
| 66 | +) |
| 67 | + |
| 68 | +############################################################################### |
| 69 | +# Evaluate magnetic fields |
| 70 | +# -------------------------- |
| 71 | +# |
| 72 | +# Next, we construct a grid where we want to plot the magentic fields and |
| 73 | +# evaluate |
| 74 | + |
| 75 | +x = np.linspace(-36, 36, 100) |
| 76 | +y = np.linspace(-36, 36, 100) |
| 77 | +xyz = utils.ndgrid([x, y, np.r_[1.]]) |
| 78 | + |
| 79 | +# evaluate the magnetic field |
| 80 | +b_vec_dipole = dipole.magnetic_flux_density(xyz) |
| 81 | +b_vec_pole = pole.magnetic_flux_density(xyz) |
| 82 | +b_total_dipole = dipole.dot_orientation(b_vec_dipole) |
| 83 | +b_total_pole = pole.dot_orientation(b_vec_pole) |
| 84 | +############################################################################### |
| 85 | +# |
| 86 | +# and define plotting code to plot an image of the amplitude of the vector |
| 87 | +# field / flux as well as the streamlines |
| 88 | + |
| 89 | + |
| 90 | +def plot_amplitude(ax, v): |
| 91 | + plt.colorbar( |
| 92 | + ax.pcolormesh( |
| 93 | + x, y, v.reshape(len(x), len(y), order='F') |
| 94 | + ), ax=ax |
| 95 | + ) |
| 96 | + ax.axis('square') |
| 97 | + ax.set_xlabel('y (east, m)') |
| 98 | + ax.set_ylabel('x (north, m)') |
| 99 | + |
| 100 | +############################################################################### |
| 101 | +# |
| 102 | +# Create subplots for plotting the results. Loop over frequencies and plot the |
| 103 | +# electric and magnetic fields along a slice through the center of the dipole. |
| 104 | + |
| 105 | +fig, ax = plt.subplots(1, 2, figsize=(12, 5)) |
| 106 | + |
| 107 | +# plot dipole vector potential |
| 108 | +plot_amplitude(ax[0], b_total_dipole) |
| 109 | + |
| 110 | +# plot loop vector potential |
| 111 | +plot_amplitude(ax[1], b_total_pole) |
| 112 | + |
| 113 | + |
| 114 | +# set the titles |
| 115 | +ax[0].set_title("Total field: dipole") |
| 116 | +ax[1].set_title("Total field: pole") |
| 117 | + |
| 118 | +# format so text doesn't overlap |
| 119 | +plt.tight_layout() |
| 120 | +plt.show() |
0 commit comments