.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/em/plot_static_vector_potentials.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_vector_potentials.py: Magnetostatic Vector Potentials: Dipole and Loop Sources ======================================================== In this example, we plot the vector potential for a dipole and a loop source in a wholespace. We can vary the magnetic permeability of the wholespace, location and orientation of the sources. For the dipole source, we can vary the moment, and for the loop source, we can vary the radius and current through the loop. :author: Lindsey Heagy (`@lheagy `_) :date: June 6, 2018 .. GENERATED FROM PYTHON SOURCE LINES 16-26 .. 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 27-32 Setup ----- define the location orientation and source, physical properties of the wholespace and source parameters .. GENERATED FROM PYTHON SOURCE LINES 32-45 .. code-block:: default mu = mu_0 # permeability of free space (this is the default) location=np.r_[0., 0., 0.] # location of the dipole orientation='Z' # vertical dipole (can also be a unit-vector) # dipole parameters moment = 1 # loop source parameters current = 1 radius = 20 .. GENERATED FROM PYTHON SOURCE LINES 46-55 Magnetostatic Dipole and Loop ----------------------------- Here, we build the geoana magnetic dipole in a wholespace and circular loop in a wholespace using the parameters defined above. For a full list of the properties you can set on a dipole, see the :class:`geoana.em.static.MagneticDipoleWholeSpace` docs and for the circular loop source, see the :class:`geoana.em.static.CircularLoopWholeSpace` docs .. GENERATED FROM PYTHON SOURCE LINES 55-67 .. code-block:: default dipole = static.MagneticDipoleWholeSpace( mu=mu, location=location, orientation=orientation , moment=moment ) loop = static.CircularLoopWholeSpace( mu=mu, location=location, orientation=orientation, current=current, radius=radius ) .. GENERATED FROM PYTHON SOURCE LINES 68-73 Evaluate vector potential -------------------------- Next, we construct a grid where we want to plot the vector potential and evaluate .. GENERATED FROM PYTHON SOURCE LINES 73-82 .. code-block:: default x = np.linspace(-50, 50, 100) y = np.linspace(-50, 50, 100) xyz = utils.ndgrid([x, y, np.r_[0]]) # evaluate the vector potential a_dipole = dipole.vector_potential(xyz) a_loop = loop.vector_potential(xyz) .. GENERATED FROM PYTHON SOURCE LINES 83-85 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 86-106 .. code-block:: default def plot_amplitude(ax, v): v = spatial.vector_magnitude(v) plt.colorbar( ax.pcolormesh( x, y, v.reshape(len(x), len(y), order='F'), norm=LogNorm() ), ax=ax ) ax.axis('square') ax.set_xlabel('x (m)') ax.set_ylabel('y (m)') # plot streamlines def plot_streamlines(ax, v): vx = v[:, 0].reshape(len(x), len(y), order='F') vy = v[:, 1].reshape(len(x), len(y), order='F') ax.streamplot(x, y, vx.T, vy.T, color='k') .. GENERATED FROM PYTHON SOURCE LINES 107-109 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 110-131 .. code-block:: default fig, ax = plt.subplots(1, 2, figsize=(12, 5)) # plot dipole vector potential plot_amplitude(ax[0], a_dipole) plot_streamlines(ax[0], a_dipole) # plot loop vector potential plot_amplitude(ax[1], a_loop) plot_streamlines(ax[1], a_loop) # set the titles ax[0].set_title("$\\vec{A}$: dipole") ax[1].set_title("$\\vec{A}$: loop") # format so text doesn't overlap fig.tight_layout() plt.show() .. image-sg:: /auto_examples/em/images/sphx_glr_plot_static_vector_potentials_001.png :alt: $\vec{A}$: dipole, $\vec{A}$: loop :srcset: /auto_examples/em/images/sphx_glr_plot_static_vector_potentials_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.060 seconds) .. _sphx_glr_download_auto_examples_em_plot_static_vector_potentials.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_vector_potentials.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_static_vector_potentials.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_