Crate pracstro

Crate pracstro 

Source
Expand description

§pracstro - Compact Astronomy Library and Ephemeris Generator

pracstro is an astronomy library made from a collection of other algorithms that is compact, principled, and easy to understand. It’s made for calculating properties of celestial objects, such as the moon, sun, planets, and stars.

use pracstro::*;

let now_date = time::Date::from_calendar(2025, 4, 16, time::Angle::from_clock(0, 0, 0.0));
let now_time = time::Angle::from_clock(19, 41, 11.0);
let my_latitude = time::Angle::from_degrees(30.5);
let my_longitude = time::Angle::from_degrees(-110.0);

sol::VENUS.location(now_date).horizon(now_date, my_latitude, my_longitude); // Get the horizontal coordinates of Venus
moon::MOON.illumfrac(now_date); // The illuminated fraction of the moons surface
time::Angle::from_degrees(120.0).clock(); // 16h00m00s

§Benchmarks

Although speed is not a direct goal of this library, the simplicity of the algorithms used often makes the library much faster than other astronomy libraries. The tradeoff for this simplicity is some accuracy, though the library remains accurate enough for most real-world use.

Average of many tests, n = 40,000:

Testpracstroastro
Moon Phase558ns2,979ns (3µs)
Jupiter Coords601ns70,860ns (70µs)
Full ephemeris3,406ns (3.4µs)1,208,833ns (1.2ms)

§Structure

This library contains 4 primary modules, which build upon the ones before them:

  1. time for the conversion and representation of times, dates, and angles.
  2. coord for the conversion and representation of coordinates.
  3. sol for the calculation of properties of planets and the sun.
  4. moon for the calculation of properties of the moon.

Each of these have one or two types that represent a certain kind of data:

  • Date - An instant in continuous time.
  • Angle - An angle automatically corrected to be between [0°, 360°]. Which can also represent a time of day.
  • Coord - A pair of angles, representing latitude/longitude on a sphere.
  • Planet - A planets orbital properties, along with data required for orbital correction.
  • Moon - The moons orbital properties.

These types have methods to get the properties of this data. Primarily in pairs of methods that convert to/from a certain representation of that data. Although lone methods that get certain data for a type do exist.

Modules§

celobj
Celestial object trait for generics
coord
Coordinate handling
moon
Lunar Dynamics
sol
Solar Dynamics and handling of planets orbits
time
Time, Date, and Angle Handling