.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated_examples/mercury-schematic.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_generated_examples_mercury-schematic.py: Creating a schematic of spacecraft orbits in Mercury's magnetosphere ==================================================================== In this example, we talk through how create a to-scale schematic of Mercury's magnetosphere, inlcuding average boundary locations, and sample orbits from both MESSENGER and predictions from BepiColombo's MPO and Mio. .. GENERATED FROM PYTHON SOURCE LINES 8-22 .. code-block:: Python import matplotlib as mpl import matplotlib.pyplot as plt import spiceypy as spice from matplotlib.patches import Circle from sunpy.time import TimeRange from hermpy.net import ClientSPICE from hermpy.plotting import plot_magnetospheric_boundaries from hermpy.utils import Constants as c # Controls the plot border width mpl.rcParams["axes.linewidth"] = 2 .. GENERATED FROM PYTHON SOURCE LINES 23-26 We start by outlining some times from which to fetch orbits. Here we use ``TimeRange`` from `sunpy`_. .. _sunpy: https://www.sunpy.org/ .. GENERATED FROM PYTHON SOURCE LINES 26-29 .. code-block:: Python bepi_time_range = TimeRange("2026-08-15", "2026-08-16") messenger_time_range = TimeRange("2012-08-01", "2012-08-02") .. GENERATED FROM PYTHON SOURCE LINES 30-36 We use ``hermpy.net.ClientSPICE`` to aid in the downloading a querying of SPICE kernels. We designate specific SPICE kernels to download which we require to get positions for BepiColombo's MPO and Mio, along with MESSENGER. See `here`_ for more details. .. _here: spice.html .. GENERATED FROM PYTHON SOURCE LINES 36-64 .. code-block:: Python spice_client = ClientSPICE() spice_client.KERNEL_LOCATIONS.update( { "MESSENGER": { "BASE": "https://naif.jpl.nasa.gov/pub/naif/", "DIRECTORY": "pds/data/mess-e_v_h-spice-6-v1.0/messsp_1000/data/spk/", "PATTERNS": ["msgr_??????_??????_??????_od431sc_2.bsp"], }, "BepiColombo": { "BASE": "http://spiftp.esac.esa.int/data/SPICE/BEPICOLOMBO/", "DIRECTORY": "kernels/spk/", "PATTERNS": [ "de432s.bsp", "bc_sci_v02.bsp", "bc_mpo_mlt_50037_20260314_20280529_v05.bsp", "bc_mmo_mlt_50038_20251220_20280305_v05.bsp", ], }, "BepiColombo Frames": { "BASE": "http://spiftp.esac.esa.int/data/SPICE/BEPICOLOMBO/", "DIRECTORY": "kernels/fk/", "PATTERNS": [ "bc_sci_v12.tf", ], }, } ) .. GENERATED FROM PYTHON SOURCE LINES 65-69 The time ranges defined earlier are used to query the positions for those times in the Mercury-Solar-Magnetospheric (MSM) frame. Those postions are divided by Mercury's radius (``hermpy.utils.Constants``) so our plot will be in units of Mercury radii. .. GENERATED FROM PYTHON SOURCE LINES 69-87 .. code-block:: Python with spice_client.KernelPool(): bepi_times = [t.center.to_datetime() for t in bepi_time_range.split(1000)] bepi_ets = spice.datetime2et(bepi_times) mpo_positions, _ = spice.spkpos("MPO", bepi_ets, "BC_MSM", "NONE", "MERCURY") mpo_positions /= c.MERCURY_RADIUS.to("km").value mmo_positions, _ = spice.spkpos("MMO", bepi_ets, "BC_MSM", "NONE", "MERCURY") mmo_positions /= c.MERCURY_RADIUS.to("km").value messenger_times = [t.center.to_datetime() for t in messenger_time_range.split(1000)] messenger_ets = spice.datetime2et(messenger_times) messenger_positions, _ = spice.spkpos( "MESSENGER", messenger_ets, "BC_MSM", "NONE", "MERCURY" ) messenger_positions /= c.MERCURY_RADIUS.to("km").value .. GENERATED FROM PYTHON SOURCE LINES 88-105 We create our plot, and begin by plotting the above positions. The are in the form of a 2D array, with each column corresopnding to x, y, and z respectively. We define some settings for the axis here as well, to centre the orbits in the panel. We add labels using matplotlib's builtin ``ax.text``, and position them manually. ``hermpy.plotting.plot_magnetospheric_boundaries`` can be used to add average bow shock and magnetopause boundary locations to the axis, as determined by Winslow et al. (2013) [`link`_]. .. _link: https://doi.org/10.1002/jgra.50237 Finally, we use matplotlib's ``Circle`` patch to draw Mercury. In the MSM coordinate system, Mercury's geographical centre is offset from the centre of the coordinate system: the dipole. .. GENERATED FROM PYTHON SOURCE LINES 105-156 .. code-block:: Python fig, ax = plt.subplots() ax.set( xlim=(-3, 6), ylim=(-6, 3), xticks=[], yticks=[], aspect="equal", ) spacecraft_params = { "lw": 3, } ax.plot( mpo_positions[:, 0], # X mpo_positions[:, 2], # Z color="blue", **spacecraft_params, ) ax.plot( mmo_positions[:, 0], mmo_positions[:, 2], color="red", **spacecraft_params, ) ax.plot( messenger_positions[:, 0], messenger_positions[:, 2], color="orange", zorder=0, **spacecraft_params, ) ax.text(1.8, 0.8, "MPO", color="blue", weight="bold") ax.text(4.8, 0, "Mio", color="red", weight="bold") ax.text(0.5, -5, "MESSENGER", color="orange", weight="bold") # WARNING: This function will likely change in future versions plot_magnetospheric_boundaries(ax, "xz", lw=2, zorder=-1) mercury_circle = Circle( (0, -c.DIPOLE_OFFSET_RADII), radius=1, linewidth=3, facecolor="lightgrey", edgecolor="black", ) ax.add_artist(mercury_circle) plt.show() .. image-sg:: /generated_examples/images/sphx_glr_mercury-schematic_001.png :alt: mercury schematic :srcset: /generated_examples/images/sphx_glr_mercury-schematic_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 11.580 seconds) .. _sphx_glr_download_generated_examples_mercury-schematic.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: mercury-schematic.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: mercury-schematic.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: mercury-schematic.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_