Rust astronomy
Need help with astro-rust?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.
saurvs

Description

Astronomical algorithms in Rust

138 Stars 21 Forks MIT License 14 Commits 9 Opened issues

Services available

Need anything else?

astro-rust

Contents

API Docs

About

astro-rust
is a library of advanced astronomical algorithms for the Rust programming language.

Implemented algorithms include:

  • planetary and solar positioning by the complete set of elements of Bretagnon and Francou's VSP087 theory
  • lunar positioning by the principle elements of Chapront's ELP-2000/82 theory
  • satellite positioning for Saturn and Jupiter
  • finding Julian dates, sidereal time, dynamical time, equinoxes, rising and setting times, times of lunar phases
  • coordinate transformations
  • corrections for precession, nutation, parallax, aberration, atmospheric refraction
  • calculation of the physical ephemeris for Mars, Jupiter, and the rings of Saturn
  • finding position angles, illuminated fractions, visual magnitudes
  • and much more.

Usage

  • Add the dependency

    astro
    in your
    Cargo.toml
    toml
    [dependencies]
    astro = "2.0.0"
    
  • Include the crate

    astro
    in your code ```rust extern crate astro;

use astro::*; ```

  • Specify your time of interest using the Julian day ```rust // for example, the time of the Apollo 11 moon landing

let dayofmonth = time::DayOfMonth{day : 20, hr : 20, min : 18, sec : 4.0, time_zone: 0.0};

let date = time::Date{year : 1969, month : 7, // July decimalday: time::decimalday(&dayofmonth), cal_type : time::CalType::Gregorian};

let julianday = time::julianday(&date);

// for higher accuracy in specifying the time of interest, // find the Julian Ephemeris day; this slightly differs from // the Julian day by ΔT, which is usually a few seconds. you // can get a reported value of it from the Astronomical // Almanac, or calculate it using the built-in function

let deltat = time::deltat(date.year, date.month);

let julianephmday = time::julianephemerisday(julianday, deltat); ```

  • Find the position of the Sun and the Moon with respect to the Earth ```rust

// geocentric ecliptic point and radius vector of the Sun let (suneclpoint, radvecsun) = sun::geocenteclpos(julian_day);

// suneclpoint.long - ecliptic longitude (radians) // suneclpoint.lat - ecliptic latitude (radians) // radvecsun - distance between the Sun and the Earth (AU)

// and similarly for the Moon let (mooneclpoint, radvecmoon) = lunar::geocenteclpos(julian_day);

* Find the position of a planet with respect to the Sun
  ```rust
  // the heliocentric point and radius vector of a planet, like Jupiter
  let (jup_long, jup_lat, rad_vec) = planet::heliocent_pos(&planet::Planet::Jupiter, julian_day);

// or neptune let (nep_long, nep_lat, rad_vec) = planet::heliocent_pos(&planet::Planet::Neptune, julian_day);

// positioning for all the eight planets (and (the dwarf planet) Pluto) is supported let (plut_long, plut_lat, rad_vec) = pluto::heliocent_pos(julian_day);

  • Find the geodesic distance between two locations on Earth ```rust // geodesic distance between the Observatoire de Paris and // the US Naval Observatory at Washington DC

    let paris = coords::GeographPoint{long: angle::degfrmdms(-2, 20, 14.0).toradians(), lat : angle::degfrmdms(48, 50, 11.0).toradians()};

    let washington = coords::GeographPoint{long: angle::degfrmdms(77, 3, 56.0).toradians(), lat : angle::degfrmdms(38, 55, 17.0).toradians()};

    // angle::degfrmdms() converts degrees expressed in degrees, // minutes and seconds into a fractional degree

    let distance = planet::earth::geodesic_dist(&paris, &washington); // in meters ```

  • Convert equatorial coordinates to ecliptic coordinates ```rust // equatorial coordinates of the star Pollux

    let rightascension = 116.328942f64.toradians(); let declination = 28.026183f64.to_radians();

    // mean obliquity of the ecliptic

    let oblqeclip = 23.4392911f64.to_radians();

    // you can also get oblqeclip from ecliptic::mnoblqIAU(julianday) // for the Julian day on which the coordinates of the star // were observed

    // also make sure to type #[macro_use] before including the crate // to use macros

    // now, convert equatorial coordinates to ecliptic coordinates

    let (ecllong, ecllat) = eclfrmeq!(rightascension, declination, oblqeclip); ```

  • Convert equatorial coordinates to galactic coordinates ```rust // equatorial coordinates of the Nova Serpentis 1978

    let rightascension = angle::degfrmhms(17, 48, 59.74).toradians(); let declination = angle::degfrmdms(-14, 43, 8.2).to_radians();

    // convert to galactic coordinates

    let (gallong, gallat) = galfrmeq!(right_ascension, declination); ```

  • Correct for nutation in different coordinate systems ```rust // nutation in ecliptic longitude and obliquity of the ecliptic let (nutinlong, nutinoblq) = nutation::nutation(julian_day);

// nutation in equatorial coordinates let (nutinasc, nutindec) = nutation::nutationineqcoords(julianday); ```

Contributing

Anyone interested to contribute in any way possible is encouraged to do so. Not all the algorithms in Meeus's book have been implemented yet. Documentation and tests need to be written for them as well. Refactored code and minor optimizations for the existing code are also welcome.

The end goal (of this project) is to build a modern, well-tested, well-documented library of algorithms for future use in astronomy. And Rust is very much the right choice for building that.

A fun suggestion is the addition of the recent IAU 2000/2006 precession-nutation model. This method improves upon the existing model implemented here "by taking into account the effect of mantle anelasticity, ocean tides, electromagnetic couplings produced between the fluid outer core and the mantle as well as between the solid inner core and fluid outer core".

References

The main reference used as the source of algorithms is the famous book Astronomical Algorithms by Jean Meeus, whose almost every chapter has been addressed here, with functions that are well-documented and tests that use example data from the book; in some cases, such as ΔT approximation and planetary heliocentric positioning, more accurate methods have been implemented.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.