import skyloc as sloc
import spiceypy as sp
# try:
# import spiceypy.cyice as cy
# except ImportError:
# print("Check your spiceypy version:", sp.__version__)
# print("If < 7, cyice (Cython accelerated spiceypy) will not work.")
# import spiceypy as sp
# print("spiceypy.cyice not found; using spiceypy instead.")
# Specify the kernels to load, and save meta kernel.
# $KERNELS is a macro that points to the directory containing the SPICE kernels in skyloc package.
# $KERNELS = <path_to_skyloc>/src/kernels
sloc.spicetools.make_meta(
"$KERNELS/lsk/naif0012.tls", # Auxiliary file containing leap seconds
"$KERNELS/pck/gm_de440.tpc", # Auxiliary file containing G[6.67e-11]*M[mass] values
"$KERNELS/pck/pck00011.tpc", # Auxiliary file containing Planetary constants
"$KERNELS/satellites_2025-2027.bsp",
output="meta.mk"
)
# Load the kernels
handle = sp.furnsh("meta.mk")Planetary satellites with SPICE
Use this when the target is a planetary satellite and a SPICE kernel is more appropriate than small-body N-body propagation.
This is a static archive. The source expects local satellite BSP files, SPICE support files, spiceypy, and optional kete; it also queries Horizons. None of those cells run during a site build. Kernel coverage and the downloaded files must be checked for a new analysis.
Workflow in the source
The notebook prepares merged satellite kernels, converts UTC times to SPICE ephemeris time, compares spkezr state vectors with Horizons, and shows how satellite states can feed a kete field-of-view check. Positions are in km and velocities in km/s in the SPICE calls.
Source and current API
The full notebook is embedded below: markdown, code, saved text output, and the saved plot. You can also download the original notebook. See the SPICE API and external-data guide before loading kernels.
Planetary Satellites
Planetary satellites have very different orbits compared to small bodies. N-body simulations for these satellites are more complex due to their proximity to other satellites in the planetary system and the non-spherical shape of their parent planets. Therefore, it is more practical to use SPICE kernels rather than running our own N-body simulations (e.g., with kete). Additionally, kete lacks the functionality to handle satellites, as it cannot even read satellite SPICE kernels.
For your convenience, I have uploaded the two versions of files here: * satellites_2025-2027.bsp: Can calculate locations of satellites from year ~2025.0 to 2028.0 (2028 Jan 01) * satellites_2025-2035.bsp: Can calculate locations of satellites from year ~2025.0 to 2035.0 (2035 Jan 01)
Preparation
The SPICE kernels for the planetary satellites are unfortunately scattered across multiple files. These are at JPL’s ftp web link. Not all satellites are in a single BSP file (e.g., Jupiter moons are separately stored in jup344.bsp, jup346.bsp, and jup365.bsp, due to different references). See the summary at JPL.
As of Dec 2024, I find the following files can include all satellites covering the next decade (each of them downloadable here):
mar097.bsp
jup344.bsp, jup346.bsp, jup365.bsp
sat415.bsp, sat441.bsp, sat454.bsp
ura111.bsp, ura115.bsp, ura117.bsp
nep095.bsp, nep104.bsp
plu060.bsp
Using SPICE toolkit’s SPKMERGE, one can merge them with specific begin/end times to minimize the size of the merged file. How? Prepare spkmerge_setup.txt as:
LEAPSECONDS_KERNEL = lsk/naif0012.tls
SPK_KERNEL = satellites_2025-2027.bsp
BEGIN_TIME = 2024-12-31T00:00:00
END_TIME = 2028-01-01T23:59:59
SOURCE_SPK_KERNEL = nep104.bsp
SOURCE_SPK_KERNEL = jup365.bsp
SOURCE_SPK_KERNEL = ura111.bsp
SOURCE_SPK_KERNEL = sat415.bsp
SOURCE_SPK_KERNEL = ura115.bsp
SOURCE_SPK_KERNEL = ura117.bsp
SOURCE_SPK_KERNEL = jup344.bsp
SOURCE_SPK_KERNEL = mar097.bsp
SOURCE_SPK_KERNEL = jup346.bsp
SOURCE_SPK_KERNEL = nep095.bsp
SOURCE_SPK_KERNEL = sat441.bsp
SOURCE_SPK_KERNEL = plu060.bsp
SOURCE_SPK_KERNEL = sat454.bsp
- NOTE: I added ± 1 day margin to the BEGIN_TIME and END_TIME. Otherwise, SPICE calculation for 2025-01-01.00 or 2027-12-31.99 may fail because the objects’ information slightly outside the time range is required due to the light-time delay.
Then prepare lsk/naif0012.tls (or change as you wish). Put the above .bsp files properly at the directory you want. Run
$ spkmerge spkmerge_setup.txt
You must have SPICE toolkits installed. This will generate satellites_2025-2027.bsp. It is ~130MB (as of writing). If the timespan is changed to 2035, the file size is roughly 3.5x larger (480MB).
Unfortunately, they are in type 3 DAF. kete currently cannot read them, so let’s use spiceypy.
Calculate the satellites’ state vector at a given time by spkezr:
times, ets = sloc.spicetools.times2et(["2025-01-01", "2025-01-02"])
# times : astropy Time object
# ets : list of ET values (list of float) - This is the convention of time in SPICE toolkits
sp.spkezr(
"TITAN", ets[0], ref="J2000", abcorr="NONE", obs="JUPITER"
)(array([ 1.25847909e+09, -9.06164937e+08, -4.42362847e+08, 1.21446916e+01,
1.11678577e+01, 1.81843771e+00]),
5379.169023917955)
Compare with JPL Horizons query results
sta, one_way_lighttime = sp.spkezr(
"TITAN", ets[0], ref="J2000", abcorr="NONE", obs="EARTH"
)
r, ra, dec = sp.recrad(sta[:3])
# SPICE always use km & km/s as units for state vectors.
# You can convert to AU and AU/day:
# sta[:3] *= sloc.spicetools.KM2AU
# sta[3:] *= sloc.spicetools.KM2AU * 86400
# Titan's ID is "606" in JPL Horizons system.
# FYI, *asteroid* 606 can be specified as "606;" in Horizons.
vec_horizons = sloc.horizons_vector(
epochs=times.tdb.jd, obsid="606", location="500", refplane="earth", aberrations="geometric", spice_units=True
)
for name, val_sp in zip(["x", "y", "z", "vx", "vy", "vz"], sta):
val_hor = vec_horizons[0][name]
print(f"{name:>3}: SPICE: {val_sp:>+12.10f}, Horizons: {val_hor:>+12.10f}, diff: {val_sp - val_hor:>12.3e} ") x: SPICE: +1443191286.1082372665, Horizons: +1443191179.9270811081, diff: 1.062e+02
y: SPICE: -353905697.5318750143, Horizons: -353905745.6412109733, diff: 4.811e+01
z: SPICE: -210140466.4260762036, Horizons: -210140475.4359380305, diff: 9.010e+00
vx: SPICE: +28.9890287019, Horizons: +28.9890287184, diff: -1.653e-08
vy: SPICE: +19.1888986051, Horizons: +19.1888985997, diff: 5.452e-09
vz: SPICE: +5.5965226427, Horizons: +5.5965226309, diff: 1.187e-08
Note the lengths are in km, velocities in km/s. Very well matched!
Try abcorr of "LT", "LT+S", "CN" and "CN+S".
(Readers from the future: Please consider using spiceypy’s cyice).
Or using convenience function within sloc.spicetools:
788961669.1839275
[ 1.25847909e+09 -9.06164937e+08 -4.42362847e+08 1.21446916e+01
1.11678577e+01 1.81843771e+00] 5379.169023917955
789048069.1839565
[ 1.25944289e+09 -9.05247324e+08 -4.42194543e+08 1.02559316e+01
9.94557176e+00 2.07739937e+00] 5379.805795426772
import numpy as np
from IPython.core.interactiveshell import InteractiveShell
from matplotlib import pyplot as plt
from astropy.time import Time
from astropy import units as u
%config InlineBackend.figure_format = 'retina'
# %matplotlib notebook
InteractiveShell.ast_node_interactivity = 'last_expr'
# We need to do it in a separate cell. See:
# https://github.com/jupyter/notebook/issues/3385
plt.style.use('default')
plt.rcParams.update({
'font.family': 'latin modern math', 'font.size':12, 'mathtext.fontset':'stix',
'axes.formatter.use_mathtext': True, 'axes.formatter.limits': (-4, 4),
'axes.grid': True, 'grid.color': 'gray', 'grid.linewidth': 0.5,
'xtick.top': True, 'ytick.right': True,
'xtick.direction': 'inout', 'ytick.direction': 'inout',
'xtick.minor.size': 2.0, 'ytick.minor.size': 2.0, # default 2.0
'xtick.major.size': 4.0, 'ytick.major.size': 4.0, # default 3.5
'xtick.minor.visible': True, 'ytick.minor.visible': True
})
times, ets = sloc.spicetools.times2et(
Time("2025-12-01", format="iso", scale="utc") + np.arange(0, 100, 0.1)*u.day
)
states = []
states_jup = []
for et in ets:
states.append(
sp.spkezr("EUROPA", et, ref="ECLIPJ2000", abcorr="NONE", obs="SUN")[0]
)
states_jup.append(
sp.spkezr("JUPITER", et, ref="ECLIPJ2000", abcorr="NONE", obs="SUN")[0]
)
states = np.array(states)
states_jup = np.array(states_jup)
fig, axs = plt.subplots(1, 1, figsize=(8, 5), layout="constrained", gridspec_kw=None, sharex=False, sharey=False)
km2au = sp.convrt(1, "km", "au")
axs.plot(states[:, 0]*km2au, states[:, 1]*km2au, label="Europa")
axs.plot(states_jup[:, 0]*km2au, states_jup[:, 1]*km2au, label="Jupiter")
axs.plot(states_jup[0, 0]*km2au, states_jup[0, 1]*km2au, "kx", label="Jupiter (start)")
axs.set_aspect("equal")
axs.set(
title=f"Trace relative to Sun ({times[0].iso} to {times[-1].iso})",
xlabel="x_ecliptic_J2000 [au]", ylabel="y_ecliptic_J2000 [au]"
)
axs.legend()
plt.show();
import kete
kete.spice.loaded_objects()[('wise', -163),
('mercury barycenter', 1),
('venus barycenter', 2),
('earth barycenter', 3),
('mars barycenter', 4),
('jupiter barycenter', 5),
('saturn barycenter', 6),
('uranus barycenter', 7),
('neptune barycenter', 8),
('pluto barycenter', 9),
('sun', 10),
('mercury', 199),
('venus', 299),
('moon', 301),
('earth', 399),
('ceres', 20000001),
('pallas', 20000002),
('vesta', 20000004),
('hygiea', 20000010),
('interamnia', 20000704)]
from astropy.time import Time
import skyloc as sloc
# Just dummy times...
ets = (Time("2025-12-01", format="iso", scale="utc") + np.arange(0, 100, 20)*u.day).tdb.jd
# make FOVs
# In this test, each fov is with respect to earth (geocenter). You can use observer's state using [V]XYZ_SC
fovs = kete.fov.FOVList(
[kete.OmniDirectionalFOV(kete.spice.get_state("earth", _t)) for _t in ets]
)
# calculate with respect to the observer to get a list of SimultaneousStates
res = kete.fov_spice_check(["jupiter barycenter", "saturn barycenter", "ceres"], fovs)
res[SimultaneousStates(states=<3 States>, fov=OmniDirectional(observer=State(desig="earth", jd=2461010.50080073, pos=[0.3584958142367484, 0.9186653990497212, -5.799993632926714e-5], vel=[-0.016304439292145294, 0.006182883520110659, -8.364900966313996e-7], frame=Ecliptic, center_id=10))),
SimultaneousStates(states=<3 States>, fov=OmniDirectional(observer=State(desig="earth", jd=2461030.5008007362, pos=[0.017122832915672917, 0.9836958095612361, -5.6299552209204684e-5], vel=[-0.017488068180696807, 0.00023352416324300403, -2.1840777847353498e-7], frame=Ecliptic, center_id=10))),
SimultaneousStates(states=<3 States>, fov=OmniDirectional(observer=State(desig="earth", jd=2461050.500800743, pos=[-0.32631413873038706, 0.9277104424544123, -5.213779854268408e-5], vel=[-0.016510131594681794, -0.005767007983805858, 9.73080477219973e-7], frame=Ecliptic, center_id=10))),
SimultaneousStates(states=<3 States>, fov=OmniDirectional(observer=State(desig="earth", jd=2461070.5008007493, pos=[-0.6296590293061185, 0.7575097184212769, -4.438356664976384e-5], vel=[-0.013502746441976856, -0.011061758944416867, 9.852835720306624e-7], frame=Ecliptic, center_id=10))),
SimultaneousStates(states=<3 States>, fov=OmniDirectional(observer=State(desig="earth", jd=2461090.5008007544, pos=[-0.8559090976809022, 0.4945442106119232, -2.538627831569218e-5], vel=[-0.008888117068047138, -0.01496812938155697, 2.8864074667293155e-7], frame=Ecliptic, center_id=10)))]
Signature: sp.spkcvo( target: str, et: float, outref: str, refloc: str, abcorr: str, obssta: Union[numpy.ndarray, Iterable[float]], obsepc: float, obsctr: str, obsref: str, ) -> Tuple[numpy.ndarray, float] Docstring: Return the state of a specified target relative to an "observer," where the observer has constant velocity in a specified reference frame. The observer's state is provided by the calling program rather than by loaded SPK files. https://naif.jpl.nasa.gov/pub/naif/misc/toolkit_docs_N0067/C/cspice/spkcvo_c.html :param target: Name of target ephemeris object. :param et: Observation epoch in ephemeris seconds past J2000 TDB. :param outref: Reference frame of output state. :param refloc: Output reference frame evaluation locus. :param abcorr: Aberration correction. :param obssta: Observer state relative to center of motion. :param obsepc: Epoch of observer state. :param obsctr: Center of motion of observer. :param obsref: Frame of observer state. :return: State of target with respect to observer in km and km/sec, One way light time between target and observer. File: ~/miniforge3/envs/spxsim/lib/python3.11/site-packages/spiceypy/spiceypy.py Type: function
Init signature: kete.OmniDirectionalFOV(observer) Docstring: Omni Directional field of view. This is a good choice when the exact field is not important. Parameters ---------- observer : State of the omniscient observer. File: ~/Dropbox/github/kete_ipac/src/kete/__init__.py Type: type Subclasses:
# [State(desig="jupiter barycenter", jd=2461010.50080073, pos=[-1.4682287863177064, 4.989042466761555, 0.012125078638922204], vel=[-0.007333508082145677, -0.00177882835073639, 0.0001714625746178901], frame=Ecliptic, center_id=10),
# State(desig="jupiter barycenter", jd=2461030.5008007362, pos=[-1.6142608667834573, 4.951372770396637, 0.015548740908950087], vel=[-0.007268723857878194, -0.001987728673924908, 0.00017088039031012275], frame=Ecliptic, center_id=10),
# State(desig="jupiter barycenter", jd=2461050.500800743, pos=[-1.7589390720756417, 4.909550283102567, 0.01895936820280153], vel=[-0.00719813886567348, -0.0021940842547724694, 0.00017015928422162922], frame=Ecliptic, center_id=10),
# State(desig="jupiter barycenter", jd=2461070.5008007493, pos=[-1.9021484669470476, 4.863627304120381, 0.022354194736512456], vel=[-0.00712186082734981, -0.0023977544272176052, 0.00016930054974803523], frame=Ecliptic, center_id=10),
# State(desig="jupiter barycenter", jd=2461090.5008007544, pos=[-2.0437762704973643, 4.813658908278093, 0.025730479335764223], vel=[-0.007039996406968244, -0.0025986046906984967, 0.00016830504612330873], frame=Ecliptic, center_id=10)]Signature: kete.spice.get_state( target: 'Union[str, int]', jd: 'Union[float, Time]', center: 'str' = 'Sun', frame: 'Frames' = Frames.Ecliptic, ) -> 'State' Docstring: Calculates the :class:`~kete.State` of the target object at the specified time `jd`. This defaults to the ecliptic heliocentric state, though other centers may be chosen. Parameters ---------- target: The names of the target object, this can include any object name listed in :meth:`~kete.spice.loaded_objects` jd: Julian time (TDB) of the desired record. center: The center point, this defaults to being heliocentric. frame: Coordinate frame of the state, defaults to ecliptic. Returns ------- State Returns the ecliptic state of the target in AU and AU/days. Raises ------ ValueError If the desired time is outside of the range of the source binary file. File: ~/Dropbox/github/kete_ipac/src/kete/spice.py Type: function