from pathlib import Path
import spiceypy as spice
from planetarypy.spice import (
datasets,
download_generic_kernels,
get_metakernel_and_files,
list_kernels_for_day,
load_generic_kernels,
)NAIF Archived SPICE Kernels
datasets.head()| Mission Name | Archive Readme | Archive Link | PDS3 or PDS4 | Data Size (GB) | Start Time | Stop Time | Subset Link | |
|---|---|---|---|---|---|---|---|---|
| shorthand | ||||||||
| bc | BepiColombo | https://naif.jpl.nasa.gov/pub/naif/pds/pds4/bc... | https://naif.jpl.nasa.gov/pub/naif/pds/pds4/bc... | 4 | 4.5 | 2018-10-20 | 2025-05-31 | https://naif.jpl.nasa.gov/cgi-bin/subsetds.pl?... |
| clps | CLPS | https://naif.jpl.nasa.gov/pub/naif/pds/pds4/cl... | https://naif.jpl.nasa.gov/pub/naif/pds/pds4/cl... | 4 | 0.2 | 2024-01-08 | 2024-02-22 | https://naif.jpl.nasa.gov/cgi-bin/subsetds.pl?... |
| cassini | Cassini Orbiter | https://naif.jpl.nasa.gov/pub/naif/pds/data/co... | https://naif.jpl.nasa.gov/pub/naif/pds/data/co... | 3 | 73.5 | 1997-10-15 | 2017-09-15 | https://naif.jpl.nasa.gov/cgi-bin/subsetds.pl?... |
| clementine | Clementine | https://naif.jpl.nasa.gov/pub/naif/pds/data/cl... | https://naif.jpl.nasa.gov/pub/naif/pds/data/cl... | 3 | 0.8 | 1994-01-26 | 1994-05-07 | https://naif.jpl.nasa.gov/cgi-bin/subsetds.pl?... |
| dart | DART | https://naif.jpl.nasa.gov/pub/naif/pds/pds4/da... | https://naif.jpl.nasa.gov/pub/naif/pds/pds4/da... | 4 | 10.1 | 2021-11-09 | 2050-01-01 | https://naif.jpl.nasa.gov/cgi-bin/subsetds.pl?... |
def last_part(path, n):
"""Show only the last n parts from a pathlib.Path object or string."""
# this is useful to remove machine-specific leading paths
# and keep the notebook clean even when coded on different machines
path = Path(path) if isinstance(path, str) else path
return Path(*path.parts[-n:]) if n > 0 else pathBelow table shows all officially archived SPICE kernels from NAIF. These kernels are less often updated and are not guaranteed to be the most recent versions.
However, they are still useful for many applications and can be used as a stable reference.
Some ongoing missions like MRO and LRO regularly update their archived kernels, but not very frequently.
The datasets object is just a parsed table from the NAIF website here.
datasets.loc["bc"].valuesarray(['BepiColombo',
'https://naif.jpl.nasa.gov/pub/naif/pds/pds4/bc/bc_spice/document/spiceds_v005.html',
'https://naif.jpl.nasa.gov/pub/naif/pds/pds4/bc/bc_spice', '4',
'4.5', '2018-10-20', '2025-05-31',
'https://naif.jpl.nasa.gov/cgi-bin/subsetds.pl?dataset=bc/bc_spice'],
dtype=object)
list_kernels_for_day?Signature: list_kernels_for_day(mission: str, start: str, stop: str = '') -> list Docstring: List all kernels for a given time range of a mission. Parameters ---------- mission : str Mission shorthand in datasets dataframe. start : str Start time in either ISO or yyyy-jjj format. stop : str, optional Stop time in either ISO or yyyy-jjj format. Defaults to None. File: ~/Dropbox/src/planetarypy/src/planetarypy/spice/archived_kernels.py Type: function
list_kernels_for_day("messenger", "2011-01-01")['ck/msgr_1101_v02.bc',
'ck/msgr_mdis_gm040819_150430v1.bc',
'fk/msgr_dyn_v600.tf',
'fk/msgr_v231.tf',
'ik/msgr_epps_v100.ti',
'ik/msgr_grns_v110.ti',
'ik/msgr_mag_v021.ti',
'ik/msgr_mascs_v100.ti',
'ik/msgr_mdis_v160.ti',
'ik/msgr_mla_v010.ti',
'ik/msgr_rs_v111.ti',
'ik/msgr_xrs_v001.ti',
'lsk/naif0011.tls',
'pck/pck00010_msgr_v23.tpc',
'sclk/messenger_2548.tsc',
'spk/msgr_040803_150430_150430_od431sc_2.bsp',
'spk/msgr_antenna_v000.bsp']
Most useful function get_metakernel_and_files():
For a given mission and time-range, it downloads and stores all relevant archived kernels in a local archive, edits the provided meta-kernel from NAIF to point to the correct local paths, and returns the path to the local meta-kernel, ready to be loaded with spiceypy.furnsh().
mk_path = get_metakernel_and_files(
mission="cassini", start="2015-01-01", stop="2015-01-02"
)
last_part(mk_path, 3)Path('spice_kernels/cassini/cas_2015_v09_150101_150102.tm')
The meta-kernel can be loaded immediately with spiceypy, its internal paths have been updated to your local system:
spice.furnsh(str(mk_path)) # spiceypy requires a string pathGeneric Kernels
The below functions download and load a few generic kernels that enable some basic SPICE calculations with the major planetary bodies.
TODO: Script a test that shows for which bodies some basic calculations can be done.
load_generic_kernels() # uses below download_generic_kernels if any kernel from generic list is missing.download_generic_kernels()naif0012.tls already downloaded. Use `overwrite=True` to download again.
pck00010.tpc already downloaded. Use `overwrite=True` to download again.
de-403-masses.tpc already downloaded. Use `overwrite=True` to download again.
de430.bsp already downloaded. Use `overwrite=True` to download again.
mar097.bsp already downloaded. Use `overwrite=True` to download again.