| 1 | # pracstro - Compact Astronomy Library and Ephemeris Generator |
| 2 | |
| 3 | pracstro is an astronomy library made from a collection of other algorithms that is |
| 4 | compact, principled, and easy to understand. It's made for calculating properties |
| 5 | of celestial objects, such as the moon, sun, planets, and stars. |
| 6 | |
| 7 | ``` |
| 8 | use pracstro::*; |
| 9 | let now_date = time::Date::from_calendar(2025, 4, 16.0); |
| 10 | let now_time = time::Angle::from_clock(19, 41, 11.0); |
| 11 | let my_latitude = time::Angle::from_degrees(30.5); |
| 12 | let my_longitude = time::Angle::from_degrees(-110.0); |
| 13 | sol::VENUS.location(now_date).horizon(now_date, now_time, my_latitude, my_longitude); // Get the horizontal coordinates of Venus |
| 14 | moon::MOON.phase(now_date).0; // The illuminated fraction of the moons surface |
| 15 | time::Angle::from_degrees(120.0).clock(); // 16h00m00s |
| 16 | ``` |
| 17 | |
| 18 | # Structure |
| 19 | This library contains 4 primary modules, which build upon the ones before them: |
| 20 | 1. `time` for the conversion and representation of times, dates, and angles. |
| 21 | 2. `coord` for the conversion and representation of coordinates. |
| 22 | 3. `sol` for the calculation of properties of planets and the sun. |
| 23 | 4. `moon` for the calculation of properties of the moon. |
| 24 | |
| 25 | Each of these have one or two types that represent a certain kind of data: |
| 26 | - `Date` - An instant in continuous time. |
| 27 | - `Angle` - An angle automatically corrected to be between \[0°, 360°\]. Which can also represent a time of day. |
| 28 | - `Coord` - A pair of angles, representing latitude/longitude on a sphere. |
| 29 | - `Planet` - A planets orbital properties, along with data required for orbital correction. |
| 30 | - `Moon` - The moons orbital properties. |
| 31 | |
| 32 | These types have methods to get the properties of this data. Primarily in pairs of methods that convert to/from a certain |
| 33 | representation of that data. Although lone methods that get certain data for a type do exist. |
| 34 | |
| 35 | ``` |
| 36 | use pracstro::*; |
| 37 | time::Angle::from_radians(time::Angle::from_decimal(16.0).radians()).clock(); |
| 38 | ``` |
| 39 | |
| 40 | # Benchmarks |
| 41 | |
| 42 | | Test | `pracstro` | [`astro`](https://crates.io/crates/astro) | |
| 43 | |----------------|----------------------|---------------------| |
| 44 | | Moon Phase | 558ns | 2,979ns (3µs) | |
| 45 | | Jupiter Coords | 601ns | 70,860ns (70µs) | |
| 46 | | Full ephemeris | 3,406ns (3.4µs) | 1,208,833ns (1.2ms) | |
| 47 | |
| 48 | # Goals |
| 49 | * **Simplicity** - The algorithms in this library should be parsimonious enough to be transcribed into several different languages. |
| 50 | * **0-dependency** - People using this library should not have to pull in 400 crates, it should do its job on its own accord. |
| 51 | * **Understandable Design** - The API for this library should be modular and understandable. |
| 52 | * **Correctness** - Although calculating the exact position of a planet or even star is not feasible in a library designed to be simple, algorithms |
| 53 | provided by this library should be good enough most real-world use. |
| 54 | * **Testing and documentation** - The bulk of the source code of this library is tests and documentation. As a general rule, bugs are a bad thing. |
| 55 | |
| 56 | # Non-Goals |
| 57 | * **Complete Accuracy** - There are an extremely large amount of factors which can throw values off over a long enough time. It is fortunate that most of these factors are negligible over time-spans of hundreds, or even in some cases thousands of years. Additionally, some of these effects (altitude, temperature, air-pressure) are not predictable. |
| 58 | * **Cataloging** - This library contains information about the Moon, Sun, and Planets (including Pluto). it does not however catalog minor planets or stars |
| 59 | * **Micro-optimization** - This library should be parsimonious and straightforward enough that *any optimization is premature optimization*. |
| 60 | |
| 61 | # Precision |
| 62 | |
| 63 | This library aims to be accurate enough across a large enough range of time for most user-end applications. |
| 64 | Its not perfect in its answers down to the arcsecond (nor could it be on a reasonable scale), |
| 65 | but is does provide enough accuracy for widgets, telescope pointing, scheduling ("Will I be able to see Venus this weekend?"), etc. |
| 66 | |
| 67 | # Resources |
| 68 | |
| 69 | Any substantial algorithm implemented from another source will be annotated with its source in this documentation. |
| 70 | This library started as an attempt to implement the algorithms from *Practical astronomy with Your Calculator*, |
| 71 | but branched out into different techniques. Most test cases in this library were either pulled from *Practical Astronomy with Your Calculator* |
| 72 | or created from data from Stellariun. |
| 73 | |
| 74 | The algorithms in this library are from several sources, mainly: |
| 75 | * <https://www.celestialprogramming.com/> by Greg Miller |
| 76 | * *Practical astronomy with Your Calculator* by Peter Duffett-Smith |
| 77 | * *Astronomical Formulae for Calculators* by Jean Meeus |
| 78 | |
| 79 | Additional tools similar to this in job: |
| 80 | * JPL's SPICE toolkit: https://naif.jpl.nasa.gov/naif/toolkit.html |
| 81 | * JPL's Online Horizons Ephemeris Generator: https://ssd.jpl.nasa.gov/horizons/ |
| 82 | * Stellarium - Full GUI Planetarium: https://stellarium.org/ |