satkit/lib.rs
1//! # SatKit: Satellite Toolkit
2//!
3//! A comprehensive, high-performance satellite astrodynamics library combining the speed of Rust
4//! with the convenience of Python. SatKit provides industrial-grade satellite orbital mechanics
5//! calculations with a clean, intuitive API. Built from the ground up in Rust for maximum performance
6//! and memory safety, it offers complete Python bindings for all functionality, making advanced orbital
7//! mechanics accessible to both systems programmers and data scientists.
8//!
9//! ## Core Features
10//!
11//! ### Time Systems
12//! - Comprehensive timescale transformations (UTC, GPS, UT1, TDB, TT, TAI)
13//! - Leap second handling
14//! - High-precision time arithmetic and conversions
15//!
16//! ### Coordinate Frame Transformations
17//! High-precision coordinate transforms between multiple reference frames:
18//! - **International Terrestrial Reference Frame (ITRF)**: Earth-fixed frame
19//! - **Geocentric Celestial Reference Frame (GCRF)**: Inertial frame using IERS 2010 reduction
20//! - **True Equinox Mean Equator (TEME)**: Frame used in SGP4 propagation
21//! - **Celestial Intermediate Reference Frame (CIRF)**: IERS 2010 intermediate frame
22//! - **Terrestrial Intermediate Reference Frame (TIRF)**: Earth-rotation intermediate frame
23//! - **RTN / NTW / LVLH**: Satellite-local frames for maneuvers, thrust, and
24//! covariance (`RTN` is the CCSDS OEM canonical name; `RIC` and `RSW` are aliases)
25//! - **Geodetic Coordinates**: Latitude, longitude, altitude conversions
26//!
27//! Unified API: [`frametransform::rotation`] / [`frametransform::transform_state`]
28//! dispatch any Earth-chain frame pair, [`frametransform::rotation_with_state`]
29//! additionally covers the orbit-local frames (RTN / NTW / LVLH), and
30//! [`frametransform::to_gcrf`] / [`frametransform::from_gcrf`] give the
31//! orbit-local direction-cosine matrices directly — together they replace the
32//! per-frame helper explosion.
33//!
34//! ### Orbit Propagation
35//! Multiple propagation methods for various accuracy requirements:
36//! - **SGP4**: Simplified General Perturbations for Two-Line Element (TLE) sets with fitting capability
37//! - **Numerical Integration**: High-precision propagation using adaptive
38//! Runge-Kutta (9(8), 8(7), 6(5), 5(4)), RODAS4 (stiff), or **Gauss-Jackson 8**
39//! (fixed-step multistep predictor-corrector specialised for long-duration
40//! orbit propagation, with per-step dense output)
41//! - **Keplerian**: Simplified two-body propagation
42//! - **State Transition Matrix**: Support for covariance propagation
43//! - **Configurable `max_steps`**: [`PropSettings::max_steps`] bounds runaway propagation
44//!
45//! ### Orbit Maneuvers
46//! - **Impulsive maneuvers**: Instantaneous delta-v at scheduled times in GCRF,
47//! RTN (= RIC / RSW), NTW, or LVLH frames. Ergonomic helpers (`prograde`,
48//! `retrograde`, `radial_out`, `normal`) cover the common scalar-magnitude burns.
49//! - **Continuous thrust**: Constant-acceleration arcs integrated into the force model
50//! - Automatic propagation segmentation through maneuver sequences, including
51//! backward propagation
52//!
53//! ### Force Models
54//! Comprehensive perturbation modeling:
55//! - High-order Earth gravity (JGM2, JGM3, EGM96, ITU GRACE16)
56//! - Solar and lunar gravity perturbations
57//! - Atmospheric drag using NRLMSISE-00 density model with space weather data
58//! - Solar radiation pressure
59//! - Continuous thrust acceleration
60//!
61//! ### Ephemerides
62//! - **JPL Ephemerides**: High-precision planetary and lunar positions
63//! - **Low-Precision Ephemerides**: Fast analytical models for sun and moon
64//!
65//! ### Additional Capabilities
66//! - Keplerian orbital elements and conversions
67//! - Geodesic distance calculations
68//! - TLE parsing, generation, and orbit fitting
69//!
70//! ## Language Bindings
71//!
72//! - **Rust**: Native library available on [crates.io](https://crates.io/crates/satkit)
73//! - **Python**: Complete Python bindings via PyO3, available on [PyPI](https://pypi.org/project/satkit/)
74//! - Binary wheels for Windows, macOS (Intel & ARM), and Linux (x86_64 & ARM64)
75//! - Python versions 3.10 through 3.14
76//! - Documentation at <https://satkit.dev/>
77//!
78//! ## Linear Algebra
79//!
80//! SatKit uses the [`numeris`](https://crates.io/crates/numeris) crate for all linear algebra
81//! (vectors, matrices, quaternions, ODE solvers). Types are re-exported via [`mathtypes`].
82//! If you need nalgebra types for interoperability with other crates, enable the `nalgebra`
83//! feature on `numeris` for zero-cost `From`/`Into` conversions:
84//!
85//! ```toml
86//! numeris = { version = "0.5.7", features = ["nalgebra"] }
87//! ```
88//!
89//! ## Optional Features
90//!
91//! - **chrono**: Enables interoperability with `chrono::DateTime` by implementing the `TimeLike` trait.
92//! Activate with Cargo feature `chrono`.
93//!
94//! ## Getting Started
95//!
96//! ### Data Files
97//!
98//! The library requires external data files for many calculations:
99//!
100//! - [JPL Planetary Ephemerides](https://ssd.jpl.nasa.gov/ephem.html) - High-precision planetary positions
101//! - [Earth Gravity Models](http://icgem.gfz-potsdam.de/) - Spherical harmonic coefficients
102//! - [Space Weather Data](https://celestrak.org/SpaceData/) - Solar flux and geomagnetic indices
103//! - [Earth Orientation Parameters](https://celestrak.org/SpaceData/) - Polar motion and UT1-UTC
104//! - [IERS Conventions Tables](https://www.iers.org/IERS/EN/Publications/TechnicalNotes/tn36.html) - Nutation coefficients
105//!
106//! Data files need to be downloaded once. Space weather and Earth orientation parameter files are
107//! updated daily and should be refreshed periodically for optimal accuracy.
108//!
109//! ### Downloading Data Files
110//!
111//! Requires building with the `download` Cargo feature.
112//!
113//! ```no_run
114//! // Print the directory where data will be stored
115//! println!("Data directory: {:?}", satkit::utils::datadir());
116//!
117//! // Download required data files
118//! // - Downloads missing files
119//! // - Updates space weather and Earth orientation parameters
120//! // - Skips files that already exist
121//! # #[cfg(feature = "download")]
122//! satkit::utils::update_datafiles(None, false);
123//! ```
124//!
125//! ## Example Usage
126//!
127//! ```no_run
128//! use satkit::prelude::*;
129//!
130//! // Create a time instant
131//! let time = Instant::from_datetime(2024, 1, 1, 12, 0, 0.0).unwrap();
132//!
133//! // Coordinate frame transformations
134//! let itrf_pos = ITRFCoord::from_geodetic_deg(42.0, -71.0, 100.0);
135//!
136//! // Get planetary ephemeris
137//! let (moon_pos, moon_vel) = satkit::jplephem::geocentric_state(
138//! SolarSystem::Moon,
139//! &time
140//! ).unwrap();
141//! ```
142//!
143//! ## Running Tests
144//!
145//! Tests require external data files and test vectors. Download them with the provided scripts:
146//!
147//! ```bash
148//! pip install requests
149//! python python/test/download_testvecs.py
150//! ```
151//!
152//! Then run with the environment variables set:
153//!
154//! ```bash
155//! SATKIT_DATA=astro-data SATKIT_TESTVEC_ROOT=satkit-testvecs cargo test
156//! ```
157//!
158//! ## References
159//!
160//! This implementation relies heavily on the following excellent references:
161//!
162//! - **"Fundamentals of Astrodynamics and Applications, Fourth Edition"**
163//! by D. Vallado, Microcosm Press and Springer, 2013
164//! - **"Satellite Orbits: Models, Methods, Applications"**
165//! by O. Montenbruck and E. Gill, Springer, 2000
166//!
167//! ## License
168//!
169//! MIT License - See LICENSE file for details
170
171#![warn(clippy::all, clippy::use_self, clippy::cargo)]
172#![allow(clippy::multiple_crate_versions)]
173
174// Math type definitions using the numeris crate
175pub mod mathtypes;
176
177/// Universal constants
178pub mod consts;
179/// Earth orientation parameters (polar motion, delta-UT1, length of day)
180pub mod earth_orientation_params;
181/// Zonal gravity model for Earth gravity
182pub mod earthgravity;
183/// Conversion between coordinate frames
184pub mod frametransform;
185/// International Terrestrial Reference Frame coordinates &
186/// transformations to Geodetic, East-North-Up, North-East-Down
187pub mod itrfcoord;
188/// Solar system body ephemerides, as published by the Jet Propulsion Laboratory (JPL)
189pub mod jplephem;
190/// Keplerian orbital elements
191pub mod kepler;
192/// Lambert's problem solver for orbital targeting
193pub mod lambert;
194/// Low-precision ephemeris for sun and moon
195pub mod lpephem;
196/// NRLMSISE-00 Density model
197pub mod nrlmsise;
198/// High-Precision Orbit Propagation using numeris ODE solvers
199pub mod orbitprop;
200/// SGP-4 Orbit Propagator
201pub mod sgp4;
202/// Solar Cycle Forecast (NOAA/SWPC predicted F10.7)
203pub mod solar_cycle_forecast;
204/// Solar system bodies
205mod solarsystem;
206/// Space Weather
207pub mod spaceweather;
208/// Two-line Element Set
209pub mod tle;
210/// Utility functions
211pub mod utils;
212
213/// Coordinate frames (re-exported as `Frame` at crate root)
214pub mod frames;
215
216// Orbital Mean-Element Messages
217pub mod omm;
218
219// Time and duration
220mod time;
221pub use time::{
222 Duration, Instant, InstantError, InvalidTimeScale, InvalidWeekday, TimeLike, TimeScale, Weekday,
223};
224
225// Top-level façade error type (deprecated 0.17.0; re-exported for source compat).
226mod error;
227#[allow(deprecated)]
228pub use error::{Error, Result};
229
230// Core types available at crate level
231pub use frames::Frame;
232pub use itrfcoord::{Geodetic, ITRFCoord};
233pub use kepler::Kepler;
234pub use mathtypes::{Quaternion, Vector3};
235pub use orbitprop::{propagate, PropSettings, SatState};
236pub use solarsystem::SolarSystem;
237pub use tle::TLE;
238
239/// Prelude for convenient wildcard import.
240///
241/// Brings the most commonly used types, traits, and functions into scope.
242///
243/// ```
244/// use satkit::prelude::*;
245/// ```
246pub mod prelude {
247 // Math types
248 pub use crate::mathtypes::{Matrix3, Matrix6, Quaternion, Vector3, Vector6};
249
250 // Time
251 pub use crate::time::{Duration, Instant, TimeLike, TimeScale, Weekday};
252
253 // Core types
254 pub use crate::frames::Frame;
255 pub use crate::itrfcoord::{Geodetic, ITRFCoord};
256 pub use crate::kepler::{Anomaly, Kepler};
257 pub use crate::lambert::lambert;
258 pub use crate::omm::OMM;
259 pub use crate::solarsystem::SolarSystem;
260 pub use crate::tle::TLE;
261
262 // Propagation
263 pub use crate::orbitprop::{
264 propagate, CovState, PropSettings, PropagationResult, SatProperties, SatPropertiesSimple,
265 SatState, SimpleState, StateCov,
266 };
267
268 // SGP4
269 pub use crate::sgp4::{sgp4, GravConst, OpsMode, SGP4State};
270
271 // Frame transforms
272 pub use crate::frametransform::{qgcrf2itrf, qitrf2gcrf, qteme2gcrf, qteme2itrf};
273
274 // Gravity
275 pub use crate::earthgravity::GravityModel;
276}