.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated_examples/spice.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_spice.py: Using SPICE kernels with hermpy =============================== In this example, we show how ``hermpy.net.ClientSPICE`` can be used to download, access, and use SPICE kernels from multiple sources. .. GENERATED FROM PYTHON SOURCE LINES 8-13 .. code-block:: Python import datetime as dt import spiceypy as spice .. GENERATED FROM PYTHON SOURCE LINES 14-20 ``hermpy.net`` introduces a client to handle the caching and fetching of SPICE kernels. There are some default kernels included by default, but more can be added on the fly. If you feel your additions would make sense as permanent inclusion, please open a PR. .. GENERATED FROM PYTHON SOURCE LINES 20-24 .. code-block:: Python from hermpy.net import ClientSPICE spice_client = ClientSPICE() .. GENERATED FROM PYTHON SOURCE LINES 25-36 Adding kernels -------------- Kernels can be added to the SPICE client through updating the ``KERNEL_LOCATIONS`` dictionary. ``KERNEL_LOCATIONS`` expects the format seen below, with a base url (``BASE``), a subdirectory (``DIRECTORY``), and a list of filepatterns to search for (``PATTERNS``). The outermost key is purely to help describe the addition and is not used internally. Character wildcards are represented as '?'. Here we show an example of adding MESSENGER mission kernels, and a coordinate system kernel defined for the BepiColombo mission. .. GENERATED FROM PYTHON SOURCE LINES 36-56 .. code-block:: Python spice_client.KERNEL_LOCATIONS.update( { "MESSENGER Frames (tf)": { "BASE": "https://naif.jpl.nasa.gov/pub/naif/", "DIRECTORY": "pds/data/mess-e_v_h-spice-6-v1.0/messsp_1000/data/fk/", "PATTERNS": ["msgr_dyn_v600.tf"], }, "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 Frames": { "BASE": "https://naif.jpl.nasa.gov/pub/naif/", "DIRECTORY": "pds/pds4/bc/bc_spice/spice_kernels/fk/", "PATTERNS": ["bc_sci_v12.tf"], }, } ) .. GENERATED FROM PYTHON SOURCE LINES 57-61 Loading kernels with ``spiceypy`` --------------------------------- We open a context in which we load kernels from ``ClientSPICE``. For more details see the ``spiceypy documentation. .. GENERATED FROM PYTHON SOURCE LINES 61-67 .. code-block:: Python with spice.KernelPool(spice_client.fetch()): et = spice.datetime2et(dt.datetime(2012, 6, 1)) position, _ = spice.spkpos("MESSENGER", et, "BC_MSO_AB", "NONE", "Mercury") print(position) .. rst-class:: sphx-glr-script-out .. code-block:: none Files Downloaded: 0%| | 0/8 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: spice.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: spice.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_