.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/em/plot_static_magnetic_fields_from_pole_source.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_em_plot_static_magnetic_fields_from_pole_source.py: Total magnetic fields: Dipole and Pole sources ============================================== In this example, we plot anomalous total magnetic field from a magnetic dipole and pole targets. These targets are excited by Earth magnetic fields. We can vary the direction of the Earth magnetic field, and magnetic moment of the target. :author: Seogi Kang (`@sgkang `_) :date: Aug 19, 2018 .. GENERATED FROM PYTHON SOURCE LINES 15-25 .. code-block:: default import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import LogNorm from scipy.constants import mu_0, epsilon_0 from geoana import utils, spatial from geoana.em import static .. GENERATED FROM PYTHON SOURCE LINES 26-31 Setup ----- define the location, orientation, and source, physical properties of the wholespace and source parameters .. GENERATED FROM PYTHON SOURCE LINES 31-41 .. code-block:: default mu = mu_0 # permeability of free space (this is the default) location = np.r_[0., 0., -10.] # location of the dipole or pole # dipole parameters moment = 1 # inclination and declination (e.g. Vancouver) inclination, declination = 67., 0. .. GENERATED FROM PYTHON SOURCE LINES 42-47 Magnetostatic Dipole and Loop ----------------------------- Here, we build the geoana magnetic dipole and poie in a wholespace using the parameters defined above. .. GENERATED FROM PYTHON SOURCE LINES 47-68 .. code-block:: default def id_to_cartesian(inclination, declination): ux = np.cos(inclination/180.*np.pi)*np.sin(declination/180.*np.pi) uy = np.cos(inclination/180.*np.pi)*np.cos(declination/180.*np.pi) uz = -np.sin(inclination/180.*np.pi) return np.r_[ux, uy, uz] orientation = id_to_cartesian(inclination, declination) dipole = static.MagneticDipoleWholeSpace( location=location, orientation=orientation, moment=moment ) pole = static.MagneticPoleWholeSpace( location=location, orientation=orientation, moment=moment ) .. GENERATED FROM PYTHON SOURCE LINES 69-74 Evaluate magnetic fields -------------------------- Next, we construct a grid where we want to plot the magentic fields and evaluate .. GENERATED FROM PYTHON SOURCE LINES 74-84 .. code-block:: default x = np.linspace(-36, 36, 100) y = np.linspace(-36, 36, 100) xyz = utils.ndgrid([x, y, np.r_[1.]]) # evaluate the magnetic field b_vec_dipole = dipole.magnetic_flux_density(xyz) b_vec_pole = pole.magnetic_flux_density(xyz) b_total_dipole = dipole.dot_orientation(b_vec_dipole) b_total_pole = pole.dot_orientation(b_vec_pole) .. GENERATED FROM PYTHON SOURCE LINES 85-87 and define plotting code to plot an image of the amplitude of the vector field / flux as well as the streamlines .. GENERATED FROM PYTHON SOURCE LINES 88-100 .. code-block:: default def plot_amplitude(ax, v): plt.colorbar( ax.pcolormesh( x, y, v.reshape(len(x), len(y), order='F') ), ax=ax ) ax.axis('square') ax.set_xlabel('y (east, m)') ax.set_ylabel('x (north, m)') .. GENERATED FROM PYTHON SOURCE LINES 101-103 Create subplots for plotting the results. Loop over frequencies and plot the electric and magnetic fields along a slice through the center of the dipole. .. GENERATED FROM PYTHON SOURCE LINES 104-121 .. code-block:: default fig, ax = plt.subplots(1, 2, figsize=(12, 5)) # plot dipole vector potential plot_amplitude(ax[0], b_total_dipole) # plot loop vector potential plot_amplitude(ax[1], b_total_pole) # set the titles ax[0].set_title("Total field: dipole") ax[1].set_title("Total field: pole") # format so text doesn't overlap plt.tight_layout() plt.show() .. image-sg:: /auto_examples/em/images/sphx_glr_plot_static_magnetic_fields_from_pole_source_001.png :alt: Total field: dipole, Total field: pole :srcset: /auto_examples/em/images/sphx_glr_plot_static_magnetic_fields_from_pole_source_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.292 seconds) .. _sphx_glr_download_auto_examples_em_plot_static_magnetic_fields_from_pole_source.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_static_magnetic_fields_from_pole_source.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_static_magnetic_fields_from_pole_source.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_