Skip to content

JPL Horizons SPK Generation

The brahe.datasets.horizons module generates, caches, and loads targeted SPK (.bsp) kernels for small bodies without packaged DE-kernel coverage via the JPL Horizons API. This unblocks third-body and solar radiation pressure perturbations for bodies such as Ceres, which are not contained in the DE kernels and therefore must be loaded separately.

HorizonsClient.get_spk(request) returns a HorizonsSPKResponse. The .bsp is cached under $BRAHE_CACHE/horizons (default ~/.cache/brahe/horizons) and reused whenever a kernel for the same request already exists, so a given body/span is downloaded only once. Setting BRAHE_NETWORK_MODE=offline serves cached data without any request; see Environment Variables.

Requesting and Loading an SPK

import brahe as bh

t0 = bh.Epoch.from_datetime(2015, 12, 1, 0, 0, 0.0, 0.0, bh.TimeSystem.TDB)
t1 = bh.Epoch.from_datetime(2016, 3, 1, 0, 0, 0.0, 0.0, bh.TimeSystem.TDB)

request = bh.datasets.horizons.HorizonsSPKRequest.for_spkid(20000001, t0, t1)
response = bh.datasets.horizons.HorizonsClient().get_spk(request)

response.load()
print(f"Cached at: {response.path}")
use brahe as bh;
use bh::datasets::horizons::{HorizonsClient, HorizonsSPKRequest};
use bh::time::{Epoch, TimeSystem};

fn main() {
    let t0 = Epoch::from_datetime(2015, 12, 1, 0, 0, 0.0, 0.0, TimeSystem::TDB);
    let t1 = Epoch::from_datetime(2016, 3, 1, 0, 0, 0.0, 0.0, TimeSystem::TDB);

    let request = HorizonsSPKRequest::for_spkid(20000001, t0, t1);
    let response = HorizonsClient::new().get_spk(&request).unwrap();

    response.load().unwrap();
    println!("Cached at: {}", response.path().display());
}

Request and Center

HorizonsSPKRequest.for_spkid(spkid, start, stop) targets a small body by SPK ID; HorizonsSPKRequest(command, start, stop) accepts a raw Horizons COMMAND. with_center(center) sets the requested ephemeris center (default "500@0"). In practice Horizons returns small-body SPKs centered on the Sun (NAIF 10) in the J2000/ICRF frame; loading de440s alongside supplies the Sun's position relative to the Solar System barycenter, so the two kernels chain and positions of the Sun and planets relative to the small body resolve for third-body and SRP forces.

Response

HorizonsSPKResponse exposes .path (cached .bsp path), .spk_file_id, and methods .bytes() (raw kernel bytes) and .load() (load into the SPICE registry).

See Also