astronomia

repository·master·Indexed 41 days ago

https://github.com/commenthol/astronomia

An astronomical library for JavaScript that provides a translation of Jean Meeus's 'Astronomical Algorithms' (2nd edition). Version 4.2.0 implements celestial calculations including coordinate transformations, planetary positions via VSOP87, lunar phases, eclipses, and angular separation.

Tokens
49.2K
Snippets
224
Records
243
Agent score
52%

What's inside astronomia

  1. Import specific packages for a smaller footprint

    master

    To reduce your application's bundle size, you can import individual packages instead of the entire library. This works for both CommonJS and ES6 module syntax.

    CommonJS: Instead of require('astronomia').package, use require('astronomia/package').

    ES6 Modules: Instead of import {package} from 'astronomia', use import package from 'astronomia/package'.

    // CommonJS
    const base = require('astronomia/base')
    
    // ES6 Syntax
    import base from 'astronomia/base'
  2. Browser usage and compatibility

    master

    astronomia runs in modern browsers. To ensure correct character encoding, add <meta charset="UTF-8"> to your HTML or include your bundle with the charset="UTF-8" attribute in the script tag.

    Supported Browsers:

    • Chrome: >=45
    • Firefox: >= 45
    • Safari: >=10
    • Mobile Safari: >=10
    • Edge: >=13
    • IE: >=10 (requires core-js/es6 polyfill)
    <script src="your-bundle.js" charset="UTF-8"></script>
  3. How to handle proper motion units

    master

    To avoid error-prone manual conversions when dealing with proper motions, use the sexa.HourAngle and sexa.Angle constructors.

    Functions in this package expect proper motions to be annual (denominator is years). For example, if you have an annual proper motion in right ascension of $-0^ ext{s}.03847$, do not perform manual division or multiplication by constants. Instead, use the constructor:

    import { HourAngle, Angle } from './sexagesimal.js';
    
    // Correct way to represent annual proper motion in RA
    const mra = new HourAngle(false, 0, 0, -0.03847);
    
    // Correct way to represent annual proper motion in Dec
    const mdec = new Angle(false, 0, 0, 0.0123);
  4. Sundial Data Structures: Point and Line

    master

    The sundial module uses two primary data structures to represent geometric components:

    Point

    Represents a 2D coordinate used in constructing the sundial.

    • x: The x-coordinate.
    • y: The y-coordinate.

    Line

    Holds data required to draw an hour line.

    • hour: The hour value (ranging from 0 to 24).
    • points: An array of Point objects corresponding to that hour.
  5. XYZ coordinate structure

    master

    The coordinates returned by the positions and e5 functions are encapsulated in XYZ objects. These represent 3D coordinates in a specific coordinate system.

    Fields:

    • x (number): X-coordinate in units of Jupiter radii.
    • y (number): Y-coordinate in units of Jupiter radii.
    • z (number): Z-coordinate in units of Jupiter radii.
  6. Access VSOP87 data sets

    master

    Dedicated VSOP87 data sets can be accessed directly from the data sub-path to keep imports lightweight.

    // CommonJS
    const vsop87Bvenus = require('astronomia/data/vsop87Bvenus')
    
    // Or via the main entry point
    const {vsop87Bvenus} = require('astronomia').data
  7. Configure VSOP loading options

    master

    When instantiating the VSOP class, you can provide an opts object to specify the file type.

    Options:

    • type (String): The file type identifier (e.g., A, B, C, or D). This determines the filename pattern used to locate the data. The default is 'B', which corresponds to HELIOCENTRIC DYNAMICAL ECLIPTIC AND EQUINOX J2000 data.

    Example:

    const vsop = new VSOP('mars', './data/vsop87', { type: 'A' });
  8. Reference of astronomia packages

    master

    The library is organized into specialized packages. For detailed documentation, refer to the source code or the test files for each specific package.

    Available Packages:

    • angle: Angular Separation.
    • apparent: Apparent Place of a Star.
    • apsis: Perigee and apogee of the Moon.
    • base: Basic constants and methods
    • binary: Binary Stars.
    • circle: Smallest Circle containing three Celestial Bodies.
    • conjunction: Planetary Conjunctions.
    • coord: Transformation of Coordinates (Ecliptic, Equatorial, Horizontal, Galactic).
    • deltat: Dynamical Time and Universal Time.
    • eclipse: Eclipses.
    • elliptic: Elliptic Motion.
    • elementequinox: Reduction of ecliptical Elements from one Equinox to another one.
    • eqtime: Equation of time.
    • fit: Curve Fitting.
    • globe: Ellipsoid, Globe, Coordinates of Earth Observer.
    • illum: Illuminated Fraction of the Disk and Magnitude of a Planet.
    • interpolation: Interpolation of equidistant values (linear, len3, len5); Lagrange Polynoms
    • iterate: Iteration.
    • jm: Jewish and Moslem Calendars.
    • julian: Julian Days, Gregorian, Julian calendar functions.
    • jupiter: Ephemeris for Physical Observations of Jupiter.
    • jupitermoons: Positions of the Satellites of Jupiter.
    • kepler: Equation of Kepler.
    • line: Bodies in Straight Line
    • mars: Ephemeris for Physical Observations of Mars.
    • moon: Ephemeris for Physical Observations of the Moon.
    • moonillum: Illuminated Fraction of the Moon's Disk.
    • moonmaxdec: Maximum Declinations of the Moon.
    • moonnode: Passages of the Moon through the Nodes.
    • moonphase: Phases of the Moon.
    • moonposition: Position of the Moon.
    • nearparabolic: Near-parabolic Motion.
    • node: Passages through the Nodes.
    • nutation: Nutation and the Obliquity of the Ecliptic.
    • parabolic: Parabolic Motion.
    • parallactic: The Parallactic Angle, and three other Topics.
    • parallax: Correction for Parallax.
    • perihelion: Planets in Perihelion and Aphelion.
    • planetelements: Elements of Planetary Orbits.
    • planetposition: Ecliptic position of planets by full VSOP87 theory.
    • pluto: Pluto.
    • precess: Precession.
    • refraction: Atmospheric Refraction.
    • rise: Rising, Transit, and Setting.
    • saturnmoons: Positions of the Satellites of Saturn.
    • saturnring: The Ring of Saturn.
    • semidiameter: Semidiameters of the Sun, Moon, and Planets.
    • sexagesimal: Sexagesimal classes.
    • sidereal: Sidereal Time at Greenwich.
    • solar: Solar Coordinates.
    • solardisk: Ephemeris for Physical Observations of the Sun.
    • solarxyz: Rectangular Coordinates of the Sun.
    • solstice: Equinoxes, Solstices and Solarterms.
    • stellar: Stellar Magnitudes.
    • sundial: Calculation of a Planar Sundial.
    • sunrise: Compute rise, noon, set of the Sun for an earth observer.
  9. Calculate illuminated fraction and limb position

    master

    These functions are used to determine the phase and appearance of a celestial body (like the Moon or a planet).

    illuminated(i)

    Returns the illuminated fraction of a body's disk based on the phase angle.

    • i: Phase angle in radians.
    • Returns: Fraction (0 to 1).

    limb(equ, appSun)

    Returns the position angle of the midpoint of an illuminated limb.

    • equ: Coord object representing equatorial coordinates of the body {ra, dec} in radians.
    • appSun: Coord object representing apparent coordinates of the Sun {ra, dec} in radians.
    • Returns: Position angle in radians.
    import { illuminated, limb, Coord } from './base.js';
    
    const bodyCoord = new Coord(0.5, 0.1);
    const sunCoord = new Coord(0.6, 0.05);
    
    const fraction = illuminated(0.4);
    const angle = limb(bodyCoord, sunCoord);
  10. Convert between Julian/Besselian years and Julian Ephemeris Days (JDE)

    master

    The base module provides utility functions to convert between various time scales and Julian Ephemeris Days (JDE).

    Julian Year Conversions

    • JulianYearToJDE(jy): Converts a Julian year to JDE.
    • JDEToJulianYear(jde): Converts JDE to a Julian year.

    Besselian Year Conversions

    • BesselianYearToJDE(by): Converts a Besselian year to JDE.
    • JDEToBesselianYear(jde): Converts JDE to a Besselian year.

    Julian Centuries

    • J2000Century(jde): Returns the number of Julian centuries since the J2000 epoch (often used as $T$ in time series).
    import { JulianYearToJDE, J2000Century } from './base.js';
    
    const jde = JulianYearToJDE(2024);
    const t = J2000Century(jde); // Centuries since J2000
  11. Calculate angle and error simultaneously with angleError()

    master

    The angleError function returns both the angle between great circles and the error angle of three nearly co-linear points in a single call. This implementation uses an algorithm by B. Pessens.

    Returns an array [ψ, ω] where:

    • ψ: The angle between great circles defined by the three points.
    • ω: The error angle of the three nearly co-linear points.
    import { angleError } from 'astronomia/line';
    
    const [psi, omega] = angleError(r1, d1, r2, d2, r3, d3);