celestial-ephemeris
Planetary and lunar ephemerides for astronomical calculations.
Pure Rust implementation of VSOP2013 planetary theory and ELP/MPP02 lunar theory, plus JPL SPK kernel support for high-precision ephemerides. No runtime FFI.
Installation
[]
= "0.1"
Modules
| Module | Purpose |
|---|---|
planets |
VSOP2013 planetary positions (Mercury through Pluto) |
earth |
VSOP2013 Earth heliocentric position |
sun |
Sun position (geocentric, derived from Earth ephemeris) |
moon |
ELP/MPP02 lunar theory (geocentric Moon position) |
jpl |
JPL SPK kernel reader (DE440, DE432s, etc.) |
Example
use ;
use ;
use ElpMpp02Moon;
use ;
// Create a TDB epoch
let tdb = TDBfrom_julian_date;
// Planetary positions (heliocentric ICRS, AU)
let mars = Vsop2013Mars;
let = mars.heliocentric_state?;
println!;
// Geocentric position
let geo_pos = mars.geocentric_position?;
println!;
// Moon position (geocentric ICRS, km)
let moon = new;
let moon_pos = moon.geocentric_position_icrs?;
println!;
JPL SPK Kernels
For higher precision, use JPL Development Ephemerides via SPK files:
use ;
let spk = open?;
// Get Mars barycenter state relative to Solar System Barycenter
let jd = 2451545.0; // J2000.0
let = spk.compute_state?;
println!;
println!;
Supported Bodies
use bodies;
SOLAR_SYSTEM_BARYCENTER // 0
MERCURY_BARYCENTER // 1
VENUS_BARYCENTER // 2
EARTH_MOON_BARYCENTER // 3
MARS_BARYCENTER // 4
JUPITER_BARYCENTER // 5
SATURN_BARYCENTER // 6
URANUS_BARYCENTER // 7
NEPTUNE_BARYCENTER // 8
PLUTO_BARYCENTER // 9
SUN // 10
MOON // 301
EARTH // 399
VSOP2013 Planets
All planets use the VSOP2013 theory with embedded coefficients:
| Struct | Body |
|---|---|
Vsop2013Mercury |
Mercury |
Vsop2013Venus |
Venus |
Vsop2013Earth |
Earth |
Vsop2013Mars |
Mars |
Vsop2013Jupiter |
Jupiter |
Vsop2013Saturn |
Saturn |
Vsop2013Uranus |
Uranus |
Vsop2013Neptune |
Neptune |
Vsop2013Pluto |
Pluto |
Vsop2013Emb |
Earth-Moon Barycenter |
Each provides:
heliocentric_position(&tdb)- Position relative to Sun (AU)heliocentric_state(&tdb)- Position and velocity (AU, AU/day)geocentric_position(&tdb)- Position relative to Earth (AU)geocentric_state(&tdb)- Position and velocity (AU, AU/day)
ELP/MPP02 Moon
use ElpMpp02Moon;
// Standard theory
let moon = new;
// With DE405 fit corrections
let moon_de405 = with_de405_fit;
// Geocentric position in mean ecliptic frame (km)
let pos_ecl = moon.geocentric_position?;
// Geocentric position in ICRS frame (km)
let pos_icrs = moon.geocentric_position_icrs?;
// Full state with velocity (km, km/day)
let state = moon.geocentric_state_icrs?;
Features
serde- Serialization supportcli- Build coefficient generation tools (vsop2013-gen, elpmpp02-gen)
Coefficient Ablation
The embedded VSOP2013 coefficients are ablated (filtered) from the full theory to reduce binary size while maintaining accuracy. The full VSOP2013 dataset contains millions of terms; we retain only terms with amplitude above a configurable threshold.
The vsop2013-gen tool (enabled with --features cli) handles this:
# Download original VSOP2013 data files
# Analyze term distribution at different thresholds
# Generate ablated Rust coefficients
The analyze command shows reduction statistics:
Planet Total Terms Above Thresh Reduction %
--------------------------------------------------------------------------------
Mercury 531456 12847 518609 2.4%
Venus 420328 8234 412094 2.0%
Earth-Moon Barycenter 460874 15632 445242 3.4%
...
Terms are filtered by amplitude: sqrt(S² + C²) > threshold.
Lower thresholds retain more terms (higher accuracy, larger binary).
The embedded coefficients are tuned for ±50 years from 2026 (1976-2076),
balancing binary size against accuracy for typical observatory use.
Accuracy
Tested against reference ephemerides:
| Theory | Valid Range | Position Error |
|---|---|---|
| VSOP2013 | ±50 years | < 5,000 km (inner), < 50,000 km (outer) |
| ELP/MPP02 | ±50 years | < 5 km vs JPL DE441 |
| JPL DE440 | Kernel-dependent | Sub-meter |
Note: VSOP2013 errors are relative to full-precision VSOP2013 reference data, not JPL DE. For pointing applications, these translate to sub-arcsecond accuracy for inner planets and ~1" for outer planets at typical observing distances.
License
Licensed under either of:
- Apache License, Version 2.0
- MIT License
Contributing
See the repository for contribution guidelines.