Astronomy in pure Rust: time scales, the IAU coordinate chain, ephemerides, FITS/XISF/SER images, WCS, telescope pointing models, a star catalog and a plate solver.
Many astronomy libraries call ERFA or SOFA, which are written in C and Fortran. That works until you need to cross-compile for a mount controller, ship a single static binary, or step through the math in a debugger. Celestial has no FFI at runtime. The IAU models in celestial-core are tested against ERFA output with exact equality, so for those models you get the same numbers without the C dependency.
Here's a star going from its catalog position to azimuth and elevation at Keck, using the Earth orientation data bundled with celestial-coords:
use celestial_coords::eop::EopProvider;
use celestial_coords::frames::cirs::CIRSPosition;
use celestial_coords::frames::icrs::ICRSPosition;
use celestial_coords::transforms::CoordinateFrame;
use celestial_core::constants::MJD_ZERO_POINT;
use celestial_core::location::Location;
use celestial_time::julian::JulianDate;
use celestial_time::scales::conversions::{ToTAI, ToTT};
use celestial_time::scales::utc::UTC;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// EOP tables are indexed by UTC MJD; precession and nutation take TT.
let mjd = 60000.35;
let utc = UTC::from_julian_date(JulianDate::new(MJD_ZERO_POINT, mjd));
let epoch = utc.to_tai()?.to_tt()?;
let eop = EopProvider::bundled()?.get(mjd)?;
let keck = Location::from_degrees(19.8283, -155.4783, 4145.0)?;
let sirius = ICRSPosition::from_hours_degrees(6.7525, -16.716)?;
let cirs = CIRSPosition::from_icrs(&sirius, &epoch)?;
let hour_angle = cirs.to_hour_angle(&keck, &eop)?;
let horizon = hour_angle.to_topocentric()?;
println!(
"HA = {:.3} h, az = {:.2}°, el = {:.2}°",
hour_angle.hour_angle().hours(),
horizon.azimuth().degrees(),
horizon.elevation().degrees()
); // HA = 1.595 h, az = 214.36°, el = 46.53°
Ok(())
}Each step takes the input its physics needs: a TT epoch for precession and nutation, a site for the horizon, and Earth orientation parameters for the Earth's rotation. Each frame is its own type, so skipping a step is a compile error.
Pick the crate for the job. Each README has an example and the details.
| Crate | Use it to |
|---|---|
celestial-core |
work with angles, vectors and rotation matrices, and run the IAU precession, nutation and Earth orientation models |
celestial-time |
convert between UTC, TAI, TT, UT1, GPS, TDB, TCB and TCG, and compute sidereal time |
celestial-coords |
move positions through ICRS, GCRS, CIRS, TIRS and ITRS to hour angle and azimuth/elevation, with refraction and proper motion |
celestial-ephemeris |
compute Sun, Moon and planet positions from VSOP2013 and ELP/MPP02, or read JPL SPK kernels |
celestial-wcs |
convert between pixel and sky coordinates with FITS WCS headers, including SIP and TPV distortion |
celestial-images |
read and write FITS, XISF, SER, PNG and TIFF, and stretch and debayer images |
celestial-catalog |
run cone searches on a Gaia DR3 and Hipparcos catalog, and build the catalog file |
celestial-solver |
plate-solve an image and write the WCS solution back to its header |
celestial-pointing |
fit and apply pointing models for equatorial mounts, from code or an interactive shell |
Each crate depends only on crates earlier in this list:
| Crate | Depends on |
|---|---|
celestial-core |
nothing in the workspace |
celestial-time |
core |
celestial-wcs |
core |
celestial-ephemeris |
core, time |
celestial-coords |
core, time |
celestial-images |
core, time, wcs |
celestial-catalog |
core, time, coords |
celestial-pointing |
core, time, coords |
celestial-solver |
core, time, coords, wcs, images, catalog |
- The API is still changing. Expect breaking changes between releases.
- Pointing models cover equatorial mounts only. Alt-azimuth mounts aren't supported yet.
- To place a star in your sky, start with
celestial-coords. - To find where a planet or the Moon is, start with
celestial-ephemeris. - To solve an image, start with
celestial-solver. It needs the catalog file described incelestial-catalog. - To build a pointing model from a night of observations, start with
celestial-pointing. - For longer guides, see the book in
book/.
The toolchain is pinned in rust-toolchain.toml. Run the tests and lints the way CI does:
cargo test --workspace
cargo clippy --workspace -- -D warningsLicensed under either Apache 2.0 or MIT.